X-Original-To: alpine-devel@lists.alpinelinux.org Delivered-To: alpine-devel@mail.alpinelinux.org Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.alpinelinux.org (Postfix) with ESMTPS id EB893DC74A8 for ; Fri, 5 Jul 2013 04:21:49 +0000 (UTC) Received: from compute2.internal (compute2.nyi.mail.srv.osa [10.202.2.42]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 07BD52087B for ; Fri, 5 Jul 2013 00:21:44 -0400 (EDT) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute2.internal (MEProxy); Fri, 05 Jul 2013 00:21:44 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=from:to:subject:date:message-id :in-reply-to:references; s=smtpout; bh=0WgspIY6j4VHLLDsT3fRQl8sJ bM=; b=HjPAzT4tajZBr+Jgx4bMYzUTXMYnHffwxvC71rQbmC+S92n/iXVs0jTF5 rmxk5CoN/ezxrWv4RaePcoRjLp8KCK8E/q88Cf/C1BpXNQeOJJSI1ZaLWNdkeHFH EBSwDwm30U0+PBo2AN+N1EdOkyg3Pj8KoNVSaFteZH6iElqJLs= X-Sasl-enc: w9diN8WG1/n+v7wxvhU5Cbmq9PgTMAL4DR00Q+/ilXxL 1372998103 Received: from localhost (unknown [69.86.161.244]) by mail.messagingengine.com (Postfix) with ESMTPA id 695F66804C1 for ; Fri, 5 Jul 2013 00:21:43 -0400 (EDT) From: Dubiousjim To: alpine-devel@lists.alpinelinux.org Subject: [alpine-devel] [PATCH 05/31] abuild-keygen: refactor Date: Fri, 5 Jul 2013 00:21:14 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: --- abuild-keygen.in | 119 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/abuild-keygen.in b/abuild-keygen.in index a095068..3cf5531 100644 --- a/abuild-keygen.in +++ b/abuild-keygen.in @@ -22,6 +22,20 @@ msg() { # ask for privkey unless non-interactive mode # returns value in global $privkey get_privkey_file() { + emailaddr=${PACKAGER##*<} + emailaddr=${emailaddr%%>*} + + # if PACKAGER does not contain a valid email address, then ask git + if [ -z "$emailaddr" ] || [ "${emailaddr##*@}" = "$emailaddr" ]; then + 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 + privkey="$abuild_home/$default_name.rsa" [ "$non_interactive" = "yes" ] && return 0 echo "Generating public/private rsa key pair for abuild" @@ -33,6 +47,52 @@ get_privkey_file() { fi } +do_keygen() { + mkdir -p "$abuild_home" + + get_privkey_file + pubkey="$privkey.pub" + + # generate the private key in a subshell with stricter umask + ( + umask 0007 + openssl genrsa -out "$privkey" 2048 + ) + openssl rsa -in "$privkey" -pubout -out "$pubkey" + + + if [ -n "$install_pubkey" ]; then + msg "Installing $pubkey to /etc/apk/keys..." + sudo mkdir -p /etc/apk/keys + sudo cp -i "$pubkey" /etc/apk/keys/ + else + + msg "" + msg "You'll need to install $pubkey into " + msg "/etc/apk/keys to be able to install packages and repositories signed with" + msg "$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 + msg "" + msg "You might want add following line to $abuild_userconf:" + msg "" + msg "PACKAGER_PRIVKEY=\"$privkey\"" + msg "" + fi + + msg "" + msg "Please remember to make a safe backup of your private key:" + msg "$privkey" + msg "" +} + # print usage and exit usage() { echo "abuild-keygen $abuild_ver" @@ -53,20 +113,6 @@ usage() { # read user config if exists [ -f "$abuild_userconf" ] && . "$abuild_userconf" -emailaddr=${PACKAGER##*<} -emailaddr=${emailaddr%%>*} - -# if PACKAGER does not contain a valid email address, then ask git -if [ -z "$emailaddr" ] || [ "${emailaddr##*@}" = "$emailaddr" ]; then - 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 - while getopts "ahinq" opt; do case $opt in a) append_config=yes;; @@ -78,47 +124,4 @@ while getopts "ahinq" opt; do done shift $(( $OPTIND - 1)) -mkdir -p "$abuild_home" - -get_privkey_file -pubkey="$privkey.pub" - -# generate the private key in a subshell with stricter umask -( -umask 0007 -openssl genrsa -out "$privkey" 2048 -) -openssl rsa -in "$privkey" -pubout -out "$pubkey" - - -if [ -n "$install_pubkey" ]; then - msg "Installing $pubkey to /etc/apk/keys..." - sudo mkdir -p /etc/apk/keys - sudo cp -i "$pubkey" /etc/apk/keys/ -else - - msg "" - msg "You'll need to install $pubkey into " - msg "/etc/apk/keys to be able to install packages and repositories signed with" - msg "$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 - msg "" - msg "You might want add following line to $abuild_userconf:" - msg "" - msg "PACKAGER_PRIVKEY=\"$privkey\"" - msg "" -fi - -msg "" -msg "Please remember to make a safe backup of your private key:" -msg "$privkey" -msg "" - +do_keygen -- 1.8.3.1 --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---