Add some utility scripts to toolbox
[girocco.git] / taskd / clone.sh
blob14015a38f766ba06fd05673317322be9103c2e81
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 --prefix=svn-origin/ "$svnurl"
29 # ask git-svn to store branches under svn-origin/heads/* instead of svn-origin/*
30 GIT_DIR=. git config svn-remote.svn.branches \
31 "$(git config --get svn-remote.svn.branches | \
32 sed 's|:refs/remotes/svn-origin/\*$|:refs/remotes/svn-origin/heads/*|')"
33 GIT_DIR=. git svn fetch
34 # Neat Trick suggested by Miklos Vajna
35 GIT_DIR=. git config remote.origin.url .
36 GIT_DIR=. git config remote.origin.fetch '+refs/remotes/svn-origin/heads/*:refs/heads/*'
37 GIT_DIR=. git config --add remote.origin.fetch '+refs/remotes/svn-origin/trunk:refs/heads/master'
38 GIT_DIR=. git config --add remote.origin.fetch '+refs/remotes/svn-origin/tags/*:refs/tags/*'
39 GIT_DIR=. git fetch
41 darcs://*)
42 httpurl="${url/darcs:\/\//http://}"
43 "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks "$httpurl" | \
44 git fast-import --export-marks=$(pwd)/gfi-marks
45 # This is here because by default only the exit code of
46 # git fast-import is checked
47 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
49 bzr://*)
50 # we just remove bzr:// here, a typical bzr url is just
51 # "lp:foo"
52 bzrurl="${url#bzr://}"
53 bzr fast-export --export-marks=$(pwd)/bfe-marks "$bzrurl" | \
54 git fast-import --export-marks=$(pwd)/gfi-marks
55 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
58 git remote rm origin >/dev/null 2>&1 || :
59 git remote add --mirror origin "$url"
60 GIT_SSL_NO_VERIFY=1 git remote update
61 git remote prune origin
63 esac
65 # The rest
66 echo "Final touches..."
67 git update-server-info
68 trap "" EXIT
69 mail -s "[$cfg_name] $proj clone completed" "$mail,$cfg_admin" <<EOT
70 Congratulations! The clone of project $proj just completed.
72 * Source URL: $url
73 * GitWeb interface: $cfg_gitweburl/$projdir
74 * Project settings: $cfg_webadmurl/editproj.cgi?name=$proj
76 Have a lot of fun.
77 EOT
79 echo "Mirroring finished successfuly!"
80 rm .clone_in_progress
81 echo "@OVER@"