-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathpflask-debuild
executable file
·152 lines (125 loc) · 4.59 KB
/
pflask-debuild
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
#!/bin/bash
#
# Build Debian packages inside Linux namespaces.
#
# Copyright (c) 2013, Alessandro Ghedini
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR
# CONTRIBUTORS 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.
set -e
export LANG=C
export LC_ALL=C
if [ -z "$PFLASK_ROOTCMD" ]; then
PFLASK_ROOTCMD="sudo -E"
fi
if [ -z "$DEBUILD_DPKG_BUILDPACKAGE_OPTS" ]; then
DEBUILD_DPKG_BUILDPACKAGE_OPTS=""
fi
if [ -z "$DEBUILD_LINTIAN" ]; then
DEBUILD_LINTIAN="yes"
fi
if [ -z "$DEBUILD_LINTIAN_OPTS" ]; then
DEBUILD_LINTIAN_OPTS="-IE --pedantic"
fi
if [ -f "$HOME/.devscripts" ]; then
source "$HOME/.devscripts"
fi
if [ -f "/etc/devscripts.conf" ]; then
source "/etc/devscripts.conf"
fi
if [ -z "${DIST}" ] && [ -r "debian/changelog" ]; then
DIST=$(dpkg-parsechangelog | awk '/^Distribution: / {print $2}')
fi
: ${DIST:="$(lsb_release --short --codename)"}
: ${ARCH:="$(dpkg --print-architecture)"}
NAME="$DIST-$ARCH"
BASEDIR="/var/cache/pflask/base-$NAME"
BUILDDIR=$(pwd)
PKGDIR=$(basename $BUILDDIR)
RESDIR=$(dirname $BUILDDIR)
TMPDIR="/mnt"
if [ -r "debian/changelog" ]; then
SRC=$(dpkg-parsechangelog | sed -rne 's,^Source: (.+).*,\1,p')
VER=$(dpkg-parsechangelog | sed -rne 's,^Version: ([0-9]:)*(.+).*,\2,p')
elif [ "$1" != "--create" ] && [ "$1" != "--update" ]; then
echo "E: Can't find 'debian/changelog'"
exit -1
fi
CHANGES_FILE="${SRC}_${VER}_${ARCH}.changes"
DSC_FILE="${SRC}_${VER}.dsc"
DEBIAN_FILE="${SRC}_${VER}.debian.tar"
DIFF_FILE="${SRC}_${VER}.diff.tar.gz"
LOG_FILE="${SRC}_${VER}.build"
PFLASK_TOOL="$PFLASK_ROOTCMD $(which pflask)"
APT_TOOL="apt-get --no-install-recommends -y --force-yes"
TOOLS_TOOL="$APT_TOOL install devscripts equivs fakeroot lintian"
BDEPS_TOOL="mk-build-deps -r -i debian/control -t '$APT_TOOL'"
BUILD_TOOL="dpkg-buildpackage -tc -rfakeroot $DEBUILD_DPKG_BUILDPACKAGE_OPTS"
LINT_TOOL="lintian --allow-root $DEBUILD_LINTIAN_OPTS ../$CHANGES_FILE"
CHOWN_TOOL="chown --from=root:root"
DSIGN_TOOL="debsign"
if [ "$1" != "--create" ] && [ ! -d "$BASEDIR" ]; then
echo "E: Missing base root directory '$BASEDIR'"
exit -1
fi
BUILD_CMD="$TOOLS_TOOL && $BDEPS_TOOL && $BUILD_TOOL; FAIL=\$?"
BUILD_CMD="$BUILD_CMD && $CHOWN_TOOL -R $UID:$UID $TMPDIR/$PKGDIR"
FILES="$CHANGES_FILE $DSC_FILE $DEBIAN_FILE.gz $DEBIAN_FILE.xz $DIFF_FILE"
if [ -r "debian/control" ]; then
for PKG in `dh_listpackages`;
do
FILES="$FILES ${PKG}_${VER}_${ARCH}.deb"
FILES="$FILES ${PKG}_${VER}_${ARCH}.udeb"
FILES="$FILES ${PKG}_${VER}_all.deb"
FILES="$FILES ${PKG}_${VER}_all.udeb"
done
elif [ "$1" != "--create" ] && [ "$1" != "--update" ]; then
echo "E: Can't find 'debian/control'"
exit -1
fi
for FILE in $FILES
do
BUILD_CMD="$BUILD_CMD && [ -f $TMPDIR/$FILE ] && $CHOWN_TOOL $UID:$UID $TMPDIR/$FILE || true"
done
BUILD_CMD="$BUILD_CMD && [ \$FAIL = 0 ]"
if [ "$DEBUILD_LINTIAN" = "yes" ]; then
BUILD_CMD="$BUILD_CMD && $LINT_TOOL"
fi
if [ "$1" = "--create" ]; then
shift
$PFLASK_ROOTCMD debootstrap \
--include=devscripts,equivs,fakeroot,lintian \
--arch=$ARCH --variant=buildd $DIST $BASEDIR $@
elif [ "$1" = "--update" ]; then
$PFLASK_TOOL --chroot $BASEDIR \
-- \
sh -c "$APT_TOOL update && $APT_TOOL dist-upgrade && $APT_TOOL autoremove --purge && $APT_TOOL autoclean"
else
$PFLASK_TOOL --keepenv --chroot $BASEDIR --ephemeral \
--mount "bind:$RESDIR:$TMPDIR" \
--chdir "/mnt/$PKGDIR" \
-- \
sh -c "$BUILD_CMD" | tee "../$LOG_FILE"
$DSIGN_TOOL "$RESDIR/$CHANGES_FILE"
fi