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