abuild-keygen: implement -n for non-interactive mode

This commit is contained in:
Natanael Copa 2010-12-20 13:22:29 +00:00
parent e524bc68e9
commit 18fa4231dc

View File

@ -15,6 +15,19 @@ abuild_conf=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
abuild_home=${ABUILD_USERDIR:-"$HOME/.abuild"} abuild_home=${ABUILD_USERDIR:-"$HOME/.abuild"}
abuild_userconf=${ABUILD_USERCONF:-"$abuild_home/abuild.conf"} abuild_userconf=${ABUILD_USERCONF:-"$abuild_home/abuild.conf"}
# ask for privkey unless non-interactive mode
# returns value in global $privkey
get_privkey_file() {
privkey="$abuild_home/$default_name.rsa"
[ "$non_interactive" = "yes" ] && return 0
echo "Generating public/private rsa key pair for abuild"
echo -n "Enter file in which to save the key ($abuild_home/$default_name.rsa): "
read line
if [ -n "$line" ]; then
privkey="$line"
fi
}
usage() { usage() {
echo "abuild-keygen $abuild_ver" echo "abuild-keygen $abuild_ver"
@ -23,6 +36,7 @@ usage() {
echo " -a Set PACKAGER_PRIVKEY=<generated key> in $abuild_userconf" echo " -a Set PACKAGER_PRIVKEY=<generated key> in $abuild_userconf"
echo " -i Install public key into /etc/apk/keys using sudo" echo " -i Install public key into /etc/apk/keys using sudo"
echo " -h Show this help" echo " -h Show this help"
echo " -n Non-interactive. Use defaults"
echo "" echo ""
exit 1 exit 1
} }
@ -47,26 +61,19 @@ else
default_name="$USER-$(printf "%x" $(date +%s))" default_name="$USER-$(printf "%x" $(date +%s))"
fi fi
while getopts "ahi" opt; do while getopts "ahin" opt; do
case $opt in case $opt in
a) append_config=yes;; a) append_config=yes;;
h) usage;; h) usage;;
i) install_pubkey=yes; i) install_pubkey=yes;;
n) non_interactive=yes;;
esac esac
done done
shift $(( $OPTIND - 1)) shift $(( $OPTIND - 1))
mkdir -p "$abuild_home" mkdir -p "$abuild_home"
echo "Generating public/private rsa key pair for abuild" get_privkey_file
echo -n "Enter file in which to save the key ($abuild_home/$default_name.rsa): "
read line
if [ -z "$line" ]; then
privkey="$abuild_home/$default_name.rsa"
else
privkey="$line"
fi
pubkey="$privkey.pub" pubkey="$privkey.pub"
# generate the private key in a subshell with stricter umask # generate the private key in a subshell with stricter umask