diff --git a/abuild-keygen.in b/abuild-keygen.in index 65737f0..29e9b40 100644 --- a/abuild-keygen.in +++ b/abuild-keygen.in @@ -20,6 +20,7 @@ usage() { echo "abuild-keygen $abuild_ver" echo "usage: abuild-keygen [-ih]" echo "options:" + echo " -a Set PACKAGER_PRIVKEY= in $abuild_userconf" echo " -i Install public key into /etc/apk/keys using sudo" echo " -h Show this help" echo "" @@ -46,8 +47,9 @@ else default_name="$USER" fi -while getopts "hi" opt; do +while getopts "ahi" opt; do case $opt in + a) append_config=yes;; h) usage;; i) install_pubkey=yes; esac @@ -69,7 +71,7 @@ pubkey="$privkey.pub" # generate the private key in a subshell with stricter umask ( -umask 0077 +umask 0007 openssl genrsa -out "$privkey" 2048 ) openssl rsa -in "$privkey" -pubout -out "$pubkey" @@ -87,7 +89,22 @@ else echo "$privkey" fi +if [ -n "$append_config" ]; then + if [ -f "$abuild_userconf" ]; then + # comment out the existing values + sed -i -e 's/^\(PACKAGER_PRIVKEY=.*\)/\#\1/' "$abuild_userconf" + fi + echo "PACKAGER_PRIVKEY=\"$privkey\"" >> "$abuild_userconf" +else + echo "" + echo "You might want add following line to $abuild_userconf:" + echo "" + echo "PACKAGER_PRIVKEY=\"$privkey\"" + echo "" +fi + echo "" -echo "Please remember to make a safe backup of $privkey" +echo "Please remember to make a safe backup of your private key:" +echo "$privkey" echo ""