-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_package
executable file
·67 lines (53 loc) · 2.55 KB
/
build_package
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
#!/bin/bash
#-------------------------------------------------------------------------------
# Purpose:
# Build distribution packages for Ubuntu
# Parameters:
# 1 - Build number, optional. If omitted, "1" is used
# Requires:
# None
#-------------------------------------------------------------------------------
SETUP_SCRIPT="setup.py"
DIST_ROOT_DIR="dist"
PO_DIR="po"
APP_BUILD=${1:-1}
# Logs a failure message and exits
# Parameters:
# 1 - message
err() {
echo "ERROR: $1" >&2
exit 1
}
# Extract name and version values from the setup script file
APP_NAME=$(sed -ne 's/\s*APP_ID\s*=\s*\x27\([^\x27]\+\)\x27.*/\1/p' "$SETUP_SCRIPT")
[[ -n "$APP_NAME" ]] || err "Failed to extract application name"
APP_VERSION=$(sed -ne 's/\s*version=\x27\([^\x27]\+\)\x27.*/\1/p' "$SETUP_SCRIPT")
[[ -n "$APP_VERSION" ]] || err "Failed to extract application version"
echo "Building ${APP_NAME} version ${APP_VERSION} build ${APP_BUILD}..."
# Verify the changelog contains the appropriate line
app_ver_string="${APP_NAME} (${APP_VERSION}-${APP_BUILD})"
(head -n 1 "debian/changelog" | grep -q "$app_ver_string") ||
err "The changelog doesn't start with the entry '${app_ver_string}'"
# Initial cleanup: clean the dist dirs
[[ ! -d "$DIST_ROOT_DIR" ]] || rm -rf "$DIST_ROOT_DIR" || err "Removing $DIST_ROOT_DIR failed"
# Run the setup script to create a source tarball
python3 "$SETUP_SCRIPT" --quiet sdist --owner=root --group=root || err "Building source tarball failed"
# Add '.orig' and change '-' to '_' before version in tarball's name
TARBALL_NAME="${DIST_ROOT_DIR}/${APP_NAME}_${APP_VERSION}.orig.tar.gz"
mv "${DIST_ROOT_DIR}/${APP_NAME}-${APP_VERSION}.tar.gz" "$TARBALL_NAME" || err "Renaming tarball file failed"
# Unpack the tarball: it will create the release dir
tar --directory "$DIST_ROOT_DIR" -xzf "$TARBALL_NAME" "${APP_NAME}-${APP_VERSION}" || err "Unpacking $TARBALL_NAME failed"
# Copy debian/ into the release dir
RELEASE_DIR="${DIST_ROOT_DIR}/${APP_NAME}-${APP_VERSION}"
cp -r debian "$RELEASE_DIR" || err "Copying debian/ into $RELEASE_DIR failed"
# Build a Debian source package
pushd .
cd "$RELEASE_DIR"
debuild -S -sa || err "Building Debian package failed"
popd >/dev/null
# Cleanup: remove the release dir
rm -rf "$RELEASE_DIR"
echo "--------------------------------------------------------------------------------"
echo "Build succeeded. To upload issue the following command:"
echo " dput ppa:yktooo/ppa \"$DIST_ROOT_DIR/${APP_NAME}_${APP_VERSION}-${APP_BUILD}_source.changes\""
echo "--------------------------------------------------------------------------------"