-
Notifications
You must be signed in to change notification settings - Fork 4
/
LFSFunctions
executable file
·891 lines (803 loc) · 22.9 KB
/
LFSFunctions
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
#!/bin/bash
#
#©K. D. Hedger. Tue 31 Jul 12:03:09 BST 2018 keithdhedger@gmail.com
#
#This file (LFSFunctions) is part of LFSMakePkg.
#
#LFSMakePkg 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.
#
#Projects 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 LFSMakePkg. If not, see <http://www.gnu.org/licenses/>.
#
#set -x
if [ X"$THISTTY" = "X" ];then
export THISTTY=$(tty)
fi
WHERE=""
RED='\e[1;31m'
GREEN='\e[1;32m'
BLACK='\e[0;30m'
NORMAL='\e[0;0m'
BLUE='\e[1;34m'
ARCH=${ARCH:-$(uname -m)}
case "$ARCH" in
"i486")
LFSFLAGS="-O2 -march=i486 -mtune=i686"
LIBDIRSUFFIX=""
;;
"i686")
LFSFLAGS="-O2 -march=i686 -mtune=i686"
LIBDIRSUFFIX=""
;;
"x86_64")
LFSFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
;;
"armv7l")
PIBUILD=1
LFSFLAGS="-O2 -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard"
LIBDIRSUFFIX=""
;;
"armv6l")
PIBUILD=1
LFSFLAGS="-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard"
LIBDIRSUFFIX=""
;;
*)
LFSFLAGS="-O2"
LIBDIRSUFFIX=""
;;
esac
export LIBDIRSUFFIX LFSFLAGS
if [ "X$NOLOADCONFIG" = "X" ];then
if [ -e /etc/lfspkg.rc ];then
. /etc/lfspkg.rc
fi
fi
PIBUILD=${PIBUILD:-0}
PIVERS=${PIVERS:-4}
if [ $PIBUILD -eq 1 ];then
if [ $PIVERS -eq 4 ];then
LFSFLAGS="-O2 -mcpu=cortex-a72 -mtune=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard"
fi
fi
#TMP=${TMP:-/tmp/LFS}
mkdir -p /tmp/LFS
OUTPUT=${OUTPUT:-/tmp/LFS}
PKGARCHIVES=${PKGARCHIVES:-$OUTPUT}
USEROPTIONS=${USEROPTIONS:-"/etc/pkgoptions"}
#XORG_PREFIX=${XORG_PREFIX:-/usr}
#if [ ! -d "$TMP" ];then mkdir -p "$TMP" &>/dev/null;fi
#if [ ! -d "$OUTPUT" ];then mkdir -p "$OUTPUT" &>/dev/null ||true;fi
#if [ ! -d "$SOURCEARCHIVES" ];then mkdir -p "$SOURCEARCHIVES" &>/dev/null ||true;fi
#if [ ! -d "$XORG_PREFIX" ];then mkdir -p "$XORG_PREFIX" &>/dev/null ||true;fi
#export TMP OUTPUT XORG_PREFIX
checkforoptions ()
{
if [ -e "${USEROPTIONS}/${PKGNAME}.options" ];then
. "${USEROPTIONS}/${PKGNAME}.options"
else
if [ -e "${CWD}/${PKGNAME}.options" ];then
. "${CWD}/${PKGNAME}.options"
fi
fi
}
sanitycheckfolder ()
{
if [ "X$1" == "X" ];then
echo "NOTSET"
return
fi
if [ ! -w "$1" ];then
echo "NOTWRITABLE"
return
fi
if [ ! -r "$1" ];then
echo "NOTREADABLE"
return
fi
echo "OK"
}
sanitycheck ()
{
mkdir -vp "$COMPILEAT" "$SOURCEARCHIVES" "$OUTPUT" &>/dev/null
if [ "$(sanitycheckfolder "$COMPILEAT")" = "NOTWRITABLE" ];then
echo -e "${RED}Can't write to $COMPILEAT defined by COMPILEAT${NORMAL}"
stat -c "%U:%G %A" "$OUTPUT"
exit 200
fi
if [ "$(sanitycheckfolder "$SOURCEARCHIVES")" = "NOTREADABLE" ] || [ "$(sanitycheckfolder "$SOURCEARCHIVES")" = "NOTWRITABLE" ];then
echo -e "${RED}Can't read/write to/from $SOURCEARCHIVES defined by SOURCEARCHIVES${NORMAL}"
stat -c "%U:%G %A" "$SOURCEARCHIVES"
exit 200
fi
if [ $UID -eq 0 ];then
chmod 777 "$OUTPUT"
fi
if [ "$(sanitycheckfolder "$OUTPUT")" = "NOTWRITABLE" ];then
echo -e "${RED}Can't write to $OUTPUT defined by OUTPUT${NORMAL}"
stat -c "%U:%G %A" "$OUTPUT"
exit 200
fi
}
sanitycheck
#export TMP OUTPUT
export OUTPUT
SCRIPTLOG=${SCRIPTLOG:-0}
LOGDIR=${LOGDIR:-"/tmp/LFS/logs"}
scriptLog ()
{
local timestr
if [ $SCRIPTLOG -eq 1 ];then
if [ -e /bin/date ];then
timestr="$(date +"-%H:%M:%S")"
else
timestr=""
fi
mkdir -p "$LOGDIR" &>/dev/null||true
ln -svfn ..${LOGDIR}/${1}${timestr}.log /tmp/CURRENTLOG
exec > >(tee -ia "${LOGDIR}/${1}${timestr}.log")
fi
}
log ()
{
for arg in "$@"
do
echo "$arg"|tee -a /tmp/lfspkg.log
done
}
findnextgid ()
{
local nextgid=1
local gidtype=$1
local sysmax=$(cat /etc/login.defs|grep "^SYS_GID_MAX"|awk '{print $2}')
local usermin=$(cat /etc/login.defs|grep "^GID_MIN"|awk '{print $2}')
if [ "X$gidtype" = "Xsystem" ];then
nextgid=0
else
nextgid=$usermin
fi
while read ANS
do
if [ X$ANS != "X" ];then
if [ $ANS -lt $sysmax -a X$gidtype = "Xsystem" -o $ANS -ge $usermin -a X$gidtype = "X" ];then
if [ $nextgid -lt $ANS ];then
echo $nextgid
return
else
((nextgid=nextgid+1))
fi
fi
fi
done < <(cat /etc/group | sed -e 's/:/ /g' | awk '{print $3}' | sort -n)
echo $nextgid
}
findnextuid ()
{
local nextuid=0
local usertype=$1
local sysmax=$(cat /etc/login.defs|grep "^SYS_UID_MAX"|awk '{print $2}')
local usermin=$(cat /etc/login.defs|grep "^UID_MIN"|awk '{print $2}')
if [ "X$usertype" = "Xsystem" ];then
nextuid=0
else
nextuid=$usermin
fi
while read ANS
do
if [ X$ANS != "X" ];then
if [ $ANS -lt $sysmax -a X$usertype = "Xsystem" -o $ANS -ge $usermin -a X$usertype = "X" ];then
if [ $nextuid -lt $ANS ];then
echo $nextuid
return
else
((nextuid=nextuid+1))
fi
fi
fi
done < <(cat /etc/passwd | sed -e 's/:/ /g' | awk '{print $3}' | sort -n)
echo $nextuid
}
findnextpair ()
{
local type=$1
local gid=0
local uid=0
gid=$(findnextgid $1)
uid=$(findnextuid $1)
if [ $gid -gt $uid ];then
echo $gid
else
echo $uid
fi
}
findArchive ()
{
local url="$1"
local name="$2"
local suffix="$3"
echo -e "${GREEN}Checking ...${NORMAL}" >&2
links -ftp.use-passive 1 -dump "$url"|grep "$name" |awk '{print $NF}'|grep "${suffix}$"|sort -r|head -n1
}
checkversion ()
{
local maxlen=0
local val1=( ${1//./ } )
local val2=( ${2//./ } )
local value1
local value2
local j
local mult
maxlen=${#val1[@]}
if [ ${#val2[@]} -gt $maxlen ];then
maxlen=${#val2[@]}
fi
for ((j=0;j<$maxlen;j++))
do
if [ "X${val1[$j]}" = "X" ];then
val1[$j]=0
fi
if [ "X${val2[$j]}" = "X" ];then
val2[$j]=0
fi
done
value1=0
mult=1
for ((j=${#val1[@]}-1;j>-1;j--))
do
value1=$((10#$value1))
val1[$j]=$((10#${val1[$j]}))
value1=$(($value1+(${val1[$j]}*mult)))
mult=$((mult*100))
done
value2=0
mult=1
for ((j=${#val2[@]}-1;j>-1;j--))
do
value2=$((10#$value2))
val2[$j]=$((10#${val2[$j]}))
value2=$(($value2+(${val2[$j]}*mult)))
mult=$((mult*100))
done
if [ $value1 -gt $value2 ];then
echo 1
fi
if [ $value1 -lt $value2 ];then
echo -1
fi
if [ $value1 -eq $value2 ];then
echo 0
fi
}
checketc ()
{
local package="$1"
local inputflag=true
local dest
local testflag=false
if [ ! -d "${package}/etc" -o $CHECKETC -eq 0 ];then
return 0
else
# if [ X"$THISTTY" = "X" ];then
# export THISTTY=$(tty)
# fi
#
# exec 6<&0
# exec 0<$THISTTY
while read ETCFILES
do
from="$ETCFILES"
to="${ETCFILES#$PKG}"
if [ -e "$from" -a -e "$to" ];then
if ! diff -Bs "$from" "$to" &>/dev/null;then
testflag=true
fi
fi
done < <(find "${package}/etc" -type f)
if $testflag;then
echo "Possible config files have neen found!"
while $inputflag
do
read -p "Do you want to (R)eplace new files with old,(I)gnore new files,(O)verwrite old files with new,(K)eep new files with .new suffix? " ANSWER
case $ANSWER in
I|i)
rm -rf "${package}/etc"
inputflag=false
;;
K|k)
while read ETCFILES
do
mv "$ETCFILES" "${ETCFILES}.new"||true
dest=$(dirname "${ETCFILES#$package}")
cp "${ETCFILES#$package}" "${package}${dest}"||true
done < <(find "${package}/etc" -type f)
inputflag=false
;;
O|o)
echo "All default config files for this package in /etc will be replaced with the default files!"
inputflag=false
;;
R|r)
while read ETCFILES
do
from="$ETCFILES"
to="${ETCFILES#$PKG}"
cp "$to" "$from"||true
done < <(find "${package}/etc" -type f)
inputflag=false
;;
*)
echo "Please enter I,K or O"
;;
esac
done
fi
fi
return 0
# exec 0<&6 6<&-
}
gettar ()
{
local url="$1" outname
local section
if [ ${NODOWNLOAD:-0} -eq 1 ];then
return
fi
if [ "X$2" != "X" ];then
section="$2"
else
section=""
fi
if [ "X$3" != "X" ];then
outname="$3"
else
outname="$(basename "$url")"
fi
if [ ! -e "$SOURCEARCHIVES" ];then
mkdir -vp "$SOURCEARCHIVES"||true
fi
mkdir -vp "${SOURCEARCHIVES}/$section" 2>/dev/null||true
pushd "${SOURCEARCHIVES}/$section"
if ! type wget &> /dev/null;then
echo "No 'wget' installed cannot download archive"
popd
return
fi
if [ "$FORCEDOWNLOAD" != "" ];then
rm $outname &>/dev/null||true
fi
if [ -e $outname ];then
popd
return
fi
if ! wget --no-check-certificate -c "$url" -O "$outname";then
echo -e "${RED}!!!!!!!Can't download file $1!!!!!${NORMAL}"
rm "$outname"
if [ $EXITONFAIL -eq 1 ];then
popd
exit -1
fi
fi
popd
}
noblastlink ()
{
local name="$1"
find "$name" -iname "*.la" -exec rm '{}' \;
pushd "$name"
while read DIR
do
if [ $DIR != "." ];then
realclean=/${DIR/"./"/}
if [ X"$(file "$realclean"|grep symbolic)" != "X" ];then
echo $DIR is a link
pushd "${name}/$(dirname "$DIR")"
mkdir -vp "${name}/$(readlink -f "$realclean")"
mv "$(basename "${DIR}")"/* "${name}$(readlink -f "$realclean")"
rm -r "${name}/${DIR}"
popd
fi
fi
done < <(find -type d)
popd
ldconfig||true
}
getindexes ()
{
echo -e "${GREEN}Getting index pages ...${NORMAL}" 1>&2
pushd /tmp &>/dev/null
if [ $USESTABLE -eq 1 ];then
wget http://www.linuxfromscratch.org/blfs/view/stable/longindex.html -O blfsindex.html 2>/dev/null
wget http://www.linuxfromscratch.org/lfs/view/stable/longindex.html -O lfsindex.html 2>/dev/null
else
wget http://www.linuxfromscratch.org/blfs/view/svn/longindex.html -O blfsindex.html 2>/dev/null
wget http://www.linuxfromscratch.org/lfs/view/development/longindex.html -O lfsindex.html 2>/dev/null
fi
popd &>/dev/null
}
makepkginfo ()
{
local appname="$1"
local page
local subpage
local infodata
local vers
pushd "${DATABASEFOLDER}" &>/dev/null
for usepage in "blfsstable" "lfsstable" "blfsdev" "lfsdev"
do
page=""
case $usepage in
"blfsstable")
echo -e "${GREEN}Checking BLFS (stable) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat blfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="http://www.linuxfromscratch.org/blfs/view/stable/${subpage}"
fi
;;
"lfsstable")
echo -e "${GREEN}Checking LFS (stable) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat lfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="http://www.linuxfromscratch.org/lfs/view/stable/${subpage}"
fi
;;
"blfsdev")
echo -e "${GREEN}Checking BLFS (development) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat blfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="http://www.linuxfromscratch.org/blfs/view/svn/${subpage}"
fi
;;
"lfsdev")
echo -e "${GREEN}Checking LFS (development) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat lfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="http://www.linuxfromscratch.org/lfs/view/development/${subpage}"
fi
;;
esac
if [ X"$page" != "X" ];then
echo "$page"
if [ ! -e ${appname}.html ];then
wget $page -O ${appname}.html 2>/dev/null
fi
case $usepage in
"blfsstable" | "blfsdev")
infodata=$(cat ${appname}.html | tr "\n" "|" | grep -o '</h2>.*<p>.*</p>.*<p>' | awk -F'<p>' '{print $2}'|awk -F'</p>' '{print $1}'|sed 's/|/\n/g')
;;
"lfsdev" | "lfsstable")
infodata=$(cat ${appname}.html | tr "\n" "|" | grep -o '</h1>.*</p>'|awk -F'<p>' '{printf $2}'|awk -F'</p>' '{print $1}'|sed 's/|/\n/g')
;;
esac
echo $infodata|sed 's/<[^<>]*>//g;s/\. /\.\n/g'
return
fi
done
for vers in "15.0" "14.2" "14.1" "14.0" "13.37" "13.1"
do
echo -e "${GREEN}Checking Slackbuilds version $vers for Info ...${NORMAL}" 1>&2
subpage=$(grep -i "SLACKBUILD LOCATION:[ ]*\./[[:alnum:]]*/${appname}$" "${vers}.txt" 2>/dev/null)||true
if [ X"${subpage}" != "X" ];then
subpage=${subpage#?*./}
page="http://slackbuilds.org/slackbuilds/$vers/${subpage}/slack-desc"
if [ ! -e ${appname}-info ];then
wget $page -O ${appname}-info 2>/dev/null
fi
infodata=$(tail -n11 ${appname}-info|tr "\n" "|"|sed "s@${appname}:[ ]*@@Ig;s@[|][|]*@\n@g")
echo "$infodata"
return
fi
done
echo -e "${RED}No info found ..." 1>&2
popd &>/dev/null
}
showwebpage ()
{
local appname="$1"
local page
local subpage
local infodata
local vers
pushd "${DATABASEFOLDER}" &>/dev/null
for usepage in "blfsstable" "lfsstable" "blfsdev" "lfsdev"
do
page=""
case $usepage in
"blfsstable")
echo -e "${GREEN}Checking BLFS (stable) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat blfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="https://www.linuxfromscratch.org/blfs/view/stable/${subpage}"
fi
;;
"lfsstable")
echo -e "${GREEN}Checking LFS (stable) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat lfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="https://www.linuxfromscratch.org/lfs/view/stable/${subpage}"
fi
;;
"blfsdev")
echo -e "${GREEN}Checking BLFS (development) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat blfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="https://www.linuxfromscratch.org/blfs/view/svn/${subpage}"
fi
;;
"lfsdev")
echo -e "${GREEN}Checking LFS (development) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat lfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="https://www.linuxfromscratch.org/lfs/view/development/${subpage}"
fi
;;
esac
if [ X"$page" != "X" ];then
xdg-open "$page"
return
fi
done
for vers in "15.0" "14.2" "14.1" "14.0" "13.37" "13.1"
do
echo -e "${GREEN}Checking Slackbuilds version $vers for Info ...${NORMAL}" 1>&2
subpage=$(grep -i "SLACKBUILD LOCATION:[ ]*\./[[:alnum:]]*/${appname}$" "${vers}.txt" 2>/dev/null)||true
if [ X"${subpage}" != "X" ];then
subpage=${subpage#?*./}
page="http://slackbuilds.org/slackbuilds/$vers/${subpage}"
xdg-open "$page"
return
fi
done
echo -e "${RED}No info found ..." 1>&2
popd &>/dev/null
}
printversioninfo ()
{
case $(checkversion $1 $2) in
1)
echo -e "${BLUE}Package $3 may need updating to $1${NORMAL}" >&2
# echo "$4"
;;
-1)
echo -e "${RED}Package $3 build script version greater than documented version ???${NORMAL}" >&2
echo -e "${RED}Package $3 build script version=$2, documented version=$1${NORMAL}" >&2
;;
0)
echo -e "${GREEN}Package $3 version $2 is Ok ...${NORMAL}" >&2
;;
esac
echo "$4"
}
checkforversion ()
{
local appname
local page
local subpage
local infodata
local vers
local packageversion
local packages
pushd "${DATABASEFOLDER}" &>/dev/null
for packages in ${OPTS[@]}
do
appname=$packages
for usepage in "lfsstable" "blfsstable" "15.0" "14.2" "14.1" "14.0" "13.37" "13.1" "lfsdev" "blfsdev"
do
case $usepage in
"lfsstable")
echo -e "${GREEN}Checking LFS (stable) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat lfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="http://www.linuxfromscratch.org/lfs/view/stable/${subpage}"
fi
;;
"blfsstable")
echo -e "${GREEN}Checking BLFS (stable) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat blfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="http://www.linuxfromscratch.org/blfs/view/stable/${subpage}"
fi
;;
"lfsdev")
echo -e "${GREEN}Checking LFS (development) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat lfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="http://www.linuxfromscratch.org/lfs/view/development/${subpage}"
fi
;;
"blfsdev")
echo -e "${GREEN}Checking BLFS (development) for $appname version ...${NORMAL}" 1>&2
subpage=$(cat blfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1)
if [ X${subpage} != "X" ];then
page="http://www.linuxfromscratch.org/blfs/view/svn/${subpage}"
fi
;;
*)
echo -e "${GREEN}Checking Slackbuilds version $usepage for $appname version ...${NORMAL}" 1>&2
linenumber=$(grep --line-number -i "SLACKBUILD NAME:[ ]*${appname}$" "${usepage}.txt"|awk -F: '{print $1}')
if [ X$linenumber != "X" ];then
vers=$(sed -n "$((linenumber+3))p" "${usepage}.txt"|awk -F: '{print $2}')
infodata=$(sed -n "/name=${appname}/I,/Installed version=/p" "${DATABASE}")
packageversion=$(echo "$infodata"|sed -n '2p'|awk -F= '{print $2}')
printversioninfo $vers $packageversion $appname "$infodata"
subpage=$(grep -i "SLACKBUILD LOCATION:[ ]*\./[[:alnum:]]*/${appname}$" "${usepage}.txt")
subpage=${subpage#?*./}
page="http://slackbuilds.org/repository/${usepage}/${subpage}/?search=${appname}"
echo "More info here: $page"
continue 2
fi
;;
esac
if [ X${page} != "X" ];then
if [ ! -e ${appname}.html ];then
wget $page -O ${appname}.html 2>/dev/null
fi
infodata=$(cat ${appname}.html|grep -i "\b$appname\b"|head -n1)
vers=${infodata##?*-}
infodata=$(sed -n "/name=${appname}$/I,/Installed version=/p" "${DATABASE}")
packageversion=$(echo "$infodata"|sed -n '2p'|awk -F= '{print $2}')
printversioninfo $vers $packageversion $appname "$infodata"
continue 2
fi
done
echo -e "${RED}No version info for $appname found ...${NORMAL}" 1>&2
done
popd &>/dev/null
}
packageclean ()
{
local pkgname="$1"
local scriptfolder="${2:-.}"
local buildscript="$0"
if [ -e "$scriptfolder/preinstall" ];then
cp "$scriptfolder/preinstall" "$pkgname"
fi
if [ -e "$scriptfolder/postinstall" ];then
cp "$scriptfolder/postinstall" "$pkgname"
fi
if [ -e "$scriptfolder/info" ];then
cp "$scriptfolder/info" "$pkgname"
fi
cp "${scriptfolder}/${buildscript}" "${pkgname}/buildscript.txt"
pushd "$pkgname"
find "$pkgname" -iname "*.la" -exec rm '{}' \; || true
find | xargs file | grep -e "executable" -e "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
rm -rf tmp
if [ ${DELETEDOCS:-0} -eq 1 ];then
find usr/share/locale/ -maxdepth 1 -mindepth 1 -type d -not -iname "${LANG%_?*}*" -exec rm -rf '{}' \; || true
find usr/share/doc -delete || true
find usr/share/man -delete || true
find usr/share/info -delete || true
find usr/share/gtk-doc -delete || true
fi
popd
ldconfig||true
}
extractarchive ()
{
local archive="$1"
local what=$2
local comm="tar -xvf"
local upname
local resetperms=1
case $what in
"zip")
#resetperms=0
comm="unzip"
;;
*)
upname="${archive^^}"
if [ "${upname##?*.}" = "ZIP" ];then
#resetperms=0
comm=unzip
fi
;;
esac
if [ $UID -eq 0 ];then
# su -s "/bin/sh" nobody -c "$comm "$archive""//TODO//
if [ $resetperms -eq 1 ];then
perms=$(stat --format="%a" $(pwd))
$comm "$archive"
chmod $perms $(pwd)
else
$comm "$archive"
fi
else
$comm "$archive"
fi
}
printBuildInfo ()
{
find $ROOTDIR/var/lib/lfspkg/packages/ -type d -iname "${1}*"|while read
do
echo -e "${GREEN}Pkg info for $(basename ${REPLY})${NORMAL}"
cat $REPLY/info 2>/dev/null||true
if [ -e $REPLY/preinstall ];then
echo
echo -e "${GREEN}Pre Install${NORMAL}"
cat $REPLY/preinstall 2>/dev/null||true
fi
if [ -e $REPLY/postinstall ];then
echo
echo -e "${GREEN}Post Install${NORMAL}"
cat $REPLY/postinstall 2>/dev/null||true
fi
if [ -e $REPLY/buildscript.txt ];then
echo
echo -e "${GREEN}Build Script${NORMAL}"
cat $REPLY/buildscript.txt 2>/dev/null||true
fi
echo
done
}
searchinfos ()
{
#tobe done
:
}
findScriptFromWeb ()
{
local pkg="${1%%-?*}"
local htmlpage=/tmp/page$$.html
local lfsversion
local thelink
ANYVERSION=1 lfspkg -Z 3 "$pkg"
#lfs
for lfsversion in "stable" "svn"
do
curl "https://www.linuxfromscratch.org/blfs/view/stable/longindex.html" 2>/dev/null > $htmlpage
startline=$(grep -n 'id="program-index"' $htmlpage|awk -F: '{print $1}')
hrefs=$(sed -n "$startline,\$p" $htmlpage |grep "$pkg.*:" -A 4|sed -n "s@.*href=\"\([^\"]*\).*@http://www.linuxfromscratch.org/blfs/view/$lfsversion/\1@p"|grep -v "#"|sort -u)
if [ "X$hrefs" = "X" ];then
hrefs=$(sed -n "$startline,\$p" $htmlpage |grep -i "$pkg.*:" -A 4|sed -n "s@.*href=\"\([^\"]*\).*@http://www.linuxfromscratch.org/blfs/view/$lfsversion/\1@p"|grep -v "#"|sort -u)
fi
if [ "X$hrefs" = "X" ];then
echo "Nothing at linuxfromscratch $lfsversion .."
else
for arg in $hrefs
do
echo "${arg}"
done
fi
done
rm $htmlpage
#sbo search
for sboversion in "15.0" "14.2" "14.1" "14.0" "13.37" "13.1"
do
curl "https://slackbuilds.org/result/?search=$pkg&sv=$sboversion" 2> /dev/null > $htmlpage
if ! grep "No results" $htmlpage &>/dev/null;then
echo "https://slackbuilds.org/result/?search=$pkg&sv=$sboversion"
else
echo "Nothing at SBO $sboversion .."
fi
done
rm $htmlpage
#slackware search
for sboversion in "15.0" "14.2" "14.1" "14.0" "13.37" "13.1"
do
curl -L "https://mirrors.slackware.com/slackware/slackware-$sboversion/source/FILE_LIST" 2>/dev/null >$htmlpage
thelink=$(grep "${pkg}.SlackBuild" $htmlpage |head -n1|awk '{print $NF}')
if [ "$thelink" != "" ];then
echo "https://mirrors.slackware.com/slackware/slackware-$sboversion/source/$thelink"
else
echo "Nothing at slackware $sboversion .."
fi
done
rm $htmlpage
#arch search
curl "https://archlinux.org/packages/?sort=&q=$pkg&maintainer=&flagged=" 2>/dev/null >$htmlpage
if ! grep "No matching packages found" $htmlpage &>/dev/null;then
echo "https://archlinux.org/packages/?sort=&q=$pkg&maintainer=&flagged="
else
echo "Nothing at arch .."
fi
rm $htmlpage
}