summaryrefslogtreecommitdiff
path: root/db-functions
blob: 8111c6d432817605353b9a5dab17d047f62b028a (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash

# Random integrity things
[ "$UID" = "" ] && UID=$(uid)

if [ -z "$BASEDIR" ]; then
	BASEDIR="$(dirname $0)"
fi

if [ -f "$BASEDIR/config" ]; then
	. "$BASEDIR/config"
fi

# Useful functions
source_makepkg () {
	if [ -f "/etc/makepkg.conf" ]; then
		#Get some config info
		. /etc/makepkg.conf
	else
		echo "error: /etc/makepkg.conf does not exist!"
		exit 1
	fi
}

UMASK=""
set_umask () {
	[ "$UMASK" == "" ] && UMASK="$(umask)"
	umask 002
}

restore_umask () {
	umask $UMASK
}

repo_lock () { #repo_lock repo-name arch
	LOCKFILE="$TMPDIR/.repolock.$1.$2"
	if [ -f "$LOCKFILE" ]; then
		owner="$(/usr/bin/stat -c %U $LOCKFILE)"
		echo "error: db generation is already in progress (started by $owner)"
		exit 1
	else
		/bin/touch "$LOCKFILE"
		set_umask
	fi
}

repo_unlock () { #repo_unlock repo-name arch
	LOCKFILE="$TMPDIR/.repolock.$1.$2"
	if [ ! -f "$LOCKFILE" ]; then
		echo "error: repo lock doesn't exist... something went terribly wrong!"
	else
		rm -f "$LOCKFILE"
	fi
	restore_umask
}

# usage: _grep_pkginfo pkgfile pattern
_grep_pkginfo() {
	local _ret

	_ret="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 -E "$2" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')"
	echo "$_ret"
}


# Get the package base or name
getpkgbase() {
	local _base

	_base="$(_grep_pkginfo "$1" "^pkg(base|name)")"
	if [ -z "$_base" ]; then
		echo "ERROR: Package '$1' has no pkgbase or pkgname in the PKGINFO. Fail!"
		exit 1
	fi

	echo "$_base"
}

# Get the package name
getpkgname() {
	local _name

	_name="$(_grep_pkginfo "$1" "^pkgname")"
	if [ -z "$_name" ]; then
		echo "ERROR: Package '$1' has no pkgname in the PKGINFO. Fail!"
		exit 1
	fi

	echo "$_name"
}

# Get the pkgver-pkgrel of this package
getpkgver() {
	local _ver

	_ver="$(_grep_pkginfo "$1" "^pkgver")"
	if [ -z "$_ver" ]; then
		echo "ERROR: Package '$1' has no pkgver in the PKGINFO. Fail!"
		exit 1
	fi

	echo "$_ver"
}

check_pkg_arch () { #check_pkg_arch pkgfile arch
	local _arch
	_arch="$(_grep_pkginfo "$1" "^arch")"

	if [ -z "$_arch" ]; then
		echo "ERROR: Package '$1' has no arch in the PKGINFO. Fail!"
		return 1
	fi
	if [ "$_arch" = "$2" ]; then
		return 0
	else
		return 1
	fi
}

get_svnpath () { #get_svnpath reponame
	local var
	local repopath
	var="\$SVNREPO_${1}"

	eval repopath=${var}
	if [ -z "$repopath" ]; then
		echo "ERROR: SVN path not defined for '${1}'" >&2
		echo "       Please check SVNREPO_${1} config setting" >&2
	fi
	
	echo "$repopath"
}


# vim: set ts=4 sw=4 noet ft=sh: