forked from puppylinux-woof-CE/woof-CE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg
executable file
·7779 lines (6140 loc) · 292 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/bash
#
# pkg - a command line package manager for Puppy Linux
#
# By Scott Jarvis (sc0ttman)
# #s243a: modified to use vars instead of explicit paths.
# 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.22"
APPTITLE="$APPNAME $APPVER"
list_deps_count=0 #Keeps track of the number of instances of the function list_deps(). Cleanup will be done when the last instance exists.
dep_id=0 #
# 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
whoami=$(whoami) # s243a copied from below. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
TMPDIR=/tmp/pkg/${whoami} # set the tmp dir
# 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 "$PKGS_DIR" ] && export PKGS_DIR="$(realpath "${HOME}/.packages")"
#These are files of the form
#[ -z "$PET_SPEC_DIR_ROOT" ] && PET_SPEC_DIR_ROOT="$PKGS_DIR"
if [ -z "$REPO_DB_FILE_DIR" ]; then
if [ -d "$PKGS_DIR/repo" ]; then #This imples mistfires ppm3 is installed
export REPO_DB_FILE_DIR="$(realpath "$PKGS_DIR/repo")"
else
export REPO_DB_FILE_DIR="$PKGS_DIR"
fi
fi
if [ -z "$PACKAGE_FILE_LIST_DIR" ]; then
if [ -d "$PKGS_DIR/package-files" ]; then #This imples mistfires ppm3 is installed
export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR/package-files")"
else
export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR")"
fi
fi
[ -z "$BUILTIN_FILE_LIST_DIR" ] && BUILTIN_FILE_LIST_DIR="$PKGS_DIR/builtin_files"
#[ -z "$PET_SPEC_DIR_BUILTIN" ] && PET_SPEC_DIR_BUILTIN=\
# "$(realpath "$PKGS_DIR/builtin_files")"
#
#[ -z "$PET_SPEC_DIR_USR_INST" ] && PET_SPEC_DIR_USR_INST="$PKGS_DIR"
#mk_spec_file_list_arry(){
declare -ga SPEC_DB_PATHS=()
#Can't put the loop in the loop in a pipeline if you want to assign array values:
#https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
#find / -wholename "$PKGS_DIR"/'*-installed-packages' |
while read SPEC_FILE; do
bname="`basename "$SPEC_FILE"`"
case "$bname" in #Consider lowering case
"layers-installed-packages")
#Do Nothing
export LAYER_INST_PKGS_FILE="$SPEC_FILE" ;;
"woof-installed-packages")
export WOOF_INST_PKGS_FILE="$SPEC_FILE" ;;
"user-installed-packages")
export USER_INST_PKGS_FILE="$SPEC_FILE" ;;
"devx-only-installed-packages")
export DEVX_INST_PKGS_FILE="$SPEC_FILE" ;;
*)
SPEC_DB_PATHS+=( "$SPEC_FILE" ) ;;
esac
#s243a: We don't need realpath for the next four vars but it will provide usefull debugging information.
#s243a: TODO search for the following files if they don't exist.
[ -z "$USER_INST_PKGS_FILE" ] && \
USER_INST_PKGS_FILE="$PKGS_DIR/user-installed-packages"
[ -z "$WOOF_INST_PKGS_FILE" ] && \
WOOF_INST_PKGS_FILE="$PKGS_DIR/woof-installed-packages"
[ -z "$LAYER_INST_PKGS_FILE" ] && \
LAYER_INST_PKGS_FILE="$PKGS_DIR/layers-installed packages"
[ -z "$DEVX_INST_PKGS_FILE" ] && \
DEVX_INST_PKGS_FILE="$PKGS_DIR/devx-only-installed-packages"
SPEC_DB_PATHS=( "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${SPEC_DB_PATHS[@]}" )
done < <( find "$PKGS_DIR" -name '*-installed-packages' )
#}
#mk_spec_file_list_arry
#echo "SPEC_DB_PATHS=${SPEC_DB_PATHS[@]}"
#mk_all_repo_file_list_arry(){
declare -gA ALL_REPO_DB_PATHS=()
#ALL_REPO_DB_PATHS=()
bname=''
#Can't put the loop in the loop in a pipeline if you want to assign array values:
#https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
#find / -wholename "$REPO_DB_FILE_DIR"/'Packages-*' |
while read REPO_FILE; do
#s243a: I was thinking of using realpath but it might cause issues.
#REPO_FILE="$(realpath "$REPO_FILE")"
bname="$(basename "$REPO_FILE")"
ALL_REPO_DB_PATHS+=( ["$bname"]="$REPO_FILE" )
#echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
#echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
done < <( find "$REPO_DB_FILE_DIR" -name 'Packages-*' )
#}
#mk_all_repo_file_list_arry
#echo "exited: mk_all_repo_file_list_arry()"
#echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
#Moved after the function repo_file_list
#mk_repo_file_list_arry
# but disable colours if called as gpkg, or the ENV variable PKG_NO_COLOURS is true
if [ "`basename $0`" != "pkg" -o "$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(){
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)
[ -f /tmp/pkg/error130 -a "$2" = '130' ] && exit "$2"
# 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
#run as root only
whoami=$(whoami) #s243a Copied to before line #40. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
[ "$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 $PKGS_DIR/DISTRO_PKGS_SPECS ] && . $PKGS_DIR/DISTRO_PKGS_SPECS #has lot sof essential info
[ -f $PKGS_DIR/PKGS_MANAGEMENT ] && . $PKGS_DIR/PKGS_MANAGEMENT #has PKG_NAME_IGNORE, PKG_PET_THEN_BLACKLIST_COMPAT_KIDS, PKG_REPOS_ENABLED
[ -f $PKGS_DIR/DISTRO_COMPAT_REPOS ] && . $PKGS_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 ;;
*) DBIN_ARCH=i486 ;;
esac
# needed for some debian based repos
case $DISTRO_COMPAT_VERSION in
wheezy) DDB_COMP=bz2 ;; # older versions
*) DDB_COMP=xz ;;
esac
# 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 "$WOOF_INST_PKGS_FILE" /tmp/ppm-layers-installed-packages &>/dev/null
cat "$PET_SPEC_DIR_DEFAULT/devx-only-installed-packages" >> /tmp/ppm-layers-installed-packages &>/dev/null
sort -u /tmp/ppm-layers-installed-packages > "$LAYER_INST_PKGS_FILE" &>/dev/null
else
cp -f "$WOOF_INST_PKGS_FILE" "$LAYER_INST_PKGS_FILE" &>/dev/null
fi
# set $DIRECTSAVEPATH (where we want to install pkgs)
if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ]; then
DIRECTSAVEPATH="/initrd${SAVE_LAYER}" #SAVE_LAYER is in /etc/rc.d/PUPSTATE.
elif [ "$PUPMODE" = "2" ]; then
DIRECTSAVEPATH=""
fi
# s243a: Need the real path to avoid overwriting sylinks. See:
# http://murga-linux.com/puppy/viewtopic.php?p=1030958#1030958
# https://github.com/puppylinux-woof-CE/woof-CE/issues/1469#issuecomment-505706014
[ -L "$DIRECTSAVEPATH" ] && DIRECTSAVEPATH="$(readlink "$DIRECTSAVEPATH")"
# 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 "" >> ~/.bashrc
echo "# enable $APPNAME $APPVER TAB completion" >> ~/.bashrc
echo "export PKG_TAB_COMPLETION=true" >> ~/.bashrc
echo ". /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='mozilla-firefox,firefox gtk+,gtk2 gtk2,gtk+2 dirac,schroedinger hunspell,myspell mp,mped mplayer,mplayer_*,mplayer-*,mplayer2,smplayer,gmplayer mrxvt,rxvt-unicode,xterm,urxvt,urxvt-unicode cxxlibs,glibc*,libc-* glibc-solibs,glibcsolibs alsalib,alsa-lib,alsa-lib2* alsautils,alsa-utils,alsa_utils,alsa-utils2* libungif,libgif,giflib zip,infozip dbus,libdbus*,libdbus-glib* hal,libhal* mesa,mesa_*,libgl1-mesa*,mesa-common* libxcb,libxcb_base sane,sane-backends samba,samba-tng,samba_*,mountcifs SDL_*,libsdl_* SDL,libsdl skype,skype_static util_linux_ng,util-linux-ng,util-linux,util_linux,utillinuxng vlc,vlc-nogui,vlc_nogui,VLC_Plus_Extras xf86-video-ati,xf86-video-ati-*,ati_fglrx xfdiff,xfdiff-cut xorg_base,xorg_base_t2,x11-common,x-dev,xorg,xorg73_base_t2 acl,libacl* xdg_puppy,xdg-utils perl_tiny,perl-base,perl-modules,perlapi* xorg-util-macros,util-macros portaudio,libportaudio jack-audio-connection-kit,libjack libjasper,jasper imlib2,libimlib2 imlib,libimlib'
[ ! -f "$TMPDIR/pkg_aliases" ] && echo "$PKG_NAME_ALIASES" | tr ' ' '\n' > $TMPDIR/pkg_aliases
# 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 -a "$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 -a "$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
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 ] && cat $TMPDIR/func_list | sort && exit 0
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 | sort
exit 0
}
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 ;;
*)
# if it's an installed pkg, get the extension from $PKGS_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'|' "$USER_SPEC_FILE" |grep -m1 ^$1`
[ "$pkg_filename" = '' ] && pkg_filename=`cut -f8 -d'|' "${SPEC_DB_PATHS[@]}" |grep -m1 ^$1`
[ "$pkg_filename" != '' ] && pkg_ext=`get_pkg_ext "$pkg_filename"`
else
# if it's a repo package, get it's extension from $PKGS_DIR/*
pkg_filename=`grep -m1 "^$1" "${REPO_DB_PATHS[@]}" |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=`get_pkg_name "$1"`
local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
local pkg_ext=`get_pkg_ext "$PKGNAME"`
local pkg_version=''
PKGNAME=$(basename "$PKGNAME" .$pkg_ext)
pkg_version=`echo $PKGNAME | sed -e "s/^${PKGNAME_ONLY}_//g"`
# if $pkg_version is same as $PKGNAME, try cutting again, using '-' instead of '_'
[ "$pkg_version" = "$PKGNAME" ] && pkg_version=`echo $PKGNAME | sed -e "s/^${PKGNAME_ONLY}-//g"`
# now trim off the other unneeded bits
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/-WITHDEPS.*//g" \
-e "s/-PLUSDEPS.*//g" \
-e 's@\\\@@g'`
# get $REPONAME and $EX
. ${PKGRC}
[ "$pkg_ext" = '' ] && pkg_ext=$EX
echo $pkg_version
return 0
}
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" != '' ] && 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_pkg_with_ext=''
local repo_ext=$EX # from $PKGRC
# check the repos
local pkg_name_only="`grep -m1 "|${1}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|'`"
[ "$pkg_name_only" = '' ] && pkg_name_only="`grep -m1 "^${1}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|' | head -1`"
[ "$pkg_name_only" = '' ] && pkg_name_only="`grep -m1 "|${1}.${pkg_ext}|" "${REPO_DB_PATHS[@]}" 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()
case $DISTRO_BINARY_COMPAT in ubuntu|trisquel|debian|devuan)
name_only=`get_pkg_name_only_from_ext "$(basename "${1}.${repo_ext}")"| head -1`
name_only=${name_only// */}
[ "$name_only" != '' -a "$name_only" != "$1" ] && echo $name_only && return 0
;;
esac
## ...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="`echo "$(basename "${1}")" | sed -e 's/-[^-][^+][^a-zA-Z][0-9.]*/@/'`"
# do 'ioquake3+u20130504' => 'oquake3'
pkg_name_only="`echo "${pkg_name_only}" | sed -e 's/+[a-z]/@/'`"
# 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="`echo "$pkg_name_only" | sed -e 's/_[^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="`echo "$pkg_name_only" | sed -e 's/_[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
# the sed bit changes 'liblzma5+20120614' to 'liblzma5'
[ "$pkg_name_only" != '' ] && echo $pkg_name_only | sed -e 's/++/+++/g' -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=''
local repo_contents=''
# 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`"
# get the repos files in the correct (fall back) order, then add file paths
#s243a: `repo_file_list` is called in mk_repo_file_list_arry
#supported_repo_files="`repo_file_list | sed -e "s#^#$PKGS_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 "$USER_SPEC_FILE" "$PET_SPEC_DIR_DEFAULT/woof-installed-packages" $supported_repo_files | sed -e "s/^/|/g" -e "s/$/|/g" 2>/dev/null | grep -i "|$pkg_name" > ${TMPDIR}/repo_contents
cut -f1,2,8 "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${REPO_DB_PATHS[@]}" | 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=`cat ${TMPDIR}/repo_contents 2>/dev/null| grep -m1 "|${pkg_name}|"` \
|| full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name//-*/}|"` \
|| full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name//_*/}|"` \
|| full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}-"` \
|| full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}_"` \
|| full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}"` \
|| full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}|"` \
|| full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}-"` \
|| full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}_"`
rm ${TMPDIR}/repo_contents &>/dev/null
fi
# 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 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" = '' ] && echo "`basename "$pkg_name" .$pkg_ext`"
}
is_blacklisted_pkg(){ # return true if PKGNAME ($1) is blacklisted FUNCLIST
# exit if no valid options
[ ! "$1" -o "$1" = "-" ] && print_usage pkg-installed && exit 1
local EX=''
local PKGNAME=''
local PKGNAME_ONLY=''
# get pkg extension
EX=`get_pkg_ext "$1"`
# strip away extension and path
PKGNAME="$(basename "$1" .$EX)"
#PKGNAME=`get_pkg_name "$PKGNAME"`
# get the package name without version
PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
[ "`echo "$PKG_NAME_IGNORE" | grep "$PKGNAME_ONLY "`" != '' ] && echo true || echo false
}
is_installed_pkg(){ # return true if PKGNAME ($1) is installed, else false FUNCLIST
# exit if no valid options
[ ! "$1" -o "$1" = "-" ] && print_usage pkg-installed && exit 1
local EX=''
local PKGNAME=''
local PKGNAME_ONLY=''
local check=''
# 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...
# get the package name without version
PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
# exit if no valid package name
[ "$PKGNAME" = '' -o "$PKGNAME_ONLY" = '' ] && print_usage pkg-installed && exit 1
# check the $PKGS_DIR/*.files
check="$(find "$PACKAGE_FILE_LIST_DIR" -name "$PKGNAME.files")"
[ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'_*.files')"
[ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'-*.files')"
[ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'*.files')"
# slow but reliable & simple: separately check fields 1,2,8 of the various files listing installed pkgs
[ "$check" = '' ] && check="`cut -f1 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME\$"`"
[ "$check" = '' ] && check="`cut -f1,2 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME|" | grep -m1 "|$PKGNAME_ONLY\$"`"
[ "$check" = '' ] && check="`cut -f8 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME"`"
[ "$check" = '' ] && check="`HIDE_BUILTINS=false list_installed_pkgs | grep -m1 ^"$PKGNAME"`"
# if any checks above returned a result, $check will not be empty (ash didn't like grep -q, not sure why?)
[ "$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 '|' "$WOOF_INST_PKGS_FILE" 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 '|' "$WOOF_INST_PKGS_FILE" 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 '|' "$DEVX_INST_PKGS_FILE" 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 '|' "$DEVX_INST_PKGS_FILE" 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
# exit if no valid input
[ ! "$1" ] && exit 1
local usr_pkg=''
local pkg_name_only=''
usr_pkg="`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" 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 [ "$usr_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
usr_pkg="`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" 2>/dev/null\
| sed -e 's@^@|@' -e 's@$@|@' \
| grep "|$1" \
| grep -m1 "|$pkg_name_only|"`"
fi
fi
# print result
[ "$usr_pkg" != '' ] && echo true || echo false
}
is_repo_pkg (){ # return true if $1 is a pkg in a supported repo, else false FUNCLIST
# if $1 is an exact match of a pkg short name,
# long name or file name in Packages-*-
# we will return true, else we return false
# exit if no valid input
[ ! "$1" ] && exit 1
local repo_pkg=''
local pkg_name_only=''
local all_supported_repofiles
# all repo files, full paths
#all_supported_repofiles=`repo_file_list | sed "s#^#$PKGS_DIR/#" | tr '\n' ' '`
#Don't need sed, but could use if you want to do wildcards
#all_supported_repofiles=`repo_file_list | sed 's#$#*#' | xargs find -name | tr '\n' ' '`
#echo "repo_file_list | xargs find \"$PKGS_DIR\" -name | tr '\n' ' '"
all_supported_repofiles="$(repo_file_list | while read a; do find "$REPO_DB_FILE_DIR" -name "$a"'*'; done | tr '\n' ' ')"
# search all repo files for the $1
repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
| sed -e 's/ //g' -e 's@^@|@' -e 's@$@|@' \
| grep -m1 "|${1}|"`"
# search all repo files for the $1*
[ "$repo_pkg" = '' ] \
&& repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
| sed -e 's/ //g' -e 's@^@|@' -e 's@$@|@' \
| grep -m1 "|${1}-\?_\?[0-9.a-zA-Z]*|"`"
# try again.. if user gave only partial name (geany-1.27), the above would fail
if [ "$repo_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
repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
| sed -e 's@^@|@' -e 's@$@|@' \
| grep "|$1" \
| grep -m1 "|$pkg_name_only|"`"
fi
fi
# print result
[ "$repo_pkg" != '' ] && echo true || echo false
}
is_current_repo_pkg(){ # takes $PKGNAME ($1), returns true or false FUNCLIST
# exit if no valid input
[ ! "$1" ] && exit 1
# get current repo ($REPOFILE)
. ${PKGRC}
local pkg_in_repo
#s243a: The repo file path
local RF_PATH="$(realpath "$(find "$REPO_DB_FILE_DIR" -name "$REPOFILE" | head -n 1 )")"
# check if given pkg ($1) is in the current repo
pkg_in_repo="`LANG=C cut -f1,2,7,8 -d'|' "$RF_PATH" 2>/dev/null | sed -e "s/^/|/" -e "s/$/|/" | grep -m1 "|${1}|"`"
# print msg
[ "$pkg_in_repo" != '' ] && echo true || echo false
}
is_local_pkg(){ # returns true if $1 is local package file FUNCLIST
# exit if no valid input
[ ! "$1" ] && exit 1
. ${PKGRC}
# if $1 is a local file with a supported package extension
# then we return true, else, we return false
local is_file=''
local is_local_pkg=false
# first, check we have a local file
if [ -f "$1" ]; then
# file *probably* has an extension, lets try to get it..
# the func get_pkg_ext() will return empty if not a valid package extension
file_ext=`get_pkg_ext "$1"`
# if not empty, it must be a local file, with valid pkg ext (a local pkg)
[ "$file_ext" != '' ] && is_local_pkg=true
elif [ -f "$CURDIR/$1" ]; then
file_ext=`get_pkg_ext "$CURDIR/$1"`
[ "$file_ext" != '' ] && is_local_pkg=true
elif [ -f "$WORKDIR/$1" ]; then
file_ext=`get_pkg_ext "$CURDIR/$1"`
[ "$file_ext" != '' ] && is_local_pkg=true
fi
# print output
echo $is_local_pkg
}
# RC file funcs
set_workdir(){ # set new WORKDIR in rc file location FUNCLIST
# get latest rc file values
. ${PKGRC}
# make sure $1 was given and doesn't already exist
[ ! "$1" ] && print_usage workdir && exit 1
[ -e "$1" ] && echo "Error: directory already exists. Choose a new one." && exit 1
# create the dir
mkdir -p "$1" 2>/dev/null
# if dir not created, exit with error
[ $? -eq 1 ] && echo "Error: Could not create $1" && exit 1
[ ! -d "$1" ] && echo "Error: Could not create directory: $1" && exit 1
# dir was created, so lets copy our pkgs in there
list_downloaded_pkgs | while read pkg_file
do
cp -v "$WORKDIR/$pkg_name" "$1/"
done
# if copying everything to new dir failed
if [ $? -eq 1 ]; then
# print msg
echo -e "${yellow}Warning:${endcolour}Could not copy packages from $WORKDIR to $1.."
echo "You should copy all packages in $WORKDIR into $1."
fi
# update the RC file
WORKDIR="$1"
set_config
echo "Success. Work directory updated."
exit 0
}
set_pkg_scope(){ # one|all set search for pkgs in current repo or all FUNCLIST
# get old values, any we dont set here are not overwritten
. ${PKGRC}
[ "$1" != "" ] && PKGSCOPE="$1" || PKGSCOPE="$PKGSCOPE"
case "$1" in
all)
# set pkg search to all
PKGSEARCH="list_all_pkg_names"
PKGSEARCHEXACT="$SELF -nea"
echo -e "${green}Success:${endcolour} Find packages in all repos."
;;
one)
# set pkg search to current only
PKGSEARCH="list_pkg_names"
PKGSEARCHEXACT="$SELF -ne"
echo -e "${green}Success:${endcolour} Find packages in current repo ($REPONAME) only."
;;