2010-04-26 18:25:02 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# install the gitolite software *system wide*. Not too robust, fancy, etc.,
|
|
|
|
# but does have a usage message and catches simple problems.
|
|
|
|
|
|
|
|
usage() { echo "
|
|
|
|
Usage:
|
2011-05-27 06:37:37 +02:00
|
|
|
$0 [shared-bin-dir shared-conf-dir shared-hooks-dir]
|
2010-04-26 18:25:02 +02:00
|
|
|
|
2011-10-21 13:48:38 +02:00
|
|
|
Installs the gitolite software (just the software, not keys or repos)
|
|
|
|
within \$HOME when invoked by a user, or system-wide when invoked by root.
|
|
|
|
|
|
|
|
Takes 0 or 3 absolute paths. The first one must be part of \$PATH.
|
|
|
|
|
2011-05-27 06:37:37 +02:00
|
|
|
Examples:
|
|
|
|
# as root
|
|
|
|
$0
|
2011-10-21 13:48:38 +02:00
|
|
|
|
2011-05-27 06:37:37 +02:00
|
|
|
# this defaults to:
|
2010-04-26 18:25:02 +02:00
|
|
|
$0 /usr/local/bin /var/gitolite/conf /var/gitolite/hooks
|
|
|
|
|
2011-05-27 06:37:37 +02:00
|
|
|
# as a normal user
|
|
|
|
$0
|
|
|
|
|
2011-10-21 13:48:38 +02:00
|
|
|
# this defaults to:
|
|
|
|
$0 \$HOME/bin \$HOME/share/gitolite/conf \$HOME/share/gitolite/hooks
|
2011-04-03 16:46:36 +02:00
|
|
|
|
|
|
|
[RPM packagers: you can supply a 4th argument to specify a 'buildroot'
|
2011-05-27 06:37:37 +02:00
|
|
|
directory. DEB folks would call this a 'DESTDIR', I believe. In this
|
|
|
|
usage the first 3 arguments are NOT optional]
|
2010-04-26 18:25:02 +02:00
|
|
|
"
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2011-10-21 13:48:38 +02:00
|
|
|
die() { echo >&2; echo "$@" >&2; echo >&2; echo Run "$0 -h" for a detailed usage message. >&2; exit 1; }
|
|
|
|
|
|
|
|
[ "$1" = "-h" ] && usage
|
2010-04-26 18:25:02 +02:00
|
|
|
|
2011-04-03 16:46:36 +02:00
|
|
|
validate_dir() {
|
2011-10-20 12:10:17 +02:00
|
|
|
echo $1 | grep '^/' >/dev/null || die "$1 should be an absolute path"
|
2011-04-03 16:46:36 +02:00
|
|
|
[ -d $1 ] || mkdir -p $1 || die "$1 does not exist and could not be created"
|
|
|
|
}
|
|
|
|
|
|
|
|
# if we have a buildroot, set that up first
|
|
|
|
buildroot=$4;
|
|
|
|
[ -n "$buildroot" ] && validate_dir $buildroot
|
|
|
|
[ -n "$buildroot" ] && buildroot=$buildroot/
|
2011-05-27 06:37:37 +02:00
|
|
|
|
|
|
|
# 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" ] && {
|
2011-10-04 10:01:44 +02:00
|
|
|
euid=`perl -e 'print $>'`
|
2011-05-27 06:37:37 +02:00
|
|
|
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
|
2011-10-21 13:48:38 +02:00
|
|
|
echo "using default values for EUID=$euid:" >&2
|
2011-05-27 06:37:37 +02:00
|
|
|
echo "$@" >&2
|
|
|
|
}
|
|
|
|
|
2011-04-03 16:46:36 +02:00
|
|
|
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
|
2010-04-26 18:25:02 +02:00
|
|
|
|
|
|
|
bindir=`echo $0 | perl -lpe 's/^/$ENV{PWD}\// unless /^\//; s/\/[^\/]+$//;'`
|
|
|
|
cd $bindir/.. # we assume the standard gitolite source tree is here!
|
|
|
|
|
2011-04-03 16:46:36 +02:00
|
|
|
cp src/* $buildroot$gl_bin_dir || die "cp src/* to $buildroot$gl_bin_dir failed"
|
|
|
|
perl -lpi -e "s(^GL_PACKAGE_CONF=.*)(GL_PACKAGE_CONF=$gl_conf_dir)" $buildroot$gl_bin_dir/gl-setup
|
2010-04-26 18:25:02 +02:00
|
|
|
|
2010-05-31 10:42:04 +02:00
|
|
|
# record which version is being sent across; we assume it's HEAD
|
|
|
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1
|
|
|
|
then
|
2011-09-28 00:40:56 +02:00
|
|
|
git describe --tags --long --dirty=-dt 2>/dev/null > conf/VERSION || die "git describe failed -- your git is probably too old"
|
2010-05-31 10:42:04 +02:00
|
|
|
else
|
2010-06-01 12:57:33 +02:00
|
|
|
[ -f conf/VERSION ] || echo '(unknown)' > conf/VERSION
|
2010-05-31 10:42:04 +02:00
|
|
|
fi
|
|
|
|
|
2011-04-03 16:46:36 +02:00
|
|
|
cp -R conf/* $buildroot$gl_conf_dir || die "cp conf/* to $buildroot$gl_conf_dir failed"
|
2010-04-26 18:25:02 +02:00
|
|
|
perl -lpi \
|
|
|
|
-e "s(^#\s*\\\$GL_PACKAGE_CONF\s*=.*)(\\\$GL_PACKAGE_CONF = '$gl_conf_dir';)" \
|
2011-04-03 16:46:36 +02:00
|
|
|
$buildroot$gl_conf_dir/example.gitolite.rc
|
2010-04-26 18:25:02 +02:00
|
|
|
perl -lpi \
|
|
|
|
-e "s(^#\s*\\\$GL_PACKAGE_HOOKS\s*=.*)(\\\$GL_PACKAGE_HOOKS = '$gl_hooks_dir';)" \
|
2011-04-03 16:46:36 +02:00
|
|
|
$buildroot$gl_conf_dir/example.gitolite.rc
|
2010-04-26 18:25:02 +02:00
|
|
|
|
2011-04-03 16:46:36 +02:00
|
|
|
cp -R hooks/* $buildroot$gl_hooks_dir || die "cp hooks/* to $buildroot$gl_hooks_dir failed"
|
2011-10-21 13:48:38 +02:00
|
|
|
|
|
|
|
# ----
|
|
|
|
|
|
|
|
# check if $gl_bin_dir is in $PATH and advise the user if needed
|
|
|
|
which=`which gl-setup 2>/dev/null`
|
|
|
|
|
|
|
|
path_advice="
|
|
|
|
Since gl-setup MUST be run from the PATH (and not as src/gl-setup or such),
|
|
|
|
you must fix this before running gl-setup. The simplest way is to add
|
|
|
|
|
|
|
|
PATH=$gl_bin_dir:\$PATH
|
|
|
|
|
|
|
|
to the end of your bashrc or similar file. You can even simply run that
|
|
|
|
command manually each time you log in and want to run a gitolite command."
|
|
|
|
|
|
|
|
[ -z "$which" ] && die " ***** WARNING *****
|
|
|
|
gl-setup is not in your \$PATH.
|
|
|
|
$path_advice"
|
|
|
|
|
|
|
|
which=`dirname $which`
|
|
|
|
[ "$which" != "$gl_bin_dir" ] && die " ***** WARNING *****
|
|
|
|
$which precedes $gl_bin_dir in your \$PATH,
|
|
|
|
and it *also* contains gl-setup. This is almost certainly going to confuse
|
|
|
|
you or me later.
|
|
|
|
$path_advice"
|