summaryrefslogtreecommitdiffstats
path: root/commitpkg.in
blob: 2216b541605e7c16429476f245303147607c15a9 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash

abort() {
	echo ${1:-'Cancelled'}
	exit 1
}

getpkgfile() {
	if [[ ${#} -ne 1 ]]; then
		echo 'ERROR: No canonical package found!' >&2
		exit 1
	elif [ ! -f "${1}" ]; then
		echo "ERROR: Package ${1} not found!" >&2
		exit 1
	fi

	echo ${1}
}

##
#  usage : get_full_version( $epoch, $pkgver, $pkgrel )
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
get_full_version() {
	if [[ $1 -eq 0 ]]; then
		# zero epoch case, don't include it in version
		echo $2-$3
	else
		echo $1:$2-$3
	fi
}

# Source makepkg.conf; fail if it is not found
if [ -r '/etc/makepkg.conf' ]; then
	source '/etc/makepkg.conf'
else
	abort '/etc/makepkg.conf not found!'
fi

# Source user-specific makepkg.conf overrides
if [ -r ~/.makepkg.conf ]; then
	. ~/.makepkg.conf
fi

cmd=${0##*/}

if [ ! -f PKGBUILD ]; then
	abort 'No PKGBUILD file'
fi

. PKGBUILD
pkgbase=${pkgbase:-$pkgname}

case "$cmd" in
	commitpkg)
		if [ $# -eq 0 ]; then
			abort 'usage: commitpkg <reponame> [-l limit] [-a arch] [commit message]'
		fi
		repo="$1"
		shift
		;;
	*pkg)
		repo="${cmd%pkg}"
		;;
	*)
		abort 'usage: commitpkg <reponame> [-l limit] [-a arch] [commit message]'
		;;
esac

case "$repo" in
	core|extra|testing|staging)
		server='gerolde.archlinux.org' ;;
	community*|multilib*)
		server='aur.archlinux.org' ;;
	*)
		server='gerolde.archlinux.org'
		echo "Non-standard repository $repo in use, defaulting to server $server" ;;
esac

# check if all local source files are under version control
for s in "${source[@]}"; do
	if [[ $s != *://* ]] && ! svn status -v "$s" | grep -q '^[ AMRX~]'; then
		abort "$s is not under version control"
	fi
done

# check if changelog and install files are under version control
for i in 'changelog' 'install'; do
	while read -r file; do
		# evaluate any bash variables used
		eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\"
		if ! svn status -v "${file}" | grep -q '^[ AMRX~]'; then
			abort "${file} is not under version control"
		fi
	done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD)
done

# see if any limit options were passed, we'll send them to rsync
rsyncopts=(-e ssh -p --chmod=ug=rw,o=r -c -h -L --progress --partial -y)
while getopts ':l:a:' flag; do
	case $flag in
		l) rsyncopts+=("--bwlimit=$2") ;;
		a) commit_arch=$2 ;;
		:) echo "option requires an argument -- '$OPTARG'" >&2
			exit 1 ;;
		\?) echo "invalid option -- '$OPTARG'" >&2
			exit 1 ;;
	esac
done
shift $(( OPTIND - 1 ))

if [ -n "$(svn status -q)" ]; then
	echo -n 'committing changes to trunk...'
	msgtemplate="upgpkg: $pkgbase $(get_full_version ${epoch:-0} $pkgver $pkgrel)"$'\n\n'
	if [ -n "$1" ]; then
		svn commit -q -m "${msgtemplate}${1}" || abort
	else
		msgfile="$(mktemp)"
		echo "$msgtemplate" > "$msgfile"
		if [ -n "$SVN_EDITOR" ]; then
			$SVN_EDITOR "$msgfile"
		elif [ -n "$VISUAL" ]; then
			$VISUAL "$msgfile"
		elif [ -n "$EDITOR" ]; then
			$EDITOR "$msgfile"
		else
			vi "$msgfile"
		fi
		[ -s "$msgfile" ] || abort
		svn commit -q -F "$msgfile" || abort
		unlink "$msgfile"
	fi
	echo 'done'
fi

declare -a uploads

for _arch in ${arch[@]}; do
	if [ -n "$commit_arch" ] && [ "${_arch}" != "$commit_arch" ]; then
		echo "skipping ${_arch}"
		continue
	fi

	for _pkgname in ${pkgname[@]}; do
		fullver=$(get_full_version ${epoch:-0} $pkgver $pkgrel)
		pkgfile=$(getpkgfile "$_pkgname-$fullver-${_arch}".pkg.tar.?z 2>/dev/null)
		pkgdestfile=$(getpkgfile "$PKGDEST/$_pkgname-$fullver-${_arch}".pkg.tar.?z 2>/dev/null)

		if [ -f "$pkgfile" ]; then
			pkgfile="./$pkgfile"
		elif [ -f "$pkgdestfile" ]; then
			pkgfile="$pkgdestfile"
		else
			echo "skipping ${_arch}"
			continue 2
		fi
		uploads+=("$pkgfile")

		sigfile="${pkgfile}.sig"
		if [[ $SIGNPKG == 'y' ]] && [ ! -f "${sigfile}" ]; then
			echo "Signing package ${pkgfile}..."
			if [[ -n $GPGKEY ]]; then
				SIGNWITHKEY="-u ${GPGKEY}"
			fi
			gpg --detach-sign --use-agent ${SIGNWITHKEY} "${pkgfile}" || abort
		fi
		if [ -f "${sigfile}" ]; then
			uploads+=("$sigfile")
		elif [[ $SIGNPKG == 'y' ]]; then
			abort "Signature ${pkgfile}.sig was not found"
		fi
	done
done

if [[ -n $commit_arch ]]; then
	archrelease "$repo-$commit_arch" || abort
else
	archrelease "${arch[@]/#/$repo-}" || abort
fi

if [[ ${#uploads[*]} -gt 0 ]]; then
	echo 'uploading all package and signature files'
	rsync "${rsyncopts[@]}" "${uploads[@]}" "$server:staging/$repo/" || abort
fi

if [ "${arch[*]}" == 'any' ]; then
	if [ -d ../repos/$repo-i686 -a -d ../repos/$repo-x86_64 ]; then
		pushd ../repos/ >/dev/null
		echo "removing $repo-i686 and $repo-x86_64..."
		svn rm $repo-i686
		svn rm $repo-x86_64
		svn commit -q -m "removed $repo-i686 and $repo-x86_64 for $pkgname"
		echo 'done'
		popd >/dev/null
	fi
else
	if [ -d ../repos/$repo-any ]; then
		pushd ../repos/ >/dev/null
		echo "removing $repo-any..."
		svn rm $repo-any
		svn commit -q -m "removed $repo-any for $pkgname"
		echo 'done'
		popd >/dev/null
	fi
fi