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_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() {
echo "abuild-keygen $abuild_ver"
@ -23,6 +36,7 @@ usage() {
echo " -a Set PACKAGER_PRIVKEY=<generated key> in $abuild_userconf"
echo " -i Install public key into /etc/apk/keys using sudo"
echo " -h Show this help"
echo " -n Non-interactive. Use defaults"
echo ""
exit 1
}
@ -47,26 +61,19 @@ else
default_name="$USER-$(printf "%x" $(date +%s))"
fi
while getopts "ahi" opt; do
while getopts "ahin" opt; do
case $opt in
a) append_config=yes;;
h) usage;;
i) install_pubkey=yes;
i) install_pubkey=yes;;
n) non_interactive=yes;;
esac
done
shift $(( $OPTIND - 1))
mkdir -p "$abuild_home"
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 [ -z "$line" ]; then
privkey="$abuild_home/$default_name.rsa"
else
privkey="$line"
fi
get_privkey_file
pubkey="$privkey.pub"
# generate the private key in a subshell with stricter umask