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