-
Notifications
You must be signed in to change notification settings - Fork 1
/
make-helper.bsh
executable file
·626 lines (560 loc) · 14.9 KB
/
make-helper.bsh
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
#!/bin/bash
## This file is part of Whonix.
## Copyright (C) 2012 - 2014 Patrick Schleizer <adrelanos@riseup.net>
## See the file COPYING for copying conditions.
## generic deb build script version 0.6
# set -x
if [ -f /usr/lib/pre.bsh ]; then
source /usr/lib/pre.bsh
fi
set -e
set -o pipefail
cd "${BASH_SOURCE[0]%/*}"
mydir="${PWD##*/}"
parse_cmd() {
## Thanks to:
## http://mywiki.wooledge.org/BashFAQ/035
local matched="false"
while :
do
case $1 in
help)
matched="true"
make_help
exit 0
shift
;;
dist)
matched="true"
make_dist
exit 0
shift
;;
manpages)
matched="true"
make_manpages
exit 0
shift
;;
uch)
matched="true"
make_uch
exit 0
shift
;;
install)
matched="true"
make_install
exit 0
shift
;;
deb-pkg)
matched="true"
deb="true"
shift
;;
deb-pkg-signed)
matched="true"
deb_signed="true"
shift
;;
deb-pkg-source)
matched="true"
deb_source="true"
shift
;;
deb-pkg-install)
matched="true"
make_deb-pkg-install
exit 0
shift
;;
deb-install)
matched="true"
make_deb-install
exit 0
shift
;;
deb-icup)
matched="true"
make_deb-icup
exit 0
shift
;;
deb-remove)
matched="true"
make_deb-remove
exit 0
shift
;;
deb-purge)
matched="true"
make_deb-purge
exit 0
shift
;;
deb-pkg)
matched="true"
deb="true"
shift
;;
deb-clean)
matched="true"
make_deb-clean
shift
;;
deb-cleanup)
matched="true"
make_deb-cleanup
shift
;;
dput-ubuntu-ppa)
matched="true"
make_dput-ubuntu-ppa
shift
;;
clean)
matched="true"
make_clean
exit 0
shift
;;
distclean)
matched="true"
make_clean
exit 0
shift
;;
checkout)
matched="true"
make_checkout
exit 0
shift
;;
installcheck)
matched="true"
make_installcheck
exit 0
shift
;;
installsim)
matched="true"
make_installsim
exit 0
shift
;;
uninstallcheck)
matched="true"
make_uninstallcheck
exit 0
shift
;;
uninstall)
matched="true"
make_uninstall
exit 0
shift
;;
uninstallsim)
matched="true"
make_uninstallsim
exit 0
shift
;;
deb-chl-bumpup)
matched="true"
make_deb-chl-bumpup
exit 0
shift
;;
--)
shift
break
;;
-*)
echo "unknown option: $1" >&2
exit 1
;;
*)
break
;;
esac
done
## If there are input files (for example) that follow the options, they
## will remain in the "$@" positional parameters.
if [ ! "$matched" = "true" ]; then
true "ERROR: no valid option chosen!"
exit 1
fi
if [ "$deb" = "true" ]; then
make_deb-pkg $@
exit 0
fi
if [ "$deb_signed" = "true" ]; then
make_deb-pkg-signed $@
exit 0
fi
if [ "$deb_source" = "true" ]; then
make_deb-pkg-source $@
exit 0
fi
}
get_variables() {
local temp
command -v dpkg-parsechangelog >/dev/null
OIFS="${IFS}"
NIFS=$'\n'
IFS="${NIFS}"
for line in $(dpkg-parsechangelog); do
## Example line:
## Version: 0.1-1
IFS="${OIFS}"
read -r first second _ <<< "$line"
## Example first:
## Version:
## Example second:
## 3:0.1-1
first="${first,,}"
## Example first:
## version
if [ "$first" = "version:" ]; then
changelog_version="$second"
## Example changelog_version:
## 3:0.1-1
revision="${second#*-}"
## Example revision:
## 1
temp="${second%-*}"
## Example version:
## 3:0.1
version="${temp#*:}"
## Example version:
## 0.1
epoch="${second%:*}"
## Example epoch:
## 3
break
fi
done
IFS="${OIFS}"
if [ "$version" = "" ]; then
true "ERROR: variable version is empty."
exit 1
fi
main_package_name="$mydir"
if [ "$main_package_name" = "" ]; then
true "ERROR: variable main_package_name is empty."
exit 1
fi
main_deb_file="../${main_package_name}_${version}-${revision}_all.deb"
local grep_output line a package
grep_output="$(grep "Package:" "debian/control")"
## Example: grep_output
## Package: anon-shared-packages-dependencies
## Package: anon-shared-packages-recommended
package_list="$main_package_name"
OIFS="$IFS"
NIFS=$'\n'
IFS="$NIFS"
for line in $grep_output; do
IFS="$OIFS"
read a package _ <<< "$line"
if [ "$package" = "$main_package_name" ]; then
continue
fi
package_list="$package_list $package"
done
IFS="$OIFS"
}
get_destdir() {
if [ "$DESTDIR" = "" ]; then
DESTDIR="/"
fi
}
make_help() {
set +x
echo "\
make help
Show this help.
make dist
Create package-version.tar.gz from source files in parent folder.
make manpages
Create man page from man source folder, which will be stored in debian/tmp-man folder.
make uch
Store upstream changelog from git log in debian/changelog.upstream.
make install
Copying the files from the source tree to system-wide directories.
make installsim
Simulate copying the files from the source tree to system-wide directories.
make deb-pkg
Create a deb, which will be stored in parent folder.
make deb-pkg-install
Create a deb, which will be stored in parent folder, and install it.
make deb-install
Install deb from parent folder.
make deb-icup
Combination of make deb-pkg, make deb-pkg-install and make deb-pkg-cleanup.
make deb-remove
apt-get remove main_package_name
make deb-purge
apt-get purge main_package_name
make deb-clean
Delete temporary debhelper files.
make deb-cleanup
Same as make deb-clean and deletes debuild artifacts from parent folder.
make dput-ubuntu-ppa
Upload to Ubuntu ppa. Requires functional .dput.cf.
make clean
Currently same as make deb-clean.
make distclean
Currently same as make clean.
make checkout
Fetch from git.
make installcheck
Check if source files match installed files.
make uninstallcheck
Check if make uninstall removed all files.
make uninstall
Delete all installed files.
make uninstallsim
Simulate what make uninstall would do.
make deb-chl-bumpup
Bump upstream version number in debian/changelog."
}
make_dist() {
get_variables
## Explicitly set access time, so we end up with a deterministic debian.tar.gz file.
shopt -s globstar dotglob
touch -t "201308151102.35" ./debian
touch -t "201308151102.35" ./debian/**
shopt -u globstar dotglob
rm --force "../${main_package_name}_${version}.orig.tar.gz"
git archive \
--format=tar HEAD --prefix="${main_package_name}-${version}/" \
| gzip -n > "../${main_package_name}_${version}.orig.tar.gz"
ls -la "../${main_package_name}_${version}.orig.tar.gz"
}
make_manpages() {
shopt -s globstar dotglob nullglob
local i source_folder filename_without_ronn_file_extension
for i in "$PWD/man"/**; do
if [ -d "$i" ]; then
continue
fi
base_name="${i##*/}"
filename_without_ronn_file_extension="${base_name%.*}"
mkdir --parents "$PWD/debian/tmp-man/$source_folder"
true "${bold}${cyan}INFO: Creating man page $PWD/debian/tmp-man/$filename_without_ronn_file_extension ${reset}"
ronn \
--manual="Whonix Documentation" \
--organization="Whonix" \
< "$i" \
> "$PWD/debian/tmp-man/$filename_without_ronn_file_extension"
done
shopt -u globstar dotglob nullglob
}
make_uch() {
git log > "$PWD/debian/changelog.upstream"
test -f "$PWD/debian/changelog.upstream"
}
make_clean() {
make_deb-clean
}
make_deb-pkg_helper() {
make_dist
if [ "$DEBUILD_LINTIAN_OPTS" = "" ]; then
export DEBUILD_LINTIAN_OPTS="--info --display-info --fail-on-warnings"
fi
## Using --no-lintian, because debuild does not exist with a non-zero exit
## code, should lintian find an error. Therefore running lintian afterwards.
debuild \
--no-lintian \
--rootcmd="$PWD/debian/gain-root-command" \
-sa \
$debuild_maybe_unsigned_opts \
$debuild_maybe_source_only_opt \
${1+"$@"}
lintian $DEBUILD_LINTIAN_OPTS
true "INFO: You can find your deb file here: $main_deb_file"
}
make_deb-pkg() {
debuild_maybe_unsigned_opts="-us -uc"
make_deb-pkg_helper $@
}
make_deb-pkg-signed() {
make_deb-pkg_helper $@
}
make_deb-pkg-source() {
debuild_maybe_source_only_opt="-S"
make_deb-pkg_helper $@
}
make_deb-install() {
get_variables
if [ ! -f "$main_deb_file" ]; then
true "ERROR: File $main_deb_file does not exist. Have you run \"make deb-pkg\" already?"
exit 1
fi
sudo dpkg -i "$main_deb_file"
}
make_deb-remove() {
get_variables
sudo apt-get remove "$main_package_name"
}
make_deb-purge() {
get_variables
sudo apt-get purge "$main_package_name"
}
make_deb-pkg-install() {
make_deb-pkg
make_deb-install
}
make_deb-icup() {
make_deb-pkg-install
make_deb-cleanup
}
make_deb-clean() {
get_variables
if [ -d "debian/tmp-man" ]; then
rm --recursive "debian/tmp-man"
fi
local to_delete package
for package in $package_list; do
for to_delete in \
"debian/$package.debhelper.log" \
"debian/$package.substvars" \
"debian/changelog.upstream" \
"debian/files" \
"debian/$package.prerm.debhelper" \
"debian/$package.postinst.debhelper" \
"debian/$package.postrm.debhelper"
do
if [ -e "$to_delete" ]; then
rm "$to_delete"
fi
if [ -d "debian/$package" ]; then
rm --recursive "debian/$package"
fi
done
done
}
make_deb-cleanup() {
make_deb-clean
local to_delete package
for package in $package_list; do
for to_delete in \
"../${package}_"*-*"_all.deb" \
"../${package}_"*-*".debian.tar.gz" \
"../${package}_"*-*".dsc" \
"../${package}_"*-*_*".build" \
"../${package}_"*-*_*".changes" \
"../${package}_"*-*"_source.build" \
"../${package}_"*-*"_source.changes" \
"../${package}_"*".orig.tar.gz" \
"../${package}_"*-*"_source.${package}.upload"
do
if [ -e "$to_delete" ]; then
rm "$to_delete"
fi
done
done
}
make_dput-ubuntu-ppa() {
get_variables
dput "$main_package_name" "../${main_package_name}_${version}-${revision}_source.changes"
}
make_checkout() {
git fetch
}
helper() {
get_destdir
shopt -s globstar dotglob nullglob
local d source_file file_without_pwd file_with_destdir
for d in bin boot dev etc home lib opt sbin srv sys usr var; do
if [ -d "$d" ]; then
for source_file in "$PWD/$d"/**; do
if [ "$install_" = "true" ]; then
cp -R "$d" "$DESTDIR"
continue
elif [ "$installsim" = "true" ]; then
true "INFO: would do: cp -R $d $DESTDIR"
continue
fi
if [ ! -f "$source_file" ]; then
continue
fi
file_without_pwd="${source_file#$PWD}"
file_with_destdir="${DESTDIR}${file_without_pwd}"
if [ "$uninstallcheck" = "true" ]; then
if [ -f "$file_with_destdir" ]; then
true "ERROR: file $file_with_destdir still installed."
still_installed="true"
fi
elif [ "$installcheck" = "true" ]; then
diff "$source_file" "$file_with_destdir"
elif [ "$uninstallsim" = "true" ]; then
if [ -f "$file_with_destdir" ]; then
true "INFO: would do: rm \"$file_with_destdir\""
fi
elif [ "$uninstall" = "true" ]; then
if [ -f "$file_with_destdir" ]; then
rm "$file_with_destdir"
fi
else
true "ERROR 2: in $FUNCNAME!"
exit 1
fi
done
fi
done
shopt -u globstar dotglob nullglob
if [ "$still_installed" = "true" ]; then
exit 1
fi
}
make_install() {
install_="true"
helper
}
make_installcheck() {
installcheck="true"
helper
}
make_installsim() {
installsim="true"
helper
}
make_uninstallcheck() {
uninstallcheck="true"
helper
}
make_uninstall() {
uninstall="true"
helper
}
make_uninstallsim() {
uninstallsim="true"
helper
}
make_deb-chl-bumpup() {
command -v debchange >/dev/null
get_variables
local new_upstream_version_without_leading_zero new_upstream_version new_changelog_version new_revision
new_upstream_version_without_leading_zero="$(bc -l <<< "scale=9 ; $version + 0.1")"
new_upstream_version="$(printf '%3.1f\n' "$new_upstream_version_without_leading_zero")"
new_revision="1"
new_changelog_version="$epoch:$new_upstream_version-$new_revision"
true "\
Bumping version from / to...
$changelog_version
$new_changelog_version"
if [ "$DEBEMAIL" = "" ]; then
export DEBEMAIL="adrelanos@riseup.net"
fi
debchange \
--newversion "$new_changelog_version" \
"New upstream version."
debchange \
--release \
""
}
parse_cmd ${1+"$@"}