Commit 83ff539c authored by Dubiousjim's avatar Dubiousjim Committed by Natanael Copa

abuild_keygen: several tweaks

* make vars local
* refactor calculation of default_name
* make non_interactive=1
* tweak error message
* tweak sed command
parent ef9fb529
......@@ -19,6 +19,7 @@ fi
# ask for privkey unless non-interactive mode
# returns value in global $privkey
get_privkey_file() {
local emailaddr default_name
emailaddr=${PACKAGER##*<}
emailaddr=${emailaddr%%>*}
......@@ -27,16 +28,12 @@ get_privkey_file() {
emailaddr=$(git config --get user.email 2>/dev/null)
fi
if [ -n "$emailaddr" ]; then
default_name="$emailaddr-$(printf "%x" $(date +%s))"
else
default_name="$USER-$(printf "%x" $(date +%s))"
fi
default_name="${emailaddr:-$USER}-$(printf "%x" $(date +%s))"
privkey="$abuild_home/$default_name.rsa"
[ "$non_interactive" = "yes" ] && return 0
[ -n "$non_interactive" ] && 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): "
echo -n "Enter file in which to save the key [$privkey]: "
read line
if [ -n "$line" ]; then
......@@ -73,7 +70,7 @@ do_keygen() {
if [ -n "$append_config" ]; then
if [ -f "$abuild_userconf" ]; then
# comment out the existing values
sed -i -e 's/^\(PACKAGER_PRIVKEY=.*\)/\#\1/' "$abuild_userconf"
sed -i -e 's/^PACKAGER_PRIVKEY=/\#&/' "$abuild_userconf"
fi
echo "PACKAGER_PRIVKEY=\"$privkey\"" >> "$abuild_userconf"
else
......@@ -119,7 +116,7 @@ while true; do
case $1 in
-a|--append) append_config=1;;
-i|--install) install_pubkey=1;;
-n) non_interactive=yes;;
-n) non_interactive=1;;
-q|--quiet) quiet=1;; # suppresses msg
-h|--help) usage; exit;;
--) shift; break;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment