Support web removal of users
[girocco.git] / taskd / clone.sh
blob3dc324dd271baecb2f4a20034492758123707a8b
1 #!/bin/bash
3 # Invoked from taskd/taskd.pl
5 . @basedir@/shlib.sh
7 set -e
9 projdir="$1"
10 proj="${projdir%.git}"
12 cd "$cfg_reporoot/$projdir"
13 trap "echo '@OVER@'; touch .clone_failed" EXIT
14 url="$(config_get baseurl)"
16 if [ "$cfg_project_owners" = "source" ]; then
17 config_set owner "$(stat -c %U "$url" 2>/dev/null)"
20 mail="$(config_get owner)"
22 # Initial mirror
23 echo "Initiating mirroring..."
24 case "$url" in
25 svn://* | svn+http://* | svn+https://*)
26 # we just remove svn+ here, so svn+http://... becomes http://...
27 svnurl="${url#svn+}"
28 GIT_DIR=. git svn init -s "$svnurl"
29 # ask git-svn to store everything in the normal non-remote locations
30 GIT_DIR=. git config svn-remote.svn.fetch 'trunk:refs/heads/master'
31 GIT_DIR=. git config svn-remote.svn.branches 'branches/*:refs/heads/*'
32 GIT_DIR=. git config svn-remote.svn.tags 'tags/*:refs/tags/*'
33 # look for additional non-standard directories to fetch
34 # check for standard layout at the same time
35 foundstd=
36 foundfile=
37 { svn ls "$svnurl" 2>/dev/null || :; } | \
38 { while read file; do case $file in
39 # skip the already-handled standard ones and any with a space or tab
40 *' '*|*' '*) :;;
41 trunk/|branches/|tags/) foundstd=1;;
42 # only fetch extra directories from the $svnurl root (not any files)
43 *?/) GIT_DIR=. git config --add svn-remote.svn.fetch "${file%/}:refs/heads/${file%/}";;
44 *?) foundfile=1;;
45 esac; done
46 # if files found and no standard directories present use a simpler layout
47 if [ -z "$foundstd" ] && [ -n "$foundfile" ]; then
48 GIT_DIR=. git config --unset svn-remote.svn.branches
49 GIT_DIR=. git config --unset svn-remote.svn.tags
50 GIT_DIR=. git config --replace-all svn-remote.svn.fetch ':refs/heads/master'
51 fi; }
52 GIT_DIR=. git svn fetch --quiet
53 # git svn does not preserve group permissions in the svn subdirectory
54 chmod -R ug+rw,o+r svn
56 darcs://*)
57 httpurl="${url/darcs:\/\//http://}"
58 "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks "$httpurl" | \
59 git fast-import --export-marks=$(pwd)/gfi-marks
60 # This is here because by default only the exit code of
61 # git fast-import is checked
62 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
64 bzr://*)
65 # we just remove bzr:// here, a typical bzr url is just
66 # "lp:foo"
67 bzrurl="${url#bzr://}"
68 bzr fast-export --export-marks=$(pwd)/bfe-marks "$bzrurl" | \
69 git fast-import --export-marks=$(pwd)/gfi-marks
70 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
73 git remote rm origin >/dev/null 2>&1 || :
74 git remote add --mirror origin "$url"
75 GIT_SSL_NO_VERIFY=1 git remote update
76 git remote prune origin
78 esac
80 # The rest
81 echo "Final touches..."
82 git update-server-info
83 trap "" EXIT
84 mail -s "[$cfg_name] $proj clone completed" "$mail,$cfg_admin" <<EOT
85 Congratulations! The clone of project $proj just completed.
87 * Source URL: $url
88 * GitWeb interface: $cfg_gitweburl/$projdir
89 * Project settings: $cfg_webadmurl/editproj.cgi?name=$proj
91 Have a lot of fun.
92 EOT
94 echo "Mirroring finished successfuly!"
95 rm .clone_in_progress
96 echo "@OVER@"