forked from matthewbauer/unipkg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunipkg.sh.in
executable file
·2802 lines (2461 loc) · 75.6 KB
/
unipkg.sh.in
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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash -e
# unipkg - make package for different distros using a single PKGBUILD file
#
# Copyright (c) 2012 by Abilng <[email protected]>
# Copyright (c) 2011 by Matthew Bauer <[email protected]>
#
# unipkg is a makepkg fork that can also compile
# to other package formats like debian and rpm(eventually).
#
# ===========================MAKEPKG===========================
#
# makepkg - make packages compatible for use with pacman
# Generated from makepkg.sh.in; do not edit by hand.
#
# Copyright (c) 2006-2012 Pacman Development Team <[email protected]>
# Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
# Copyright (c) 2005 by Aurelien Foret <[email protected]>
# Copyright (c) 2006 by Miklos Vajna <[email protected]>
# Copyright (c) 2005 by Christian Hamar <[email protected]>
# Copyright (c) 2006 by Alex Smith <[email protected]>
# Copyright (c) 2006 by Andras Voroskoi <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# makepkg uses quite a few external programs during its execution. You
# need to have at least the following installed for makepkg to function:
# awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
# gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
# gettext initialization
export TEXTDOMAIN='pacman-scripts'
export TEXTDOMAINDIR='/usr/share/locale'
# file -i does not work on Mac OSX unless legacy mode is set
export COMMAND_MODE='legacy'
# Ensure CDPATH doesn't screw with our cd calls
unset CDPATH
myver='4.0.3'
confdir='/etc'
BUILDSCRIPT='PKGBUILD'
startdir="$PWD"
packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx')
other_options=('ccache' 'distcc' 'buildflags' 'makeflags')
splitpkg_overrides=('pkgver' 'pkgrel' 'epoch' 'pkgdesc' 'arch' 'license' \
'groups' 'depends' 'optdepends' 'provides' 'conflicts' \
'replaces' 'backup' 'options' 'install' 'changelog')
deb_subst=('avahi' 'avahi-daemon'\
'python2' 'python'\
'python2-pyserial' 'pyserial')
readonly -a packaging_options other_options splitpkg_overrides
# Options
ASROOT=0
CLEANUP=0
DEP_BIN=0
FORCE=0
INFAKEROOT=0
GENINTEG=0
SKIPCHECKSUMS=0
SKIPPGPCHECK=0
INSTALL=0
NOBUILD=0
NODEPS=0
NOEXTRACT=0
RMDEPS=0
REPKG=0
LOGGING=0
SOURCEONLY=0
IGNOREARCH=0
HOLDVER=0
BUILDFUNC=0
CHECKFUNC=0
PKGFUNC=0
SPLITPKG=0
PKGLIST=()
SIGNPKG=''
# Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
# when dealing with svn/cvs/etc PKGBUILDs.
FORCE_VER=""
PACMAN_OPTS=
shopt -s extglob
### SUBROUTINES ###
plain() {
local mesg=$1; shift
printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
msg() {
local mesg=$1; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
msg2() {
local mesg=$1; shift
printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
warning() {
local mesg=$1; shift
printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
error() {
local mesg=$1; shift
printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
##
# Special exit call for traps, Don't print any error messages when inside,
# the fakeroot call, the error message will be printed by the main call.
##
trap_exit() {
local signal=$1; shift
if (( ! INFAKEROOT )); then
echo
error "$@"
fi
[[ -n $srclinks ]] && rm -rf "$srclinks"
# unset the trap for this signal, and then call the default handler
trap -- "$signal"
kill "-$signal" "$$"
}
##
# Clean up function. Called automatically when the script exits.
##
clean_up() {
local EXIT_CODE=$?
if (( INFAKEROOT )); then
# Don't clean up when leaving fakeroot, we're not done yet.
return
fi
if (( ! EXIT_CODE && CLEANUP )); then
local pkg file
# If it's a clean exit and -c/--clean has been passed...
msg "$(gettext "Cleaning up...")"
rm -rf "$pkgdir" "$srcdir"
if [[ -n $pkgbase ]]; then
local fullver=$(get_full_version)
# Can't do this unless the BUILDSCRIPT has been sourced.
if (( BUILDFUNC )); then
rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
fi
if (( CHECKFUNC )); then
rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
fi
if (( PKGFUNC )); then
rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
elif (( SPLITPKG )); then
for pkg in ${pkgname[@]}; do
rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
done
fi
# clean up dangling symlinks to packages
for pkg in ${pkgname[@]}; do
for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
if [[ -h $file && ! -e $file ]]; then
rm -f "$file"
fi
done
done
fi
fi
remove_deps
}
##
# Signal Traps
##
set -E
trap 'clean_up' 0
trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
enter_fakeroot() {
msg "$(gettext "Entering %s environment...")" "fakeroot"
if [[ -n $newpkgver ]]; then
fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
else
fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
fi
}
# a source entry can have two forms :
# 1) "filename::http://path/to/file"
# 2) "http://path/to/file"
# Return the absolute filename of a source entry
#
# This function accepts a source entry or the already extracted filename of a
# source entry as input
get_filepath() {
local file="$(get_filename "$1")"
if [[ -f "$startdir/$file" ]]; then
file="$startdir/$file"
elif [[ -f "$SRCDEST/$file" ]]; then
file="$SRCDEST/$file"
else
return 1
fi
echo "$file"
}
# Print 'source not found' error message and exit makepkg
missing_source_file() {
error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
plain "$(gettext "Aborting...")"
exit 1 # $E_MISSING_FILE
}
# extract the filename from a source entry
get_filename() {
# if a filename is specified, use it
local filename="${1%%::*}"
# if it is just an URL, we only keep the last component
echo "${filename##*/}"
}
# extract the URL from a source entry
get_url() {
# strip an eventual filename
echo "${1#*::}"
}
##
# usage : get_full_version( [$pkgname] )
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
get_full_version() {
if [[ -z $1 ]]; then
if [[ $epoch ]] && (( ! $epoch )); then
echo $pkgver-$pkgrel
else
echo $epoch:$pkgver-$pkgrel
fi
else
for i in pkgver pkgrel epoch; do
local indirect="${i}_override"
eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p")
[[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\"
done
if (( ! $epoch_override )); then
echo $pkgver_override-$pkgrel_override
else
echo $epoch_override:$pkgver_override-$pkgrel_override
fi
fi
}
##
# Checks to see if options are present in makepkg.conf or PKGBUILD;
# PKGBUILD options always take precedence.
#
# usage : check_option( $option )
# return : y - enabled
# n - disabled
# ? - not found
##
check_option() {
local ret=$(in_opt_array "$1" ${options[@]})
if [[ $ret != '?' ]]; then
echo $ret
return
fi
# fall back to makepkg.conf options
ret=$(in_opt_array "$1" ${OPTIONS[@]})
if [[ $ret != '?' ]]; then
echo $ret
return
fi
echo '?' # Not Found
}
##
# Check if option is present in BUILDENV
#
# usage : check_buildenv( $option )
# return : y - enabled
# n - disabled
# ? - not found
##
check_buildenv() {
in_opt_array "$1" ${BUILDENV[@]}
}
##
# usage : in_opt_array( $needle, $haystack )
# return : y - enabled
# n - disabled
# ? - not found
##
in_opt_array() {
local needle=$1; shift
local opt
for opt in "$@"; do
if [[ $opt = $needle ]]; then
echo 'y' # Enabled
return
elif [[ $opt = "!$needle" ]]; then
echo 'n' # Disabled
return
fi
done
echo '?' # Not Found
}
##
# usage : in_array( $needle, $haystack )
# return : 0 - found
# 1 - not found
##
in_array() {
local needle=$1; shift
local item
for item in "$@"; do
[[ $item = $needle ]] && return 0 # Found
done
return 1 # Not Found
}
source_has_signatures(){
local file
for file in "${source[@]}"; do
if [[ $file = *.@(sig?(n)|asc) ]]; then
return 0
fi
done
return 1
}
get_downloadclient() {
# $1 = URL with valid protocol prefix
local url=$1
local proto="${url%%://*}"
# loop through DOWNLOAD_AGENTS variable looking for protocol
local i
for i in "${DLAGENTS[@]}"; do
local handler="${i%%::*}"
if [[ $proto = $handler ]]; then
local agent="${i##*::}"
break
fi
done
# if we didn't find an agent, return an error
if [[ -z $agent ]]; then
error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
plain "$(gettext "Aborting...")"
exit 1 # $E_CONFIG_ERROR
fi
# ensure specified program is installed
local program="${agent%% *}"
if [[ ! -x $program ]]; then
local baseprog="${program##*/}"
error "$(gettext "The download program %s is not installed.")" "$baseprog"
plain "$(gettext "Aborting...")"
exit 1 # $E_MISSING_PROGRAM
fi
echo "$agent"
}
download_file() {
# download command
local dlcmd=$1
# URL of the file
local url=$2
# destination file
local file=$3
# temporary download file, default to last component of the URL
local dlfile="${url##*/}"
# replace %o by the temporary dlfile if it exists
if [[ $dlcmd = *%o* ]]; then
dlcmd=${dlcmd//\%o/\"$file.part\"}
dlfile="$file.part"
fi
# add the URL, either in place of %u or at the end
if [[ $dlcmd = *%u* ]]; then
dlcmd=${dlcmd//\%u/\"$url\"}
else
dlcmd="$dlcmd \"$url\""
fi
local ret=0
eval "$dlcmd || ret=\$?"
if (( ret )); then
[[ ! -s $dlfile ]] && rm -f -- "$dlfile"
return $ret
fi
# rename the temporary download file to the final destination
if [[ $dlfile != "$file" ]]; then
mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
fi
}
run_pacman() {
local cmd
if [[ ! $1 = -@(T|Qq) ]]; then
printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
else
printf -v cmd "%q " "$PACMAN" "$@"
fi
if (( ! ASROOT )) && [[ ! $1 = -@(T|Qq) ]]; then
if type -p sudo >/dev/null; then
cmd="sudo $cmd"
else
cmd="su root -c '$cmd'"
fi
fi
eval "$cmd"
}
check_deps() {
(( $# > 0 )) || return 0
# Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
# Also, a non-zero return value is not unexpected and we are manually dealing them
set +E
local ret=0
local pmout
pmout=$(run_pacman -T "$@") || ret=$?
set -E
if (( ret == 127 )); then #unresolved deps
echo "$pmout"
elif (( ret )); then
error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
return "$ret"
fi
}
handle_deps() {
local R_DEPS_SATISFIED=0
local R_DEPS_MISSING=1
(( $# == 0 )) && return $R_DEPS_SATISFIED
local deplist="$*"
if (( ! DEP_BIN )); then
return $R_DEPS_MISSING
fi
if (( DEP_BIN )); then
# install missing deps from binary packages (using pacman -S)
msg "$(gettext "Installing missing dependencies...")"
if ! run_pacman -S --asdeps $deplist; then
error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
exit 1 # TODO: error code
fi
fi
# we might need the new system environment
# avoid triggering the ERR trap and exiting
set +e
local restoretrap=$(trap -p ERR)
trap - ERR
source /etc/profile &>/dev/null
eval $restoretrap
set -e
return $R_DEPS_SATISFIED
}
resolve_deps() {
local R_DEPS_SATISFIED=0
local R_DEPS_MISSING=1
# deplist cannot be declared like this: local deplist=$(foo)
# Otherwise, the return value will depend on the assignment.
local deplist
deplist="$(set +E; check_deps $*)" || exit 1
[[ -z $deplist ]] && return $R_DEPS_SATISFIED
if handle_deps $deplist; then
# check deps again to make sure they were resolved
deplist="$(set +E; check_deps $*)" || exit 1
[[ -z $deplist ]] && return $R_DEPS_SATISFIED
fi
msg "$(gettext "Missing Dependencies:")"
local dep
for dep in $deplist; do
msg2 "$dep"
done
#Skipping runtime dependency checks for Debian Pakage.
case "$PKGEXT" in
*.pkg.*)
return $R_DEPS_MISSING;;
*.deb)
msg "$(gettext "Debian pkg:Skipping runtime dependency checks.... ")"
return $R_DEPS_SATISFIED ;;
esac
}
remove_deps() {
(( ! RMDEPS )) && return
# check for packages removed during dependency install (e.g. due to conflicts)
# removing all installed packages is risky in this case
if [[ -n $(grep -xvFf <(printf '%s\n' "${current_packagelist[@]}") \
<(printf '%s\n' "${original_packagelist[@]}") || true) ]]; then
warning "$(gettext "Failed to remove installed dependencies.")"
return 0
fi
local deplist
deplist=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \
<(printf "%s\n" "${current_pkglist[@]}") || true))
if [[ -z $deplist ]]; then
return
fi
msg "Removing installed dependencies..."
# exit cleanly on failure to remove deps as package has been built successfully
if ! run_pacman -Rn ${deplist[@]}; then
warning "$(gettext "Failed to remove installed dependencies.")"
return 0
fi
}
download_sources() {
msg "$(gettext "Retrieving Sources...")"
pushd "$SRCDEST" &>/dev/null
local netfile
for netfile in "${source[@]}"; do
local file=$(get_filepath "$netfile" || true)
if [[ -n "$file" ]]; then
msg2 "$(gettext "Found %s")" "${file##*/}"
rm -f "$srcdir/${file##*/}"
ln -s "$file" "$srcdir/"
continue
fi
file=$(get_filename "$netfile")
local url=$(get_url "$netfile")
# if we get here, check to make sure it was a URL, else fail
if [[ $file = $url ]]; then
error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
exit 1 # $E_MISSING_FILE
fi
# find the client we should use for this URL
local dlclient
dlclient=$(get_downloadclient "$url") || exit $?
msg2 "$(gettext "Downloading %s...")" "$file"
# fix flyspray bug #3289
local ret=0
download_file "$dlclient" "$url" "$file" || ret=$?
if (( ret )); then
error "$(gettext "Failure while downloading %s")" "$file"
plain "$(gettext "Aborting...")"
exit 1
fi
rm -f "$srcdir/$file"
ln -s "$SRCDEST/$file" "$srcdir/"
done
popd &>/dev/null
}
get_integlist() {
local integ
local integlist=()
for integ in md5 sha1 sha256 sha384 sha512; do
local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
if [[ -n "$integrity_sums" ]]; then
integlist=(${integlist[@]} $integ)
fi
done
if (( ${#integlist[@]} > 0 )); then
echo ${integlist[@]}
else
echo ${INTEGRITY_CHECK[@]}
fi
}
generate_checksums() {
msg "$(gettext "Generating checksums for source files...")"
plain ""
if ! type -p openssl >/dev/null; then
error "$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl"
exit 1 # $E_MISSING_PROGRAM
fi
local integlist
if (( $# == 0 )); then
integlist=$(get_integlist)
else
integlist=$@
fi
local integ
for integ in ${integlist[@]}; do
case "$integ" in
md5|sha1|sha256|sha384|sha512) : ;;
*)
error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
exit 1;; # $E_CONFIG_ERROR
esac
local ct=0
local numsrc=${#source[@]}
echo -n "${integ}sums=("
local i
local indent=''
for (( i = 0; i < ${#integ} + 6; i++ )); do
indent="$indent "
done
local netfile
for netfile in "${source[@]}"; do
local file
file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
local sum="$(openssl dgst -${integ} "$file")"
sum=${sum##* }
(( ct )) && echo -n "$indent"
echo -n "'$sum'"
ct=$(($ct+1))
(( $ct < $numsrc )) && echo
done
echo ")"
done
}
check_checksums() {
(( SKIPCHECKSUMS )) && return 0
(( ! ${#source[@]} )) && return 0
local correlation=0
local integ required
for integ in md5 sha1 sha256 sha384 sha512; do
local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
if (( ${#integrity_sums[@]} == ${#source[@]} )); then
msg "$(gettext "Validating source files with %s...")" "${integ}sums"
correlation=1
local errors=0
local idx=0
local file
for file in "${source[@]}"; do
local found=1
file="$(get_filename "$file")"
echo -n " $file ... " >&2
if ! file="$(get_filepath "$file")"; then
printf -- "$(gettext "NOT FOUND")\n" >&2
errors=1
found=0
fi
if (( $found )) ; then
local expectedsum=$(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
local realsum="$(openssl dgst -${integ} "$file")"
realsum="${realsum##* }"
if [[ $expectedsum = $realsum ]]; then
printf -- "$(gettext "Passed")\n" >&2
else
printf -- "$(gettext "FAILED")\n" >&2
errors=1
fi
fi
idx=$((idx + 1))
done
if (( errors )); then
error "$(gettext "One or more files did not pass the validity check!")"
exit 1 # TODO: error code
fi
elif (( ${#integrity_sums[@]} )); then
error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
exit 1 # TODO: error code
fi
done
if (( ! correlation )); then
error "$(gettext "Integrity checks are missing.")"
exit 1 # TODO: error code
fi
}
check_pgpsigs() {
(( SKIPPGPCHECK )) && return 0
! source_has_signatures && return 0
msg "$(gettext "Verifying source file signatures with %s...")" "gpg"
local file pubkey
local warning=0
local errors=0
local statusfile=$(mktemp)
for file in "${source[@]}"; do
file="$(get_filename "$file")"
if [[ ! $file = *.@(sig?(n)|asc) ]]; then
continue
fi
printf " %s ... " "${file%.*}" >&2
if ! file="$(get_filepath "$file")"; then
printf '%s\n' "$(gettext "SIGNATURE NOT FOUND")" >&2
errors=1
continue
fi
if ! sourcefile="$(get_filepath "${file%.*}")"; then
printf '%s\n' "$(gettext "SOURCE FILE NOT FOUND")" >&2
errors=1
continue
fi
if ! gpg --quiet --batch --status-file "$statusfile" --verify "$file" "$sourcefile" 2> /dev/null; then
printf '%s' "$(gettext "FAILED")" >&2
if ! pubkey=$(awk '/NO_PUBKEY/ { print $3; exit 1; }' "$statusfile"); then
printf ' (%s)' "$(gettext "unknown public key") $pubkey" >&2
warnings=1
else
errors=1
fi
printf '\n' >&2
else
if grep -q "REVKEYSIG" "$statusfile"; then
printf '%s (%s)' "$(gettext "FAILED")" "$(gettext "the key has been revoked.")" >&2
errors=1
else
printf '%s' "$(gettext "Passed")" >&2
if grep -q "EXPSIG" "$statusfile"; then
printf ' (%s)' "$(gettext "WARNING:") $(gettext "the signature has expired.")" >&2
warnings=1
elif grep -q "EXPKEYSIG" "$statusfile"; then
printf ' (%s)' "$(gettext "WARNING:") $(gettext "the key has expired.")" >&2
warnings=1
fi
fi
printf '\n' >&2
fi
done
rm -f "$statusfile"
if (( errors )); then
error "$(gettext "One or more PGP signatures could not be verified!")"
exit 1
fi
if (( warnings )); then
warning "$(gettext "Warnings have occurred while verifying the signatures.")"
plain "$(gettext "Please make sure you really trust them.")"
fi
}
check_source_integrity() {
if (( SKIPCHECKSUMS && SKIPPGPCHECK )); then
warning "$(gettext "Skipping all source file integrity checks.")"
elif (( SKIPCHECKSUMS )); then
warning "$(gettext "Skipping verification of source file checksums.")"
check_pgpsigs
elif (( SKIPPGPCHECK )); then
warning "$(gettext "Skipping verification of source file PGP signatures.")"
check_checksums
else
check_checksums
check_pgpsigs
fi
}
extract_sources() {
msg "$(gettext "Extracting Sources...")"
local netfile
for netfile in "${source[@]}"; do
local file=$(get_filename "$netfile")
if in_array "$file" "${noextract[@]}"; then
#skip source files in the noextract=() array
# these are marked explicitly to NOT be extracted
continue
fi
# fix flyspray #6246
local file_type=$(file -bizL "$file")
local ext=${file##*.}
local cmd=''
case "$file_type" in
*application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
cmd="bsdtar" ;;
*application/x-gzip*)
case "$ext" in
gz|z|Z) cmd="gzip" ;;
*) continue;;
esac ;;
*application/x-bzip*)
case "$ext" in
bz2|bz) cmd="bzip2" ;;
*) continue;;
esac ;;
*application/x-xz*)
case "$ext" in
xz) cmd="xz" ;;
*) continue;;
esac ;;
*)
# See if bsdtar can recognize the file
if bsdtar -tf "$file" -q '*' &>/dev/null; then
cmd="bsdtar"
else
continue
fi ;;
esac
local ret=0
msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
if [[ $cmd = bsdtar ]]; then
$cmd -xf "$file" || ret=$?
else
rm -f "${file%.*}"
$cmd -dcf "$file" > "${file%.*}" || ret=$?
fi
if (( ret )); then
error "$(gettext "Failed to extract %s")" "$file"
plain "$(gettext "Aborting...")"
exit 1
fi
done
if (( EUID == 0 )); then
# change perms of all source files to root user & root group
chown -R 0:0 "$srcdir"
fi
}
error_function() {
if [[ -p $logpipe ]]; then
rm "$logpipe"
fi
# first exit all subshells, then print the error
if (( ! BASH_SUBSHELL )); then
error "$(gettext "A failure occurred in %s().")" "$1"
plain "$(gettext "Aborting...")"
remove_deps
fi
exit 2 # $E_BUILD_FAILED
}
run_function() {
if [[ -z $1 ]]; then
return 1
fi
local pkgfunc="$1"
# clear user-specified buildflags if requested
if [[ $(check_option buildflags) = "n" ]]; then
unset CFLAGS CXXFLAGS LDFLAGS
fi
# clear user-specified makeflags if requested
if [[ $(check_option makeflags) = "n" ]]; then
unset MAKEFLAGS
fi
msg "$(gettext "Starting %s()...")" "$pkgfunc"
cd "$srcdir"
# ensure all necessary build variables are exported
export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
# save our shell options so pkgfunc() can't override what we need
local shellopts=$(shopt -p)
local ret=0
local restoretrap
if (( LOGGING )); then
local fullver=$(get_full_version)
local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
if [[ -f $BUILDLOG ]]; then
local i=1
while true; do
if [[ -f $BUILDLOG.$i ]]; then
i=$(($i +1))
else
break
fi
done
mv "$BUILDLOG" "$BUILDLOG.$i"
fi
# ensure overridden package variables survive tee with split packages
logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
mkfifo "$logpipe"
tee "$BUILDLOG" < "$logpipe" &
local teepid=$!
restoretrap=$(trap -p ERR)
trap 'error_function $pkgfunc' ERR
$pkgfunc &>"$logpipe"
eval $restoretrap
wait $teepid
rm "$logpipe"
else
restoretrap=$(trap -p ERR)
trap 'error_function $pkgfunc' ERR
$pkgfunc 2>&1
eval $restoretrap
fi
# reset our shell options
eval "$shellopts"
}
run_build() {
# use distcc if it is requested (check buildenv and PKGBUILD opts)
if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
[[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH"
export DISTCC_HOSTS
fi
# use ccache if it is requested (check buildenv and PKGBUILD opts)
if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
[[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
fi
run_function "build"
}
run_check() {
run_function "check"
}
run_package() {
local pkgfunc
if [[ -z $1 ]]; then
pkgfunc="package"
else
pkgfunc="package_$1"
fi
run_function "$pkgfunc"
}
tidy_install() {
cd "$pkgdir"
msg "$(gettext "Tidying install...")"
if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
msg2 "$(gettext "Removing doc files...")"