Merge branch 'wip/doc-migration' into rorcz
[girocco.git] / toolbox / remove-inactive-projects.sh
blobb41ad11f061719a57ee17da864a5036c383d8753
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 -L . -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 "[$cfg_name] Automated project removal" $y <<-EOM
62 Hello,
64 I have removed your project '$x' from $cfg_name 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 $cfg_name in the future,
68 feel free to create the project again. If you experienced any technical
69 difficulties with publishing on $cfg_name, 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 $cfg_name!
78 (You may also contact our support team at <$cfg_admin> which will
79 probably get you faster answers.)
80 EOM
81 done <$OUT
82 echo " done."
84 exit
86 #for i in $(find -L . -name heads -type d); do [ "$(ls $i)" ] && continue; mv ${i%/refs/heads} "$cfg_reporoot/_recyclebin/"; done
87 printf "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 printf "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