f00b9f6db39d831c1b119257878835ca4818122c
[girocco.git] / install.sh
blobf00b9f6db39d831c1b119257878835ca4818122c
1 #!/bin/sh
2 # The Girocco installation script
3 # We will OVERWRITE basedir!
5 set -e
7 # What Config should we use?
8 [ -n "$GIROCCO_CONF" ] || GIROCCO_CONF=Girocco::Config
9 echo "*** Initializing using $GIROCCO_CONF..."
11 # First run Girocco::Config consistency checks
12 perl -I. -M$GIROCCO_CONF -e ''
14 . ./shlib.sh
16 owngroup=""
17 [ -z "$cfg_owning_group" ] || owngroup=":$cfg_owning_group"
18 if [ -n "$cfg_httpspushurl" -a -z "$cfg_certsdir" ]; then
19 echo "ERROR: \$httpspushurl is set but \$certsdir is not!" >&2
20 echo "ERROR: perhaps you have an incorrect Config.pm?" >&2
21 exit 1
25 echo "*** Checking for compiled utilities..."
26 if [ ! -x src/can_user_push ]; then
27 echo "ERROR: src/can_user_push is not built! Did you _REALLY_ read INSTALL?" >&2
28 echo "ERROR: perhaps you forgot to run make?" >&2
29 exit 1
31 if [ ! -x src/getent ]; then
32 echo "ERROR: src/getent is not built! Did you _REALLY_ read INSTALL?" >&2
33 echo "ERROR: perhaps you forgot to run make?" >&2
34 exit 1
38 echo "*** Checking for ezcert..."
39 if [ ! -f ezcert.git/CACreateCert ]; then
40 echo "ERROR: ezcert.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
41 exit 1
45 echo "*** Checking for git..."
46 if [ ! -x "$cfg_git_bin" ]; then
47 echo "ERROR: $cfg_git_bin does not exist or is not executable" >&2
48 exit 1
50 if ! git_version="$("$cfg_git_bin" --version)"; then
51 echo "ERROR: $cfg_git_bin --version failed" >&2
52 exit 1
54 case "$git_version" in
55 "git version "*) :;;
57 echo "ERROR: '$cfg_git_bin --version' output does not start with 'git version '" >&2
58 exit 1
59 esac
62 echo "*** Setting up basedir..."
63 rm -fr "$cfg_basedir"
64 mkdir -p "$cfg_basedir"
65 cp -pR Girocco jobd taskd gitweb html jobs toolbox hooks apache.conf shlib.sh bin screen "$cfg_basedir"
66 cp -p src/can_user_push ezcert.git/CACreateCert "$cfg_basedir/bin"
67 [ -n "$cfg_httpspushurl" ] || rm -f "$cfg_basedir"/html/rootcert.html "$cfg_basedir"/html/httpspush.html
68 [ -n "$cfg_mob" ] || rm -f "$cfg_basedir"/html/mob.html
70 # Put the correct Config in place
71 [ "$GIROCCO_CONF" = "Girocco::Config" ] || cp "$(echo "$GIROCCO_CONF" | sed 's#::#/#g; s/$/.pm/')" "$cfg_basedir/Girocco/Config.pm"
74 echo "*** Preprocessing scripts..."
75 perl -I. -M$GIROCCO_CONF -i -p \
76 -e 's/(?<!")\@basedir\@/"$Girocco::Config::basedir"/g;' -e 's/(?<=")\@basedir\@/$Girocco::Config::basedir/g;' \
77 -e 's/\@reporoot\@/"$Girocco::Config::reporoot"/g;' -e 's/\@jailreporoot\@/"$Girocco::Config::jailreporoot"/g;' \
78 -e 's/\@webadmurl\@/"$Girocco::Config::webadmurl"/g;' -e 's/\@screen_acl_file\@/"$Girocco::Config::screen_acl_file"/g;' \
79 -e 's/\@mob\@/"$Girocco::Config::mob"/g;' "$cfg_basedir"/jobs/*.sh "$cfg_basedir"/jobd/*.sh \
80 "$cfg_basedir"/taskd/*.sh "$cfg_basedir"/gitweb/*.sh "$cfg_basedir"/shlib.sh "$cfg_basedir"/hooks/* \
81 "$cfg_basedir"/toolbox/* "$cfg_basedir"/bin/git-* "$cfg_basedir"/bin/create-* "$cfg_basedir"/screen/*
84 if [ -n "$cfg_mirror" ]; then
85 echo "--- Remember to start $cfg_basedir/taskd/taskd.pl"
87 echo "--- Also remember to either start $cfg_basedir/jobd/jobd.sh, or add this"
88 echo "--- to the crontab of $cfg_mirror_user (adjust frequency on number of repos):"
89 echo "*/30 * * * * /usr/bin/nice -n 18 $cfg_basedir/jobd/jobd.sh -q --all-once"
92 echo "*** Setting up repository root..."
93 mkdir -p "$cfg_reporoot" "$cfg_reporoot-recyclebin"
94 if [ "$cfg_owning_group" ]; then
95 chown :"$cfg_owning_group" "$cfg_reporoot" || echo "WARNING: Cannot chgrp $cfg_owning_group $cfg_reporoot"
96 chown :"$cfg_owning_group" "$cfg_reporoot-recyclebin" || echo "WARNING: Cannot chgrp $cfg_owning_group $cfg_reporoot-recyclebin"
98 chmod 02775 "$cfg_reporoot" || echo "WARNING: Cannot chmod $cfg_reporoot properly"
99 chmod 02775 "$cfg_reporoot-recyclebin" || echo "WARNING: Cannot chmod $cfg_reporoot-recyclebin properly"
102 if [ -n "$cfg_chrooted" ]; then
103 echo "*** Setting up chroot jail for pushing..."
104 if [ "$(id -u)" -eq 0 ]; then
105 ./jailsetup.sh
106 else
107 echo "WARNING: Skipping jail setup, not root"
112 echo "*** Setting up jail configuration (project database)..."
113 [ "$(id -u)" -eq 0 ] || ./jailsetup.sh dbonly
114 mkdir -p "$cfg_chroot" "$cfg_chroot/etc"
115 touch "$cfg_chroot/etc/passwd" "$cfg_chroot/etc/group"
116 chown "$cfg_mirror_user""$owngroup" "$cfg_chroot/etc" ||
117 echo "WARNING: Cannot chown $cfg_mirror_user$owngroup $cfg_chroot/etc"
118 chown "$cfg_cgi_user""$owngroup" "$cfg_chroot/etc/passwd" "$cfg_chroot/etc/group" ||
119 echo "WARNING: Cannot chown $cfg_cgi_user$owngroup the files"
120 chmod g+w "$cfg_chroot/etc/passwd" "$cfg_chroot/etc/group" ||
121 echo "WARNING: Cannot chmod g+w the etc/passwd and/or etc/group files"
122 chmod 02775 "$cfg_chroot/etc" || echo "WARNING: Cannot chmod 02775 $cfg_chroot/etc"
125 echo "*** Setting up gitweb from git.git..."
126 if [ ! -f git.git/Makefile ]; then
127 echo "ERROR: git.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
128 exit 1
130 mkdir -p "$cfg_webroot" "$cfg_cgiroot"
131 (cd git.git && make --quiet gitweb/gitweb.cgi && cp gitweb/gitweb.cgi "$cfg_cgiroot" \
132 && cp gitweb/*.png gitweb/*.css gitweb/*.js "$cfg_webroot")
135 echo "*** Setting up git-browser from git-browser.git..."
136 if [ ! -f git-browser.git/git-browser.cgi ]; then
137 echo "ERROR: git-browser.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
138 exit 1
140 mkdir -p "$cfg_webroot"/git-browser "$cfg_cgiroot"
141 (cd git-browser.git && cp git-browser.cgi "$cfg_cgiroot" \
142 && cp -r *.html *.js *.css js.lib/ JSON/ "$cfg_webroot"/git-browser)
143 ln -sf "$cfg_webroot/git-browser/JSON" "$cfg_cgiroot"
144 cat >"$cfg_cgiroot"/git-browser.conf <<EOT
145 gitbin: $cfg_git_bin
146 warehouse: $cfg_reporoot
148 cat >"$cfg_webroot"/git-browser/GitConfig.js <<EOT
149 cfg_gitweb_url="$cfg_gitweburl/"
150 cfg_browsercgi_url="$cfg_webadmurl/git-browser.cgi"
154 echo "*** Setting up darcs-fast-export from bzr-fastimport.git..."
155 if [ ! -d bzr-fastimport.git/exporters/darcs/ ]; then
156 echo "ERROR: bzr-fastimport.git is not checked out! Did you _REALLY_ read INSTALL?" >&2
157 exit 1
159 mkdir -p "$cfg_basedir"/bin
160 cp bzr-fastimport.git/exporters/darcs/darcs-fast-export "$cfg_basedir"/bin
163 echo "*** Setting up our part of the website..."
164 mkdir -p "$cfg_webroot" "$cfg_cgiroot"
165 cp cgi/*.cgi gitweb/gitweb_config.perl "$cfg_cgiroot"
166 [ -n "$cfg_httpspushurl" ] || rm -f "$cfg_cgiroot/usercert.cgi"
167 ln -fs "$cfg_basedir"/Girocco "$cfg_cgiroot"
168 [ -z "$cfg_webreporoot" ] || { rm -f "$cfg_webreporoot" && ln -s "$cfg_reporoot" "$cfg_webreporoot"; }
169 if [ -z "$cfg_httpspushurl" ]; then
170 grep -v 'rootcert[.]html' gitweb/indextext.html > "$cfg_webroot/indextext.html"
171 else
172 cp gitweb/indextext.html "$cfg_webroot"
174 mv "$cfg_basedir"/html/*.css "$cfg_basedir"/html/*.js "$cfg_webroot"
175 cp mootools.js "$cfg_webroot"
176 cp htaccess "$cfg_webroot/.htaccess"
177 cp git-favicon.ico "$cfg_webroot/favicon.ico"
178 cp robots.txt "$cfg_webroot"
179 cat gitweb/gitweb.css >>"$cfg_webroot"/gitweb.css
182 if [ -n "$cfg_httpspushurl" ]; then
183 echo "*** Setting up SSL certificates..."
184 mkdir -p "$cfg_certsdir"
185 [ -d "$cfg_certsdir" ]
186 wwwcertcn=
187 if [ -e "$cfg_certsdir/girocco_www_crt.pem" ]; then
188 wwwcertcn="$( \
189 openssl x509 -in "$cfg_certsdir/girocco_www_crt.pem" -noout -subject | \
190 sed -e 's,[^/]*,,' \
193 needroot=
194 [ -e "$cfg_certsdir/girocco_client_crt.pem" -a \
195 -e "$cfg_certsdir/girocco_client_key.pem" -a \
196 -e "$cfg_certsdir/girocco_www_key.pem" -a \
197 -e "$cfg_certsdir/girocco_www_crt.pem" -a "$wwwcertcn" = "/CN=$cfg_httpsdnsname" -a \
198 -e "$cfg_certsdir/girocco_root_crt.pem" ] || needroot=1
199 if [ -n "$needroot" -a ! -e "$cfg_certsdir/girocco_root_key.pem" ]; then
200 rm -f "$cfg_certsdir/girocco_root_crt.pem" "$cfg_certsdir/girocco_root_key.pem"
201 openssl genrsa -f4 -out "$cfg_certsdir/girocco_root_key.pem" 2048
202 chmod 0600 "$cfg_certsdir/girocco_root_key.pem"
203 rm -f "$cfg_certsdir/girocco_root_crt.pem"
204 echo "Created new root key"
206 if [ ! -e "$cfg_certsdir/girocco_root_crt.pem" ]; then
207 ezcert.git/CACreateCert --root --key "$cfg_certsdir/girocco_root_key.pem" \
208 --out "$cfg_certsdir/girocco_root_crt.pem" "girocco $cfg_nickname root certificate"
209 rm -f "$cfg_certsdir/girocco_www_crt.pem" "$cfg_certsdir/girocco_www_chain.pem"
210 rm -f "$cfg_certsdir/girocco_client_crt.pem" "$cfg_certsdir/girocco_client_suffix.pem"
211 rm -f "$cfg_certsdir/girocco_mob_user_crt.pem"
212 rm -f "$cfg_chroot/etc/sshcerts"/*.pem
213 echo "Created new root certificate"
215 if [ ! -e "$cfg_certsdir/girocco_www_key.pem" ]; then
216 openssl genrsa -f4 -out "$cfg_certsdir/girocco_www_key.pem" 2048
217 chmod 0600 "$cfg_certsdir/girocco_www_key.pem"
218 rm -f "$cfg_certsdir/girocco_www_crt.pem"
219 echo "Created new www key"
221 if [ ! -e "$cfg_certsdir/girocco_www_crt.pem" -o "$wwwcertcn" != "/CN=$cfg_httpsdnsname" ]; then
222 openssl rsa -in "$cfg_certsdir/girocco_www_key.pem" -pubout |
223 ezcert.git/CACreateCert --server --key "$cfg_certsdir/girocco_root_key.pem" \
224 --cert "$cfg_certsdir/girocco_root_crt.pem" \
225 --out "$cfg_certsdir/girocco_www_crt.pem" "$cfg_httpsdnsname"
226 echo "Created www certificate"
228 if [ ! -e "$cfg_certsdir/girocco_www_chain.pem" ]; then
229 cat "$cfg_certsdir/girocco_root_crt.pem" > "$cfg_certsdir/girocco_www_chain.pem"
230 echo "Created www certificate chain file"
232 if [ ! -e "$cfg_certsdir/girocco_client_key.pem" ]; then
233 openssl genrsa -f4 -out "$cfg_certsdir/girocco_client_key.pem" 2048
234 chmod 0640 "$cfg_certsdir/girocco_client_key.pem"
235 rm -f "$cfg_certsdir/girocco_client_crt.pem"
236 echo "Created new client key"
238 if [ ! -e "$cfg_certsdir/girocco_client_crt.pem" ]; then
239 openssl rsa -in "$cfg_certsdir/girocco_client_key.pem" -pubout |
240 ezcert.git/CACreateCert --subca --key "$cfg_certsdir/girocco_root_key.pem" \
241 --cert "$cfg_certsdir/girocco_root_crt.pem" \
242 --out "$cfg_certsdir/girocco_client_crt.pem" "girocco $cfg_nickname client authority"
243 rm -f "$cfg_certsdir/girocco_client_suffix.pem"
244 rm -f "$cfg_certsdir/girocco_mob_user_crt.pem"
245 rm -f "$cfg_chroot/etc/sshcerts"/*.pem
246 echo "Created client certificate"
248 if [ ! -e "$cfg_certsdir/girocco_client_suffix.pem" ]; then
249 cat "$cfg_certsdir/girocco_client_crt.pem" > "$cfg_certsdir/girocco_client_suffix.pem"
250 echo "Created client certificate suffix file"
252 cat "$cfg_rootcert" > "$cfg_webroot/${cfg_nickname}_root_cert.pem"
253 if [ -n "$cfg_mob" ]; then
254 if [ ! -e "$cfg_certsdir/girocco_mob_user_key.pem" ]; then
255 openssl genrsa -f4 -out "$cfg_certsdir/girocco_mob_user_key.pem" 2048
256 chmod 0640 "$cfg_certsdir/girocco_client_key.pem"
257 rm -f "$cfg_certsdir/girocco_mob_user_crt.pem"
258 echo "Created new mob user key"
260 if [ ! -e "$cfg_certsdir/girocco_mob_user_crt.pem" ]; then
261 openssl rsa -in "$cfg_mobuserkey" -pubout |
262 ezcert.git/CACreateCert --client --key "$cfg_clientkey" \
263 --cert "$cfg_clientcert" \
264 --out "$cfg_certsdir/girocco_mob_user_crt.pem" 'mob'
265 echo "Created mob user client certificate"
267 cat "$cfg_mobuserkey" > "$cfg_webroot/${cfg_nickname}_mob_key.pem"
268 cat "$cfg_mobusercert" "$cfg_clientcertsuffix" > "$cfg_webroot/${cfg_nickname}_mob_user.pem"
269 else
270 rm -f "$cfg_webroot/${cfg_nickname}_mob_key.pem" "$cfg_webroot/${cfg_nickname}_mob_user.pem"
272 else
273 rm -f "$cfg_webroot/${cfg_nickname}_root_cert.pem"
274 rm -f "$cfg_webroot/${cfg_nickname}_mob_key.pem" "$cfg_webroot/${cfg_nickname}_mob_user.pem"
278 echo "*** Finalizing permissions..."
279 chown -R -h "$cfg_mirror_user""$owngroup" "$cfg_basedir" "$cfg_webroot" "$cfg_cgiroot"
280 [ -z "$cfg_httpspushurl" ] || chown -R -h "$cfg_mirror_user""$owngroup" "$cfg_certsdir"