2010-02-08 15:31:14 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
GL_PACKAGE_CONF=/tmp/share/gitolite/conf
|
|
|
|
# must be the same as the value for the same variable in
|
|
|
|
# $GL_PACKAGE_CONF/example.gitolite.rc. Sorry about the catch-22 :)
|
|
|
|
|
|
|
|
# TODO need to fix for portability to ksh and so on
|
|
|
|
# TODO need to get the version in there somehow
|
|
|
|
|
|
|
|
# This program is meant to be completely non-interactive, suitable for running
|
|
|
|
# server-side from a "post RPM/DEB install" script, or manually by users.
|
|
|
|
|
|
|
|
# usage:
|
|
|
|
# $0 [foo.pub]
|
|
|
|
|
|
|
|
# The pubkey filename must end with ".pub" and is mandatory when you first run
|
|
|
|
# this command. Otherwise it is optional, and can be used to override a
|
|
|
|
# pubkey file if you happen to have lost all gitolite-access to the repos (but
|
|
|
|
# do have shell access via some other means)
|
|
|
|
|
2011-10-20 12:10:17 +02:00
|
|
|
die() { echo "$@" >&2; exit 1; }
|
2010-02-08 15:31:14 +01:00
|
|
|
|
2011-01-15 16:39:56 +01:00
|
|
|
get_rc_val() {
|
2011-10-16 14:02:30 +02:00
|
|
|
`dirname $0`/gl-query-rc $1
|
2011-01-15 16:39:56 +01:00
|
|
|
}
|
|
|
|
|
2011-10-04 10:01:44 +02:00
|
|
|
TEMPDIR=`mktemp -d -t tmp.XXXXXXXXXX`
|
2010-11-04 08:54:41 +01:00
|
|
|
export TEMPDIR
|
|
|
|
trap "/bin/rm -rf $TEMPDIR" 0
|
2010-09-05 15:18:29 +02:00
|
|
|
|
2011-01-16 10:12:11 +01:00
|
|
|
# quiet mode; only used to suppress popping up an editor on a new rc file
|
|
|
|
if [ "$1" = "-q" ]
|
|
|
|
then
|
|
|
|
shift
|
|
|
|
quiet=1
|
|
|
|
fi
|
|
|
|
|
2010-09-05 15:18:29 +02:00
|
|
|
if [ -n "$GITOLITE_HTTP_HOME" ]
|
2010-02-08 15:31:14 +01:00
|
|
|
then
|
2010-09-05 15:18:29 +02:00
|
|
|
HOME=$GITOLITE_HTTP_HOME
|
|
|
|
admin_name=$1
|
|
|
|
else
|
|
|
|
pubkey_file=$1
|
|
|
|
admin_name=
|
|
|
|
if [ -n "$pubkey_file" ]
|
|
|
|
then
|
|
|
|
echo $pubkey_file | grep '.pub$' >/dev/null || die "$pubkey_file must end in .pub"
|
|
|
|
[ -f $pubkey_file ] || die "cant find $pubkey_file"
|
|
|
|
admin_name=` basename $pubkey_file .pub`
|
|
|
|
echo $admin_name | grep '@' >/dev/null && die "please don't use '@' in the initial admin name"
|
|
|
|
fi
|
2010-02-08 15:31:14 +01:00
|
|
|
fi
|
|
|
|
|
2011-01-15 16:39:56 +01:00
|
|
|
export GL_RC
|
2011-10-04 10:01:44 +02:00
|
|
|
GL_RC=`get_rc_val GL_RC 2>/dev/null`
|
2011-01-15 16:39:56 +01:00
|
|
|
[ -z "$GL_RC" ] && GL_RC=$HOME/.gitolite.rc
|
|
|
|
|
|
|
|
if [ -f $GL_RC ]
|
2010-02-08 15:31:14 +01:00
|
|
|
then
|
2010-11-18 19:22:26 +01:00
|
|
|
print_rc_vars() {
|
|
|
|
perl -ne 's/^\s+//; s/[\s=].*//; print if /^\$/;' < $1 | sort
|
|
|
|
}
|
|
|
|
print_rc_vars $GL_PACKAGE_CONF/example.gitolite.rc > $TEMPDIR/.newvars
|
2011-01-15 16:39:56 +01:00
|
|
|
print_rc_vars $GL_RC > $TEMPDIR/.oldvars
|
2010-11-04 08:54:41 +01:00
|
|
|
comm -23 $TEMPDIR/.newvars $TEMPDIR/.oldvars > $TEMPDIR/.diffvars
|
|
|
|
if [ -s $TEMPDIR/.diffvars ]
|
2010-02-08 15:31:14 +01:00
|
|
|
then
|
2010-03-30 14:23:40 +02:00
|
|
|
cp $GL_PACKAGE_CONF/example.gitolite.rc $HOME/.gitolite.rc.new
|
|
|
|
echo new version of the rc file saved in $HOME/.gitolite.rc.new
|
2010-02-08 15:31:14 +01:00
|
|
|
echo
|
2011-01-15 16:39:56 +01:00
|
|
|
echo please update $GL_RC manually if you need features
|
2010-02-08 15:31:14 +01:00
|
|
|
echo controlled by any of the following variables:
|
|
|
|
echo ----
|
2010-11-04 08:54:41 +01:00
|
|
|
sed -e 's/^/ /' < $TEMPDIR/.diffvars
|
2010-02-08 15:31:14 +01:00
|
|
|
echo ----
|
|
|
|
fi
|
|
|
|
else
|
2010-09-05 15:18:29 +02:00
|
|
|
[ -n "$GITOLITE_HTTP_HOME" ] || [ -n "$pubkey_file" ] || die "looks like first run -- I need a pubkey file"
|
|
|
|
[ -z "$GITOLITE_HTTP_HOME" ] || [ -n "$admin_name" ] || die "looks like first run -- I need an admin name"
|
|
|
|
|
2011-01-15 16:39:56 +01:00
|
|
|
cp $GL_PACKAGE_CONF/example.gitolite.rc $GL_RC
|
2011-01-16 10:12:11 +01:00
|
|
|
if [ -z "$quiet" ]
|
|
|
|
then
|
|
|
|
printf "The default settings in the "rc" file ($GL_RC) are fine for most\n"
|
|
|
|
printf "people but if you wish to make any changes, you can do so now.\n\nhit enter..."
|
|
|
|
read i
|
|
|
|
${EDITOR:-vi} $GL_RC
|
|
|
|
fi
|
2010-02-08 15:31:14 +01:00
|
|
|
fi
|
|
|
|
|
2010-03-12 04:34:00 +01:00
|
|
|
# setup ssh stuff. We break our normal rule that we will not fiddle with
|
|
|
|
# authkeys etc., because in this case it seems appropriate
|
2010-07-25 05:31:04 +02:00
|
|
|
(
|
|
|
|
cd $HOME
|
|
|
|
mkdir -p .ssh
|
|
|
|
chmod go-rwx .ssh
|
|
|
|
touch .ssh/authorized_keys
|
|
|
|
chmod go-w . .ssh .ssh/authorized_keys
|
|
|
|
)
|
2010-03-12 04:34:00 +01:00
|
|
|
|
2011-01-15 16:39:56 +01:00
|
|
|
export GL_BINDIR
|
|
|
|
export REPO_BASE
|
|
|
|
export GL_ADMINDIR
|
2011-10-04 10:01:44 +02:00
|
|
|
GL_BINDIR=` get_rc_val GL_BINDIR `
|
|
|
|
REPO_BASE=` get_rc_val REPO_BASE `
|
|
|
|
GL_ADMINDIR=`get_rc_val GL_ADMINDIR`
|
2011-01-15 16:39:56 +01:00
|
|
|
|
2010-03-12 04:34:00 +01:00
|
|
|
# now we get to gitolite itself
|
|
|
|
|
2010-02-08 15:31:14 +01:00
|
|
|
gl-install -q
|
|
|
|
|
2010-03-18 16:18:29 +01:00
|
|
|
[ -f $GL_ADMINDIR/conf/gitolite.conf ] || {
|
2010-11-27 01:56:07 +01:00
|
|
|
cat <<EOF | cut -c9- > $GL_ADMINDIR/conf/gitolite.conf
|
2010-02-08 15:31:14 +01:00
|
|
|
repo gitolite-admin
|
|
|
|
RW+ = $admin_name
|
|
|
|
|
|
|
|
repo testing
|
|
|
|
RW+ = @all
|
|
|
|
EOF
|
|
|
|
}
|
2010-03-18 16:18:29 +01:00
|
|
|
[ -n "$pubkey_file" ] && cp $pubkey_file $GL_ADMINDIR/keydir
|
2010-02-08 15:31:14 +01:00
|
|
|
|
|
|
|
touch $HOME/.ssh/authorized_keys
|
|
|
|
gl-compile-conf -q
|
|
|
|
|
|
|
|
# setup push-to-admin
|
gl-setup: dont try to 'git add' and all that when no key was provided
Apparently some people want gitolite-admin as a non-repo. Completely
outside gitolite, managed by puppet or such, and leaving only symlinks
for 'conf' and 'keydir' in $GL_ADMINDIR.
But then when they have to run 'gl-setup', the 'git add' complains about
the symlink. Hence this patch.
----
Meanwhile, if you're one of those puppet masters, here's the script I
gave them for the *compile* (this has nothing to do with this patch; I'm
just throwing it in here so I won't lose it):
#!/bin/bash
# let's say you install using "non-root" method. (Adjust GL_BINDIR for root
# method or package method).
# install normally, then make changes directly in $GL_ADMINDIR/conf and
# $GL_ADMINDIR/keydir. (Please leaves "logs/" and "hooks/" alone).
# Then run this:
export GL_ADMINDIR=$HOME/.gitolite
export GL_BINDIR=$HOME/bin
export GL_RC=$HOME/.gitolite.rc
cd $GL_ADMINDIR
$GL_BINDIR/gl-compile-conf
# BE SURE TO REMOVE THE ADMIN REPO ITSELF FROM conf/gitolite.conf, as well as
# repositories/gitolite-admin.git, lest a push by someone end up overwriting
# this hand- (or machine-) crafted config.
# you can get away even further from gitolite's control. You can, for
# example, set GL_NO_SETUP_AUTHKEYS in the rc file, and manage even the keys
# yourself. Just put the full path to $GL_BINDIR/gl-auth-command followed by
# the username in the "command=" part of the authkeys file you generate.
2011-11-28 18:18:59 +01:00
|
|
|
[ -n "$pubkey_file" ] && (
|
2010-11-18 19:18:07 +01:00
|
|
|
cd $HOME; cd $REPO_BASE/gitolite-admin.git
|
|
|
|
GIT_WORK_TREE=$GL_ADMINDIR; export GIT_WORK_TREE
|
|
|
|
git add conf/gitolite.conf keydir
|
2011-11-15 05:33:01 +01:00
|
|
|
git config --get user.email >/dev/null || git config user.email $USER@`hostname`
|
|
|
|
git config --get user.name >/dev/null || git config user.name "$USER on `hostname`"
|
2010-11-18 19:18:07 +01:00
|
|
|
git diff --cached --quiet 2>/dev/null || git commit -am start
|
|
|
|
)
|
2010-02-08 15:31:14 +01:00
|
|
|
|
|
|
|
# now that the admin repo is created, you have to set the hooks properly; best
|
|
|
|
# do it by running install again
|
|
|
|
gl-install -q
|
2011-11-13 13:07:01 +01:00
|
|
|
|
|
|
|
# ----
|
|
|
|
|
|
|
|
# the never-ending quest to help with bloody ssh issues...
|
|
|
|
cd $GL_ADMINDIR/keydir
|
2012-01-02 01:21:00 +01:00
|
|
|
[ -n "$pubkey_file" ] && $GL_BINDIR/sshkeys-lint -q -a $admin_name < $HOME/.ssh/authorized_keys
|
gl-setup: dont try to 'git add' and all that when no key was provided
Apparently some people want gitolite-admin as a non-repo. Completely
outside gitolite, managed by puppet or such, and leaving only symlinks
for 'conf' and 'keydir' in $GL_ADMINDIR.
But then when they have to run 'gl-setup', the 'git add' complains about
the symlink. Hence this patch.
----
Meanwhile, if you're one of those puppet masters, here's the script I
gave them for the *compile* (this has nothing to do with this patch; I'm
just throwing it in here so I won't lose it):
#!/bin/bash
# let's say you install using "non-root" method. (Adjust GL_BINDIR for root
# method or package method).
# install normally, then make changes directly in $GL_ADMINDIR/conf and
# $GL_ADMINDIR/keydir. (Please leaves "logs/" and "hooks/" alone).
# Then run this:
export GL_ADMINDIR=$HOME/.gitolite
export GL_BINDIR=$HOME/bin
export GL_RC=$HOME/.gitolite.rc
cd $GL_ADMINDIR
$GL_BINDIR/gl-compile-conf
# BE SURE TO REMOVE THE ADMIN REPO ITSELF FROM conf/gitolite.conf, as well as
# repositories/gitolite-admin.git, lest a push by someone end up overwriting
# this hand- (or machine-) crafted config.
# you can get away even further from gitolite's control. You can, for
# example, set GL_NO_SETUP_AUTHKEYS in the rc file, and manage even the keys
# yourself. Just put the full path to $GL_BINDIR/gl-auth-command followed by
# the username in the "command=" part of the authkeys file you generate.
2011-11-28 18:18:59 +01:00
|
|
|
|
|
|
|
exit 0
|