Add very brief mention of license in README
[girocco.git] / toolbox / remove-inactive-projects.sh
blob347cb103dbd78fc796e7c7024a931b301300cd8c
1 #!/bin/bash
2 # Checking for inactive projects (empty repositories)
4 echo "Not ready for usage yet; have to figure out locking and check conditions --jast"
5 exit 99
7 PRETEND=
8 OUT=/srv/git/.girocco-remove-list
9 if [ "$1" = "-n" ]; then
10 shift
11 PRETEND=yes
12 OUT=/dev/stdout
15 if [ -z "$1" ]; then
16 cat <<-EOM
17 Dear person running this, please pass 'Your Name <email@address>' as the
18 first argument.
19 EOM
20 exit 1
23 if [ -z $PRETEND ]; then
24 {sackfd}>$OUT
25 flock -n $sackfd || {
26 echo "Another cleanup process is running; aborting!"
27 exit 1
31 cd /srv/git
33 NOW=`date +%s`
34 TOTAL=0
36 for i in $(find . -mindepth 3 -maxdepth 3 -name heads -type d); do
37 # any branches?
38 [ "$(ls $i)" ] && continue
39 fb="${i##*/}"; fb="${fb%.git}"
40 # any forks?
41 [ -d "$i/../../../$fb" ] && continue
42 [ -e "$i/../../packed-refs" ] && continue
43 # less than 60 days old?
44 [ $(($NOW - `stat -c %Y $i/../../branches`)) -le 5184000 ] && continue
45 echo "${i%/refs/heads} $(git --git-dir="$i/../.." config gitweb.owner)"
46 TOTAL=$(($TOTAL + 1))
47 done >$OUT
49 [ $PRETEND ] && exit
51 CURRENT=0
53 while read x y; do
54 CURRENT=$(($CURRENT + 1))
55 echo -en "\rSending notification mails [$CURRENT/$TOTAL]..."
57 continue
59 mail -s '[repo.or.cz] Automated project removal' $y <<-EOM
60 Hello,
62 I have removed your project '$x' from repo.or.cz since you set it up
63 quite some time ago and nothing has ever been pushed in (I run this job
64 once every few months and it removes all unused projects older than two
65 months). If you want to publish anything on repo.or.cz in the future,
66 feel free to create the project again. If you experienced any technical
67 difficulties with publishing on repo.or.cz, please let me know,
68 hopefully we can solve them together (sometimes I don't reply for some
69 time, in that case it's best to harass me again, and repeatedly ;-). In
70 case the automated check went wrong, the repository is still backed
71 up...
73 Thanks for using repo.or.cz!
76 (You can also contact our support team at <admin@repo.or.cz> which will
77 probably get you faster answers.)
78 EOM
79 done <$OUT
80 echo " done."
82 exit
84 #for i in $(find . -name heads -type d); do [ "$(ls $i)" ] && continue; mv ${i%/refs/heads} /srv/git-recyclebin/; done
85 echo -n "Moving repositories to recycle bin..."
86 while read x y; do
87 f="${x%/*}"
88 x="${x##*/}"
89 [ "$f" != "$x" ] || f=""
90 echo "$f .. $x"
91 mkdir -p /srv/git-recyclebin/$f
92 mv /srv/git/$f/$x /srv/git-recyclebin/$f
93 done <$OUT
94 echo " done."
96 echo -n "Deregistering projects..."
97 for i in `cut -d ' ' -f 1 $OUT`; do
98 echo $i
99 j=${i#./}
100 j=${j%.git}
101 perl -Icgi -MGirocco::Project -e 'Girocco::Project->ghost("'$j'", 0)->_group_remove()'
102 done
103 echo " done."
105 rm -f $OUT