-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaur2ccr-unstable
executable file
·870 lines (826 loc) · 38.2 KB
/
aur2ccr-unstable
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
#!/bin/bash
# aur2ccr - version 0.7.3
# Pull information from AUR or Arch repos, and make source packages that are ready for uploading to CCR.
# Usage: aur2ccr [OPTIONS] [PACKAGES]
# -- CREDITS --
# This script uses the information on converting Arch/AUR files to CCR from http://chakra-linux.org/wiki/index.php/How_to_upload_a_package_to_CCR_when_it_exists_on_Arch_or_Aur
# Portions of this script have been taken from "CCR - A Chakra Community Repository helper", which was in turn forked from "Packer by Matthew Bruenig <matthewbruenig@gmail.com>", a GPL3 bash script.
# Thanks to:
# CaptainKnots for the github repo and the original idea behind aur2ccr;
# Inkane for submitting bug reports, feature requests, and code;
# abveritas for adding to the arch/chakra package name translations list;
# tetris4 and [jmc] for their support and help developing the script;
# the developers of ccr, packer, abs, and the other tools this script uses;
# the Chakra devs, for making such an awesome distro;
# ...and all others who have used aur2ccr or helped in some other way.
# internal settings - you can modify some of these in aur2ccr.conf
pname="aur2ccr" pver="0.7.3"
confdir="/etc/aur2ccr" lconfdir=~/.aur2ccr # must be unquoted to use ~ substitution
tmpdir="/tmp/aur2ccr" ltmpdir=~/tmp/aur2ccr
namesconf="names.conf" apconf="archrepos.pacman.conf"
acconf="aur2ccr.conf" # initialize variables
startdir="$(pwd)" findir="$(pwd)"
badpkgs=0 consolidate=0
edit=0 addad=0
install=0 archrinit=0
resetrel=0 newline=$'\n'
RED='\e[1;31m' YELLOW='\e[1;33m'
BLUE='\e[1;34m' PINK='\e[1;35m'
WHITE='\e[1;37m' ENDCOLOR='\e[0m'
programs=( abs autoconf automake bison ccr cmake curl ed flex gawk gcc jshon libtool m4 make makepkg patch pacman )
# output formatting functions
debug() { # echo things when called like 'debug doing stuff...' only when debug=1
pushd "$(pwd)" >/dev/null; cd "$startdir"
if [[ "$debug" == 1 ]]; then
if [[ "$1" == "-n" ]]; then
local eopts="$1"; shift
fi; ([[ -n "$logfile" ]] && echo -e $eopts "${PINK}++>${ENDCOLOR}" "$@" | tee -a "$logfile") || echo -e $eopts "${PINK}++>${ENDCOLOR}" "$@"
fi; popd >/dev/null
}
msg() { # make aur2ccr's normal output prettier and more unified.
debug "msg('$@')"
pushd "$(pwd)" >/dev/null; cd "$startdir"
if [[ "$1" == "-n" ]]; then
local eopts="$1"
shift
fi; ([[ -n "$logfile" ]] && echo -e $eopts "${BLUE}==>${ENDCOLOR}" "$@" | tee -a "$logfile") || echo -e $eopts "${BLUE}==>${ENDCOLOR}" "$@"
popd >/dev/null
}
warn() { # make aur2ccr's warning messages prettier and more unified.
debug "warn('$@')"
pushd "$(pwd)" >/dev/null; cd "$startdir"
if [[ "$1" == "-n" ]]; then
local eopts="$1"
shift
fi; ([[ -n "$logfile" ]] && echo -e $eopts "${YELLOW}==>${ENDCOLOR}" "$@" | tee -a "$logfile") || echo -e $eopts "${YELLOW}==>${ENDCOLOR}" "$@"
popd >/dev/null
}
err() { # make aur2ccr's error messages prettier and more unified.
debug "err('$@')"
pushd "$(pwd)" >/dev/null; cd "$startdir"
if [[ "$1" == "-n" ]]; then
local eopts="$1"
shift
fi; ([[ -n "$logfile" ]] && echo -e $eopts "${RED}==> ERROR:${ENDCOLOR}" "$@" | tee -a "$logfile") || echo -e $eopts "${RED}==> ERROR:${ENDCOLOR}" "$@" >&2
popd >/dev/null
}
# other functions
clean() { # clean up temp files
debug "clean('$@')"
warn "Keyboard interrupt caught, cleaning up..."; debug "exiting..."
exit 1
}
initarchr() { # set up the arch repo vars, so we only need to sudo once
debug "initarchr('$@')"
if sudo pacman -Sy --config "$paconf"; then
areplist=$(pacman --config "$paconf" -Ssq)
afullist=$(pacman --config "$paconf" -Ss)
archrinit=1
debug "sudo pacman -Syy ..."
sudo pacman -Syy >&2> /dev/null
else
err "An error occurred while checking Arch repos."
debug "exiting..."
exit 1
fi
}
grepacfull() { # grep the output of pacman -Ss in a useful manner
debug "grepacfull('$@')"
debug $1
[[ "$archrinit" == 0 ]] && initarchr
local num=0; local ret=0; IFS=$'\n'; debug "entering 'for' loop..."
for line in $afullist; do
debug $line
if [[ "$num" == 0 ]]; then
entry="${line}${newline}" ; num=1
elif [[ "$num" == 1 ]]; then
entry="${entry}${line}" ; num=0
fentry="$(echo "$entry" | grep -i "$1")" # this is slow [avg 45-50s total], we need a better way. would perl be faster?
[[ -n "$fentry" ]] && echo "$entry"
[[ -n "$fentry" ]] && ret=1
fi
done ; IFS=" "
[[ "$ret" == 0 ]] && echo " (nothing found)"
}
isoutofdate() { # stolen from the isoutofdate() and rpcinfo() functions in 'ccr'
debug "isoutofdate('$@')"
RPCURL="https://aur.archlinux.org/rpc.php?type"
[[ -f "$tmpdir/$1.info" ]] || curl -LfGs --data-urlencode "arg=$1" "$RPCURL=info" > "$tmpdir/$1.info"
[[ "$(jshon -Q -e results -e OutOfDate -u < "$tmpdir/$1.info")" = "1" ]]
}
vcsver() { # look for version control system versions, like pkgname-git
debug "vcsver('$@')"
if isinccr "$1-git"; then # git
vpkgname="$1-git"
return 0
elif isinccr "$1-bzr"; then # bazaar
vpkgname="$1-bzr"
return 0
elif isinccr "$1-svn"; then # subversion
vpkgname="$1-svn"
return 0
elif isinccr "$1-hg"; then # mercurial
vpkgname="$1-hg"
return 0
else
return 1
fi
}
isinccr() { # check in CCR and main repos for package
debug "isinccr('$@')"
ccr -Ssq $1 | grep -q "^$1$"
}
isinrepos() { # check in main Chakra repos for package - stolen from 'ccr'
debug "isinrepos('$@')"
pacman -Si -- "$1" &>/dev/null
}
isinaur() {
debug "isinaur('$@')"
echo "$1" | grep -q '^..' || (err "Package names must be at least two characters in length"; exit 1) || exit 1 # if the package name is not at least 2 chars, checking aur will fail.
wget -q --spider "https://aur.archlinux.org/packages/$(echo "$1" | sed 's/\(..\).*/\1/')/$1/PKGBUILD"
}
isinarchr() {
debug "isinarchr('$@')"
msg "Checking Arch repos..."
[[ "$archrinit" == 0 ]] && initarchr
echo "$areplist" | grep -q "^$1$" # much nicer than the old function
}
getarchname() {
debug "getarchname('$@')"
if isinarchr $1; then
archname=$(echo "$afullist" | grep -o "^[^ ]*/$1\s" | sed 's/\s//g')
else
err "'$1' not found in Arch repos"
fi
}
depends() { # get the dependencies from the PKGBUILD - stolen from 'ccr'
local pkgname=; local pkgbase=; local pkgver=; local pkgrel=; local url=; local arch=; local license=; local source=; local md5sums=; local srcdir=; local pkgdir=; local install= # declare vars from the PKGBUILD as local, so aur2ccr doens't get confused
debug "depends($@)"; debug "current dir: $(pwd; ls)"
. PKGBUILD; IFS=$'\n'
depends=( $(echo -e "${depends[*]}\n${makedepends[*]}" | sed -e 's/=.*//' -e 's/>.*//' -e 's/<.*//'| sort -u) ); IFS=' '
debug "depends=( ${depends[@]} )"
}
addmaintainer() { # change maintainer info in the PKGBUILD
debug "addmaintainer('$@')"
sed -i 's/^# Maintainer: /# Contributor: /' PKGBUILD
(printf "# Maintainer: ${maintainer}\n$(cat PKGBUILD)" > PKGBUILD.1 && mv PKGBUILD.1 PKGBUILD) || return 1
}
addad() {
debug "addad('$@')"
ed -s PKGBUILD << EOF && msg "Ad added. Thanks for supporting aur2ccr! :)"
2i
# Contributor: aur2ccr (http://ddg.gg/?q=!ccr+aur2ccr)
.
wq
EOF
}
uchksums() { # update checksums with 'makepkg -gf'
debug "uchksums($@)"
debug "current dir: $(pwd; ls)"
if makepkg -gf > "$tmpdir/${PID}${UID}.sums"; then
sums="$(cat "$tmpdir/${PID}${UID}.sums")"
else
err "'makepkg -g' failed in '$(pwd)'!"
return 1
fi
stype="$(echo $sums | grep -o "^..*sums=")"
if echo "$sums" | grep -q "^$stype"; then
if grep -q "^$stype" PKGBUILD; then
stype="$(echo "$stype" | sed 's/=//; s/\s//g')" ; debug "awking..."
local new="$(awk -v "newsums=$sums" -v "stype=$stype" '$1 ~ stype { t = 1; } t == 1 { if ($0 ~ "\)") { t = 0; print(newsums); next; } next; } { print; }' PKGBUILD 2>/dev/null)" # sheesh. awk courtesy of pr3d4t0r, I haven't a clue how it works.
debug "sending awk output to PKGBUILD..."
echo "$new" > PKGBUILD
elif [[ -z "$sums" ]]; then
return 0
else
return 1
fi
else
err "something went wrong while updating checksums"
return 1
fi
}
optipkg() { # optimize PKGBUILDs by getting rid of a few easy-to-fix errors, etc - note that this must be run AFTER the unsplitp function, or it will break split packages.
debug "optipkg($@)"
grep -q '^# $Id' PKGBUILD && sed -i '/^# $Id[$:].*$/d' PKGBUILD # get rid of $Id tags, which are not used by CCR.
grep -q "^[^ ]*=(['\"\s]*)" PKGBUILD && sed -i "/^[^ ]*=(['\"\s]*)/d" PKGBUILD # get rid of empty arrays, like depends=()
grep -q "^[^ ]*=([^'\"\s][^ ]*[^'\"\s])" PKGBUILD && sed -i "s/\(^[^ ]*=(\)\([^'\"\s][^ ]*[^'\"\s]\)\().*$\)/\1\"\2\"\3/" PKGBUILD # quote unquoted single values in arrays, like arch=(any)
} # seems to cause errors: grep -q "^package()" PKGBUILD || grep -q "^build()" PKGBUILD && sed -i "/^build()/s//package()/" PKGBUILD # if there is no package() function, but there is a build() function, rename build() to package()
isplitp() { # is $1 a split PKGBUILD?
debug "isplitp('$@')"
grep -q "package_.*()" "$1" && grep -q "build()" "$1" || return 1 #grep -q "^pkgbase=" "$1" &&
}
unsplitp() { # take one split PKGBUILD and create multiple normal PKGBUILDs
debug "unsplitp('$@')"
local pkgname=; local pkgbase=; local pkgver=; local pkgrel=; local url=; local arch=; local license=; local source=; local md5sums=; local srcdir=; local pkgdir=; local install=
unstartd="$(pwd)"
cp PKGBUILD PKGBUILD$BASHPID.orig
. PKGBUILD # get the PKGBUILD's vars into our mem
[[ -z "$pkgbase" ]] && pkgbase=$pkgname
for pkg in ${pkgname[@]}; do # seperate PKGBUILDs
[[ "$pkg" == "$pkgbase" ]] && continue # skip pkgbase
mkdir -p "../../$pkg/$pkg" && cd "../../$pkg/$pkg" || return 1
cp -f "$unstartd/PKGBUILD" ./ || return 1
sed -i "/^pkgbase=.*/d; /^package_$pkg()/s//package()/; /^true && pkgname=.*/d; /^pkgname=.*/s//pkgname=$pkg/; /true && depends=()/d; /^package_.*()/,/^}\s*$/d; s/\(.*\)\$pkgbase\(.*\)/\1$pkgbase\2/; s/\(.*\)\$pkgname\([^\[].*\)/\1$pkgname\2/; s/\(.*\)\$pkgname\[\(\d\d*\)\]\(.*\)/\1${pkgname[\2]}\3/; s/\([^=]\)$pkg/\1\${pkgname}/g" PKGBUILD || return 1
done; cd "$unstartd"
sed -i "/^pkgbase=.*/d; /^package_$pkgbase()/s//package()/; /^true && pkgname=.*/d; /^pkgname=.*/s//pkgname=$pkgbase/; /true && depends=()/d; /^package_.*()/,/^}\s*$/d; s/\(.*\)\$pkgbase\(.*\)/\1$pkgbase\2/; s/\(.*\)\$pkgname\([^\[].*\)/\1$pkgname\2/; s/\(.*\)\$pkgname\[\(\d\d*\)\]\(.*\)/\1${pkgname[\2]}\3/; s/\([^=]\)$pkgbase/\1\${pkgname}/g" PKGBUILD || return 1 # fix pkgbase PKGBUILD
grep -q "^package()" PKGBUILD || sed -i "/^build()/s//package()/" PKGBUILD || return 1 # if no package(), rename build() to package()
__PKGNAMES=( ${pkgname[@]} ) __PKGBASE="$pkgbase"
}
isinstalled() { # check if $1 is already installed
debug "isinstalled('$@')"
pacman -Qq -- "$1" &>/dev/null
}
getneedeps() { # get the deps we need from CCR, return in $needeps
debug "getneedeps($@)"
needeps=
for dep in "${depends[@]}"; do
if isinrepos $dep; then
needeps="$needeps"
elif isinstalled $dep; then
needeps="$needeps"
elif isinccr $dep; then
needeps="$needeps $dep"
else
err "dependency $dep cannot be found!"
exit 1
fi
done
needeps="$(echo $needeps | sed 's/^\s*//')"; debug "neepeds='$needeps'"
}
logerr() { # keep track of errors; $1 is the package name
debug "logerr('$@')"
[[ -n "$1" ]] && let badpkgs=$badpkgs+1
[[ -n "$1" ]] && failedpkgs="$failedpkgs $1"
}
namelookup() { # see https://github.com/redhat69/aur2ccr/issues/1
debug "namelookup('$@')"
if [[ -r "$namesconf" ]]; then
if grep -q "$1=..*" "$namesconf"; then
apkgname="$1"
cpkgname="$(grep "^$1=..*" "$namesconf" | sed "s/$1=//")"
return 0
else
return 1
fi
else
return 1
fi
}
namechange() { # companion function to namelookup()
debug "namechange('$@')"
namelookup $1 && sed -i "s/\(^[^ ]*depends=.*[( '\"]*\)${apkgname}\([ '\")]\)/\1${cpkgname}\2/g; s/\([ '\"]\)${apkgname}\([ '\"]\)/\1${cpkgname}\2/g" PKGBUILD || return 1
debug "new PKGBUILD: $(cat PKGBUILD)"
depends
}
dotherest() { # this used to be 150 lines, but I managed to get it down a little bit - it's still too large.
debug "dotherest('$@')"
local pkgname=$1; debug "pkgname=$pkgname"
depsnotinrep=0
msg "Checking if this is a split PKGBUILD..."
isplitp PKGBUILD && (makeccrpkg_s $pkgname && exit 0) && return 0
msg "This doesn't appear to be a split PKGBUILD, continuing..."; msg -n "Checking for and fixing common PKGBUILD problems... "
optipkg; echo "done."
[[ -n "$maintainer" ]] && (msg "Changing maintainer information..."; debug "if addmaintainer \$maintainer, then msg(done), else err(failed)..."; (addmaintainer "$maintainer" && msg "Done" || err "Failed"))
debug "if \$addad then addad..."
[[ "$addad" == 1 ]] && addad
if [[ "$resetrel" == 1 ]]; then
debug "reset pkgrel"
sed -rie 's/pkgrel=[0-9]+/pkgrel=1/g' PKGBUILD
fi
debug "if uchksums..."
(uchksums && msg "checksums for $pkgname updated") || warn "checksums for $pkgname could not be updated!"
debug "if \$edit, then edit..."
[[ "$edit" -eq 1 ]] && (msg "Opening '$pkgname' PKGBUILD with $EDITOR"; warn "Note: dependencies have not yet been checked, so the PKGBUILD"; warn " may be changed after you modify it."; debug "\$EDITOR PKGBUILD"; ${EDITOR-vi} PKGBUILD)
depends
debug "for pkg in ${depends[@]}..."
for pkg in ${depends[@]}; do
if [ "$pkg" == "java-environment" -o "$pkg" == "java-runtime" ]; then
msg "$pkg is a special package in the Chakra repos, continuing"
elif [[ "$pkg" == "$pkgname" ]]; then
warn "dependency cycle detected!"; warn "skipping '$pkgname' dependency '$pkg'"
elif isinccr $pkg; then
msg "$pkgname dependency '$pkg' already in CCR or repos, continuing"
isinrepos $pkg || let depsnotinrep=$depsnotinrep+1
elif namelookup $pkg; then
debug "namelookup returned 0, namechanging..."
namechange $pkg || (err "Something went wrong while attempting to edit the $pkgname PKGBUILD"; logerr $pkg; exit 1) || return 1
if isinccr $cpkgname; then
msg "$pkgname dependency '$apkgname' already in CCR or repos as '$cpkgname', continuing"
isinrepos $cpkgname || let depsnotinrep=$depsnotinrep+1
else
err "There seems to be a bad definition in '$namesconf'. Please fix this."; err "The offending line is: '$apkgname=$cpkgname'"; logerr $pkg
return 1
fi
else
let depsnotinrep=$depsnotinrep+1
msg "$pkgname dependency '$pkg' not in CCR or repos, looking at Arch packages..."
if isinaur $pkg; then
debug "pushd `pwd`"
pushd "$(pwd)" >/dev/null
(isdepend=1 makeccrpkg $pkg && (debug "popd"; popd >/dev/null)) || (err "Some error occurred while building '$pkg'"; err "Without this dependency, $pkgname cannot be built"; debug "popd"; popd >/dev/null; exit 1) || return 1
elif isinarchr $pkg; then
msg "'$pkg' found in the Arch repos..."; debug "pushd `pwd`"
pushd "$(pwd)" >/dev/null
(isdepend=1 makeccrpkg_r $pkg && (debug "popd"; popd >/dev/null)) || (err "Some error occurred while building '$pkg'"; err "Without this dependency, $pkgname cannot be built"; debug "popd"; popd >/dev/null; exit 1) || return 1
else
err "Sorry, dependency '$pkg' cannot be found."; err "Without this dependency, $pkgname cannot be built"; logerr $pkg
return 1
fi
fi
done
if [[ "$depsnotinrep" -eq 0 ]]; then
msg "Testing package '$pkgname'..."
makepkg -sfr || (err "Some error occurred, check the $pkgname PKGBUILD in $(pwd)"; logerr $pkgname; exit 1) || return 1
else
msg "Package '$pkgname' has dependencies outside of the Chakra repos."
msg "Attempting to install dependencies with 'ccr'..."; msg "(This may take a while)"
getneedeps
if [[ -z "$needeps" ]]; then
msg "Oops, looks like you already have all these dependencies installed."
makepkg -sfr || (err "Some error occurred, check the $pkgname PKGBUILD in $(pwd)"; logerr $pkgname; exit 1) || return 1
elif ccr -S $needeps; then
msg "Succeeded, continuing"
makepkg -sfr || (err "Some error occurred, check the $pkgname PKGBUILD in $(pwd)"; logerr $pkgname; exit 1) || return 1
if [[ "$install" -eq 0 ]]; then
msg "Removing packages..."
(sudo pacman -Rn $needeps && msg "Packages removed") || err "could not remove packages!"
else
depsnotinrep=0
fi
else
warn "Package '$pkgname' has dependencies outside of the Chakra repos and CCR."; warn "Running 'makepkg -s' on this package will fail, so we cannot test it now."; warn "Please test the final .src.tar.gz package manually with ccr."
fi
fi
if makepkg --source -f; then
msg "Package '$pkgname' built successfully."
if [[ "$consolidate" -eq 1 ]]; then
pkgpkg="$(ls $pkgname*.src.tar.gz)"
(mv $pkgpkg "$findir" && msg "$pkgpkg moved to $findir") || (err "$pkgpkg could not be moved to $findir"; logerr $pkgname; exit 1) || return 1
fi
if [[ "$install" -eq 1 && "$depsnotinrep" == 0 ]]; then
msg "Installing $pkgname..."
if ! sudo pacman -U $(ls *.pkg.tar.xz); then
warn "pacman failed, trying 'makepkg -i'..."
makepkg -if || (err "Could not install $pkgname."; exit 1) || return 1
fi
(isinstalled $pkgname && msg "$pkgname installed") || (err "Could not install $pkgname."; exit 1) || return 1
elif [[ "$install" -eq 1 ]]; then
warn "$pkgname cannot be installed, because it is missing dependencies."
fi
else
err "Some error occurred, check the $pkgname PKGBUILD in '$(pwd)'"
logerr $pkgname
return 1
fi
}
makeccrpkg() { # grab a package from AUR, and make it into a CCR-ready src package
debug "makeccrpkg('$@')"
cd "$startdir"
local pkgname=$1
mkdir -p "$pkgname" || (err "cannot create directory '$startdir/$pkgname'"; logerr $pkgname; exit 1) || return 1
cd "$pkgname"
[[ -r "$pkgname.tar.gz" ]] && rm "$pkgname.tar.gz"
wget "https://aur.archlinux.org/packages/$(echo "$pkgname" | sed 's/\(..\).*/\1/')/$pkgname/$pkgname.tar.gz" || (err "There was an error while trying to download the package."; logerr $pkgname; exit 1) || return 1
(tar -xzf "$pkgname.tar.gz" && rm "$pkgname.tar.gz") || (err "tar could not extract the archive"; logerr $pkgname; exit 1) || return 1
cd "$pkgname"
if [[ "$isdepend" == 1 ]]; then
installb=$install
install=1
fi
if dotherest "$pkgname"; then
install=$installb
return 0
else
install=$installb
logerr $pkgname
return 1
fi
}
makeccrpkg_r() { # grab a package from Arch repos, and make it into a CCR-ready src package
debug "makeccrpkg_r('$@')"
cd "$startdir"
local pkgname=$1
mkdir -p "$pkgname" || (err "cannot create directory '$startdir/$pkgname'"; logerr $pkgname; exit 1) || return 1
cd "$pkgname"
[[ -r "$pkgname.tar.gz" ]] && rm "$pkgname.tar.gz"
# get Arch package with PKGBUILD, .install, etc, using perl or whatever - extract the package if needed
getarchname $pkgname
if [[ -z "$archname" || "$archname" == 0 ]]; then
err "'$pkgname' cannot be found"; logerr $pkgname
return 1
fi; msg "found '$pkgname' as '$archname'"
[[ -d /var/abs ]] || sudo mkdir -p /var/abs
if sudo abs "$archname"; then
rm -rf "./$pkgname"
if sudo mv "/var/abs/$archname" "./$pkgname"; then
(sudo chown -hR $USER:$GROUPS "./$pkgname" && msg "$pkgname info retrieved from Arch repos successfully") || (err "chown failed"; logerr $pkgname; exit 1) || return 1
else
err "could not move /var/abs/$archname to working dir"; logerr $pkgname
return 1
fi
else
err "abs failed"; logerr $pkgname
return 1
fi # ^ this is a quick fix ^
cd "$pkgname"
if [[ "$isdepend" == 1 ]]; then
installb=$install
install=1
fi
if dotherest "$pkgname"; then
install=$installb
return 0
else
install=$installb
logerr $pkgname
return 1
fi
}
makeccrpkg_u() { # make a package from a URL
debug "makeccrpkg_u('$@')"
cd "$startdir"
local pkgname="$(basename "$url" | sed 's/\([^\.]\)\..*/\1/')"; local pkgname="${pkgname-$BASHPID}" # if $url is http://example.com/path/package.tar.gz, $pkgname is set to "package".
local myfile="$(basename "$url")"; local myfile="${myfile-$BASHPID}"
mkdir -p "$pkgname" || (err "cannot create directory '$startdir/$pkgname'"; logerr $pkgname; exit 1) || return 1
cd "$pkgname"
wget -O "$myfile" "$url" || (err "There was an error while trying to download the package"; logerr $pkgname; exit 1) || return 1
local dir="$(tar -taf "$myfile" | head -1)"
tar -xaf "$myfile" || (err "tar could not extract the archive"; logerr $pkgname; exit 1) || return 1
cd "$dir"
[[ -r PKGBUILD ]] || (err "The package you specified does not seem to be a valid source archive."; logerr $pkgname; exit 1) || return 1
dotherest "$pkgname" || (logerr $pkgname; exit 1) || return 1
}
makeccrpkg_f() { # make a package from a *.src.tar.gz file
debug "makeccrpkg_f('$@')"
cd "$startdir"
local pkgname="$(basename "$file" | sed 's/\([^\.]\)\..*/\1/')" # same as in _u above
local dir="$(tar -taf "$file" | head -1)"
[[ -r "$file" ]] || (err "'$file' cannot be opened or does not exist"; logerr $pkgname; exit 1) || return 1
mkdir -p "$pkgname" || (err "cannot create directory '$startdir/$pkgname'"; logerr $pkgname; exit 1) || return 1
tar -xaf "$file" -C "$pkgname" || (err "tar could not extract the archive"; logerr $pkgname; exit 1) || return 1
cd "$pkgname/$dir"
[[ -r PKGBUILD ]] || (err "The package you specified does not seem to be a valid source archive."; logerr $pkgname; exit 1) || return 1
dotherest "$pkgname" || (logerr $pkgname; exit 1) || return 1
}
makeccrpkg_d() { # uses $pkgdir as directory containting PKGBUILD. (argument to -d)
debug "makeccrpkg_d('$@')"
cd "$startdir"
local pkgname="$(basename "$pkgdir")"
[[ -d "$pkgdir" ]] || (err "$pkgdir is not a directory or does not exist"; logerr $pkgname; exit 1) || return 1
cd "$pkgdir"; [[ -r "PKGBUILD" ]] || (debug "cd: `pwd`"; err "'$pkgdir/PKGBUILD' cannot be opened or does not exist"; logerr $pkgname; exit 1) || return 1
cd "$startdir"
mkdir -p "$pkgname" || (err "cannot create directory '$startdir/$pkgname'"; logerr $pkgname; exit 1) || return 1
if [[ "$pkgdir" != "$pkgname/$pkgname" && "$pkgdir" != "$(pwd)/$pkgname/$pkgname" && "$pkgdir" != "./$pkgname/$pkgname" ]]; then # This is bad
cp -r "$pkgdir" "$pkgname/" || (err "cannot copy files from '$pkgdir'"; logerr $pkgname; exit 1) || return 1
fi
cd "$pkgname/$pkgname"
dotherest "$pkgname" || (logerr $pkgname; exit 1) || return 1
}
makeccrpkg_s() { # handle split PKGBUILDs
debug "makeccrpkg_s('$@')"
local pkgname=$1
warn "'$pkgname' seems to be a split PKGBUILD, which cannot be uploaded to CCR."
warn "For more information on split PKGBUILDs, see PKGBUILD(5) or"
warn "http://www.archlinux.org/pacman/PKGBUILD.5.html#_package_splitting"
warn "aur2ccr can attempt to rectify this by dividing the PKGBUILD up into multiple"
warn "packages, but this is an experimental feature and does not always work. If"
warn "you do not want this script to attempt to 'unsplit' this package, you will"
warn "need to do it manually."
warn "If aur2ccr does try to fix the PKGBUILD, the original will be backed up as"
warn "PKGBUILD.orig in the package's build dir. "
warn -n "Should aur2ccr attempt to fix this PKGBUILD? [y/N] "
read ans
if [[ -z "$ans" || "$ans" == "n" || "$ans" == "N" || "$ans" == "no" ]]; then
warn "aur2ccr will not attempt to fix this PKGBUILD. You need to fix it"
warn "manually before uploading the package to CCR."
return 0
else
warn "Attempting to fix the PKGBUILD..."
unsplitp PKGBUILD
warn "Done. There is no way to see if this worked without testing the packages."
for pkg in ${__PKGNAMES[@]}; do
[[ "$pkg" == "$__PKGBASE" ]] && continue
dotherest $pkg || (logerr $pkg; exit 1) || return 1
done
[[ -n "$__PKGBASE" ]] && dotherest $__PKGBASE || (logerr $__PKGBASE; exit 1) || return 1
fi
}
aursearch() { # this code is stolen from 'packer'. This used to be, and is the equivalent of: packer --auronly -Ss $1
debug "aursearch('$@')" >&2 ; aret=0
RPCURL="https://aur.archlinux.org/rpc.php?type"
curl -LfGs --data-urlencode "arg=$1" "$RPCURL=search" | sed -e 's/","/"\n"/g' -e 's/\\//g' > "$tmpdir/$1$UID.search"
parsefile="$tmpdir/$1$UID.search" IFS=$'\n' aurname=( $(grep -F '"Name":"' "$parsefile" | cut -d '"' -f 4) )
version=( $(grep -F '"Version":"' "$parsefile" | cut -d '"' -f 4) ) aurtotal="${#aurname[@]}"
description=( $(grep -F '"Description":"' "$parsefile" | sed -e 's/^"Description":"//' -e 's/"$/ /') )
for ((i=0 ; i<$aurtotal ; i++)); do
printf "aur/${aurname[$i]} ${version[$i]}\n ${description[$i]}\n" ; aret=1
done
}
pkgsearch() { # there is no reason for this function to ever be called except right after isinarchr returns 1
debug "pkgsearch('$@')"
warn "Package '$1' not found in AUR or Arch repos."; warn "Did you mean: "; debug "checking aursearch..."
aursearch $1 ; ([[ -n "$aret" && "$aret" == 1 ]] || grepacfull $1)
exit 1
}
checkaur() {
debug "checkaur('$@')"
if isinaur $1; then
msg "'$1' found in AUR..."
if isoutofdate $1; then
warn "$1 is marked as out of date in AUR!"
warn -n "Are you sure you want to continue? [y/N] "; read ans
([[ -z "$ans" || "$ans" == "n" || "$ans" == "N" || "$ans" == "no" ]] && (warn "Skipping $1"; exit 0)) || (warn "Continuing. This is a bad idea!"; sleep 2)
fi
makeccrpkg $1 || logerr $1
elif isinarchr $1; then
msg "'$1' found in the Arch repos..."
makeccrpkg_r $1 || logerr $1
else
pkgsearch $1
fi
}
setup() { # perform some setup-related stuff interactively
# (this is just temp until the python script gets here, there are too many explicitly-specified paths instead of variables used)"
msg "Leave all options blank (just press Enter) to use defaults/current values."
msg "Please wait, gathering required information..."
[[ -d "$HOME/.aur2ccr/" ]] || mkdir -p "$HOME/.aur2ccr"
[[ -f "$HOME/.aur2ccr/archrepos.pacman.conf" ]] || cp -f "/etc/aur2ccr/archrepos.pacman.conf" "$HOME/.aur2ccr/archrepos.pacman.conf"
[[ -f "$HOME/.aur2ccr/aur2ccr.conf" ]] || cp -f "/etc/aur2ccr/aur2ccr.conf" "$HOME/.aur2ccr/aur2ccr.conf"
[[ -f "$HOME/.aur2ccr/names.conf" ]] || cp -f "/etc/aur2ccr/names.conf" "$HOME/.aur2ccr/names.conf"
a2cc="$HOME/.aur2ccr/aur2ccr.conf"
paconf="$HOME/.aur2ccr/archrepos.pacman.conf" getmirrors.py # getmirrors.py must exist in PATH
msg "Enter your maintainer information, in the format below:"
msg "My Name (optional nickname) <email_address@example.com>"
msg "For example: jimbob <jimbob54@beispiel.com>"
msg -n ""; read maintainer && (
if [[ -z "$maintaintainer" ]]; then source "$a2cc"; fi
if grep -q "^[# ]*maintainer=.*" "$a2cc"; then sed -i "s,^[# ]*maintainer=.*,maintainer='$maintainer'," "$a2cc"
else echo "maintainer='$maintainer'" >> "$a2cc"; fi
)
msg -n "Always move *.src.tar.gz packages to the working dir? [y/N] "; read consolidate && (
if [[ $consolidate == yes || $consolidate == Y || $consolidate == y || $consolidate == 1 ]]; then consolidate=1
else consolidate=0; fi
if grep -q "^[# ]*consolidate=.*" "$a2cc"; then sed -i "s/^[# ]*consolidate=.*/consolidate=$consolidate/" "$a2cc"
else echo "consolidate=$consolidate" >> "$a2cc"; fi
)
msg -n "Always edit PKGBUILDs in \$EDITOR ($EDITOR)? [y/N] "; read edit && (
if [[ $edit == yes || $edit == Y || $edit == y || $edit == 1 ]]; then edit=1
else edit=0; fi
if grep -q "^[# ]*edit=.*" "$a2cc"; then sed -i "s/^[# ]*edit=.*/edit=$edit/" "$a2cc"
else echo "edit=$edit" >> "$a2cc"; fi
)
msg "Enter the full path to your CCR dir (eg: $HOME/pkgbuilds)"
msg "Default: wherever you run the script."
msg -n ""; read startdir && (
if [[ -d "$startdir" ]]; then findir="$startdir"
else source "$a2cc"
if [[ -z "$startdir" ]]; then startdir='$(pwd)'; fi
if [[ -z "$findir" ]]; then findir='$(pwd)'; fi
fi
(
if grep -q "^[# ]*startdir=.*" "$a2cc"; then sed -i "s@^[# ]*startdir=.*@startdir=\"$startdir\"@" "$a2cc"
else echo "startdir=\"$startdir\"" >> "$a2cc"; fi
if grep -q "^[# ]*findir=.*" "$a2cc"; then sed -i "s@^[# ]*findir=.*@findir=\"$findir\"@" "$a2cc"
else echo "findir=\"$findir\"" >> "$a2cc"; fi
)
)
msg "Current configuration: "
cat "$a2cc" | grep -v "^[ ]*#.*"
exit 0
}
usage() {
debug "usage('$@')"
echo "Usage: $(basename $0) [OPTIONS] [PACKAGES]"
echo "Create CCR-ready source packages from packages in AUR or Arch repos"
echo "Example: $(basename $0) twisted"
echo
echo "General: "
echo " -m <maintainer> add maintainer information to each PKGBUILD before building"
echo " (--maintainer <m...>) <maintainer> should be in the form 'My Name (nick) <me@example.com>'"
echo " -e, --edit edit the PKGBUILD for each package with \$EDITOR before building"
echo " -c, --consolidate move all CCR source packages into the working directory"
echo " -i, --install install packages that build successfully, in order to test them"
echo " -1, --reset-pkgrel reset the pkgrel to 1 before building packages (recommended)"
echo
echo "Advanced: "
echo " -f, --from-src <file> create a CCR source package from source package <file>"
echo " -u, --from-url <URL> ... or from an AUR/CCR-compatible source package at <URL>"
echo " -d, --from-dir <dir> ... or from a PKGBUILD and (optional) other files in <dir>"
echo " -C, --cd <newdir> use <newdir> as the working directory instead of the current dir"
echo " -t, --temp use '$tmpdir' as the build directory instead of the current dir"
echo " (all finished src packages will be moved into the working dir, like -c)"
echo " -l, --log <logfile> use 'tee' to send all aur2ccr messages to <logfile>"
echo
echo "Other: "
echo " -s, --setup perform setup-related tasks (not required)"
echo " -a, --addad add an aur2ccr advertisement - add as Contributor: "
echo " 'aur2ccr (http://ddg.gg/?q=!ccr+aur2ccr)'"
echo " -h, --help display this help and exit"
echo " -v, --version print version information and exit"
echo
echo "For debugging, use: debug=1 $(basename $0) [OPTIONS] [PACKAGES]"
echo
echo "Report bugs at: <https://github.com/redhat69/aur2ccr/issues/>"
echo "aur2ccr home: <https://github.com/redhat69/aur2ccr/>" ; debug "exiting..."
exit 0
}
# helper function for popopt
validate_option() {
if [[ "$1" == "" ]]; then
return 127
elif [[ $(echo "$1" | cut -c 1) == "-" ]]; then
err "option parameter must not start with - "
exit 1
else
return 0
fi
}
# global variable where the package names are stored
packages=""
popopts() { # populate variables, enumerate options and arguments
debug "popopts('$@')"
while [[ "$1" != "" ]]; do
debug "current option $1"
case "$1" in
"-1"|"--reset-pkgrel") resetrel=1;;
"-m"|"--maintainer") shift
if validate_option "$1"; then
maintainer="$1";
else
err "missing maintainer" && exit 2;
fi;;
"-e"|"--edit") edit=1;;
"-c"|"--consolidate") consolidate=1;;
"-f"|"--from-src") shift
if validate_option "$1"; then
file="$1";
else
err "missing source file" && exit 3;
fi;;
"-u"|"--from-url") shift
if validate_option "$1" ; then
url="$1";
else
err "missing url" && exit 4;
fi;;
"-d"|"--from-dir") shift
if validate_option "$1"; then
pkgdir="$1"
else
err "missing directory" && exit 5;
fi;;
"-C"|"--cd") shift
if validate_option "$1"; then
startdir="$1" finddir="$1"
else
err "missing directory" && exit 6;
fi;;
"-t"|"--temp") startdir="$tmpdir"
consolidate=1;;
"-l"|"--log") shift
if validate_option "$1"; then
logfile="$1"
touch "$logfile" >&2> /dev/null
if ! test -w "$logfile"; then
err "specified log file '$logfile' is not writable"
exit 8
fi;
echo >> "$logfile"
echo "+++++ aur2ccr logfile, started $(date) +++++" >> "$logfile"
echo >> "$logfile"
else
err "missing logfile" && exit 8
fi;;
"-i"|"--install") install=1;;
"-s"|"--setup") setup;;
"-h"|"--help") usage;;
"-v"|"--version") echo "$pname $pver" && exit 0;;
"-a"|"--addad") addad=1;;
# match every other option starting with -, followed by two or more chars
-[a-z][a-z]*) # replace -foo therest with -f -o -o therest
# split the option string, add a - before every option
argops=$(echo "$1"|echo $(fold -w1)) stmp=""
for char in $noargops; do
case "$char" in
"m"|"f"|"u"|"d"|"C"|"l") debug "$char" && break;;
*) argops=${argops:1}&&stmp=${stmp}" "${char}
esac
done
debug start $stmp; debug $argops end
local tmp=$(echo "$1"|echo $(fold -w1)|sed -e 's/ / -/g'|cut -c2- && shift)
debug "tmp=" $tmp
set -- $tmp "${@:2}"
debug "new options" "$@"
continue ;;
# package names won't start with - or --, so we can catch invalid options
-[a-z]|--[a-z]*) err "$1 is not a valid option" && exit 9;;
*) packages="$packages $1";;
esac
shift
done
debug "args is $args"
[[ -z "$packages" && -z "$url" && -z "$file" && -z "$pkgdir" ]] && (err "You did not specify any packages to build"; err "There is nothing to do. Exiting..."; exit 0) && exit 1
}
# main()
debug "main('$@') /* version = $pver */"
# prevent running the script as root
([[ $EUID -eq 0 ]] && (err "This script must not be run as root!"; err "aur2ccr will ask for your password if needed."; \
err "Exiting..."; debug "script run as root, exiting"; exit 0) && exit 0) && exit 1
# test for important programs that may not be installed
for bin in ${programs[@]}; do
debug "checking for $bin..."
if [[ -x "$(which $bin 2>/dev/null)" ]]; then
debug " found"
continue
else
debug " not found"; err "Sorry, you need '$bin' to use this script."; err "Try running 'sudo pacman -Sy abs base-devel ccr cmake curl gawk jshon sed'"
exit 1
fi
done
# load setting from config files, prefer local over global
if [[ -r "$confdir/$acconf" ]]; then
debug "found global conf, using"
. "$confdir/$acconf"
fi; if [[ -r "$lconfdir/$acconf" ]]; then
debug "found local conf, using"
. "$lconfdir/$acconf"
fi # if none exist, just use default values
mkdir -p "$tmpdir" || (err "tmpdir '$tmpdir' is a file!"; exit 1) || exit 1 # make the temp dir, if it does not already exist
# find other config files, and set variables to point to them- prefer global over local
if [[ -r "$lconfdir/$apconf" ]]; then
debug "found local pacman conf, using"
paconf="$lconfdir/$apconf"
elif [[ -r "$confdir/$apconf" ]]; then
debug "found global pacman conf, using"
paconf="$confdir/$apconf"
else
debug "could not find local or global pacman conf, using $tmpdir/pacman.conf.tmp instead"
printf '[community]\nServer = http://ftp.osuosl.org/pub/archlinux/$repo/os/i686\n\n[core]\nServer = http://ftp.osuosl.org/pub/archlinux/$repo/os/i686\n\n[extra]\nServer = http://ftp.osuosl.org/pub/archlinux/$repo/os/i686\n\n[multilib]\nServer = http://ftp.osuosl.org/pub/archlinux/$repo/os/x86_64\n' > "$tmpdir/pacman.conf.tmp"
paconf="$tmpdir/pacman.conf.tmp"
fi; if [[ -r "$confdir/$namesconf" ]]; then
debug "found global names.conf, using"
namesconf="$confdir/$namesconf"
elif [[ -r "$lconfdir/$namesconf" ]]; then
debug "found local names.conf, using"
namesconf="$lconfdir/$namesconf"
fi
# fix empty/unset variables to prevent errors
pname="${pname-aur2ccr}" pver="${pver-0.7.3}"
confdir="${confdir-/etc/aur2ccr}" lconfdir="${lconfdir-~/.aur2ccr}"
tmpdir="${tmpdir-/tmp}" namesconf="${namesconf-names.conf}"
apconf="${apconf-archrepos.pacman.conf}" acconf="${acconf-aur2ccr.conf}"
startdir="${startdir-$(pwd)}" findir="${findir-$(pwd)}"
consolidate="${consolidate-0}" edit="${edit-0}" addad="${addad-0}"
[[ -z "$1" || "$1" == "--help" || "$1" == "-h" ]] && usage
popopts "$@"
debug "setting trap"; trap clean INT # trap keyboard interrupts (^C), in order to clean up temp files
debug "entering 'for' loop"
for pkgname in $packages; do
debug "checking $pkgname"
debug "$pkgname has to be at least two characters long"
echo "$pkgname" | grep -q '^..' || (err "Package names must be at least two characters in length"; exit 1) || exit 1 # if the package name is not at least 2 chars, lots of stuff wiull fail.
if isinccr $pkgname; then
msg "$pkgname is already in CCR or main Chakra repos."
msg -n "Continue anyway? [y/N] "
read ans
if [[ -z "$ans" || "$ans" == "n" || "$ans" == "N" || "$ans" == "no" ]]; then
warn "Skipping $pkgname"; continue
else
checkaur $pkgname
fi
elif namelookup $pkgname; then
msg "$apkgname is already in CCR or main Chakra repos as $cpkgname."
msg -n "Continue anyway? [y/N] "; read ans
if [ -z "$ans" -o "$ans" == "n" -o "$ans" == "N" -o "$ans" == "no" ]; then
warn "Skipping $pkgname"; continue
else
checkaur $pkgname
fi
elif vcsver $pkgname; then
msg "$pkgname is already in CCR or main Chakra repos as $vpkgname."
msg -n "Continue anyway? [y/N] "; read ans
if [[ -z "$ans" || "$ans" == "n" || "$ans" == "N" || "$ans" == "no" ]]; then
warn "Skipping $pkgname"; continue
else
checkaur $pkgname
fi
else
checkaur $pkgname
fi
done
[[ -n "$url" ]] && makeccrpkg_u || logerr $url
[[ -n "$file" ]] && makeccrpkg_f || logerr $file
[[ -n "$pkgdir" ]] && makeccrpkg_d || logerr $pkgdir
# finish up
if [[ "$badpkgs" -gt 0 ]]; then
err "$badpkgs package(s) failed"
debug "at least $badpkgs packages failed..."
else
msg "$badpkgs package(s) failed"; debug "0 pkgs failed, exiting..."
warn "Remember, just because aur2ccr seems to have succeeded, does not mean the package(s)"
warn "will work. Please thoroughly test all packages BEFORE uploading them to CCR."
warn "Broken packages may be removed without warning."
exit 0
fi
([[ -n "$failedpkgs" ]] && (err "The bad package(s) are:"; err "$failedpkgs"; debug "exiting..."; exit 1)) || exit 0