diff --git a/src/00-easy-install.sh b/src/00-easy-install.sh index 4cc6ff1..5e468d5 100755 --- a/src/00-easy-install.sh +++ b/src/00-easy-install.sh @@ -15,10 +15,18 @@ # command!) set -e +# ---------------------------------------------------------------------- +# temp files +# ---------------------------------------------------------------------- + export tmpgli=tmp-gl-install trap "rm -rf $tmpgli" 0 mkdir -p $tmpgli +# ---------------------------------------------------------------------- +# service functions +# ---------------------------------------------------------------------- + die() { echo "$@"; echo; echo "run $0 again without any arguments for help and tips"; exit 1; } prompt() { # receives two arguments. A short piece of text to be displayed, without @@ -38,15 +46,16 @@ prompt() { } usage() { cat </dev/null -then - prompt " ...adding key to agent..." \ - "you're running ssh-agent. We'll try and do an ssh-add of the - private key we just created, otherwise this key won't get picked up. If - you specified a passphrase in the previous step, you'll get asked for one - now -- type in the same one." + if ssh-add -l &>/dev/null + then + prompt " ...adding key to agent..." \ + "you're running ssh-agent. We'll try and do an ssh-add of the + private key we just created, otherwise this key won't get picked up. If + you specified a passphrase in the previous step, you'll get asked for one + now -- type in the same one." - ssh-add $HOME/.ssh/$admin_name -fi + ssh-add $HOME/.ssh/$admin_name + fi -# MANUAL: you now need to add some lines to the end of your ~/.ssh/config -# file. If the file doesn't exist, create it. Make sure the file is "chmod -# 644". + # MANUAL: you now need to add some lines to the end of your ~/.ssh/config + # file. If the file doesn't exist, create it. Make sure the file is + # "chmod 644". -# The lines to be included look like this: + # The lines to be included look like this: -# host gitolite -# user git -# hostname server -# port 22 -# identityfile ~/.ssh/sitaram + # host gitolite + # user git + # hostname server + # port 22 + # identityfile ~/.ssh/sitaram -echo " + echo " host gitolite - user $user - hostname $host - port $port - identityfile ~/.ssh/$admin_name" > $tmpgli/.gl-stanza + user $user + hostname $host + port $port + identityfile ~/.ssh/$admin_name" > $tmpgli/.gl-stanza -if grep 'host *gitolite' $HOME/.ssh/config &>/dev/null -then - prompt "found gitolite para in ~/.ssh/config; assuming it is correct..." \ - "your \$HOME/.ssh/config already has settings for gitolite. I will - assume they're correct, but if they're not, please edit that file, delete - that paragraph (that line and the following few lines), Ctrl-C, and rerun. + if grep 'host *gitolite' $HOME/.ssh/config &>/dev/null + then + prompt "found gitolite para in ~/.ssh/config; assuming it is correct..." \ + "your \$HOME/.ssh/config already has settings for gitolite. I will + assume they're correct, but if they're not, please edit that file, delete + that paragraph (that line and the following few lines), Ctrl-C, and rerun. - In case you want to check right now (from another terminal) if they're - correct, here's what they are *supposed* to look like: -$(cat $tmpgli/.gl-stanza)" + In case you want to check right now (from another terminal) if they're + correct, here's what they are *supposed* to look like: + $(cat $tmpgli/.gl-stanza)" -else - prompt "creating gitolite para in ~/.ssh/config..." \ - "creating settings for your gitolite access in $HOME/.ssh/config; - these are the lines that will be appended to your ~/.ssh/config: -$(cat $tmpgli/.gl-stanza)" + else + prompt "creating gitolite para in ~/.ssh/config..." \ + "creating settings for your gitolite access in $HOME/.ssh/config; + these are the lines that will be appended to your ~/.ssh/config: + $(cat $tmpgli/.gl-stanza)" - cat $tmpgli/.gl-stanza >> $HOME/.ssh/config - # if the file didn't exist at all, it might have the wrong permissions - chmod 644 $HOME/.ssh/config -fi + cat $tmpgli/.gl-stanza >> $HOME/.ssh/config + # if the file didn't exist at all, it might have the wrong permissions + chmod 644 $HOME/.ssh/config + fi +} # ---------------------------------------------------------------------- -# client side stuff almost done; server side now +# server side # ---------------------------------------------------------------------- # MANUAL: copy the gitolite directories "src", "conf", and "doc" to the @@ -323,42 +344,44 @@ prompt "installing/upgrading..." \ GL_ADMINDIR=$(ssh -p $port $user@$host "perl -e 'do \".gitolite.rc\"; print \$GL_ADMINDIR'") REPO_BASE=$( ssh -p $port $user@$host "perl -e 'do \".gitolite.rc\"; print \$REPO_BASE'") +# determine if this is an upgrade; we decide based on whether a file called +# $GL_ADMINDIR/conf/gitolite.conf exists on the remote side. We can't do this +# till we know the correct value for GL_ADMINDIR +upgrade=0 +if ssh -p $port $user@$host cat $GL_ADMINDIR/conf/gitolite.conf &> /dev/null +then + upgrade=1 + [[ -n $admin_name ]] && echo "looks like an upgrade... not using new key '$admin_name' after all!" +else + [[ -z $admin_name ]] && die "this doesn't look like an upgrade... I need a name for the admin" +fi + # MANUAL: still in the "gitolite-install" directory? Good. Run # "src/install.pl" ssh -p $port $user@$host "cd gitolite-install; src/install.pl $quiet" -# MANUAL: if you're upgrading, just go to your clone of the admin repo, make a -# dummy change, and push. (This assumes that you didn't change the -# admin_name, pubkeys, userids, ports, or whatever, and you ran easy install -# only to upgrade the software). And then you are **done** -- ignore the rest -# of this file for the purposes of an upgrade +# MANUAL: if you're upgrading, run "src/gl-compile-conf" and you're done! -- +# ignore the rest of this file for the purposes of an upgrade -# determine if this is an upgrade; we decide based on whether a pubkey called -# $admin_name.pub exists in $GL_ADMINDIR/keydir on the remote side -upgrade=0 -if ssh -p $port $user@$host cat $GL_ADMINDIR/keydir/$admin_name.pub &> /dev/null -then - prompt "done! +[[ $upgrade == 1 ]] && { + # just compile it, in case the config file's internal format has changed + # and the hooks expect something different + ssh -p $port $user@$host "cd $GL_ADMINDIR; src/gl-compile-conf $quiet" + + prompt "" "done! If you forgot the help message you saw when you first ran this, there's a somewhat generic version of it at the end of this file. Try: tail -30 $0 -" \ - "this looks like an upgrade, based on the fact that a file called - $admin_name.pub already exists in $GL_ADMINDIR/keydir on the server. - - Please go to your clone of the admin repo, make a dummy change (like maybe - add a blank line to something), commit, and push. You're done! - - (This assumes that you didn't change the admin_name, pubkeys, userids, - ports, or whatever, and you ran easy install only to upgrade the - software)." - +" exit 0 +} -fi +# ---------------------------------------------------------------------- +# from here on it's install only +# ---------------------------------------------------------------------- # MANUAL: setup the initial config file. Edit $GL_ADMINDIR/conf/gitolite.conf # and add at least the following lines to it: