From 78d02e143760a0df8022dae601d809a4d452cab3 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Sun, 25 Oct 2009 08:29:52 +0530 Subject: [PATCH] the rc file can now be in one of 2 places... Packaging gitolite for debian requires the rc file to be in /etc/gitolite. But non-root installs must still be supported, and they need it in $HOME. This means the rc file is no longer in a fixed place, which needs code to find the rc file first. See comments inside new file 'gitolite.pm' for details. The rest of the changes are in the other programs, to replace the hard-coded rc filename with a call to this new code. --- src/gitolite.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/gl-auth-command | 11 +++++++++-- src/gl-compile-conf | 10 ++++++++-- src/install.pl | 16 ++++++++++------ src/update-hook.pl | 5 +++-- 5 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 src/gitolite.pm diff --git a/src/gitolite.pm b/src/gitolite.pm new file mode 100644 index 0000000..2c325e2 --- /dev/null +++ b/src/gitolite.pm @@ -0,0 +1,45 @@ +# this file is commonly used using "require". It is not required to use "use" +# (because it doesn't live in a different package) + +# warning: preceding para requires 4th attribute of a programmer after +# laziness, impatience, and hubris: sense of humour :-) + +# WARNING +# ------- +# the name of this file will change as soon as its function/feature set +# stabilises enough ;-) + +# right now all it does is define a function that tells you where to find the +# rc file + +# ---------------------------------------------------------------------------- +# where is the rc file hiding? +# ---------------------------------------------------------------------------- + +sub where_is_rc +{ + # till now, the rc file was in one fixed place: .gitolite.rc in $HOME of + # the user hosting the gitolite repos. This was fine, because gitolite is + # all about empowering non-root users :-) + + # then we wanted to make a debian package out of it (thank you, Rhonda!) + # which means (a) it's going to be installed by root anyway and (b) any + # config files have to be in /etc/ + + # the only way to resolve this in a backward compat way is to look for the + # $HOME one, and if you don't find it look for the /etc one + + # this common routine does that, setting an env var for the first one it + # finds + + return if $ENV{GL_RC}; + + for my $glrc ( $ENV{HOME} . "/.gitolite.rc", "/etc/gitolite/gitolite.rc" ) { + if (-f $glrc) { + $ENV{GL_RC} = $glrc; + return; + } + } +} + +1; diff --git a/src/gl-auth-command b/src/gl-auth-command index 8201403..62e5add 100755 --- a/src/gl-auth-command +++ b/src/gl-auth-command @@ -27,8 +27,15 @@ use warnings; our ($GL_LOGT, $GL_CONF_COMPILED, $REPO_BASE, $GIT_PATH); our %repos; -my $glrc = $ENV{HOME} . "/.gitolite.rc"; -die "parse $glrc failed: " . ($! or $@) unless do $glrc; +# the common setup module is in the same directory as this running program is +my $bindir = $0; +$bindir =~ s/\/[^\/]+$//; +require "$bindir/gitolite.pm"; + +# ask where the rc file is, get it, and "do" it +&where_is_rc(); +die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC}; +# then "do" the compiled config file, whose name we now know die "parse $GL_CONF_COMPILED failed: " . ($! or $@) unless do $GL_CONF_COMPILED; # add a custom path for git binaries, if specified diff --git a/src/gl-compile-conf b/src/gl-compile-conf index d99976e..5f8b3ae 100755 --- a/src/gl-compile-conf +++ b/src/gl-compile-conf @@ -54,8 +54,14 @@ our ($GL_ADMINDIR, $GL_CONF, $GL_KEYDIR, $GL_CONF_COMPILED, $REPO_BASE, $REPO_UM # typical push generates my $ATTN = "\n\t\t***** ERROR *****\n "; -my $glrc = $ENV{HOME} . "/.gitolite.rc"; -die "$ATTN parse $glrc failed: " . ($! or $@) unless do $glrc; +# the common setup module is in the same directory as this running program is +my $bindir = $0; +$bindir =~ s/\/[^\/]+$//; +require "$bindir/gitolite.pm"; + +# ask where the rc file is, get it, and "do" it +&where_is_rc(); +die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC}; # add a custom path for git binaries, if specified $ENV{PATH} .= ":$GIT_PATH" if $GIT_PATH; diff --git a/src/install.pl b/src/install.pl index f6e4142..1eb4a70 100755 --- a/src/install.pl +++ b/src/install.pl @@ -18,20 +18,24 @@ sub wrap_mkdir print STDERR "created $dir\n"; } -# the only path that is *fixed* (can't be changed without changing all 3 -# programs) is ~/.gitolite.rc +# the common setup module is in the same directory as this running program is +my $bindir = $0; +$bindir =~ s/\/[^\/]+$//; +require "$bindir/gitolite.pm"; -my $glrc = $ENV{HOME} . "/.gitolite.rc"; -unless (-f $glrc) { +# ask where the rc file is, get it, and "do" it +&where_is_rc(); +unless ($ENV{GL_RC}) { # doesn't exist. Copy it across, tell user to edit it and come back + my $glrc = $ENV{HOME} . "/.gitolite.rc"; system("cp conf/example.gitolite.rc $glrc"); print STDERR "created $glrc\n"; print STDERR "please edit it, change the paths if you wish to, and RERUN THIS SCRIPT\n"; exit; } -# ok now $glrc exists; read it to get the other paths -die "parse $glrc failed: " . ($! or $@) unless do $glrc; +# ok now the rc file exists; read it to get the other paths +die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC}; # add a custom path for git binaries, if specified $ENV{PATH} .= ":$GIT_PATH" if $GIT_PATH; diff --git a/src/update-hook.pl b/src/update-hook.pl index 5f1c3bb..cdf7402 100755 --- a/src/update-hook.pl +++ b/src/update-hook.pl @@ -28,8 +28,9 @@ use warnings; our ($GL_CONF_COMPILED, $PERSONAL); our %repos; -my $glrc = $ENV{HOME} . "/.gitolite.rc"; -die "parse $glrc failed: " . ($! or $@) unless do $glrc; +# we should already have the GL_RC env var set when we enter this hook +die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC}; +# then "do" the compiled config file, whose name we now know die "parse $GL_CONF_COMPILED failed: " . ($! or $@) unless do $GL_CONF_COMPILED; # ----------------------------------------------------------------------------