forked from brbsix/debtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-deb.sh
executable file
·108 lines (80 loc) · 2.34 KB
/
build-deb.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
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
#
# Build debtool Debian package
error(){
echo "$PROGRAM:ERROR: $*" >&2
exit 1
}
warning(){
echo "$PROGRAM:WARNING: $*" >&2
}
PROGRAM=${0##*/}
APPLICATION=debtool
SCRIPT_DIRECTORY=$(readlink -m "$(dirname "$0")")
TEMP_DIRECTORY=$SCRIPT_DIRECTORY/temp_dir
BUILD_DIRECTORY=$TEMP_DIRECTORY/build_dir
BUILD_PATHS=(debian "$APPLICATION" "${APPLICATION}-completion" README.md)
VERSION=$(awk -F= '/^VERSION=/ {gsub("[\042\047]", ""); print $2}' "$APPLICATION")
DEVELOPMENT=0
if (( $# == 1 )) && [[ $1 =~ ^(-d|--dev(elopment)?)$ ]]; then
DEVELOPMENT=1
elif (( $# != 0 )); then
cat <<-EOF
Usage: $PROGRAM [-d|--development]
Build a Debian package.
-d, --development DO NOT remove build files after build
Build details:
APPLICATION=$APPLICATION
VERSION=$VERSION
SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY
TEMP_DIRECTORY=$TEMP_DIRECTORY
BUILD_DIRECTORY=$BUILD_DIRECTORY
BUILD_PATHS=${BUILD_PATHS[*]}
EOF
exit 0
fi
# enter the script directory
cd "$SCRIPT_DIRECTORY" || {
error "Failed to cd into $SCRIPT_DIRECTORY"
}
# ensure temp directory does not already exist
if [[ -d $TEMP_DIRECTORY ]]; then
error "Temporary directory '$TEMP_DIRECTORY' already exists... Remove it before continuing."
fi
# create temp directory and build directory
mkdir -p "$BUILD_DIRECTORY" || {
error "Failed to create $BUILD_DIRECTORY"
}
# copy paths into build directory
cp -at "$BUILD_DIRECTORY" "${BUILD_PATHS[@]}" || {
error "Failed to copy paths into build directory"
}
# rename README.md to README
mv "$BUILD_DIRECTORY/README.md" "$BUILD_DIRECTORY/README"
# enter the build directory
cd "$BUILD_DIRECTORY" || {
error "Failed to cd into $BUILD_DIRECTORY"
}
# perform build
debuild -b -uc -us
EC=$?
# warn upon debuild failure
if (( EC != 0 )); then
warning "debuild returned a nonzero exit code [$EC]"
fi
# enter the temp directory containing .deb and logs
cd "$TEMP_DIRECTORY" || {
error "Failed to cd into $TEMP_DIRECTORY"
}
# move .deb into the root directory
mv ./*.deb "$SCRIPT_DIRECTORY" || {
error "Failed to move .deb into $SCRIPT_DIRECTORY"
}
# exit before removing build files if dev mode is enabled
(( DEVELOPMENT == 1 )) && exit 0
# return to the script directory
cd "$SCRIPT_DIRECTORY" || {
error "Failed to cd back into $SCRIPT_DIRECTORY"
}
# remove the temp directory
rm -rf "$TEMP_DIRECTORY"