-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakepkg.sh
executable file
·2354 lines (2030 loc) · 56 KB
/
makepkg.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
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
#
# minimal adaptation of archlinux's 'makepkg' for centos/rhel via fpm
# original:
# https://projects.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in
#
#
# makepkg - make packages compatible for use with pacman
# Generated from makepkg.sh.in; do not edit by hand.
#
# Copyright (c) 2006-2014 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/>.
#
# 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
# Ensure GREP_OPTIONS doesn't screw with our grep calls
unset GREP_OPTIONS
declare -r makepkg_version='4.2.1'
declare -r confdir='/etc'
declare -r BUILDSCRIPT='PKGBUILD'
declare -r startdir="$PWD"
packaging_options=('strip')
other_options=('ccache' 'distcc' 'buildflags' 'makeflags')
splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends'
'optdepends' 'provides' 'conflicts' 'replaces' 'backup'
'options' 'install' 'changelog')
readonly -a packaging_options other_options splitpkg_overrides
known_hash_algos=('md5' 'sha1' 'sha224' 'sha256' 'sha384' 'sha512')
# Options
BUILDFUNC=0
CHECKFUNC=0
CLEANBUILD=0
CLEANUP=0
FORCE=0
GENINTEG=0
INSTALL=0
LOGGING=0
NOARCHIVE=0
NOBUILD=0
NODEPS=0
NOEXTRACT=0
PKGFUNC=0
PKGLIST=()
PREPAREFUNC=0
REPKG=0
SKIPCHECKSUMS=0
SPLITPKG=0
VERIFYSOURCE=0
RPM_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 (( ! 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 "$pkgdirbase" "$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}-*-*-*{${PKGEXT},${SRCEXT}}; do
if [[ -h $file && ! -e $file ]]; then
rm -f "$file"
fi
done
done
fi
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
get_filepath() {
local file="$(get_filename "$1")"
local proto="$(get_protocol "$1")"
case $proto in
bzr*|git*|hg*|svn*)
if [[ -d "$startdir/$file" ]]; then
file="$startdir/$file"
elif [[ -d "$SRCDEST/$file" ]]; then
file="$SRCDEST/$file"
else
return 1
fi
;;
*)
if [[ -f "$startdir/$file" ]]; then
file="$startdir/$file"
elif [[ -f "$SRCDEST/$file" ]]; then
file="$SRCDEST/$file"
else
return 1
fi
;;
esac
printf "%s\n" "$file"
}
# extract the filename from a source entry
get_filename() {
local netfile=$1
# if a filename is specified, use it
if [[ $netfile = *::* ]]; then
printf "%s\n" ${netfile%%::*}
return
fi
local proto=$(get_protocol "$netfile")
case $proto in
bzr*|git*|hg*|svn*)
filename=${netfile%%#*}
filename=${filename%/}
filename=${filename##*/}
if [[ $proto = bzr* ]]; then
filename=${filename#*lp:}
fi
if [[ $proto = git* ]]; then
filename=${filename%%.git*}
fi
;;
*)
# if it is just an URL, we only keep the last component
filename="${netfile##*/}"
;;
esac
printf "%s\n" "${filename}"
}
# extract the URL from a source entry
get_url() {
# strip an eventual filename
printf "%s\n" "${1#*::}"
}
# extract the protocol from a source entry - return "local" for local sources
get_protocol() {
if [[ $1 = *://* ]]; then
# strip leading filename
local proto="${1#*::}"
printf "%s\n" "${proto%%://*}"
elif [[ $1 = *lp:* ]]; then
local proto="${1#*::}"
printf "%s\n" "${proto%%lp:*}"
else
printf "%s\n" local
fi
}
get_downloadclient() {
local proto=$1
# 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 "Unknown download protocol: %s")" "$proto"
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
printf "%s\n" "$agent"
}
download_local() {
local netfile=$1
local filepath=$(get_filepath "$netfile")
if [[ -n "$filepath" ]]; then
msg2 "$(gettext "Found %s")" "${filepath##*/}"
else
local filename=$(get_filename "$netfile")
error "$(gettext "%s was not found in the build directory and is not a URL.")" "$filename"
exit 1 # $E_MISSING_FILE
fi
}
download_file() {
local netfile=$1
local filepath=$(get_filepath "$netfile")
if [[ -n "$filepath" ]]; then
msg2 "$(gettext "Found %s")" "${filepath##*/}"
return
fi
local proto=$(get_protocol "$netfile")
# find the client we should use for this URL
local -a cmdline
IFS=' ' read -a cmdline < <(get_downloadclient "$proto")
(( ${#cmdline[@]} )) || exit
local filename=$(get_filename "$netfile")
local url=$(get_url "$netfile")
if [[ $proto = "scp" ]]; then
# scp downloads should not pass the protocol in the url
url="${url##*://}"
fi
msg2 "$(gettext "Downloading %s...")" "$filename"
# temporary download file, default to last component of the URL
local dlfile="${url##*/}"
# replace %o by the temporary dlfile if it exists
if [[ ${cmdline[*]} = *%o* ]]; then
dlfile=$filename.part
cmdline=("${cmdline[@]//%o/$dlfile}")
fi
# add the URL, either in place of %u or at the end
if [[ ${cmdline[*]} = *%u* ]]; then
cmdline=("${cmdline[@]//%u/$url}")
else
cmdline+=("$url")
fi
if ! command -- "${cmdline[@]}" >&2; then
[[ ! -s $dlfile ]] && rm -f -- "$dlfile"
error "$(gettext "Failure while downloading %s")" "$filename"
plain "$(gettext "Aborting...")"
exit 1
fi
# rename the temporary download file to the final destination
if [[ $dlfile != "$filename" ]]; then
mv -f "$SRCDEST/$dlfile" "$SRCDEST/$filename"
fi
}
extract_file() {
local file=$1
local filepath=$(get_filepath "$file")
rm -f "$srcdir/${file}"
ln -s "$filepath" "$srcdir/"
if in_array "$file" "${noextract[@]}"; then
# skip source files in the noextract=() array
# these are marked explicitly to NOT be extracted
return 0
fi
# do not rely on extension for file type
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*)
case "$ext" in
zip) cmd="unzip" ;;
*) cmd="tar" ;;
esac ;;
*application/x-gzip*)
case "$ext" in
gz|z|Z) cmd="gzip" ;;
*) return;;
esac ;;
*application/x-bzip*)
case "$ext" in
bz2|bz) cmd="bzip2" ;;
*) return;;
esac ;;
*application/x-xz*)
case "$ext" in
xz) cmd="xz" ;;
*) return;;
esac ;;
*)
# See if bsdtar can recognize the file
if tar -taf "$file" -q '*' &>/dev/null; then
cmd="tar"
else
return 0
fi ;;
esac
local ret=0
msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
if [[ $cmd = "tar" ]]; then
$cmd -xaf "$file" || ret=$?
elif [[ $cmd = "unzip" ]]; then
$cmd -qo "$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
if (( EUID == 0 )); then
# change perms of all source files to root user & root group
chown -R 0:0 "$srcdir"
fi
}
download_bzr() {
local netfile=$1
local url=$(get_url "$netfile")
if [[ $url != bzr+ssh* ]]; then
url=${url#bzr+}
fi
url=${url%%#*}
local repo=$(get_filename "$netfile")
local displaylocation="$url"
local dir=$(get_filepath "$netfile")
[[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
msg2 "$(gettext "Branching %s ...")" "${displaylocation}"
if ! bzr branch "$url" "$dir" --no-tree --use-existing-dir; then
error "$(gettext "Failure while branching %s")" "${displaylocation}"
plain "$(gettext "Aborting...")"
exit 1
fi
elif (( ! HOLDVER )); then
msg2 "$(gettext "Pulling %s ...")" "${displaylocation}"
cd_safe "$dir"
if ! bzr pull "$url"; then
# only warn on failure to allow offline builds
warning "$(gettext "Failure while pulling %s")" "${displaylocation}"
fi
fi
}
extract_bzr() {
local netfile=$1
local repo=$(get_filename "$netfile")
local fragment=${netfile#*#}
if [[ $fragment = "$netfile" ]]; then
unset fragment
fi
rev="last:1"
if [[ -n $fragment ]]; then
case ${fragment%%=*} in
revision)
rev="${fragment#*=}"
displaylocation="$url -r ${fragment#*=}"
;;
*)
error "$(gettext "Unrecognized reference: %s")" "${fragment}"
plain "$(gettext "Aborting...")"
exit 1
esac
fi
local dir=$(get_filepath "$netfile")
[[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "bzr"
pushd "$srcdir" &>/dev/null
if [[ -d "${dir##*/}" ]]; then
cd_safe "${dir##*/}"
if ! (bzr pull "$dir" -q --overwrite -r "$rev" && bzr clean-tree -q --detritus --force); then
error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "bzr"
plain "$(gettext "Aborting...")"
exit 1
fi
elif ! bzr checkout "$dir" -r "$rev"; then
error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "bzr"
plain "$(gettext "Aborting...")"
exit 1
fi
popd &>/dev/null
}
download_git() {
local netfile=$1
local dir=$(get_filepath "$netfile")
[[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
local repo=$(get_filename "$netfile")
local url=$(get_url "$netfile")
url=${url#git+}
url=${url%%#*}
if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git"
if ! git clone --mirror "$url" "$dir"; then
error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
plain "$(gettext "Aborting...")"
exit 1
fi
elif (( ! HOLDVER )); then
cd_safe "$dir"
# Make sure we are fetching the right repo
if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then
error "$(gettext "%s is not a clone of %s")" "$dir" "$url"
plain "$(gettext "Aborting...")"
exit 1
fi
msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git"
if ! git fetch --all -p; then
# only warn on failure to allow offline builds
warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git"
fi
fi
}
extract_git() {
local netfile=$1
local fragment=${netfile#*#}
if [[ $fragment = "$netfile" ]]; then
unset fragment
fi
local repo=${netfile##*/}
repo=${repo%%#*}
repo=${repo%%.git*}
local dir=$(get_filepath "$netfile")
[[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "git"
pushd "$srcdir" &>/dev/null
local updating=0
if [[ -d "${dir##*/}" ]]; then
updating=1
cd_safe "${dir##*/}"
if ! git fetch; then
error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "git"
plain "$(gettext "Aborting...")"
exit 1
fi
cd_safe "$srcdir"
elif ! git clone "$dir" "${dir##*/}"; then
error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git"
plain "$(gettext "Aborting...")"
exit 1
fi
cd_safe "${dir##*/}"
local ref=origin/HEAD
if [[ -n $fragment ]]; then
case ${fragment%%=*} in
commit|tag)
ref=${fragment##*=}
;;
branch)
ref=origin/${fragment##*=}
;;
*)
error "$(gettext "Unrecognized reference: %s")" "${fragment}"
plain "$(gettext "Aborting...")"
exit 1
esac
fi
if [[ $ref != "origin/HEAD" ]] || (( updating )) ; then
if ! git branch -f --no-track makepkg $ref; then
error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git"
plain "$(gettext "Aborting...")"
exit 1
fi
if ! git checkout makepkg; then
error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git"
plain "$(gettext "Aborting...")"
exit 1
fi
fi
popd &>/dev/null
}
download_hg() {
local netfile=$1
local dir=$(get_filepath "$netfile")
[[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
local repo=$(get_filename "$netfile")
local url=$(get_url "$netfile")
url=${url#hg+}
url=${url%%#*}
if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "hg"
if ! hg clone -U "$url" "$dir"; then
error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "hg"
plain "$(gettext "Aborting...")"
exit 1
fi
elif (( ! HOLDVER )); then
msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "hg"
cd_safe "$dir"
if ! hg pull; then
# only warn on failure to allow offline builds
warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "hg"
fi
fi
}
extract_hg() {
local netfile=$1
local fragment=${netfile#*#}
if [[ $fragment = "$netfile" ]]; then
unset fragment
fi
local dir=$(get_filepath "$netfile")
[[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
local repo=${netfile##*/}
repo=${repo%%#*}
msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "hg"
pushd "$srcdir" &>/dev/null
local ref=tip
if [[ -n $fragment ]]; then
case ${fragment%%=*} in
branch|revision|tag)
ref="${fragment##*=}"
;;
*)
error "$(gettext "Unrecognized reference: %s")" "${fragment}"
plain "$(gettext "Aborting...")"
exit 1
esac
fi
if [[ -d "${dir##*/}" ]]; then
cd_safe "${dir##*/}"
if ! (hg pull && hg update -C -r "$ref"); then
error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "hg"
plain "$(gettext "Aborting...")"
exit 1
fi
elif ! hg clone -u "$ref" "$dir" "${dir##*/}"; then
error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "hg"
plain "$(gettext "Aborting...")"
exit 1
fi
popd &>/dev/null
}
download_svn() {
local netfile=$1
local fragment=${netfile#*#}
if [[ $fragment = "$netfile" ]]; then
unset fragment
fi
local dir=$(get_filepath "$netfile")
[[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
local repo=$(get_filename "$netfile")
local url=$(get_url "$netfile")
if [[ $url != svn+ssh* ]]; then
url=${url#svn+}
fi
url=${url%%#*}
local ref=HEAD
if [[ -n $fragment ]]; then
case ${fragment%%=*} in
revision)
ref="${fragment##*=}"
;;
*)
error "$(gettext "Unrecognized reference: %s")" "${fragment}"
plain "$(gettext "Aborting...")"
exit 1
esac
fi
if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn"
mkdir -p "$dir/.makepkg"
if ! svn checkout -r ${ref} --config-dir "$dir/.makepkg" "$url" "$dir"; then
error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn"
plain "$(gettext "Aborting...")"
exit 1
fi
elif (( ! HOLDVER )); then
msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "svn"
cd_safe "$dir"
if ! svn update -r ${ref}; then
# only warn on failure to allow offline builds
warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn"
fi
fi
}
extract_svn() {
local netfile=$1
local dir=$(get_filepath "$netfile")
[[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
local repo=${netfile##*/}
repo=${repo%%#*}
msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "svn"
cp -au "$dir" "$srcdir"
}
get_all_sources() {
local aggregate l a
if array_build l 'source'; then
aggregate+=("${l[@]}")
fi
for a in "${arch[@]}"; do
if array_build l "source_$a"; then
aggregate+=("${l[@]}")
fi
done
array_build "$1" "aggregate"
}
get_all_sources_for_arch() {
local aggregate l
if array_build l 'source'; then
aggregate+=("${l[@]}")
fi
if array_build l "source_$CARCH"; then
aggregate+=("${l[@]}")
fi
array_build "$1" "aggregate"
}
download_sources() {
local netfile all_sources
local get_source_fn=get_all_sources_for_arch get_vcs=1
msg "$(gettext "Retrieving sources...")"
while true; do
case $1 in
allarch)
get_source_fn=get_all_sources
;;
novcs)
get_vcs=0
;;
*)
break 2
;;
esac
shift
done
"$get_source_fn" 'all_sources'
for netfile in "${all_sources[@]}"; do
pushd "$SRCDEST" &>/dev/null
local proto=$(get_protocol "$netfile")
case "$proto" in
local)
download_local "$netfile"
;;
bzr*)
(( get_vcs )) && download_bzr "$netfile"
;;
git*)
(( get_vcs )) && download_git "$netfile"
;;
hg*)
(( get_vcs )) && download_hg "$netfile"
;;
svn*)
(( get_vcs )) && download_svn "$netfile"
;;
*)
download_file "$netfile"
;;
esac
popd &>/dev/null
done
}
# 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
}
##
# usage : get_full_version()
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
get_full_version() {
if [[ "$RPM_DIST" = "" ]]; then
local trailer=''
else
local trailer=".$RPM_DIST"
fi
if (( epoch > 0 )); then
printf "%s\n" "$epoch:$pkgver-$pkgrel$trailer"
else
printf "%s\n" "$pkgver-$pkgrel$trailer"
fi
}
##
# usage : get_pkg_arch( [$pkgname] )
# return : architecture of the package
##
get_pkg_arch() {
if [[ -z $1 ]]; then
if [[ $arch = "any" ]]; then
printf "%s\n" "noarch"
else
printf "%s\n" "$CARCH"
fi
else
local arch_override
pkgbuild_get_attribute "$1" arch 0 arch_override
(( ${#arch_override[@]} == 0 )) && arch_override=("${arch[@]}")
if [[ $arch_override = "any" ]]; then
printf "%s\n" "noarch"
else
printf "%s\n" "$CARCH"
fi
fi
}
##
# Checks to see if options are present in makepkg.conf or PKGBUILD;
# PKGBUILD options always take precedence.
#
# usage : check_option( $option, $expected_val )
# return : 0 - matches expected
# 1 - does not match expected
# 127 - not found
##
check_option() {
in_opt_array "$1" ${options[@]}
case $? in
0) # assert enabled
[[ $2 = y ]]
return ;;
1) # assert disabled
[[ $2 = n ]]
return
esac
# fall back to makepkg.conf options
in_opt_array "$1" ${OPTIONS[@]}
case $? in
0) # assert enabled
[[ $2 = y ]]
return ;;
1) # assert disabled
[[ $2 = n ]]
return
esac
# not found
return 127
}
##
# Check if option is present in BUILDENV
#
# usage : check_buildenv( $option, $expected_val )
# return : 0 - matches expected
# 1 - does not match expected
# 127 - not found
##
check_buildenv() {
in_opt_array "$1" ${BUILDENV[@]}
case $? in
0) # assert enabled
[[ $2 = "y" ]]
return ;;
1) # assert disabled
[[ $2 = "n" ]]
return ;;
esac
# not found
return 127
}
##
# usage : in_opt_array( $needle, $haystack )
# return : 0 - enabled
# 1 - disabled
# 127 - not found
##
in_opt_array() {
local needle=$1; shift
local i opt
for (( i = $#; i > 0; i-- )); do
opt=${!i}
if [[ $opt = "$needle" ]]; then
# enabled
return 0
elif [[ $opt = "!$needle" ]]; then
# disabled
return 1
fi
done
# not found
return 127
}
##
# 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 all_sources
get_all_sources_for_arch 'all_sources'
for file in "${all_sources[@]}"; do
if [[ ${file%%::*} = *.@(sig?(n)|asc) ]]; then
return 0
fi
done
return 1
}
run_rpm() {
local cmd
if [[ "$1" = "install" ]]; then
cmd=("$RPM_PATH" $RPM_OPTS "$@")
else
cmd=("$RPM_PATH" "$@")
fi
if [[ $1 != -@(T|Qq) ]]; then
if type -p sudo >/dev/null; then
cmd=(sudo "${cmd[@]}")
else
cmd=(su root -c "$(printf '%q ' "${cmd[@]}")")
fi
fi
"${cmd[@]}"
}
get_integlist() {
local integ
local integlist=()