-
Notifications
You must be signed in to change notification settings - Fork 0
/
packaging.sh
434 lines (383 loc) · 11.1 KB
/
packaging.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/bin/sh
export PACKAGING_ROOT STATE_ROOT SOURCE_ROOT WORK_ROOT
export PATH LOGFILE LIBNAME TOOLS OUTPUT CONFIG_ROOT
export PKGNAME VERSION REL_VERSION BRANCH CHANNEL FULL_VERSION
export BASE_VERSION MAJOR_VERSION MINOR_VERSION RELEASE_VERSION
export KNO_VERSION KNO_MAJOR KNO_MINOR GIT_PROTOCOL
export REPOMAN REPO_SYSTEM REPO REPO_URL REPO_LOGIN
export CODENAME DISTRO STATUS ARCH URGENCY
export PKGTOOL PKGINFO
PKGLOG=${PKGLOG:-/dev/null}
logmsg () {
echo "pkg ($$@$(pwd):${DISTRO}) $1" >&2;
}
infomsg () {
if [ -n "${PKGLOG}" ] && [ -w "${PKGLOG}" ]; then
echo "pkg ($$@$(pwd):${DISTRO}) $1" >>${PKGLOG};
else
echo "pkg ($$@$(pwd):${DISTRO}) $1" >&2;
fi;
}
dbgmsg () {
if [ -n "${DEBUGGING}" ]; then
echo "pkgdebug ($$@$(pwd):${DISTRO}) $1" >&2;
fi;
}
dbgmsg "Sourcing packaging.sh into $$";
export SUDO
if [ "$(id -u)" != "0" ]; then SUDO=sudo; fi;
set_pkg_state() {
local state=$1;
if [ -z "${PKGNAME}" ]; then
echo "# No current package! set_pkg_state ${state}" >&2;
return -1
else
if [ -n "${state}" ]; then
rm -f *.sourced *.prepped *.packaged *.installed *.pushed;
fi;
touch ${PKGNAME}.${state};
return 0;
fi;
}
get_pkg_state() {
local state=$1;
if [ -z "${PKGNAME}" ]; then
echo "# No current package! get_pkg_state" >&2;
else
for state in sourced prepped packaged installed pushed; do
if [ -f "${PKGNAME}.${state}" ]; then
echo ${state};
return;
fi;
done;
fi;
}
mkpath () {
local root=$1;
local path=$2;
local slash_root=${root}
if [ "${path#/}" != "${path}" ]; then
# starts with /
echo ${path};
else
if [ ${root%/} = ${root} ]; then slash_root="${root}/"; fi
if [ ${path#./} != ${path} ]; then path=${path#./}; fi;
if [ ${path#../} != ${path} ]; then
path=${path#../};
slash_root=$(dirname ${slash_root});
fi;
echo ${slash_root}${path};
fi;
}
make_dirs () {
local path=$1;
local dir=$(dirname $1);
if [ -z "${path}" ]; then
:;
elif [ -d "${path}" ]; then
:;
else
make_dirs ${dir};
mkdir ${path};
fi;
}
if [ "$(basename $0)" = "packaging.sh" ]; then
echo "This file should be loaded (sourced) rather than run by itself";
exit;
else
echo "Loading packaging.sh into $$, arg1=$1" >>${PKGLOG}
fi;
if [ -z "${PACKAGING_ROOT}" ]; then
if [ -f packaging.sh ]; then
PACKAGING_ROOT=$(pwd);
else
script_dir=$(dirname $0)
if [ -f ${script_dir}/packaging.sh ]; then
PACKAGING_ROOT=$(pwd);
fi;
fi;
if [ -z "${PACKAGING_ROOT}" ]; then
echo "Couldn't find packaging root directory";
exit;
else
TOOLS=${PACKAGING_ROOT}/tools;
PATH="${PATH}:${TOOLS}";
STATE_ROOT=${PACKAGING_ROOT}/state;
DEFAULTS_ROOT=${PACKAGING_ROOT}/defaults;
CONFIG_ROOT=${PACKAGING_ROOT}/sources;
SOURCE_ROOT=${PACKAGING_ROOT}/src;
WORK_ROOT=${PACKAGING_ROOT}/work;
OUTPUT=${PACKAGING_ROOT}/output;
fi;
fi;
if [ ! -d "${PACKAGING_ROOT}/output" ]; then
mkdir "${PACKAGING_ROOT}/output";
fi;
if [ -f ${STATE_ROOT}/PKGNAME ]; then
curpkg=$(cat ${STATE_ROOT}/PKGNAME);
fi;
# Handle defaults from the environment
if [ -n "${DISTRO}" ]; then
:;
elif [ -f ${STATE_ROOT}/DISTRO ]; then
DISTRO=$(cat ${STATE_ROOT}/DISTRO);
elif which lsb_release 2>/dev/null 1>/dev/null; then
distributor=$(lsb_release -si);
case ${distributor} in
Ubuntu|Debian|Mint)
DISTRO=$(lsb_release -sc);
;;
RedHatEnterprise)
DISTRO="el$(lsb_release -sr)";
;;
Fedora*)
DISTRO="fc$(lsb_release -sr)";
;;
*)
DISTRO="${distributor}$(lsb_release -sr)";
;;
esac
else
DISTRO=$(uname -o | tr '/' '_');
fi;
if [ -n "${ARCH}" ]; then
:;
elif [ -f ${STATE_ROOT}/ARCH ]; then
ARCH=$(cat ${STATE_ROOT}/ARCH);
else
ARCH=$(uname -p || echo x86_64);
fi;
if [ -n "${DISTRIBUTOR}" ]; then
:;
elif which lsb_release 1>/dev/null 2>/dev/null; then
DISTRIBUTOR=$(lsb_release -i -s | sed - -e 's|Distributor ID:\t||g');
else
DISTRIBUTOR=any
fi;
if [ -n "${REPO_SYSTEM}" ]; then
:;
elif [ -f ${STATE_ROOT}/REPO_SYSTEM ]; then
REPO_SYSTEM=$(cat ${STATE_ROOT}/REPO_SYSTEM);
elif [ -f ${DEFAULTS_ROOT}/REPO_SYSTEM ]; then
REPO_SYSTEM=$(cat ${DEFAULTS_ROOT}/REPO_SYSTEM);
else case "${DISTRIBUTOR}" in
Fedora|Centos|RedHat|RedHatEnterprise)
REPO_SYSTEM="yum";
;;
Debian|Mint|Ubuntu)
REPO_SYSTEM="apt";
;;
Alpine)
REPO_SYSTEM="apk";
;;
*)
REPO_SYSTEM="apt";
;;
esac;
fi;
if [ -n "${GIT_PROTOCOL}" ]; then
:;
elif [ -f ${STATE_ROOT}/GIT_PROTOCOL ]; then
GIT_PROTOCOL=$(cat ${STATE_ROOT}/GIT_PROTOCOL);
elif [ -f ${DEFAULTS_ROOT}/GIT_PROTOCOL ]; then
GIT_PROTOCOL=$(cat ${DEFAULTS_ROOT}/GIT_PROTOCOL);
fi;
if [ -n "${DEFAULT_BRANCH}" ]; then
echo ${DEFAULT_BRANCH} > ${DEFAULTS_ROOT}/BRANCH;
fi;
if [ -n "${DEFAULT_CHANNEL}" ]; then
echo ${DEFAULT_CHANNEL} > ${DEFAULTS_ROOT}/CHANNEL;
fi;
# This is all information which should come from getsource
get_state() {
local file=$1;
if [ -f ${file} ]; then
cat ${file};
else echo;
fi;
}
import_state() {
local dir=${1:-${STATE_ROOT}};
if [ -f ${dir}/PKGNAME ]; then
PKGNAME=$(cat ${dir}/PKGNAME);
else PKGNAME=;
fi;
if [ -f ${dir}/BRANCH ]; then
BRANCH=$(cat ${dir}/BRANCH);
else BRANCH=;
fi;
if [ -f ${dir}/VERSION ]; then
VERSION=$(cat ${dir}/VERSION);
else VERSION=;
fi;
if [ -f ${dir}/BASE_VERSION ]; then
BASE_VERSION=$(cat ${dir}/BASE_VERSION);
else BASE_VERSION=${VERSION};
fi;
if [ -f ${dir}/FULL_VERSION ]; then
FULL_VERSION=$(cat ${dir}/FULL_VERSION);
else FULL_VERSION=${VERSION};
fi;
MAJOR_VERSION=$(echo $VERSION | cut -d. -f 1);
MINOR_VERSION=$(echo $VERSION | cut -d. -f 2);
RELEASE_VERSION=$(echo $VERSION | cut -d. -f 3);
if [ -f ${STATE_ROOT}/CHANNEL ]; then
CHANNEL=$(cat ${STATE_ROOT}/CHANNEL);
elif [ -f defaults/CHANNEL ]; then
CHANNEL=$(cat defaults/CHANNEL);
else CHANNEL=;
fi;
if [ -f ${dir}/LIBNAME ]; then
LIBNAME=$(cat ${dir}/LIBNAME);
fi;
if [ -f ${dir}/STATUS ]; then
STATUS=$(cat ${dir}/STATUS);
else STATUS=stable;
fi;
if [ -f ${dir}/URGENCY ]; then
URGENCY=$(cat ${dir}/URGENCY);
else URGENCY=normal;
fi;
CODENAME=${DISTRO};
if [ -n "${REPO}" ]; then
:;
elif [ -f "${dir}/REPO" ]; then
# Get repo from state
REPO=$(cat "${dir}/REPO");
elif [ -f "${DEFAULTS_ROOT}/REPO" ]; then
REPO=$(cat "${DEFAULTS_ROOT}/REPO");
else
REPO=beingmeta;
fi;
}
import_state;
# More repo information
resolve_repo() {
local dir=${1:-${PACKAGING_ROOT}/repos/${REPO}};
if [ -n "${USE_REPO_URL}" ]; then
REPO_URL="${USE_REPO_URL}";
elif [ -f "${dir}/${PKGNAME}.${REPO_SYSTEM}" ]; then
REPO_URL=$(cat "${dir}/${PKGNAME}.${REPO_SYSTEM}");
elif [ -n "${CHANNEL}" ] && [ -f "${dir}/${CHANNEL}.${REPO_SYSTEM}" ]; then
REPO_URL=$(cat "${dir}/${CHANNEL}.${REPO_SYSTEM}");
elif [ -f "${dir}/default.${REPO_SYSTEM}" ]; then
REPO_URL=$(cat "${dir}/default.${REPO_SYSTEM}");
fi;
if [ -n "${USE_REPO_LOGIN}" ]; then
REPO_LOGIN="${USE_REPO_LOGIN}";
elif [ -f "${dir}/${PKGNAME}.${REPO_SYSTEM}.login" ]; then
REPO_LOGIN=$(cat "${dir}/${PKGNAME}.${REPO_SYSTEM}.login");
elif [ -n "${CHANNEL}" ] && [ -f "${dir}/${CHANNEL}.${REPO_SYSTEM}.login" ]; then
REPO_LOGIN=$(cat "${dir}/${CHANNEL}.${REPO_SYSTEM}.login");
elif [ -n "${CHANNEL}" ] && [ -f "${dir}/${CHANNEL}.login" ]; then
REPO_LOGIN=$(cat "${dir}/${CHANNEL}.login");
elif [ -f "${dir}/default.${REPO_SYSTEM}.login" ]; then
REPO_LOGIN=$(cat "${dir}/default.${REPO_SYSTEM}.login");
elif [ -f "${dir}/default.login" ]; then
REPO_LOGIN=$(cat "${dir}/default.login");
fi;
if [ -n "${DISTRO}" ]; then
REPO_URL=$(echo ${REPO_URL} | sed - -e "s/-@DISTRO@/-${DISTRO}/");
REPO_URL=$(echo ${REPO_URL} | sed - -e "s|/@DISTRO@|/${DISTRO}|");
else
REPO_URL=$(echo ${REPO_URL} | sed - -e "s/-@DISTRO@/-universal/");
REPO_URL=$(echo ${REPO_URL} | sed - -e "s|/@DISTRO@|/universal|");
fi;
if [ -n "${CHANNEL}" ]; then
REPO_URL=$(echo ${REPO_URL} | sed - -e "s/-@CHANNEL@/-${CHANNEL}/");
REPO_URL=$(echo ${REPO_URL} | sed - -e "s|/@CHANNEL@|/${CHANNEL}|");
else
REPO_URL=$(echo ${REPO_URL} | sed - -e "s/-@CHANNEL@//");
REPO_URL=$(echo ${REPO_URL} | sed - -e "s|/@CHANNEL@|/stable|");
fi;
if [ -n "${REPOMAN}" ]; then
:;
elif [ -f "${dir}/${PKGNAME}.repoman" ]; then
REPOMAN=$(cat "${dir}/${PKGNAME}.repoman");
elif [ -n "${CHANNEL}" ] && [ -f "${dir}/${CHANNEL}.repoman" ]; then
REPOMAN=$(cat "${dir}/${CHANNEL}.repoman");
elif [ -f "${dir}/default.repoman" ]; then
REPOMAN=$(cat "${dir}/default.repoman");
else
REPOMAN="Repository Manager <[email protected]>";
fi;
}
resolve_repo;
# Log files
if [ -z "${LOGFILE}" ]; then
if [ -f defaults/${PKGNAME}.LOGFILE ]; then
LOGFILE=$(cat defaults/${PKGNAME}.LOGFILE);
elif [ -f defaults/LOGFILE ]; then
LOGFILE=$(cat defaults/LOGFILE);
fi;
fi;
# Information about KNO
if which knoconfig 2>/dev/null 1>/dev/null; then
KNO_VERSION=$(knoconfig version);
KNO_MAJOR=$(knoconfig major);
KNO_MINOR=$(knoconfig minor);
elif [ -d src/kno/.git ]; then
KNO_VERSION=$("cd" src/kno; u8_gitversion etc/base_version);
KNO_MAJOR=$(echo ${KNO_VERSION} | cut - -d'.' -f1);
KNO_MINOR=$(echo ${KNO_VERSION} | cut - -d'.' -f2);
else
KNO_VERSION="2110.1.4";
KNO_MAJOR="2110;"
KNO_MINOR="1";
fi;
if [ -f ${STATE_ROOT}/GPGID ]; then
GPGID=$(cat ${STATE_ROOT}/GPGID);
fi;
# Find the package tool
if [ -n "${PKGTOOL}" ]; then
dbgmsg "PKGTOOL=${PKGTOOL}"
elif [ -f "${STATE_ROOT}/PKGTOOL" ]; then
PKGTOOL=$(cat "${STATE_ROOT}/PKGTOOL");
else
for probe in "${PACKAGING_ROOT}/defaults/${PKGNAME}/PKGTOOL" "${PACKAGING_ROOT}/defaults/PKGTOOL"; do
if [ -z "${PKGTOOL}" ] && [ -f "${probe}" ]; then
PKGTOOL=$(cat "${probe}");
fi;
done;
if [ -z "${PKGTOOL}" ] && [ -n "${DISTRIBUTOR}" ]; then
case ${DISTRIBUTOR} in
Ubuntu|Debian)
PKGTOOL=${PACKAGING_ROOT}/tools/debtool;
;;
Fedora|RHEL|CENTOS|RedHat|RedHatEnterprise)
PKGTOOL=${PACKAGING_ROOT}/tools/rpmtool;
;;
Alpine)
PKGTOOL=${PACKAGING_ROOT}/tools/apktool;
;;
*)
PKGTOOL=
;;
esac
if [ -n "${PKGTOOL}" ]; then
echo ${PKGTOOL} > ${STATE_ROOT}/PKGTOOL;
fi;
fi;
fi;
TOOLNAME=${PKGTOOL##*/}
if [ -z "${TOOLNAME}" ]; then
echo "No TOOLNAME";
elif [ "${TOOLNAME}" = "debtool" ]; then
PKGINFO=debinfo
elif [ "${TOOLNAME}" = "rpmtool" ]; then
PKGINFO=rpminfo
elif [ "${TOOLNAME}" = "apktool" ]; then
PKGINFO=apkinfo
else
PKGINFO=none
fi;
if [ -f ${STATE_ROOT}/OUTDIR ]; then OUTDIR=$(cat ${STATE_ROOT}/OUTDIR); fi;
dbgmsg "REPO HOST=${REPO} URL=${REPO_URL} REPO_LOGIN=${REPO_LOGIN}";
if [ -f ${STATE_ROOT}/GIT_NO_LFS ]; then
GIT_NO_LFS=$(cat ${STATE_ROOT}/GIT_NO_LFS);
elif ! git lfs status 2>/dev/null 1>/dev/null; then
GIT_NO_LFS=sorry;
echo ${GIT_NO_LFS} > ${STATE_ROOT}/GIT_NO_LFS;
else
unset GIT_NO_LFS
fi;