$mqueuedir now stores $proj.git dirs instead of just $proj dirs
[girocco.git] / mirroring / clone.sh
blob358741249aa518c0f6885b673a20e25753e0f5b5
1 #!/bin/bash
3 . @basedir@/shlib.sh
5 set -e
7 projdir="$1"
8 proj="${projdir#.git}"
9 queuedir="$(pwd)"
11 bang_setup
12 bang_action="clone"
13 bang_trap() {
14 # This removes any remnants from "$cfg_reporoot"/$projdir _and_ gets rid
15 # of the group record.
16 perl -I@basedir@ -MGirocco::Project -e 'Girocco::Project->ghost('"'$proj'"')->delete;'
17 cd "$queuedir" && rm -rf "$projdir"/* "$projdir"/.banged && rmdir -p "$projdir"
20 cd "$projdir"
21 url="$(cat base_url)"
22 mail="$(cat owner)"
24 # First, the boring clone itself
25 ref=()
26 if [ -s objects/info/alternates ]; then
27 ref=(--reference "$(cat objects/info/alternates | sed 's#/objects$##')")
29 bang git clone "${ref[@]}" --bare "$url" repodir
31 # Double-check that we aren't going to overwrite anything existing
32 ! [ -d "$cfg_reporoot/$projdir" ]
34 # Set up fork container if necessary
35 lproj="$(echo "$proj" | sed 's/^\(.*\/\)\(.*\)/\1/')"
36 if [ z"$lproj" != z"$proj" ]; then
37 bang mkdir -m 0775 -p "$cfg_reporoot/$lproj"
40 # Move us into our new home
41 bang mv repodir "$cfg_reporoot/$projdir.git"
42 bang mv base_url ctags owner description homepage README.html "$cfg_reporoot/$projdir.git/"
44 # Reconfigure
45 bang git --git-dir="$cfg_reporoot/$projdir.git" config --bool --add mirror.allowed true
46 bang git --git-dir="$cfg_reporoot/$projdir.git" update-server-info
48 # Clean up the queue
49 cd "$queuedir" && rm -rf "$projdir"/* "$projdir"/.banged && rmdir -p "$projdir"
50 # NO bang BELOW THIS POINT! rm -r depends on cwd.
52 mail -s "[$cfg_name] $proj clone completed" "$mail,$cfg_admin" <<EOT
53 Congratulations! The clone of project $proj just completed.
55 * GitWeb interface: $cfg_gitweburl/$projdir
56 * Project settings: $cfg_webadmurl/editproj.cgi?name=$proj
58 Have a lot of fun.
59 EOT