summaryrefslogtreecommitdiffstats
path: root/bin/git-clone.sh
blob: 4a619c58a9163558c2cd644ce4d6f575a38dcce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

set -e

for DIRECTORY in \
	/srv/local/bin /srv/local/web \
	/srv/data/*/bin /srv/data/*/web \
	/srv/*/bin /srv/*/web
do
	if [ ! -e "${DIRECTORY}/.git/config" ]
	then
		continue
	fi

	URL="$(awk '/url = / { print $3 }' ${DIRECTORY}/.git/config)"

	if [ -z "${URL}" ]
	then
		continue
	fi

	git clone "${URL}" "${DIRECTORY}.tmp"

	cd "${DIRECTORY}.tmp"
	git submodule init
	git submodule update
	cd "${OLDPWD}"

	rm -rf "${DIRECTORY}"
	mv "${DIRECTORY}.tmp" "${DIRECTORY}"

	chown 1000:1000 "${DIRECTORY}" -R
done