Skip to content
Snippets Groups Projects
Commit 83ff539c authored by Jim Pryor's avatar Jim Pryor Committed by Natanael Copa
Browse files

abuild_keygen: several tweaks

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