File: debpear

package info (click to toggle)
debpear 0.5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch
  • size: 48 kB
  • sloc: sh: 238; makefile: 2
file content (309 lines) | stat: -rwxr-xr-x 9,297 bytes parent folder | download
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#!/bin/sh

# Copyright: (c) 2012, Thomas Goirand <zigo@debian.org>
# License: LGPL-2.1
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# .
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
# .
# You should have received a copy of the GNU Lesser General Public License along
# with this library; if not, write to the Free Software Foundation, Inc., 51
# Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# .
# On Debian systems, the complete text of the GNU Lesser General Public License
# (LGPL) may be found in /usr/share/common-licenses/LGPL-2.1

set -e

# Path to the pkg-php-tools script
PHPPKGINFO=/usr/bin/pkgtools

# Default values
DO_INSTALL=no
PEAR_CHANNEL=pear.php.net
BUILD_DIR=./build-area
VERBOSE=no

######################################
### EVALUATION OF INPUT PARAMETERS ###
######################################
print_usage () {
	echo "$0 [options] <pear-package-name>"
	echo "Options are:"
	echo "            Specify build dir: --build-dir|-b <build-dir>"
	echo "              Be more verbose: --verbose|-v"
	echo "         Specify PEAR channel: --channel|-c <alias-channel>"
	echo "              Specify tarball: --tarball|-t <tarball> --pkg-version|-pv <pkg-version>"
	echo "                               [--wget|-w <URL>]"
	echo "Install the resulting package: --install|-i"
}

echoIfVerbose () {
	if [ ${VERBOSE} = "yes" ] ; then
		echo ${1}
	fi
}

for i in $@ ; do
	case ${1} in
	"--channel"|"-c")
		if [ -z ${2} ] ; then
			echo "Please specify an alias of PEAR channel"
			print_usage
			exit 1
		fi
		if [ -z "`dpkg -L pear-channels | grep .alias/ | cut -d'/' -f7 | grep -w ^${2}.txt`" -a "${2}" != "pecl"  -a "${2}" != "pear" ] ; then
			echo "The ${2} channel not provided by pear-channels package."
			exit 1
		fi
		PEAR_CHANNEL=${2}
		shift
		shift
		;;
	"--tarball"|"-t")
		TARBALL=${2}
		if ! [ -f "${TARBALL}" -a "${5}" != "--wget" ] ; then
			if [ "${5}" != "--wget" -a "${5}" != "-w" ] ; then
				echo "Cannot find specified tarball file."
				print_usage
				exit 1
			fi
		fi
		if [ "${3}" != "--pkg-version" -a "${3}" != "-pv" ] ; then
			echo "Please specify a package version when using --tarball|-t"
			print_usage
			exit 1
		fi
		if [ -z "${4}" ] ; then
			echo "No package version specified after --pkg-version|-pv"
			print_usage
			exit 1
		fi
		VERSION_STRING="${4}"
		shift
		shift
		shift
		shift
		if [ "${1}" = "--wget" -o "${1}" = "-w" ] ; then
			WGET_URL=${2}
			shift
			shift
		fi
		;;
	"--build-dir"|"-b")
		BUILD_DIR=${2}
		shift
		shift
		;;
	"--install"|"-i")
		DO_INSTALL=yes
		shift
		;;
	"--verbose"|"-v")
		VERBOSE=yes
		shift
		;;
	*)
		;;
	esac
done

