/
pkg
executable file
·7713 lines (6138 loc) · 272 KB
/
pkg
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/ash
#
# pkg - a command line package manager for Puppy Linux
#
# By Scott Jarvis (sc0ttman)
#
# Copyright (c) 2013 Puppy Linux Community
#
# 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 1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
#================== setup script vars =====================#
APPNAME="Pkg"
APPVER="1.9.23"
# get current locale settings
USER_LANG=$LANG
USER_LC_ALL=$LC_ALL
SELF=$(basename "$0") # this script
QTAG='' # gets set to (y/n) if ASK=-true
LANG=C # speed up
LC_ALL=C # speed up
EDITOR=${EDITOR:-vi} # just in case
PAGER=${PAGER:-less} # just in case
CURDIR="${PWD}" # get current dir, before cd to WORKDIR
TMPDIR=/tmp/pkg/${whoami} # set the tmp dir
REPO_DIR=~/.packages # where the repo files live
[ -d /var/packages ] && REPO_DIR=/var/packages
export REPO_DIR
#run as root only
whoami=$(whoami)
# set colours true by default
green="\e[32m"; red="\e[91m"; magenta="\e[95m"; lightblue="\e[36m"; yellow="\e[93m"; bold="\e[1m"; endcolour="\e[0m"
# ENVIRONMENT VARS, which may be overridden later
[ -z "$PKGRC" ] && export PKGRC=${HOME}/.pkg/pkgrc # config file for this script
[ -z "$ASK" ] && ASK=false # if true, ask user before doing stuff. Overridden by --ask
[ -z "$QUIET" ] && QUIET=false # if true, hide output that doesnt log well in Xdialog, Gtkdialog, etc
[ -z "$FORCE" ] && FORCE=false # if true, force (re)install/remove pkgs. Overridden by --force
[ -z "$HIDE_INSTALLED" ] && export HIDE_INSTALLED=false # if true, hide installed pkgs from pkg searches (-n, -na, -ss, -ssa)
[ -z "$HIDE_BUILTINS" ] && export HIDE_BUILTINS=true # if true, remove builtins pkgs from dep lists, dont download/install them
[ -z "$HIDE_USER_PKGS" ] && export HIDE_USER_PKGS=true # if true, hide user installed pkgs from dep lists, dont download/install them
[ -z "$NO_ALIASES" ] && export NO_ALIASES=false # if true, skip searching pkg alias names for pkg alternatives
[ -z "$NO_INSTALL" ] && export NO_INSTALL=false # if true, skip installing of pkgs
[ -z "$PKG_NO_COLOURS" ] && export PKG_NO_COLOURS=false # if true, disable coloured output or not
[ -z "$PKG_CONFIGURE" ] && export PKG_CONFIGURE='' # reset
[ -z "$PKG_CFLAGS" ] && export PKG_CFLAGS='' # reset
[ -z "$PKG_BLACKLIST" ] && export PKG_BLACKLIST='' # reset
[ -z "$PKG_PPA2PUP_FN" ] && if [ ! -z "$(which gawk)" ]; then PKG_PPA2PUP_FN=ppa2pup_gawk; else PKG_PPA2PUP_FN=ppa2pup; fi
# but disable colours if called as gpkg, or the ENV variable PKG_NO_COLOURS is true
if [ "$SELF" != "pkg" ] || [ "$PKG_NO_COLOURS" = true ];then
green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour=''
fi
# report errors better than just echo
error(){
echo -e 1>&2 "${red}Error:${endcolour} $1"
}
# for correct error output, trap commands early
cleanup(){
# shellcheck disable=SC2086
rm -f ${TMPDIR}/missing_dep* ${TMPDIR}/installed_pkg* ${TMPDIR}/all_dep* ${TMPDIR}/DEP_DONE /tmp/pkg/list_deps_busy ${TMPDIR}/pkg_file_list ${TMPDIR}/dependents_list ${TMPDIR}/DEP_DONE ${TMPDIR}/ldd_file_list &>/dev/null
rm -rf /tmp/pkg/build_pkg/ &>/dev/null
# prevent double msg output if error=130 (user Ctrl-C)
if [ -f /tmp/pkg/error130 ] && [ "$2" = '130' ];then
exit "$2"
fi
# make the tmp dir we'll use
mkdir -p /tmp/pkg &>/dev/null
# only add line numbers if it was given
[ "$1" != 'none' ] && lineno="line $1, " || lineno=''
# get the right error msg
case "$2" in
130) echo; msg="User cancelled operation!"; touch /tmp/pkg/error130;;
8) msg="Package URL invalid.";;
7) msg="Package extraction failed.";;
6) msg="Missing package file.";;
5) msg="Missing directory.";;
4) msg="Copy failed.";;
3) msg="Setup failed.";;
2) msg="Code error!";;
1) exit 1 ;; # user gave wrong options or pkg name, not serious
*) msg="Error code = $2" ;;
esac
# print msg
[ "$2" != "0" ] && echo -e 1>&2 "${red}Error${endcolour} ${2}: ${lineno}$msg"
exit "$2"
}
trap 'cleanup ${LINENO:-none} $?' EXIT INT TERM
[ "$whoami" != "root" ] && echo "You must be root to run Pkg." && exit 1
#080413 make sure all config files are present, copy from /etc if need be
if [ ! -f "${PKGRC}" ];then
echo "Restoring default settings from /etc/pkg"
[ ! -d /etc/pkg/ ] && error "Default config files in /etc/pkg/ not found." && exit 3
mkdir -p "$HOME/.pkg"
[ ! -d "$HOME/.pkg" ] && error "Default user config dir '$HOME/.pkg/' could not be created." && exit 3
cp --force -a /etc/pkg/* "$HOME/.pkg/" || exit 3
fi
# get puppy distro env vars
[ -f /etc/rc.d/PUPSTATE ] && . /etc/rc.d/PUPSTATE #this has PUPMODE and SAVE_LAYER.
[ -f /etc/DISTRO_SPECS ] && . /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
[ -f /etc/rc.d/BOOTCONFIG ] && . /etc/rc.d/BOOTCONFIG #has EXTRASFSLIST PREVUNIONRECORD, LASTUNIONRECORD (sfs stuff)
[ -f /etc/xdg/menus/hierarchy ] && . /etc/xdg/menus/hierarchy #w478 has PUPHIERARCHY variable.
[ -f ${REPO_DIR}/DISTRO_PKGS_SPECS ] && . ${REPO_DIR}/DISTRO_PKGS_SPECS #has lot sof essential info
[ -f ${REPO_DIR}/PKGS_MANAGEMENT ] && . ${REPO_DIR}/PKGS_MANAGEMENT #has PKG_NAME_IGNORE, PKG_PET_THEN_BLACKLIST_COMPAT_KIDS, PKG_REPOS_ENABLED
[ -f ${REPO_DIR}/DISTRO_COMPAT_REPOS ] && . ${REPO_DIR}/DISTRO_COMPAT_REPOS #has repo URL related vars
# set the package name suffix appended to combined pkgs (pkg+deps)
CP_SUFFIX="WITHDEPS_${DISTRO_FILE_PREFIX}"
# set correct arch for repo URLs (used by some slack-pup repos)
case "$DISTRO_TARGETARCH" in
x86) DBIN_ARCH=i486 ;;
x86_64) DBIN_ARCH=x86_64 ; DSUFFIX=64 ;;
arm64) DBIN_ARCH=arm64 ; DSUFFIX=64 ;;
armel) DBIN_ARCH=armel ; DSUFFIX=64 ;;
armhf) DBIN_ARCH=armh ; DSUFFIX=64 ;;
*) DBIN_ARCH=i486 ;;
esac
export DSUFFIX;
# set correct package name/version separator (helps resolve package names)
separator='_'
case $DISTRO_BINARY_COMPAT in
ubuntu|trisquel|debian|devuan)
separator='_'
;;
*)
separator='-'
;;
esac
export separator
# needed for some debian based repos
case $DISTRO_COMPAT_VERSION in
wheezy) DDB_COMP=bz2 ;; # older versions
*) DDB_COMP=xz ;;
esac
# 0setup must be used differently in older and newer Woof-CE versions, so
# check which version of 0setup we're using, then set a flag on how to use it
PKG_REPO_UPDATE_METHOD=${PKG_REPO_UPDATE_METHOD:-standard}
# shellcheck disable=SC2016
if [ "$(grep -m1 'if \[ -d ./support -a -f ./DISTRO_SPECS -a -d ./rootfs-skeleton \] ;then' /usr/local/petget/0setup)" = "" ] && \
[ "$(grep -m1 'if \[ "$RUNNINGPUP" = "yes" \];then' /usr/local/petget/0setup)" != "" ]
then
PKG_REPO_UPDATE_METHOD=legacy
fi
export PKG_REPO_UPDATE_METHOD
# now create 'layers-installed': will contain builtins (and devx packages, if devx is loaded)
#130511 need to include devx-only-installed-packages, if loaded...
if which gcc &>/dev/null;then
[ ! -f /tmp/ppm-layers-installed-packages ] && cp -f ${REPO_DIR}/woof-installed-packages /tmp/ppm-layers-installed-packages &>/dev/null
cat ${REPO_DIR}/devx-only-installed-packages >> /tmp/ppm-layers-installed-packages &>/dev/null
sort -u /tmp/ppm-layers-installed-packages > ${REPO_DIR}/layers-installed-packages &>/dev/null
else
cp -f ${REPO_DIR}/woof-installed-packages ${REPO_DIR}/layers-installed-packages &>/dev/null
fi
# set $DIRECTSAVEPATH (where we want to install pkgs)
if [ $PUPMODE -eq 3 ] || [ $PUPMODE -eq 7 ] || [ $PUPMODE -eq 13 ];then
DIRECTSAVEPATH="/initrd${SAVE_LAYER}" #SAVE_LAYER is in /etc/rc.d/PUPSTATE.
elif [ "$PUPMODE" = "2" ]; then
DIRECTSAVEPATH=""
fi
# get repo details, workdir, search settings and so on.. you could
# you can also add any ENVIRONMENT VARS above to PKGRC, to override the defaults
. ${PKGRC}
# set and create workdir if no valid dir set
[ ! -d "$WORKDIR" ] && mkdir -p "$WORKDIR"
if [ ! -d "$WORKDIR" ];then
error "Can't create $WORKDIR. Please create it."
exit 3
fi
WORKDIR=~/pkg
# add to tab completion settings to bashrc and print hint
if [ -z "$PKG_TAB_COMPLETION" ];then
if [ "$(grep 'export PKG_TAB_COMPLETION=true' ~/.bashrc)" = "" ];then
# add to bashrc
{ echo ""
echo "# enable $APPNAME $APPVER TAB completion"
echo "export PKG_TAB_COMPLETION=true"
echo "source /etc/bash_completion.d/pkg 2>/dev/null"
} >> ~/.bashrc
fi
fi
# make tmp dir writable by everyone if needed
if [ ! -d "$TMPDIR" ];then
mkdir -p "$TMPDIR" 2>/dev/null
chmod -R 1777 /tmp/pkg/ 2>/dev/null
fi
# if no tmp dir created or accessible, exit
[ ! -d "$TMPDIR" ] && error "Cannot create temp dir ${lightblue}$TMPDIR${endcolour}" && exit 3
# support aliases, create ALIASES tmp file
PKG_NAME_ALIASES='rxvt-unicode,urxvt,urxvt-unicode
gtk+,gtk+2*
gtkdialog,gtkdialog3
dbus*,libdbus*,libdbus-glib*
mesa,mesa_*,libgl1-mesa*,mesa-common*
sane,sane-backends
samba,samba-tng,samba_*,mountcifs
udev,udev_*,libudev*,libgudev*
xdg_puppy,xdg-utils
perl_tiny,perl-base,perl-modules,perlapi*'
[ ! -f "$TMPDIR/pkg_aliases" ] && echo "$PKG_NAME_ALIASES" > $TMPDIR/pkg_aliases
# get blacklisted packages (each on new line) from $PKG_NAME_IGNORE
# and ~/.pkg/blacklisted_packages .. exports $PKG_BLACKLIST
get_blacklist(){
PKG_BLACKLIST="$(echo "$PKG_BLACKLIST $PKG_NAME_IGNORE $(cat ${HOME}/.pkg/blacklisted_packages 2>/dev/null)" \
| tr ' ' '\n' \
| grep -v ^$ \
| sort -u)"
export PKG_BLACKLIST
}
get_blacklist
# create a list like "foo|bar|baz", to be used in grep commands
PKG_BLACKLIST_REGEX="$(echo "$PKG_BLACKLIST" | tr '\n' '|' | sed -e 's/^|//' -e 's/|$//')"
export PKG_BLACKLIST_REGEX
# remove error code flag if we got here
rm -f /tmp/pkg/error130 &>/dev/null
# if not first run, and no options given, print the help
[ ! -f ~/.pkg/firstrun ] && [ "$1" = "" ] && $SELF -H && exit 1 #200913 more help by default
}
#================== setup script vars =====================#
{
#==================== main functions ======================#
set -a
# utility funcs
print_usage(){ # print usage text. Requires $1, a valid Pkg cmd FUNCLIST
local examples_file=/usr/share/pkg/docs/examples.txt
[ -f "$examples_file" ] && source "$examples_file"
# get and print the usage info from its usage file
if [ -f /usr/share/pkg/docs/usage/$1 ] && [ "$1" ];then
source /usr/share/pkg/docs/usage/$1
echo -e "\n$USAGE"
# show examples, taken from $EXAMPLES, if they exist
if [ "$(echo "$EXAMPLES" | grep "$SELF" | grep "\-$1")" != '' ];then
echo -e "\n${bold}Usage Examples${endcolour}:\n"
echo -e "$EXAMPLES" | grep "$SELF " | grep "$1 "
fi
else
echo -e "Usage: ${bold}$SELF usage CMD${endcolour}"
echo
echo "Commands:"
echo -e "add-repo get-only repo-convert
add-source help repo-dep-scope
all-pkgs help-all repo-file-list
add remove repo-info
ask install repo-list
autoclean install-all repo-pkg-scope
bleeding-edge list-deps repo-update
clean list-downloaded search
contents list-installed search-all
deb2pet names sfs2pet
delete names-all sfs-combine
delete-all names-exact show-config
deps names-exact-all split
deps-all pet2sfs tgz2pet
deps-check pet2tgz uninstall
deps-download pet2txz uninstall-all
dir2pet build unpack
dir2sfs build-list update-sources
dir2tgz pkg-combine version
download installed which
examples repack which-repo
extract status rdep-check
force update what-needs
func-list workdir rm-repo
txz2pet dir2repo merge
whitelist blacklist
Usage: ${bold}$SELF usage CMD${endcolour}"
#cd /usr/share/pkg/docs/usage/; echo `ls` | fold -w 70 -s
fi
exit 1
}
func_list(){ # list all functions available in this script FUNCLIST
[ -f $TMPDIR/func_list ] && sort $TMPDIR/func_list && exit 0
# shellcheck disable=SC2016
grep "(){" $0 | grep '#' \
| grep FUNCLIST \
| sed -e 's|^| |g' \
-e 's|{||g' \
-e 's| | |g' \
-e 's|# ||g' \
-e 's| FUNCLIST||g' \
| grep -v 'FUNCLIST $0' \
| sort > $TMPDIR/func_list
cat $TMPDIR/func_list
exit 0
}
update_system_cache() {
# $1 = PKGFILES [ex: ${REPO_DIR}/abiword.files]
local PKGFILES=$1
if grep -q -m 1 '/usr/share/glib-2.0/schemas' $PKGFILES ;then
if [ -e /usr/bin/glib-compile-schemas ] ; then
/usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
fi
fi
if grep -q -m 1 '/usr/lib/gio/modules' $PKGFILES ;then
if [ -e /usr/bin/gio-querymodules ] ; then
/usr/bin/gio-querymodules /usr/lib/gio/modules
fi
fi
if grep -q -m 1 '/usr/share/applications/' $PKGFILES ;then
if [ -e /usr/bin/update-desktop-database ] ; then
rm -f /usr/share/applications/mimeinfo.cache
/usr/bin/update-desktop-database /usr/share/applications
fi
fi
if grep -q -m 1 '/usr/share/mime/' $PKGFILES ;then
if [ -e /usr/bin/update-mime-database ] ; then
/usr/bin/update-mime-database /usr/share/mime
fi
fi
if grep -q -m 1 '/usr/share/icons/hicolor/' $PKGFILES ;then
if [ -e /usr/bin/gtk-update-icon-cache ] ; then
/usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
fi
fi
if grep -q -m 1 '/usr/lib/gdk-pixbuf' $PKGFILES ;then
if [ -e /usr/bin/update-gdk-pixbuf-loaders ] ; then
update-gdk-pixbuf-loaders
elif [ -e /usr/bin/gdk-pixbuf-query-loaders ] ; then
gdk-pixbuf-query-loaders --update-cache
fi
fi
if grep -q -m 1 '/usr/lib/gconv/' $PKGFILES ;then
iconvconfig
fi
if grep -q -m 1 '/usr/lib/pango/' $PKGFILES; then
if [ -e /usr/bin/update-pango-querymodules ] ; then
update-pango-querymodules
elif [ -e /usr/bin/pango-querymodules ] ; then
pango-querymodules --update-cache
fi
fi
if grep -m 1 "/usr/lib/gtk-2.0" $PKGFILES |grep -q "/immodules" ; then
if [ -e /usr/bin/update-gtk-immodules-2.0 ] ; then
update-gtk-immodules-2.0
elif [ -e /usr/bin/gtk-query-immodules-2.0 ] ; then
gtk-query-immodules-2.0 --update-cache
fi
fi
if grep -m 1 "/usr/lib/gtk-3.0" $PKGFILES |grep -q "/immodules" ; then
if [ -e /usr/bin/update-gtk-immodules-3.0 ] ; then
update-gtk-immodules-3.0
elif [ -e /usr/bin/gtk-query-immodules-3.0 ] ; then
gtk-query-immodules-3.0 --update-cache
fi
fi
if grep -q -m 1 '/usr/share/fonts/' $PKGFILES ;then
fc-cache -f
fi
if grep -q -m 1 "/lib/modules/$(uname -r)/" $PKGFILES ;then
depmod -a
fi
}
get_pkg_ext(){ # return file extension of $1 FUNCLIST
# get valid usage or exit
[ ! "$1" ] && echo 'Usage: get_pkg_ext PKGNAME' && exit 1
local pkg_installed=''
local pkg_filename=''
local pkg_ext=''
local pkg_name=''
# check given file type, see if it matches our supported pkg types
case "$1" in
*.bz2) echo bz2 ;;
*.pet) echo pet ;;
*.deb) echo deb ;;
*.pkg.tar.gz) echo pkg.tar.gz ;;
*.pkg.tar.xz) echo pkg.tar.xz ;;
*.pkg.tgz) echo pkg.tgz ;;
*.pkg.txz) echo pkg.txz ;;
*.tar.bz2) echo tar.bz2 ;;
*.tar.lzma) echo tar.lzma ;;
*.tar.gz) echo tar.gz ;;
*.tar.xz) echo tar.xz ;;
*.tbz) echo tbz ;;
*.tgz) echo tgz ;;
*.tlz) echo tlz ;;
*.txz) echo txz ;;
*.gz) echo gz ;;
*.xz) echo xz ;;
*.rpm) echo rpm ;;
*.sfs) echo sfs ;;
#*.tcz) echo tcz ;;
#*.tpkg) echo tpkg ;;
#*.apk) echo apk ;;
*)
# no extension given, or extension not recognised, so..
# if it's an installed pkg, get the extension from ${REPO_DIR}/*
pkg_installed=$(list_installed_pkgs "$1" | grep -m1 "^$1")
# if $pkg_check not empty, then $1 is an installed pkg
if [ "$pkg_installed" != '' ];then
pkg_filename=$(cut -f8 -d'|' ${REPO_DIR}/user-installed-packages |grep -m1 "^$1")
[ "$pkg_filename" = '' ] && pkg_filename=$(cut -f8 -d'|' ${REPO_DIR}/*-installed-packages |grep -m1 "^$1")
[ "$pkg_filename" != '' ] && pkg_ext=$(get_pkg_ext "$pkg_filename")
else
# if it's a repo package, get it's extension from ${REPO_DIR}/*
# shellcheck disable=SC2086
pkg_filename=$(grep -m1 "^$1" ${REPO_DIR}/Packages-* |cut -f8 -d'|')
[ "$pkg_filename" != '' ] && pkg_ext=$(get_pkg_ext "$pkg_filename")
fi
[ "$pkg_ext" != '' ] && echo $pkg_ext
;;
esac
}
get_pkg_version(){ # returns version of PKGNAME ($1) FUNCLIST
# exit if no pkg given
[ ! "$1" ] && exit 1
local PKGNAME PKGNAME_ONLY PKG_VERSION
PKGNAME=$(get_pkg_name "$1")
PKGNAME_ONLY=$(get_pkg_name_only "$PKGNAME")
PKG_VERSION="$(grep -m1 "^$PKGNAME|" ${REPO_DIR}/user-installed-packages | cut -f3 -d'|')"
# cut pkg name only off start (field 3 of user-installed-packges might have full nanes, not versions)
PKG_VERSION="${PKG_VERSION/${PKGNAME_ONLY}${separator}/}"
if [ -z "$PKG_VERSION" ];then
PKG_VERSION="$(grep -m1 "^$PKGNAME|" $REPO_DIR/Packages-* | cut -f3 -d'|')"
fi
if [ -z "$PKG_VERSION" ];then
PKG_VERSION="$(grep -m1 "|$PKGNAME_ONLY|" $REPO_DIR/Packages-* | cut -f3 -d'|')"
fi
if [ -z "$PKG_VERSION" ];then
PKG_VERSION="$(grep -m1 "^$PKGNAME" $REPO_DIR/Packages-* | cut -f3 -d'|')"
fi
if [ -z "$PKG_VERSION" ];then
PKG_VERSION="${PKGNAME/${PKGNAME_ONLY}${separator}/}"
# shellcheck disable=SC2006
PKG_VERSION=`echo "$PKG_VERSION" \
| sed \
-e "s/^-//g" \
-e "s/^_//g" \
-e "s/^DEV-//g" \
-e "s/^DOC-//g" \
-e "s/^NLS-//g" \
-e "s/^dev-//g" \
-e "s/^doc-//g" \
-e "s/^nls-//g" \
-e "s/+deb.*//g" \
-e "s/+ubuntu.*//g" \
-e "s/-i[346].*//g" \
-e "s/-x[86].*//g" \
-e "s/-pup.*//g" \
-e "s/-q[0-9].*//g" \
-e "s/${CP_SUFFIX}.*//g" \
-e "s/-WITHDEPS.*//g" \
-e "s/-PLUSDEPS.*//g" \
-e "s/_all//g" \
-e 's@\\\@@g'`
fi
[ ! -z "$PKG_VERSION" ] && echo "$PKG_VERSION" && return 0
return 1
}
get_pkg_name_only_from_ext(){ # return package name from $1 (must include file extension)
# get valid usage or exit
[ ! "$1" ] && echo 'Usage: get_pkg_name_only_from_ext <PKG_FILENAME>' && exit 1
# get the extension of the given package name, if any
local pkg_ext=$(get_pkg_ext "$1")
# get the name without path and extension
local pkg_name=$(basename "$1" ".$pkg_ext")
local PKGNAME=''
local PKGNAME_ONLY=''
local DB_pkgrelease=''
local prPATTERN=''
local DB_version=''
local xDB_version=''
local xPATTERN=''
#split PKGMAIN, ex: FULLPKGNAME=xvidtune-1.0.1-i486-1.tgz has PKGNAME=xvidtune-1.0.1
case $pkg_ext in
deb)
#deb ex: xsltproc_1.1.24-1ubuntu2_i386.deb xserver-common_1.5.2-2ubuntu3_all.deb
PKGNAME_ONLY="$(echo -n "$pkg_name" | cut -f 1 -d '_')"
DB_pkgrelease="$(echo -n "$pkg_name" | rev | cut -f 2 -d '_' | cut -f 1 -d '-' | rev)"
prPATTERN="s%\\-${DB_pkgrelease}.*%%"
PKGNAME="$(echo -n "$pkg_name" | sed -e "$prPATTERN" 2>/dev/null)"
;;
pet)
PKGNAME="$pkg_name"
DB_version="$(echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\-%%')"
xDB_version="$(echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g')"
xPATTERN="s%${xDB_version}%%"
PKGNAME_ONLY="$(echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null)"
;;
tgz|txz)
#slack ex: xvidtune-1.0.1-i486-1.tgz printproto-1.0.4-noarch-1.tgz
PKGNAME="$(echo -n "$pkg_name" | sed -e 's%\\-i[3456]86.*%%' -e 's%\\-noarch.*%%')"
DB_version="$(echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\\-%%')"
xDB_version="$(echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g')"
xPATTERN="s%${xDB_version}%%"
PKGNAME_ONLY="$(echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\-$%%' 2>/dev/null)"
;;
tar.gz)
#arch ex: xproto-7.0.14-1-i686.pkg.tar.gz trapproto-3.4.3-1.pkg.tar.gz
PKGNAME="$(echo -n "$pkg_name" | sed -e 's%\\-i[3456]86.*%%' -e 's%\\.pkg$%%' | rev | cut -f 2-9 -d '-' | rev)"
DB_version="$(echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\\-%%')"
xDB_version="$(echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g')"
xPATTERN="s%${xDB_version}%%"
PKGNAME_ONLY="$(echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null)"
;;
rpm) #110523
#exs: hunspell-fr-3.4-1.1.el6.noarch.rpm
PKGNAME="$pkg_name"
DB_version="$(echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\-%%')"
xDB_version="$(echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g')"
xPATTERN="s%${xDB_version}%%"
PKGNAME_ONLY="$(echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null)"
;;
esac
PKGNAME_ONLY="${PKGNAME_ONLY//.pet/}"
PKGNAME_ONLY="${PKGNAME_ONLY//\.${EX:-noextension}/}"
PKGNAME_ONLY="${PKGNAME_ONLY//\.${pkg_ext:-noextension}/}"
PKGNAME_ONLY="${PKGNAME_ONLY//_amd64/}"
PKGNAME_ONLY="${PKGNAME_ONLY//_arm64/}"
PKGNAME_ONLY="${PKGNAME_ONLY//_armel/}"
PKGNAME_ONLY="${PKGNAME_ONLY//_armhf/}"
PKGNAME_ONLY="${PKGNAME_ONLY//_i[3-6]86/}"
PKGNAME_ONLY="${PKGNAME_ONLY//_x84_64/}"
PKGNAME_ONLY="${PKGNAME_ONLY//_all/}"
# remove the +20080738 from packages with dates in the version
PKGNAME_ONLY="$(echo "$PKGNAME_ONLY" | sed -e 's/+19.*//g' -e 's/+20.*//g')"
[ "$PKGNAME_ONLY" != '' ] && echo "$PKGNAME_ONLY" || echo "$1"
}
get_pkg_name_only(){ # return pkg name only from $1, with no version or suffix FUNCLIST
# exit if no valid options
[ ! "$1" ] && exit 1
# get config settings, inc current repo file
#. ${PKGRC}
local pkg_name=''
local pkg_name_only=''
local name_only=''
local pkg_ext=$(get_pkg_ext "$1")
local repo_of_pkg=''
local repo_ext="$EX" # from $PKGRC
# check the repos
local pkg_name_only="$(grep -m1 "|${1}|" ${REPO_DIR}/Packages-* 2>/dev/null | cut -f2 -d'|')"
[ "$pkg_name_only" = '' ] && pkg_name_only="$(grep -m1 "^${1}|" ${REPO_DIR}/Packages-* 2>/dev/null | cut -f2 -d'|' | head -1)"
[ "$pkg_name_only" = '' ] && pkg_name_only="$(grep -m1 "|${1}|" ${REPO_DIR}/Packages-* 2>/dev/null | cut -f2 -d'|' | head -1)"
[ "$pkg_name_only" = '' ] && pkg_name_only="$(grep -m1 "|${1}.${pkg_ext:-$EX}|" ${REPO_DIR}/Packages-* 2>/dev/null | cut -f2 -d'|' | head -1)"
pkg_name_only="${pkg_name_only// */}"
# if we found it, print it and exit
if [ "$pkg_name_only" != '' ];then
echo "${pkg_name_only}"
return 0
fi
# if not, but we have an extension, try get_pkg_name_only_from_ext()
if [ ! -z "$pkg_ext" ] || [ ! -z "$EX" ];then
case $DISTRO_BINARY_COMPAT in
ubuntu|trisquel|debian|devuan)
name_only=$(get_pkg_name_only_from_ext "$(basename "${1}.${pkg_ext:-$EX}")"| head -1)
name_only="${name_only// */}"
name_only="${name_only//.pet/}"
name_only="${name_only//\.${EX:-noextension}/}"
name_only="${name_only//\.${pkg_ext:-noextension}/}"
name_only="${name_only//_amd64/}"
name_only="${name_only//_arm64/}"
name_only="${name_only//_armel/}"
name_only="${name_only//_armhf/}"
name_only="${name_only//_i[3-6]86/}"
name_only="${name_only//_x84_64/}"
name_only="${name_only//_all/}"
[ "$name_only" != '' ] && [ "$name_only" != "$1" ] && echo "$name_only" && return 0
;;
esac
fi
## ...if we didn't find the name using the above, do the horrible checks below
# replace the dash before the version number with an @ symbol.
# INFO: sed /-[^-][^+][^a-zA-Z][0-9.]*/ (hopefully?) replaces '-$VER' with '@'
# not including when $VER starts with a number/letter
pkg_name_only="$(basename "${1/-[^-][^+][^a-zA-Z][0-9.]*/@}")"
# do 'ioquake3+u20130504' => 'oquake3'
pkg_name_only="${pkg_name_only/+[Aa-Zz]/@}"
# note, we haven't cut away version numbers preceeded with underscores (_) yet
# if the version number was preceeded by an underscore, the version
# will still be in the $pkg_name_only - pkgname_2.3.4 - so cut it out
if [ "$(echo "$pkg_name_only" | grep -o "_[0-9]\.")" != '' ];then
pkg_name_only="${pkg_name_only/_[^a-z][^A-Z][0-9.]*/@}"
# maybe the underscore preceeds a version that starts with a letter
elif [ "$(echo "$pkg_name_only" | grep -o "_[a-zA-Z][0-9]\.")" != '' ];then
pkg_name_only="${pkg_name_only/_[a-zA-Z][0-9.]*/@}"
fi
# now cut away everything after the @, that will leave only the package name
pkg_name_only1="${pkg_name_only/@*/}"
pkg_name_only="$pkg_name_only1"
# we might still have foo_bar_v1.2.3, so lets chop off * after the last _
if [ "$(echo "$pkg_name_only" | grep -o "_[a-zA-Z][0-9]\.")" != '' ];then
pkg_name_only="${pkg_name_only/_[a-zA-Z][0-9]*/}"
fi
# another chop, we might have foo_bar_vv1.2.3, so lets chop off
# everything after the last underscore, if we still have version numbers
if [ "$(echo "$pkg_name_only" | grep -o "_[a-zA-Z][a-zA-Z][0-9]\.")" != '' ];then
pkg_name_only="${pkg_name_only/_[a-zA-Z][a-zA-Z][0-9]*/}"
fi
# we might still have foo_bar_vvv1.2.3, so lets chop off
# everything after the last underscore, if we still have version numbers
if [ "$(echo "$pkg_name_only" | grep -o "_[a-zA-Z*][0-9]\.")" != '' ];then
pkg_name_only="${pkg_name_only/_[a-zA-Z*][0-9]*/}"
fi
# chop again, we might have abc_xwy-zzz1.2.3-blah-etc, so lets chop off
# everything after the last dash-before-number
if [ "$(echo "$pkg_name_only" | grep -o "\-[a-zA-Z*]*[0-9]\.")" != '' ];then
pkg_name_only="${pkg_name_only/-[a-zA-Z*]*[0-9]*/}"
fi
# another fix, if we still have PKGNAME-1.2, remove the '-1.2'
if [ "$(echo "$pkg_name_only" | grep -o "\-[0-9]")" != '' ];then
pkg_name_only="${pkg_name_only/-[0-9]*/}"
fi
# remove the +20080738 from packages with dates in the version
pkg_name_only="$(echo "$pkg_name_only" | sed -e 's/\+19.*//g' -e 's/\+20.*//g')"
pkg_name_only="${pkg_name_only//.pet/}"
pkg_name_only="${pkg_name_only//\.${EX:-noextension}/}"
pkg_name_only="${pkg_name_only//\.${pkg_ext:-noextension}/}"
pkg_name_only="${pkg_name_only//_amd64/}"
pkg_name_only="${pkg_name_only//_arm64/}"
pkg_name_only="${pkg_name_only//_armel/}"
pkg_name_only="${pkg_name_only//_armhf/}"
pkg_name_only="${pkg_name_only//_i[3-6]86/}"
pkg_name_only="${pkg_name_only//_x84_64/}"
pkg_name_only="${pkg_name_only//_all/}"
# the sed bit changes 'liblzma5+20120614' to 'liblzma5'
# shellcheck disable=SC2001
[ "$pkg_name_only" != '' ] && echo "$pkg_name_only" | sed -e 's/\+[a-z0-9].*//g' || return 1
}
get_pkg_name(){ # return full pkg name (with version) from $1 FUNCLIST
# get config settings, inc current repo file
. ${PKGRC}
local pkg_ext=''
local pkg_name=''
local full_name=''
local supported_repo_files=''
# get the extension of the given package name, if any
local pkg_ext=$(get_pkg_ext "$1")
# get the name without path and extension
local pkg_name="$(basename "$1" .${pkg_ext:-$EX})"
# get the repos files in the correct (fall back) order, then add file paths
supported_repo_files="$(repo_file_list | sed -e "s#^#${REPO_DIR}/#g")"
# get the relevant repo contents (fields 1,2,8) from all repos,
# then add pipes to line start/end for easier parsing later, then do
# a basic search, for $pkg* (we'll refine it later), to avoid 'Argument list too long'..
cut -f1,2,8 $supported_repo_files ${REPO_DIR}/woof-installed-packages \
| sed \
-e "s/^/|/g" \
-e "s/$/|/g" 2>/dev/null \
| grep -i "|$pkg_name" > ${TMPDIR}/repo_contents
# get fields 1,2 and 8 (the 3 name fields) from all supported repo files, then
# add '|' to start and end of lines, then find exact match of $pkg_name..
# if no exact match, look for $pkg_name-*, then $pkg_name_*
if [ -f ${TMPDIR}/repo_contents ];then
full_name=$( grep -m1 "|${pkg_name}|" "${TMPDIR}/repo_contents" 2>/dev/null) || \
full_name=$(grep -m1 "|${pkg_name//-*/}|" "${TMPDIR}/repo_contents" 2>/dev/null) || \
full_name=$(grep -m1 "|${pkg_name//_*/}|" "${TMPDIR}/repo_contents" 2>/dev/null) || \
full_name=$(grep -m1 "|${pkg_name}-" "${TMPDIR}/repo_contents" 2>/dev/null) || \
full_name=$(grep -m1 "|${pkg_name}_" "${TMPDIR}/repo_contents" 2>/dev/null) || \
full_name=$(grep -m1 "|${pkg_name}" "${TMPDIR}/repo_contents" 2>/dev/null) || \
full_name=$(grep -m1 "^${pkg_name}|" "${TMPDIR}/repo_contents" 2>/dev/null) || \
full_name=$(grep -m1 "^${pkg_name}-" "${TMPDIR}/repo_contents" 2>/dev/null) || \
full_name=$(grep -m1 "^${pkg_name}_" "${TMPDIR}/repo_contents" 2>/dev/null)
full_name="${full_name//.pet/}"
full_name="${full_name//.${EX:-noextension}/}"
full_name="${full_name//.${pkg_ext:-noextension}/}"
full_name="${full_name//_amd64/}"
full_name="${full_name//_arm64/}"
full_name="${full_name//_armel/}"
full_name="${full_name//_armhf/}"
full_name="${full_name//_i[3-6]86/}"
full_name="${full_name//_x84_64/}"
full_name="${full_name//_all/}"
fi
rm ${TMPDIR}/repo_contents &>/dev/null
# if we found pkg in repo, keep only the package name ('|pkg-123|pkg|blah|' -> 'pkg-123')
[ "$full_name" != '' ] && full_name=$(echo $full_name| cut -f2 -d '|' | tr -d '|') || full_name="$pkg_name"
# if we have a package name, return it here and leave the func
[ "$full_name" != '' ] && echo $full_name && return 0
# if dealing with local files, .deb packages have the arch appended at
# the end, before the extension, so we'll need to remove that (if there)
pkg_name="${pkg_name//_amd64/}"
pkg_name="${pkg_name//_arm64/}"
pkg_name="${pkg_name//_armel/}"
pkg_name="${pkg_name//_armhf/}"
pkg_name="${pkg_name//_i[3-6]86/}"
pkg_name="${pkg_name//_x84_64/}"
pkg_name="${pkg_name//all/}"
# if no pkg found in repos, we cant translate/lookup its longer name,
# so just return what we got, without path, without pkg extension
[ "$full_name" = '' ] && basename "$pkg_name" .${pkg_ext:-${EX:-noextension}}
}
get_pkg_filename(){ # return filename of $1, if its a local file or repo package FUNCLIST
# exit if no valid options
[ ! "$1" ] || [ "$1" = "-" ] && exit 1
if [ -f "$1" ];then
basename "$1"
return 0
fi
# strip away extension and path
local PKGNAME="$(basename "$1" .$EX)"
local PKGNAME=$(get_pkg_name "$PKGNAME")
local PKGNAME_ONLY=$(get_pkg_name_only "$PKGNAME")
# check repos in fallback order
all_supported_repofiles=$(repo_file_list | sed "s#^#${REPO_DIR}/#" | tr '\n' ' ')
local pkgname
for repofile in ${REPO_DIR}/${REPOFILE} $REPO_DIR/*-installed-packages $all_supported_repofiles
do
pkgname="$(grep -m1 "^$PKGNAME|" "$repofile" | cut -f8 -d'|')"
[ ! -z "$pkgname" ] && break
done
if [ -z "$pkgname" ];then
for repofile in ${REPO_DIR}/${REPOFILE} $REPO_DIR/*-installed-packages $all_supported_repofiles
do
pkgname="$(grep -m1 "|$PKGNAME_ONLY|" "$repofile" | cut -f8 -d'|')"
[ ! -z "$pkgname" ] && break
done
fi
[ ! -z "$pkgname" ] && echo "$pkgname" | grep -v ^$ | head -1
}
get_pkg_category(){
# $1 must be PKGNAME_ONLY ('gimp', 'vlc', etc)
[ -z "$1" ] && return 1
local category=''
category="$(grep -i -m1 " ${1} " /usr/local/petget/categories.dat \
| cut -f1 -d'=' \
| cut -f2- -d'_' \
| tr '_' ';')"
# do this in a sub shell
(
\cd $REPO_DIR/ &>/dev/null || exit 1
if [ -z "$category" ];then
# search the repo files
category="$(cut -f1,2,5 -d'|' $(repo_file_list) \
| grep -i -m1 "^${1}.*|${1}|" \
| cut -f3 -d'|')"
fi
[ ! -z "$category" ] && echo "$category" | grep -v ^$
)
}
is_blacklisted_pkg(){ # return true if PKGNAME ($1) is blacklisted FUNCLIST
# exit if no valid options
[ ! "$1" ] || [ "$1" = "-" ] && exit 1
# if we find an exact match of PKGNAME_ONLY in $PKG_BLACKLIST
if [ "$(echo "$PKG_BLACKLIST" | grep -E "^$(get_pkg_name_only "$1")\$")" != '' ];then
echo true
return 0
fi
echo false
return 1
}
is_installed_pkg(){ # return true if PKGNAME ($1) is installed, else false FUNCLIST
# exit if no valid options
[ ! "$1" ] || [ "$1" = "-" ] && print_usage pkg-installed && exit 1
local EX=''
local PKGNAME=''
local PKGNAME_ONLY=''
local PKGFILENAME=''
local PKGFILENAME_NO_EX=''
local check=''
local repo_files="${REPO_DIR}/woof-installed-packages ${REPO_DIR}/user-installed-packages"
# get pkg extension
EX=$(get_pkg_ext "$1")
# strip away extension and path
PKGNAME="$(basename "$1" .$EX)"
PKGNAME=$(get_pkg_name "$PKGNAME")
# we cant rely on the strings the user passes us, so...
[ -z "$check" ] && check="$(find ${REPO_DIR}/ -name "${PKGNAME}.files")"
PKGFILENAME="$(get_pkg_filename ${PKGNAME})"
PKGFILENAME_NO_EX="${PKGFILENAME//.$EX/}"
[ -z "$check" ] && check="$(find ${REPO_DIR}/ -name "${PKGFILENAME_NO_EX}.files" -print -quit)"
[ -z "$check" ] && check="$(cut -f1,2 -d'|' $repo_files | grep -m1 "^$PKGNAME|")"
[ -z "$check" ] && check="$(cut -f8 -d'|' $repo_files | grep -m1 "^${PKGNAME}.$EX")"
[ -z "$check" ] && check="$(cut -f8 -d'|' $repo_files | grep -m1 "^${PKGFILENAME}.deb)")"
PKGNAME_ONLY=$(get_pkg_name_only "$PKGNAME")
[ -z "$check" ] && check="$(cut -f1,2 -d'|' $repo_files | grep -m1 "^$PKGNAME" | grep -m1 "|$PKGNAME_ONLY\$")"
# if any checks above returned a result, $check will not be empty (ash didn't like grep -q, not sure why?)
[ ! -z "$check" ] && echo true || echo false
}
is_builtin_pkg (){ # return true if $1 is a builtin pkg, else false FUNCLIST
# if $1 is an exact match of a pkg short name,
# long name or file name in woof-installed-packages,
# we will return true, else we return false
# exit if no valid input
[ ! "$1" ] && exit 1
local pkg_builtin=''
local pkg_name_only=''
pkg_builtin="$(cut -f1,2,8 -d '|' ${REPO_DIR}/woof-installed-packages 2>/dev/null \
| sed -e 's@^@|@' -e 's@$@|@' \
| grep -m1 "|$1|")"
# try again.. if user gave only partial name (geany-1.27), the above would fail
if [ "$pkg_builtin" = '' ];then
pkg_name_only=$(get_pkg_name_only "$1")
# so search for pkg_name* AND pkg_name_only (exact match, should be in field 2)
if [ "$pkg_name_only" != '' ];then
pkg_builtin="$(cut -f1,2,8 -d '|' ${REPO_DIR}/woof-installed-packages 2>/dev/null \
| sed -e 's@^@|@' -e 's@$@|@' \
| grep "|$1" \
| grep -m1 "|$pkg_name_only|")"
fi
fi
# print result
[ "$pkg_builtin" != '' ] && echo true || echo false
}
is_devx_pkg (){ # return true if $1 is a pkg in the devx, else false FUNCLIST
# if $1 is an exact match of a pkg short name,
# long name or file name in devx-only-installed-packages,
# we will return true, else we return false
# exit if no valid input
[ ! "$1" ] && exit 1
local devx_pkg=''
local pkg_name_only=''
devx_pkg="$(cut -f1,2,8 -d '|' ${REPO_DIR}/devx-only-installed-packages 2>/dev/null\
| sed -e 's@^@|@' -e 's@$@|@' \
| grep -m1 "|$1|")"
# try again.. if user gave only partial name (geany-1.27), the above would fail
if [ "$devx_pkg" = '' ];then
pkg_name_only=$(get_pkg_name_only "$1")
# so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
if [ "$pkg_name_only" != '' ];then
devx_pkg="$(cut -f1,2,8 -d '|' ${REPO_DIR}/devx-only-installed-packages 2>/dev/null\
| sed -e 's@^@|@' -e 's@$@|@' \
| grep "|$1" \
| grep -m1 "|$pkg_name_only|")"
fi
fi
# print result
[ "$devx_pkg" != '' ] && echo true || echo false
}
is_usr_pkg (){ # return true if $1 is a user installed pkg, else false FUNCLIST
# if $1 is an exact match of a pkg short name,
# long name or file name in user-installed-packages,
# we will return true, else we return false