forked from venomlinux/scratchpkg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scratch
executable file
·1504 lines (1381 loc) · 34.5 KB
/
scratch
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/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 ([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 3 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 <https://www.gnu.org/licenses/>.
#
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
CYAN='\033[36m'
PURPLE='\033[35m'
CRESET='\033[0m'
nocolor() {
RED=
GREEN=
YELLOW=
CYAN=
PURPLE=
CRESET=
}
msg() {
printf "${GREEN}==>${CRESET} %s\n" "$1"
}
msginst() {
printf "[${GREEN}i${CRESET}] %s\n" "$1"
}
msgmiss() {
printf "[${YELLOW}m${CRESET}] %s\n" "$1"
}
msgnoinst() {
printf "[-] %s\n" "$1"
}
msgerr() {
printf "${RED}==> ERROR:${CRESET} %s\n" "$1" >&2
}
msgwarn() {
printf "${YELLOW}==> WARNING:${CRESET} %s\n" "$1" >&2
}
needroot() {
if [ "$(id -u)" != 0 ]; then
if [ "$#" -eq 0 ]; then
needroot "This operation"
else
msgerr "$* need root access!"
fi
exit 1
fi
}
getportpath() {
for repo in $PORT_REPO; do
if [ -f "$repo/$1/$BUILD_SCRIPT" ]; then
dirname "$repo/$1/$BUILD_SCRIPT"
return 0
fi
done
return 1
}
vercomp() {
if [ "$1" = "$2" ]; then
return 0 # same version
#elif [ "$1" = "$(echo "$1\n$2" | sort -V | head -n1)" ]; then
elif [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]; then
return 1 # $1 lower than $2
else
return 2 # $1 higher than $2
fi
}
get_iver() {
head -n1 $PKGDB_DIR/$1 2>/dev/null | awk '{print $1}'
}
get_irelease() {
head -n1 $PKGDB_DIR/$1 2>/dev/null | awk '{print $2}'
}
allinstalled() {
for i in $PKGDB_DIR/*; do
echo ${i##*/}
done
}
deps_alias() {
[ -f "$ALIAS_FILE" ] || {
echo $@
return
}
while [ "$1" ]; do
if [ "$(grep -w ^$1 $ALIAS_FILE)" ]; then
getalias=$(grep -w ^$1 $ALIAS_FILE | awk '{print $2}')
[ "$getalias" ] && echo "$getalias"
else
echo "$1"
fi
shift
unset getalias
done
}
get_depends() {
ppath=$(getportpath $1) || return 0
deps=$(grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \
| sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \
| tr ' ' '\n' \
| awk '!a[$0]++' \
| sed 's/,//')
deps_alias $deps
}
confirm() {
printf "$1 (Y/n) "
read -r response
case "$response" in
[Nn][Oo]|[Nn]) echo "$2"; return 2 ;;
*) : ;;
esac
return 0
}
checktool() {
if ! command -v $1 >/dev/null; then
msgerr "'$1' not exist in your system!"
exit 1
fi
}
needarg() {
[ "$*" ] || {
msgerr "This operation required an arguments!"
exit 1
}
}
isinstalled() {
if [ -s "$PKGDB_DIR/$1" ]; then
return 0
else
return 1
fi
}
settermtitle() {
printf "\033]0;$*\a"
}
scratch_integrity() {
if [ "$1" ]; then
cd /
if [ -f $PKGDB_DIR/$1 ]; then
tail -n+2 $PKGDB_DIR/$1 | while read -r line; do
if [ ! -e "$line" ]; then
if [ -L "$line" ]; then
printf "${YELLOW}broken symlink${CRESET} $1: /$line"
else
printf "${RED}file missing${CRESET} $1: /$line"
fi
fi
done
else
echo "Package '$1' not installed."
exit 1
fi
cd - >/dev/null
else
cd /
for pkg in $(allinstalled); do
tail -n+2 $PKGDB_DIR/$pkg | while read -r line; do
if [ ! -e "$line" ]; then
if [ -L "$line" ]; then
echo "broken symlink $pkg: /$line"
else
echo "missing file $pkg: /$line"
fi
fi
done
done
cd - >/dev/null
fi
}
scratch_locate() {
needarg $@
for repo in $PORT_REPO; do
grep -R $@ $repo/*/.pkgfiles 2>/dev/null | sed 's/:/ /;s/\/\.pkgfiles//' | awk '{print $1,$4}'
done
}
scratch_isorphan() {
needarg $@
for pkg in $(allinstalled); do
if depend=$(get_depends $pkg); then
for dep in $depend; do
if [ $dep = $1 ]; then
return 1
fi
done
fi
unset depend dep
done
return 0
}
scratch_sync() {
portsync
}
cvperms() {
# converts symbolic to numeric permissions
# required an input (symbolic, eg: drwxr-xr-x)
s=0; n=0; count=0
for i in $(echo "$1" | sed -e 's/\(.\)/\1\n/g'); do
count=$((count+1))
case $i in
d) ;;
r) n=$((n+4));;
w) n=$((n+2));;
x) n=$((n+1));;
s) [ $count = 4 ] && s=$((s+4)) || s=$((s+2)); n=$((n+1));;
t) s=$((s+1));n=$((n+1));;
S) s=$((s+2));;
T) s=$((s+1));;
esac
[ "$count" = 4 ] && {
user=$n; n=0
}
[ "$count" = 7 ] && {
group=$n; n=0
}
[ "$count" = 10 ] && {
other=$n; n=0
}
done
echo "$s$user$group$other"
}
fixperms() {
needroot "Fix permissions"
for i in $PKGDBPERMS_DIR/*; do
[ -s $i ] || continue
while read -r perms own dir; do
chmod $(cvperms $perms) /$dir
echo $own | while IFS=/ read -r o g; do
chown $o:$g /$dir
done
done < $i
done
}
scratch_trigger() {
needroot "Run trigger"
if [ -z "$*" ]; then
for i in $(seq 12); do
eval trig_$i=1
done
else
pre_triggers $@
fi
post_triggers
}
post_triggers() {
if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then
echo "trigger: Updating fontconfig cache..."
fc-cache -s
fi
if [ "$trig_10" = 1 ] && [ $(command -v gdk-pixbuf-query-loaders) ]; then
echo "trigger: Probing GDK-Pixbuf loader modules..."
gdk-pixbuf-query-loaders --update-cache
fi
if [ "$trig_9" = 1 ] && [ $(command -v gio-querymodules) ]; then
echo "trigger: Updating GIO module cache..."
gio-querymodules /usr/lib/gio/modules
fi
if [ "$trig_8" = 1 ] && [ $(command -v glib-compile-schemas) ]; then
echo "trigger: Compiling GSettings XML schema files..."
glib-compile-schemas /usr/share/glib-2.0/schemas
fi
if [ "$trig_7" = 1 ] && [ $(command -v gtk-query-immodules-2.0) ]; then
echo "trigger: Probing GTK2 input method modules..."
gtk-query-immodules-2.0 --update-cache
fi
if [ "$trig_6" = 1 ] && [ $(command -v gtk-query-immodules-3.0) ]; then
echo "trigger: Probing GTK3 input method modules..."
gtk-query-immodules-3.0 --update-cache
fi
if [ "$trig_5" = 1 ] && [ $(command -v gtk-update-icon-cache) ]; then
echo "trigger: Updating icon theme caches..."
for dir in /usr/share/icons/* ; do
if [ -e $dir/index.theme ]; then
gtk-update-icon-cache -q $dir 2>/dev/null
else
rm -f $dir/icon-theme.cache
rmdir --ignore-fail-on-non-empty $dir
fi
done
fi
if [ "$trig_4" = 1 ] && [ $(command -v udevadm) ]; then
echo "trigger: Updating hardware database..."
udevadm hwdb --update
fi
if [ "$trig_3" = 1 ] && [ $(command -v mkfontdir) ] && [ $(command -v mkfontscale) ]; then
echo "trigger: Updating X fontdir indices..."
for dir in $(find /usr/share/fonts -maxdepth 1 -type d \( ! -path /usr/share/fonts \)); do
rm -f $dir/fonts.scale $dir/fonts.dir $dir/.uuid
rmdir --ignore-fail-on-non-empty $dir
[ -d "$dir" ] || continue
mkfontdir $dir
mkfontscale $dir
done
fi
if [ "$trig_2" = 1 ] && [ $(command -v update-desktop-database) ]; then
echo "trigger: Updating desktop file MIME type cache..."
update-desktop-database --quiet
fi
if [ "$trig_1" = 1 ] && [ $(command -v update-mime-database) ]; then
echo "trigger: Updating the MIME type database..."
update-mime-database /usr/share/mime
fi
fixperms
}
pre_triggers() {
# mime db
if [ "$trig_1" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/mime/$ $PKGDB_DIR/$pkg)" ]; then
trig_1=1
break
fi
done
fi
# desktop db
if [ "$trig_2" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/applications/$ $PKGDB_DIR/$pkg)" ]; then
trig_2=1
break
fi
done
fi
# mkfontdir
if [ "$trig_3" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/fonts/$ $PKGDB_DIR/$pkg)" ]; then
trig_3=1
break
fi
done
fi
# hwdb
if [ "$trig_4" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^etc/udev/hwdb.d/$ $PKGDB_DIR/$pkg)" ]; then
trig_4=1
break
fi
done
fi
# icon caches
if [ "$trig_5" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/icons/$ $PKGDB_DIR/$pkg)" ]; then
trig_5=1
break
fi
done
fi
# gtk3 immodules
if [ "$trig_6" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/lib/gtk-3.0/3.0.0/immodules/.*.so $PKGDB_DIR/$pkg)" ]; then
trig_6=1
break
fi
done
fi
# gtk2 immodules
if [ "$trig_7" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/lib/gtk-2.0/2.10.0/immodules/.*.so $PKGDB_DIR/$pkg)" ]; then
trig_7=1
break
fi
done
fi
# gsettings schema
if [ "$trig_8" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/glib-2.0/schemas/$ $PKGDB_DIR/$pkg)" ]; then
trig_8=1
break
fi
done
fi
# gio modules
if [ "$trig_9" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/lib/gio/modules/.*.so $PKGDB_DIR/$pkg)" ]; then
trig_9=1
break
fi
done
fi
# gdk-pixbuf
if [ "$trig_10" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/.*.so $PKGDB_DIR/$pkg)" ]; then
trig_10=1
break
fi
done
fi
# font caches
if [ "$trig_11" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/fonts/$ $PKGDB_DIR/$pkg)" ]; then
trig_11=1
break
fi
done
fi
}
scratch_build() {
while [ "$1" ]; do
case $1 in
-i|-u|-r|-g|-p) ;;
--log) LOG=1;;
-*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";;
esac
shift
done
[ "$PKGNAME" ] || {
echo "Please specify package(s) to build."
return 1
}
for pkg in $PKGNAME; do
ppath=$(getportpath $pkg) || {
echo "Package '$pkg' not found."
return 1
}
cd $ppath
settermtitle "Building $pkg..."
if [ "$LOG" ]; then
pkgbuild $OPTS | tee /var/log/pkgbuild.log || {
settermtitle "Building $pkg failed."
return 1
}
else
pkgbuild $OPTS || {
settermtitle "Building $pkg failed."
return 1
}
fi
settermtitle "Building $pkg done."
cd - >/dev/null
done
}
scratch_install() {
needroot "Installing package"
while [ "$1" ]; do
case $1 in
-i|-u) ;;
-r|--reinstall) REINSTALL=1;;
-y|--yes) NOCONFIRM=1;;
-n|--no-dep) NO_DEP=1;;
--exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";;
esac
shift
done
[ "$PKGNAME" ] || {
echo "Please specify package(s) to install."
return 1
}
# if reinstall, dont calculate dep, just reinstall it then exit
if [ "$REINSTALL" = 1 ]; then
error=0
for ii in $PKGNAME; do
if [ ! $(getportpath $ii) ]; then
echo "Package '$ii' not found."
elif ! isinstalled $ii; then
echo "Package '$ii' not installed."
else
cd $(getportpath $ii)
settermtitle "Reinstalling $ii..."
pkgbuild $OPTS -r || {
error=1
break
}
[ -f ./post-install.sh ] && {
sh ./post-install.sh
}
done_pkg="$done_pkg $ii"
cd - >/dev/null
fi
done
settermtitle "Triggering install hook..."
[ "$done_pkg" ] && scratch_trigger $done_pkg
settermtitle "Reinstalling done."
return "$error"
fi
if [ "$NO_DEP" = 1 ]; then
error=0
for ii in $PKGNAME; do
if [ ! $(getportpath $ii) ]; then
echo "Package '$ii' not found."
elif isinstalled $ii; then
echo "Package '$ii' already installed."
continue
else
cd $(getportpath $ii)
settermtitle "Installing $ii..."
pkgbuild -i $OPTS || {
error=1
break
}
done_pkg="$done_pkg $ii"
cd - >/dev/null
fi
done
settermtitle "Triggering install hook..."
[ "$done_pkg" ] && scratch_trigger $done_pkg
settermtitle "Installing done."
return "$error"
fi
for i in $PKGNAME; do
if [ ! $(getportpath $i) ]; then
echo "Package '$i' not found."
elif isinstalled $i; then
echo "Package '$i' already installed."
else
IPKG="$IPKG $i"
fi
done
[ "$IPKG" ] || return 0
echo "Resolving dependencies..."
INST="$(scratch_deplist -q $IPKG $EXOPT)"
if [ "$INST" ]; then
echo
pkgcount=0
for pkg in $INST; do
pkgcount=$(( pkgcount + 1 ))
printf "[${GREEN}i${CRESET}] $pkg "
done
echo; echo
echo "( $pkgcount install )"
echo
if [ ! "$NOCONFIRM" ]; then
confirm "Continue install package(s)?" "Package installation cancelled." || exit $?
echo
fi
error=0
count=0
total=$(echo $INST | wc -w)
for int in $INST; do
count=$(( count + 1 ))
if portpathh=$(getportpath $int); then
cd $portpathh
settermtitle "[ $count/$total ] installing $int..."
[ -f ./pre-install.sh ] && {
sh ./pre-install.sh
}
pkgbuild -i $OPTS || {
error=1
count=$(( count - 1 ))
break
}
[ -f ./post-install.sh ] && {
sh ./post-install.sh
}
done_pkg="$done_pkg $int"
cd - >/dev/null
else
msgwarn "Skipping missing package: $int"
fi
unset portpathh
done
settermtitle "Triggering install hook..."
[ "$done_pkg" ] && scratch_trigger $done_pkg
settermtitle "$count/$total package(s) installed."
return "$error"
fi
}
scratch_remove() {
needroot "Removing package"
while [ "$1" ]; do
case $1 in
-y|--yes) NOCONFIRM=1;;
-*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";;
esac
shift
done
[ "$PKGNAME" ] || {
echo "Please specify package(s) to remove."
return 1
}
for i in $PKGNAME; do
if ! isinstalled $i; then
echo "Package '$i' not installed."
else
IPKG="$IPKG $i"
fi
done
[ "$IPKG" ] || return 0
echo "Removing packages..."
echo
pkgcount=0
count=0
for pkg in $IPKG; do
pkgcount=$(( pkgcount + 1 ))
printf "[${RED}x${CRESET}] $pkg "
done
echo; echo
echo "( $pkgcount remove )"
echo
[ "$NOCONFIRM" ] || {
confirm "Continue remove package(s)?" "Package removing cancelled." || exit $?
echo
}
for pkg in $IPKG; do
count=$(( count + 1 ))
pre_triggers $pkg
settermtitle "[ $count/$pkgcount ] Removing $pkg..."
pkgdel $pkg $OPTS || {
error=1
break
}
done
settermtitle "Triggering remove hook..."
post_triggers
settermtitle "$pkgcount package(s) removed."
}
outdatepkg() {
for pkg in $(allinstalled); do
###error is here for sysup
if [[ -f "$MASK_FILE" ]] && [[ $(grep -Ev '^(#|$| )' $MASK_FILE | grep -Fx "$pkg" ) ]]; then
#if [[ -f "$MASK_FILE" ]] && [[ $(grep -Ev '^(#|$| )' $MASK_FILE | grep -w $pkg) ]]; then
continue
fi
[ -e "$PKGDB_DIR/$pkg/.lock" ] && continue
getportpath $pkg >/dev/null || continue
. $(getportpath $pkg)/$BUILD_SCRIPT
if [ -z "$name" ] || [ -z "$version" ]; then
continue
fi
iversion=$(get_iver $pkg)
irelease=$(get_irelease $pkg)
if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then
echo $name
fi
unset iversion irelease version release
done
}
scratch_sysup() {
needroot "Upgrading package"
while [ "$1" ]; do
case $1 in
-i|-u|-r) ;;
-y|--yes) NOCONFIRM=1;;
-n|--no-dep) NODEP=1;;
--exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";;
esac
shift
done
echo "Checking for outdated packages..."
PKGOUTDATE=$(outdatepkg)
[ "$PKGOUTDATE" ] || {
echo "All packages are up to date."
return 0
}
[ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x scratchpkg)" ] && {
echo
msgerr "Please upgrade 'scratchpkg' first."
return 1
}
UPGPKG=0
NEWPKG=0
if [ "$NODEP" != 1 ]; then
echo "Resolving dependencies..."
DEP=$(scratch_deplist $PKGOUTDATE $EXOPT | awk '{print $2}')
echo
for d in $DEP; do
if [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x $d)" = "$d" ]; then
printf "[${GREEN}u${CRESET}] $d "
WILLINSTALL="$WILLINSTALL $d"
UPGPKG=$(( UPGPKG + 1 ))
elif ! isinstalled $d && [ "$(getportpath "$d")" ]; then
printf "[${CYAN}n${CRESET}] $d "
WILLINSTALL="$WILLINSTALL $d"
NEWPKG=$(( NEWPKG + 1 ))
fi
done
else
echo
for dd in $PKGOUTDATE; do
printf "[${GREEN}u${CRESET}] $dd "
WILLINSTALL="$WILLINSTALL $dd"
UPGPKG=$(( UPGPKG + 1 ))
done
fi
echo; echo
echo "( $UPGPKG upgrade, $NEWPKG new install )"
echo
[ "$NOCONFIRM" ] || {
confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $?
echo
}
error=0
count=0
total=$(echo $WILLINSTALL | wc -w)
for inst in $WILLINSTALL; do # install all required dependencies and target packages itself
count=$(( count + 1 ))
cd $(getportpath $inst)
if ! isinstalled $inst; then
settermtitle "[ $count/$total ] Installing $inst..."
[ -f ./pre-install.sh ] && {
sh ./pre-install.sh
}
pkgbuild -i $OPTS || {
error=1
count=$(( count - 1 ))
break
}
[ -f ./post-install.sh ] && {
sh ./post-install.sh
}
else
settermtitle "[ $count/$total ] Upgrading $inst..."
[ -f ./pre-upgrade.sh ] && {
sh ./pre-upgrade.sh
}
pkgbuild -u $OPTS || {
error=1
count=$(( count - 1 ))
break
}
[ -f ./post-upgrade.sh ] && {
sh ./post-upgrade.sh
}
fi
cd - >/dev/null
done_pkg="$done_pkg $inst"
done
settermtitle "Triggering install hook."
[ "$done_pkg" ] && scratch_trigger $done_pkg
settermtitle "$count/$total package(s) upgraded."
return "$error"
}
scratch_upgrade() {
needroot "Upgrading package"
while [ "$1" ]; do
case $1 in
-i|-r) ;;
-y|--yes) NOCONFIRM=1;;
-d|--no-dep) NO_DEP=1;;
--exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";;
esac
shift
done
[ "$PKGNAME" ] || {
echo "Please specify package(s) to upgrade."
return 1
}
for pkg in $PKGNAME; do
if ! isinstalled $pkg; then
echo "Package '$pkg' not installed."
continue
elif [ ! $(getportpath $pkg) ]; then
echo "Package '$pkg' not exist."
continue
else
. $(getportpath $pkg)/$BUILD_SCRIPT
if [ "$(get_iver $pkg)-$(get_irelease $pkg)" = "$version-$release" ]; then
echo "Package '$pkg' is up to date."
continue
fi
fi
upkg="$upkg $pkg"
done
[ "$upkg" ] || return 0
UPGPKG=0
NEWPKG=0
if [ "$NODEP" != 1 ]; then
echo "Resolving dependencies..."
DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}')
echo
for d in $DEP; do
if [ "$(echo $upkg | tr ' ' '\n' | grep -x $d)" = "$d" ]; then
printf "[${GREEN}u${CRESET}] $d "
WILLINSTALL="$WILLINSTALL $d"
UPGPKG=$(( UPGPKG + 1 ))
elif ! isinstalled $d && [ "$(getportpath "$d")" ]; then
printf "[${CYAN}n${CRESET}] $d "
WILLINSTALL="$WILLINSTALL $d"
NEWPKG=$(( NEWPKG + 1 ))
fi
done
else
echo
for dd in $upkg; do
printf "[${GREEN}u${CRESET}] $dd "
WILLINSTALL="$WILLINSTALL $dd"
UPGPKG=$(( UPGPKG + 1 ))
done
fi
echo; echo
echo "( $UPGPKG upgrade, $NEWPKG new install )"
echo
[ "$NOCONFIRM" ] || {
confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $?
echo
}
error=0
count=0
total=$(echo $WILLINSTALL | wc -w)
for inst in $WILLINSTALL; do # install all required dependencies and target packages itself
count=$(( count + 1 ))
cd $(getportpath $inst)
if ! isinstalled $inst; then
settermtitle "[ $count/$total ] Installing $inst..."
[ -f ./pre-upgrade.sh ] && {
sh ./pre-upgrade.sh
}
pkgbuild -i $OPTS || {
error=1
count=$(( count - 1 ))
break
}
[ -f ./post-upgrade.sh ] && {
sh ./post-upgrade.sh
}
else
settermtitle "[ $count/$total ] Upgrading $inst..."
[ -f ./pre-upgrade.sh ] && {
sh ./pre-upgrade.sh
}
pkgbuild -u $OPTS || {
error=1
count=$(( count - 1 ))
break
}
[ -f ./post-upgrade.sh ] && {
sh ./post-upgrade.sh
}
fi
cd - >/dev/null
done_pkg="$done_pkg $inst"
done
settermtitle "Triggering install hook."
[ "$done_pkg" ] && scratch_trigger $done_pkg
settermtitle "$count/$total package(s) upgraded."
return "$error"
}
scratch_outdate() {
for pkg in $(allinstalled); do
if [ "$(getportpath $pkg)" ]; then
. $(getportpath $pkg)/$BUILD_SCRIPT
if [ -z "$name" ] || [ -z "$version" ]; then
continue
fi
iversion=$(get_iver $pkg)
irelease=$(get_irelease $pkg)
#if [[ -f "$MASK_FILE" ]] && [[ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]]; then
if [[ -f "$MASK_FILE" ]] && [[ $(grep -Ev '^(#|$| )' $MASK_FILE | grep -Fx "$pkg" ) ]]; then
ITSLOCK="[masked]"
fi
#outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK"
#newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK"
outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}"
newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}"
if [ "$version" != "$iversion" ]; then
vercomp $version $iversion
if [ $? = 2 ]; then
echo -e "$outdatemsg"
OUTDATE=yes
elif [ $? = 1 ]; then
echo -e "$newerinstmsg"
OUTDATE=yes
fi
elif [ "$release" != "$irelease" ]; then
vercomp $release $irelease
if [ $? = 2 ]; then
echo -e "$outdatemsg"
OUTDATE=yes
elif [ $? = 1 ]; then
echo -e "$newerinstmsg"
OUTDATE=yes
fi
fi
unset ITSLOCK name version
fi
done
[ ! "$OUTDATE" ] && msg "All packages are up to date."
}
scratch_search() {
needarg $@
arg=$*
for repo in $PORT_REPO; do
[ -d $repo ] || continue
out=$(grep -R "# description" $repo/*/$BUILD_SCRIPT | grep -i "$arg" | awk -F : '{print $1}' | sort)
[ "$out" ] || continue
found=1
for line in $out; do
repo=$(echo $line | rev | awk -F / '{print $3}' | rev)
desc=$(grep "^# description[[:blank:]]*:" $line | sed 's/^# description[[:blank:]]*:[[:blank:]]*//')
. $line
if isinstalled $name; then
ins="[${GREEN}*${CRESET}]"
else
ins="[ ]"
fi
printf "$ins ${PURPLE}($repo)${CRESET} $name ${CYAN}$version-$release${CRESET}: $desc\n"
unset repo desc name version release build
done
unset out
done
if [ ! "$found" ]; then
msg "No matching package found."
fi
}
scratch_changelog() {
needarg $@
arg=$*
for repo in $PORT_REPO; do
#echo $repo/$1
if [[ -d $repo/$1 ]];
then
found=1
if [[ -f $repo/$1/CHANGELOG ]];
then
cat $repo/$1/CHANGELOG;
else
echo "No Changelog Exists"
fi
break
fi
done