summaryrefslogtreecommitdiff
path: root/common.sh
blob: d2fcb5fcdc0e80fe8bf97851b26e6fbfc2f0a728 (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
48
49
50
51
52
53
54
55
56
57
pkgrel=1
arch=(any)
pkgname=$(basename "$BUILDFILE" .PKGBUILD)

pkgver() {
	local oldpkgver oldpkgver_date oldpkgver_rel
	local newpkgver newpkgver_date
	oldpkgver="$pkgver"
	oldpkgver_date=${oldpkgver%%.*}
	oldpkgver_rel=${oldpkgver#${oldpkgver_date}}; oldpkgver_rel=${oldpkgver_rel#.}; oldpkgver_rel=${oldpkgver_rel:-0}
	newpkgver_date=$(date +%Y%m%d)
	# Handle doing multiple versions in the same day
	if [[ "$newpkgver_date" == "$oldpkgver_date" ]]; then
		declare -i newpkgver_rel=${oldpkgver_rel}+1
		newpkgver=${newpkgver_date}.${newpkgver_rel}
	else
		newpkgver=${newpkgver_date}
	fi
	echo $newpkgver
}

netctl-enable() (
	. "etc/netctl/$1"
	unit=netctl@"$(systemd-escape -- "$1")".service
	install -Dm644 /dev/stdin etc/systemd/system/"${unit}" <<EOF
.include /usr/lib/systemd/system/netctl@.service

[Unit]
Description=${Description}
BindsTo=sys-subsystem-net-devices-${Interface}.device
After=sys-subsystem-net-devices-${Interface}.device
EOF
	add-unit etc/systemd/system/multi-user.target.wants/"$unit"
)

add-unit() (
	install -dm755 "${1%/*}"
	base="$(sed 's/@[^.]*\./@./' <<<"${1##*/}")"
	srcs=(
		"etc/systemd/system/${1##*/}"
		"etc/systemd/system/$base"
		"usr/lib/systemd/system/$base"
	)
	for src in "${srcs[@]}"; do
		if test -f "$src"; then
			break
		fi
		if test -f "/$src"; then
			break
		fi
	done
	ln -s "/$src" "$1"
)

add-file() {
	install -Dm644 /dev/stdin "$@"
}