if [ $# != 1 ] ; then
	echo "No PEAR package given as parameter: exiting"
	print_usage
	exit 1
fi
PEAR_PKG_NAME=$1

if [ -z "${PEAR_PKG_NAME}" ] ; then
	echo "No PEAR package defined: exiting"
	print_usage
	exit 1
fi

###########################
### START OF THE SCRIPT ###
###########################
echoIfVerbose "debpear ===> Preparing build area in ${BUILD_DIR}"
DEB_PKG_NAME=`${PHPPKGINFO} phppear debianname ${PEAR_CHANNEL} ${PEAR_PKG_NAME}`

if ! [ -d "${BUILD_DIR}" ] ; then
	mkdir ${BUILD_DIR}
fi
if [ -n "${TARBALL}" ] ; then
	if [ -n "${WGET_URL}" ] ; then
		if ! [ -f ${TARBALL} ] ; then
			wget ${WGET_URL} -O ${TARBALL}
		fi
	fi
	cp ${TARBALL} ${BUILD_DIR}/${PEAR_PKG_NAME}-${VERSION_STRING}.tgz
fi
cd ${BUILD_DIR}

if [ -z "${TARBALL}" ] ; then
	if [ -z ${PEAR_CHANNEL} ] ; then
		pear download ${PEAR_PKG_NAME}
	elif [ "${PEAR_CHANNEL}" = "pecl" ] ; then
		pecl download ${PEAR_PKG_NAME}
	else
		pear download ${PEAR_CHANNEL}/${PEAR_PKG_NAME}
	fi
fi

### CALCULATION OF VERSIONS AND NAMES ###
DOWNLOADED_PEAR_PKG=`ls | grep ${PEAR_PKG_NAME}`
FILENAME_LEN=`echo ${DOWNLOADED_PEAR_PKG} | awk '{printf length($0)}'`
PEAR_PKG_NAME_LEN=`echo ${PEAR_PKG_NAME} | awk '{printf length($0)}'`
VERSION_START=$((PEAR_PKG_NAME_LEN + 2))
VERSION_LEN=$((${FILENAME_LEN} - ${PEAR_PKG_NAME_LEN} - 5))
VERSION_STRING=`echo ${DOWNLOADED_PEAR_PKG} | awk '{printf substr($0,'${VERSION_START}','${VERSION_LEN}')}'`
DEB_SRC_FOLDER="${DEB_PKG_NAME}-${VERSION_STRING}"
DEB_PKG_RESULT="${DEB_PKG_NAME}_${VERSION_STRING}-1_all.deb"
DEB_BIN_PKG_NAME=${DEB_PKG_NAME}

cp ${DOWNLOADED_PEAR_PKG} ${DEB_PKG_NAME}_${VERSION_STRING}.orig.tar.gz

if ! [ -d "${DEB_SRC_FOLDER}" ] ; then
	mkdir ${DEB_SRC_FOLDER}
fi

echo "debpear ===> Extracting orig tarball"
if [ ${VERBOSE} = "yes" ] ; then
	TAR_OPT="v"
fi
tar -C ${DEB_SRC_FOLDER} -zx${TAR_OPT}f ${DOWNLOADED_PEAR_PKG}

cd ${DEB_SRC_FOLDER}

### GATHERING PACKAGE INFORMATIONS ###

DEB_MAINTAINER="Debian PHP PEAR Maintainers <pkg-php-pear@lists.alioth.debian.org>"
DEB_BUILD_DEPENDS="debhelper (>= 9), pkg-php-tools"
DEB_DEPENDS="\${misc:Depends}, \${phppear:Debian-Depends}"
DEB_ARCH="all"
CHANNEL_URL=`${PHPPKGINFO} phppear channel .`
WATCH_URL="http://${CHANNEL_URL}/package/${PEAR_PKG_NAME}/download .*/${PEAR_PKG_NAME}-(.*).tgz"
HOMEPAGE="http://pear.php.net/package/${PEAR_PKG_NAME}"



if [ "${PEAR_CHANNEL}" != "pear.php.net" -a "${PEAR_CHANNEL}" != "pecl" ] ; then
	DEB_BUILD_DEPENDS="${DEB_BUILD_DEPENDS}, pear-channels"
	WATCH_URL="http://${CHANNEL_URL} .*/${PEAR_PKG_NAME}-(.*).tgz"
	HOMEPAGE="#http://${CHANNEL_URL}"
fi

if [ "${PEAR_CHANNEL}" = "pecl" ] ; then
	DEB_MAINTAINER="Debian PHP PECL Maintainers <pkg-php-pecl@lists.alioth.debian.org>"
	DEB_BUILD_DEPENDS="${DEB_BUILD_DEPENDS}, php-all-dev, dh-php"
	WITH_PHP="--with php"
	DEB_BIN_PKG_NAME=`echo ${DEB_PKG_NAME}`
	DEB_DEPENDS="${DEB_DEPENDS}, \${php:Depends}, \${shlibs:Depends}"
	DEB_ARCH="any"
	PECL_MOD_NAME=`echo ${DEB_BIN_PKG_NAME} | cut -d'-' -f2`
	WATCH_URL="http://${CHANNEL_URL}/package/${PEAR_PKG_NAME}/download .*/${PEAR_PKG_NAME}-(.*).tgz"
	HOMEPAGE="http://pecl.php.net/package/${PEAR_PKG_NAME}"
fi

#########################################
### GENERATION OF THE ./debian FOLDER ###
#########################################
echo "debpear ===> Building ${DEB_PKG_RESULT}"
mkdir -p debian/source
echo "3.0 (quilt)" >debian/source/format
echo "9" >debian/compat
if ! [ -f debian/changelog ] ; then
	EDITOR=touch dch --create --package ${DEB_PKG_NAME} --distribution unstable --urgency medium -v ${VERSION_STRING}-1
fi
echo "Source: ${DEB_PKG_NAME}
Section: php
Priority: optional
Maintainer: ${DEB_MAINTAINER}
Uploaders: ${DEBFULLNAME} <${DEBEMAIL}>
Build-Depends: ${DEB_BUILD_DEPENDS}
Standards-Version: 3.9.7
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-php/${DEB_PKG_NAME}.git
Vcs-Git: https://anonscm.debian.org/git/pkg-php/${DEB_PKG_NAME}.git
Homepage: ${HOMEPAGE}

Package: ${DEB_BIN_PKG_NAME}
Architecture: ${DEB_ARCH}
Depends: ${DEB_DEPENDS}
Recommends: \${phppear:Debian-Recommends}
Breaks: \${phppear:Debian-Breaks}
Description: \${phppear:summary}
 \${phppear:description}
" >debian/control

echo "Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ${PEAR_PKG_NAME}
Source: ${HOMEPAGE}

Files: *
Copyright: <please-fill>
License: <please-check>

Files: debian/*
Copyright: Generated by debpear
License: BSD-2-clause

License: BSD-2-clause
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 .
 1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.
 .
 2. Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.
 .
 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

">debian/copyright

echo "#!/usr/bin/make -f
%:
	dh \$@ --buildsystem=phppear --with phppear ${WITH_PHP}
" >debian/rules
chmod 0755 debian/rules

echo "version=3
${WATCH_URL}
" >debian/watch


if [ "${PEAR_CHANNEL}" = "pecl" ] ; then
	echo "extension=${PECL_MOD_NAME}.so" >debian/${PECL_MOD_NAME}.ini
	echo "mod debian/${PECL_MOD_NAME}.ini" >debian/${DEB_BIN_PKG_NAME}.php
fi

###############################
### BUILDING AND INSTALLING ###
###############################
dpkg-buildpackage
cd ..

if [ "${DO_INSTALL}" = "yes" ] ; then
	if ! [ `whoami` = "root" ] ; then
		sudo dpkg -i ${DEB_PKG_RESULT}
	else
		dpkg -i ${DEB_PKG_RESULT}
	fi
fi