-
Notifications
You must be signed in to change notification settings - Fork 0
/
deb-build-pkg
executable file
·205 lines (182 loc) · 5.17 KB
/
deb-build-pkg
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
#!/usr/bin/env bash
# vim: ft=sh tw=80
declare help="
Script for building .deb packages using Docker.
Usage:
deb-build-pkg run [-d <distro> ] [-v <version>] [-o <path>] [-x <repo>]
[-x <repo>] [-e <entrypoint>]
deb-build-pkg build [-d <distro>] [-v <version>] [-o <path>] [-x <repo>]
[-x <repo>] [-g <keyid>]
deb-build-pkg pack [-d <distro>] [-v <version>] [-o <path>] [-r <path>]
deb-build-pkg bundle [-d <distro>] [-v <version>] [-o <path>]
[-r <path>] [-x <repo>] [-x <repo>] [-g <keyid>]
deb-build-pkg --version
deb-build-pkg -h | --help
Options:
-d Distro to use (expects debian or ubuntu). Defaults to debian.
-v Version to use (expects unstable, testing or stable for debian and
xenial, trusty or bionic for ubuntu). Defaults to unstable.
-o Path to output directory. Defaults to ../pkgs.
-r Path to release output. Defaults to ../release.
-s Path to source (where the debian directory is in), defaults to
current directory, \$CWD or \$PWD.
-e Entrypoint for Docker cmdline.
-x Add extra repo, like: 'http://repo.org/repo dist section'.
Multiple entries accepted.
-g Add extra gpg keys to apt-key.
-n n is short for non-standard. This applies special rules like using
a particular git branch per version tried to be build. Go to the
README.md file or https://github.com/resnullius/deb-build-pkg/ to
learn more about what non-standard means.
-h --help Show this screen.
--version Show versions.
"
declare version="
Version: 1.4.0
Released under the MIT license terms.
"
declare ARCH
ARCH="$(uname -m)"
declare output_dir="${OUTPUT_DIR:-$PWD/../pkgs}"
declare rel_dir="${REL_DIR:-$PWD/../release}"
declare src_dir="${SRC_DIR:-$PWD}"
declare distro="${DISTRO:-debian}"
declare image_name="${IMAGE_NAME:-resnullius/debian-devel}"
declare image_ver="${IMAGE_VER:-unstable}"
declare entrypoint
declare pkg_name
declare non_standard=false
declare -a extra_repos
declare -a extra_repos_cmd
declare -a extra_gpgs
declare -a extra_gpgs_cmd
initialize_dirs() {
[ ! -d "$output_dir" ] && mkdir "$output_dir"
[ -d "$output_dir" ] && output_dir=$(cd "$output_dir" && pwd)
[ -d "$src_dir" ] && src_dir=$(cd "$src_dir" && pwd)
[ ! -d "$rel_dir" ] && mkdir "$rel_dir"
[ -d "$rel_dir" ] && rel_dir=$(cd "$rel_dir" && pwd)
}
grab_pkg_name() {
pkg_name=$(grep "Source:" "$src_dir"/debian/control | sed -e 's/Source: //')
}
eval_image_name() {
[ "$distro" = "ubuntu" ] && image_name="resnullius/ubuntu-devel"
if [ "$ARCH" != "x86_64" ]; then
image_name+="-armhf"
fi
}
eval_opts() {
while getopts ":d:v:g:o:s:e:x:r:n:" opt "$@"; do
case "$opt" in
d)
distro="$OPTARG";;
v)
image_ver="$OPTARG";;
o)
output_dir="$OPTARG";;
r)
rel_dir="$OPTARG";;
s)
src_dir="$OPTARG";;
x)
extra_repos+=("$OPTARG");;
n)
non_standard=true;;
g)
extra_gpgs+=("$OPTARG");;
e)
entrypoint="--entrypoint $OPTARG"
if [ "$OPTARG" == "/bin/bash" ]; then
entrypoint+=" -ti"
fi
shift; shift;;
\?)
echo "Invalid option -$OPTARG was ignored." >&2;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1;;
esac
done
initialize_dirs
grab_pkg_name
eval_image_name
echo "Will build version $image_ver for $pkg_name on $distro..."
}
git_in() {
git checkout "$distro/$image_ver"
}
clear_out() {
git checkout master
}
pull_docker() {
docker pull "$image_name":"$image_ver"
}
build_extra_repos_cmd() {
for repo in "${extra_repos[@]}"; do
extra_repos_cmd+=("-e" "$repo")
done
}
build_extra_gpgs_cmd() {
for key in "${extra_gpgs[@]}"; do
extra_gpgs_cmd+=("-g" "$key")
done
}
# shellcheck disable=SC2086
run_docker() {
docker run \
$entrypoint \
--rm \
-v "$src_dir":/opt/src \
-v "$output_dir":/opt/pkgs \
"$image_name":"$image_ver" "$@"
}
build() {
eval_opts "$@"
if [ "$non_standard" == true ]; then
git_in
fi
pull_docker
build_extra_repos_cmd
build_extra_gpgs_cmd
run_docker "-p" "$pkg_name" "${extra_repos_cmd[@]}" "${extra_gpgs_cmd[@]}"
if [ "$non_standard" == true ]; then
clear_out
fi
}
run() {
eval_opts "$@"
if [ "$non_standard" == true ]; then
git_in
fi
pull_docker
run_docker
if [ "$non_standard" == true ]; then
clear_out
fi
}
pack_for_release() {
eval_opts "$@"
tar -cJf "$rel_dir"/"$distro"-"$image_ver"-"$ARCH".tar.xz -C "$output_dir" .
sudo rm -rf "$output_dir"
}
print_version() {
echo "$version"
}
print_help() {
echo "$help"
}
main() {
set -eo pipefail; [ "$TRACE" ] && set -x
declare cmd="$1"
case "$cmd" in
-h|--help) shift; print_help "$@";;
--version) shift; print_version "$@";;
run) shift; set - "$@" "-e" "/bin/bash"; run "$@";;
build) shift; build "$@";;
pack) shift; pack_for_release "$@";;
bundle) shift; build "$@"; pack_for_release "$@";;
*) print_help "$@";;
esac
}
main "$@"