From 660fad954a4a4b63d4dac0dafebb344892195e69 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Fri, 27 May 2011 10:07:37 +0530 Subject: [PATCH] make gl-system-install easier to run make the arguments optional (with documented defaults) plus they need not exist a priori, reducing one command (the silly mkdir!) that the user has to run. All this is preparatory to deprecating the from-client method. We've even switched the test suite to 'non-root' method now --- src/gl-system-install | 33 ++++++++++++++++++++++++++++----- t/install-gitolite | 23 ++++++++++++++++++++--- t/keys/config | 5 ++++- t/rollback.server | 2 +- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/gl-system-install b/src/gl-system-install index 2a82527..b1f88f8 100755 --- a/src/gl-system-install +++ b/src/gl-system-install @@ -5,25 +5,32 @@ usage() { echo " Usage: - $0 shared-bin-dir shared-conf-dir shared-hooks-dir + $0 [shared-bin-dir shared-conf-dir shared-hooks-dir] - Example: + Examples: + # as root + $0 + # this defaults to: $0 /usr/local/bin /var/gitolite/conf /var/gitolite/hooks + # as a normal user + $0 + # this defaults to: + $0 $HOME/bin $HOME/share/gitolite/conf $HOME/share/gitolite/hooks + In this example, all the binaries go to /usr/local/bin, and the shared conf and hooks files/directories go to the other 2 directories given. All the 3 paths supplied MUST be absolute. [RPM packagers: you can supply a 4th argument to specify a 'buildroot' - directory. DEB folks would call this a 'DESTDIR', I believe.] + directory. DEB folks would call this a 'DESTDIR', I believe. In this + usage the first 3 arguments are NOT optional] " exit 1; } die() { echo "$@"; echo; usage; exit 1; } >&2 -[ -z "$3" ] && usage - validate_dir() { echo $1 | grep ^/ >/dev/null || die "$1 should be an absolute path" [ -d $1 ] || mkdir -p $1 || die "$1 does not exist and could not be created" @@ -33,6 +40,22 @@ validate_dir() { buildroot=$4; [ -n "$buildroot" ] && validate_dir $buildroot [ -n "$buildroot" ] && buildroot=$buildroot/ + +# either all 3 args must be supplied or none at all +[ -n "$1" ] && [ -z "$3" ] && die "I need all 3 directories or none at all" +# supply default values to args 1, 2, and 3 if not provided +[ -z "$1" ] && { + euid=$(perl -e 'print $>') + if [ "$euid" = "0" ] + then + set /usr/local/bin /var/gitolite/conf /var/gitolite/hooks + else + set $HOME/bin $HOME/share/gitolite/conf $HOME/share/gitolite/hooks + fi + echo "using default value for EUID=$euid:" >&2 + echo "$@" >&2 +} + gl_bin_dir=$1; validate_dir $buildroot$gl_bin_dir gl_conf_dir=$2; validate_dir $buildroot$gl_conf_dir gl_hooks_dir=$3; validate_dir $buildroot$gl_hooks_dir diff --git a/t/install-gitolite b/t/install-gitolite index 973685a..d1e8938 100755 --- a/t/install-gitolite +++ b/t/install-gitolite @@ -1,5 +1,6 @@ #!/bin/bash + export TESTDIR=$PWD # prepare local ssh @@ -16,15 +17,31 @@ chmod 600 ~/.ssh/u? # blank out the server side echo the next command MAY ask for a password -ssh gitolite-test@localhost rm -rf .ssh .gitolite .gitolite.rc repositories gitolite-install /tmp/glrb +ssh gitolite-test@localhost rm -rf .ssh .gitolite .gitolite.rc repositories /tmp/glrb bin share echo the next command SHOULD ask for a password ssh-copy-id -i ~/.ssh/id_rsa gitolite-test@localhost echo the next command should NOT ask for a password +scp ~/.ssh/tester.pub gitolite-test@localhost: # install it -../src/gl-easy-install -q gitolite-test localhost tester +echo installing whatever is here now... +# ../src/gl-easy-install -q gitolite-test localhost tester +cat < conf/VERSION +src/gl-system-install +cd +gl-setup -q tester.pub +EOF +echo ============================= +echo +echo +echo # add 6 keys +rm -rf ~/gitolite-admin +cd +git clone gitolite:gitolite-admin cd ~/gitolite-admin cp $TESTDIR/keys/u*pub keydir git add keydir; git commit -m 'added 6 keys' @@ -34,5 +51,5 @@ git push cd tar cf rollback.tar gitolite-admin ssh gitolite-test@localhost mkdir -p repositories /tmp/glrb -ssh gitolite-test@localhost tar cf rollback.tar .ssh .gitolite .gitolite.rc repositories gitolite-install +ssh gitolite-test@localhost tar cf rollback.tar .ssh .gitolite .gitolite.rc repositories bin share ssh gitolite-test@localhost tar -C /tmp -cf \$HOME/rollback2.tar glrb diff --git a/t/keys/config b/t/keys/config index 7330f7b..4dea0a2 100644 --- a/t/keys/config +++ b/t/keys/config @@ -1,4 +1,7 @@ -host u? +host gitolite + identityfile ~/.ssh/tester + +host u? gitolite user gitolite-test hostname localhost host u1 diff --git a/t/rollback.server b/t/rollback.server index ce26d80..17b2694 100755 --- a/t/rollback.server +++ b/t/rollback.server @@ -1,7 +1,7 @@ #!/bin/bash cd -rm -rf .ssh .gitolite .gitolite.rc repositories gitolite-install /tmp/glrb +rm -rf .ssh .gitolite .gitolite.rc repositories gitolite-install /tmp/glrb bin share tar xf rollback.tar ( cd /tmp; tar xf ~/rollback2.tar )