configurable own for a git repo
[infrastructure.git] / scripts / git-check.sh
1 #!/bin/sh
2
3 MLIST="git@onelab.eu"
4
5 cd /git
6
7 gitwebfiles="git-favicon.png git-logo.png gitweb.cgi gitweb.css"
8
9 ########
10 gitwebpattern=""
11 for file in $gitwebfiles; do gitwebpattern="${gitwebpattern}|$file" ; done
12 gitwebpattern=$(echo "$gitwebpattern" | sed -e 's,|,,')
13
14 function missing_gitweb () {
15
16     echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx missing in gitweb (for web)"
17     for i in $gitwebfiles; do
18         echo -n "$i "
19         if [ -f ${i} ] ; then
20             echo -n "OK "
21         else
22             echo -n "MISSING.. " ; 
23         fi
24     done
25     echo ""
26
27 }
28
29
30 function fill_descriptions () {
31     echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx checking descriptions "
32     for arg in "$@" ; do
33         # accept args like plcapi or plcapi.git
34         b=$(basename $arg .git)
35         git=${b}.git
36         echo -n "$git "
37         grep -q Unnamed $git/description && { echo -n $i "Setting.. "; echo $b > $git/description ; }
38     done
39     echo ""
40 }
41
42 function update_server_info () {
43     echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx updating server info "
44     for arg in "$@" ; do
45         # accept args like plcapi or plcapi.git
46         b=$(basename $arg .git)
47         git=${b}.git
48         echo -n "$git "
49         cd $git
50         git update-server-info
51         cd - >& /dev/null
52     done
53     echo ""
54 }
55
56 function check_permissions () {
57     echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx checking permissions "
58     for arg in "$@" ; do
59         # accept args like plcapi or plcapi.git
60         b=$(basename $arg .git)
61         git=${b}.git
62         owner=root:onelab
63         if [ -f $git/owner ] ; then owner=$(cat $git/owner); fi
64         echo -n "$git ($owner) "
65         chown -R $owner $git
66         chmod -R g+w,o-w $git
67     done
68     echo ""
69 }
70
71 function check_configs () {
72     echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx checking config (upload*, hooks...) "
73     for arg in "$@" ; do
74         # accept args like plcapi or plcapi.git
75         b=$(basename $arg .git)
76         git=${b}.git
77         echo -n "$git "
78         cd $git 
79         git config core.bare true; echo -n "bare ";
80         git config core.sharedrepository >& /dev/null || { git config core.sharedrepository true; echo -n "sharedrepository "; }
81         git config daemon.uploadpack >& /dev/null || { git config daemon.uploadpack true; echo -n "uploadpack "; }
82         git config daemon.uploadarch >& /dev/null || { git config daemon.uploadarch true; echo -n "uploadarch "; }
83         (git config hooks.mailinglist|grep $MLIST) >& /dev/null || { git config hooks.mailinglist $MLIST; echo -n "mailinglist "; }
84         (git config hooks.announcelist|grep $MLIST) >& /dev/null || { git config hooks.announcelist $MLIST; echo -n "announcelist "; }
85         (git config hooks.envelopesender|grep $MLIST) >& /dev/null || { git config hooks.envelopesender $MLIST; echo -n "envelopesender "; }
86         git config hooks.emailprefix >& /dev/null || { git config hooks.emailprefix ''; echo -n "emailprefix "; }
87         cd - >& /dev/null
88     done
89     echo ""
90 }
91
92 function check_hooks () {
93     echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx checking hooks "
94     for arg in "$@" ; do
95         # accept args like plcapi or plcapi.git
96         b=$(basename $arg .git)
97         git=${b}.git
98         echo -n "$git "
99         # standard version is in /usr/share/doc/git-1.5.5.6/hooks/post-receive-email
100         (cd $git/hooks; cp -f /root/bin/post-receive-email-with-diffs post-receive; chmod 755 post-receive )
101     done
102     echo ""
103 }
104
105 # missing_gitweb
106 args="$@"
107 [[ -z "$args" ]] && args=$(ls -d *.git)
108 fill_descriptions $args
109 update_server_info $args
110 check_permissions $args
111 check_configs $args
112 check_hooks $args