/
pkgr
executable file
·2471 lines (2109 loc) · 75 KB
/
pkgr
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
#!/usr/bin/bash
if [ -e $PREFIX/usr/bin/busybox ];
then
mv="$PREFIX/usr/bin/busybox mv"
cp="$PREFIX/usr/bin/busybox cp"
find="$PREFIX/usr/bin/busybox find"
sed="$PREFIX/usr/bin/busybox sed"
awk="$PREFIX/usr/bin/busybox awk"
dd="$PREFIX/usr/bin/busybox dd"
chmod="$PREFIX/usr/bin/busybox chmod"
chown="$PREFIX/usr/bin/busybox chown"
wget="$PREFIX/usr/bin/busybox wget"
tar="$PREFIX/usr/bin/busybox tar"
echo="$PREFIX/usr/bin/busybox echo"
cat="$PREFIX/usr/bin/busybox cat"
mkdir="$PREFIX/usr/bin/busybox mkdir"
grep="$PREFIX/usr/bin/busybox grep"
egrep="$PREFIX/usr/bin/busybox egrep"
ls="$PREFIX/usr/bin/busybox ls"
wc="$PREFIX/usr/bin/busybox wc"
rm="$PREFIX/usr/bin/busybox rm"
xargs="$PREFIX/usr/bin/busybox xargs"
uname="$PREFIX/usr/bin/busybox uname"
diff="$PREFIX/usr/bin/busybox diff"
sort="$PREFIX/usr/bin/busybox sort"
uniq="$PREFIX/usr/bin/busybox uniq"
else
mv="mv"
cp="cp"
find="find"
sed="sed"
awk="awk"
dd="dd"
chmod="chmod"
chown="chown"
wget="wget"
tar="tar"
echo="echo"
cat="cat"
mkdir="mkdir"
grep="grep"
grep="egrep"
ls="ls"
wc="wc"
rm="rm"
xargs="xargs"
uname="uname"
diff="diff"
sort="sort"
uniq="uniq"
fi
ARCH=`$uname -m`
BLDRTMPDIR=$PREFIX/tmp/bldr
LIBDB=$PREFIX/var/noop/libdb
USER_MIRRORS=$PREFIX/etc/noop/mirrors
USER_OVERRIDES=$PREFIX/etc/noop/overrides
METADIR=$PREFIX/var/noop/meta
NEWCONF=$PREFIX/var/noop/new_config
INSTALLEDDIR=$PREFIX/var/noop/installed
TMPLIBDB=$PREFIX/var/noop/libdb.tmp
PACKAGEDB=$PREFIX/var/noop/packages
DEPDB=$PREFIX/var/noop/deps
TMPDIR=$PREFIX/tmp/noop
TMPFILE=$TMPDIR/meta.tmp
TMPLIBFILE=$TMPDIR/tmplib.tmp
GITHOST=https://github.com/nemasu/noop-linux.git
HOST=https://www.nooplinux.org/noop
if [ -e $USER_MIRRORS ];
then
source $USER_MIRRORS
fi
if [ -e $USER_OVERRIDES ];
then
source $USER_OVERRIDES
fi
if [ -z "$BLDR_CORES" ]; then
let BLDR_CORES=`$grep "processor" /proc/cpuinfo | $wc -l`
let BLDR_CORES=${BLDR_CORES}+1
fi
PKGHOST=$HOST/packages/$ARCH
$mkdir -p $INSTALLEDDIR
$mkdir -p $METADIR
$mkdir -p $TMPDIR/run
Black='\033[0;30m'
Red='\033[0;31m'
Green='\033[0;32m'
BrownOrange='\033[0;33m'
Blue='\033[0;34m'
Purple='\033[0;35m'
Cyan='\033[0;36m'
LightGray='\033[0;37m'
DarkGray='\033[1;30m'
LightRed='\033[1;31m'
LightGreen='\033[1;32m'
Yellow='\033[1;33m'
LightBlue='\033[1;34m'
LightPurple='\033[1;35m'
LightCyan='\033[1;36m'
White='\033[1;37m'
NoColor='\033[0m'
function trs() {
local string="$1"
declare -A translate
translate=( ["a"]="0"
["b"]="1"
["c"]="2"
["d"]="3"
["e"]="4"
["f"]="5"
["g"]="6"
["h"]="7"
["i"]="8"
["j"]="9"
["k"]="10"
["l"]="11"
["m"]="12"
["n"]="13"
["o"]="14"
["p"]="15"
["q"]="16"
["r"]="17"
["s"]="18"
["t"]="19"
["u"]="20"
["v"]="21"
["w"]="22"
["x"]="23"
["y"]="24"
["z"]="25")
for i in "${!translate[@]}"; do
string="$(sed -e "s/$i/${translate[$i]}/g" <<< "$string")"
done
echo "$string"
}
function vercomp ()
{
if [[ $1 == $2 ]]
then
return 0
fi
#Relpace any "-" with "." and any alpha with number.
V1=`$echo $1 | $sed 's/\-/\./g'`
V2=`$echo $2 | $sed 's/\-/\./g'`
V1=`trs $V1`
V2=`trs $V2`
local IFS=.
local i ver1=($V1) ver2=($V2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1 # >
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2 # <
fi
done
return 0 # =
}
function meson-wrap() {
meson setup \
--prefix /usr \
--libdir /usr/lib \
--libexecdir /usr/lib \
--bindir /usr/bin \
--sbindir /usr/bin \
--includedir /usr/include \
--datadir /usr/share \
--mandir /usr/share/man \
--infodir /usr/share/info \
--localedir /usr/share/locale \
--sysconfdir /etc \
--localstatedir /var \
--sharedstatedir /var/lib \
--buildtype release \
--wrap-mode nofallback \
"$@"
}
function GetFileList() {
curl -L -s $LISTURL | sed -ne'/'"${NAME}"'-[0-9.]*.tar.\(gz\|xz\|bz2\)/p' | sed -e 's/.*'"${NAME}"'/'"${NAME}"'/g;s/.tar.\(gz\|xz\|bz2\).*/.tar.\1/g' | sort | uniq
}
function LatestVersionGitHub() {
curl -s -L $1 | egrep "v[0-9\.]+\.tar\.gz" | head -n1 | sed -e 's/.*v\([0-9\.]*\)\.tar\.gz.*/\1/g'
}
function ShowProgress
{
#tput civis
let amount=25
let n=$1
let d=$2
draw=`echo "($n * $amount) / $d" | bc`
#percent=`echo "($draw * 100) / $amount" | bc`
percent=`echo "($n * 100) / $d" | bc`
echo -ne "\r"
for spcount in $(seq 1 $draw);
do
echo -n "#"
done
for spcount in $(seq $draw 25)
do
echo -n " "
done
echo -n "($percent%)"
#tput cnorm
}
function bininst_install() {
BININST_DLFILE=/tmp/noop-${BININST_NAME}
IS_ENV_SET=`cat /etc/profile | grep "${BININST_ENV_HOME}" | wc -l`
if [ $IS_ENV_SET -gt 0 ]; then
echo "Environment variables seem to be set, skipping..."
else
echo >> /etc/profile
echo "export ${BININST_ENV_HOME}=/opt/${BININST_NAME}" >> /etc/profile
echo 'export PATH=${'"${BININST_ENV_HOME}"'}'"${BININST_ENV_BINDIR}"':${PATH}' >> /etc/profile
fi
wget "${DOWNLOAD_TAR}" -O${BININST_DLFILE}
mkdir -p /opt && pushd /opt &> /dev/null
if [ "$1" == "deb" ]; then
bsdtar -xf "${BININST_DLFILE}"
rm control.tar.gz debian-binary
tar xf data.tar.gz && rm data.tar.gz
NEW_DIR=`ls opt`
mv ./opt/* . && rm -r ./opt
popd
else
NEW_DIR=`tar tf "${BININST_DLFILE}" | head -n1 | sed -e 's/\/.*//'`
tar xof "${BININST_DLFILE}"
fi
if [ "${BININST_NAME}" != "${NEW_DIR}" ];
then
rm -rf ${BININST_NAME}
ln -s ${NEW_DIR} ${BININST_NAME}
fi
popd &> /dev/null
rm "${BININST_DLFILE}"
echo
echo "Done, source /etc/profile or re-login to gain environment variables."
exit
}
#1 name
function get_packagedb_version() {
ARCHPOST="_$ARCH"
#+ is a valid character in a package name.
name=`echo ${1} | sed -e 's|+|\\\+|g'`
#Why isnt this working...
#$echo "`$egrep "^${1}," $PACKAGEDB | perl -pe 's/^.*?-([0-9])/\1/g' | $sed -e 's/\.pkg//g' | $sed -e 's/'"$ARCHPOST"'//g'`"
echo "`egrep "^${name}," $PACKAGEDB | perl -pe 's/^.*?-([0-9])/\1/g' | sed -e 's/\.pkg//g' | sed -e 's/'"$ARCHPOST"'//g'`"
}
#1 name
function get_installed_version() {
#why isnt this working...
#$echo `$grep -m1 "VER:" "$INSTALLEDDIR/$1" | $sed -e 's/VER://'`
grep -m1 "VER:" "$INSTALLEDDIR/$1" | sed 's/VER://'
}
function DoSync() {
if [ ! -e $PREFIX/var/noop/.git ];
then
echo "New install detected, initializing repo."
cd $PREFIX/var/
mv noop noop.bak
git clone --depth=1 $GITHOST noop
cp -r noop.bak/* noop/ && rm -rf noop.bak
rm -rf $PREFIX/usr/sbin/pkgr
ln -s /var/noop/pkgr $PREFIX/usr/sbin/pkgr
#Use current mirror
if [ -e /etc/noop/mirrors ]; then
mkdir -p $PREFIX/etc/noop/
cp /etc/noop/mirrors $PREFIX/etc/noop/
fi
pushd $PREFIX/var/noop &> /dev/null
$echo
else
$echo -e "${Cyan}Syncing ...${LightBlue}"
pushd $PREFIX/var/noop &> /dev/null
if [ ! `git status -s | wc -l` -eq 0 ]; then
$echo "Local noop repository contains changes, exiting..."
popd &> /dev/null
return 1
fi
git pull
$echo
$echo -e "${Green}done.${NoColor}"
fi
$echo
$echo -ne "${Cyan}Generating packages list..."
curl -s -L $HOST/packages/${ARCH}/ | $grep -E "href=\".+.pkg\"" | $sed 's/.*href="//g;s/">.*//g;' | perl -pe 's/(^.*?)-([0-9])/\1,\1-\2/g' > $PACKAGEDB
$echo -e "${Green}done."
$echo
$echo -en "${Cyan}Generating deps list..."
rm -rf deps; for i in `cat packages | sed 's/,/ /' | awk '{print $1;}'`; do for j in `grep -m1 "^DEPS=" blds/$i/*.bld 2>/dev/null | sed "s/DEPS=//g;s/(//g;s/)//;s/'//g;"`; do echo ${i}:${j} >> deps; done done
$echo -e "${Green}done.${NoColor}"
popd &> /dev/null
}
function DoDownload() {
name=$1
dest=$2
let PKGEXIST=`$grep "^$name," $PACKAGEDB | $wc -l`
if [ 1 -eq $PKGEXIST ]; then
PKGNAME=`$grep "^$name," $PACKAGEDB | $sed -e 's/^'"$name"',//g'`;
$wget $PKGHOST/$PKGNAME -O$TMPDIR/$PKGNAME
if [ $? != 0 ]; then
$echo $wget encountered an error.
exit 1
fi
if [ ! -z $dest ]; then
$mv $TMPDIR/$PKGNAME $dest
$echo Location: $dest
else
$echo Location: $TMPDIR/$PKGNAME
fi
else
$echo "Error: $name is not a valid package."
exit 1
fi
}
function DoNewconfig() {
let NUM=`cat $NEWCONF | wc -l`
if [ $NUM -gt 0 ]; then
echo "You have $NUM files that need updating."
echo "What would you like to do?"
read -p "Overwrite all old files(a), Quit(q), Wizard(w): " INPUT
if [ "$INPUT" == "q" ]; then
exit 0
else
for i in `cat $NEWCONF`; do
if [ -e "$i" ]; then
OLD=`echo "$i" | sed 's/\.new$//g'`
if [ "$INPUT" == "a" ]; then
mv -v "$i" "$OLD"
elif [ "$INPUT" == "w" ]; then
git diff "$OLD" "$i"
read -p "(k)eep yours or (r)eplace with new?: " WATDO
if [ "$WATDO" == "k" ]; then
rm -v "$i"
elif [ "$WATDO" == "r" ]; then
mv -v "$i" "$OLD"
else
echo "Invalid input, exiting..."
exit 1
fi
else
echo "Invalid input, exiting..."
exit 1
fi
else
echo "$i not found, skipping.."
fi
let LOC=`grep -n "$i" $NEWCONF | sed 's/:/ /;' | awk '{print $1;}'`
$sed -i -e "${LOC}d" $NEWCONF
done
fi
else
echo "No files need updating."
fi
}
function DoVersioncheck() {
name=$1
if ! [[ $name =~ .*\.bldj ]];
then
pushd $PREFIX/var/noop/blds/$name &> /dev/null
else
rm -rf /tmp/noop/verchecktmp
mkdir -p /tmp/noop/verchecktmp
pushd /tmp/noop/verchecktmp &> /dev/null
BLDJFILE=`readlink -f $name`
tar xf $BLDJFILE
fi
BLDFILE=`ls *.bld`
source ./$BLDFILE
Detect
popd &> /dev/null
rm -rf /tmp/noop/verchecktmp
}
function DoShowRevdeps() {
name=$1
if [ -z "$name" ]; then
echo "Please provide a package name."
exit 1
fi
$grep ":$name$" $DEPDB | $sed -e 's/:.*//g'
}
function DoDepcheckPackages() {
name=$1
$echo "Scanning package for missing dependencies"
ldconfig &>/dev/null
tput civis
$rm -f /tmp/missinglibs && touch /tmp/missinglibs
$rm -f /tmp/missinglibs.found && touch /tmp/missinglibs.found
sed -ne '/FILES:/,$p' "$INSTALLEDDIR/$name" | grep -E "/usr/bin|/usr/lib|/bin|/lib" > /tmp/filelist
total_lines=`cat /tmp/filelist | wc -l`
let count=0
for i in `$cat /tmp/filelist`;
do
let count=$count+1
ShowProgress $count $total_lines
MISSINGLIBS=`ldd $i 2>&1 | $grep "not found" | $awk '{print $1;}' | sort | uniq`
for j in ${MISSINGLIBS[@]};
do
ISDIRECT=`readelf -d $i | $grep NEEDED | $awk '{print $5;}' | grep $j | wc -l`
DIRECT="DIRECT"
if [ "$ISDIRECT" == "0" ]; then
DIRECT="INDIRECT"
fi
if [ "$DIRECT" != "DIRECT" ];
then
$echo "$i -> $DIRECT $j" >> /tmp/missinglibs
else
#TODO determine if library is 32-bit or not and check accordingly
#if [ "$DIRECT" == "DIRECT" ] && [ "`find /usr/lib /usr/lib32 -name $j 2>/dev/null | wc -l`" == "0" ];
extra_dir=$(dirname `readlink -f "$i"`)
if [ "$DIRECT" == "DIRECT" ] && [ "`find /usr/lib $extra_dir -name $j 2>/dev/null | wc -l`" == "0" ];
then
$echo "$i -> $j $DIRECT" >> /tmp/missinglibs
else
$echo "$i -> $j $DIRECT File Found! Probably Okay." >> /tmp/missinglibs.found
fi
fi
done
done
$cat /tmp/missinglibs | sort | uniq > /tmp/missinglibs.sorted
$echo ""
if [ `cat /tmp/missinglibs.sorted | wc -l` -gt 0 ]; then
$echo "Missing Libs ( File -> Missing Library ):"
r=1
else
$echo "Nothing broken found!"
r=0
fi
$cat /tmp/missinglibs.sorted
$cp /tmp/missinglibs.sorted /tmp/depcheck.results
$echo "Results saved in /tmp/depcheck.results"
$rm /tmp/missinglibs /tmp/missinglibs.sorted /tmp/filelist 2>/dev/null
tput cnorm
exit $r
}
function DoCheckIsRequired() {
if [ -z $1 ]; then
echo "Error: Please provide a package name"
fi
let dep_exists=0
for i in `pkgr -D $1`; do
if [ -e /var/noop/installed/$i ]; then
let dep_exists=1
echo "$i is installed and depends on ${1}."
fi
done
if [ $dep_exists -eq 0 ]; then
echo "No packages that depend on ${1} were found, it can (probably) safely be removed."
fi
}
function genRDepTree() {
if [ -z "$1" ]; then
return
fi
for i in `pkgr -D $1`; do
if [ ${listedPkgs[$i]+_} ]; then #if found
continue
else
listedPkgs[$i]=1
fi
for (( j=0; j<$2; j++ )) do
echo -n " "
done
echo "|$i";
genRDepTree $i $(($2+1))
done
}
function genDepTree() {
if [ -z "$1" ]; then
return
fi
for i in `pkgr --jsonmeta $1 | jq -r .deps[]`; do
if [ ${listedPkgs[$i]+_} ]; then #if found
continue
else
listedPkgs[$i]=1
fi
for (( j=0; j<$2; j++ )) do
echo -n " "
done
echo "|$i";
genDepTree $i $(($2+1))
done
}
function DoPrintDepTree() {
unset listedPkgs
declare -A listedPkgs
genDepTree $1 0
}
function DoPrintRDepTree() {
unset listedPkgs
declare -A listedPkgs
genRDepTree $1 0
}
#TODO while loop not called if no parameters are passed
if [ -z $1 ]; then
isold=1
fi
while [[ $# > 0 ]]
do
key="$1"
case $key in
-s|--sync)
DoSync
;;
-d|--download)
shift
DoDownload $@
;;
-n|--newconfig)
DoNewconfig
;;
-V|--version-check)
shift
DoVersioncheck $1
;;
-R|--is-required)
shift
DoCheckIsRequired $1;
;;
-D|--show-revdeps)
shift
DoShowRevdeps $1
;;
-Cp|--depcheck-package)
shift
DoDepcheckPackages $1
;;
-pd|--print-dep-tree)
shift
DoPrintDepTree $1
;;
-prd|--print-rdep-tree)
shift
DoPrintRDepTree $1
;;
*)
#echo "Error: Unknown option: $1"
#exit 1
isold=1
break #TODO do this for now till the rest is ported over
;;
esac
shift # past argument or value
done
#TODO Fall through for now
if [ "$isold" != "1" ]; then
exit 0
fi
if [ -z $1 ] || [ $1 == "-h" ] || [ $1 == "--help" ]; then
if [ "$LANG" == "ja_JP.UTF-8" ]; then
$echo -e "\npkgr -- noop Linuxのパッケージマナじゃー"
$echo -e "\n使用法:"
$echo -e "\t-s,\t--sync パッケージのデータベースを同期します"
$echo -e "\t-d,\t--download pkg ダウンロードだけ"
$echo -e "\t-i,\t--install pkg インストール"
$echo -e "\t \t--to-install pkg Display required dependencies for pkg(s)."
$echo -e "\t-f,\t--install-file foo.pkg pkgファイルからインストールします"
$echo -e "\t-u,\t--upgrade pkg アップグレード"
$echo -e "\t-U,\t--upgrade-all システムアップグレード"
$echo -e "\t-r,\t--remove pkg 削除します"
$echo -e "\t-l,\t--list リスト利用可能なパッケージ"
$echo -e "\t \t--list-non-meta List installed packages that are not required."
$echo -e "\t-R,\t--is-required pkg Check if any packages that require pkg are installed"
$echo -e "\t-b,\t--belongs file-path パッケージのファイルをさがす"
$echo -e "\t-pd,\t--print-dep-tree pkg Print dependency tree for pkg."
$echo -e "\t-prd,\t--print-rdep-tree pkg Print reverse dependency tree for pkg."
$echo -e "\t-D,\t--show-revdeps pkg パッケージの逆依存関係をリストします"
$echo -e "\t-c,\t--depcheck dynamic-binary バイナリの依存関係をチェックします"
$echo -e "\t-C,\t--depcheck-system 全システムの依存関係をチェックします"
$echo -e "\t-Cp,\t--depcheck-package パッケージの依存関係をチェックします"
$echo -e "\t-Cr,\t--depcheck-revdep パッケージの逆依存関係の依存関係をチェックします"
$echo -e "\t-m,\t--make-bldj foo.bldj or name パッケージをビルドします(bldjファイルそれと、レポからダウンロードします)"
$echo -e "\t-V,\t--version-check name ビルドのため、新ソースをチェックみて。"
$echo -e "\t-n,\t--new-config 新コンフィグファイルを処理します"
$echo -e "\t \t--mkinitramfs Create initramfs"
else
$echo -e "\npkgr -- noop Linux package manager"
$echo -e "\nUsage:"
$echo -e "\n---Basic---"
$echo -e "\t-s,\t--sync Sync packgage database"
$echo -e "\t-i,\t--install pkg1 <pkg2...> Install"
$echo -e "\t-ia\t Install (show dependencies first)"
$echo -e "\t-u,\t--upgrade pkg Upgrade"
$echo -e "\t-U,\t--upgrade-all Upgrade system"
$echo -e "\t-r,\t--remove pkg Remove"
$echo -e "\t-l,\t--list List available packages"
$echo -e "\n---Dependencies---"
$echo -e "\t-C,\t--depcheck-system Check dependencies for entire system"
$echo -e "\t-Cp,\t--depcheck-package Check dependencies for given package"
$echo -e "\t-Cr,\t--depcheck-revdep Check dependencies for given packages reverse dependencies"
$echo -e "\t-R,\t--is-required pkg Check if any packages that require pkg are installed"
$echo -e "\t-pd,\t--print-dep-tree pkg Print dependency tree for pkg."
$echo -e "\t-prd,\t--print-rdep-tree pkg Print reverse dependency tree for pkg."
$echo -e "\t-D,\t--show-revdeps pkg List reverse dependencies for a package"
$echo -e "\t-c,\t--depcheck dynamic-binary Check dependencies for a binary"
$echo -e "\n---System---"
$echo -e "\t--mkinitramfs Create initramfs"
$echo -e "\t-n,\t--new-config Process new config files"
$echo -e "\t-b,\t--belongs file-path List package file belongs to"
$echo -e "\t--list-non-meta List installed packages that are not required."
$echo -e "\n---Build---"
$echo -e "\t-m,\t--make-bldj foo.bldj or name Build a package (bldj file or grab it from repo)"
$echo -e "\t-V,\t--version-check name Check(try) if new source is available for building"
$echo -e "\t-genmeta package-name version Generate meta information using current directory."
$echo -e "\t-genpkg <metafile> Generate pkg using current directory."
$echo -e "\n---Other---"
$echo -e "\t-getfiles pkg-file Get files from pkg"
$echo -e "\t-readmeta pkg-file Read meta information from pkg file."
$echo -e "\t-d,\t--download pkg Only download"
$echo -e "\t--to-install pkg Display required dependencies for pkg(s)."
$echo -e "\t-f,\t--install-file foo.pkg Install from .pkg file"
$echo -e "\t-libdiff Run diff on libdb with git version."
$echo
$echo -e "Mirrors:\n\tcopy /var/noop/etc/mirrors to /etc/noop/mirrors and uncomment desired mirror."
fi
$echo -e "\n"
exit 0;
fi
if [ $1 == "--depcheck-revdep" ] || [ $1 == "-Cr" ]; then
$echo "Scanning machine for missing dependencies"
ldconfig &>/dev/null
tput civis
$rm -f /tmp/missinglibs && touch /tmp/missinglibs
$rm -f /tmp/missinglibs.found && touch /tmp/missinglibs.found
for i in `pkgr -D $2`;
do
sed -ne '/FILES:/,$p' $INSTALLEDDIR/$i | grep -E "/usr/bin|/usr/lib|/bin|/lib" >> /tmp/filelist
done
#TODO Factorize out these two depcheck functions
total_lines=`cat /tmp/filelist | wc -l`
let count=0
for i in `$cat /tmp/filelist`;
do
let count=$count+1
ShowProgress $count $total_lines
MISSINGLIBS=`ldd $i 2>&1 | $grep "not found" | $awk '{print $1;}' | sort | uniq`
for j in ${MISSINGLIBS[@]};
do
ISDIRECT=`readelf -d $i | $grep NEEDED | $awk '{print $5;}' | grep $j | wc -l`
DIRECT="DIRECT"
if [ "$ISDIRECT" == "0" ]; then
DIRECT="INDIRECT"
fi
if [ "$DIRECT" != "DIRECT" ];
then
$echo "$i -> $DIRECT $j" >> /tmp/missinglibs
else
#TODO determine if library is 32-bit or not and check accordingly
#if [ "$DIRECT" == "DIRECT" ] && [ "`find /usr/lib /usr/lib32 -name $j 2>/dev/null | wc -l`" == "0" ];
if [ "$DIRECT" == "DIRECT" ] && [ "`find /usr/lib -name $j 2>/dev/null | wc -l`" == "0" ];
then
$echo "$i -> $j $DIRECT" >> /tmp/missinglibs
else
$echo "$i -> $j $DIRECT File Found! Probably Okay." >> /tmp/missinglibs.found
fi
fi
done
done
$cat /tmp/missinglibs | sort | uniq > /tmp/missinglibs.sorted
$echo ""
if [ `cat /tmp/missinglibs.sorted | wc -l` -gt 0 ]; then
$echo "Missing Libs ( File -> Missing Library ):"
else
$echo "Nothing broken found!"
fi
$cat /tmp/missinglibs.sorted
$cp /tmp/missinglibs.sorted /tmp/depcheck.results
$echo "Results saved in /tmp/depcheck.results"
$rm /tmp/missinglibs /tmp/missinglibs.sorted /tmp/filelist 2>/dev/null
tput cnorm
fi
if [ $1 == "--depcheck-system" ] || [ $1 == "-C" ]; then
echo "Scanning machine for missing dependencies (this will take a while)."
let tot=`ls /var/noop/installed | wc -l`
let c=0
for i in `ls /var/noop/installed`; do
let c=$c+1
ShowProgress $c $tot
pkgr -Cp $i &> /dev/null
if [ $? -ne 0 ]; then
echo
echo $i
cat /tmp/depcheck.results
echo
fi
done
fi
if [ $1 == "--make-bldj" ] || [ $1 == "-m" ]; then
if [ -z $2 ]; then
echo Too few arguments.
exit 1;
fi
ISFILE=`echo $2 | grep ".bldj" | wc -l`
if [ "$ISFILE" != "0" ] && [ ! -e "$2" ]; then
echo "File $2 does not exist."
exit 1;
fi
if [ "$ISFILE" == "0" ]; then
if [ ! -e "$PREFIX/var/noop/blds/$2" ]; then
echo "Error: $PREFIX/var/noop/blds/$2 does not exist"
exit 1
fi
cd "$PREFIX/var/noop/blds/$2"
tar cjf /tmp/file.bldj *
else
cp `readlink -f $2` /tmp/file.bldj
fi
FILE="/tmp/file.bldj"
#Called inside of BuildAndInstall
#It will grab another source tar and cd into it
#Note: do this after installing previous package
function GetSource
{
cd ..
rm -rf *
wget --inet4-only $1 -Osrc
tar xf src
rm src
cd `ls`
}
function PushScripts
{
if [ -e /tmp/bldr/pkg.install ];
then
mv /tmp/bldr/pkg.install /tmp/bldr/pkg.install.p
fi
}
function PopScripts
{
if [ -e /tmp/bldr/pkg.install.p ];
then
mv /tmp/bldr/pkg.install.p /tmp/bldr/pkg.install
fi
}
pushd .
rm -rf $BLDRTMPDIR
mkdir -p $BLDRTMPDIR
cd $BLDRTMPDIR
tar xf $FILE
rm $FILE
set -e
source $BLDRTMPDIR/*.bld
rm $BLDRTMPDIR/*.bld
if [ -z "${SKIP_DEP_CHECK}" ];
then
for i in ${DEPS[@]};
do
if [ ! -e $INSTALLEDDIR/$i ];
then
echo "Installing dependency ${i}..."
pkgr -i $i
fi
done
fi
AT_BLDR_CONF="--enable-static --includedir=/usr/include --mandir=/usr/man --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib --datadir=/usr/share --bindir=/usr/bin --prefix=/usr"
if [ -z "$BLDR_CONTINUE" ];
then
rm -rf ~/bldr-tmp/*
fi
rm -rf ~/bldr-inst
mkdir -p ~/bldr-tmp
mkdir -p ~/bldr-inst
mkdir -p ~/bldr-done
cd ~/bldr-tmp
if [ -n "$SRC" ];
then
if [ -z "$BLDR_CONTINUE" ];
then
if [[ $SRC =~ ^git+.* ]]; then
addr=`echo "${SRC}" | sed -e 's/#.*$//g;s/^git+//'`
tag=`echo "${SRC}" | sed -e 's/.*#//g'`
git clone ${addr} src
cd src
git checkout ${tag}
else
wget --inet4-only $SRC -Osrc
if [[ $SRC =~ .*zip$ ]]; then
unzip src
else
tar xf src
fi
rm src
fi
fi
cd `ls` || true
fi
for i in `ls $BLDRTMPDIR/*.patch`;
do
if [ -z "$BLDR_CONTINUE" ];
then
patch -Np1 -i $i
fi
rm $i
done
if [ -z "$BLDR_DIST" ]; then
echo "NOTE: BLDR_DIST is not set, building using march=native"
export CFLAGS="$CFLAGS -march=native"
export CXXFLAGS="$CXXFLAGS -march=native"
fi
if [ "$BUILD" == "autotools" ]; then
if [ ! -e ./configure ] && [ -e ./autogen.sh ]; then
./autogen.sh
fi
if [ ! -e ./configure ]; then
autoreconf -i
fi
./configure $AT_BLDR_CONF ${EXTRACONF}
make -j${BLDR_CORES}
make DESTDIR=/root/bldr-inst install
fi
if [ "$BUILD" == "cmake" ]; then
mkdir -p build && cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF ${EXTRACONF}
make -j${BLDR_CORES}
make DESTDIR=/root/bldr-inst install
fi
if [ "$BUILD" == "perl" ]; then
perl Makefile.PL INSTALLDIRS=vendor
make -j${BLDR_CORES}
make DESTDIR=/root/bldr-inst install
fi
if [ "$BUILD" == "python" ]; then
cd ..
DIR=`ls`
cp -r $DIR ${DIR}-python2
cd $DIR
python3 setup.py install --root=/root/bldr-inst/ --optimize=1
cd ../${DIR}-python2
python2 setup.py install --root=/root/bldr-inst/ --optimize=1
fi
if [ "$BUILD" == "python3" ]; then
python3 setup.py install --root=/root/bldr-inst/ --optimize=1
fi
if [ "$BUILD" == "32bit" ]; then
export CC="gcc -m32"
export CXX="g++ -m32"
export PKG_CONFIG_PATH="/usr/lib32/pkgconfig"
if [ ! -e ./configure ] && [ -e ./autogen.sh ]; then
./autogen.sh
fi
./configure --prefix=/usr --libdir=/usr/lib32 --sysconfdir=/etc ${EXTRACONF}
make -j${BLDR_CORES}
make DESTDIR=/root/bldr-inst install
rm -rf /root/bldr-inst/{bin,sbin,etc,var,lib}
rm -rf /root/bldr-inst/usr/{bin,sbin,lib,include,man,share,libexec}
fi
if [ "$BUILD" == "meson" ]; then
mkdir -p build
meson-wrap build $EXTRACONF
ninja -C build
DESTDIR=/root/bldr-inst ninja -C build install
fi
if [ "$BUILD" == "custom" ]; then
BuildAndInstall;
fi
cd ~/bldr-inst
let XTRA=`find $BLDRTMPDIR | wc -l`
if [ $XTRA != 1 ]; then
cp -r $BLDRTMPDIR/* .
fi
rm -rf pkg.install
echo Ridding any /run, /var/run, or /tmp directories
if [ -e ./run ]; then
rm -rf run
fi
if [ -e ./var/run ]; then
rm -rf var/run
fi
if [ -e ./tmp ]; then
rm -rf tmp
fi
echo Moving any lib64 contents to lib
if [ -e ./lib64 ]; then
mkdir -p ./lib
cp -r ./lib64/* ./lib/
rm -rf ./lib64
fi
if [ -e ./usr/lib64 ]; then
mkdir -p ./usr/lib
cp -r ./usr/lib64/* ./usr/lib/
rm -rf ./usr/lib64