mirroring/clone.sh: Do not rely on pwd when determining $queuedir
[girocco/test-forks.git] / mirroring / clone.sh
blob1132b09e3033c8f04b1fe962c5987ba14c3569ae
1 #!/bin/bash
3 . @basedir@/shlib.sh
5 set -e
7 projdir="$1"
8 proj="${projdir#.git}"
9 queuedir="$cfg_mqueuedir"/cloning
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