3
# ----------------------------------------------------------------------
5
# ----------------------------------------------------------------------
7
# - set TRASH_CAN in the rc if you don't like the default. It should be
8
# relative to GL_REPO_BASE or an absolute value. It should also be on the
9
# same filesystem as GL_REPO_BASE, otherwise the 'mv' will take too long.
11
# - you could set TRASH_SUFFIX also but I recomend you leave it as it is
13
# - run a cron job to delete old repos based on age (the TRASH_SUFFIX has a
14
# timestamp); your choice how/how often you do that
16
# - you can completely disable the 'rm' command by setting an rc variable
17
# called D_DISABLE_RM to "1".
18
# ----------------------------------------------------------------------
20
# ----------------------------------------------------------------------
21
# Usage: ssh git@host D <subcommand> <argument>
23
# The whimsically named "D" command deletes repos ("D" is a counterpart to the
24
# "C" permission which lets you create repos. Which also means that, just
25
# like "C", it only works for wild repos).
27
# There are two kinds of deletions: 'rm' removes a repo completely, while
28
# 'trash' moves it to a trashcan which can be recovered later (upto a time
29
# limit that your admin will tell you).
31
# The 'rm', 'lock', and 'unlock' subcommands:
32
# Initially, all repos are "locked" against 'rm'. The correct sequence is
33
# ssh git@host D unlock repo
34
# ssh git@host D rm repo
35
# Since the initial condition is always locked, the "lock" command is
36
# rarely used but it is there if you want it.
38
# The 'trash', 'list-trash', and 'restore' subcommands:
39
# You can 'trash' a repo, which moves it to a special place:
40
# ssh git@host D trash repo
41
# You can then 'list-trash'
42
# ssh git@host D list-trash
43
# which prints something like
44
# repo/2012-04-11_05:58:51
45
# allowing you to restore by saying
46
# ssh git@host D restore repo/2012-04-11_05:58:51
48
die() { echo "$@" >&2; exit 1; }
49
usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }
51
[ "$1" = "-h" ] && usage
52
[ "$1" != "list-trash" ] && [ -z "$2" ] && usage
53
[ -z "$GL_USER" ] && die GL_USER not set
55
# ----------------------------------------------------------------------
58
# ----------------------------------------------------------------------
59
RB=`gitolite query-rc GL_REPO_BASE`; cd $RB
60
TRASH_CAN=`gitolite query-rc TRASH_CAN`; tcan=Trash; TRASH_CAN=${TRASH_CAN:-$tcan}
61
TRASH_SUFFIX=`gitolite query-rc TRASH_SUFFIX`; tsuf=`date +%Y-%m-%d_%H:%M:%S`; TRASH_SUFFIX=${TRASH_SUFFIX:-$tsuf}
62
# ----------------------------------------------------------------------
65
gitolite creator "$repo" $GL_USER || die You are not authorised
68
# ----------------------------------------------------------------------
73
gitolite query-rc -q D_DISABLE_RM && die "sorry, 'unlock' and 'rm' are disabled"
76
[ -f $repo.git/gl-rm-ok ] || die "'$repo' is locked!"
78
echo "'$repo' is now gone!"
80
elif [ "$cmd" = "lock" ]
84
rm -f $repo.git/gl-rm-ok
85
echo "'$repo' is now locked"
87
elif [ "$cmd" = "unlock" ]
90
gitolite query-rc -q D_DISABLE_RM && die "sorry, 'unlock' and 'rm' are disabled"
93
touch $repo.git/gl-rm-ok
94
echo "'$repo' is now unlocked"
96
elif [ "$cmd" = "trash" ]
100
mkdir -p $TRASH_CAN/$repo 2>/dev/null || die "failed creating directory in trashcan"
101
[ -d $TRASH_CAN/$repo/$TRASH_SUFFIX ] && die "try again in a few seconds..."
102
mv $repo.git $TRASH_CAN/$repo/$TRASH_SUFFIX
103
echo "'$repo' moved to trashcan"
105
elif [ "$cmd" = "list-trash" ]
108
cd $TRASH_CAN 2>/dev/null || exit 0
109
find . -name gl-creator | sort | while read t
113
[ "$owner" = "$GL_USER" ] && dirname $t
116
elif [ "$cmd" = "restore" ]
120
owner=`cat $TRASH_CAN/$repo/gl-creator 2>/dev/null`
121
[ "$owner" = "$GL_USER" ] || die "'$repo' is not yours!"
124
realrepo=`dirname $repo`
125
[ -d $RB/$realrepo.git ] && die "'$realrepo' already exists"
126
mv $repo $RB/$realrepo.git
127
echo "'$repo' restored to '$realrepo'"
130
die "unknown subcommand '$cmd'"