summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--abuild-keygen.in29
1 files changed, 18 insertions, 11 deletions
diff --git a/abuild-keygen.in b/abuild-keygen.in
index af1ad90..6eefc16 100644
--- a/abuild-keygen.in
+++ b/abuild-keygen.in
@@ -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