summaryrefslogtreecommitdiff
path: root/libre/parabolaweb-utils/parabolaweb-download
blob: e124295d4a83c7747157adae62b9ffe88fb40b66 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

. /etc/conf.d/parabolaweb
. /usr/bin/libremessages

dir=$WEBDIR
repo=$GITURL
ref=$GITREF

cd_safe() {
	if ! cd "$1"; then
		error "$(gettext "Failed to change to directory %s")" "$1"
		plain "$(gettext "Aborting...")"
		exit 1
	fi
}

download_git() {
	if [[ ! -d "$dir/.git" ]] ; then
		msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git"
		if ! git clone "$repo" "$dir"; then
			error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
			plain "$(gettext "Aborting...")"
			exit 1
		fi
	else
		cd_safe "$dir"
		# Make sure we are fetching the right repo
		if [[ "$repo" != "$(git config --get remote.origin.url)"  ]] ; then
			error "$(gettext "%s is not a clone of %s")" "$dir" "$repo"
			plain "$(gettext "Aborting...")"
			exit 1
		fi
		msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git"
		if ! git pull origin "$ref"; then
			# only warn on failure to allow offline builds
			warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git"
		fi
	fi
}

main() {
	[[ -d "${dir%/*}" ]] || mkdir -p "${dir%/*}"
	download_git
}

main "$@"