toolbox: anchor _repo pattern to start of line
[girocco.git] / install.sh
blob880abc797b7b0a4b075d35d42a5cd93584dc9988
1 #!/bin/sh
2 # The Girocco installation script
3 # We will OVERWRITE basedir!
5 set -e
7 if [ -z "$MAKE" ]; then
8 echo "ERROR: MAKE not set" >&2
9 echo "Please run install.sh using 'make install'" >&2
10 echo "or set MAKE to the name of the GNU make executable" >&2
11 exit 1
14 # Run perl module checker
15 if [ ! -x toolbox/check-perl-modules.pl ]; then
16 echo "ERROR: missing toolbox/check-perl-modules.pl!" >&2
17 exit 1
19 toolbox/check-perl-modules.pl
21 # What Config should we use?
22 [ -n "$GIROCCO_CONF" ] || GIROCCO_CONF=Girocco::Config
23 echo "*** Initializing using $GIROCCO_CONF..."
25 # First run Girocco::Config consistency checks
26 perl -I. -M$GIROCCO_CONF -e ''
28 . ./shlib.sh
30 owngroup=""
31 [ -z "$cfg_owning_group" ] || owngroup=":$cfg_owning_group"
32 if [ -n "$cfg_httpspushurl" -a -z "$cfg_certsdir" ]; then
33 echo "ERROR: \$httpspushurl is set but \$certsdir is not!" >&2
34 echo "ERROR: perhaps you have an incorrect Config.pm?" >&2
35 exit 1
39 echo "*** Checking for compiled utilities..."
40 if [ ! -x src/can_user_push ]; then
41 echo "ERROR: src/can_user_push is not built! Did you _REALLY_ read INSTALL?" >&2
42 echo "ERROR: perhaps you forgot to run make?" >&2
43 exit 1
45 if [ ! -x src/can_user_push_http ]; then
46 echo "ERROR: src/can_user_push_http is not built! Did you _REALLY_ read INSTALL?" >&2
47 echo "ERROR: perhaps you forgot to run make?" >&2
48 exit 1
50 if [ ! -x src/getent ]; then
51 echo "ERROR: src/getent is not built! Did you _REALLY_ read INSTALL?" >&2
52 echo "ERROR: perhaps you forgot to run make?" >&2
53 exit 1
55 if [ ! -x src/get_user_uuid ]; then
56 echo "ERROR: src/get_user_uuid is not built! Did you _REALLY_ read INSTALL?" >&2
57 echo "ERROR: perhaps you forgot to run make?" >&2
58 exit 1
62 echo "*** Checking for ezcert..."
63 if [ ! -f ezcert.git/CACreateCert ]; then
64 echo "ERROR: ezcert.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
65 exit 1
69 echo "*** Checking for git..."
70 if [ ! -x "$cfg_git_bin" ]; then
71 echo "ERROR: $cfg_git_bin does not exist or is not executable" >&2
72 exit 1
74 if ! git_version="$("$cfg_git_bin" --version)"; then
75 echo "ERROR: $cfg_git_bin --version failed" >&2
76 exit 1
78 case "$git_version" in
79 "git version "*) :;;
81 echo "ERROR: '$cfg_git_bin --version' output does not start with 'git version '" >&2
82 exit 1
83 esac
84 case "$cfg_git_bin" in /*) :;; *)
85 echo 'ERROR: $Girocco::Config::git_bin must be set to an absolute path' >&2
86 exit 1
87 esac
90 chown_make() {
91 if [ "$LOGNAME" = root -a -n "$SUDO_USER" -a "$SUDO_USER" != root ]; then
92 find "$@" -user root -print0 2>/dev/null | \
93 xargs $(: | xargs echo -r) -0 chown "$SUDO_USER:$(id -gn "$SUDO_USER")"
94 elif [ "$LOGNAME" = root -a -z "$SUDO_USER" -o "$SUDO_USER" = root ]; then
95 echo "*** WARNING: running make as root w/o sudo may leave root-owned: $*"
99 echo "*** Setting up basedir..."
100 "$MAKE" --no-print-directory --quiet apache.conf
101 chown_make apache.conf
102 "$MAKE" --no-print-directory --quiet -C src
103 chown_make src
104 rm -fr "$cfg_basedir"
105 mkdir -p "$cfg_basedir"
106 cp -pR Girocco jobd taskd gitweb html jobs toolbox hooks apache.conf shlib.sh bin screen "$cfg_basedir"
107 cp -p src/can_user_push src/can_user_push_http src/get_user_uuid ezcert.git/CACreateCert cgi/authrequired.cgi "$cfg_basedir/bin"
108 [ -n "$cfg_httpspushurl" ] || rm -f "$cfg_basedir"/html/rootcert.html "$cfg_basedir"/html/httpspush.html
109 [ -n "$cfg_mob" ] || rm -f "$cfg_basedir"/html/mob.html
111 # Put the correct Config in place
112 [ "$GIROCCO_CONF" = "Girocco::Config" ] || cp "$(echo "$GIROCCO_CONF" | sed 's#::#/#g; s/$/.pm/')" "$cfg_basedir/Girocco/Config.pm"
115 echo "*** Preprocessing scripts..."
116 perl -I. -M$GIROCCO_CONF -i -p \
117 -e 's/(?<!")\@basedir\@/"$Girocco::Config::basedir"/g;' \
118 -e 's/(?<=")\@basedir\@/$Girocco::Config::basedir/g;' \
119 -e 's/\@reporoot\@/"$Girocco::Config::reporoot"/g;' \
120 -e 's/\@jailreporoot\@/"$Girocco::Config::jailreporoot"/g;' \
121 -e 's/\@chroot\@/"$Girocco::Config::chroot"/g;' \
122 -e 's/\@webadmurl\@/"$Girocco::Config::webadmurl"/g;' \
123 -e 's/\@screen_acl_file\@/"$Girocco::Config::screen_acl_file"/g;' \
124 -e 's/\@mob\@/"$Girocco::Config::mob"/g;' \
125 "$cfg_basedir"/jobs/*.sh "$cfg_basedir"/jobd/*.sh \
126 "$cfg_basedir"/taskd/*.sh "$cfg_basedir"/gitweb/*.sh \
127 "$cfg_basedir"/shlib.sh "$cfg_basedir"/hooks/* \
128 "$cfg_basedir"/toolbox/*.sh "$cfg_basedir"/toolbox/*.pl \
129 "$cfg_basedir"/toolbox/reports/*.sh \
130 "$cfg_basedir"/bin/git-* \
131 "$cfg_basedir"/bin/create-* "$cfg_basedir"/bin/update-* \
132 "$cfg_basedir"/bin/authrequired.cgi "$cfg_basedir"/screen/*
134 # Dump all the cfg_ and defined_ variables to shlib_vars.sh
135 get_girocco_config_var_list > "$cfg_basedir"/shlib_vars.sh
137 if [ -n "$cfg_mirror" ]; then
138 echo "--- Remember to start $cfg_basedir/taskd/taskd.pl"
140 echo "--- Also remember to either start $cfg_basedir/jobd/jobd.sh, or add this"
141 echo "--- to the crontab of $cfg_mirror_user (adjust frequency on number of repos):"
142 echo "*/30 * * * * /usr/bin/nice -n 18 $cfg_basedir/jobd/jobd.sh -q --all-once"
145 echo "*** Setting up repository root..."
146 mkdir -p "$cfg_reporoot" "$cfg_reporoot-recyclebin"
147 if [ "$cfg_owning_group" ]; then
148 chgrp "$cfg_owning_group" "$cfg_reporoot" || echo "WARNING: Cannot chgrp $cfg_owning_group $cfg_reporoot"
149 chgrp "$cfg_owning_group" "$cfg_reporoot-recyclebin" || echo "WARNING: Cannot chgrp $cfg_owning_group $cfg_reporoot-recyclebin"
151 chmod 02775 "$cfg_reporoot" || echo "WARNING: Cannot chmod $cfg_reporoot properly"
152 chmod 02775 "$cfg_reporoot-recyclebin" || echo "WARNING: Cannot chmod $cfg_reporoot-recyclebin properly"
155 if [ -n "$cfg_chrooted" ]; then
156 echo "*** Setting up chroot jail for pushing..."
157 if [ "$(id -u)" -eq 0 ]; then
158 ./jailsetup.sh
159 else
160 echo "WARNING: Skipping jail setup, not root"
165 echo "*** Setting up jail configuration (project database)..."
166 [ "$(id -u)" -eq 0 ] || ./jailsetup.sh dbonly
167 mkdir -p "$cfg_chroot" "$cfg_chroot/etc"
168 touch "$cfg_chroot/etc/passwd" "$cfg_chroot/etc/group"
169 chown "$cfg_mirror_user""$owngroup" "$cfg_chroot/etc" ||
170 echo "WARNING: Cannot chown $cfg_mirror_user$owngroup $cfg_chroot/etc"
171 chown "$cfg_cgi_user""$owngroup" "$cfg_chroot/etc/passwd" "$cfg_chroot/etc/group" ||
172 echo "WARNING: Cannot chown $cfg_cgi_user$owngroup the files"
173 chmod g+w "$cfg_chroot/etc/passwd" "$cfg_chroot/etc/group" ||
174 echo "WARNING: Cannot chmod g+w the etc/passwd and/or etc/group files"
175 chmod 02775 "$cfg_chroot/etc" || echo "WARNING: Cannot chmod 02775 $cfg_chroot/etc"
177 echo "*** Setting up gitweb from git.git..."
178 if [ ! -f git.git/Makefile ]; then
179 echo "ERROR: git.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
180 exit 1
182 mkdir -p "$cfg_webroot" "$cfg_cgiroot"
183 (cd git.git && "$MAKE" --no-print-directory --quiet NO_SUBDIR=: bindir="$(dirname "$cfg_git_bin")" gitweb && \
184 chown_make gitweb && \
185 cp gitweb/gitweb.cgi "$cfg_cgiroot" && \
186 cp gitweb/static/*.png gitweb/static/*.css gitweb/static/*.js "$cfg_webroot")
189 echo "*** Setting up git-browser from git-browser.git..."
190 if [ ! -f git-browser.git/git-browser.cgi ]; then
191 echo "ERROR: git-browser.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
192 exit 1
194 mkdir -p "$cfg_webroot"/git-browser "$cfg_cgiroot"
195 (cd git-browser.git && cp git-browser.cgi "$cfg_cgiroot" \
196 && cp -r *.html *.js *.css js.lib JSON "$cfg_webroot"/git-browser)
197 ln -sf "$cfg_webroot/git-browser/JSON" "$cfg_cgiroot"
198 cat >"$cfg_cgiroot"/git-browser.conf <<EOT
199 gitbin: $cfg_git_bin
200 warehouse: $cfg_reporoot
202 cat >"$cfg_webroot"/git-browser/GitConfig.js <<EOT
203 cfg_gitweb_url="$cfg_gitweburl/"
204 cfg_browsercgi_url="$cfg_webadmurl/git-browser.cgi"
208 echo "*** Setting up darcs-fast-export from bzr-fastimport.git..."
209 if [ ! -d bzr-fastimport.git/exporters/darcs/ ]; then
210 echo "ERROR: bzr-fastimport.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
211 exit 1
213 mkdir -p "$cfg_basedir"/bin
214 cp bzr-fastimport.git/exporters/darcs/darcs-fast-export "$cfg_basedir"/bin
217 echo "*** Setting up hg-fast-export from fast-export.git..."
218 if [ ! -f fast-export.git/hg-fast-export.py -o ! -f fast-export.git/hg2git.py ]; then
219 echo "ERROR: fast-export.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
220 exit 1
222 mkdir -p "$cfg_basedir"/bin
223 cp fast-export.git/hg-fast-export.py fast-export.git/hg2git.py "$cfg_basedir"/bin
226 echo "*** Setting up our part of the website..."
227 mkdir -p "$cfg_webroot" "$cfg_cgiroot"
228 cp cgi/*.cgi gitweb/gitweb_config.perl "$cfg_cgiroot"
229 rm -f "$cfg_cgiroot"/authrequired.cgi
230 [ -z "$cfg_httpspushurl" ] || cp "$cfg_basedir"/bin/authrequired.cgi "$cfg_cgiroot"
231 [ -n "$cfg_httpspushurl" ] || rm -f "$cfg_cgiroot"/usercert.cgi
232 ln -fs "$cfg_basedir"/Girocco "$cfg_cgiroot"
233 [ -z "$cfg_webreporoot" ] || { rm -f "$cfg_webreporoot" && ln -s "$cfg_reporoot" "$cfg_webreporoot"; }
234 if [ -z "$cfg_httpspushurl" ]; then
235 grep -v 'rootcert[.]html' gitweb/indextext.html > "$cfg_webroot/indextext.html"
236 else
237 cp gitweb/indextext.html "$cfg_webroot"
239 mv "$cfg_basedir"/html/*.css "$cfg_basedir"/html/*.js "$cfg_webroot"
240 cp mootools.js "$cfg_webroot"
241 cp htaccess "$cfg_webroot/.htaccess"
242 cp git-favicon.ico "$cfg_webroot/favicon.ico"
243 cp robots.txt "$cfg_webroot"
244 cat gitweb/gitweb.css >>"$cfg_webroot"/gitweb.css
247 if [ -n "$cfg_httpspushurl" ]; then
248 echo "*** Setting up SSL certificates..."
249 bits=2048
250 if [ "$cfg_rsakeylength" -gt "$bits" ] 2>/dev/null; then
251 bits="$cfg_rsakeylength"
253 mkdir -p "$cfg_certsdir"
254 [ -d "$cfg_certsdir" ]
255 wwwcertcn=
256 if [ -e "$cfg_certsdir/girocco_www_crt.pem" ]; then
257 wwwcertcn="$( \
258 openssl x509 -in "$cfg_certsdir/girocco_www_crt.pem" -noout -subject | \
259 sed -e 's,[^/]*,,' \
262 needroot=
263 [ -e "$cfg_certsdir/girocco_client_crt.pem" -a \
264 -e "$cfg_certsdir/girocco_client_key.pem" -a \
265 -e "$cfg_certsdir/girocco_www_key.pem" -a \
266 -e "$cfg_certsdir/girocco_www_crt.pem" -a "$wwwcertcn" = "/CN=$cfg_httpsdnsname" -a \
267 -e "$cfg_certsdir/girocco_root_crt.pem" ] || needroot=1
268 if [ -n "$needroot" -a ! -e "$cfg_certsdir/girocco_root_key.pem" ]; then
269 rm -f "$cfg_certsdir/girocco_root_crt.pem" "$cfg_certsdir/girocco_root_key.pem"
270 openssl genrsa -f4 -out "$cfg_certsdir/girocco_root_key.pem" $bits
271 chmod 0600 "$cfg_certsdir/girocco_root_key.pem"
272 rm -f "$cfg_certsdir/girocco_root_crt.pem"
273 echo "Created new root key"
275 if [ ! -e "$cfg_certsdir/girocco_root_crt.pem" ]; then
276 ezcert.git/CACreateCert --root --key "$cfg_certsdir/girocco_root_key.pem" \
277 --out "$cfg_certsdir/girocco_root_crt.pem" "girocco $cfg_nickname root certificate"
278 rm -f "$cfg_certsdir/girocco_www_crt.pem" "$cfg_certsdir/girocco_www_chain.pem"
279 rm -f "$cfg_certsdir/girocco_client_crt.pem" "$cfg_certsdir/girocco_client_suffix.pem"
280 rm -f "$cfg_certsdir/girocco_mob_user_crt.pem"
281 rm -f "$cfg_chroot/etc/sshcerts"/*.pem
282 echo "Created new root certificate"
284 if [ ! -e "$cfg_certsdir/girocco_www_key.pem" ]; then
285 openssl genrsa -f4 -out "$cfg_certsdir/girocco_www_key.pem" $bits
286 chmod 0600 "$cfg_certsdir/girocco_www_key.pem"
287 rm -f "$cfg_certsdir/girocco_www_crt.pem"
288 echo "Created new www key"
290 if [ ! -e "$cfg_certsdir/girocco_www_crt.pem" -o "$wwwcertcn" != "/CN=$cfg_httpsdnsname" ]; then
291 openssl rsa -in "$cfg_certsdir/girocco_www_key.pem" -pubout |
292 ezcert.git/CACreateCert --server --key "$cfg_certsdir/girocco_root_key.pem" \
293 --cert "$cfg_certsdir/girocco_root_crt.pem" \
294 --out "$cfg_certsdir/girocco_www_crt.pem" "$cfg_httpsdnsname"
295 echo "Created www certificate"
297 if [ ! -e "$cfg_certsdir/girocco_www_chain.pem" ]; then
298 cat "$cfg_certsdir/girocco_root_crt.pem" > "$cfg_certsdir/girocco_www_chain.pem"
299 echo "Created www certificate chain file"
301 if [ ! -e "$cfg_certsdir/girocco_client_key.pem" ]; then
302 openssl genrsa -f4 -out "$cfg_certsdir/girocco_client_key.pem" $bits
303 chmod 0640 "$cfg_certsdir/girocco_client_key.pem"
304 rm -f "$cfg_certsdir/girocco_client_crt.pem"
305 echo "Created new client key"
307 if [ ! -e "$cfg_certsdir/girocco_client_crt.pem" ]; then
308 openssl rsa -in "$cfg_certsdir/girocco_client_key.pem" -pubout |
309 ezcert.git/CACreateCert --subca --key "$cfg_certsdir/girocco_root_key.pem" \
310 --cert "$cfg_certsdir/girocco_root_crt.pem" \
311 --out "$cfg_certsdir/girocco_client_crt.pem" "girocco $cfg_nickname client authority"
312 rm -f "$cfg_certsdir/girocco_client_suffix.pem"
313 rm -f "$cfg_certsdir/girocco_mob_user_crt.pem"
314 rm -f "$cfg_chroot/etc/sshcerts"/*.pem
315 echo "Created client certificate"
317 if [ ! -e "$cfg_certsdir/girocco_client_suffix.pem" ]; then
318 cat "$cfg_certsdir/girocco_client_crt.pem" > "$cfg_certsdir/girocco_client_suffix.pem"
319 echo "Created client certificate suffix file"
321 cat "$cfg_rootcert" > "$cfg_webroot/${cfg_nickname}_root_cert.pem"
322 if [ -n "$cfg_mob" ]; then
323 if [ ! -e "$cfg_certsdir/girocco_mob_user_key.pem" ]; then
324 openssl genrsa -f4 -out "$cfg_certsdir/girocco_mob_user_key.pem" $bits
325 chmod 0640 "$cfg_certsdir/girocco_client_key.pem"
326 rm -f "$cfg_certsdir/girocco_mob_user_crt.pem"
327 echo "Created new mob user key"
329 if [ ! -e "$cfg_certsdir/girocco_mob_user_crt.pem" ]; then
330 openssl rsa -in "$cfg_mobuserkey" -pubout |
331 ezcert.git/CACreateCert --client --key "$cfg_clientkey" \
332 --cert "$cfg_clientcert" \
333 --out "$cfg_certsdir/girocco_mob_user_crt.pem" 'mob'
334 echo "Created mob user client certificate"
336 cat "$cfg_mobuserkey" > "$cfg_webroot/${cfg_nickname}_mob_key.pem"
337 cat "$cfg_mobusercert" "$cfg_clientcertsuffix" > "$cfg_webroot/${cfg_nickname}_mob_user.pem"
338 else
339 rm -f "$cfg_webroot/${cfg_nickname}_mob_key.pem" "$cfg_webroot/${cfg_nickname}_mob_user.pem"
341 else
342 rm -f "$cfg_webroot/${cfg_nickname}_root_cert.pem"
343 rm -f "$cfg_webroot/${cfg_nickname}_mob_key.pem" "$cfg_webroot/${cfg_nickname}_mob_user.pem"
347 echo "*** Finalizing permissions..."
348 chown -R -h "$cfg_mirror_user""$owngroup" "$cfg_basedir" "$cfg_webroot" "$cfg_cgiroot"
349 [ -z "$cfg_httpspushurl" ] || chown -R -h "$cfg_mirror_user""$owngroup" "$cfg_certsdir"