-
Notifications
You must be signed in to change notification settings - Fork 79
/
recompile_local_debian_package.sh
95 lines (64 loc) · 2.55 KB
/
recompile_local_debian_package.sh
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
#!/bin/bash
cat <<EOF
========================================================================
One-step Debian package generation script.
========================================================================
This script takes a git-version-controlled tree hierarchy containing
a proper debian/ directory for package generation, does a temporary
clone and builds debian packages from it.
Added value :
* automatically generated a proper *.orig.tar.gz as required by debuild.
* make sure the build it not polluted by any local non-commited files
* keep the original tree hierarchy clean
This script should be generic enough to be used in other programe. It
might be confused by stray version names with strange or worse, evil,
characters, but if you name your package "little bobby tables" you
deserve to to all this by hand.
Written by Stéphane Gourichon <[email protected]>
========================================================================
Let's go!
EOF
set -euo pipefail
cd "$(dirname "$(readlink -f "$0")" )"
dpkg-checkbuilddeps
echo -e "* dpkg-checkbuilddeps\tPASSED"
PKGDIR="$PWD"
TMPDIR=$( mktemp -d ) && echo "* Will work in temp dir $TMPDIR"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) && echo "* Current git branch $CURRENT_BRANCH"
NAMEFORTAR="$( head -n 1 debian/changelog | sed -n 's/^\([^ ]*\)* (\([^-]*\)-[0-9]*).*$/\1_\2/p' )"
DIRNAMEFORDEB=${NAMEFORTAR//_/-}
if [[ -z "$NAMEFORTAR" ]]
then
echo >&2 "Cannot figure out tar archive name from first line of debian/changelog. Aborting"
head -n 1 debian/changelog
exit 1
fi
if output=$(git status --porcelain) && [ -z "$output" ]; then
echo "Working directory clean"
else
echo >&2 "WARNING: uncommitted changes. Consider aborting."
git status
echo >&2 "WARNING: uncommitted changes. Consider aborting."
echo >&2 "Waiting for 10 second."
sleep 10
fi
GITREV=$( git describe )
cd "$TMPDIR"
git clone "$PKGDIR" "${DIRNAMEFORDEB}"
tar zcvf ${NAMEFORTAR}.orig.tar.gz "${DIRNAMEFORDEB}"
cd "${DIRNAMEFORDEB}"
dpkg-checkbuilddeps
debuild -us -uc
. /etc/os-release ; DISTRO_ID="${ID}-${VERSION_ID}"
OUTDIR="$PKGDIR/../compiled_packages/${DISTRO_ID}/${NAMEFORTAR}" #_$( date +%Yy%mm%dd_%Hh%Mm%Ss )"
mkdir -p "$OUTDIR"
echo "generated from git commit $GITREV" >"${OUTDIR}/${NAMEFORTAR}.gitversion"
cd ..
cp -v "${NAMEFORTAR}"?* "$OUTDIR"
echo
echo ================================================================
echo "Artifacts available in $OUTDIR:"
echo "OUTDIR=$OUTDIR"
echo ================================================================
cd "$OUTDIR"
ls -al