Advertisement
s243a

pkg-classic (md5sum)

Nov 19th, 2019
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 302.21 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #  pkg - a command line package manager for Puppy Linux
  4. #
  5. #  By Scott Jarvis (sc0ttman)
  6. #  #s243a: modified to use vars instead of explicit paths.
  7. #  Copyright (c) 2013 Puppy Linux Community
  8. #
  9. #  This program is free software; you can redistribute it and/or modify
  10. #  it under the terms of the GNU General Public License as published by
  11. #  the Free Software Foundation; either version 1 of the License, or
  12. #  (at your option) any later version.
  13. #
  14. #  This program is distributed in the hope that it will be useful,
  15. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #  GNU General Public License for more details.
  18. #
  19. #  You should have received a copy of the GNU General Public License
  20. #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21.  
  22.  
  23. #==================  setup script vars  =====================#
  24.  
  25. APPNAME="Pkg"
  26. APPVER="1.9.22"
  27. APPTITLE="$APPNAME $APPVER"
  28. 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.
  29. dep_id=0 #
  30. # get current locale settings
  31. USER_LANG=$LANG
  32. USER_LC_ALL=$LC_ALL
  33. export HTTPS_CHECK=all
  34. SELF=$(basename $0)        # this script
  35. QTAG=''                    # gets set to (y/n) if ASK=-true
  36. LANG=C                     # speed up
  37. LC_ALL=C                   # speed up
  38. EDITOR=${EDITOR:-vi}       # just in case
  39. PAGER=${PAGER:-less}       # just in case
  40. CURDIR="${PWD}"            # get current dir, before cd to WORKDIR
  41. whoami=$(whoami)           # s243a copied from below. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
  42. TMPDIR=/tmp/pkg/${whoami}  # set the tmp dir
  43.  
  44. # set colours true by default
  45. green="\e[32m"; red="\e[91m"; magenta="\e[95m"; lightblue="\e[36m"; yellow="\e[93m"; bold="\e[1m"; endcolour="\e[0m"
  46.  
  47. # ENVIRONMENT VARS, which may be overridden later
  48. [ -z "$PKGRC" ] && export PKGRC=${HOME}/.pkg/pkgrc      # config file for this script
  49. [ -z "$ASK"   ] && ASK=false                            # if true, ask user before doing stuff. Overridden by --ask
  50. [ -z "$QUIET" ] && QUIET=false                          # if true, hide output that doesnt log well in Xdialog, Gtkdialog, etc
  51. [ -z "$FORCE" ] && FORCE=false                          # if true, force (re)install/remove pkgs. Overridden by --force
  52. [ -z "$HIDE_INSTALLED" ] && export HIDE_INSTALLED=false # if true, hide installed pkgs from pkg searches (-n, -na, -ss, -ssa)
  53. [ -z "$HIDE_BUILTINS"  ] && export HIDE_BUILTINS=true   # if true, remove builtins pkgs from dep lists, dont download/install them
  54. [ -z "$HIDE_USER_PKGS" ] && export HIDE_USER_PKGS=true  # if true, hide user installed pkgs from dep lists, dont download/install them
  55. [ -z "$NO_ALIASES"     ] && export NO_ALIASES=false     # if true, skip searching pkg alias names for pkg alternatives
  56. [ -z "$NO_INSTALL"     ] && export NO_INSTALL=false     # if true, skip installing of pkgs
  57. [ -z "$PKG_NO_COLOURS" ] && export PKG_NO_COLOURS=false # if true, disable coloured output or not
  58. [ -z "$PKG_CONFIGURE"  ] && export PKG_CONFIGURE=''     # reset
  59. [ -z "$PKG_CFLAGS"     ] && export PKG_CFLAGS=''        # reset
  60.  
  61. [ -z "$PKGS_DIR" ] && export PKGS_DIR="$(realpath "${HOME}/.packages")"
  62. #These are files of the form
  63. #[ -z "$PET_SPEC_DIR_ROOT" ] && PET_SPEC_DIR_ROOT="$PKGS_DIR"
  64. if [ -z "$REPO_DB_FILE_DIR" ]; then
  65.   if [ -d "$PKGS_DIR/repo" ]; then #This imples mistfires ppm3 is installed
  66.     export REPO_DB_FILE_DIR="$(realpath "$PKGS_DIR/repo")"
  67.   else
  68.     export REPO_DB_FILE_DIR="$PKGS_DIR"
  69.   fi
  70. fi
  71. if [ -z "$PACKAGE_FILE_LIST_DIR" ]; then
  72.   if [ -d "$PKGS_DIR/package-files" ]; then #This imples mistfires ppm3 is installed
  73.     export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR/package-files")"
  74.   else
  75.     export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR")"
  76.   fi
  77. fi
  78. [ -z "$BUILTIN_FILE_LIST_DIR" ] && BUILTIN_FILE_LIST_DIR="$PKGS_DIR/builtin_files"
  79. #[ -z "$PET_SPEC_DIR_BUILTIN" ] && PET_SPEC_DIR_BUILTIN=\
  80. #  "$(realpath "$PKGS_DIR/builtin_files")"
  81. #
  82. #[ -z "$PET_SPEC_DIR_USR_INST" ] && PET_SPEC_DIR_USR_INST="$PKGS_DIR"
  83.  
  84.  
  85. #mk_spec_file_list_arry(){
  86.  declare -ga SPEC_DB_PATHS=()
  87.  #Can't put the loop in the loop in a pipeline if you want to assign array values:
  88.  #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop  
  89.  #find / -wholename "$PKGS_DIR"/'*-installed-packages' |
  90.  while read SPEC_FILE; do
  91.    bname="`basename "$SPEC_FILE"`"
  92.    case "$bname" in #Consider lowering case
  93.    "layers-installed-packages")
  94.      #Do Nothing
  95.      export LAYER_INST_PKGS_FILE="$SPEC_FILE" ;;
  96.    "woof-installed-packages")
  97.      export WOOF_INST_PKGS_FILE="$SPEC_FILE" ;;
  98.    "user-installed-packages")
  99.      export USER_INST_PKGS_FILE="$SPEC_FILE" ;;
  100.    "devx-only-installed-packages")
  101.      export DEVX_INST_PKGS_FILE="$SPEC_FILE" ;;    
  102.    *)
  103.      SPEC_DB_PATHS+=( "$SPEC_FILE" ) ;;
  104.    esac
  105.    #s243a: We don't need realpath for the next four vars but it will provide usefull debugging information.
  106.    #s243a: TODO search for the following files if they don't exist.
  107.    [ -z "$USER_INST_PKGS_FILE" ] && \
  108.      USER_INST_PKGS_FILE="$PKGS_DIR/user-installed-packages"
  109.    [ -z "$WOOF_INST_PKGS_FILE" ] && \
  110.      WOOF_INST_PKGS_FILE="$PKGS_DIR/woof-installed-packages"
  111.    [ -z "$LAYER_INST_PKGS_FILE" ] && \
  112.      LAYER_INST_PKGS_FILE="$PKGS_DIR/layers-installed packages"
  113.    [ -z "$DEVX_INST_PKGS_FILE" ] && \
  114.      DEVX_INST_PKGS_FILE="$PKGS_DIR/devx-only-installed-packages"
  115.    SPEC_DB_PATHS=( "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${SPEC_DB_PATHS[@]}" )
  116.  done < <( find "$PKGS_DIR" -name '*-installed-packages' )
  117. #}  
  118. #mk_spec_file_list_arry
  119. #echo "SPEC_DB_PATHS=${SPEC_DB_PATHS[@]}"
  120.  
  121.  
  122.  
  123. #mk_all_repo_file_list_arry(){
  124.  declare -gA ALL_REPO_DB_PATHS=()
  125.  #ALL_REPO_DB_PATHS=()
  126.  bname=''
  127.  
  128.  #Can't put the loop in the loop in a pipeline if you want to assign array values:
  129.  #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  130.  #find / -wholename "$REPO_DB_FILE_DIR"/'Packages-*' |
  131.  while read REPO_FILE; do
  132.      #s243a: I was thinking of using realpath but it might cause issues.
  133.      #REPO_FILE="$(realpath "$REPO_FILE")"
  134.      bname="$(basename "$REPO_FILE")"  
  135.      ALL_REPO_DB_PATHS+=( ["$bname"]="$REPO_FILE" )
  136.      #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  137.      #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  138.  done < <( find "$REPO_DB_FILE_DIR" -name 'Packages-*' )
  139. #}  
  140. #mk_all_repo_file_list_arry
  141. #echo "exited: mk_all_repo_file_list_arry()"
  142. #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  143.  
  144.   [ -z "$PKGS_DIR" ] && export PKGS_DIR="$(realpath "${HOME}/.packages")"
  145.   [ -z "$MD5_DIR" ] && export MD5_DIR="$PKGS_DIR/md5_dir" && mkdir -p "$MD5_DIR"
  146.  
  147.  
  148. #Moved after the function repo_file_list
  149. #mk_repo_file_list_arry
  150. # but disable colours if called as gpkg, or the ENV variable PKG_NO_COLOURS is true
  151. if [ "`basename $0`" != "pkg" -o "$PKG_NO_COLOURS" = true ]; then
  152.   green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour=''
  153. fi
  154.  
  155. # report errors better than just echo
  156. error(){
  157.   echo -e 1>&2 "${red}Error:${endcolour} $1"
  158. }
  159.  
  160. # for correct error output, trap commands early
  161. cleanup(){
  162.   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
  163.   rm -rf /tmp/pkg/build_pkg/ &>/dev/null
  164.  
  165.   # prevent double msg output if error=130 (user Ctrl-C)
  166.   [ -f /tmp/pkg/error130 -a "$2" = '130' ] && exit "$2"
  167.   # make the tmp dir we'll use
  168.   mkdir -p /tmp/pkg &>/dev/null
  169.   # only add line numbers if it was given
  170.   [ "$1" != 'none' ] && lineno="line $1, " || lineno=''
  171.   # get the right error msg
  172.   case "$2" in
  173.   130) echo; msg="User cancelled operation!"; touch /tmp/pkg/error130;;
  174.   8)   msg="Package URL invalid.";;
  175.   7)   msg="Package extraction failed.";;
  176.   6)   msg="Missing package file.";;
  177.   5)   msg="Missing directory.";;
  178.   4)   msg="Copy failed.";;
  179.   3)   msg="Setup failed.";;
  180.   2)   msg="Code error!";;
  181.   1)   exit 1 ;; # user gave wrong options or pkg name, not serious
  182.   *)   msg="Error code = $2" ;;
  183.   esac
  184.   # print msg
  185.   [ "$2" != "0" ]  && echo -e 1>&2 "${red}Error${endcolour} ${2}: ${lineno}$msg"
  186.   exit $2
  187. }
  188. trap 'cleanup ${LINENO:-none} $?' EXIT INT TERM
  189.  
  190. #run as root only
  191. whoami=$(whoami) #s243a Copied to before line #40. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
  192. [ "$whoami" != "root" ] && echo "You must be root to run Pkg." && exit 1
  193.  
  194. #080413 make sure all config files are present, copy from /etc if need be
  195. if [ ! -f ${PKGRC} ]; then
  196.   echo "Restoring default settings from /etc/pkg"
  197.   [ ! -d /etc/pkg/ ] && error "Default config files  in /etc/pkg/ not found." && exit 3
  198.   mkdir -p "$HOME/.pkg"
  199.   [ ! -d "$HOME/.pkg" ] && error "Default user config dir '$HOME/.pkg/' could not be created." && exit 3
  200.   cp --force -a /etc/pkg/* "$HOME/.pkg/" || exit 3
  201. fi
  202.  
  203. # get puppy distro env vars
  204. [ -f /etc/rc.d/PUPSTATE ]                   && . /etc/rc.d/PUPSTATE                    #this has PUPMODE and SAVE_LAYER.
  205. [ -f /etc/DISTRO_SPECS ]                    && . /etc/DISTRO_SPECS                     #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  206. [ -f /etc/rc.d/BOOTCONFIG ]                 && . /etc/rc.d/BOOTCONFIG                  #has EXTRASFSLIST PREVUNIONRECORD, LASTUNIONRECORD (sfs stuff)
  207. [ -f /etc/xdg/menus/hierarchy ]             && . /etc/xdg/menus/hierarchy              #w478 has PUPHIERARCHY variable.
  208. [ -f $PKGS_DIR/DISTRO_PKGS_SPECS ]    && . $PKGS_DIR/DISTRO_PKGS_SPECS     #has lot sof essential info
  209. [ -f $PKGS_DIR/PKGS_MANAGEMENT ]      && . $PKGS_DIR/PKGS_MANAGEMENT       #has PKG_NAME_IGNORE, PKG_PET_THEN_BLACKLIST_COMPAT_KIDS, PKG_REPOS_ENABLED
  210. [ -f $PKGS_DIR/DISTRO_COMPAT_REPOS ]  && . $PKGS_DIR/DISTRO_COMPAT_REPOS   #has repo URL related vars
  211.  
  212. # set the package name suffix appended to combined pkgs (pkg+deps)
  213. CP_SUFFIX="WITHDEPS_${DISTRO_FILE_PREFIX}"
  214.  
  215. # set correct arch for repo URLs (used by some slack-pup repos)
  216. case "$DISTRO_TARGETARCH" in
  217.   x86)    DBIN_ARCH=i486                ;;
  218.   x86_64) DBIN_ARCH=x86_64 ; DSUFFIX=64 ;;
  219.   *)      DBIN_ARCH=i486                ;;
  220. esac
  221.  
  222. # needed for some debian based repos
  223. case $DISTRO_COMPAT_VERSION in
  224.   wheezy) DDB_COMP=bz2 ;; # older versions
  225.   *)      DDB_COMP=xz  ;;
  226. esac
  227.  
  228. # now create 'layers-installed': will contain builtins (and devx packages, if devx is loaded)
  229. #130511 need to include devx-only-installed-packages, if loaded...
  230. if which gcc &>/dev/null; then
  231.   [ ! -f /tmp/ppm-layers-installed-packages ] && cp -f "$WOOF_INST_PKGS_FILE" /tmp/ppm-layers-installed-packages &>/dev/null
  232.   cat "$PET_SPEC_DIR_DEFAULT/devx-only-installed-packages" >> /tmp/ppm-layers-installed-packages &>/dev/null
  233.   sort -u /tmp/ppm-layers-installed-packages > "$LAYER_INST_PKGS_FILE" &>/dev/null
  234. else
  235.   cp -f "$WOOF_INST_PKGS_FILE" "$LAYER_INST_PKGS_FILE" &>/dev/null
  236. fi
  237.  
  238. # set $DIRECTSAVEPATH (where we want to install pkgs)
  239. if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ]; then
  240.   DIRECTSAVEPATH="/initrd${SAVE_LAYER}" #SAVE_LAYER is in /etc/rc.d/PUPSTATE.
  241. elif [ "$PUPMODE" = "2" ]; then
  242.   DIRECTSAVEPATH=""
  243. fi
  244. # s243a: Need the real path to avoid overwriting sylinks. See:
  245. # http://murga-linux.com/puppy/viewtopic.php?p=1030958#1030958  
  246. # https://github.com/puppylinux-woof-CE/woof-CE/issues/1469#issuecomment-505706014
  247. [ -L "$DIRECTSAVEPATH" ] && DIRECTSAVEPATH="$(readlink "$DIRECTSAVEPATH")"
  248. # get repo details, workdir, search settings and so on.. you could
  249. # you can also add any ENVIRONMENT VARS above to PKGRC, to override the defaults
  250. . ${PKGRC}
  251. [ -z "$HTTPS_CHECK" ] && HTTPS_CHECK=all
  252. CHECKSUM_DIR=/var/packages/checksums
  253. export HTTPS_CHECK="$HTTPS_CHECK"
  254.  
  255. # set and create workdir if no valid dir set
  256. [ ! -d "$WORKDIR" ] && mkdir -p "$WORKDIR"
  257. if [ ! -d "$WORKDIR" ]; then
  258.   error "Can't create $WORKDIR. Please create it."
  259.   exit 3
  260. fi
  261. WORKDIR=~/pkg
  262.  
  263. # add to tab completion settings to bashrc and print hint
  264. if [ -z "$PKG_TAB_COMPLETION" ]; then
  265.   if [ "$(grep 'export PKG_TAB_COMPLETION=true' ~/.bashrc)" = "" ]; then
  266.     # add to bashrc
  267.     echo "" >> ~/.bashrc
  268.     echo "# enable $APPNAME $APPVER TAB completion" >> ~/.bashrc
  269.     echo "export PKG_TAB_COMPLETION=true" >> ~/.bashrc
  270.     echo ". /etc/bash_completion.d/pkg 2>/dev/null" >> ~/.bashrc
  271.   fi
  272. fi
  273.  
  274. # make tmp dir writable by everyone if needed
  275. if [ ! -d "$TMPDIR" ]; then
  276.   mkdir -p "$TMPDIR" 2>/dev/null
  277.   chmod -R 1777 /tmp/pkg/ 2>/dev/null
  278. fi
  279.  
  280. # if no tmp dir created or accessible, exit
  281. [ ! -d "$TMPDIR" ] && error "Cannot create temp dir ${lightblue}$TMPDIR${endcolour}" && exit 3
  282.  
  283. # support aliases, create ALIASES tmp file
  284. 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'
  285. [ ! -f "$TMPDIR/pkg_aliases" ] && echo "$PKG_NAME_ALIASES" | tr ' ' '\n' > $TMPDIR/pkg_aliases
  286.  
  287. # remove error code flag if we got here
  288. rm -f /tmp/pkg/error130 &>/dev/null
  289.  
  290. # if not first run, and no options given, print the help
  291. [ ! -f ~/.pkg/firstrun -a "$1" = "" ] && $SELF -H && exit 1 #200913 more help by default
  292.  
  293. #==================  setup script vars  =====================#
  294.  
  295.  
  296.  
  297. #====================  main functions  ======================#
  298.  
  299. set -a
  300.  
  301. # utility funcs
  302.  
  303. print_usage(){                    # print usage text. Requires $1, a valid Pkg cmd FUNCLIST
  304.  
  305.   local examples_file=/usr/share/pkg/docs/examples.txt
  306.  
  307.   [ -f $examples_file ] && source $examples_file
  308.  
  309.   # get and print the usage info from its usage file
  310.   if [ -f /usr/share/pkg/docs/usage/$1 -a "$1" ]; then
  311.     source /usr/share/pkg/docs/usage/$1
  312.     echo -e "\n$USAGE"
  313.     # show examples, taken from $EXAMPLES, if they exist
  314.     if [ "`echo "$EXAMPLES" | grep "$SELF" | grep "\-$1"`" != '' ]; then
  315.       echo -e "\n${bold}Usage Examples${endcolour}:\n"
  316.       echo -e "$EXAMPLES" | grep "$SELF " | grep "$1 "
  317.     fi
  318.   else
  319.     echo -e "Usage: ${bold}$SELF usage CMD${endcolour}"
  320.     echo
  321.     echo "Commands:"
  322.     echo -e "add-repo       get-only         repo-convert
  323. add-source     help             repo-dep-scope
  324. all-pkgs       help-all         repo-file-list
  325. add            remove           repo-info
  326. ask            install          repo-list
  327. autoclean      install-all      repo-pkg-scope
  328. bleeding-edge  list-deps        repo-update
  329. clean          list-downloaded  search
  330. contents       list-installed   search-all
  331. deb2pet        names            sfs2pet
  332. delete         names-all        sfs-combine
  333. delete-all     names-exact      show-config
  334. deps           names-exact-all  split
  335. deps-all       pet2sfs          tgz2pet
  336. deps-check     pet2tgz          uninstall
  337. deps-download  pet2txz          uninstall-all
  338. dir2pet        build            unpack
  339. dir2sfs        build-list       update-sources
  340. dir2tgz        pkg-combine      version
  341. download       installed        which
  342. examples       repack           which-repo
  343. extract        status           rdep-check
  344. force          update           what-needs
  345. func-list      workdir          rm-repo
  346. txz2pet        dir2repo
  347.  
  348. Usage: ${bold}$SELF usage CMD${endcolour}"
  349.     #cd /usr/share/pkg/docs/usage/; echo `ls` | fold -w 70 -s
  350.   fi
  351.   exit 1
  352. }
  353.  
  354.  
  355. func_list(){                      # list all functions available in this script FUNCLIST
  356.   [ -f $TMPDIR/func_list ] && cat $TMPDIR/func_list | sort && exit 0
  357.   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
  358.   cat $TMPDIR/func_list | sort
  359.   exit 0
  360. }
  361.  
  362.  
  363. get_pkg_ext(){                    # return file extension of $1 FUNCLIST
  364.  
  365.   # get valid usage or exit
  366.   [ ! "$1" ] && echo 'Usage: get_pkg_ext PKGNAME' && exit 1
  367.  
  368.   local pkg_installed=''
  369.   local pkg_filename=''
  370.   local pkg_ext=''
  371.   local pkg_name=''
  372.  
  373.   # check given file type, see if it matches our supported pkg types
  374.   case "$1" in
  375.     *.bz2)        echo bz2        ;;
  376.     *.pet)        echo pet        ;;
  377.     *.deb)        echo deb        ;;
  378.     *.pkg.tar.gz) echo pkg.tar.gz ;;
  379.     *.pkg.tar.xz) echo pkg.tar.xz ;;
  380.     *.pkg.tgz)    echo pkg.tgz    ;;
  381.     *.pkg.txz)    echo pkg.txz    ;;
  382.     *.tar.bz2)    echo tar.bz2    ;;
  383.     *.tar.lzma)   echo tar.lzma   ;;
  384.     *.tar.gz)     echo tar.gz     ;;
  385.     *.tar.xz)     echo tar.xz     ;;
  386.     *.tbz)        echo tbz        ;;
  387.     *.tgz)        echo tgz        ;;
  388.     *.tlz)        echo tlz        ;;
  389.     *.txz)        echo txz        ;;
  390.     *.gz)         echo gz         ;;
  391.     *.xz)         echo xz         ;;
  392.     *.rpm)        echo rpm        ;;
  393.     *.sfs)        echo sfs        ;;
  394.     #*.tcz)        echo tcz       ;;
  395.     #*.tpkg)       echo tpkg      ;;
  396.     #*.apk)        echo apk       ;;
  397.     *)
  398.       # if it's an installed pkg, get the extension from $PKGS_DIR/*
  399.       pkg_installed=`list_installed_pkgs "$1" | grep -m1 "^$1"`
  400.  
  401.       # if $pkg_check not empty, then $1 is an installed pkg
  402.       if [ "$pkg_installed" != '' ]; then
  403.         pkg_filename=`cut -f8 -d'|' "$USER_SPEC_FILE" |grep -m1 ^$1`
  404.         [ "$pkg_filename" = '' ] && pkg_filename=`cut -f8 -d'|' "${SPEC_DB_PATHS[@]}" |grep -m1 ^$1`
  405.         [ "$pkg_filename" != '' ] && pkg_ext=`get_pkg_ext "$pkg_filename"`
  406.       else
  407.         # if it's a repo package, get it's extension from $PKGS_DIR/*
  408.         pkg_filename=`grep -m1 "^$1" "${REPO_DB_PATHS[@]}" |cut -f8 -d'|'`
  409.        [ "$pkg_filename" != '' ] &&  pkg_ext=`get_pkg_ext "$pkg_filename"`
  410.       fi
  411.       [ "$pkg_ext" != '' ] && echo $pkg_ext
  412.       ;;
  413.   esac
  414. }
  415.  
  416.  
  417. get_pkg_version(){                # returns version of PKGNAME ($1) FUNCLIST
  418.  
  419.   # exit if no pkg given
  420.   [ ! "$1" ] && exit 1
  421.  
  422.   local PKGNAME=`get_pkg_name "$1"`
  423.   local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  424.   local pkg_ext=`get_pkg_ext "$PKGNAME"`
  425.   local pkg_version=''
  426.  
  427.   PKGNAME=$(basename "$PKGNAME" .$pkg_ext)
  428.  
  429.   pkg_version=`echo $PKGNAME | sed -e "s/^${PKGNAME_ONLY}_//g"`
  430.   # if $pkg_version is same as $PKGNAME, try cutting again, using '-' instead of '_'
  431.   [ "$pkg_version" = "$PKGNAME" ] && pkg_version=`echo $PKGNAME | sed -e "s/^${PKGNAME_ONLY}-//g"`
  432.  
  433.   # now trim off the other unneeded bits
  434.   pkg_version=`echo  $pkg_version | sed \
  435.     -e "s/^-//g" \
  436.     -e "s/^_//g" \
  437.     -e "s/^DEV-//g" \
  438.     -e "s/^DOC-//g" \
  439.     -e "s/^NLS-//g" \
  440.     -e "s/^dev-//g" \
  441.     -e "s/^doc-//g" \
  442.     -e "s/^nls-//g" \
  443.     -e "s/+deb.*//g" \
  444.     -e "s/+ubuntu.*//g" \
  445.     -e "s/-i[346].*//g" \
  446.     -e "s/-x[86].*//g" \
  447.     -e "s/-pup.*//g" \
  448.     -e "s/-q[0-9].*//g" \
  449.     -e "s/-WITHDEPS.*//g" \
  450.     -e "s/-PLUSDEPS.*//g" \
  451.     -e 's@\\\@@g'`
  452.  
  453.   # get $REPONAME and $EX
  454.   . ${PKGRC}
  455.  
  456.   [ "$pkg_ext" = '' ] && pkg_ext=$EX
  457.  
  458.   echo $pkg_version
  459.   return 0
  460. }
  461.  
  462.  
  463. get_pkg_name_only_from_ext(){     # return package name from $1 (must include file extension)
  464.  
  465.   # get valid usage or exit
  466.   [ ! "$1" ] && echo 'Usage: get_pkg_name_only_from_ext <PKG_FILENAME>' && exit 1
  467.  
  468.   # get the extension of the given package name, if any
  469.   local pkg_ext=`get_pkg_ext "$1"`
  470.   # get the name without path and extension
  471.   local pkg_name=`basename "$1" .$pkg_ext`
  472.   local PKGNAME=''
  473.   local PKGNAME_ONLY=''
  474.   local DB_pkgrelease=''
  475.   local prPATTERN=''
  476.   local DB_version=''
  477.   local xDB_version=''
  478.   local xPATTERN=''
  479.  
  480.   #split PKGMAIN, ex: FULLPKGNAME=xvidtune-1.0.1-i486-1.tgz has PKGNAME=xvidtune-1.0.1
  481.   case $pkg_ext in
  482.     deb)
  483.      #deb ex: xsltproc_1.1.24-1ubuntu2_i386.deb  xserver-common_1.5.2-2ubuntu3_all.deb
  484.      PKGNAME_ONLY="`echo -n "$pkg_name" | cut -f 1 -d '_'`"
  485.      DB_pkgrelease="`echo -n "$pkg_name" | rev | cut -f 2 -d '_' | cut -f 1 -d '-' | rev`"
  486.      prPATTERN="s%\\-${DB_pkgrelease}.*%%"
  487.      PKGNAME="`echo -n "$pkg_name" | sed -e "$prPATTERN" 2>/dev/null`"
  488.     ;;
  489.     pet)
  490.      PKGNAME="$pkg_name"
  491.      DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\-%%'`"
  492.      xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  493.      xPATTERN="s%${xDB_version}%%"
  494.      PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  495.     ;;
  496.     tgz|txz)
  497.      #slack ex: xvidtune-1.0.1-i486-1.tgz  printproto-1.0.4-noarch-1.tgz
  498.      PKGNAME="`echo -n "$pkg_name" | sed -e 's%\\-i[3456]86.*%%' -e 's%\\-noarch.*%%'`"
  499.      DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\\-%%'`"
  500.      xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  501.      xPATTERN="s%${xDB_version}%%"
  502.      PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\-$%%' 2>/dev/null`"
  503.     ;;
  504.     tar.gz)
  505.      #arch ex: xproto-7.0.14-1-i686.pkg.tar.gz  trapproto-3.4.3-1.pkg.tar.gz
  506.      PKGNAME="`echo -n "$pkg_name" | sed -e 's%\\-i[3456]86.*%%' -e 's%\\.pkg$%%' | rev | cut -f 2-9 -d '-' | rev`"
  507.      DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\\-%%'`"
  508.      xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  509.      xPATTERN="s%${xDB_version}%%"
  510.      PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  511.     ;;
  512.     rpm) #110523
  513.      #exs: hunspell-fr-3.4-1.1.el6.noarch.rpm
  514.      PKGNAME="$pkg_name"
  515.      DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\-%%'`"
  516.      xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  517.      xPATTERN="s%${xDB_version}%%"
  518.      PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  519.     ;;
  520.   esac
  521.   [ "$PKGNAME_ONLY" != '' ] && echo $PKGNAME_ONLY || echo "$1"
  522. }
  523.  
  524.  
  525. get_pkg_name_only(){              # return pkg name only from $1, with no version or suffix FUNCLIST
  526.  
  527.   # exit if no valid options
  528.   [ ! "$1" ] && exit 1
  529.  
  530.   # get config settings, inc current repo file
  531.   #. ${PKGRC}
  532.  
  533.   local pkg_name=''
  534.   local pkg_name_only=''
  535.   local name_only=''
  536.   local pkg_ext=`get_pkg_ext "$1"`
  537.   local repo_of_pkg=''
  538.   local repo_pkg_with_ext=''
  539.   local repo_ext=$EX      # from $PKGRC
  540.  
  541.   # check the repos
  542.   local pkg_name_only="`grep -m1 "|${1}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|'`"
  543.   [ "$pkg_name_only" = '' ] && pkg_name_only="`grep -m1 "^${1}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|' | head -1`"
  544.   [ "$pkg_name_only" = '' ] && pkg_name_only="`grep -m1 "|${1}.${pkg_ext}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|' | head -1`"
  545.  
  546.   pkg_name_only=${pkg_name_only// */}
  547.  
  548.   # if we found it, print it and exit
  549.   if [ "$pkg_name_only" != '' ]; then
  550.       echo ${pkg_name_only}
  551.       return 0
  552.   fi
  553.  
  554.   # if not, but we have an extension, try  get_pkg_name_only_from_ext()
  555.   case $DISTRO_BINARY_COMPAT in ubuntu|trisquel|debian|devuan)
  556.     name_only=`get_pkg_name_only_from_ext "$(basename "${1}.${repo_ext}")"| head -1`
  557.     name_only=${name_only// */}
  558.     [ "$name_only" != '' -a "$name_only" != "$1" ] && echo $name_only && return 0
  559.     ;;
  560.   esac
  561.  
  562.   ## ...if we didn't find the name using the above, do the horrible checks below
  563.  
  564.   # replace the dash before the version number with an @ symbol.
  565.   # INFO: sed /-[^-][^+][^a-zA-Z][0-9.]*/ (hopefully?) replaces '-$VER' with '@'
  566.   # not including when $VER starts with a number/letter
  567.   pkg_name_only="`echo "$(basename "${1}")" | sed -e 's/-[^-][^+][^a-zA-Z][0-9.]*/@/'`"
  568.  
  569.   # do 'ioquake3+u20130504' => 'oquake3'
  570.   pkg_name_only="`echo "${pkg_name_only}" | sed -e 's/+[a-z]/@/'`"
  571.  
  572.   # note, we haven't cut away version numbers preceeded with underscores (_) yet
  573.  
  574.   # if the version number was preceeded by an underscore, the version
  575.   # will still be in the $pkg_name_only - pkgname_2.3.4 - so cut it out
  576.   if [ "`echo "$pkg_name_only" | grep -o "_[0-9]\."`" != '' ]; then
  577.     pkg_name_only="`echo "$pkg_name_only" | sed -e 's/_[^a-z][^A-Z][0-9.]*/@/'`"
  578.  
  579.   # maybe the underscore preceeds a version that starts with a letter
  580.   elif [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][0-9]\."`" != '' ]; then
  581.     pkg_name_only="`echo "$pkg_name_only" | sed -e 's/_[a-zA-Z][0-9.]*/@/'`"
  582.   fi
  583.  
  584.   # now cut away everything after the @, that will leave only the package name
  585.   pkg_name_only1="${pkg_name_only/@*/}"
  586.   pkg_name_only="$pkg_name_only1"
  587.  
  588.   # we might still have foo_bar_v1.2.3, so lets chop off * after the last _
  589.   if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][0-9]\."`" != '' ]; then
  590.     pkg_name_only="${pkg_name_only/_[a-zA-Z][0-9]*/}"
  591.   fi
  592.  
  593.   # another chop, we might have foo_bar_vv1.2.3, so lets chop off
  594.   # everything after the last underscore, if we still have version numbers
  595.   if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][a-zA-Z][0-9]\."`" != '' ]; then
  596.     pkg_name_only="${pkg_name_only/_[a-zA-Z][a-zA-Z][0-9]*/}"
  597.   fi
  598.  
  599.   # we might still have foo_bar_vvv1.2.3, so lets chop off
  600.   # everything after the last underscore, if we still have version numbers
  601.   if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z*][0-9]\."`" != '' ]; then
  602.     pkg_name_only="${pkg_name_only/_[a-zA-Z*][0-9]*/}"
  603.   fi
  604.  
  605.   # chop again, we might have abc_xwy-zzz1.2.3-blah-etc, so lets chop off
  606.   # everything after the last dash-before-number
  607.   if [ "`echo "$pkg_name_only" | grep -o "\-[a-zA-Z*]*[0-9]\."`" != '' ]; then
  608.     pkg_name_only="${pkg_name_only/-[a-zA-Z*]*[0-9]*/}"
  609.   fi
  610.  
  611.   # another fix, if we still have PKGNAME-1.2, remove the '-1.2'
  612.   if [ "`echo "$pkg_name_only" | grep -o "\-[0-9]"`" != '' ]; then
  613.     pkg_name_only="${pkg_name_only/-[0-9]*/}"
  614.   fi
  615.  
  616.   # the sed bit changes 'liblzma5+20120614' to 'liblzma5'
  617.   [ "$pkg_name_only" != '' ] && echo $pkg_name_only | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g' || return 1
  618. }
  619. check_md5sum(){
  620.     local file_path="$1"
  621.     local repo_filename="$(bname $2)"
  622.     loadl md5sums_path="$MD5_DIR/${repo_filename//Packages/PKG_SUMS}"
  623.     local fname="$(bname "$file_path")"
  624.     local fsum="$(md5sum "$file_path" | cut -f1 -d' ')"
  625.     #for aRepoFile in "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${REPO_DB_PATHS[@]}"; do
  626.     #  md5sum "$file_path"
  627.     #done
  628.     if [ -z "$(cut -f4 "$md5sums_path" | grep fsum -m1)" ]; then
  629.       return 1
  630.     else
  631.       return 0
  632.     fi
  633. }
  634.  
  635. get_pkg_name(){                   # return full pkg name (with version) from $1 FUNCLIST
  636.  
  637.   # get config settings, inc current repo file
  638.   #. ${PKGRC}
  639.  
  640.   local pkg_ext=''
  641.   local pkg_name=''
  642.   local full_name=''
  643.   local supported_repo_files=''
  644.   local repo_contents=''
  645.  
  646.   # get the extension of the given package name, if any
  647.   local pkg_ext=`get_pkg_ext "$1"`
  648.   # get the name without path and extension
  649.   local pkg_name="`basename "$1" .$pkg_ext`"
  650.  
  651.   # get the repos files in the correct (fall back) order, then add file paths
  652.  
  653.   #s243a: `repo_file_list` is called in mk_repo_file_list_arry
  654.   #supported_repo_files="`repo_file_list | sed -e "s#^#$PKGS_DIR/#g"`"
  655.  
  656.   # get the relevant repo contents (fields 1,2,8) from all repos,
  657.   # then add pipes to line start/end for easier parsing later, then do
  658.   # a basic search, for $pkg* (we'll refine it later), to avoid 'Argument list too long'..
  659.   #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
  660.   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
  661.   # get fields 1,2 and 8 (the 3 name fields) from all supported repo files, then
  662.   # add '|' to start and end of lines, then find exact match of $pkg_name..
  663.   # if no exact match, look for $pkg_name-*, then $pkg_name_*
  664.   if [ -f ${TMPDIR}/repo_contents ]; then
  665.     full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null| grep -m1 "|${pkg_name}|"` \
  666.       || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name//-*/}|"` \
  667.       || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name//_*/}|"` \
  668.       || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}-"` \
  669.       || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}_"` \
  670.       || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}"` \
  671.       || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}|"` \
  672.       || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}-"` \
  673.       || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}_"`
  674.  
  675.     rm ${TMPDIR}/repo_contents &>/dev/null
  676.   fi
  677.  
  678.   # if we found pkg in repo, keep only the package name ('|pkg-123|pkg|blah|' -> 'pkg-123')
  679.   [ "$full_name" != '' ] && full_name=`echo $full_name| cut -f2 -d '|' | tr -d '|'` || full_name=$pkg_name
  680.  
  681.   # if we have a package name, return it here and leave the func
  682.   [ "$full_name" != '' ] && echo $full_name && return 0
  683.  
  684.   # if no pkg found in repos, we cant translate/lookup its longer name,
  685.   # so just return what we got, without path, without pkg extension
  686.   [ "$full_name" = '' ] && echo "`basename "$pkg_name" .$pkg_ext`"
  687. }
  688.  
  689.  
  690. is_blacklisted_pkg(){             # return true if PKGNAME ($1) is blacklisted FUNCLIST
  691.   # exit if no valid options
  692.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-installed && exit 1
  693.  
  694.   local EX=''
  695.   local PKGNAME=''
  696.   local PKGNAME_ONLY=''
  697.  
  698.   # get pkg extension
  699.   EX=`get_pkg_ext "$1"`
  700.  
  701.   # strip away extension and path
  702.   PKGNAME="$(basename "$1" .$EX)"
  703.   #PKGNAME=`get_pkg_name "$PKGNAME"`
  704.  
  705.   # get the package name without version
  706.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  707.  
  708.   [ "`echo "$PKG_NAME_IGNORE" | grep "$PKGNAME_ONLY "`" != '' ] && echo true || echo false
  709. }
  710.  
  711.  
  712. is_installed_pkg(){               # return true if PKGNAME ($1) is installed, else false FUNCLIST
  713.  
  714.   # exit if no valid options
  715.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-installed && exit 1
  716.  
  717.   local EX=''
  718.   local PKGNAME=''
  719.   local PKGNAME_ONLY=''
  720.   local check=''
  721.  
  722.   # get pkg extension
  723.   EX=`get_pkg_ext "$1"`
  724.  
  725.   # strip away extension and path
  726.   PKGNAME="$(basename "$1" .$EX)"
  727.   PKGNAME=`get_pkg_name "$PKGNAME"`
  728.  
  729.   # we cant rely on the strings the user passes us, so...
  730.  
  731.   # get the package name without version
  732.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  733.  
  734.   # exit if no valid package name
  735.   [ "$PKGNAME" = '' -o "$PKGNAME_ONLY" = '' ] && print_usage pkg-installed && exit 1
  736.  
  737.   # check the $PKGS_DIR/*.files
  738.   check="$(find "$PACKAGE_FILE_LIST_DIR" -name "$PKGNAME.files")"
  739.   [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'_*.files')"
  740.   [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'-*.files')"
  741.   [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'*.files')"
  742.  
  743.   # slow but reliable & simple: separately check fields 1,2,8 of the various files listing installed pkgs
  744.   [ "$check" = '' ] && check="`cut -f1 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME\$"`"
  745.   [ "$check" = '' ] && check="`cut -f1,2 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME|" | grep -m1 "|$PKGNAME_ONLY\$"`"
  746.   [ "$check" = '' ] && check="`cut -f8 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME"`"
  747.   [ "$check" = '' ] && check="`HIDE_BUILTINS=false list_installed_pkgs | grep -m1 ^"$PKGNAME"`"
  748.  
  749.   # if any checks above returned a result, $check will not be empty (ash didn't like grep -q, not sure why?)
  750.   [ "$check" != '' ] && echo true || echo false
  751. }
  752.  
  753.  
  754. is_builtin_pkg (){                # return true if $1 is a builtin pkg, else false FUNCLIST
  755.  
  756.   # if $1 is an exact match of a pkg short name,
  757.   # long name or file name in woof-installed-packages,
  758.   # we will return true, else we return false
  759.  
  760.   # exit if no valid input
  761.   [ ! "$1"  ] && exit 1
  762.  
  763.   local pkg_builtin=''
  764.   local pkg_name_only=''
  765.  
  766.   pkg_builtin="`cut -f1,2,8 -d '|' "$WOOF_INST_PKGS_FILE" 2>/dev/null\
  767.    | sed -e 's@^@|@' -e 's@$@|@' \
  768.    | grep -m1 "|$1|"`"
  769.  
  770.   # try again.. if user gave only partial name (geany-1.27), the above would fail
  771.   if [ "$pkg_builtin" = '' ]; then
  772.     pkg_name_only=`get_pkg_name_only "$1"`
  773.  
  774.     # so search for pkg_name* AND pkg_name_only (exact match, should be in field 2)
  775.     if [ "$pkg_name_only" != '' ]; then
  776.       pkg_builtin="`cut -f1,2,8 -d '|' "$WOOF_INST_PKGS_FILE" 2>/dev/null\
  777.        | sed -e 's@^@|@' -e 's@$@|@' \
  778.        | grep "|$1" \
  779.        | grep -m1 "|$pkg_name_only|"`"
  780.     fi
  781.   fi
  782.  
  783.   # print result
  784.   [ "$pkg_builtin" != '' ] && echo true || echo false
  785. }
  786.  
  787.  
  788. is_devx_pkg (){                   # return true if $1 is a pkg in the devx, else false FUNCLIST
  789.  
  790.   # if $1 is an exact match of a pkg short name,
  791.   # long name or file name in devx-only-installed-packages,
  792.   # we will return true, else we return false
  793.  
  794.   # exit if no valid input
  795.   [ ! "$1"  ] && exit 1
  796.  
  797.   local devx_pkg=''
  798.   local pkg_name_only=''
  799.  
  800.   devx_pkg="`cut -f1,2,8 -d '|' "$DEVX_INST_PKGS_FILE" 2>/dev/null\
  801.    | sed -e 's@^@|@' -e 's@$@|@' \
  802.    | grep -m1 "|$1|"`"
  803.  
  804.   # try again.. if user gave only partial name (geany-1.27), the above would fail
  805.   if [ "$devx_pkg" = '' ]; then
  806.     pkg_name_only=`get_pkg_name_only "$1"`
  807.  
  808.     # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  809.     if [ "$pkg_name_only" != '' ]; then
  810.       devx_pkg="`cut -f1,2,8 -d '|' "$DEVX_INST_PKGS_FILE" 2>/dev/null\
  811.        | sed -e 's@^@|@' -e 's@$@|@' \
  812.        | grep "|$1" \
  813.        | grep -m1 "|$pkg_name_only|"`"
  814.     fi
  815.   fi
  816.  
  817.   # print result
  818.   [ "$devx_pkg" != '' ] && echo true || echo false
  819. }
  820.  
  821.  
  822. is_usr_pkg (){                    # return true if $1 is a user installed pkg, else false FUNCLIST
  823.  
  824.   # if $1 is an exact match of a pkg short name,
  825.   # long name or file name in user-installed-packages,
  826.   # we will return true, else we return false
  827.  
  828.   # exit if no valid input
  829.   [ ! "$1"  ] && exit 1
  830.  
  831.   local usr_pkg=''
  832.   local pkg_name_only=''
  833.  
  834.   usr_pkg="`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" 2>/dev/null\
  835.    | sed -e 's@^@|@' -e 's@$@|@' \
  836.    | grep -m1 "|$1|"`"
  837.  
  838.   # try again.. if user gave only partial name (geany-1.27), the above would fail
  839.   if [ "$usr_pkg" = '' ]; then
  840.     pkg_name_only=`get_pkg_name_only "$1"`
  841.  
  842.     # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  843.     if [ "$pkg_name_only" != '' ]; then
  844.       usr_pkg="`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" 2>/dev/null\
  845.        | sed -e 's@^@|@' -e 's@$@|@' \
  846.        | grep "|$1" \
  847.        | grep -m1 "|$pkg_name_only|"`"
  848.     fi
  849.   fi
  850.  
  851.   # print result
  852.   [ "$usr_pkg" != '' ] && echo true || echo false
  853. }
  854.  
  855.  
  856. is_repo_pkg (){                   # return true if $1 is a pkg in a supported repo, else false FUNCLIST
  857.  
  858.   # if $1 is an exact match of a pkg short name,
  859.   # long name or file name in Packages-*-
  860.   # we will return true, else we return false
  861.  
  862.   # exit if no valid input
  863.   [ ! "$1"  ] && exit 1
  864.  
  865.   local repo_pkg=''
  866.   local pkg_name_only=''
  867.   local all_supported_repofiles
  868.  
  869.   # all repo files, full paths
  870.   #all_supported_repofiles=`repo_file_list | sed "s#^#$PKGS_DIR/#" | tr '\n' ' '`
  871.  
  872.   #Don't need sed, but could use if you want to do wildcards
  873.   #all_supported_repofiles=`repo_file_list | sed 's#$#*#' | xargs find -name  | tr '\n' ' '`
  874.   #echo "repo_file_list | xargs find \"$PKGS_DIR\" -name  | tr '\n' ' '"
  875.   all_supported_repofiles="$(repo_file_list | while read a; do find "$REPO_DB_FILE_DIR" -name "$a"'*'; done  | tr '\n' ' ')"
  876.   # search all repo files for the $1
  877.   repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  878.    | sed -e 's/ //g' -e 's@^@|@' -e 's@$@|@' \
  879.    | grep -m1 "|${1}|"`"
  880.  
  881.   # search all repo files for the $1*
  882.   [ "$repo_pkg" = '' ] \
  883.     && repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  884.    | sed -e 's/ //g' -e 's@^@|@' -e 's@$@|@' \
  885.    | grep -m1 "|${1}-\?_\?[0-9.a-zA-Z]*|"`"
  886.  
  887.   # try again.. if user gave only partial name (geany-1.27), the above would fail
  888.   if [ "$repo_pkg" = '' ]; then
  889.     pkg_name_only=`get_pkg_name_only "$1"`
  890.  
  891.     # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  892.     if [ "$pkg_name_only" != '' ]; then
  893.       repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  894.        | sed -e 's@^@|@' -e 's@$@|@' \
  895.        | grep "|$1" \
  896.        | grep -m1 "|$pkg_name_only|"`"
  897.     fi
  898.   fi
  899.  
  900.   # print result
  901.   [ "$repo_pkg" != '' ] && echo true || echo false
  902. }
  903.  
  904.  
  905. is_current_repo_pkg(){            # takes $PKGNAME ($1), returns true or false FUNCLIST
  906.  
  907.   # exit if no valid input
  908.   [ ! "$1"  ] && exit 1
  909.  
  910.   # get current repo ($REPOFILE)
  911.   . ${PKGRC}
  912.  
  913.   local pkg_in_repo
  914.   #s243a: The repo file path
  915.   local RF_PATH="$(realpath "$(find "$REPO_DB_FILE_DIR" -name "$REPOFILE" | head -n 1 )")"
  916.  # check if given pkg ($1) is in the current repo
  917.  pkg_in_repo="`LANG=C cut -f1,2,7,8 -d'|' "$RF_PATH" 2>/dev/null | sed -e "s/^/|/" -e "s/$/|/" | grep -m1 "|${1}|"`"
  918.  
  919.  # print msg
  920.  [ "$pkg_in_repo" != '' ] && echo true || echo false
  921. }
  922.  
  923.  
  924. is_local_pkg(){                   # returns true if $1 is local package file FUNCLIST
  925.  
  926.  # exit if no valid input
  927.  [ ! "$1"  ] && exit 1
  928.  
  929.  . ${PKGRC}
  930.  
  931.  # if $1 is a local file with a supported package extension
  932.  # then we return true, else, we return false
  933.  
  934.  local is_file=''
  935.  local is_local_pkg=false
  936.  
  937.  # first, check we have a local file
  938.  if [ -f "$1" ]; then
  939.  
  940.    # file *probably* has an extension, lets try to get it..
  941.    # the func get_pkg_ext() will return empty if not a valid package extension
  942.    file_ext=`get_pkg_ext "$1"`
  943.  
  944.    # if not empty, it must be a local file, with valid pkg ext (a local pkg)
  945.    [ "$file_ext" != '' ] && is_local_pkg=true
  946.  
  947.  elif [ -f "$CURDIR/$1" ]; then
  948.  
  949.    file_ext=`get_pkg_ext "$CURDIR/$1"`
  950.    [ "$file_ext" != '' ] && is_local_pkg=true
  951.  
  952.  elif [ -f "$WORKDIR/$1" ]; then
  953.  
  954.    file_ext=`get_pkg_ext "$CURDIR/$1"`
  955.    [ "$file_ext" != '' ] && is_local_pkg=true
  956.  
  957.  fi
  958.  
  959.  # print output
  960.  echo $is_local_pkg
  961. }
  962.  
  963.  
  964.  
  965. # RC file funcs
  966.  
  967. set_workdir(){                    # set new WORKDIR in rc file location FUNCLIST
  968.  
  969.  # get latest rc file values
  970.  . ${PKGRC}
  971.  
  972.  # make sure $1 was given and doesn't already exist
  973.  [ ! "$1"  ] && print_usage workdir && exit 1
  974.  [ -e "$1" ] && echo "Error: directory already exists. Choose a new one." && exit 1
  975.  
  976.  # create the dir
  977.  mkdir -p "$1" 2>/dev/null
  978.  
  979.  # if dir not created, exit with error
  980.  [ $? -eq 1  ] && echo "Error: Could not create $1" && exit 1
  981.  [ ! -d "$1" ] && echo "Error: Could not create directory:  $1" && exit 1
  982.  
  983.  # dir was created, so lets copy our pkgs in there
  984.  list_downloaded_pkgs | while read pkg_file
  985.  do
  986.    cp -v "$WORKDIR/$pkg_name" "$1/"
  987.  done
  988.  
  989.  # if copying everything to new dir failed
  990.  if [ $? -eq 1 ]; then
  991.    # print msg
  992.    echo -e "${yellow}Warning:${endcolour}Could not copy packages from $WORKDIR to $1.."
  993.    echo "You should copy all packages in $WORKDIR into $1."
  994.  fi
  995.  
  996.  # update the RC file
  997.  WORKDIR="$1"
  998.  set_config
  999.  echo "Success. Work directory updated."
  1000.  exit 0
  1001. }
  1002.  
  1003.  
  1004. set_pkg_scope(){                  # one|all set search for pkgs in current repo or all FUNCLIST
  1005.  
  1006.  # get old values, any we dont set here are not overwritten
  1007.  . ${PKGRC}
  1008.  
  1009.  [ "$1" != "" ] && PKGSCOPE="$1" || PKGSCOPE="$PKGSCOPE"
  1010.  
  1011.  case "$1" in
  1012.    all)
  1013.    # set pkg search to all
  1014.    PKGSEARCH="list_all_pkg_names"
  1015.    PKGSEARCHEXACT="$SELF -nea"
  1016.    echo -e "${green}Success:${endcolour} Find packages in all repos."
  1017.    ;;
  1018.    one)
  1019.    # set pkg search to current only
  1020.    PKGSEARCH="list_pkg_names"
  1021.    PKGSEARCHEXACT="$SELF -ne"
  1022.    echo -e "${green}Success:${endcolour} Find packages in current repo ($REPONAME) only."
  1023.    ;;
  1024.    *)
  1025.    PKGSCOPE="one"
  1026.    # set pkg search to current only
  1027.    PKGSEARCH="list_pkg_names"
  1028.    PKGSEARCHEXACT="$SELF -ne"
  1029.    echo "Find packages in current repo ($REPONAME) only."
  1030.    ;;
  1031.  esac
  1032.  
  1033.  set_config #170213
  1034. }
  1035.  
  1036.  
  1037. set_dep_scope(){                  # all|one set search for deps in current repo or all FUNCLIST
  1038.  
  1039.   # get RC file values, so any we dont set here are not overwritten
  1040.   . ${PKGRC}
  1041.  
  1042.  # make sure we have a valid value
  1043.  [ "$1" != "" ] && DEPSCOPE="$1" || DEPSCOPE="$DEPSCOPE"
  1044.  
  1045.  case "$1" in
  1046.    all)
  1047.    # set pkg search to all
  1048.    DEPSEARCH="list_all_pkg_names"
  1049.    DEPSEARCHEXACT="$SELF -nea"
  1050.    echo -e "${green}Success:${endcolour} Find dependencies in all repos."
  1051.    ;;
  1052.    one)
  1053.    # set pkg search to one
  1054.    DEPSEARCH="list_pkg_names"
  1055.    DEPSEARCHEXACT="$SELF -ne"
  1056.    echo -e "${green}Success:${endcolour} Find dependencies in current repo ($REPONAME) only."
  1057.    ;;
  1058.  esac
  1059.  
  1060.  set_config
  1061. }
  1062.  
  1063.  
  1064. set_recursive_deps(){             # yes|no search for deps of deps or not FUNCLIST
  1065.  [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && print_usage recursive-dep-check && exit 1
  1066.  
  1067.  # get old values, any we dont set here are not overwritten
  1068.  . ${PKGRC}
  1069.  
  1070.  # make sure we have a valid value
  1071.  RDCHECK="$1"
  1072.  [ "$RDCHECK" = "yes" -o "$RDCHECK" = "no" ] || RDCHECK=no
  1073.  
  1074.  set_config
  1075.  
  1076.  # print final msg
  1077.  if [ "$1" = "yes" ]; then
  1078.    echo -e "${green}Success:${endcolour} 'Recursive dependency checking' enabled."
  1079.  else
  1080.    echo -e "${green}Success:${endcolour} 'Recursive dependency checking' disabled"
  1081.  fi
  1082. }
  1083.  
  1084.  
  1085. set_bleeding_edge(){              # yes|no get latest pkgs, ignore fall backs FUNCLIST
  1086.  [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && echo usage bleeding-edge && exit 1
  1087.  
  1088.  #get old values, any we dont set here are not overwritten
  1089.  . ${PKGRC}
  1090.  
  1091.  # make sure we have a valid value
  1092.  BLEDGE="$1"
  1093.  [ "$BLEDGE" = "yes" -o "$BLEDGE" = "no" ] || BLEDGE=no
  1094.  
  1095.  set_config
  1096.  
  1097.  # print final msg
  1098.  if [ "$1" = "yes" ]; then
  1099.    echo -e "${green}Success:${endcolour} 'Bleeding edge' package search enabled."
  1100.  else
  1101.    echo -e "${green}Success:${endcolour} 'Bleeding edge' package search disabled."
  1102.  fi
  1103. }
  1104.  
  1105.  
  1106. set_autoclean(){                  # yes|no auto delete installed packages from WORKDIR FUNCLIST
  1107.  [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && print_usage autoclean && exit 1
  1108.  
  1109.  #get old values, any we dont set here are not overwritten
  1110.  . ${PKGRC}
  1111.  
  1112.  # make sure we have a valid value
  1113.  AUTOCLEAN="$1"
  1114.  [ "$AUTOCLEAN" = "yes" -o "$AUTOCLEAN" = "no" ] || AUTOCLEAN=no
  1115.  
  1116.  set_config
  1117.  
  1118.  # print final msg
  1119.  if [ "$1" = "yes" ]; then
  1120.    echo -e "${green}Success:${endcolour} Auto-remove installed packages ENABLED."
  1121.  else
  1122.    echo -e "${green}Success:${endcolour} Auto-remove installed packages DISABLED."
  1123.  fi
  1124. }
  1125.  
  1126.  
  1127. set_config(){                     # update all options in config file FUNCLIST
  1128.  echo "WORKDIR=$WORKDIR"                    > ${PKGRC}
  1129.  echo "REPONAME=$REPONAME"                 >> ${PKGRC}
  1130.  echo "EX=$EX"                             >> ${PKGRC}
  1131.  echo "REPOFILE=$REPOFILE"                 >> ${PKGRC}
  1132.  echo "REPOURL1=$REPOURL1"                 >> ${PKGRC}
  1133.  echo "REPOURL2=$REPOURL2"                 >> ${PKGRC}
  1134.  #140213 add all urls
  1135.  echo "REPOURL3=$REPOURL3"                 >> ${PKGRC}
  1136.  echo "REPOURL4=$REPOURL4"                 >> ${PKGRC}
  1137.  # seach settings
  1138.  echo "PKGSEARCH=\"$PKGSEARCH\""           >> ${PKGRC}
  1139.  echo "PKGSEARCHEXACT=\"$PKGSEARCHEXACT\"" >> ${PKGRC}
  1140.  echo "DEPSEARCH=\"$DEPSEARCH\""           >> ${PKGRC}
  1141.  echo "DEPSEARCHEXACT=\"$DEPSEARCHEXACT\"" >> ${PKGRC}
  1142.  # multiple repo settings
  1143.  echo "REPOFALLBACKS=\"$REPOFALLBACKS\""   >> ${PKGRC}
  1144.  echo "PKGSCOPE=\"$PKGSCOPE\""             >> ${PKGRC}
  1145.  echo "DEPSCOPE=\"$DEPSCOPE\""             >> ${PKGRC}
  1146.  echo "BLEDGE=\"$BLEDGE\""                 >> ${PKGRC}
  1147.  echo "RDCHECK=\"$RDCHECK\""               >> ${PKGRC} #150813
  1148.  echo "AUTOCLEAN=\"$AUTOCLEAN\""           >> ${PKGRC}
  1149.  echo "BUILDTOOL=$BUILDTOOL"               >> ${PKGRC}
  1150. }
  1151.  
  1152.  
  1153. show_config(){                    # show config settings from ~/.pkg/pkgrc FUNCLIST
  1154.  . ${PKGRC}
  1155.  
  1156.  # set default values
  1157.  PKGSCOPETXT="Search for packages in all repos."
  1158.  DEPSCOPETXT="Search for dependencies in all repos."
  1159.  FALLBACKTXT="Accessing other repos in this order:"
  1160.  FALLBACKTXT="$FALLBACKTXT\n`repo_list | grep -v "^$REPONAME" | tr '\n' ' ' | sed -e "s/ /, /g" -e "s/, $//" | fold -w 54 -s`"
  1161.  RDCHECKTXT="Recursive dependency search is NOT enabled."
  1162.  
  1163.  # update with values from PKGRC file
  1164.  [ "$PKGSCOPE" = "one" ] && PKGSCOPETXT="Search for packages in current repo only."
  1165.  [ "$DEPSCOPE" = "one" ] && DEPSCOPETXT="Search for dependencies in current repo only."
  1166.  [ "$BLEDGE"   = "yes" ] && FALLBACKTXT="Bleeding-edge enabled - searching all repos, for the latest packages versions.."
  1167.  [ "$RDCHECK"  = "yes" ] && RDCHECKTXT="Recursive dependency search is enabled."
  1168.  
  1169.  # print current Pkg config
  1170.  echo "==========================="
  1171.  echo "$APPNAME $APPVER"
  1172.  echo "==========================="
  1173.  echo "Config file:  $PKGRC"
  1174.  echo "Packages dir: ${WORKDIR}/"
  1175.  echo "Autoclean:    $AUTOCLEAN"
  1176.  echo
  1177.  echo "Search settings:"
  1178.  #echo "- $HIDEINSTALLEDTXT"
  1179.  echo "- $PKGSCOPETXT"
  1180.  echo "- $DEPSCOPETXT"
  1181.  echo "- $RDCHECKTXT"
  1182.  echo
  1183.  echo "Package Compiling backend:"
  1184.  echo "- $BUILDTOOL"
  1185.  echo
  1186.  echo "Repo details:"
  1187.  echo "- Current Repo: $REPONAME"
  1188.  echo "- Package type: $EX"
  1189.  echo "- Packages:     $(cat "$REPO_DB_FILE_DIR/${REPOFILE}" | wc -l)"
  1190.  echo "- Mirror 1:     `echo $REPOURL1 | cut -f1-3 -d'/' `"
  1191.  [ "$REPOURL2" != "" ] && echo "- Mirror 2:     `echo $REPOURL2 | cut -f1-3 -d'/' `"
  1192.  [ "$REPOURL3" != "" ] && echo "- Mirror 3:     `echo $REPOURL3 | cut -f1-3 -d'/' `"
  1193.  [ "$REPOURL4" != "" ] && echo "- Mirror 4:     `echo $REPOURL4 | cut -f1-3 -d'/' `"
  1194.  echo
  1195.  echo -e "$FALLBACKTXT"
  1196. }
  1197.  
  1198.  
  1199. # repo and source funcs
  1200.  
  1201. get_repo_info(){                  # return details of given repo name ($1) FUNCLIST
  1202.  [ ! "$1" -o "$1" = "-" ] && print_usage repo-info && exit 1
  1203.  
  1204.  REPOLINE="`list_all_sources $1 | sort -u | uniq`" #170214 always get latest info, not info from rcfile
  1205.  
  1206.  # on first run, this might be needed to set the repo correctly
  1207.  [ "$REPOLINE" = '' ] && REPOLINE="`list_all_sources noarch`"
  1208.  
  1209.  REPONAME="`echo $REPOLINE | cut -f1 -d'|'`"
  1210.        EX="`echo $REPOLINE | cut -f2 -d'|'`"
  1211.  REPOFILE="`echo $REPOLINE | cut -f3 -d'|'`"
  1212.  REPOURL1="`echo $REPOLINE | cut -f4 -d'|'`"
  1213.  REPOURL2="`echo $REPOLINE | cut -f5 -d'|'`"
  1214.  REPOURL3="`echo $REPOLINE | cut -f6 -d'|'`"
  1215.  REPOURL4="`echo $REPOLINE | cut -f7 -d'|'`"
  1216.  REPOFALLBACKS="`echo "$REPOLINE"| cut -f8 -d'|'`"
  1217. }
  1218.  
  1219.  
  1220. set_current_repo(){               # set the current repo to use, give repo name as $1 FUNCLIST
  1221.  
  1222.  # print usage if no valid options
  1223.  [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ] && print_usage repo && exit 1
  1224.  
  1225.  # get repo details from rc file
  1226.  . ${PKGRC}
  1227.  
  1228.  # remove the default mirror tmp file, we're changing repo and mirrors
  1229.  rm $TMPDIR/CURREPOURL 2>/dev/null
  1230.  
  1231.  # remove old repo files list (used in list_source_files)
  1232.  rm -f ${TMPDIR}/source_files 2>/dev/null
  1233.  
  1234.  # if not updating the scopes or bleeding-edge,leave them as set in rcfile
  1235.  [ "$PKGSCOPE" = "" ] && PKGSCOPE="$PKGSCOPE"
  1236.  [ "$DEPSCOPE" = "" ] && DEPSCOPE="$DEPSCOPE"
  1237.  [ "$BLEDGE" = "" ]   && BLEDGE="$BLEDGE"
  1238.  
  1239.  # if nothing was found in rcfile, we need to set to default
  1240.  [ "`echo $PKGSCOPE | grep -E "^one\$|^all\$"`" = "" ] && PKGSCOPE="one"
  1241.  [ "`echo $DEPSCOPE | grep -E "^one\$|^all\$"`" = "" ] && DEPSCOPE="one"
  1242.  [ "$BLEDGE" = "" ] && BLEDGE="no"
  1243.  
  1244.  # check if $1 is valid repo
  1245.  if [ "$(LANG=C list_sources "$1")" != "" ]; then
  1246.    # set repo details
  1247.    LANG=C get_repo_info "$1"
  1248.    LANG=C set_config #170213
  1249.    LANG=C update_sources 1>/dev/null #update the order of sources to match new fallback list of new current repo
  1250.    LANG=C print_repo_info "$1" #output msg, repo info
  1251.  else
  1252.    # not a valid repo, print message
  1253.    echo "The name '$1' is not a valid repo name. These are:"
  1254.    LANG=C repo_list #250613
  1255.  fi
  1256. }
  1257.  
  1258.  
  1259. repo_list(){                      # list names of all avail repos [optionally matching $1] FUNCLIST
  1260.  
  1261.  # we need to list these repos in the order defined in the RC file
  1262.  # so Pkg can 'fall back' to other repos in that order
  1263.  
  1264.  # get current config
  1265.  . ${PKGRC}
  1266.  
  1267.  # set vars for this func
  1268.  local list=''
  1269.  local repo_file=''
  1270.  local repo_names=`cut -f1 -d'|' ${HOME}/.pkg/sources`
  1271.  local current_fallback_list=`grep "^$REPONAME|" ${HOME}/.pkg/sources | cut -f8 -d'|' | grep -v "^\$"`
  1272.  
  1273.  # get current repo fallback list order.. note if repo not listed in fallback list, it will be appended after
  1274.  for line in $current_fallback_list
  1275.  do
  1276.    # get the repo file
  1277.    repo_file="`grep "^$line|" ${HOME}/.pkg/sources | cut -f3 -d'|'`"
  1278.    # add it to the list
  1279.    [ "$repo_file" != "" ] && list="$list$line "
  1280.  done
  1281.  
  1282.  # now add all other avail repos to the end of fallback list
  1283.  for repo_name in $repo_names
  1284.  do
  1285.    #if not blank, not already in the repo list and not the current repo ($REPONAME from rc file) then add to list
  1286.    [ "$repo_name" != "" -a "`echo "$list" | grep "$repo_name "`" = ""  -a "$repo_name" != "$REPONAME" ] && list="$list$repo_name "
  1287.  done
  1288.  
  1289.  # list the current repo first
  1290.  echo $REPONAME
  1291.  # then the other repos
  1292.  echo "$list" | tr ' ' '\n' | grep -v "^\$"
  1293. }
  1294.  
  1295.  
  1296. repo_file_list(){                 # list available repo files, $1 optional FUNCLIST
  1297.  
  1298.  # we need to list these repos in the order defined in the RC file
  1299.  # so Pkg can 'fall back' to other repos in that order
  1300.  
  1301.  # get current config
  1302.  . ${PKGRC}
  1303.  
  1304.  # set vars for this func
  1305.  local list=''
  1306.  local repo_file=''
  1307.  local repo_files=`cut -f3 -d'|' ${HOME}/.pkg/sources`
  1308.  local current_fallback_list=`grep "^$REPONAME|" ${HOME}/.pkg/sources | cut -f8 -d'|' | grep -v "^\$"`
  1309.  
  1310.  # get current repo fallback list order.. note if repo not listed in fallback list, it will be appended after
  1311.  for line in $current_fallback_list
  1312.  do
  1313.    # get the repo file
  1314.    repo_file="`grep "^$line|" ${HOME}/.pkg/sources | cut -f3 -d'|'`"
  1315.    # add it to the list
  1316.    [ "$repo_file" != "" ] && list="$list$repo_file "
  1317.  done
  1318.  
  1319.  # now add all other avail repos to the end of fallback list
  1320.  for repo_file in $repo_files
  1321.  do
  1322.    #if not blank, not already in the repo list and not the current repo ($REPONAME from rc file) then add to list
  1323.    [ "$repo_file" != "" -a "`echo "$list" | grep "$repo_file "`" = ""  -a "$repo_file" != "$REPOFILE" ] && list="$list$repo_file "
  1324.  done
  1325.  
  1326.  # list the current repo first
  1327.  echo $REPOFILE
  1328.  # then the other repos
  1329.  echo "$list" | tr ' ' '\n' | grep -v "^\$"
  1330. }
  1331. declare -ga REPO_DB_PATHS
  1332. #mk_repo_file_list_arry(){
  1333.  
  1334.  #REPO_DB_PATHS=()
  1335.  #declare -A REPO_DB_PATHS
  1336.  
  1337. #Can't put the loop in the loop in a pipeline if you want to assign array values:
  1338. #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  1339. # repo_file_list |
  1340. while read REPO_FILE_NAME; do
  1341.    #echo "REPO_FILE_NAME=$REPO_FILE_NAME"
  1342.    RF_FILE_PATH="${ALL_REPO_DB_PATHS[$REPO_FILE_NAME]}"
  1343.    if [ -e "$RF_FILE_PATH" ]; then
  1344.      REPO_DB_PATHS+=( "$RF_FILE_PATH" )
  1345.    fi
  1346. done < <( repo_file_list )
  1347. #echo "REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  1348. #echo "REPO_DB_PATHS_keys=${!ALL_REPO_DB_PATHS[@]}"  
  1349. #}
  1350. #mk_repo_file_list_arry
  1351.  
  1352. dir2repo(){                       # create a native-Puppy repo from a dir of packages FUNCLIST
  1353.  
  1354.  # exit if not a valid directory
  1355.  if [ ! -d "$1" ]; then
  1356.    print_usage dir2repo && exit 1
  1357.  fi
  1358.  
  1359.  local filename=''
  1360.  local filepath=''
  1361.  local fileext=''
  1362.  local prevext=''
  1363.  local repo_name
  1364.  
  1365.  # get the repo directory
  1366.  local repo_dir="$(realpath "$1")"
  1367.  
  1368.  # create a temp repo_file name
  1369.  local repo_file="${repo_dir}/Packages-$DISTRO_BINARY_COMPAT-$DISTRO_COMPAT_VERSION"
  1370.  
  1371.  # remove any old files
  1372.  rm "${repo_dir}/install" "${repo_dir}/Packages-"* "$repo_file" &>/dev/null
  1373.  
  1374.  echo
  1375.  echo "Creating repo from contents of: $repo_dir"
  1376.  echo
  1377.  
  1378.  # exit if we encounter multiple file extensions
  1379.  for file in $(find "$repo_dir" -maxdepth 5 -type f)
  1380.  do
  1381.    filename=$(basename $file)
  1382.    fileext="$(get_pkg_ext $filename)"
  1383.    if [ "$fileext" != "$prevext" ] && [ "$prevext" != "" ]; then
  1384.      echo "All packages must have the same extension."
  1385.      echo "Extensions '$fileext' and '$prevext' don't match."
  1386.      echo "Package '$filename' needs to be converted to $prevext or removed."
  1387.      exit 1
  1388.    fi
  1389.    prevext="$fileext"
  1390.  done
  1391.  
  1392.  
  1393.  # get the packages in $repo_dir
  1394.  local package_list="$(find "$repo_dir" -maxdepth 5 -type f | grep -v ^Packages | grep -v "^install$")"
  1395.  
  1396.  if [ "$package_list" = "" ]; then
  1397.    echo "No packages found in ${repo_dir}!"
  1398.    exit 1
  1399.  fi
  1400.  
  1401.  # for each file in the repo dir
  1402.  for file in $package_list
  1403.  do
  1404.    # skip if not a recognised package type
  1405.    [ "$(is_local_pkg "$file")" != true ] && continue
  1406.  
  1407.    # get the package info
  1408.    filename=$(basename $file)
  1409.    fileext="$(get_pkg_ext $filename)"
  1410.    filepath="$(realpath $(dirname $file))"
  1411.    pathname="$(dirname ${filepath})"
  1412.    repopath="$(echo $filepath | sed -e "s#${repo_dir}##" -e "s/^\///")"
  1413.    pkgname=$(basename $filename .$fileext)
  1414.    pkgnameonly="$(get_pkg_name_only $pkgname)"
  1415.    pkgversion="$(get_pkg_version $pkgname)"
  1416.    pkgcat="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f5 -d'|')"
  1417.    pkgsize="$(du "$file" 2>/dev/null | cut -f1)K"
  1418.    [ "$pkgsize" = "" ] && pkgsize="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f6 -d'|')"
  1419.    pkgdeps="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f9 -d'|')"
  1420.    # dont include deps if we're adding a combined package + plus deps (they have $CP_SUFFIX in the name)
  1421.     [ "$(echo "$filename" | grep "$CP_SUFFIX")" != "" ] && pkgdeps=''
  1422.     pkgdesc="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f10 -d'|')"
  1423.     pkgdistro="$DISTRO_BINARY_COMPAT"
  1424.     pkgdistroversion="$DISTRO_COMPAT_VERSION"
  1425.  
  1426.     # if we don't have the required package info, dont add it to the repo file
  1427.     [ "$pkgname" = "" -o "$pkgnameonly" = "" -o "$filename" = "" ] && continue
  1428.  
  1429.     # add this package to the repo file
  1430.     echo "$pkgname|$pkgnameonly|$pkgversion||${pkgcat:-BuildingBlock}|$pkgsize|$repopath|$filename|$pkgdeps|${pkgdesc:-No description}|$pkgdistro|$pkgdistroversion|" >> "$repo_file"
  1431.   done
  1432.  
  1433.   if [ ! -f "$repo_file" ]; then
  1434.     echo "Error: file '$repo_file' not created."
  1435.     exit 1
  1436.   fi
  1437.  
  1438.   echo "Step 1 of 3: CHOOSE A REPO NAME"
  1439.   echo "(something like 'distroversion-username-repo', such as 'bionic-bob-main' or 'stretch-sc0ttman-games')"
  1440.   echo
  1441.   bash -c 'read -e -r -p "Type a repo name and hit ENTER: " repo_name; echo "$repo_name" > /tmp/pkg/repo_name'
  1442.   repo_name="$(cat /tmp/pkg/repo_name)"
  1443.  
  1444.   # rename the repo file to the new name
  1445.   mv "$repo_file"   "${repo_dir}/Packages-${DISTRO_BINARY_COMPAT:-puppy}-$repo_name"
  1446.   repo_file="${repo_dir}/Packages-${DISTRO_BINARY_COMPAT:-puppy}-$repo_name"
  1447.  
  1448.   # build repo entry
  1449.   local repo_entry="$repo_name|$fileext|$repo_file|$repo_url||||$repo_fallbacks"
  1450.  
  1451.   # get the URL where the repo file and packages will live
  1452.   echo
  1453.   echo "Step 2 of 3: ADD THE REPO URL"
  1454.   echo "(the full URL where you will upload your repo file and packages)"
  1455.   echo
  1456.   bash -c 'read -e -r -i "http://" -p "Type a repo URL and hit ENTER: " mirror1; echo "$mirror1" > /tmp/pkg/mirror1'
  1457.   mirror1="$(cat /tmp/pkg/mirror1)"
  1458.  
  1459.   # get fallback repos list
  1460.   echo
  1461.   echo "Step 3 of 3: ADD FALLBACK REPOS"
  1462.   echo "(the other repos to fall back to when looking for dependencies)"
  1463.   echo
  1464.   bash -c 'read  -e -r -i "noarch common32" -p "List fallback repos (separated by a space) and hit ENTER: " fallback_repos; echo "$fallback_repos" > /tmp/pkg/fallback_repos'
  1465.   fallback_repos="$(cat /tmp/pkg/fallback_repos)"
  1466.  
  1467.   # remove the tmp files which store user input, they're no longer needed
  1468.   rm /tmp/pkg/repo_name /tmp/pkg/mirror1 /tmp/pkg/fallback_repos
  1469.  
  1470.   # add a trailing slash to the URL
  1471.   if [ "$(echo "${mirror1}" | grep "/$")" = "" ]; then
  1472.     mirror1="${mirror1}/"
  1473.   fi
  1474.  
  1475.   # create repo installer file in $repo_dir
  1476.   echo "REPONAME=$repo_name
  1477. EX=$fileext
  1478. REPOFILE=$(basename $repo_file)
  1479. URL1=${mirror1}
  1480. URL2=''
  1481. URL3=''
  1482. URL4=''
  1483. FALLBACKS='$fallback_repos'" > "${repo_dir}/install"
  1484.  
  1485.   # print final message
  1486.   echo
  1487.   echo -e "${green}Success${endcolour}: Repo ${yellow}$repo_name${endcolour} created."
  1488.   echo
  1489.   echo -e "You should upload everything in ${lightblue}$repo_dir${endcolour} to:"
  1490.   echo
  1491.   echo "  $mirror1"
  1492.   echo
  1493.   echo "You (and anyone else) can then install the repo using:"
  1494.   echo
  1495.   echo "  pkg add-repo ${mirror1}"
  1496.   echo
  1497.   echo -e "NOTE: You can edit the ${yellow}install${endcolour} and ${yellow}$(basename $repo_file)${endcolour}"
  1498.   echo "files in a text editor, before you upload your new repo."
  1499.   echo
  1500. }
  1501.  
  1502. check_https_cert(){
  1503.   if [ "$HTTPS_CHECK" = 'none' ] || [ -z "$HTTPS_CHECK" ]; then
  1504.     echo --no-check-certificate
  1505.   elif [ ! "$HTTPS_CHECK" = all ]; then
  1506.     local repo_name="$1"
  1507.     local repo_file_url="$2"
  1508.     local check_cert=-1
  1509.     #TODO add further certificate checking logic here.
  1510.     #TODO: First check for a config file
  1511.     #Then use hardcoded defaults:
  1512.     if [ $check_cert -eq -1 ]; then
  1513.       case "$repo_file_url" in
  1514.       https://*tor*)
  1515.         check_cert=1
  1516.       https://*nodesource*)
  1517.         check_cert=1
  1518.       *)
  1519.         check_cert=0 #TODO: have some config variable for the default checkcert value
  1520.       esac
  1521.     fi
  1522.     if [ check_cert -eq 0 ]; then
  1523.       echo --no-check-certificate
  1524.     fi
  1525.   fi
  1526.    
  1527. }
  1528. add_pkg_repo() {                  # add a Pkg-created repo, called by add_repo() FUNCLIST
  1529.   [ ! "$1" ] && return 1
  1530.   mkdir -p /tmp/pkg/
  1531.   # this is probably a Pkg created Puppy repo, get info from 'install' file
  1532.   rm /tmp/pkg/repo_info &>/dev/null
  1533.  
  1534.   # check if the 'install' file we need exists
  1535.   wget --no-check-certificate -O "/tmp/pkg/repo_info" -4 "$1" &>/dev/null
  1536.   if [ ! -f /tmp/pkg/repo_info ]; then
  1537.     echo "Error: Repo installer file not downloaded!"
  1538.     return 1
  1539.   elif [ "$(grep -m1 "^REPONAME" /tmp/pkg/repo_info 2>/dev/null)" = "" ]; then
  1540.     echo "Error: invalid repo installer file"
  1541.     return 1
  1542.   fi
  1543.  
  1544.   # build a valid repo entry for the ~/.pkg/sources* files
  1545.   # (must have some fallbacks, strip quotes, newlines, no trailing pipes)
  1546.   local repo_entry="$(cat /tmp/pkg/repo_info \
  1547.    | sed -e "s/FALLBACKS=''/FALLBACKS='noarch common32'/" -e 's/.*=//g' \
  1548.    | tr -d '"' \
  1549.    | tr -d "'" \
  1550.    | tr '\n' '|' \
  1551.    | head -c -1)"
  1552.  
  1553.   if [ "$repo_entry" = "" ]; then
  1554.     echo "Error: repo entry not created."
  1555.     return 1
  1556.   fi
  1557.  
  1558.   # get repo info
  1559.   local repo_name="$(echo "$repo_entry" | cut -f1 -d'|')"
  1560.   local repo_filename="$(echo "$repo_entry" | cut -f3 -d'|')"
  1561.   local repo_file_url="$(echo ${1} | sed 's#/install$##')/${repo_filename}"
  1562.   local repo_check_cert=$(check_https_cert "$repo_name" "$repo_file_url")
  1563.   # download the repo file
  1564.  
  1565.   wget $repo_check_cert -O "/tmp/pkg/$repo_filename" -4 "$repo_file_url" &>/dev/null
  1566.   if [ -z /tmp/pkg/$repo_filename ] || [ ! -f /tmp/pkg/$repo_filename ]; then
  1567.     echo "Error: Repo file $repo_filename not downloaded!"
  1568.     return 1
  1569.   fi
  1570.  
  1571.   # install the repo file
  1572.   mv /tmp/pkg/$repo_filename "$REPO_DB_FILE_DIR/$repo_filename"
  1573.   RETVAL=$?
  1574.  
  1575.   # add repo entry to ~/.pkg/sources
  1576.   echo
  1577.   add_source "${repo_entry}"
  1578.   echo
  1579.  
  1580.   # refresh list of available repos
  1581.   update_sources
  1582.   echo
  1583.   echo "Repo info:"
  1584.   print_repo_info $repo_name
  1585.   echo
  1586.  
  1587.   if [ "$(cat ~/.pkg/sources 2>/dev/null | grep -m1 "^$repo_name|")" != "" ]; then
  1588.     echo "Success! Repo added and available to use."
  1589.     echo
  1590.     echo "To use this repo, simply type the following and hit ENTER:"
  1591.     echo "  pkg repo $repo_name"
  1592.     echo
  1593.  
  1594.     # register as a user installed repo, so we can remove it later (using rm_repo)
  1595.     touch ~/.pkg/sources-user
  1596.     echo "$repo_entry" >> ~/.pkg/sources-user
  1597.     local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1598.     echo "$user_repos" > ~/.pkg/sources-user
  1599.  
  1600.   fi
  1601.  
  1602.   return $RETVAL
  1603. }
  1604.  
  1605.  
  1606. add_repo(){                       # add Pkg/Ubuntu/Debian/Slackware third-party repos FUNCLIST
  1607.  
  1608.   local slack_repo_url
  1609.  
  1610.   if [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ]; then
  1611.     print_usage add_repo && exit 1
  1612.   fi
  1613.  
  1614.   # work out which kind of repo we are processing
  1615.   case "$1" in
  1616.     'http'*'/PACKAGES.TXT.gz'|'http'*'/PACKAGES.TXT')
  1617.       # strip trailing /PACKAGES.TXT[.gz]
  1618.       slack_repo_url="${1//PACKAGES.TXT.gz/}"
  1619.       slack_repo_url="${slack_repo_url//\/.gz/}"
  1620.       slack_repo_url="${slack_repo_url//.gz\//}"
  1621.       slack_repo_url="${slack_repo_url//PACKAGES.TXT/}"
  1622.       # add trailing slash, if needed
  1623.       if [ "$(echo $slack_repo_url | grep '/$')" = '' ]; then
  1624.         slack_repo_url="${slack_repo_url}/"
  1625.       fi
  1626.       slack2pup "$@"
  1627.       retval=$?
  1628.       if [ $retval -eq 0 ]; then
  1629.         # register repo, so we know to update it in update_sources()
  1630.         touch ~/.pkg/sources-user
  1631.         echo "$repo_entry" >> ~/.pkg/sources-user
  1632.         local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1633.         echo "$user_repos" > ~/.pkg/sources-user
  1634.  
  1635.         # register in a slack supported file too
  1636.         mkdir -p /etc/slackpkg/
  1637.         touch /etc/slackpkg/mirrors
  1638.         echo "$slack_repo_url" >> /etc/slackpkg/mirrors
  1639.         local slack_repos="$(sort -u /etc/slackpkg/mirrors | uniq)"
  1640.         echo "$slack_repos" > /etc/slackpkg/mirrors
  1641.       fi
  1642.       ;;
  1643.  
  1644.     'http'*'/install')
  1645.       add_pkg_repo "$1"
  1646.       ;;
  1647.  
  1648.     'ppa:'*|'http://'*|'https://'*)
  1649.       wget --quiet --timeout=2 --no-parent --spider "${1}install"
  1650.       REPLY=$?
  1651.       if [ "$REPLY" = 0 ]; then
  1652.         add_pkg_repo "${1}install"
  1653.         exit $?
  1654.       fi
  1655.  
  1656.       ppa2pup "$@"
  1657.       retval=$?
  1658.       if [ $retval -eq 0 ]; then
  1659.         # register repo, so we know to update it in update_sources()
  1660.         touch ~/.pkg/sources-user
  1661.         echo "$repo_entry" >> ~/.pkg/sources-user
  1662.         local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1663.         echo "$user_repos" > ~/.pkg/sources-user
  1664.  
  1665.         # register in an apt-supported file too
  1666.         mkdir -p /etc/apt/
  1667.         touch /etc/apt/sources.list
  1668.         echo "deb $@" >> /etc/apt/sources.list
  1669.         local deb_repos="$(sort -u /etc/apt/sources.list | uniq)"
  1670.         echo "$deb_repos" > /etc/apt/sources.list
  1671.       fi
  1672.       ;;
  1673.  
  1674.     *)
  1675.       print_usage add_repo && exit 1
  1676.       ;;
  1677.  
  1678.   esac
  1679.  
  1680. }
  1681.  
  1682.  
  1683. rm_repo(){                        # remove an installed repo by name ($1) FUNCLIST
  1684.   if [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ]; then
  1685.     print_usage rm_repo
  1686.     exit 1
  1687.   fi
  1688.  
  1689.   # $1 must be a valid, installed repo name
  1690.   if [ "$(repo_list | grep -m1 "^${1}$")" = "" ]; then
  1691.     print_usage rm-repo
  1692.     exit 1
  1693.   fi
  1694.  
  1695.   # get the repo file and URL of the given repo
  1696.   local repo_file="$(grep "^$1" ~/.pkg/sources-all | cut -f3 -d'|' )"
  1697.   local repo_url="$(grep "^$1" ~/.pkg/sources-all | cut -f4 -d'|')"
  1698.  
  1699.   # dont allow removal of 'built in' repos, only user-added repos
  1700.   local matching_user_added_repos="$(grep -m1 -E "\|$repo_name\||$repo_url|${repo_name//*-/}" ~/.pkg/sources-user /etc/apt/sources.list /etc/slackpkg/mirrors 2>/dev/null)"
  1701.   if [ "${matching_user_added_repos}" = "" ]; then
  1702.     echo "You can only remove the repositories that you installed yourself."
  1703.     echo -e "Use the command  ${bold}pkg repo-list${endcolour}  to see which repos are installed."
  1704.     exit 1
  1705.   fi
  1706.  
  1707.   # dont allow removal of current repo
  1708.   if [ "$REPONAME" = "$1" ]; then
  1709.     echo "Can't remove current repo."
  1710.     echo -e "Switch to another repo first using:  ${bold}pkg repo REPONAME${endcolour}"
  1711.     exit 1
  1712.   fi
  1713.  
  1714.   # remove the repo file
  1715.   echo "Removing '$1'.. Please wait.."
  1716.   [ -f "$REPO_DB_FILE_DIR/$repo_file" ] && rm "$REPO_DB_FILE_DIR/$repo_file"
  1717.  
  1718.   # remove from sources
  1719.   grep -v "^$1|" ~/.pkg/sources > /tmp/pkg/sources
  1720.   grep -v "^$1|" ~/.pkg/sources-all > /tmp/pkg/sources-all
  1721.   [ -f /tmp/pkg/sources-all ] && mv /tmp/pkg/sources-all ~/.pkg/sources-all
  1722.   [ -f /tmp/pkg/sources     ] && mv /tmp/pkg/sources ~/.pkg/sources
  1723.  
  1724.   # remove from third-party lists
  1725.   grep -v  "|${repo_url}|"  ~/.pkg/sources-user > /tmp/pkg/sources-user
  1726.   grep -vE "$repo_url|${repo_name//*-/}" /etc/apt/sources.list > /tmp/pkg/sources.list
  1727.   grep -v  "$repo_url" /etc/slackpkg/mirrors > /tmp/pkg/mirrors
  1728.   [ -f /tmp/pkg/sources-user ] && mv /tmp/pkg/sources-user ~/.pkg/sources-user
  1729.   [ -f /tmp/pkg/sources.list ] && mv /tmp/pkg/sources.list /etc/apt/sources.list
  1730.   [ -f /tmp/pkg/mirrors ] && mv /tmp/pkg/mirrors /etc/slackpkg/mirrors
  1731.  
  1732.   if [ "$(repo_list | grep -m1 "^${1}$")" = "" ]; then
  1733.     update_sources &>/dev/null
  1734.     echo -e "${green}Success${endcolour}: Repo removed."
  1735.   fi
  1736.  
  1737. }
  1738.  
  1739.  
  1740. add_source(){                     # add a new repo to your repo 'sources' list FUNCLIST
  1741.   [ ! "$1" \
  1742.     -o "$1" = "-" \
  1743.     -o "$1" = "-h" \
  1744.     -o "$1" = "--help" \
  1745.     -o "`echo "$1" |  grep '|'`" = "" \
  1746.     -o "`echo "$1" | cut -f2 -d'|'`" = "" \
  1747.     -o "`echo "$1" | cut -f4 -d'|'`" = "" \
  1748.     -o "`echo "$1" | cut -f8 -d'|'`" = "" ] && \
  1749.     print_usage add_source && exit 1
  1750.  
  1751.   # get repo file to add to sources
  1752.   REPOTOADD="`echo $1 | cut -f1 -d'|'`"
  1753.   REPOFILETOADD="`echo $1 | cut -f3 -d'|'`"
  1754.  
  1755.   # do checks before adding repo (dont add duplicate, make sure file exists, etc)
  1756.  
  1757.   # check if repo name already in sources-all
  1758.   #if [ "`grep "^$REPOTOADD\$" ~/.pkg/sources-all`" != "" ] || \
  1759.   #   [ "`repo_list | grep "^$REPOTOADD\$"`" != "" ]; then
  1760.   #  echo "Repo with the name '$REPOTOADD' already in the list"
  1761.   #fi
  1762.  
  1763.   # check if repo filename already  exists in sources-all
  1764.   #if [ "`repo_file_list | grep -m1 "^$REPOFILETOADD\$"`" != "" ]; then
  1765.   #  echo "Repo with database file $PKGS_DIR/'$REPOFILETOADD' already in the list"
  1766.   #fi
  1767.  
  1768.   # check if the repo file exists in $PKGS_DIR
  1769.   #if [ ! -f "`find $PKGS_DIR/ -name "$REPOFILETOADD"`" ]; then
  1770.   #  echo "The repo database file '$PKGS_DIR/$REPOFILETOADD' not found."
  1771.   #fi
  1772.  
  1773.   # add the repo to sources-all, if not already there
  1774.   if [ "$(grep -m1 "^$REPOTOADD|" ${HOME}/.pkg/sources-all)" = "" ]; then
  1775.     # all good, so add repo entry to sources-all
  1776.     echo "$1" >> ${HOME}/.pkg/sources-all
  1777.   fi
  1778.  
  1779.   # update users repo sources to get the new repo
  1780.   update_sources 1>/dev/null || { echo "Could not update repo sources."; exit 2; }
  1781.  
  1782.   # print msg
  1783.   echo "Repo '$REPOTOADD' added successfully."
  1784. }
  1785.  
  1786.  
  1787. update_sources(){                 # create the list of available repos FUNCLIST
  1788.  
  1789.   # get current repo values and Pkg settings
  1790.   . ${PKGRC}
  1791.  
  1792.   #list current repo first in sources
  1793.   get_repo_info "${REPONAME:-noarch}"
  1794.  
  1795.  
  1796.   # only add the current repo to the list of available sources if it exists
  1797.   if [ "$(find "$REPO_DB_FILE_DIR" -iname "$REPOFILE" )" != '' ]; then
  1798.     echo "$REPONAME|$EX|$REPOFILE|$REPOURL1|$REPOURL2|$REPOURL3|$REPOURL4|$REPOFALLBACKS" > ${HOME}/.pkg/sources
  1799.   #elif [ "$(find "$(realpath "/var/packages/")" -iname "$REPOFILE" )" != '' ]; then
  1800.   #  echo "$REPONAME|$EX|$REPOFILE|$REPOURL1|$REPOURL2|$REPOURL3|$REPOURL4|$REPOFALLBACKS" > ${HOME}/.pkg/sources
  1801.   fi
  1802.  
  1803.  
  1804.   # get repos in order of fallbacks, pkg will then 'fall back' to each repo in that order
  1805.   FALLBACKS="`grep -m1 "^${REPONAME}|" ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#' | cut -f8 -d'|'`"
  1806.  
  1807.   # for each repo in fallback list
  1808.   for FBACK in $REPOFALLBACKS; do
  1809.     # dont add current repo, its already added
  1810.     [ "$FBACK" = "$REPONAME" ] && continue
  1811.  
  1812.     # check if repo is supported (has entries in sources-all)
  1813.     LINE="`grep -m1 "^$FBACK|" ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#' | grep -v "^${REPONAME}|"`"
  1814.     [ "$LINE" = "" ] && continue
  1815.  
  1816.     # if repo is valid, add to users list of in-use repos (only valid repos from sources-all => sources)
  1817.     if [ -f "$REPO_DB_FILE_DIR/`echo "$LINE" | cut -f3 -d'|'`" ]; then
  1818.  
  1819.       if [ "$(grep -m1 "^$FBACK|" ${HOME}/.pkg/sources)" = "" ]; then
  1820.         echo "Adding repo: `echo "$LINE"|cut -f1 -d'|'`.."
  1821.         echo "$LINE" >> ${HOME}/.pkg/sources
  1822.       fi
  1823.     fi
  1824.   done
  1825.  
  1826.   cleaned_repo_list="`cat ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#'| grep -v ^$`"
  1827.  
  1828.   # now add any other repos to the list (repos that are installed, but not added from fallback list)
  1829.   echo "$cleaned_repo_list" | uniq | while read repo_entry
  1830.   do
  1831.     # dont add current repo, its already added
  1832.     [ "`echo "$repo_entry" | cut -f1 -d'|'`" = "$REPONAME" ] && echo "Adding repo: $REPONAME.." && continue
  1833.  
  1834.     # get the repo name
  1835.     repo_name="`echo "$repo_entry"|cut -f1 -d'|'`"
  1836.  
  1837.     # build the repo file (full path)
  1838.     repo_file="$REPO_DB_FILE_DIR"/`echo "$repo_entry" | cut -f3 -d'|'`
  1839.  
  1840.     # set a flag true if repo already in repo, false if not
  1841.     already_in_repo=false
  1842.     [ "`grep -m1 "^$repo_entry" ${HOME}/.pkg/sources 2>/dev/null`" != "" ] && already_in_repo=true
  1843.  
  1844.     if [ -f "$repo_file" -a "$already_in_repo" = false ]; then
  1845.       echo "Adding repo: $repo_name.."
  1846.       echo "$repo_entry" >> ${HOME}/.pkg/sources
  1847.     fi
  1848.   done
  1849.  
  1850.   # finished, print message
  1851.   [ -f ${HOME}/.pkg/sources ] && echo "Sources updated." && . ${PKGRC}
  1852. }
  1853.  
  1854.  
  1855. update_repo(){                    # update the current repo from a file stored online FUNCLIST
  1856.  
  1857.   # check internet, net connection required
  1858.   NET="`check_net`"; [ $NET -eq 1 ] && echo "You need an internet connection" && exit 1
  1859.  
  1860.   # remove the repo update tmp file
  1861.   rm -f $TMPDIR/update_repo_results 2>/dev/null
  1862.  
  1863.   echo "Updating system repositories, please wait.."
  1864.   echo
  1865.  
  1866.   # use petget for now .. not ideal, petget wont accept $1 and only do that repo,
  1867.   # also petget uses loads of other files pkg doesnt have/need (in $PKGS_DIR)
  1868.   # also, we're limited to updating only the repos that petget supports, not all the ones Pkg supports..
  1869.   # .. on the plus side petget code is way faster than mine
  1870.   mkdir -p /var/local/petget/
  1871.   chmod 777 /var/local/petget/
  1872.   echo 'false' > /var/local/petget/db_verbose
  1873.  
  1874.   # now call petget 0setup.. the ENV options prevent popup windows, and need for user input
  1875.   #DISPLAY='' SETUPCALLEDFROM=ppm /usr/local/petget/0setup &>$TMPDIR/update_repo_results
  1876.  
  1877.   # if the repos updated ok
  1878.   if [ $? -eq 0 ]; then
  1879.     [ "`which logger`" != '' ] && logger "$0 Repo files updated by $APP $APPVER"
  1880.     echo -e "Repo files updated:"
  1881.     grep ^Processing $TMPDIR/update_repo_results | cut -f2 -d' '
  1882.     # remove the repo update tmp file
  1883.     rm -f $TMPDIR/update_repo_results 2>/dev/null
  1884.   else
  1885.     # repo did not update ok
  1886.     error "Repos NOT updated."
  1887.     cat $TMPDIR/update_repo_results | tail -20
  1888.     exit 2
  1889.   fi
  1890.  
  1891.   # update Pkg created, user-added (third-party) repos
  1892.   if [ -f ~/.pkg/sources-user ] || [ -f /etc/apt/sources.list ] || [ -f /etc/slackpkg/mirrors ]; then
  1893.     echo
  1894.     echo "Updating third-party repos.. This may take a while.."
  1895.     echo
  1896.   fi
  1897.  
  1898.   # update Pkg created repos
  1899.   if [ -f ~/.pkg/sources-user ]; then
  1900.     pkg_repos="$(sort -u ~/.pkg/sources-user | grep -v ^$ | uniq | cut -f1 -d'|')"
  1901.     for pkg_repo in $pkg_repos
  1902.     do
  1903.       local pkg_repo_url="$(cat ~/.pkg/sources-user | grep -m1 "^$pkg_repo|" | cut -f4 -d'|')"
  1904.       echo "Processing:  $pkg_repo_url"
  1905.  
  1906.       ANSWER=y
  1907.       if [ "$ASK" = true ]; then
  1908.         bash -c 'read -r -N 1 -p "Update repo $pkg_repo? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1909.         echo
  1910.         ANSWER="$(cat /tmp/pkg/ANSWER)"
  1911.       fi
  1912.  
  1913.       if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ]; then
  1914.         echo "Please wait..."
  1915.         add_pkg_repo ${pkg_repo_url}install 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$pkg_repo'"
  1916.       fi
  1917.     done
  1918.   fi
  1919.  
  1920.   # update third-party non-native repos.. These repos comes 'from source',
  1921.   # and are not in native Puppy format - they need to be downloaded, converted
  1922.   # into the Puppy format, then installed... so this will be slow..
  1923.   if [ -f /etc/apt/sources.list ] || [ -f /etc/slackpkg/mirrors ]; then
  1924.  
  1925.     # update third-party Ubuntu/Debian repos
  1926.     # search inside /etc/apt/sources.list /etc/apt/sources.list.d/*.list
  1927.     # ...look for lines starting with 'deb ', ignore others
  1928.     # ...(use grep -h, to remove the preppended filenames if grepping multiple files)
  1929.     # ...remove any arch stuff from the entries, ppa2pup will handle that,
  1930.     # ...convert spaces to | chars, so we can process each line as a whole later
  1931.     local apt_sources_list="$(grep -h '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null \
  1932.      | sed \
  1933.        -e "s/^deb //g" \
  1934.        -e "s/^tor+//g" \
  1935.        -e 's/\[arch=[a-z,0-9].*\] //g' \
  1936.        -e 's/ /|/g'\
  1937.    )"
  1938.  
  1939.     # for each repo in $apt_sources_list, use `ppa2pup` to update the repo
  1940.     for line in $apt_sources_list
  1941.     do
  1942.       [ "$line" = "" ] && continue
  1943.       [ "$line" = "\n" ] && continue
  1944.  
  1945.       local ppa_repo_url="$(echo ${line//|/ } | cut -f1 -d" ")"
  1946.       local ppa_repo_name=$(cat ~/.pkg/sources-all | grep -m1 $ppa_repo_url | cut -f1 -d'|')
  1947.  
  1948.       # if a PPA repo, get a user-friendly repo name from the /etc/sources.list entry
  1949.       if [ "$ppa_repo_name" = "" ]; then
  1950.         ppa_repo_name="$(echo ${line} | cut -f3 -d'|')-$(echo $line | cut -f2 -d':' | cut -f1 -d '/' | tr -d '-' | tr -d '_')"
  1951.       fi
  1952.  
  1953.       echo
  1954.       echo "Processing:  ${line//|/ }"
  1955.  
  1956.       ANSWER=y
  1957.       if [ "$ASK" = true ]; then
  1958.         # ask user to update repo
  1959.         bash -c 'read -r -N 1 -p "Update repo $ppa_repo_name? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1960.         echo
  1961.         ANSWER="$(cat /tmp/pkg/ANSWER)"
  1962.       fi
  1963.  
  1964.       if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ]; then
  1965.         echo "Please wait..."
  1966.         ppa2pup ${line//|/ } 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$ppa_repo_name'"
  1967.         retval=$?
  1968.       fi
  1969.     done
  1970.  
  1971.     # update third-party Slackware repos
  1972.     if [ -f /etc/slackpkg/mirrors ]; then
  1973.       local slack_repos="$(sort -u /etc/slackpkg/mirrors | uniq)"
  1974.       local slack_repo_url=""
  1975.  
  1976.       for slack_repo in $slack_repos
  1977.       do
  1978.         slack_repo_url="${slack_repo//PACKAGES.TXT.gz/}"
  1979.         slack_repo_url="${slack_repo_url//\/.gz/}"
  1980.         slack_repo_url="${slack_repo_url//.gz\//}"
  1981.         slack_repo_url="${slack_repo_url//PACKAGES.TXT/}"
  1982.  
  1983.         # add trailing slash, if needed
  1984.         if [ "$(echo $slack_repo_url | grep '/$')" = '' ]; then
  1985.           slack_repo_url="${slack_repo_url}/"
  1986.         fi
  1987.  
  1988.         local slack_repo_name=$(cat ~/.pkg/sources-all | grep -m1 $slack_repo_url | cut -f1 -d'|')
  1989.  
  1990.         echo
  1991.         echo "Processing:  $slack_repo_url"
  1992.  
  1993.         ANSWER=y
  1994.         if [ "$ASK" = true ]; then
  1995.           # ask user to update repo
  1996.           bash -c 'read -r -N 1 -p "Update repo '"$slack_repo_name"'? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1997.           echo
  1998.           ANSWER="$(cat /tmp/pkg/ANSWER)"
  1999.         fi
  2000.  
  2001.         if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ]; then
  2002.           echo "Please wait..."
  2003.           slack2pup "${slack_repo_url}/PACKAGES.TXT" $slack_repo_name 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$slack_repo_name'"
  2004.         fi
  2005.       done
  2006.     fi
  2007.   fi
  2008.  
  2009.   echo
  2010.   exit 0
  2011.  
  2012. }
  2013.  
  2014.  
  2015. list_sources(){                   # return available (matching) repos (~/.pkg/sources) FUNCLIST
  2016.   grep -m1 "^$1" ${HOME}/.pkg/sources ${HOME}/.pkg/sources-user | cut -f2-99 -d':' | uniq
  2017. }
  2018.  
  2019.  
  2020. list_all_sources(){               # return all (or matching) repos (~/.pkg/sources-all) FUNCLIST
  2021.   grep -m1 "^$1" ${HOME}/.pkg/sources-all ${HOME}/.pkg/sources-user | cut -f2-99 -d':' | uniq
  2022. }
  2023.  
  2024.  
  2025. convert_repofile(){               # convert repo files formats (pre-woof/post-woof) FUNCLIST
  2026.  
  2027.   # get the file name (FILENAME) and full path (FILE)
  2028.   FILENAME="`basename "$1"`"
  2029.   FILE="${CURDIR}/${FILENAME}"
  2030.  
  2031.   # check for valid options
  2032.   [ ! -f "$FILE" ] && print_usage repo-convert && exit 1
  2033.  
  2034.   # dont replace repo unless -f was given
  2035.   [ "$FORCE" != true -a -f "$REPO_DB_FILE_DIR/${FILENAME}" ] && echo "File '$REPO_DB_FILE_DIR/$FILENAME' already exists."  && exit 1
  2036.  
  2037.   # remove tmp files
  2038.   rm $TMPDIR/$FILENAME &>/dev/null
  2039.   rm $TMPDIR/${FILENAME}_subdirs &>/dev/null
  2040.  
  2041.   # check repo file format (woof or pre-woof)
  2042.   if [ -f "$FILE" -a "`cat "$FILE" | head -1 | grep -m1 '^"'`" = "" ]; then #if is a new format  #'
  2043.  
  2044.     # convert woof repo file to pre-woof repo file.. takes ages..
  2045.     echo "Converting '${FILE}' to pre-woof format.. This might take a while.."
  2046.     cat "$FILE" | while read LINE
  2047.     do
  2048.       PKGNAME="`echo $LINE| cut -f1 -d'|'`"
  2049.       PKGNAME1=''
  2050.       # we need to get the package name, try lots of different extensions
  2051.       [ "`echo $PKGNAME1 | grep ".deb\$"`" != "" ]  && PKGNAME1="`echo $LINE| cut -f8 -d'|'`"
  2052.       [ "`echo $PKGNAME1 | grep ".deb\$"`" != "" ]  && PKGNAME="`basename $PKGNAME1 .deb`"
  2053.       [ "`echo $PKGNAME1 | grep ".rpm\$"`" != "" ]  && PKGNAME="`basename $PKGNAME1 .rpm`"
  2054.       [ "`echo $PKGNAME1 | grep ".txz\$"`" != "" ]  && PKGNAME="`basename $PKGNAME1 .txz`"
  2055.       [ "`echo $PKGNAME1 | grep ".tgz\$"`" != "" ]  && PKGNAME="`basename $PKGNAME1 .tgz`"
  2056.       [ "`echo $PKGNAME1 | grep ".tar.xz\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .tar.xz`"
  2057.       [ "`echo $PKGNAME1 | grep ".tar.gz\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .tar.gz`"
  2058.       # get size
  2059.       SIZE=" `echo $LINE| cut -f6 -d'|'`"
  2060.       # get category
  2061.       CAT="`echo $LINE| cut -f5 -d'|'`"
  2062.       #150813 remove extra categories .. example 'Setup;Installation' .. remove 'Installation'
  2063.       [ "`echo "$CAT" | grep ';'`" != "" ] && CAT="`echo "$CAT" | cut -f1 -d';'`"
  2064.       # get sub dir in repo
  2065.       SUBDIR="`echo $LINE| cut -f7 -d'|'`" #150213
  2066.       # get deps
  2067.       DEPS=" `echo $LINE| cut -f9 -d'|'| grep '+'`"
  2068.       # get desc
  2069.       DESC="`echo $LINE| cut -f10 -d'|'`"
  2070.       # add repo entry to tmp file
  2071.       [ "$PKGNAME" != "" ] && echo "\"$PKGNAME\" \"$PKGNAME: ${DESC//:/,}\" off \"$CAT$DEPS$SIZE\" /" | sed -e 's/  / /g' -e 's/,,/,/g' -e 's/, ,/,/g' | sort --field-separator='-' -k1,1d -k2gr -k3gr -k4gr | uniq >> $TMPDIR/$FILENAME
  2072.       #150213 now do subdirs... slow..
  2073.       [ "`echo $SUBDIR | grep "/"`" != "" -a "`echo $SUBDIR | grep -i pet_packages`" = "" ] && echo "$PKGNAME|/$SUBDIR" >> $TMPDIR/${FILENAME}_subdirs
  2074.     done
  2075.     # done making a pre-woof repo file, print message
  2076.     [ -f $TMPDIR/$FILENAME ] && echo "Finished converting $FILENAME to pre-woof format." || exit 1
  2077.  
  2078.   else
  2079.  
  2080.     # convert pre-woof repo file to woof repo file.. takes ages..
  2081.     echo "Converting '$FILENAME' to a 'woof' compatible repo file. This could take a while..."
  2082.  
  2083.     # parse a pre-woof repo file
  2084.     cat "$FILE" | while read LINE
  2085.     do
  2086.       PKGNAME='' PKGNAMEONLY='' PKGVER='' SIZE='' CAT='' DEPS='' BUILD='' SUBDIR='' PKGEXT='.pet' DESC=''
  2087.  
  2088.       PKGNAME="`echo "$LINE" | cut -d'"' -f2`" #'micro
  2089.       [ "`echo $PKGNAME | grep ".deb\$"`" != "" ]     && PKGEXT='.deb'    && PKGNAME="`basename $PKGNAME1 .deb`"
  2090.       [ "`echo $PKGNAME | grep ".pet\$"`" != "" ]     && PKGEXT='.pet'    && PKGNAME="`basename $PKGNAME1 .pet`"
  2091.       [ "`echo $PKGNAME | grep ".rpm\$"`" != "" ]     && PKGEXT='.rpm'    && PKGNAME="`basename $PKGNAME1 .rpm`"
  2092.       [ "`echo $PKGNAME | grep ".tcz\$"`" != "" ]     && PKGEXT='.tcz'    && PKGNAME="`basename $PKGNAME1 .tcz`"
  2093.       [ "`echo $PKGNAME | grep ".tgz\$"`" != "" ]     && PKGEXT='.tgz'    && PKGNAME="`basename $PKGNAME1 .tgz`"
  2094.       [ "`echo $PKGNAME | grep ".txz\$"`" != "" ]     && PKGEXT='.txz'    && PKGNAME="`basename $PKGNAME1 .txz`"
  2095.       [ "`echo $PKGNAME | grep ".tar.gz\$"`" != "" ]    && PKGEXT='.tar.gz'   && PKGNAME="`basename $PKGNAME1 .tar.gz`"
  2096.       [ "`echo $PKGNAME | grep ".tar.xz\$"`" != "" ]    && PKGEXT='.tar.xz'   && PKGNAME="`basename $PKGNAME1 .tar.xz`"
  2097.       [ "`echo $PKGNAME | grep ".pkg.tar.gz\$"`" != "" ]  && PKGEXT='.pkg.tar.gz' && PKGNAME="`basename $PKGNAME1 .pkg.tar.gz`"
  2098.       [ "`echo $PKGNAME | grep ".pkg.tar.xz\$"`" != "" ]  && PKGEXT='.pkg.tar.xz' && PKGNAME="`basename $PKGNAME1 .pkg.tar.xz`"
  2099.  
  2100.       # get pkg name only .. without versions or suffix
  2101.       PKGNAME_ONLY="`echo "${PKGNAME}" | sed -e 's/-[0-9.]*/-/g' -e 's/-$//'`"
  2102.       # if that didnt work, use the old method
  2103.       if [ "$PKGNAME_ONLY" = '' -o "$PKGNAME_ONLY" = "$PKGNAME" ]; then
  2104.         # get pkg name without version
  2105.         PKGNAMEONLY="`echo $PKGNAME | cut -d'-' -f1`"
  2106.       fi
  2107.       PKGNAME_ONLY="${PKGNAME_ONLY//-*/}"
  2108.  
  2109.       # get pkg version
  2110.       PKGVER="`LANG=C echo "$LINE" | sed -e 's/^[^0-9]*-//g' | cut -f1 -d'_' | cut -f1 -d'-'`"
  2111.       # get pkg size
  2112.       SIZE="`echo $LINE| cut -d'"' -f6 | cut -d' ' -f3`" #'micro
  2113.       SIZE=${SIZE## }
  2114.       SIZE=${SIZE%% }
  2115.       # must check again if pkg had no deps
  2116.       [ "$SIZE" = "" ] && SIZE=" `echo $LINE| cut -d'"' -f6|cut -d' ' -f2`"
  2117.       # get pkg category
  2118.       CAT="`echo $LINE | cut -d'"' -f6 | cut -d' ' -f1`"
  2119.       # remove extra categories
  2120.       [ "`echo "$CAT" | grep ';'`" != "" ] && CAT="`echo "$CAT" | cut -f1 -d';'`"
  2121.       # get pkg deps
  2122.       DEPS="`echo "$LINE" | cut -d'"' -f6 | cut -d' ' -f2 | grep ^'+'`"
  2123.       DESC="`echo "$LINE" | cut -f10 -d'|'`" #'micro
  2124.       # build the woof compatible repo file
  2125.       [ "$PKGNAME" != "" ] && echo "$PKGNAME|$PKGNAMEONLY|$VER|$BUILD|$CAT|$SIZE|$SUBDIR|${PKGNAME}${PKGEXT}|$DEPS|$DESC|$DISTRO_BINARY_COMPAT|$DISTRO_COMPAT_VERSION||" >> $TMPDIR/$FILENAME
  2126.     done
  2127.     #done making a woof repo file, print message
  2128.     [ -f $TMPDIR/$FILENAME ] && echo "Finished converting $FILENAME to woof format." || exit 1
  2129.   fi
  2130.  
  2131.   # if we are updating the repo, we dont wanna install the converted file straight over
  2132.   # the actual repo file, we wanna parse it for new pkgs and add only those
  2133.   if [ "$2" != "for_repo_update" ]; then
  2134.     # we converted a repo that we actually wanna install, so install it
  2135.     mv $TMPDIR/$FILENAME "$REPO_DB_FILE_DIR/$FILENAME"
  2136.     mv $TMPDIR/${FILENAME}_subdirs "$REPO_DB_FILE_DIR/${FILENAME}_subdirs" 2>/dev/null
  2137.     echo "Repo file '$REPO_DB_FILE_DIR/$FILENAME' created."
  2138.     update_sources #210613 update the list of sources after adding the newly converted repo
  2139.     #exit 0
  2140.   else
  2141.     mv "$TMPDIR/$FILENAME" "$REPO_DB_FILE_DIR/$FILENAME"
  2142.   fi
  2143. }
  2144.  
  2145.  
  2146. print_repo_info(){                # get repo settings, return current repo name FUNCLIST
  2147.  
  2148.   # get latest repo info (from sources file), or from PKGRC if that fails
  2149.   [ "$1" ] && get_repo_info "$1" || . ${PKGRC}
  2150.  
  2151.   local pkg_count=$(cat "$REPO_DB_FILE_DIR/${REPOFILE}" | wc -l)
  2152.  
  2153.   # output the repo info
  2154.   echo "- Repo:          $REPONAME"
  2155.   echo "- Repo file:     $REPOFILE"
  2156.   echo "- Package Type:  $EX"
  2157.   echo "- Packages:      $pkg_count"
  2158.   echo "- URL Mirror 1:  `echo $REPOURL1 | cut -f1-3 -d'/'`"
  2159.   [ "$REPOURL2" != "" ] && echo "- URL Mirror 2:  `echo $REPOURL2  | cut -f1-3 -d'/'`"
  2160.   [ "$REPOURL3" != "" ] && echo "- URL Mirror 3:  `echo $REPOURL3  | cut -f1-3 -d'/'`"
  2161.   [ "$REPOURL4" != "" ] && echo "- URL Mirror 4:  `echo $REPOURL4  | cut -f1-3 -d'/'`"
  2162.   echo
  2163.   echo "- Fall back to:`echo $REPOFALLBACKS | fold -w 50 -s | sed -e "s/ /, /g" -e "s/^/  /g"`"
  2164. }
  2165.  
  2166.  
  2167.  
  2168. # pkg search funcs
  2169.  
  2170. hide_blacklisted_pkgs_from_search_results(){ # hide BUILTIN and installed pkgs from searches NOLIST
  2171.  
  2172.   # dont hide package if using --force (the user may want to force a re-install of already installed pkg, for example)
  2173.   [ "$FORCE" = true ] && return 0
  2174.  
  2175.   # get pkg names (generic names, no versions) of all blacklisted packages in pipe delimited list
  2176.   blacklisted_pkgs_list="$(echo $PKG_NAME_IGNORE | sed -e 's/ /|/g')"
  2177.  
  2178.   # remove blacklisted packages from search list
  2179.   cat $TMPDIR/pkglist | grep -v -E "'$blacklisted_pkgs_list'" > $TMPDIR/pkglist_without_blacklisted
  2180.   mv $TMPDIR/pkglist_without_blacklisted $TMPDIR/pkglist
  2181.  
  2182.   # clean up tmp files
  2183.   rm $TMPDIR/pkglist_* &>/dev/null
  2184. }
  2185.  
  2186.  
  2187. hide_installed_pkgs_from_search_results(){  # hide BUILTIN and installed pkgs from searches NOLIST
  2188.  
  2189.   # dont hide package if using --force (the user may want to force a re-install of already installed pkg, for example)
  2190.   [ "$FORCE" = true ] && return 0
  2191.  
  2192.   # reset tmp file
  2193.   rm $TMPDIR/pkglist_inst &>/dev/null
  2194.  
  2195.   # get pkg names (generic names, no versions) of all installed pkgs (builtins, devx and user installed)
  2196.   inst_pkg_list="`cut -f1 -d'|' "$USER_INST_PKGS_FILE" \
  2197.    "$DEVX_INST_PKGS_FILE" \
  2198.    "$WOOF_INST_PKGS_FILE" 2>/dev/null \
  2199.    | grep -v ^$ \
  2200.    | tr '\n' '|' \
  2201.    | sed -e "s/||/|/g" \
  2202.    | sed -e "s/|\$//g"`"
  2203.  
  2204.   # remove woof and user installed packages from search list
  2205.   cat $TMPDIR/pkglist | grep -v -E "'$inst_pkg_list'" > $TMPDIR/pkglist_without_inst
  2206.   mv $TMPDIR/pkglist_without_inst $TMPDIR/pkglist
  2207.  
  2208.   # clean up tmp files
  2209.   rm $TMPDIR/pkglist_* &>/dev/null
  2210. }
  2211.  
  2212.  
  2213. list_pkg_names(){                 # list pkg names in current repo only ($1 is optional filter) FUNCLIST
  2214.  
  2215.   # remove any previous searches
  2216.   rm $TMPDIR/pkglist* 2>/dev/null
  2217.  
  2218.   # get current repo ($REPOFILE)
  2219.   . ${PKGRC}
  2220.  
  2221.   # create the search results
  2222.   cut -f1 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$1" > $TMPDIR/pkglist
  2223.  
  2224.   # filter out builtin and user installed packages
  2225.   if [ $HIDE_INSTALLED = true ]; then
  2226.     hide_installed_pkgs_from_search_results
  2227.   fi
  2228.  
  2229.   hide_blacklisted_pkgs_from_search_results
  2230.  
  2231.   # support pkg name aliases in finding packages
  2232.   if [ $NO_ALIASES = false ]; then
  2233.     local ALIAS_LIST
  2234.     local ALIAS
  2235.     local ALIAS_RES
  2236.     # if we have some results to parse
  2237.     if [ "$1" != "" -a -f $TMPDIR/pkg_aliases ]; then
  2238.       # get the list of aliases
  2239.       ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases  2>/dev/null | tr ',' ' '`";
  2240.       # for each alias
  2241.       echo $ALIAS_LIST | while read ALIAS
  2242.       do
  2243.         [ "$ALIAS" = '' ] && continue
  2244.         # get the match from the current repo (if any)
  2245.         ALIAS_RES="`LANG=C cut -f1 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$ALIAS"`" #'
  2246.         [ ! "$ALIAS_RES" ] && ALIAS_RES="`LANG=C cut -f2 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$ALIAS"`" #'
  2247.         # if the repo match was found in the search results
  2248.         if [ "$ALIAS_RES" != "" ]; then
  2249.           # add the alias results to the search results
  2250.           echo "$ALIAS_RES" >> $TMPDIR/pkglist
  2251.         fi
  2252.       done # for each alias
  2253.       # sort and clean the search results
  2254.       LANG=C cat $TMPDIR/pkglist | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq > $TMPDIR/pkglist1
  2255.       # replace the original search results
  2256.       mv $TMPDIR/pkglist1 $TMPDIR/pkglist
  2257.     fi
  2258.   fi
  2259.  
  2260.   # return the search results
  2261.   [ -s $TMPDIR/pkglist ] && cat $TMPDIR/pkglist 2>/dev/null
  2262.  
  2263.   # clean up
  2264.   [ ! -f $TMPDIR/pkglist ] && exit 1
  2265.   rm $TMPDIR/pkglist* 2>/dev/null
  2266.  
  2267. }
  2268.  
  2269.  
  2270. list_all_pkg_names(){             # list pkg names in any repo  ($1 is optional filter)FUNCLIST
  2271.  
  2272.   # remove any previous search results
  2273.   rm $TMPDIR/pkglist &>/dev/null
  2274.  
  2275.   # if bleeding edge disabled, output the list repo by repo, in the fallback order, current repo first (that order is set in update_sources)
  2276.   repo_file_list | while read repo_file
  2277.   do
  2278.     cut -f1 -d'|' "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep "^$1" | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr >> $TMPDIR/pkglist
  2279.   done
  2280.  
  2281.   # if bleeding edge enabled, re-order the whole list, so Pkg returns the most recent pgk versions from ANY repos
  2282.   if [ "$BLEDGE" = "yes" ]; then
  2283.     LANG=C cat $TMPDIR/pkglist  2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr > $TMPDIR/pkglist1
  2284.     mv $TMPDIR/pkglist1 $TMPDIR/pkglist
  2285.   fi
  2286.  
  2287.   # filter out built-in and user installed packages
  2288.   if [ $HIDE_INSTALLED = true ]; then
  2289.     hide_installed_pkgs_from_search_results
  2290.   fi
  2291.  
  2292.   hide_blacklisted_pkgs_from_search_results
  2293.  
  2294.   # support pkg name aliases in finding packages
  2295.   if [ $NO_ALIASES = false ]; then
  2296.     local ALIAS_LIST
  2297.     local ALIAS
  2298.     local ALIAS_RES
  2299.     # if we have some results to parse
  2300.     if [ "$1" != "" -a -f $TMPDIR/pkg_aliases ]; then
  2301.       # get the list of aliases
  2302.       ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases  2>/dev/null | tr ',' ' '`";
  2303.       # for each repo
  2304.       LANG=C repo_file_list | while read RF
  2305.       do
  2306.         # and for each alias
  2307.         for ALIAS in $ALIAS_LIST; do
  2308.           # get the match from the current repo (if any)
  2309.           ALIAS_RES="`LANG=C cut -f1 -d'|' "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -m1 "^$ALIAS"`"
  2310.           [ ! "$ALIAS_RES" ] && ALIAS_RES="`LANG=C cut -f2 -d'|' "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -m1 "^$ALIAS"`"
  2311.           # if the repo match was found in the search results
  2312.           if [ "$ALIAS_RES" != "" ]; then
  2313.             # add the alias results to the search results
  2314.             echo "$ALIAS_RES" >> $TMPDIR/pkglist
  2315.           fi
  2316.         done # for each alias
  2317.       done # for each repo
  2318.     fi
  2319.   fi
  2320.  
  2321.   # return the search results
  2322.   [ -s $TMPDIR/pkglist ] && LANG=C cat $TMPDIR/pkglist | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq
  2323.  
  2324.   # clean up
  2325.   [ ! -f $TMPDIR/pkglist ] && exit 1
  2326.   rm $TMPDIR/pkglist &>/dev/null
  2327. }
  2328.  
  2329.  
  2330. list_build_scripts(){             # list available build scripts  ($1 is optional filter)FUNCLIST
  2331.  
  2332.   # get settings from RC file
  2333.   . ${PKGRC}
  2334.  
  2335.   # make sure PetBuild is ready
  2336.   [ "$BUILDTOOL" = "petbuild" ] && prepare_petbuild
  2337.  
  2338.   # if no option given, just sort the results
  2339.   [ "$1" != "" ] && FILTER="grep -i $1" || FILTER="sort"
  2340.  
  2341.   # different build tools have their build scripts in different places.
  2342.   # check which BUILDTOOL we are using and list its build scripts
  2343.   case $BUILDTOOL in
  2344.     petbuild)
  2345.       echo "$(LANG=C ls -R -1 /usr/share/petbuild/ 2>/dev/null | grep -v ^'/' | grep -v ^$ | grep '.petbuild' | sed -e "s/.petbuild$//g" | sort | $FILTER)" | grep -v ^$
  2346.     ;;
  2347.     buildpet)
  2348.       echo "$(LANG=C ls -R -1 /usr/share/buildpet/ 2>/dev/null  | grep -v ^'/' | grep -v ^$ | grep -v 'buildpet.profile' | sed -e "s/.bp$//g" | sort | $FILTER)" | grep -v ^$
  2349.     ;;
  2350.     src2pkg)
  2351.       echo "Use: src2pkg FILE|URL or src2pkg -h"
  2352.     ;;
  2353.     sbopkg)
  2354.       sbopkg
  2355.     ;;
  2356.     *)
  2357.       echo "No build system configured. Set BUILDTOOL in $PKGRC."
  2358.       echo "Supported build tools: petbuild, buildpet, src2pkg, sbopkg"
  2359.     ;;
  2360.   esac
  2361. }
  2362.  
  2363.  
  2364. list_downloaded_pkgs(){           # list packages downloaded in WORKDIR ($1 is optional filter) FUNCLIST
  2365.  
  2366.   . ${PKGRC}
  2367.  
  2368.   cd "$WORKDIR" || { error "Cant cd into $WORKDIR"; exit 3; }
  2369.  
  2370.   local pkg
  2371.  
  2372.   # if no pkg given, list all
  2373.   if [ ! "$1" ]; then
  2374.  
  2375.     # get all pkgs in WORKDIR
  2376.     find "${WORKDIR}" -maxdepth 1 -type f | sed -e "s#${WORKDIR}##g" -e "s#^/##g" | grep -v ^'.pkg' | sort \
  2377.       | while read pkg # but go through each and only print it if a valid pkg
  2378.       do
  2379.         [ "`is_local_pkg "$pkg"`" = true ] && echo $pkg || continue
  2380.       done
  2381.  
  2382.     return 0
  2383.  
  2384.   else
  2385.  
  2386.     # $1 might be a pkg, or list of pkgs, loop through them
  2387.     for x in $1; do
  2388.       if [ "$x" != "-" ]; then
  2389.  
  2390.         # print the list of packages matching $x
  2391.         find "${WORKDIR}" -maxdepth 1 -type f | sed -e "s#${WORKDIR}##g" -e "s#^/##g" | grep -v ^'.pkg'|grep ^"$x" | sort \
  2392.           | while read pkg # but go through each and only print it if a valid pkg
  2393.           do
  2394.             [ "`is_local_pkg "$pkg"`" = true ] && echo $pkg || continue
  2395.           done
  2396.  
  2397.         return 0
  2398.       fi
  2399.     done
  2400.   fi
  2401.  
  2402.   cd -
  2403. }
  2404.  
  2405.  
  2406. list_installed_pkgs(){            # list user installed packages ($1 is optional filter) FUNCLIST
  2407.  
  2408.   local user_pkgs_list=''
  2409.   local builtins_list=''
  2410.   local devx_pkgs_list=''
  2411.  
  2412.   user_pkgs_list="$USER_INST_PKGS_FILE"
  2413.  
  2414.   if [ "$HIDE_BUILTINS" != true -a -f "$DEVX_INST_PKGS_FILE" ]; then
  2415.     devx_pkgs_list="$DEVX_INST_PKGS_FILE"
  2416.   fi
  2417.  
  2418.   [ "$HIDE_BUILTINS" != true ] && builtins_list="$WOOF_INST_PKGS_FILE"
  2419.  
  2420.   # search current repo file only .. $1 is the optional pkg filter.. take field1, remove empty lines, remove dashes, remove Pkg from pkg list too
  2421.   if [ ! "$1" ]; then
  2422.     cut -f1 -d'|' $user_pkgs_list $devx_pkgs_list $builtins_list | grep -vE '^\$|^pkg\-'
  2423.     return 0
  2424.   else
  2425.     cut -f1 -d'|' $user_pkgs_list $devx_pkgs_list $builtins_list | grep "^$1" | grep -vE '^\$|^pkg\-'
  2426.     return 0
  2427.   fi
  2428. }
  2429.  
  2430.  
  2431. list_builtin_pkgs(){              # lists builtin packages FUNCLIST
  2432.  
  2433.   local builtins_repo
  2434.  
  2435.   builtins_repo="$WOOF_INST_PKGS_FILE"
  2436.  
  2437.   # search builtins (woof-installed) repo file only .. $1 is the optional pkg filter.. take field1, remove empty lines, remove dashes, remove Pkg from pkg list too
  2438.   cut -f1 -d'|' $builtins_repo | grep "^$1" | grep -v ^\$  | grep -v "\-$" | grep -v ^pkg\- | sort
  2439. }
  2440.  
  2441.  
  2442. search_pkgs(){                    # given $1, searches current repo, shows name and desc columns FUNCLIST
  2443.  
  2444.   local name
  2445.   local desc
  2446.   local descfull
  2447.   local search
  2448.  
  2449.   # convert "foo[ -_]bar" into "foo.*bar"
  2450.   search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2451.  
  2452.   # convert repo file to nice columnised output, use cat|grep so empty searches return all results
  2453.   cat "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep -i "$search" | while read repo_line;
  2454.   do
  2455.     name=`echo  "$repo_line"|cut -f2  -d'|'`
  2456.     desc="`echo "$repo_line"|cut -f10 -d'|' | head -c 57`"
  2457.     descfull="`echo "$repo_line"|cut -f10 -d'|'`"
  2458.     [ "$desc" != "$descfull" ] && desc="${desc}.."
  2459.     printf "%-20s" "$name" " ${desc:-No description}"
  2460.     echo
  2461.   done
  2462. }
  2463.  
  2464.  
  2465. search_fast(){                    # given $1, searches current repo, show pkg names only, case sensitive FUNCLIST
  2466.   local RES
  2467.   local search
  2468.  
  2469.   # convert "foo[ -_]bar" into "foo.*bar"
  2470.   search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2471.  
  2472.   # get matching pkgs
  2473.   RES="`LANG=C grep "$search" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f1 -d'|'`"
  2474.   # error if no result
  2475.   [ ! "$RES" ] && exit 1
  2476.  
  2477.   # put results into file
  2478.   echo "$RES" > $TMPDIR/pkglist
  2479.  
  2480.   # hide built-in, devx and user installed packages
  2481.   if [ $HIDE_INSTALLED = true ]; then
  2482.     hide_installed_pkgs_from_search_results
  2483.   fi
  2484.  
  2485.   hide_blacklisted_pkgs_from_search_results
  2486.  
  2487.   # now build the search results
  2488.   RES="`grep -v "^\$" $TMPDIR/pkglist 2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq`"
  2489.   rm $TMPDIR/pkglist &>/dev/null
  2490.  
  2491.   #finshed making search results, print results
  2492.   [ "$RES" = "" ] && exit 1
  2493.   echo "$RES"
  2494. }
  2495.  
  2496.  
  2497. search_all_pkgs(){                # given $1, search all repos, show name and desc columns FUNCLIST
  2498.  
  2499.   local name
  2500.   local desc
  2501.   local descfull
  2502.   local search
  2503.  
  2504.   # convert "foo[ -_]bar" into "foo.*bar"
  2505.   search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2506.  
  2507.   for repo_file in `repo_file_list`
  2508.   do #090817
  2509.     # convert repo file to nice columnised output
  2510.     cat "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -i "$search" | while read repo_line;
  2511.     do
  2512.     # get details from repo
  2513.     name=`echo  "$repo_line"|cut -f2  -d'|'`
  2514.     desc="`echo "$repo_line"|cut -f10 -d'|' | head -c 57`"
  2515.     descfull="`echo "$repo_line"|cut -f10 -d'|'`"
  2516.     [ "$desc" != "$descfull" ] && desc="${desc}.."
  2517.     # remove spaces and comments (slackware-extra repo has some dodgy entries.. dogy names, descriptions with comments, etc)
  2518.     name="${name// /}"
  2519.     name="${name//#/}"
  2520.     [ "$name" = '' ] && continue
  2521.     # print columnised output
  2522.     printf "%-20s" "$name" " ${desc:-No description}"
  2523.     echo
  2524.     done
  2525.   done
  2526.  
  2527. }
  2528.  
  2529.  
  2530. search_all_fast(){                # given $1, search all repos, show pkg names only, case sensitive FUNCLIST
  2531.   local RES
  2532.   local search
  2533.  
  2534.   # convert "foo[ -_]bar" into "foo.*bar"
  2535.   search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2536.  
  2537.   #if bleeding edge enabled, combine into 1 list, so
  2538.   # that `pkg -g` etc return most recent from ALL repos
  2539.   rm $TMPDIR/pkglist &>/dev/null
  2540.   if [ "$BLEDGE" = "yes" ]; then
  2541.     RES=''
  2542.     for RF in `repo_file_list`
  2543.     do #090817
  2544.       cat "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -i "$search" | cut -f1 -d'|' | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq | sed -e '/^$/d' >> $TMPDIR/pkglist
  2545.     done
  2546.  
  2547.   else
  2548.     # if bleeding edge disabled, output the list repo by repo, in #
  2549.     # the fallback order, current repo first (that order is set in update_sources)
  2550.     for RF in `repo_file_list`
  2551.     do #090817
  2552.       cat "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -i "$search"| cut -f1 -d'|' | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq | sed -e '/^$/d' >> $TMPDIR/pkglist
  2553.     done
  2554.  
  2555.   fi
  2556.  
  2557.   #100817 hide built-in, devx and user installed packages
  2558.   if [ $HIDE_INSTALLED = true ]; then
  2559.     hide_installed_pkgs_from_search_results
  2560.   fi
  2561.  
  2562.   hide_blacklisted_pkgs_from_search_results
  2563.  
  2564.   # now build the search results
  2565.   RES="`grep -v "^\$" $TMPDIR/pkglist 2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq`"
  2566.   rm $TMPDIR/pkglist &>/dev/null
  2567.  
  2568.   #finshed making search results, print results
  2569.   [ "$RES" = "" ] && exit 1
  2570.  
  2571.   echo "$RES"
  2572. }
  2573.  
  2574.  
  2575. which_repo(){                     # list repo of given package ($1) FUNCLIST
  2576.  
  2577.   # if no valid options, quit
  2578.   [ ! "$1" -o "$1" = "-" -o "$1" = " " ] && print_usage which-repo && exit 1
  2579.  
  2580.   . ${PKGRC}
  2581.  
  2582.   local PKGNAME=''
  2583.   local PKGNAME_ONLY=''
  2584.   local pkg_ext=''
  2585.   local repo_file=''
  2586.   local repo_name=''
  2587.   local pkg_list=''
  2588.  
  2589.   PKGNAME=`get_pkg_name "$1"`
  2590.   PKGNAME_ONLY=`get_pkg_name_only "$1"`
  2591.   pkg_ext=`get_pkg_ext "$PKGNAME"`
  2592.  
  2593.   repo_file="$(grep -l "|$PKGNAME.$pkg_ext|" "$REPO_DB_FILE_DIR"/Packages-*)"
  2594.   if [ "$repo_file" != '' ]; then
  2595.     # get the repo name
  2596.     repo_name="`grep -m1 "$(basename $repo_file)|" ${HOME}/.pkg/sources | cut -f1 -d'|'`"
  2597.     pkg_list="$PKGNAME $repo_name"
  2598.   else
  2599.  
  2600.     # for each repo
  2601.     for repo_file in `repo_file_list`
  2602.     do
  2603.       # get the repo name
  2604.       repo_name="`grep -m1 "$repo_file|" ${HOME}/.pkg/sources | cut -f1 -d'|'`"
  2605.       # create the entries, example: "vlc slacko14.2"
  2606.       # (each line shows a matching package, then a SPACE, then the name of repo the package lives in)
  2607.       pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "^$PKGNAME|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2608.       [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "|$PKGNAME.$EX|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2609.       [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "|$1.$EX|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2610.       [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "|$PKGNAME_ONLY|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2611.       [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "^$PKGNAME_ONLY|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2612.       [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "|$1|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2613.       [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "^$1|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2614.     done
  2615.   fi
  2616.  
  2617.   # show results
  2618.   LANG=C echo -e "$pkg_list" | sed -e '/^$/d' | uniq
  2619. }
  2620.  
  2621.  
  2622. which_pkg(){                      # find out which pkg FILE ($1) comes from FUNCLIST
  2623.  
  2624.   # exit if no valid opts
  2625.   [ ! "$1" -o "$1" = '-' -o "$1" = '' ] && print_usage which && exit 1
  2626.  
  2627.   local PKGNAME=''
  2628.   local PKG_FILE_LIST=''
  2629.   local FILENAME=''
  2630.   local FILENAME_ONLY=''
  2631.   local DIRNAME=''
  2632.   local builtins_without_busybox="$(find "$BUILTIN_FILE_LIST_DIR"/* -maxdepth 1 -type f | grep -v "/busybox")"
  2633.  
  2634.   # get user input
  2635.   FILENAME="`basename "$1"`"
  2636.   FILENAME_ONLY="$FILENAME"
  2637.   DIRNAME="`dirname "$1"`"
  2638.  
  2639.   # if we don't have a file, the user probably gave a command,
  2640.   # so lets check see
  2641.   if [ ! -f "$1" ]; then
  2642.     # if we get a command, then that is our FILENAME
  2643.     cmd=`which "$1"`
  2644.     # if $cmd found, set FILENAME to $cmd (FILENAME now includes full path)
  2645.     [ "$cmd" != '' ] && FILENAME=$cmd && FILENAME_ONLY=`basename "$FILENAME"`
  2646.   fi
  2647.  
  2648.   # dont use relative paths
  2649.   [ "`echo "$DIRNAME" | grep "^\."`" != '' ] && DIRNAME=''
  2650.  
  2651.   # try user installed pkgs contents of $PKGS_DIR/*.files
  2652.  
  2653.   # try '$dir/$file', returns filename (no path) of matching *.files
  2654.   [ "$PKG_FILE_LIST" = '' ] && PKG_FILE_LIST="`grep -l "$DIRNAME/$FILENAME\$"  "$PACKAGE_FILE_LIST_DIR"/*.files 2>/dev/null| sed "s#$PKGS_DIR/##g" 2>/dev/null`"
  2655.  
  2656.   # try '$dir/$file_*' if needed
  2657.   [ "$PKG_FILE_LIST" = '' ] && PKG_FILE_LIST="`grep -l "$DIRNAME/${FILENAME}_" "$PACKAGE_FILE_LIST_DIR"/*.files 2>/dev/null| sed "s#$PKGS_DIR/##g" 2>/dev/null`"
  2658.  
  2659.   # try '$dir/$file-*' if needed
  2660.   [ "$PKG_FILE_LIST" = '' ] && PKG_FILE_LIST="`grep -l "$DIRNAME/${FILENAME}\-" "$PACKAGE_FILE_LIST_DIR"/*.files 2>/dev/null| sed "s#$PKGS_DIR/##g" 2>/dev/null`"
  2661.  
  2662.   # if we found a package, set the package name to the name of the *.files file that we got
  2663.   [ "$PKG_FILE_LIST" != '' ] && PKGNAME="`basename "$PKG_FILE_LIST" .files`"
  2664.  
  2665.   # maybe we got nothing from *.files.. check builtins/$1* for ' $FILENAME_ONLY',
  2666.   # returns PKGNAME of the matching builtin
  2667.  
  2668.   # if needed, search inside builtin file lists (EXCEPT busybox) for ' $FILENAME_ONLY'
  2669.   [ "$PKG_FILE_LIST" = '' ] && [ "$PKGNAME" = "" ] \
  2670.     && PKGNAME="$(basename `grep -l "^ $FILENAME_ONLY\$" $builtins_without_busybox | sed "s#$BUILTIN_FILE_LIST_DIR/##g"` 2>/dev/null)"
  2671.  
  2672.   # if that didn't work, search inside builtin file lists of busybox for ' $FILENAME_ONLY'
  2673.   [ "$PKG_FILE_LIST" = '' ] && [ "$PKGNAME" = "" ] \
  2674.     && PKGNAME="$(basename `grep -l "^ $FILENAME_ONLY\$" "$BUILTIN_FILE_LIST_DIR/busybox" | sed "s#$BUILTIN_FILE_LIST_DIR/##g"` 2>/dev/null)"
  2675.  
  2676.   # apps in ADRV sfs dont have their files listed in their $PKGS_DIR/builtin_files/$pkgname.. so..
  2677.  
  2678.  
  2679.   # now check pkg names (not pkg contents) of builtins (EXCEPT busybox) for '$file'.. cos maybe we didnt find the file inside the file lists
  2680.   [ "$PKGNAME" = "" ] \
  2681.     && PKGNAME="`echo "$builtins_without_busybox" | grep -m1 "^${FILENAME_ONLY}\$" | sed "s#$BUILTIN_FILE_LIST_DIR/##g" 2>/dev/null`"
  2682.  
  2683.   # now look for '$file' in user installed repo list
  2684.   [ "$PKGNAME" = "" ] \
  2685.     && PKGNAME="`cut -f1,2,8 -d'|' "$USER_INST_PKGS_FILE" 2>/dev/null | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null| grep -m1 "|$FILENAME_ONLY|" | cut -f2 -d'|'`"
  2686.  
  2687.   # also look for '$file' in user/woof/devx installed repo list
  2688.   [ "$PKGNAME" = "" ] \
  2689.     && PKGNAME="$(cut -f1,2,8 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null | grep -m1 "|$FILENAME_ONLY|" | cut -f2 -d'|')"
  2690.  
  2691.  
  2692.   # we searched for an exact match in builtins, user installed, woof installed and devx pkgs, now try some fuzzier matches
  2693.  
  2694.   # try /$file_* in builtins
  2695.   [ "$PKGNAME" = "" ] \
  2696.     && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}_" "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2697.  
  2698.   # try $file-* in builtins
  2699.   [ "$PKGNAME" = "" ] \
  2700.     && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}-" "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_DIR/builtin_files/##g"` 2>/dev/null)"
  2701.  
  2702.   # try $file.* in builtins
  2703.   [ "$PKGNAME" = "" ] \
  2704.     && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}\." "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2705.  
  2706.   # try *file in builtin pkgs
  2707.   [ "$PKGNAME" = "" ] \
  2708.     && PKGNAME="$(basename `grep -l "${FILENAME_ONLY}"\$ "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2709.  
  2710.  
  2711.   # if we still didnt find it, look in user installed package lists, for FILENAME
  2712.   [ "$PKGNAME" = "" ] \
  2713.     && PKGNAME=`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" \
  2714.       | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2715.       | grep -m1 "|${FILENAME_ONLY}|" \
  2716.       | cut -f2 -d'|'` 2>/dev/null
  2717.  
  2718.   # if we still didnt find it, look in all installed package lists, for FILENAME
  2719.   [ "$PKGNAME" = "" ] \
  2720.     && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2721.       | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2722.       | grep -m1 "|${FILENAME_ONLY}|" \
  2723.       | cut -f2 -d'|'` 2>/dev/null
  2724.  
  2725.   # if we still didnt find it, look in all installed package lists, for *FILENAME
  2726.   [ "$PKGNAME" = "" ] \
  2727.     && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2728.       | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2729.       | grep -m1 "${FILENAME_ONLY}|" \
  2730.       | cut -f2 -d'|'` 2>/dev/null
  2731.  
  2732.   # if we still didnt find it, look in all installed package lists, for FILENAME*
  2733.   [ "$PKGNAME" = "" ] \
  2734.     && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2735.       | sed -e "s/^/|/" -e "s/\$/|/" \
  2736.       | grep -m1 "|${FILENAME_ONLY}" \
  2737.       | cut -f2 -d'|'` 2>/dev/null
  2738.  
  2739.  
  2740.   # clean up
  2741.   [ "$PKGNAME" = '.files' ] && PKGNAME=''
  2742.   PKGNAME="`echo "$PKGNAME" | head -1`"
  2743.  
  2744.   # now print pkgs which contain the given file ($1)
  2745.   if [ "$PKGNAME" != "" ]; then
  2746.     echo "$PKGNAME"
  2747.     return 0
  2748.   else
  2749.     echo "File '$FILENAME' not found in any installed or built-in pkgs."
  2750.     exit 1
  2751.   fi
  2752. }
  2753.  
  2754.  
  2755.  
  2756. # pkg info funcs
  2757.  
  2758. pkg_contents(){                   # list package ($1) contents FUNCLIST
  2759.  
  2760.   # if no valid options, quit
  2761.   [ ! "$1" -o "$1" = "-" -o "$1" = " " ] && print_usage contents && exit 1
  2762.  
  2763.   # get settings
  2764.   . ${PKGRC}
  2765.  
  2766.   local PKGFILE
  2767.   local ext
  2768.   local PKGNAME
  2769.   local PKGNAME_ONLY
  2770.   local pkg_is_local_file
  2771.   local pkg_is_builtin
  2772.   local pkg_is_installed
  2773.   local PKGFLIST=''
  2774.  
  2775.   # get pkg extension
  2776.   ext=`get_pkg_ext "$1"`
  2777.  
  2778.   # get pkg name (includes version), but no extension or path
  2779.   PKGNAME="$(basename "$1" .$ext)"
  2780.   PKGNAME=`get_pkg_name "$PKGNAME"`
  2781.  
  2782.   # get pkg name without version
  2783.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  2784.  
  2785.   pkg_is_local_file=`is_local_pkg "$1"`
  2786.   pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY"`
  2787.   pkg_is_installed=`is_installed_pkg "$PKGNAME_ONLY"`
  2788.  
  2789.   # now we check various ways to find out the contents of
  2790.   # a pkg (either by *.files, user installed, woof, builtin, etc)
  2791.  
  2792.   [ "$pkg_is_local_file" = true ] && PKGFILE="$1"
  2793.  
  2794.   # try a file in the current dir if needed
  2795.   [ ! -f "$PKGFILE" ] && PKGFILE="${CURDIR}/${PKGNAME}.$ext"
  2796.   # check $WORKDIR if needed
  2797.   [ ! -f "$PKGFILE" ] && PKGFILE="${WORKDIR}/${PKGNAME}.$ext"
  2798.  
  2799.   # if the pkg is a local file
  2800.   if [ -f "$PKGFILE" ]; then
  2801.     #list contents based on extension
  2802.     case "$ext" in
  2803.     sfs)
  2804.       unsquashfs -l "$PKGFILE"  | cut -f2-99 -d'/'| sed -e 's#^#/#g' 2>/dev/null | grep -v -E 'unsquashfs:|/squashfs-root|) to write' | grep -v "^/$"
  2805.     ;;
  2806.     deb)
  2807.       dpkg-deb -c "$PKGFILE" 2>/dev/null | grep -v "^/$"
  2808.      ;;
  2809.     pet|tar|tar**tcz|*txz|*tgz|*xz|*gz)
  2810.       # remove leading pkg name from each line of file list
  2811.       # (shown if listing *some* pkg file contents)
  2812.       tar -tf "$PKGFILE" 2>/dev/null \
  2813.         | sed -e "s#^./${PKGNAME}/#/#g" -e "s#^${PKGNAME}/#/#g" -e "s#^./##g" 2>/dev/null \
  2814.         | grep -v ^$ 2>/dev/null 2>/dev/null \
  2815.         | grep -v "^/$"
  2816.     ;;
  2817.     rpm)
  2818.       busybox rpm -qlp "$PKGFILE" 2>/dev/null | grep -v "^/$"
  2819.     ;;
  2820.     esac
  2821.     exit $?
  2822.   fi
  2823.  
  2824.   # if we are here, the pkg is not a downloaded pkg, so we build a
  2825.   # list of files by checking  *.files, woof, builtins ..
  2826.  
  2827.   # check if we need to (and can) get our pkg contents from builtins/PKGNAME
  2828.   local  need_to_check_builtins=`echo "$PKG_FLIST" | grep -m1 'packages/builtin_files/'`
  2829.  
  2830.   # if the pkg is a builtin, we will re-format the output of LIST to match the others (full paths on each line)
  2831.   if [ "$need_to_check_builtins" != '' -a "$pkg_is_builtin" = true ]; then
  2832.  
  2833.     # reset the list of pkg files, we will re-build it
  2834.     rm $TMPDIR/pkg_file_list 2>/dev/null
  2835.  
  2836.     # first we get the package contents from $PKGS_DIR/builtin_files/$PKGNAME_ONLY
  2837.     cat "$PKG_FLIST" 2>/dev/null | while read line
  2838.     do
  2839.       # parse it, so we get a full path to file on each line
  2840.       if [ "`echo "$line" | grep '^/'`" != '' ]; then
  2841.         # set the dir to use in our file list
  2842.         dir="$line"
  2843.       else
  2844.         # keep previous dir
  2845.         dir="$dir"
  2846.       fi
  2847.  
  2848.       # create our new line (a full file path) to $LIST
  2849.       line_to_add="$dir/`echo "$line" | cut -f2 -d' '`"
  2850.  
  2851.       # if only a dir, skip it
  2852.       [ "$line" = "$dir" ] && continue
  2853.  
  2854.       # if its already added, skip it
  2855.       [ "`grep -m1 "$line_to_add" ${TMPDIR}/pkg_file_list 2>/dev/null `" != '' ] && continue
  2856.  
  2857.       # if its not a file on the system (it should be), skip it
  2858.       [ ! -f "$line_to_add" ] && continue
  2859.  
  2860.       # all should be ok, add the line to our list
  2861.       echo "$line_to_add" >> $TMPDIR/pkg_file_list
  2862.  
  2863.     done
  2864.  
  2865.     # now get our pkg contents list, it might have been re-formatted (if a builtin)
  2866.     PKG_FLIST="`cat ${TMPDIR}/pkg_file_list 2>/dev/null`"
  2867.  
  2868.     # last resort, if we lost our file list or still dont have, try the basics again
  2869.     [ "$PKG_FLIST" = '' ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}"'*.files' 2>/dev/null)"
  2870.  
  2871.     # clean up the list a bit
  2872.     [ "$PKG_FLIST" != '' ] && PKG_FLIST="`echo "$PKG_FLIST" | grep -v ' ' | grep -v "^\$" | sort | uniq`"
  2873.  
  2874.     # and clean up the tmp files
  2875.     rm ${TMPDIR}/pkg_file_list 2>/dev/null
  2876.   fi
  2877.  
  2878.   # try PKGNAME_ONLY.files (exact match)
  2879.   PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}.files" 2>/dev/null)"
  2880.  
  2881.   # try finding PKGNAME.files (exact match)
  2882.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}.files" 2>/dev/null)"
  2883.  
  2884.   # try the builtins files (exact match)
  2885.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$BUILTIN_FILE_LIST_DIR" -maxdepth 1 -type f -name "$PKGNAME_ONLY")"
  2886.  
  2887.   # try PKGNAME (exact match) in user installed pkgs
  2888.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -m1 ^"$PKGNAME\$" 2>/dev/null`.files"
  2889.  
  2890.   # try PKGNAME (exact match) in all installed pkgs
  2891.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME\$" 2>/dev/null`.files"
  2892.  
  2893.   # try PKGNAME_ONLY (exact match) in all installed pkgs
  2894.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f2 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME_ONLY\$" 2>/dev/null`.files"
  2895.  
  2896.  
  2897.   # no exact matches found, try fuzzy searches..
  2898.  
  2899.   # try PKGNAME*.files
  2900.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "/${PKGNAME}"'*.files'  2>/dev/null)"
  2901.  
  2902.   # try finding *PKGNAME.files
  2903.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name '*'"${PKGNAME}.files" 2>/dev/null)"
  2904.  
  2905.   # try ^PKGNAME_ONLY[_-] in user installed pkgs
  2906.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -Em1 "^$PKGNAME_ONLY[_-]" 2>/dev/null`.files"
  2907.  
  2908.   # try PKGNAME_ONLY* in user installed pkgs only
  2909.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -m1 ^"$PKGNAME_ONLY" 2>/dev/null`.files"
  2910.  
  2911.   # try PKGNAME_ONLY-* (any installed pkgs)
  2912.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -Em1 ^"${PKGNAME_ONLY}[_-]" 2>/dev/null`.files"
  2913.  
  2914.   # try PKGNAME_ONLY* (any installed pkgs)
  2915.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME_ONLY" 2>/dev/null`.files"
  2916.  
  2917.   # try PKGNAME_ONLY*.files
  2918.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PKGS_DIR" -maxdepth 1 -type f -name "/${PKGNAME_ONLY}"'*.files'  2>/dev/null)"
  2919.  
  2920.  
  2921.  
  2922.   #if we found a list of files
  2923.   if [ "$PKG_FLIST" != "" ]; then
  2924.  
  2925.     print_cmd=echo
  2926.     # PKG_FLIST just might contain a path to the pkg contents
  2927.     # themselves (a *.files, or a file in builtin_files/*).. so if
  2928.     # its a file path, we will cat it, if not, its the pkg contents
  2929.     # themselves, we echo it
  2930.     if [ "`echo "$PKG_FLIST" | grep -m1 '/builtin_files/'`" != '' -o "`echo "$PKG_FLIST" | grep -m1 "packages/$PKGNAME"`" != '' ]; then
  2931.       print_cmd=cat
  2932.     fi
  2933.  
  2934.     $print_cmd "$PKG_FLIST" | grep -v "^/$" 2>/dev/null
  2935.  
  2936.   else # if no files found
  2937.     if [ "$PKGNAME" != '' ]; then
  2938.       INST_CHECK="`is_installed_pkg $PKGNAME 2>/dev/null`"
  2939.       if [ "$INST_CHECK" != true -o "$pkg_is_local_file" = false ]; then
  2940.         error "Package must be installed, downloaded or built-in."
  2941.       else
  2942.         error "Could not get package contents, unable to get file list."
  2943.       fi
  2944.     else
  2945.       error "Could not get name of package."
  2946.     fi
  2947.   fi
  2948. }
  2949.  
  2950.  
  2951. pkg_entry(){                      # show pkg ($1) repo entry, each field on a new line FUNCLIST
  2952.  
  2953.   # exit if no valid opts
  2954.   [ ! "$1" -o "$1" = '-' ] && print_usage pkg-entry && exit 1
  2955.  
  2956.   local EX
  2957.   local PKGNAME
  2958.   local PKGNAME_ONLY
  2959.  
  2960.   # get pkg extension
  2961.   EX=`get_pkg_ext "$1"`
  2962.  
  2963.   # get pkg name with version, but no extension or path
  2964.   PKGNAME="$(basename "$1" .$EX)"
  2965.  
  2966.   # dont rely on the string the user gave us, try to get the exact match
  2967.   PKGNAME=`get_pkg_name "$PKGNAME"`
  2968.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  2969.  
  2970.   PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "|$PKGNAME|")"
  2971.   [ "$PKG_ENTRY" = '' ] && PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "^$PKGNAME|")"
  2972.   [ "$PKG_ENTRY" = '' ] && PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "|$PKGNAME_ONLY|")"
  2973.   if [ "$PKG_ENTRY" = '' ]; then
  2974.     echo "$1 not found in $REPOFILE"
  2975.     exit 1
  2976.   else
  2977.     echo "$PKG_ENTRY" | tr '|' '\n' | grep -v '^$'
  2978.   fi
  2979.   return 0
  2980. }
  2981.  
  2982.  
  2983. pkg_status(){                     # print package ($1) name, status, deps, etc FUNCLIST
  2984.  
  2985.   # exit if no valid options
  2986.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-status && exit 1
  2987.  
  2988.   # get current repo name
  2989.   . ${PKGRC}
  2990.  
  2991.   local EX
  2992.   local PKGNAME=''
  2993.   local PKGNAME_ONLY=''
  2994.   local PKGFILE=''
  2995.   local MSG=''
  2996.   local install_status=''
  2997.   local pkg_found=false
  2998.   local pkg_repo=''
  2999.   local pkg_repo_file=''
  3000.   local prev_repo=${REPONAME}
  3001.  
  3002.   # get pkg extension
  3003.   EX=`get_pkg_ext "$1"`
  3004.  
  3005.   # get pkg name with version, but no extension or path
  3006.   PKGNAME="$(basename "$1" .$EX)"
  3007.  
  3008.   # dont rely on the string the user gave us, try to get the exact match
  3009.   PKGNAME=`get_pkg_name "$PKGNAME"`
  3010.  
  3011.   # get pkg name without version
  3012.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  3013.  
  3014.   [ "$PKGNAME" = '' ] && error "Can't find $1" && exit 1
  3015.  
  3016.   # get install status of pkg (installed or not)
  3017.   [ "`is_installed_pkg $PKGNAME`" = true ] && install_status="installed" || install_status="not installed"
  3018.  
  3019.   # if pkg is installed, find out from where
  3020.   if [ "$install_status" = "installed" ]; then
  3021.  
  3022.     # check user installed pkgs for $PKGNAME
  3023.     pkg_found=`LANG=C is_usr_pkg "${PKGNAME}"`
  3024.     [ "$pkg_found" = true ] && install_status="installed (user)"
  3025.  
  3026.     # if pkg not found yet, check if pkg is from the devx
  3027.     if [ -f "$PKGS_DIR/devx-only-installed-packages" -a "$pkg_found" = false ]; then
  3028.       pkg_found=`LANG=C is_devx_pkg "${PKGNAME}"`
  3029.       [ "$pkg_found" = true ] && install_status="installed (in devx)"
  3030.     fi
  3031.  
  3032.     # check builtins for PKGNAME_ONLY, if it exists, its a builtin pkg
  3033.     if [ -d "$BUILTIN_FILE_LIST_DIR/" -a "$pkg_found" = false ]; then
  3034.       pkg_found=`LANG=C is_builtin_pkg "${PKGNAME_ONLY}"`
  3035.       [ "$pkg_found" = true ] && install_status="installed (builtin)"
  3036.     fi
  3037.  
  3038.     # last gasp, if pkg not found yet, check if pkg if listed in layers-installed packages
  3039.     if [ -f "$PKGS_DIR/layers-installed-packages" -a "$pkg_found" = false ]; then
  3040.       pkg_found=$(LANG=C grep -m1 "^${PKGNAME}|" "$LAYER_INST_PKGS_FILE")
  3041.  
  3042.       [ "$pkg_found" = '' ] && install_status="installed (layers)"
  3043.     fi
  3044.  
  3045.   fi
  3046.  
  3047.   # get the repo of this pkg, if needed
  3048.   [ "$pkg_repo" = '' ] && pkg_repo="`which_repo "$PKGNAME" 2>/dev/null | cut -f2 -d' '`"
  3049.  
  3050.   # if we got a repo name, get the repo file
  3051.   [ "$pkg_repo" != '' ] && pkg_repo_file="$(grep -m1 "^$pkg_repo|" ${HOME}/.pkg/sources | cut -f3 -d'|')"
  3052.  
  3053.   # if we have a repo to search for pkg info
  3054.   if [ "$pkg_repo_file" != "" ]; then
  3055.  
  3056.     # get package description from its repo entry
  3057.     pkg_desc="`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/$pkg_repo_file" 2>/dev/null| grep -m1 "$PKGNAME" | cut -f10 -d'|' | head -1`"
  3058.  
  3059.     if [ "$pkg_desc" = '' ]; then
  3060.       pkg_desc="`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$PKGS_DIR/Packages-"* 2>/dev/null| grep -m1 "${PKGNAME}|" | cut -f10 -d'|' | head -1`"
  3061.     fi
  3062.  
  3063.     # get size of pkg
  3064.     pkg_size=`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/$pkg_repo_file" 2>/dev/null | cut -f6 -d'|' | head -1`
  3065.  
  3066.     # add K to end of pkg_size, if not there already
  3067.     [ "$pkg_size" != '' ] && pkg_size="${pkg_size}K" && pkg_size="${pkg_size//KK/K}"
  3068.  
  3069.     # if called with -PS, we get the full info (where we sort deps missing or installed)
  3070.     if [ "$FULL_PKG_STATUS" = true ]; then
  3071.  
  3072.       # if pkg has many deps, checking the deps might take a while, print a 'please wait' msg
  3073.       please_wait=false
  3074.       # count deps of pkg
  3075.       [ "`has_deps "$PKGNAME"`" = true ] && please_wait=true
  3076.       [ "$please_wait" = true ] && echo -ne "Please wait.. Gathering dependency information.\n"
  3077.  
  3078.       set_current_repo $pkg_repo 1>/dev/null
  3079.       # sort deps into 2 lists: missing deps and installed deps
  3080.       find_deps "$PKGNAME"
  3081.       set_current_repo $prev_repo 1>/dev/null
  3082.  
  3083.       # create a nicely formatted, coloured list of deps, green for installed, yellow for missing
  3084.       INSTALLED_DEPS_MSG="${green}`echo "${DEPS_INSTALLED}"|grep -v "^\$"| tr '\n' ','| sed -e "s#,\\$##" -e 's#,#, #g' 2>/dev/null| fold -w 50 -s | sed '2,10 s/^/                /g' 2>/dev/null`${endcolour}"
  3085.       MISSING_DEPS_MSG="${yellow}`echo "${DEPS_MISSING}"   |grep -v "^\$"| tr '\n' ','| sed -e "s#,\\$##" -e 's#,#, #g' 2>/dev/null| fold -w 50 -s | sed '2,10 s/^/                /g'`${endcolour}"
  3086.  
  3087.       DEPS_ENTRY="Installed deps: ${INSTALLED_DEPS_MSG:-None}
  3088. Missing deps:   ${MISSING_DEPS_MSG:-None}"
  3089.  
  3090.     else
  3091.  
  3092.       DEPS_ENTRY="Dependencies:   `list_deps "$PKGNAME" 2>/dev/null`"
  3093.  
  3094.     fi
  3095.  
  3096.     #250613 added desc
  3097.     MSG="
  3098. Name:           ${PKGNAME}
  3099. Description:    `echo ${pkg_desc:-No description} | fold -w 50 -s | sed '2,10 s/^/                /g'`
  3100. Size:           ${pkg_size:-Unknown}
  3101. Status:         ${install_status:-Unknown}
  3102. In Repo:        ${pkg_repo:-Not in any repos}
  3103. Repo file:      `basename ${pkg_repo_file:-Not in any repositories} 2>/dev/null`
  3104. $DEPS_ENTRY"
  3105.  
  3106.   fi
  3107.  
  3108.   # if not found in any repo, maybe a woof or alien (user-installed) package
  3109.   if [ "$MSG" = "" ]; then #if nothing found in any repo
  3110.  
  3111.     PKGFILE="`list_downloaded_pkgs | grep -m1 "^$PKGNAME"`"
  3112.  
  3113.     # if the pkg is a downloaded file (in WORKDIR)
  3114.     if [ -f "$WORKDIR/$PKGFILE" ]; then
  3115.  
  3116.       # get the file, and get its file size
  3117.       PKGFILE="$WORKDIR/${PKGFILE}"
  3118.       [ "$pkg_size" = '' ] && pkg_size="`du -s -k "$PKGFILE" | cut -f1`K"
  3119.       [ "$pkg_size" = '' ] && pkg_size="`grep -m1 "|${PKGNAME_ONLY}|" "${SPEC_DB_PATHS[@]" | cut -f6 -d'|' | head -1`"
  3120.  
  3121.  
  3122.       # create msg for downloaded pkgs
  3123.       MSG="Name:           ${PKGNAME}
  3124. Size:           ${pkg_size:-Unknown}
  3125. Status:         Downloaded
  3126. Note:           Downloaded package, not in any repo.
  3127. $DEPS_ENTRY"
  3128.  
  3129.     # else, search for exact match, then pkg-*, then pkg_*, then pkg* in installed pkgs
  3130.     elif [ "$(grep -m1 "|${PKGNAME_ONLY}|" "$USER_INST_PKGS_FILE" 2>/dev/null)"   \
  3131.       -o "$(grep -m1 "^${PKGNAME}|" "$USER_INST_PKGS_FILE" 2>/dev/null)"   \
  3132.       -o "`grep -m1 "^${PKGNAME}|" "${SPEC_DB_PATHS[@]" 2>/dev/null`"   \
  3133.       -o "`grep -m1 "^${PKGNAME}-" "${SPEC_DB_PATHS[@]" 2>/dev/null`" \
  3134.       -o "`grep -m1 "^${PKGNAME}_" "${SPEC_DB_PATHS[@]" 2>/dev/null`" \
  3135.       -o "`grep -m1 "^${PKGNAME}" "${SPEC_DB_PATHS[@]" 2>/dev/null`" ]; then
  3136.  
  3137.       # get deps and size from its entry in user-installed-packages
  3138.       DEPS_ENTRY="Dependencies:   `grep -m1 "^$PKGNAME" "$USER_INST_PKGS_FILE" | cut -f9 -d'|' | sed -e 's/,+/,/g' -e 's/^+//g' -e 's/,$//g' 2>/dev/null`"
  3139.       [ "$DEPS_ENTRY" = '' ] && DEPS_ENTRY="Dependencies:   `grep -m1 "^$PKGNAME" "${SPEC_DB_PATHS[@]" | cut -f9 -d'|' | sed -e 's/,+/,/' -e 's/^+//' -e 's/,$//' 2>/dev/null`"
  3140.       pkg_size=`LANG=C grep -m1 "|$PKGNAME_ONLY|" "${SPEC_DB_PATHS[@]" | cut -f6 -d'|' | head -1`
  3141.       # add K to end of pkg_size, if not there already
  3142.       [ "$pkg_size" != '' ] && pkg_size="${pkg_size}K" && pkg_size="${pkg_size//KK/K}"
  3143.  
  3144.       # create msg for user installed pkgs
  3145.       MSG="Name:      ${PKGNAME}
  3146. Size:           ${pkg_size:-Unknown}
  3147. Status:         ${install_status}
  3148. Repo:           Alien package, not in any repo.
  3149. $DEPS_ENTRY"
  3150.  
  3151.     else # pkg wasn't found, it's unknown to Pkg
  3152.       MSG="$PKGNAME not found.
  3153.  
  3154. Here are some packages in other repos:"
  3155.       PLIST="`which_repo ${PKGNAME}`"
  3156.       [ "$PLIST" != "" ] && MSG="$MSG
  3157. $PLIST"
  3158.       # create msg for alien pkgs
  3159.       MSG="$MSG
  3160.  
  3161. Name:           ${PKGNAME}
  3162. Status:         ${install_status:-Unknown}
  3163. Repo:           Alien package, not in $REPONAME repo.
  3164. $DEPS_ENTRY"
  3165.  
  3166.     fi
  3167.  
  3168.   fi
  3169.  
  3170.   # print message
  3171.   if [ "$MSG" != "" ]; then
  3172.     # now output the final msg
  3173.     echo -e "$MSG" | grep -v ^$
  3174.     menu_entry_msg "$PKGNAME"
  3175.     echo
  3176.   else
  3177.     not_found "${PKGNAME}"
  3178.     exit 1
  3179.   fi
  3180. }
  3181.  
  3182.  
  3183. # pkg creation funcs
  3184.  
  3185. prepare_petbuild(){               # get 01mickos petbuild system from Git, if needed FUNCLIST
  3186.  
  3187.   local gitcheck=`which git`
  3188.  
  3189.   # exit if no devx
  3190.   [ "`which gcc`" = '' ] \
  3191.     && echo "You need the devx SFS installed to compile packages." \
  3192.     && rm /tmp/pkg/petbuild_prepared 2>/dev/null \
  3193.     && exit 3
  3194.  
  3195.   # exit if no git
  3196.   [ "`$gitcheck`" = '' ] \
  3197.     && echo "You need git installed to auto-install petbuild." \
  3198.     && rm /tmp/pkg/petbuild_prepared 2>/dev/null \
  3199.     && exit 3
  3200.  
  3201.   if [ ! -d /usr/share/petbuild ]; then
  3202.     rm /tmp/pkg/petbuild_prepared 2>/dev/null && exit 1
  3203.   fi
  3204.  
  3205.   # if petbuild prepared flag not yet set
  3206.   if [ ! -f /tmp/pkg/petbuild_prepared ]; then
  3207.  
  3208.     # backup old petbuild if installed
  3209.     [ -d /usr/share/petbuild/ ] && mv /usr/share/petbuild/ /usr/share/petbuild.backup/ 2>/dev/null
  3210.  
  3211.     # remove the original petbuild dir (we have a backup)
  3212.     if [ -d /usr/share/petbuild.backup/ ]; then
  3213.       rm -rf /usr/share/petbuild 2>/dev/null
  3214.     fi
  3215.  
  3216.     # clone petbuild into /usr/share/petbuild
  3217.     git clone https://github.com/puppylinux-woof-CE/petbuilds.git /usr/share/petbuild &>/dev/null
  3218.  
  3219.     # if still no petbuild dir in /usr/share, tell user to install themselves
  3220.     if [ ! -d /usr/share/petbuild ]; then
  3221.       echo >&2
  3222.       echo "Run this command to download PetBuild:" >&2
  3223.       echo >&2
  3224.       echo -e " ${green}git clone https://github.com/puppylinux-woof-CE/petbuilds /usr/share/petbuild${endcolour}" >&2
  3225.       echo >&2
  3226.       echo "Alternatively, use a different build tool backend by changing BUILDTOOL= " >&2
  3227.       echo "to one of the options below, in the $PKGRC file:" >&2
  3228.       echo "petbuild, buildpet, sbopkg or src2pkg" >&2
  3229.       echo >&2
  3230.  
  3231.       exit 1
  3232.     fi
  3233.  
  3234.     # go into buildpet dir, check which Pup we have ($DISTRO_DB_SUBNAME)
  3235.     # and checkout the right branch for the running system
  3236.     cd /usr/share/petbuild
  3237.  
  3238.     # check the puppy running and checkout the relevant branch
  3239.     if [ "`echo $DISTRO_DB_SUBNAME | grep slacko`" != '' ]; then
  3240.       if [ "`echo $DISTRO_DB_SUBNAME | grep '14.2'`" != '' ]; then
  3241.         git checkout slacko_142
  3242.       else
  3243.         git checkout slacko_141
  3244.       fi
  3245.     elif [ "`echo $DISTRO_DB_SUBNAME | grep tahrpup`" ]; then
  3246.       git checkout tahrpup
  3247.     elif [ "`echo $DISTRO_DB_SUBNAME | grep stretch`" ]; then
  3248.       git checkout stretch || git checkout tahrpup
  3249.     elif [ "`echo $DISTRO_DB_SUBNAME | grep xenialpup`" ]; then
  3250.       git checkout xenialpup || git checkout tahrpup
  3251.     elif [ "$DISTRO_DB_SUBNAME" != '' ]; then
  3252.       git checkout tahrpup
  3253.     else
  3254.       echo "No pet builds available for your system ($DISTRO_DB_SUBNAME),"
  3255.       echo "using buildpet instead.."
  3256.       rm -rf /usr/share/petbuild 2>/dev/null
  3257.     fi
  3258.  
  3259.     # buildpet setup finished, create flag
  3260.     echo 'true' > /tmp/pkg/petbuild_prepared
  3261.  
  3262.     cd "$CURDIR"
  3263.   fi
  3264. }
  3265.  
  3266.  
  3267. pkg_build(){                      # build package ($1) from source (see BUILDTOOL in pkgrc) FUNCLIST
  3268.  
  3269.   # exit if devx not installed
  3270.   [ "`which gcc`" = "" ]   && echo "You need the devx SFS installed to compile." && exit 1
  3271.  
  3272.   # get the settins from RC file
  3273.   . ${PKGRC}
  3274.  
  3275.   # we do a different build method for each supported build tool
  3276.   case $BUILDTOOL in
  3277.  
  3278.     petbuild) # by 01micko
  3279.  
  3280.       # use git to install the latest petbuild
  3281.       prepare_petbuild
  3282.  
  3283.       # if petbuild not installed, quit
  3284.       [ ! -d /usr/share/petbuild ] && error "PetBuild not installed at /usr/share/petbuild." && exit 3
  3285.  
  3286.       # petbuild needs a package name, or exit
  3287.       [ ! "$1" -o "$1" = "-" ] && print_usage pkg-build && exit 1 #220613 #250613
  3288.  
  3289.       # get pkg extension
  3290.       EX=`get_pkg_ext "$1"`
  3291.  
  3292.       # get pkg name only, no extension or path
  3293.       PKGNAME="$(basename "$1" .$EX)"
  3294.  
  3295.       # get petbuild PKGNAME, then build using 01mickos petbuild
  3296.       BUILDSCRIPT="`find /usr/share/petbuild -iname ${PKGNAME}"*.petbuild"| grep -m1 "$PKGNAME"`"
  3297.  
  3298.       # if we got a build script
  3299.       if [ -f "$BUILDSCRIPT" ]; then
  3300.         cd `dirname "$BUILDSCRIPT"`
  3301.         # compile the pkg
  3302.         bash *.petbuild
  3303.         # after build, move any pets created to WORKDIR
  3304.         mv /usr/share/petbuild/0pets_out/*.pet "$WORKDIR" 2>/dev/null
  3305.         # back to prev dir (WORKDIR)
  3306.         cd -
  3307.       fi
  3308.  
  3309.       # if build script not found, exit
  3310.       [ ! -f "$BUILDSCRIPT" ] && echo "Build script for '$PKGNAME' not found in /usr/share/petbuild/" && exit 1
  3311.  
  3312.       # get the packages we just moved to WORKDIR
  3313.       PKGFILES="`find "$WORKDIR" -iname "$PKGNAME*.pet"`"
  3314.  
  3315.       # list any packages we just built
  3316.       [ "$PKGFILES" != '' ] && echo -e "${green}Success:${endcolour} Packages in $WORKDIR:" && echo "$PKGFILES"
  3317.     ;;
  3318.  
  3319.     buildpet) # by Tman/iguleder
  3320.  
  3321.       # exit if buildpet dir not found
  3322.       [ ! -d /usr/share/buildpet ] && error "buildpet not installed." && exit 1
  3323.  
  3324.       # buildpet expects a PKGNAME, or exit
  3325.       [ ! "$1" -o "$1" = "-" ] && print_usage pkg-build && exit 1
  3326.  
  3327.       # get pkg extension
  3328.       EX=`get_pkg_ext "$1"`
  3329.  
  3330.       # get pkg name (with version), no extension or path
  3331.       PKGNAME="$(basename "$1" .$EX)"
  3332.  
  3333.       # get the buildpet script of PKGNAME
  3334.       BUILDSCRIPT="`find /usr/share/buildpet/ -name $PKGNAME"*"`"
  3335.  
  3336.       # if build script not found, exit
  3337.       [ ! -f "$BUILDSCRIPT" ] && echo "Build script for '$PKGNAME' not found in /usr/share/buildpet/" && exit 1
  3338.  
  3339.       # now compile the package
  3340.       PKG_CONFIGURE="$PKG_CONFIGURE" PKG_CFLAGS="$PKG_CFLAGS" buildpet $BUILDSCRIPT
  3341.  
  3342.     ;;
  3343.  
  3344.     src2pkg)  # by amigo
  3345.  
  3346.       ### This code is a horribly simple wrapper to a great tool..
  3347.       ### Implement all src2pkg options here at some point..
  3348.       ##
  3349.       ### We should pass all options to src2pkg, and make it build a
  3350.       ### (petbuild|buildpet) buildscipt on successful compile
  3351.  
  3352.       # exit if src2pkg not installed
  3353.       [ "`which src2pkg`" = '' ] && error "src2pkg not installed." && error "Get it from http://distro.ibiblio.org/amigolinux/download/src2pkg/src2pkg-3.0-noarch-2.txz" && exit 3
  3354.  
  3355.       # exit if $1 not given or valid
  3356.       [ ! "$1" -o "$1" = "-" ]   && print_usage pkg-build && exit 1
  3357.  
  3358.       # show src2pkg help if user supplied any of the help options
  3359.       if [ "$1" = '-h'  -o "$1" = '-hh'  -o "$1" = '--help' -o "$1" = '--more-help' -o "$1" = '--list' ]; then
  3360.         src2pkg $1 | sed -e "s/  src2pkg /  $SELF -pb /g"
  3361.         echo -e "\n   See 'src2pkg' by amigo"
  3362.         exit 0
  3363.       fi
  3364.  
  3365.       # get pkg extension.. not really needed here
  3366.       EX=`get_pkg_ext "$1"`
  3367.  
  3368.       # use amigos src2pkg
  3369.       src2pkg $1
  3370.  
  3371.       # if src2pkg exited without error, copy any pets it made to WORKDIR
  3372.       [ $? -eq 0 ] && mv /tmp/*.pet "$WORKDIR" 2>/dev/null
  3373.  
  3374.     ;;
  3375.  
  3376.     sbopkg)   # slackware peeps
  3377.  
  3378.       # exit if not installed
  3379.       [ "`which sbopkg`" = '' ] && error "Sbopkg not installed." && exit 3
  3380.  
  3381.       # exit if no valid options
  3382.       [ ! "$1" -o "$1" = "-" ]  && print_usage pkg-build && exit 1
  3383.  
  3384.       sbopkg -b "$1"
  3385.  
  3386.       # move any built pkgs to WORKDIR.. need a better way to do this
  3387.       if [ "`find /tmp/* -iname $1*.t*`" != '' ]; then
  3388.         mv /tmp/*.tgz "$WORKDIR" 2>/dev/null
  3389.         mv /tmp/*.txz "$WORKDIR" 2>/dev/null
  3390.         mv /tmp/*.tar.xz "$WORKDIR" 2>/dev/null
  3391.         echo -e "DONE... The package should be in $WORKDIR."
  3392.       fi
  3393.  
  3394.     ;;
  3395.  
  3396.   *)
  3397.     # get pkg name only, no extension or path
  3398.     PKGNAME="$(basename "$1" .$EX)"
  3399.  
  3400.     echo "Cannot compile '$PKGNAME', no build system installed."
  3401.     echo
  3402.     echo "Please install one of the following:"
  3403.     echo " * petbuild by 01micko: http://murga-linux.com/puppy/viewtopic.php?t=96027"
  3404.     echo " * buildpet by Tman:    http://murga-linux.com/puppy/viewtopic.php?t=81056"
  3405.     echo " * src2pkg  by amigo:   http://distro.ibiblio.org/amigolinux/download/src2pkg/"
  3406.     echo " * sbopkg   by various: https://www.sbopkg.org/downloads.php"
  3407.     echo
  3408.     echo "Then set BUILDTOOL to either petbuild, buildpet, src2pkg or sbopkg "
  3409.     echo "in $PKGRC to enable building packages from source."
  3410.     echo
  3411.     echo "NOTE:"
  3412.     echo "01mickos petbuild should be installed to /usr/share/petbuild"
  3413.     echo "And Tmans buildpet should be installed to /usr/share/buildpet"
  3414.   ;;
  3415.   esac
  3416. }
  3417.  
  3418.  
  3419. pkg_repack(){                     # create package ($1) from its *.files list FUNCLIST
  3420.  
  3421.   # exit if no valid options
  3422.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-repack && exit 1
  3423.  
  3424.   local list=''
  3425.   local pkg_ext=''
  3426.   local PKGNAME=''
  3427.   local PKGNAME_ONLY=''
  3428.   local dir=''
  3429.   local build_number=''
  3430.  
  3431.   # get pkg extension
  3432.   pkg_ext=`get_pkg_ext "$1"`
  3433.  
  3434.   #get pkg name only, no extension or path
  3435.   PKGNAME="$(LANG=C basename "$1" .$pkg_ext)"
  3436.  
  3437.   # assume the file name from $1
  3438.   PKGFILE="${CURDIR}/${PKGNAME}.$pkg_ext"
  3439.  
  3440.   # don't rely on the given pkg name string, get the full name from repo if poss
  3441.   PKGNAME=`get_pkg_name "$PKGNAME"`
  3442.  
  3443.   # get pkg name without version
  3444.   PKGNAME_ONLY="`get_pkg_name_only "${PKGNAME}"`"
  3445.  
  3446.   # if the list is empty, pkg is not user installed or built in, cant show contents
  3447.   [ "`is_installed_pkg "$PKGNAME"`" = false ] && echo "$PKGNAME needs to be installed." && exit 1
  3448.  
  3449.   # if the package to built already exists, ask user to delete it
  3450.   [ -f "${PKGFILE}" ] && echo "$PKGNAME.$pkg_ext already exists in $CURDIR" && rm -f "${PKGFILE}" 2>/dev/null
  3451.  
  3452.   # if pkg exists, user didn't delete it
  3453.   [ -f "${PKGFILE}" ] && exit 0
  3454.  
  3455.   # get the build number, and increment by one
  3456.   build_number="`grep -m1 "^$PKGNAME|$PKGNAME_ONLY|" "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "$DEVX_INST_PKGS_FILE" "$REPO_DB_FILE_DIR"/Packages-* | cut -f4 -d'|'`"
  3457.   build_number=${build_number:-0}
  3458.   build_number="-$(($build_number + 1))"
  3459.  
  3460.   # process the file list, copy each file to our pkg folder
  3461.   pkg_contents "$PKGNAME_ONLY" | while read line
  3462.   do
  3463.     if [ -f "$line" ]; then
  3464.       linedir="$(dirname "${line}")"
  3465.       [ ! -d "${CURDIR}/$PKGNAME/${linedir}" ] && mkdir -p "${CURDIR}/$PKGNAME/${linedir}"
  3466.       cp -p -P "$line" "${CURDIR}/${PKGNAME}/${linedir}"
  3467.     fi
  3468.   done
  3469.  
  3470.   sync
  3471.  
  3472.   # make sure we populated a pkg folder, ready to package up
  3473.   [ ! -d "${CURDIR}/${PKGNAME}/" ] && error "No '$PKGNAME' directory in $CURDIR" && exit 5
  3474.  
  3475.   # pkg folder should be populated, now package it up and print final msg
  3476.   dir2pet "${CURDIR}/${PKGNAME}/" "$build_number"
  3477.   rm -rf "${CURDIR}/${PKGNAME}/" 2>/dev/null
  3478.   rm -rf "${CURDIR}/${PKGNAME}$build_number/" 2>/dev/null
  3479.   sync
  3480. }
  3481.  
  3482.  
  3483. pkg_unpack(){                     # extract/unpack $1 to current dir FUNCLIST
  3484.  
  3485.   # exit if not valid usage
  3486.   [ ! -f "$1" ] && print_usage unpack && exit 1
  3487.  
  3488.   local PKGNAME
  3489.   local PKGFILE
  3490.   local PKGEXT
  3491.   local comp
  3492.  
  3493.   # get pkg details
  3494.   PKGFILE="$1"
  3495.   PKGNAME=`get_pkg_name "$PKGFILE"`
  3496.   PKGEXT=`get_pkg_ext "$PKGFILE"`
  3497.  
  3498.   # exit if we dont have enough info
  3499.   [ "$PKGEXT" = '' ]  && error "Cant get package extension" && exit 1
  3500.   [ ! -f "$PKGFILE" ] && error "Cant find $1" && exit 6
  3501.   [ "$PKGNAME" = '' ] && error "Cant get PKGNAME" && exit 3
  3502.  
  3503.   # support overriding the output dir with $2
  3504.   if [ "$2" != "" ]; then
  3505.     PKGNAME="$2"
  3506.   fi
  3507.  
  3508.   # determine compression utility
  3509.   case $PKGEXT in
  3510.  
  3511.     deb)
  3512.       mkdir "$PKGNAME" 2>/dev/null
  3513.       rm -rf "$PKGNAME"/* 2>/dev/null
  3514.       dpkg-deb -x "$PKGFILE" "$PKGNAME"    # extracts main pkg contents
  3515.       result=$?
  3516.       dpkg-deb -e "$PKGFILE" "$PKGNAME"/DEBIAN # extracts deb control files
  3517.       [ $result -eq 0 ] && echo -e "${green}Extracted${endcolour}: ${magenta}`basename $PKGFILE`${endcolour}" || error -e "${red}Error${endcolour}: Cannot extract $PKGFILE"
  3518.       return $result
  3519.       ;;
  3520.  
  3521.     rpm)
  3522.       mkdir "${PKGNAME}" 2>/dev/null
  3523.       rm -rf "$PKGNAME"/* 2>/dev/null
  3524.       # create dir called $PKGNAME, cd into it, extract the rpm in there
  3525.       cp "$PKGFILE" "$PKGNAME/"
  3526.       cd "$PKGNAME" 1>/dev/null
  3527.       # now extract the rpm contents into current dir
  3528.       exploderpm -x "$PKGFILE" &>/dev/null
  3529.       result=$?
  3530.       # clean up and leave
  3531.       rm -f *.rpm 2>/dev/null
  3532.       cd - 1>/dev/null
  3533.       # final msg
  3534.       [ $result -eq 0 ] && echo -e "${green}Success${endcolour}: File ${magenta}`basename $PKGFILE`${endcolour} extracted." || error "Cannot extract $PKGFILE"
  3535.       return $result
  3536.       ;;
  3537.  
  3538.     sfs)
  3539.  
  3540.       mkdir "/${PKGNAME}" 2>/dev/null
  3541.       rm -rf "$PKGNAME"/* 2>/dev/null
  3542.  
  3543.       # make mnt dir, mount sfs
  3544.       mkdir "/mnt/${PKGNAME}" 2>/dev/null
  3545.       mount -t squashfs "$PKGFILE" /mnt/"$PKGNAME" -o loop 1>/dev/null || { error "Could not mount $PKGFILE"; exit 3; }
  3546.       # copy sfs contents into ./$PKGNAME
  3547.       cp -a -Rf --remove-destination /mnt/"$PKGNAME" "$PKGNAME" || { error "Failed copying files from /mnt/$PKGNAME to ./$PKGNAME"; exit 4; }
  3548.       result=$?
  3549.       # clean up
  3550.       umount "/mnt/${PKGNAME}"
  3551.       rmdir "/mnt/${PKGNAME}"
  3552.       # final msg
  3553.       [ $result -eq 0 ] && echo -e "${green}Success${endcolour}: File ${magenta}`basename $PKGFILE`${endcolour} extracted." || { error "Cannot extract $PKGFILE"; exit 7; }
  3554.       return $result
  3555.       ;;
  3556.     pet)  file -b "$PKGFILE" | grep -i -q "^xz" && comp=xz || comp=gzip ;;
  3557.     tgz)  comp=gzip ;;
  3558.     gz)   comp=gzip ;;
  3559.     tbz)  comp=bzip2 ;;
  3560.     bz2)  comp=bzip2 ;;
  3561.     tlz)  comp=lzma ;;
  3562.     lzma) comp=lzma ;;
  3563.     txz)  comp=xz ;;
  3564.     xz)   comp=xz ;;
  3565.   esac
  3566.   sync
  3567.  
  3568.   # if pkg is extractable with tar, then unpack
  3569.   case $PKGEXT in
  3570.   pet|tgz|gz|tbz|bz2|tlz|lzma|txz|xz)
  3571.     ( umask 000 ; cat "$PKGFILE" | $comp -dc 2>/dev/null | tar -xf - 2> /dev/null && echo -e "${green}Success${endcolour}: File ${magenta}`basename $PKGFILE`${endcolour} extracted." || error "Cannot extract $PKGFILE" )
  3572.     ;;
  3573.   esac
  3574.  
  3575.   # return
  3576.   return ${result:-0}
  3577.  
  3578. }
  3579.  
  3580.  
  3581. pkg_combine(){                    # combine a pkg ($1) and deps into one single pkg FUNCLIST
  3582.  
  3583.   # exit if no valid options
  3584.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-combine && exit 1
  3585.  
  3586.   . ${PKGRC}
  3587.  
  3588.   local EX=''
  3589.   local PKGNAME=''
  3590.   local PKGNAME_ONLY=''
  3591.   local PKG_FILENAME=''
  3592.   local PKG_FILE=''
  3593.   local ALL_DEPS=''
  3594.   local PKG_DEPLIST=''
  3595.   local SUFFIX="${CP_SUFFIX}"
  3596.   local BUILD_DIR=$TMPDIR/build_pkg
  3597.   local SFS_FILE
  3598.   local please_wait=false
  3599.   local PREVDIR="$CURDIR"
  3600.   local ask_opt=$ASK
  3601.   local force_opt=$FORCE
  3602.  
  3603.   cd "$WORKDIR"
  3604.  
  3605.   # get pkg extension
  3606.   EX=`get_pkg_ext "$1"`
  3607.  
  3608.   # get reliable package names
  3609.   PKGNAME="$(basename "$1" .$EX)"
  3610.   PKGNAME=`get_pkg_name "$PKGNAME"`
  3611.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  3612.  
  3613.   PKG_FILE="${WORKDIR}/${PKGNAME}.$EX" #the file to install
  3614.  
  3615.   # we want to include all deps, except builtins, by default
  3616.   # we dont set HIDE_BUILTINS here, we leave that up to user
  3617.   # when user gives -F, HIDE_BUILTINS= false, and builtin
  3618.   # pkgs will be included in the package created
  3619.   FORCE=true
  3620.   HIDE_USER_PKGS=false
  3621.  
  3622.   # get full pkg filename (inc name-ver.ext).. try repos first
  3623.   PKG_FILENAME="`cut -f8 -d'|' "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "^$PKGNAME"`"
  3624.   # then WORKDIR if needed (dont include the combined pkgs)
  3625.   [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="`ls -1 "$WORKDIR" | grep -v "${SUFFIX}" | grep -v ".sfs\$" | grep -m1 "^$PKGNAME"`"
  3626.  
  3627.   # just in case its empty, revert back to the earlier PKGNAME value
  3628.   [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="$PKGNAME"
  3629.  
  3630.   [ "$PKG_FILENAME" = "" ] && error "Cant find $1" && exit 1
  3631.  
  3632.   # update PKGFILE with new pkg filename (PKG)
  3633.   PKG_FILE="${WORKDIR}/${PKG_FILENAME}"
  3634.  
  3635.   # check if the desired file has already been built
  3636.   [ "$COMBINE2SFS" = true ] && final_ext=sfs || final_ext=pet
  3637.   [ -f "${WORKDIR}/${PKGNAME}-${SUFFIX}.$final_ext" ] && echo -e "File ${magenta}${WORKDIR}/${PKGNAME}-${SUFFIX}.${final_ext}${endcolour} already exists." && continue
  3638.  
  3639.   # get list of deps for PKGNAME, if no deps, exit
  3640.   PKG_DEPLIST="`FORCE=$force_opt list_deps $PKGNAME_ONLY`"
  3641.   [ "$PKG_DEPLIST" = "" ] && echo "No need to combine, $PKGNAME has no dependencies." && exit 1
  3642.  
  3643.   # if exact match of pkgname is found in a repo list
  3644.   if [ "`is_repo_pkg "$PKGNAME"`" = true ]; then
  3645.  
  3646.     echo "Please wait.. Gathering dependency information."
  3647.  
  3648.     # get the deps of the pkg, but dont install
  3649.     FORCE=$force_opt find_deps "$PKGNAME"
  3650.     ALL_DEPS="`cat $TMPDIR/deps_installed $TMPDIR/deps_missing 2>/dev/null | sort | uniq`"
  3651.  
  3652.     # download the needed package
  3653.     if [ ! -f "$PKG_FILE" -o "$FORCE" = true ]; then
  3654.       ASK=false pkg_download "$PKGNAME"
  3655.     fi
  3656.  
  3657.     # make work dirs
  3658.     mkdir -p "$BUILD_DIR/"
  3659.     mkdir -p "$BUILD_DIR/${PKGNAME}-${SUFFIX}"
  3660.  
  3661.     if [ -f "$PKG_FILE" ]; then
  3662.       # copy the main pkg to the tmp dir
  3663.       # and remove the downloade file, we no longer need it
  3664.       cp "$PKG_FILE" "$BUILD_DIR/" 2>/dev/null && rm "$PKG_FILE"
  3665.     else
  3666.        error "Could not add the main package '$PKGNAME_ONLY'"
  3667.     fi
  3668.  
  3669.  
  3670.     # make a cleaned list to go over (sanity check)
  3671.     ALL_DEPS_LIST="`echo "$ALL_DEPS" | tr ',' '\n' | grep -v "^\$" | sort | uniq`"
  3672.  
  3673.     # go through each dep listed
  3674.     echo "$ALL_DEPS_LIST" | while read LINE
  3675.     do
  3676.  
  3677.       [ "$LINE" = "" -o "$LINE" = "-" -o "$LINE" = " " -o "$LINE" = "," -o "$LINE" = ", " ] && continue
  3678.  
  3679.       # only include builtins if HIDE_BUILTINS=true
  3680.       [ "`is_builtin_pkg "$LINE"`" = true -a "$HIDE_BUILTINS" = true ] && continue
  3681.  
  3682.       # only include devx pkgs if user gave the -f option
  3683.       [ "`is_devx_pkg "$LINE"`" = true -a "$force_opt" = false ] && continue
  3684.  
  3685.       # download the matching package(s)
  3686.       [ "`list_downloaded_pkgs "$LINE"`" = "" ] && ASK=false pkg_download "$LINE"
  3687.  
  3688.       # get the downloaded file
  3689.       PKGDEP="`find "$WORKDIR" -maxdepth 1 -type f -name "${LINE}*" | grep -v ".sfs\$" | grep -v "${SUFFIX}" | head -1`"
  3690.  
  3691.       # re-try download in other repos if needed
  3692.       if [ ! -f "$PKGDEP" ]; then
  3693.         PKGREPO=''; PKGREPO="`LANG=C which_repo $LINE | cut -f2 -d' ' | head -1`"
  3694.         [ "$PKGREPO" != "" ] && ASK=false pkg_download "$LINE"
  3695.       fi
  3696.  
  3697.       #if downloaded
  3698.       if [ -f "$PKGDEP" -o "$FORCE" = true ]; then
  3699.  
  3700.         # copy dep to the tmp dir, with the main pkg
  3701.         if [ ! -f "$BUILD_DIR/$PKGDEP" ]; then
  3702.           cp "$PKGDEP" "$BUILD_DIR/$(basename $PKGDEP)" && rm "$PKGDEP"
  3703.         else
  3704.           error "Cannot copy $PKGDEP to $BUILD_DIR/$(basename $PKGDEP)"
  3705.         fi
  3706.  
  3707.       else # dep not found, may be missing, or in another repo
  3708.         echo -e "${yellow}Warning:${endcolour} $LINE not downloaded to $WORKDIR.. Cannot add $LINE.."
  3709.         continue
  3710.       fi
  3711.     done
  3712.  
  3713.     # we should now be ready to make our combined pkg
  3714.     cd "$BUILD_DIR"
  3715.  
  3716.     PARENTPKG=${PKGNAME}
  3717.  
  3718.     # for all pkgs in the tmp dir (nto including any 'combined' pkgs)
  3719.     TMP_PKGS="`find "$BUILD_DIR/" -maxdepth 1 -type f -name "*" | grep -v $SUFFIX | grep -v ^$ | grep -v ' ' | sort | uniq`"
  3720.  
  3721.     local count=1
  3722.  
  3723.     for i in $TMP_PKGS
  3724.     do
  3725.  
  3726.       # skip if not a valid pkg file
  3727.       [ ! "$i" -o "$i" = ' ' -o "$i" = '' -o ! -f "$i" ] && continue
  3728.  
  3729.       # dont include the combined pkgs
  3730.       [ "`echo "$i" | grep -m1 "${SUFFIX}"`" != "" ] && continue
  3731.  
  3732.       # get the extensions of each file .. they might be from different repos, so cant use $EX
  3733.       base="`basename "$i" 2>/dev/null`"
  3734.       FILE_EXT=`get_pkg_ext "$base"`
  3735.  
  3736.       [ ! "$base" -o "$base" = ' ' -o "$base" = '' ] && continue
  3737.  
  3738.       # get name without version for this pkg ($i)
  3739.       name_only=`get_pkg_name_only "$i"`
  3740.  
  3741.       [ ! "$name_only" -o "$name_only" = ' ' -o "$name_only" = '' ] && continue
  3742.  
  3743.       CONFIRM=y
  3744.       if [ "$ask_opt" = true ]; then
  3745.         echo -n "Add package: $name_only  ($FILE_EXT)  (y/N):  "
  3746.         read -n 1 CONFIRM </dev/tty
  3747.         echo
  3748.       else
  3749.         echo "Adding package: $name_only  ($FILE_EXT)"
  3750.       fi
  3751.  
  3752.       # skip pkg if user wants to skip it
  3753.       if [ "$CONFIRM" != 'y' ]; then
  3754.         rm "$i"
  3755.         continue
  3756.       fi
  3757.  
  3758.       # add each file
  3759.       case $FILE_EXT in
  3760.       pet)
  3761.  
  3762.         # convert and extract
  3763.         pkg_unpack "${i}" 1>/dev/null
  3764.         sync
  3765.  
  3766.         # copy extracted contents (only the stuff inside the extracted folders)
  3767.         if [ ! -d "${i/.pet/}/" ]; then
  3768.           error "Dir '${i/.pet/}/' does not exist"
  3769.         fi
  3770.         cp -a --preserve=all -fr -L "${i/.pet/}/"* "${PARENTPKG}-${SUFFIX}/"
  3771.  
  3772.         if [ -f "${i/.pet/}/pinstall.sh" ]; then
  3773.           mv "${i/.pet/}/pinstall.sh" "${PARENTPKG}-${SUFFIX}/pinstall_${count}.sh"
  3774.         fi
  3775.  
  3776.         # now remove the pet and extract folder
  3777.         rm "${i}"
  3778.         rm -rf "${i/.pet/}/"
  3779.         sync
  3780.         ;;
  3781.  
  3782.       deb)
  3783.  
  3784.         #cp "$i" "$BUILD_DIR/${PARENTPKG}-${SUFFIX}"
  3785.         pkg_unpack "$i" 2>$TMPDIR/$SELF-cp-errlog
  3786.         dpkg-deb -e "$i" "$BUILD_DIR/${PARENTPKG}-${SUFFIX}/DEBIAN"
  3787.  
  3788.         # .deb package names often have extra stuff at the end of the file name
  3789.         # that does not exist in the root folder name, inside the package.. so
  3790.         # we need to strip off that extra stuff to get the correct unpacked
  3791.         # package dir
  3792.         local pkg_dir="${i/.deb/}/"
  3793.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_all/}"
  3794.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_i386/}"
  3795.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_amd64/}"
  3796.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_x64/}"
  3797.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/~dfsg-[0-9]/}"
  3798.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/~dsfg-[0-9]/}"
  3799.  
  3800.         if [ ! -d "$pkg_dir" ]; then
  3801.           needle="$(get_pkg_name "$i")"
  3802.           pkg_dir="$(find "${BUILD_DIR}" -type d -iname "$needle" | head -1)"
  3803.         fi
  3804.  
  3805.         if [ ! -d "$pkg_dir" ]; then
  3806.           error "Dir '$pkg_dir' does not exist!"
  3807.         fi
  3808.  
  3809.         # copy extracted contents (only the stuff inside the extracted folders)
  3810.         cp -a --preserve=all -fr -L "${pkg_dir}/"* "${PARENTPKG}-${SUFFIX}/"
  3811.  
  3812.         if [ -f "${pkg_dir}DEBIAN/postinst" ]; then
  3813.           mv "${pkg_dir}DEBIAN/postinst" "${PARENTPKG}-${SUFFIX}/DEBIAN/postinst_${count}"
  3814.         fi
  3815.  
  3816.         if [ -f "${pkg_dir}DEBIAN/preinst" ]; then
  3817.           mv "${pkg_dir}DEBIAN/preinst" "${PARENTPKG}-${SUFFIX}/DEBIAN/preinst_${count}"
  3818.         fi
  3819.  
  3820.         # now remove the deb and extracted folder
  3821.         rm "$i"
  3822.         rm -rf "$pkg_dir"
  3823.         sync
  3824.         ;;
  3825.  
  3826.       *tgz|*txz|*tar.gz|*tar.xz|*xz|*gz)
  3827.  
  3828.         pkg_unpack "$i" 1>/dev/null
  3829.  
  3830.         # now copy $BUILD_DIR/$PKGNAME/* into our output (combined pkg) dir
  3831.         cp -a --preserve=all -fr -L "${name_only}/"* "${PARENTPKG}-${SUFFIX}/" || error "Dir '${name_only}/' does not exist!"
  3832.  
  3833.         if [ -f "${PARENTPKG}-${SUFFIX}/install/doinst.sh" ]; then
  3834.           mv "${PARENTPKG}-${SUFFIX}/install/doinst.sh" "${PARENTPKG}-${SUFFIX}/install/doinst_${count}.sh"
  3835.         fi
  3836.  
  3837.         # remove the package and folder we just extracted
  3838.         rm "$i"
  3839.         rm -rf "${i/.*/}/"
  3840.         sync
  3841.         ;;
  3842.  
  3843.       rpm)
  3844.         pkg_unpack "$i" 1>/dev/null
  3845.  
  3846.         # now copy $BUILD_DIR/$PKGNAME/* into our output (combined pkg) dir
  3847.         cp -a --preserve=all -fr -L "${name_only}/"* "${PARENTPKG}-${SUFFIX}/"
  3848.  
  3849.         if [ -f "${PARENTPKG}-${SUFFIX}/install/doinst.sh" ]; then
  3850.           mv "${PARENTPKG}-${SUFFIX}/install/doinst.sh" "${PARENTPKG}-${SUFFIX}/install/doinst_${count}.sh"
  3851.         fi
  3852.  
  3853.         # remove the package and folder we just extracted
  3854.         rm "$i"
  3855.         rm -rf "${i/.rpm/}/"
  3856.         ;;
  3857.  
  3858.       esac
  3859.       count=$(($count + 1))
  3860.     done
  3861.  
  3862.     # we have now unpacked the package, lets combine the pre/post install scripts
  3863.     # into one pinstall.sh script
  3864.  
  3865.     local pinstall_file="$BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh"
  3866.  
  3867.     # append this pinstall/postinst/doinst script to a new pinstall.sh
  3868.     echo '#!/bin/sh' > "$pinstall_file"
  3869.  
  3870.     # concat the post install scripts (for puppy, slackware, arch, debian/ubuntu, etc) into 'pinstall.sh'
  3871.     for i in ${PARENTPKG}-${SUFFIX}/pinstall_* ${PARENTPKG}-${SUFFIX}/install/doinst_* ${PARENTPKG}-${SUFFIX}/DEBIAN/postinst_*
  3872.     do
  3873.       [ -z ${PARENTPKG}-${SUFFIX}/${i} ] && continue
  3874.       cd ${PARENTPKG}-${SUFFIX}/ 2>/dev/null
  3875.  
  3876.       files=`find . -type f -iname "$(basename $i)"`
  3877.  
  3878.       for file in $files
  3879.       do
  3880.         if [ -f "$file" ]; then
  3881.           echo "Appending ${file} to $pinstall_file"
  3882.           cat ${file} | grep -vE '^#!|^exit|exit 0|exit 1' >> "$pinstall_file"
  3883.           echo '' >> "$pinstall_file"
  3884.         fi
  3885.       done
  3886.       # we have combined the pre/post install stuff in $i into a new, combined file,
  3887.       # so remove the original
  3888.       rm -f ${PARENTPKG}-${SUFFIX}/${i}
  3889.     done
  3890.  
  3891.     chmod +x $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh 2>/dev/null
  3892.  
  3893.     #xmessage "$(cat $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh)"
  3894.  
  3895.     # remove any debian/ubuntu/slackware pre/post install stuff left in the package
  3896.     rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall_*
  3897.     rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/install
  3898.     rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/DEBIAN
  3899.  
  3900.     # fix the symlinks to lib dirs - the linux-gnu-* dirs are symlinks in puppy,
  3901.     # so make sure we dont replace them with dirs (or programs won't load)
  3902.     for libdir in i386-linux-gnu i486-linux-gnu i586-linux-gnu i686-linux-gnu amd64-linux-gnu
  3903.     do
  3904.       if [ -d $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/${libdir}/ ]; then
  3905.         mv -n -u $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/${libdir}/* $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/
  3906.         cd $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib
  3907.         rmdir ${libdir}/
  3908.         ln -s ${libdir}/ .
  3909.         cd -
  3910.       fi
  3911.     done
  3912.  
  3913.  
  3914.     # now we are ready to build our combined pkg
  3915.     [ "`pwd`" != "$BUILD_DIR" ] && cd "$BUILD_DIR/"
  3916.  
  3917.  
  3918.     # if not building SFS, build a .pet
  3919.     if [ "$COMBINE2SFS" = false ]; then #240613
  3920.       echo "Building PET package.. Please wait.."
  3921.  
  3922.       # build pet package... start with $removing PKGNAME-${SUFFIX}.pet.specs
  3923.       rm ${PKGNAME}-${SUFFIX}/*.specs 2>/dev/null
  3924.  
  3925.       # get compression type
  3926.       file -b "${PKGNAME}-${SUFFIX}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  3927.  
  3928.       # tar up the folder
  3929.       tar -c -f ${PKGNAME}-${SUFFIX}.tar ${PKGNAME}-${SUFFIX} &>/dev/null
  3930.       sync
  3931.  
  3932.       case $TAREXT in
  3933.         xz)xz -z -9 -e ${PKGNAME}-${SUFFIX}.tar ;;
  3934.         gz)gzip --best ${PKGNAME}-${SUFFIX}.tar ;;
  3935.       esac
  3936.  
  3937.       TARBALL="${PKGNAME}-${SUFFIX}.tar.$TAREXT"
  3938.       FULLSIZE="`stat --format=%s ${TARBALL}`"
  3939.       MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  3940.       echo -n "$MD5SUM" >> $TARBALL
  3941.       sync
  3942.  
  3943.       mv -f $TARBALL ${PKGNAME}-${SUFFIX}.pet
  3944.       sync
  3945.  
  3946.       if [ $? -eq 1 ]; then
  3947.         echo "Cannot create PET file ${PKGNAME}-${SUFFIX} from dir."
  3948.         error "Please check `pwd`"
  3949.       fi
  3950.  
  3951.       # move our new PET to $WORKDIR
  3952.       mv ${PKGNAME}-${SUFFIX}.pet $WORKDIR/${PKGNAME}-${SUFFIX}.pet
  3953.       # get the size
  3954.       s=`LANG=C du -m "$WORKDIR/${PKGNAME}-${SUFFIX}.pet" | sed "s/\s.*//"`
  3955.  
  3956.     else #240613  build a .sfs
  3957.       echo "Building SFS package.. Please wait.."
  3958.  
  3959.       dir2sfs "${PKGNAME}-${SUFFIX}" 1>/dev/null
  3960.  
  3961.       # get the full file name, it may (or not) have been appended with '-DISTRO_VERSION'
  3962.       SFS_FILE=`find . -maxdepth 1 -type f -name "*${PKGNAME}-${SUFFIX}*.sfs" | head -1`
  3963.  
  3964.       s=`LANG=C du -m "${SFS_FILE}" | sed "s/\s.*//"`
  3965.       MD5SUM=`md5sum "$SFS_FILE" | cut -f1 -d ' '`
  3966.       mv "$SFS_FILE" "$WORKDIR/"
  3967.     fi
  3968.  
  3969.     # done, go back to work dir from WORKDIR/build_pkg
  3970.     cd "$WORKDIR"
  3971.     rm -R  "$BUILD_DIR/" 2>/dev/null
  3972.  
  3973.     # create install command
  3974.     if [ "$COMBINE2SFS" = false ]; then
  3975.       PKGEXT=pet
  3976.       PKGCMD="Install command: $SELF install ${WORKDIR}/${PKGNAME}-${SUFFIX}"
  3977.     else
  3978.       PKGEXT=sfs
  3979.       PKGCMD="Install command: sfs_loadr --cli -q \"${WORKDIR}/$(basename $SFS_FILE)\""
  3980.     fi
  3981.  
  3982.     #226013 updated output
  3983.     echo -e "Created package ${magenta}${PKGNAME}-${SUFFIX}.${PKGEXT}${endcolour} (${s}MB)"
  3984.     echo "The md5 checksum: $MD5SUM"
  3985.     echo "$PKGCMD"
  3986.  
  3987.   else # no exact PKGNAME match in repo
  3988.     not_found "${PKGNAME}"
  3989.     exit 1
  3990.   fi
  3991.  
  3992.   cd "$PREVDIR"
  3993. }
  3994.  
  3995.  
  3996. merge_pkg(){                      # merge the given comma-separated packages FUNCLIST
  3997.   # make sure at least 2 packages exist
  3998.  
  3999.   [ ! "$1" ] && print_usage merge && exit 1
  4000.   [ "$(echo "$1" |grep ',')" = "" ] && print_usage merge && exit 1
  4001.  
  4002.   cd "$WORKDIR" 1>/dev/null
  4003.  
  4004.   local PKG_LIST="$(echo "${1}" | tr ',' '\n' | sort -u | uniq)"
  4005.   local SUFFIX=''
  4006.  
  4007.   if [ "$2" = "--with-deps" ]; then
  4008.     SUFFIX="-WITHDEPS"
  4009.     echo "Gathering dependencies to include.."
  4010.     echo
  4011.     # add deps of pkgs to list of pkgs to merge
  4012.     for package in $PKG_LIST
  4013.     do
  4014.       PKG_LIST="$PKG_LIST $(pkg le $package)"
  4015.     done
  4016.     PKG_LIST="$(echo "$PKG_LIST" | tr ' ' '\n' | sort -u | uniq)"
  4017.   fi
  4018.  
  4019.   echo "Merging the following packages:"
  4020.   echo
  4021.   echo "${PKG_LIST}" | sed 's/^/  /g'
  4022.   echo
  4023.  
  4024.   # get a new package name for the new, merged package
  4025.   local PKGNAME="`get_pkg_name "$(basename "${1//,*/}")" 2>/dev/null`"
  4026.   bash -c 'read -e -r -p "Enter a package name and hit ENTER: " -i "${PKGNAME}-MERGED${SUFFIX}" NEWPKGNAME; echo $NEWPKGNAME > /tmp/pkg/NEWPKGNAME'
  4027.   echo
  4028.   NEWPKGNAME="$(cat /tmp/pkg/NEWPKGNAME)"
  4029.  
  4030.   if [ "$NEWPKGNAME" = "" ]; then
  4031.     echo "You must give a new package name!"
  4032.     return 1
  4033.   fi
  4034.  
  4035.   rm -rf "${NEWPKGNAME}/" &>/dev/null
  4036.   mkdir "${NEWPKGNAME}"
  4037.  
  4038.   # remove any old folders
  4039.   rm -rf ${WORKDIR}${NEWPKGNAME}/ &>/dev/null
  4040.  
  4041.   # for each package to merge
  4042.   for package in $PKG_LIST
  4043.   do
  4044.  
  4045.     # get the package details
  4046.     local PKGNAME="`get_pkg_name "$(basename "$package")" 2>/dev/null`"
  4047.     local PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME" 2>/dev/null`"
  4048.     local PKGEXT="`get_pkg_ext "$PKGNAME"`"
  4049.     local PKGFILE=''
  4050.  
  4051.     [ "$PKGNAME" = "" ] && continue
  4052.     [ "$PKGNAME" = " " ] && continue
  4053.     [ "$PKGNAME" = "-" ] && continue
  4054.  
  4055.     # download it
  4056.     pkg_download "$PKGNAME"
  4057.  
  4058.     retval=$?
  4059.  
  4060.     if [ $retval -eq 1 ]; then
  4061.       echo -e "${yellow}Warning${endcolour}: package '$PKGNAME' not downloaded."
  4062.       continue
  4063.     fi
  4064.  
  4065.     # get the downloaded file
  4066.     PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME}*${PKGEXT}")"
  4067.  
  4068.     [ ! -f "$PKGFILE" ] && \
  4069.       PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME_ONLY}_*${PKGEXT}")"
  4070.  
  4071.     [ ! -f "$PKGFILE" ] && \
  4072.       PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME_ONLY}-*${PKGEXT}")"
  4073.  
  4074.     if [ ! -f "$PKGFILE" ]; then
  4075.       echo -e "${red}Error${endcolour}: could not find downloaded package '$PKGFILE'"
  4076.       return 1
  4077.     fi
  4078.  
  4079.     # unpack the downloaded file
  4080.     pkg_unpack "$PKGFILE"
  4081.     rm "${PKGFILE}"
  4082.  
  4083.     # move the unpacked files into our new package dir
  4084.     PKGDIR="$(find $WORKDIR -maxdepth 1 -type d -name "${PKGNAME}*" | grep -v ${NEWPKGNAME})"
  4085.  
  4086.     if [ ! -d "$PKGDIR" ]; then
  4087.       echo -e "${red}Error${endcolour}: could not find extracted package dir '$PKGDIR'"
  4088.       return 1
  4089.     fi
  4090.  
  4091.     cp -R "$PKGDIR"/* "$NEWPKGNAME"
  4092.     rm -rf "${PKGDIR}/"
  4093.   done
  4094.  
  4095.   if [ ! -d "${WORKDIR}/$NEWPKGNAME" ]; then
  4096.     echo -e "${red}Error${endcolour}: Dir ${lightblue}${NEWPKGNAME}${endcolour} NOT created!"
  4097.     return 1
  4098.   fi
  4099.  
  4100.   echo
  4101.   echo "Package contents:"
  4102.   find "${NEWPKGNAME}/"
  4103.   echo '--------------------------------'
  4104.   echo
  4105.  
  4106.   # create the merged PET package
  4107.   dir2pet "${NEWPKGNAME}/" || error "Could not create $NEWPKGNAME} PET file"
  4108.  
  4109.   rm -rf "./${NEWPKGNAME}/" &>/dev/null
  4110.   rm -rf "${WORKDIR}/${NEWPKGNAME}/" &>/dev/null
  4111.  
  4112.   # get the filename of the new PET package
  4113.   NEWPKGFILENAME="$(find . -maxdepth 1 -type f -name "${NEWPKGNAME}*.pet")"
  4114.  
  4115.   # output messages
  4116.   if [ ! -f "$NEWPKGFILENAME" ]; then
  4117.     echo
  4118.     echo -e "${red}Error${endcolour}: Package ${yellow}${NEWPKGFILENAME}${endcolour} NOT created!"
  4119.     return 1
  4120.   fi
  4121.  
  4122.   return 0
  4123. }
  4124.  
  4125.  
  4126. split_pkg(){                      # split package ($1) into dev, doc, nls packages FUNCLIST
  4127.  
  4128.   # make sure the package exists
  4129.   [ ! "$1" -o ! -f "$1" ] && print_usage split && exit 1
  4130.  
  4131.   local PKGNAME="`get_pkg_name "$(basename "$1")" 2>/dev/null`"
  4132.   local PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME" 2>/dev/null`"
  4133.   local PKGEXT="pet"
  4134.  
  4135.   # get package extension
  4136.   PKGEXT="`get_pkg_ext "$1"`"
  4137.  
  4138.   pkg_unpack "$1" &>/dev/null
  4139.  
  4140.   # get the package directory we just extracted
  4141.   local PKG_PATH="$(find $(dirname "$PKGNAME") -maxdepth 1 -type d -iname "$PKGNAME" | head -1)"
  4142.  
  4143.   # get the full path to the package dir (dir with contents of pkg to be split)
  4144.   PKG_PATH="$(realpath "$PKG_PATH")"
  4145.  
  4146.   # make sure we have the right package dir
  4147.   [ ! -d "$PKG_PATH" ] && PKG_PATH="$(realpath "$PKGNAME")"
  4148.  
  4149.   # get the base name of the package directory
  4150.   local PKG_DIR_NAME=$(basename "$PKG_PATH")
  4151.  
  4152.   # get the package name
  4153.   local PKG_NAME="$PKGNAME_ONLY"
  4154.  
  4155.   # get the parent directory of the package
  4156.   local PARENT_DIR="$(dirname "$PKG_PATH")"
  4157.  
  4158.   # set the correct package naming style
  4159.   local dev_suffix='_DEV'
  4160.   local doc_suffix='_DOC'
  4161.   local nls_suffix='_NLS'
  4162.   if [ "${PKGEXT:-pet}" = "deb" ]; then
  4163.     dev_suffix='-dev'
  4164.     doc_suffix='-doc'
  4165.     nls_suffix='-nls'
  4166.   fi
  4167.  
  4168.   # get the sub-package names
  4169.   local EXE_PKG="$PKGNAME"
  4170.   local DEV_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${dev_suffix}/")"
  4171.   local DOC_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${doc_suffix}/")"
  4172.   local NLS_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${nls_suffix}/")"
  4173.  
  4174.   # remove the target package dirs if they already exist
  4175.   [ -d "$DEV_PKG" ] && rm -rf "$DEV_PKG"
  4176.   [ -d "$DOC_PKG" ] && rm -rf "$DOC_PKG"
  4177.   [ -d "$NLS_PKG" ] && rm -rf "$NLS_PKG"
  4178.   # now create them fresh and empty
  4179.   mkdir -p "$DEV_PKG"
  4180.   mkdir -p "$DOC_PKG"
  4181.   mkdir -p "$NLS_PKG"
  4182.  
  4183.   # make sure the package directory begins with the given package name
  4184.   case $(basename "$PKG_PATH") in
  4185.     $PKG_NAME*)
  4186.         ;;
  4187.     *)
  4188.         echo "Error: $(basename "$PKG_PATH") must match $PKG_NAME"
  4189.         print_usage split
  4190.         exit 1
  4191.         ;;
  4192.   esac
  4193.  
  4194.   cd "$PKG_PATH" &>/dev/null || { echo "Not found: $PKG_PATH"; return 1; }
  4195.  
  4196.   for i in $(find -mindepth 1)
  4197.   do
  4198.     # if the file no longer exists, skip this iteration
  4199.     [ ! -e "$i" ] && continue
  4200.  
  4201.     local FILE_NAME=$(basename "$i")
  4202.  
  4203.     case "$FILE_NAME" in
  4204.         *.la|*.a|*.o|*.prl|pkgconfig|include|*.m4|*.h|*.c|*.cpp)
  4205.             PKGNAME="$DEV_PKG"
  4206.             ;;
  4207.         gdb)
  4208.             [ -d "$i" ] && PKGNAME="$DEV_PKG"
  4209.             ;;
  4210.         dir)
  4211.             [ -f "$i" ] && PKGNAME="$DOC_PKG"
  4212.             ;;
  4213.         doc|*-doc|gtk-doc|Help|HELP|readme.*|README.*|ABOUT|about.txt|ABOUT.TXT|readme|README|manual|MANUAL|faq|FAQ|todo|TODO|examples|EXAMPLES|LessTif|man-html|E-docs)
  4214.             PKGNAME="$DOC_PKG"
  4215.             ;;
  4216.         help)
  4217.             [ -d "$i" ] && PKGNAME="$DOC_PKG"
  4218.             ;;
  4219.         man|info) # if it's a directory named "man" or "info", move to doc
  4220.             [ -d "$i" ] && PKGNAME="$DOC_PKG"
  4221.              ;;
  4222.         locale|locales|lang|strings) # if it's a directory named "locale", move to nls
  4223.             [ -d "$i" ] && PKGNAME="$NLS_PKG"
  4224.             ;;
  4225.         i18n|nls)
  4226.             PKGNAME="$NLS_PKG"
  4227.             ;;
  4228.         system.profile-*|*.strings|normal.awt-*) # AbiWord stores its locale information in those files
  4229.             [ "$PKGNAME_ONLY" = "abiword" ] && PKGNAME="$NLS_PKG"
  4230.             ;;
  4231.         *)
  4232.             PKGNAME="$EXE_PKG"
  4233.             ;;
  4234.     esac
  4235.  
  4236.     # verbosity, output the redirection for each redirected file
  4237.     case "$PKGNAME" in
  4238.         $DEV_PKG|$DOC_PKG|$NLS_PKG)
  4239.             #local SUFFIX="$(echo $SUFFIX | tr [:lower:] [:upper:])"
  4240.  
  4241.             #echo "$FILE_NAME -> $PKG"
  4242.  
  4243.             # detect the sub_directory inside the package
  4244.             local SUB_DIR="${i%/$FILE_NAME}"
  4245.             SUB_DIR="${SUB_DIR:2}"
  4246.  
  4247.             # create the directory under the sub-package directory
  4248.             mkdir -p "$PARENT_DIR/$PKGNAME/$SUB_DIR"
  4249.  
  4250.             # move the file to the sub-package
  4251.             mv "$i" "$PARENT_DIR/$PKGNAME/$SUB_DIR"
  4252.  
  4253.             # get rid of empty directories in the EXE package
  4254.             rmdir "$SUB_DIR" &>/dev/null
  4255.             ;;
  4256.     esac
  4257.  
  4258.   done
  4259.  
  4260.   # if the EXE package is empty, remove it
  4261.   is_empty="$(find "$PKG_PATH" -maxdepth 2 -type f 2>/dev/null)"
  4262.   [ -z "$is_empty" ] && rm -rf "$PKG_PATH"
  4263.  
  4264.   # go back to where we started (where the main package lives)
  4265.   [ -d "$CURDIR" ] && cd "$CURDIR" &>/dev/null
  4266.  
  4267.   # build each package from the package dir
  4268.   for dir in "$EXE_PKG" "$DEV_PKG" "$DOC_PKG" "$NLS_PKG"
  4269.   do
  4270.     if [ -d "$dir" ]; then
  4271.       dir2${PKGEXT//./} "$dir" && rm -rf "$dir"
  4272.     fi
  4273.   done
  4274.  
  4275.   # get a list of the new packages we created
  4276.   new_pkgs="$(find . -maxdepth 1 -type f -name "${PKGNAME}*.$PKGEXT"
  4277.  find . -maxdepth 1 -type f -name "${DEV_PKG}*.$PKGEXT"
  4278.  find . -maxdepth 1 -type f -name "${DOC_PKG}*.$PKGEXT"
  4279.  find . -maxdepth 1 -type f -name "${NLS_PKG}*.$PKGEXT")"
  4280.  
  4281.   if [ "$new_pkgs" != "" ]; then
  4282.     echo
  4283.     echo -e "${green}Success${endcolour}: Package split into these new files:"
  4284.     echo "$new_pkgs" | sed 's/^.\// /'
  4285.   fi
  4286.  
  4287.   # cleanup
  4288.   [ -d "$DEV_PKG" ] && rm -rf "$DEV_PKG"
  4289.   [ -d "$DOC_PKG" ] && rm -rf "$DOC_PKG"
  4290.   [ -d "$NLS_PKG" ] && rm -rf "$NLS_PKG"
  4291.  
  4292.   return 0
  4293. }
  4294.  
  4295.  
  4296.  
  4297. # main pkg funcs
  4298.  
  4299. pkg_download(){                   # download a pkg ($1) to WORKDIR FUNCLIST
  4300.  
  4301.   # exit if no valid options
  4302.   [ ! "$1" -o "$1" = "-" ] && print_usage download && exit 1
  4303.  
  4304.   . ${PKGRC}
  4305.  
  4306.   local pkg_ext=''        # extension of pkg, empty if not a supported pkg ext
  4307.   local PKGNAME=''        # the pkgname with version
  4308.   local ORIG_PKGNAME=''   # keeps the original pkg name ($1)
  4309.   local PKG_FILENAME=''   # package file name (field 8 of repo, with extension)
  4310.   local PKGFILE=''        # full path to package file
  4311.   local NET=''            # 1 or 0 if net connection available
  4312.   local curr_repo=''      # name of current repo in the loop
  4313.   local curr_repo_ext=''  # pkg ext for the current repo in the loop
  4314.   local prev_repo_url=''  # holder for the prev checked url we know is working
  4315.   local curr_repo_url=''  # mirror that is used to download the pkg
  4316.   local curr_repo_url1='' # mirror1 for the current repo in the loop
  4317.   local curr_repo_url2='' # mirror2 for the current repo in the loop
  4318.   local curr_repo_url3='' # mirror3 for the current repo in the loop
  4319.   local curr_repo_url4='' # mirror4 for the current repo in the loop
  4320.   local pkg_in_repo=''    # true if pkg found in ANY repo, else false
  4321.  
  4322.   # get pkg extension
  4323.   pkg_ext=`get_pkg_ext "$1"`
  4324.  
  4325.   # get pkg name with version (if given!), no extension or path
  4326.   PKGNAME="$(basename "$1" .$pkg_ext)"
  4327.  
  4328.   # get full package name from given pkg name string .. vlc -> vlc-1.2.3-blah
  4329.   PKGNAME=`get_pkg_name "$PKGNAME"`
  4330.  
  4331.   # the file to save to.. not reliable till we checked the repos
  4332.   PKGFILE="${WORKDIR}/${PKGNAME}.$pkg_ext"
  4333.  
  4334.   # set download options
  4335.   [ "$FORCE" = true  ] && CONTINUE='' || CONTINUE='-c'
  4336.   [ "$ASK"  != true  ] && QTAG=''
  4337.  
  4338.   #if pkg not yet downloaded, or we are downloading all, or we are forcing downloads
  4339.   if [ ! -f "$PKGFILE" -o "$NO_INSTALL" = true -o "$FORCE" = true ]; then
  4340.  
  4341.     # mark this pkg as not yet downloaded
  4342.     DONE=false
  4343.  
  4344.     # exit if no internet connection
  4345.     #NET="`check_net`"; [ $NET -eq 1 ] && echo "You need an internet connection" && exit 2
  4346.  
  4347.     # for each repo, starting with current repo
  4348.     repo_file_list | while read repo_file
  4349.     do
  4350.  
  4351.       # the file with our repo URL info
  4352.       sources_file="${HOME}/.pkg/sources"
  4353.  
  4354.       # check if $repo_file contains the given pkg
  4355.       pkg_in_this_repo="$(LANG=C cut -f1,2,7,8 -d'|' "$REPO_DB_FILE_DIR/$repo_file" 2>/dev/null | sed -e "s/^/|/" -e "s/$/|/" | grep -m1 "|${PKGNAME}|")"
  4356.       [ "$pkg_in_this_repo" = '' ] && pkg_in_this_repo="$(LANG=C cut -f1,2,7,8 -d'|' "$REPO_DB_FILE_DIR/$repo_file" 2>/dev/null | sed -e "s/^/|/" -e "s/$/|/" | grep -m1 "|${PKGNAME}")"
  4357.  
  4358.       # if package file found in current repo file
  4359.       if [ "$pkg_in_this_repo" != "" ]; then #if true, its an exact match
  4360.  
  4361.         # get name of current repo in loop
  4362.         prev_repo="$curr_repo"
  4363.         curr_repo="`LANG=C grep $repo_file $sources_file 2>/dev/null | cut -f1 -d'|'`"
  4364.  
  4365.         # get ext of cur repo, it might be different
  4366.         curr_repo_ext="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f2 -d'|'`"
  4367.  
  4368.         # keep a copy of the PKGNAME we got from `get_pkg_name $1`
  4369.         ORIG_PKGNAME=$PKGNAME
  4370.  
  4371.         # get proper PKGNAME (inc name-ver) from the repo
  4372.         PKGNAME="`echo "$pkg_in_this_repo" | cut -f3 -d'|'`"
  4373.         # just in case it didn't work, revert back to the old PKGNAME value
  4374.         [ "$PKGNAME" = "" ] && PKGNAME="$ORIG_PKGNAME"
  4375.  
  4376.         # get full pkg FILENAME (inc name-ver.ext) from the repo
  4377.         PKG_FILENAME="`echo "$pkg_in_this_repo" | cut -f5 -d'|'`"
  4378.  
  4379.         # just in case its empty, revert back to the earlier PKGNAME value
  4380.         [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="$PKGNAME"
  4381.  
  4382.         # update the filename to check/download
  4383.         PKGFILE="${WORKDIR}/${PKG_FILENAME}"
  4384.  
  4385.         # skip if downloaded already, print msg
  4386.         [ -f "$PKGFILE" -a "$FORCE" = false ] && DONE=true && echo -e "Already downloaded ${magenta}${PKG_FILENAME}${endcolour}" && continue
  4387.  
  4388.         # update the package name, based on PKG_FILENAME
  4389.         PKGNAME="$(basename "$PKG_FILENAME" .$curr_repo_ext)"
  4390.  
  4391.         # update generic name
  4392.         PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  4393.  
  4394.         if [ "${PKG_FILENAME}" = '' ]; then
  4395.           error "Cant find pkg file name, needed to download"
  4396.           return 1
  4397.         fi
  4398.  
  4399.         # skip pings and download if already downloaded.. unless forcing download
  4400.         if [ ! -f "$PKGFILE" -o "$FORCE" = true ]; then
  4401.  
  4402.           # ask user to download
  4403.           echo -en "Download ${magenta}${PKGNAME_ONLY}${endcolour} from ${lightblue}${curr_repo}${endcolour} repo$QTAG:  "
  4404.           [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  4405.           [ "$CONFIRM" != 'y' ] && echo
  4406.  
  4407.           # if user answered yes, we will now download the pkgs
  4408.           if [ "$CONFIRM" = "y" ]; then #25073
  4409.  
  4410.             # only ask once
  4411.             ASK=false
  4412.  
  4413.             echo # start a new line
  4414.  
  4415.             # get the subdir (from repo line) that the package lives in
  4416.             sub_dir="`echo "$pkg_in_this_repo" | cut -f4 -d'|' | sed 's/^\.//'`"
  4417.  
  4418.             if [ "$sub_dir" = "." ]; then
  4419.               sub_dir=''
  4420.             fi
  4421.  
  4422.             #s243a: TODO: figure out what this file is for???
  4423.             # pre-woof get subdir
  4424.             if [ "$sub_dir" != "" ] && [ -f "$PKGS_DIR/${repo_file}_subdirs" ]; then
  4425.               sub_dir="`grep -m1 "^$PKGNAME|" "$PKGS_DIR/${repo_file}_subdirs"  2>/dev/null | cut -f7 -d'|'`"
  4426.             fi
  4427.             #s243a: TODO: maybe if the folowing produces a trailing double slash than remove it.
  4428.             # get repo mirrors (only url1 is required .. we also add a final /)
  4429.             curr_repo_url1="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f4 -d'|'`/"
  4430.             curr_repo_url2="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f5 -d'|'`/"
  4431.             curr_repo_url3="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f6 -d'|'`/"
  4432.             curr_repo_url4="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f7 -d'|'`/"
  4433.  
  4434.             # make a space separated list of all our repo URLs
  4435.             curr_repo_url_list="$curr_repo_url1 $curr_repo_url2 $curr_repo_url3 $curr_repo_url4"
  4436.  
  4437.             # clean up the list, remove any double slashes at the end of each URL
  4438.             curr_repo_url_list="`echo "$curr_repo_url_list" | sed -e "s|// |/ |g" -e "s|//\$|/\$|g"`"
  4439.  
  4440.             # update the ext to that of current repo
  4441.             pkg_ext="$curr_repo_ext"
  4442.  
  4443.             # get the best repo mirror
  4444.             #if [ "$prev_repo" != "$current_repo"  -a -f $TMPDIR/curr_repo_url ] || [ ! -f $TMPDIR/curr_repo_url ]; then
  4445.               #echo "Checking '$curr_repo' repo mirrors..."
  4446.               for URL in $curr_repo_url_list
  4447.               do
  4448.                 [ -z "$URL" ] && continue
  4449.                 [ "$URL" = '/' ] && continue
  4450.                 [ "$URL" = '' ] && continue
  4451.                 #s243a:TODO: The following additions to the URL doesn't seem to do anything
  4452.                 # add some system values into the repo URL (arch, distro version, etc.. from DISTRO_SPECS)
  4453.                 URL="`echo "$URL"| sed -e 's@${DBIN_ARCH}@'$DBIN_ARCH'@g'`"
  4454.                 URL="`echo "$URL"| sed -e 's@${DISTRO_COMPAT_VERSION}@'$DISTRO_COMPAT_VERSION'@g'`"
  4455.                 URL="`echo "$URL"| sed -e 's@${DDB_COMP}@'$DDB_COMP'@g'`"
  4456.                 URL="`echo "$URL"| sed -e 's@${SLACKWARE}@'$SLACKWARE'@g'`"
  4457.                 URL="`echo "$URL"| sed -e 's@${SLACKARCH}@'$SLACKARCH'@g'`"
  4458.                 URL="`echo "$URL"| sed -e 's@${lxDISTRO_COMPAT_VERSION}@'$lxDISTRO_COMPAT_VERSION'@g'`"
  4459.                 #ping -W2 -c1 -q $(echo  "${URL}" | awk -F/ '{print $3}') &>/dev/null
  4460.                 wget --quiet --timeout=1 --no-parent --spider "${URL}" && \
  4461.                 {
  4462.                   # set the current URL
  4463.                   curr_repo_url="$URL"
  4464.                   if [ ! -z "$curr_repo_url" ]; then
  4465.                     echo "$curr_repo_url" > $TMPDIR/curr_repo_url
  4466.                     break
  4467.                   fi
  4468.                 }
  4469.               done
  4470.             #else
  4471.             # curr_repo_url="`cat $TMPDIR/curr_repo_url`"
  4472.             #fi
  4473.  
  4474.             # exit if URL is not found or empty
  4475.             if [ -z "$curr_repo_url" ]; then
  4476.               error "Package URL not found"
  4477.               return 8
  4478.             fi
  4479.  
  4480.             # lets build our DOWNLOAD_URL: set it to the working repo mirror we found above
  4481.             DOWNLOAD_URL="${curr_repo_url}"
  4482.  
  4483.             # now add the subdir to DOWNLOAD_URL .. sub_dir may be empty, but we add a trailing '/' anyway
  4484.             DOWNLOAD_URL="${DOWNLOAD_URL}${sub_dir}/"
  4485.  
  4486.             # add some system values into the repo URL (arch, distro version, etc.. from DISTRO_SPECS)
  4487.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DBIN_ARCH}@'$DBIN_ARCH'@g'`"
  4488.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DISTRO_COMPAT_VERSION}@'$DISTRO_COMPAT_VERSION'@g'`"
  4489.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DDB_COMP}@'$DDB_COMP'@g'`"
  4490.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${SLACKWARE}@'$SLACKWARE'@g'`"
  4491.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${SLACKARCH}@'$SLACKARCH'@g'`"
  4492.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${lxDISTRO_COMPAT_VERSION}@'$lxDISTRO_COMPAT_VERSION'@g'`"
  4493.  
  4494.             # add our package to the URL
  4495.             DOWNLOAD_URL="${DOWNLOAD_URL}${PKG_FILENAME}"
  4496.  
  4497.             # remove any double forward slashes (the main URL or subdir may have ended in slashes, it may not, we added our own to be sure)
  4498.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e "s@//$PKG_FILENAME@/$PKG_FILENAME@g"`"
  4499.  
  4500.             # if sub_dir not empty, lets clean that bit too
  4501.             [ "$sub_dir" != '' ] && DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e "s@//${sub_dir}@/${sub_dir}@g" -e "s@${sub_dir}//@${sub_dir}/@g"`"
  4502.  
  4503.             # exit if URL is not found (if we get a 404 back)
  4504.             if [ -z "$DOWNLOAD_URL" ]; then
  4505.               error "Package URL not found   $DOWNLOAD_URL"
  4506.               return 8
  4507.             else
  4508.               wget -S --spider "$DOWNLOAD_URL" || { \
  4509.                 error "Package URL not found   $DOWNLOAD_URL"
  4510.                 return 8                 
  4511.               }
  4512.             fi
  4513.  
  4514.             # we may be using multiple URLs, so each time we change URL,
  4515.             #  remember the new one
  4516.             if [ "$OLDURL" != "$DOWNLOAD_URL" ]; then
  4517.               OLDURL="$DOWNLOAD_URL";
  4518.               #echo -e "URL: ${lightblue}${DOWNLOAD_URL}${endcolour}";
  4519.             fi
  4520.  
  4521.             # if --force, remove the package if it already exists
  4522.             [ "$FORCE" = true ] && rm -f "${WORKDIR}/${PKG_FILENAME}" &>/dev/null
  4523.  
  4524.             # if file not downloaded, or forcing downloads
  4525.             if [ ! -f "${WORKDIR}/${PKG_FILENAME}" -o "$FORCE" = true ]; then
  4526.  
  4527.               # BEGIN DOWNLOAD file here..
  4528.  
  4529.               # print DOWNLOADING msg
  4530.               echo -en "Downloading ${magenta}${PKG_FILENAME}${endcolour}. Please wait:     "
  4531.  
  4532.               # if called as 'gpkg', give a pop GUI (uses Xdialog) showing download progress..
  4533.               # can be used by X apps to easily start (and show!) downloads
  4534.               if [ "$SELF" = "gpkg" ]; then
  4535.  
  4536.                 download_progress "$DOWNLOAD_URL" "${WORKDIR}/${PKG_FILENAME}" 2>/dev/null
  4537.  
  4538.               else # if called as 'pkg', dont use Xdialog, output to terminal
  4539.  
  4540.                 if [ "$QUIET" = true ]; then
  4541.                   echo
  4542.                   echo -n "Downloading now..."
  4543.                   LANG=C wget \
  4544.                     --no-check-certificate \
  4545.                     --progress=dot -O "${WORKDIR}/${PKG_FILENAME}" \
  4546.                     -4 $CONTINUE "$DOWNLOAD_URL" &>/dev/null
  4547.                 else
  4548.                   # START DOWNLOAD, show percentage as we go
  4549.                   LANG=C wget \
  4550.                     --no-check-certificate \
  4551.                     --progress=dot -O "${WORKDIR}/${PKG_FILENAME}" \
  4552.                     -4 $CONTINUE "$DOWNLOAD_URL" 2>&1 \
  4553.                     | grep --line-buffered "%" \
  4554.                     | sed -u -e "s#\.##g" \
  4555.                     | awk '{printf("\b\b\b\b%4s", $2)}' #220613
  4556.                 fi
  4557.  
  4558.               fi
  4559.  
  4560.             fi # end if WORKDIR/PKG not a file or FORCE=true
  4561.  
  4562.             # clean up output
  4563.             [ "$QUIET" != true ] && echo -ne "\b\b\b\b"
  4564.             echo
  4565.  
  4566.             # if file downloaded ok
  4567.             if [ -f "${WORKDIR}/${PKG_FILENAME}" ]; then
  4568.                if check_md5sum "${WORKDIR}/${PKG_FILENAME}" "$REPO_DB_FILE_DIR/$repo_file"; then
  4569.                  echo -e "${green}Downloaded:${endcolour} ${WORKDIR}/${PKG_FILENAME}"
  4570.                  DONE=true
  4571.                  break              
  4572.                else
  4573.                  #error "Failed md5sum check '${WORKDIR}/${PKG_FILENAME}'."
  4574.                  echo "Failed md5sum check '${WORKDIR}/${PKG_FILENAME}'."
  4575.  
  4576.                  # remove the download
  4577.                  rm "${WORKDIR}/${PKG_FILENAME}" &>/dev/null
  4578.                  DONE=true
  4579.                  exit 6                
  4580.                fi
  4581.             fi
  4582.             # if file downloaded ok
  4583.             if [ -f "${WORKDIR}/${PKG_FILENAME}" ]; then
  4584.               #TODO check md5sum here.
  4585.              
  4586.               echo -e "${green}Downloaded:${endcolour} ${WORKDIR}/${PKG_FILENAME}"
  4587.               DONE=true
  4588.               break
  4589.  
  4590.             #TODO: Maybe we can try a mirror here if the download fails.
  4591.             else # file NOT downloaded ok
  4592.  
  4593.               error "Failed to download '${WORKDIR}/${PKG_FILENAME}'."
  4594.               echo "Check '$DOWNLOAD_URL'"
  4595.  
  4596.               # remove the page we tried to get pkg from (if exists)
  4597.               rm "${WORKDIR}/index.html" &>/dev/null
  4598.               DONE=true
  4599.               exit 6
  4600.             fi
  4601.  
  4602.           fi # end if CONFIRM=y
  4603.  
  4604.           # user chose not to do anything
  4605.           DONE=true
  4606.           break
  4607.  
  4608.         else # Already downloaded, skip to next iteration
  4609.  
  4610.           #echo "Package $1 already downloaded"
  4611.           DONE=true
  4612.           break
  4613.         fi
  4614.  
  4615.       else # no repo match, nothing to download
  4616.  
  4617.         # go to next repo, try to ge tthe pkg there
  4618.         DONE=false
  4619.  
  4620.       fi # end if repo match was found
  4621.  
  4622.       # if download not successful, keep going to next repo
  4623.       [ "$DONE" = true ] && continue
  4624.  
  4625.     done #done while read list of repo files
  4626.  
  4627.   fi
  4628. }
  4629.  
  4630.  
  4631. pkg_install(){                    # install downloaded package ($1) FUNCLIST
  4632.  
  4633.   . ${PKGRC}
  4634.  
  4635.   # exit if no valid option
  4636.   [ ! "$1" -o "$1" = "-" ] && print_usage install && exit 1
  4637.  
  4638.   # skip if not installing pkgs
  4639.   [ "$NO_INSTALL" = true ] && continue
  4640.  
  4641.   local pkg_ext
  4642.   local PKGNAME
  4643.   local PKGNAME_ONLY
  4644.   local PKGFILE
  4645.   local PREVDIR="$CURDIR"
  4646.   local petspecs
  4647.  
  4648.   # get pkg extension
  4649.   pkg_ext=`get_pkg_ext "$1"`
  4650.   # get pkg name only, no extension or path
  4651.   PKGNAME="$(basename "$1" .$pkg_ext)"
  4652.   # exit if no valid option
  4653.   [ "$PKGNAME" = '' ] && print_usage install && exit 1
  4654.   # get name without version
  4655.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  4656.  
  4657.   [ "`is_installed_pkg "$PKGNAME"`" = true -a "$FORCE" = false ] && echo "Already installed: $PKGNAME" && return 1
  4658.   [ "`is_blacklisted_pkg "$PKGNAME_ONLY"`" = true ] && echo "Blacklisted package: $PKGNAME" && return 1
  4659.  
  4660.   if [ -f "$1" ]; then
  4661.     PKGFILE="$1"
  4662.     CURDIR="$(dirname "$(realpath "$1")")"
  4663.    PKGNAME=`basename "$1" .$pkg_ext`
  4664.  else
  4665.    # get the real file name (inc path) from the given PKGFILE and pkg_ext (which may be empty)
  4666.    PKGFILE=`find "$CURDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${pkg_ext}" | head -1`
  4667.    [ ! -f "$PKGFILE" ] && PKGFILE=`find "$CURDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${EX}" | grep -m1 $EX`
  4668.    [ -f "$PKGFILE" ] && PKGNAME=`basename "$1" .$pkg_ext`
  4669.  fi
  4670.  
  4671.  # maybe the file is not in the current dir, but in WORKDIR, so lets look there too
  4672.  if [ ! -f "$PKGFILE" ]; then
  4673.    PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${pkg_ext}" | head -1`
  4674.    [ ! -f "$PKGFILE" ] && PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${EX}" | grep -m1 $EX`
  4675.  
  4676.    # if we found the file in WORKDIR, make that our CURDIR
  4677.    if [ -f "$PKGFILE" ]; then
  4678.      PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4679.      CURDIR="$WORKDIR"
  4680.      cd "$WORKDIR"
  4681.    else
  4682.      # if we still didn't find it, do a broader check
  4683.      PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*" | head -1`
  4684.      if [ -f "$PKGFILE" ]; then
  4685.        PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4686.        CURDIR="$WORKDIR"
  4687.        cd "$WORKDIR"
  4688.      fi
  4689.    fi
  4690.  fi
  4691.  
  4692.  # if the file exists, or using --force
  4693.  if [ -f "$PKGFILE" -o "$FORCE" = true ]; then
  4694.  
  4695.    [ ! -f "$PKGFILE" ] && echo "The file $1 was not found." && return 1
  4696.  
  4697.    # get the extension of this newly found pkg (which we should have found by now)
  4698.    pkg_ext=`get_pkg_ext "$PKGFILE"`
  4699.    # get extension again, we may have been given only a pkg name, find its extension from repo files
  4700.    [ "$pkg_ext" = "" ] && pkg_ext=`get_pkg_ext "$PKGNAME"`
  4701.  
  4702.    [ "$pkg_ext" = '' ] && echo "Not installing $PKGFILE." && error "Invalid file extension ($pkg_ext)." && return 1
  4703.  
  4704.    # remove any previous PET/pkg stuff lying around from previous installs
  4705.    rm -f /pet.specs /pinstall.sh /puninstall.sh /install/doinst.sh
  4706.  
  4707.    # if pkg is not yet installed, or we are force re-installing
  4708.  
  4709.    # get filename from download file
  4710.    PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4711.  
  4712.    # ask/inform user before install
  4713.    echo -n "Install package ${PKGNAME}$QTAG:  "
  4714.    [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  4715.    [ "$ASK" = true ] && echo -ne "\b\b\n"
  4716.  
  4717.    # if user answered yes, we will now download the pkgs
  4718.    if [ "$CONFIRM" = "y" ]; then
  4719.  
  4720.      # print new line if we didnt take any user input on tty
  4721.      [ "$ASK" != true ] && echo
  4722.  
  4723.      # only ask once
  4724.      ASK=false
  4725.  
  4726.      #if [ "`pkg_contents "$PKGFILE" 2>/dev/null`" = '' ]; then
  4727.      # error "$PKGFILE not a valid package."
  4728.      # exit 1
  4729.      #fi
  4730.  
  4731.      # fallback to repo pkg ext if none found
  4732.      [ "$pkg_ext" = "" ] && pkg_ext="$EX"
  4733.  
  4734.      #remove the old error log
  4735.      rm $TMPDIR/$SELF-cp-errlog 2>/dev/null
  4736.  
  4737.      # extract the archive file into a $CURDIR/$PKGNAME folder
  4738.      case "$pkg_ext" in
  4739.  
  4740.        pet)
  4741.          PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.pet"`"
  4742.          #determine the compression, extend test to 'XZ'
  4743.          file -b "${PKGFILE}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  4744.          [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  4745.  
  4746.          # convert to tar extractable archive
  4747.          pet2tgz "${PKGFILE}" 1>/dev/null
  4748.  
  4749.          # now extract the file
  4750.          tar $taropts "${CURDIR}/${PKGNAME}.tar.${TAREXT}" 2> $TMPDIR/$SELF-cp-errlog
  4751.  
  4752.          # some old types need this extra step
  4753.          if [ -f "${CURDIR}/${PKGNAME}.tar.$TAREXT" ]; then
  4754.            cd "${CURDIR}/${PKGNAME}/" 1>/dev/null
  4755.            tar --absolute-names $tarops "./${PKGNAME}.tar.$TAREXT" ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog #260713
  4756.            sync
  4757.            rm -f  "./${PKGNAME}.tar.$TAREXT" 1>/dev/null
  4758.            cd - 1>/dev/null
  4759.          fi
  4760.  
  4761.          # save the uninstall script for later
  4762.          if [ -f "${CURDIR}/${PKGNAME}/puninstall.sh" ]; then
  4763.            mv "${CURDIR}/${PKGNAME}/puninstall.sh" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove"
  4764.          fi
  4765.  
  4766.          # create a tgz
  4767.          tgz2pet "${CURDIR}/${PKGNAME}.tar.$TAREXT" 1>/dev/null
  4768.          rm "${CURDIR}/${PKGNAME}.tar.$TAREXT" 2>/dev/null
  4769.        ;;
  4770.  
  4771.        sfs)
  4772.          PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.sfs"`"
  4773.          [ ! -f "$PKGFILE" ] && PKGFILE="`find ${WORKDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.sfs"`"
  4774.          echo sfs_loadr -q --cli +"$PKGFILE" #2>/dev/null
  4775.          sfs_loadr -q --cli +"$PKGFILE" #2>/dev/null
  4776.          rm -f $PACKAGE_FILE_LIST_DIR/${PKGNAME}.files 2>/dev/null
  4777.          # create $PKGS_DIR/$PKGNAME.files
  4778.          pkg_contents "$PKGFILE" | while read line
  4779.          do
  4780.            [ -f "$line" ] && echo "$line" >> $PACKAGE_FILE_LIST_DIR/${PKGNAME}.files
  4781.          done
  4782.          # exit, we dont need to unpack and copy
  4783.          return 0
  4784.        ;;
  4785.  
  4786.        deb)
  4787.  
  4788.          rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4789.          mkdir -p "${CURDIR}/${PKGNAME}"
  4790.          [ ! -f "$PKGFILE" ] && PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.deb"`"
  4791.          cp "${PKGFILE}" "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" || exit 4
  4792.          cd "${CURDIR}/${PKGNAME}/"
  4793.  
  4794.          if [ -f "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" ]; then
  4795.            dpkg-deb --contents "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" \
  4796.              | grep -v '/$' \
  4797.              | tr -s ' ' \
  4798.              | cut -f6 -d' ' \
  4799.              | sed -e 's/^.//g' 2>/dev/null \
  4800.              | grep -v '^$' > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4801.          fi
  4802.  
  4803.                     # woofce: NO_MULTIARCH_SYMLINK=1 (DISTRO_SPECS)
  4804.                     if [ -z "$NO_MULTIARCH_SYMLINK" ] ; then
  4805.            if [ -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ]; then
  4806.              pkg_has_archdir="$(grep -m1 "$DISTRO_ARCHDIR" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")"
  4807.            fi
  4808.  
  4809.                         # Workaround to avoid overwriting the $DISTRO_ARCHDIR symlink.
  4810.                         if [ "$DISTRO_ARCHDIR" != "" -a -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" -a "$pkg_has_archdir" != "" ]; then
  4811.                           mkdir -p /tmp/$PKGNAME
  4812.                           rm -rf /tmp/$PKGNAME/*
  4813.                           dpkg-deb -x ${CURDIR}/${PKGNAME}.deb /tmp/$PKGNAME/ 2> $TMPDIR/$SELF-cp-errlog
  4814.                           #set -x
  4815.                           while read f
  4816.                           do
  4817.                               xpath="$(echo "$f" |  cut  -f 4-30 -d "/" | sed "s/$DISTRO_ARCHDIR\///")"
  4818.                               mkdir -p ${DIRECTSAVEPATH}/$(dirname "$xpath")
  4819.                               cp -a "$f" ${DIRECTSAVEPATH}/$(dirname "$xpath")/
  4820.                           done < <(find "/tmp/$PKGNAME" \( -type f -o -type l \))
  4821.                           #set +x
  4822.                           rm -rf /tmp/$PKGNAME &>/dev/null
  4823.                         else
  4824.                           dpkg-deb -x ${CURDIR}/${PKGNAME}.deb ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4825.                         fi
  4826.                     else
  4827.                         dpkg-deb -x ${CURDIR}/${PKGNAME}.deb ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4828.                     fi
  4829.  
  4830.          if [ "`cat $TMPDIR/$SELF-cp-errlog | grep 'tar: Exiting with failure status due to previous errors'`" != "" ]; then
  4831.            error "Failed to unpack $PKGNAME.deb"
  4832.            exit 1
  4833.          fi
  4834.          [ -d /DEBIAN ] && rm -rf /DEBIAN #130112 precaution.
  4835.          dpkg-deb -e "${CURDIR}/${PKGNAME}.deb" /DEBIAN #130112 extracts deb control files to dir /DEBIAN. may have a post-install script, see below.
  4836.          rm "${PKGNAME}.deb"
  4837.  
  4838.          cd - 1>/dev/null
  4839.        ;;
  4840.  
  4841.        *tbz|*tar.bz2)
  4842.          rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4843.          mkdir -p "${CURDIR}/${PKGNAME}"
  4844.          cp "${CURDIR}/${PKGNAME}.$pkg_ext" "${CURDIR}/${PKGNAME}/${PKGNAME}.$pkg_ext" || exit 4
  4845.          cd "${CURDIR}/${PKGNAME}/"
  4846.  
  4847.          ( umask 000 ; cat "${PKGNAME}.$pkg_ext" | bzip2 -dc | tar -xf - 2> $TMPDIR/$SELF-cp-errlog )
  4848.  
  4849.          rm "${PKGNAME}.$pkg_ext"
  4850.          cd - 1>/dev/null
  4851.        ;;
  4852.  
  4853.        *tlz|*tar.lzma)
  4854.          rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4855.          mkdir -p "${CURDIR}/${PKGNAME}"
  4856.          PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.${pkg_ext}"`"
  4857.          cp "$PKGFILE" "${CURDIR}/${PKGNAME}/`basename $PKGFILE`" || exit 4
  4858.          cd "${CURDIR}/${PKGNAME}/"
  4859.  
  4860.          ( umask 000 ; cat "${PKGNAME}.$pkg_ext" | lzma -dc | tar -xf - 2> $TMPDIR/$SELF-cp-errlog )
  4861.  
  4862.          rm "${PKGNAME}.$pkg_ext"
  4863.          cd - 1>/dev/null
  4864.        ;;
  4865.  
  4866.        *tgz|*txz|*tar.gz|*tar.xz|*xz|*gz)
  4867.          rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4868.          mkdir -p "${CURDIR}/${PKGNAME}"
  4869.          PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.${pkg_ext}"`"
  4870.          cp "$PKGFILE" "${CURDIR}/${PKGNAME}/`basename $PKGFILE`" || exit 4
  4871.          cd "${CURDIR}/${PKGNAME}/"
  4872.  
  4873.          file -b "${PKGNAME}.$pkg_ext" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  4874.          [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  4875.  
  4876.          tar $taropts "${PKGNAME}.$pkg_ext" 2> $TMPDIR/$SELF-cp-errlog
  4877.          rm "${PKGNAME}.$pkg_ext"
  4878.          cd - 1>/dev/null
  4879.        ;;
  4880.  
  4881.        rpm)
  4882.          PKGNAME="`basename ${PKGFILE} .rpm`"
  4883.          busybox rpm -qp "$PKGFILE" > /dev/null 2>&1
  4884.          [ $? -ne 0 ] && exit 1
  4885.          PFILES="`busybox rpm -qpl $PKGFILE`"
  4886.          [ $? -ne 0 ] && exit 1
  4887.          echo "$PFILES" > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4888.          pkg_unpack "$PKGFILE" 1>/dev/null
  4889.        ;;
  4890.  
  4891.      esac
  4892.  
  4893.      # now extract pkg contents to /
  4894.      [ ! -d "${PKGNAME}/" ] && error "Cannot enter directory '${PKGNAME}/', it doesn't exist." && exit 4
  4895.      cd "${PKGNAME}/" 1>/dev/null
  4896.  
  4897.      cp -a --remove-destination * ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4898.  
  4899.      #source is a directory, target is a symlink...
  4900.      if [ -s $TMPDIR/$SELF-cp-errlog ]; then
  4901.        cat $TMPDIR/$SELF-cp-errlog  2>/dev/null | grep -E 'Cannot create symlink to|cannot overwrite non-directory' | cut -f 1 -d "'" | cut -f 2 -d '`' |
  4902.        while read ONEDIRSYMLINK
  4903.        do
  4904.          #adding that extra trailing / does the trick...
  4905.          cp -a --remove-destination ${ONEDIRSYMLINK}/* /${ONEDIRSYMLINK}/ 2> $TMPDIR/$SELF-cp-errlog #260713
  4906.        done
  4907.      fi
  4908.      sync
  4909.      cd .. 1>/dev/null
  4910.  
  4911.      if [ ! -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ] || \
  4912.         [ -z "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ]; then
  4913.        # add ${HOME}/.packages/${PKGNAME}.files, need to find regular files and links separately... then images..
  4914.        find "./${PKGNAME}/" -mount -mindepth 2 -type f | sed -e "s/\.\/${PKGNAME}//g" -e 's/\/root0\//\/root\//g' > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4915.        find "./${PKGNAME}/" -mount -mindepth 2 -type l | sed -e "s/\.\/${PKGNAME}//g" -e 's/\/root0\//\/root\//g' >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4916.  
  4917.        for ONEIMAGEFILE in `ls -1 /*[0-9].xpm 2>/dev/null`
  4918.        do
  4919.         BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4920.         echo "/usr/local/lib/X11/pixmaps/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4921.        done
  4922.        for ONEIMAGEFILE in `ls -1 /*[0-9].png 2>/dev/null`
  4923.        do
  4924.         BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4925.         echo "/usr/local/lib/X11/pixmaps/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4926.        done
  4927.        for ONEIMAGEFILE in `ls -1 /*[^0-9].xpm 2>/dev/null`
  4928.        do
  4929.         BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4930.         echo "/usr/local/lib/X11/mini-icons/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4931.        done
  4932.        for ONEIMAGEFILE in `ls -1 /*[^0-9].png 2>/dev/null` #v2.16
  4933.        do
  4934.         BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4935.         echo "/usr/local/lib/X11/mini-icons/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4936.        done
  4937.      fi
  4938.  
  4939.      # move the *.files to $PKGS_DIR
  4940.      FILES=''
  4941.      FILES="`find "$CURDIR" -mount -maxdepth 1 -iname "*.files" | head -1`"
  4942.      [ -f "`echo $FILES`" ] && mv "$FILES" "$PACKAGE_FILE_LIST_DIR/" 2>/dev/null #260713
  4943.  
  4944.      #pkgname.files may need to be fixed...
  4945.      cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" | grep -v '/$' | sed -e 's%^\\.%%' -e 's%^%/%' -e 's%^//%/%' 2>/dev/null > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2"
  4946.      mv "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4947.  
  4948.      sort -u "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2"
  4949.      mv "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4950.  
  4951.      # some pets add images and icons at / so move them
  4952.      mv /{*.xpm,*.png} /usr/share/pixmaps/ 2>/dev/null
  4953.      mv /*.ico /usr/share/pixmaps/ 2>/dev/null
  4954.  
  4955.      # run the post install scripts (for puppy, slackware, arch, debian/ubuntu, etc)
  4956.      for i in /pinstall.sh /install/doinst.sh /DEBIAN/postinst
  4957.      do
  4958.        [ -z /${i} -o ! -e /${i} ] && continue
  4959.        chmod +x /${i}
  4960.        cd /
  4961.        nohup sh ${i} &>/dev/null
  4962.        sleep 0.2
  4963.        rm -f ${i}
  4964.        cd ${CURDIR}/
  4965.      done
  4966.      rm -rf /install
  4967.      rm -rf /DEBIAN
  4968.  
  4969.      #130314 run arch linux pkg post-install script...
  4970.      if [ -f /.INSTALL -a /usr/local/petget/ArchRunDotInstalls ]; then #precaution. see 3builddistro, script created by noryb009.
  4971.        #this code is taken from below...
  4972.        dlPATTERN='|'"`echo -n "${PKGNAME}" | sed -e 's%\\-%\\\\-%'`"'|'
  4973.        archVER="`cat $TMPDIR/petget_missing_dbentries-Packages-* 2>/dev/null | grep "$dlPATTERN" | head -n 1 | cut -f 3 -d '|'`"
  4974.        if [ "$archVER" ]; then #precaution.
  4975.          cd /
  4976.          mv -f .INSTALL .INSTALL1-${archVER}
  4977.          cp -a /usr/local/petget/ArchRunDotInstalls ArchRunDotInstalls
  4978.          LANG=$LANG_USER ./ArchRunDotInstalls
  4979.          rm -f ArchRunDotInstalls
  4980.          rm -f .INSTALL*
  4981.          cd ${CURDIR}/
  4982.        fi
  4983.      fi
  4984.  
  4985.      PKGCAT=''
  4986.      PKGSIZE=''
  4987.      PKGDESC=''
  4988.      DEPLIST=''
  4989.  
  4990.      # clean up pet installs
  4991.      if [ "$pkg_ext" = "pet" ]; then
  4992.        cd /
  4993.  
  4994.        # get pkg info from pet.spec before we delete it, because the PET may not be a repo pkg
  4995.        petspecs="`cat /pet.specs 2>/dev/null`"
  4996.  
  4997.        if [ "$petspecs" != '' ]; then
  4998.          # now get pkg info
  4999.          PKGCAT="`echo $petspecs|  cut -f5  -d'|'`"
  5000.          PKGSIZE="`echo $petspecs| cut -f6  -d'|'`"
  5001.          PKGDESC="`echo $petspecs| cut -f10 -d'|'`"
  5002.          DEPSLIST="`echo $petspecs|cut -f9  -d'|'`"
  5003.        fi
  5004.  
  5005.        cd ${CURDIR}/
  5006.      fi
  5007.  
  5008.      # cleanup a bit
  5009.      rm -R "${PKGNAME}/" 2>/dev/null || echo "${yellow}Warning:${endcolour} Cannot remove directory '${PKGNAME}/'." #150213
  5010.  
  5011.      #120102 install may have overwritten a symlink-to-dir...
  5012.      #tar defaults to not following symlinks, for both dirs and files, but i want to follow symlinks
  5013.      #for dirs but not for files. so, fix here... (note, dir entries in .files have / on end)
  5014.      cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" | grep '[a-zA-Z0-9]/$' | sed -e 's%/$%%' | grep -v '^/mnt' |
  5015.      while read ONESPEC
  5016.      do
  5017.       if [ -d "${DIRECTSAVEPATH}${ONESPEC}" ]; then
  5018.        if [ ! -h "${DIRECTSAVEPATH}${ONESPEC}" ]; then
  5019.         DIRLINK=""
  5020.         if [ -h "/initrd${PUP_LAYER}${ONESPEC}" ]; then #120107
  5021.          DIRLINK="`readlink -m "/initrd${PUP_LAYER}${ONESPEC}" | sed -e "s%/initrd${PUP_LAYER}%%"`" #PUP_LAYER: see /etc/rc.d/PUPSTATE. 120107
  5022.          xDIRLINK="`readlink "/initrd${PUP_LAYER}${ONESPEC}"`" #120107
  5023.         fi
  5024.         if [ ! "$DIRLINK" ]; then
  5025.          if [ -h "/initrd${SAVE_LAYER}${ONESPEC}" ]; then #120107
  5026.           DIRLINK="`readlink -m "/initrd${SAVE_LAYER}${ONESPEC}" | sed -e "s%/initrd${SAVE_LAYER}%%"`" #SAVE_LAYER: see /etc/rc.d/PUPSTATE. 120107
  5027.           xDIRLINK="`readlink "/initrd${SAVE_LAYER}${ONESPEC}"`" #120107
  5028.          fi
  5029.         fi
  5030.         if [ "$DIRLINK" ]; then
  5031.          if [ -d "$DIRLINK"  ]; then
  5032.           if [ "$DIRLINK" != "${ONESPEC}" ]; then #precaution.
  5033.            mkdir -p "${DIRECTSAVEPATH}${DIRLINK}" #120107
  5034.            cp -a -f --remove-destination ${DIRECTSAVEPATH}"${ONESPEC}"/* "${DIRECTSAVEPATH}${DIRLINK}/" #ha! fails if put double-quotes around entire expression.
  5035.            rm -rf "${DIRECTSAVEPATH}${ONESPEC}"
  5036.            if [ "$DIRECTSAVEPATH" = "" ]; then
  5037.             ln -s "$xDIRLINK" "${ONESPEC}"
  5038.            else
  5039.             DSOPATH="`dirname "${DIRECTSAVEPATH}${ONESPEC}"`"
  5040.             DSOBASE="`basename "${DIRECTSAVEPATH}${ONESPEC}"`"
  5041.             rm -f "${DSOPATH}/.wh.${DSOBASE}" #allow underlying symlink to become visible on top.
  5042.            fi
  5043.           fi
  5044.          fi
  5045.         fi
  5046.        fi
  5047.       fi
  5048.      done
  5049.  
  5050.             # woofce: NO_MULTIARCH_SYMLINK=1 (DISTRO_SPECS)
  5051.             if [ -z "$NO_MULTIARCH_SYMLINK" ] ; then
  5052.        #121217 it seems that this problem is occurring in other modes (13 reported)...
  5053.        #121123 having a problem with multiarch symlinks in full-installation...
  5054.        #it seems that the symlink is getting replaced by a directory.
  5055.        if [ "$DISTRO_ARCHDIR" ]; then #in /etc/rc.d/DISTRO_SPECS. 130112 change test from DISTRO_ARCHDIR. 130114 revert DISTRO_ARCHDIR_SYMLINKS==yes.
  5056.          if [ -d /usr/lib/${DISTRO_ARCHDIR} ]; then
  5057.            if [ ! -h /usr/lib/${DISTRO_ARCHDIR} ]; then
  5058.              cp -a -f --remove-destination /usr/lib/${DISTRO_ARCHDIR}/* /usr/lib/
  5059.              sync
  5060.              rm -r -f /usr/lib/${DISTRO_ARCHDIR}
  5061.              ln -s ./ /usr/lib/${DISTRO_ARCHDIR}
  5062.            fi
  5063.          fi
  5064.          if [ -d /lib/${DISTRO_ARCHDIR} ]; then
  5065.            if [ ! -h /lib/${DISTRO_ARCHDIR} ]; then
  5066.              cp -a -f --remove-destination /lib/${DISTRO_ARCHDIR}/* /lib/
  5067.              sync
  5068.              rm -r -f /lib/${DISTRO_ARCHDIR}
  5069.              ln -s ./ /lib/${DISTRO_ARCHDIR}
  5070.            fi
  5071.          fi
  5072.          if [ -d /usr/bin/${DISTRO_ARCHDIR} ]; then
  5073.            if [ ! -h /usr/bin/${DISTRO_ARCHDIR} ]; then
  5074.              cp -a -f --remove-destination /usr/bin/${DISTRO_ARCHDIR}/* /usr/bin/
  5075.              sync
  5076.              rm -r -f /usr/bin/${DISTRO_ARCHDIR}
  5077.              ln -s ./ /usr/bin/${DISTRO_ARCHDIR}
  5078.            fi
  5079.          fi
  5080.        fi
  5081.      fi
  5082.  
  5083.      #flush unionfs cache, so files in pup_save layer will appear "on top"...
  5084.      if [ "$DIRECTSAVEPATH" != "" ]; then
  5085.       #but first, clean out any bad whiteout files...
  5086.       # 22sep10 shinobar: bugfix was not working clean out whiteout files
  5087.       find /initrd/pup_rw -mount -type f -name .wh.\*  -printf '/%P\n'|
  5088.       while read ONEWHITEOUT
  5089.       do
  5090.        ONEWHITEOUTFILE="`basename "$ONEWHITEOUT"`"
  5091.        ONEWHITEOUTPATH="`dirname "$ONEWHITEOUT"`"
  5092.        if [ "$ONEWHITEOUTFILE" = ".wh.__dir_opaque" ]; then
  5093.         [ "$(grep "$ONEWHITEOUTPATH" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != "" ] && rm -f "/initrd/pup_rw/$ONEWHITEOUT"
  5094.         continue
  5095.        fi
  5096.        ONEPATTERN="`echo -n "$ONEWHITEOUT" | sed -e 's%/\\.wh\\.%/%'`"'/*' ;#echo "$ONEPATTERN" >&2
  5097.        [ "$(grep -x "$ONEPATTERN" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != "" ] && rm -f "/initrd/pup_rw/$ONEWHITEOUT"
  5098.       done
  5099.       #111229 /usr/local/petget/removepreview.sh when uninstalling a pkg, may have copied a file from sfs-layer to top, check...
  5100.       cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" |
  5101.       while read ONESPEC
  5102.       do
  5103.        [ "$ONESPEC" = "" ] && continue #precaution.
  5104.        if [ ! -d "$ONESPEC" ]; then
  5105.         [ -e "/initrd/pup_rw${ONESPEC}" ] && rm -f "/initrd/pup_rw${ONESPEC}"
  5106.        fi
  5107.       done
  5108.       #now re-evaluate all the layers...
  5109.       busybox mount -t aufs -o remount,udba=reval unionfs / #remount with faster evaluation mode.
  5110.       [ $? -ne 0 ] && logger -s -t "pkg" "Failed to remount aufs / with udba=reval"
  5111.       sync
  5112.      fi
  5113.  
  5114.      # get pkg size, category and description
  5115.      [ "$PKGCAT" = ''  ] && PKGCAT=`LANG=C  grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f5 -d'|' | head -1`
  5116.      [ "$PKGCAT" = ''  ] && PKGCAT=`LANG=C  grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f5 -d'|' | head -1`
  5117.      [ "$PKGDESC" = '' ] && PKGDESC=`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null| cut -f10 -d'|' | head -1`
  5118.      [ "$PKGDESC" = '' ] && PKGDESC=`LANG=C grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null| cut -f10 -d'|' | head -1`
  5119.      [ "$PKGSIZE" = '' ] && PKGSIZE=`LANG=C du -s -k ${CURDIR}/${PKG} 2>/dev/null | cut -f1`
  5120.      # get pkg version
  5121.      PKGVER="`LANG=C  echo "$PKGNAME" | sed -e 's/^[^0-9]*-//g'`"
  5122.      PKGARCH="`LANG=C echo "$PKGNAME" | cut -f3 -d'-' | grep -E 'i[3-9]|x[8-9]|noarch'`"
  5123.  
  5124.      # last check for pkg info
  5125.      [ "$DEPSLIST" = '' ] && DEPSLIST="`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR"/Packages-* 2>/dev/null | cut -f9 -d'|' | grep '+' | head -1`"
  5126.      [ "$PKGDESC" = ''  ] && PKGDESC="No description"
  5127.  
  5128.      #080917 - build woof compatible repo line .. #090817
  5129.      if [ "`cut -f1 -d'|' "$USER_INST_PKGS_FILE" 2>/dev/null | grep -m1 ^${PKGNAME}`" = '' ]; then
  5130.  
  5131.        # get the package db entry to add to user-installed-packages...
  5132.        # first, get it from petspecs if possible, or from the pkgs repo, or make one
  5133.        if [ -f /pet.specs ]; then
  5134.          DB_ENTRY="`cat /pet.specs | head -n 1`"
  5135.        elif [ "`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/$REPOFILE"`" != "" ]; then
  5136.          DB_ENTRY="`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/$REPOFILE"`"
  5137.        else
  5138.          DB_ENTRY="${PKGNAME}|${PKGNAME_ONLY}|${PKGVER}|${BUILD}|${PKGCAT}|${PKGSIZE}|${PKGDIR}|${PKGNAME}.${pkg_ext}|${DEPSLIST}|${PKGDESC}|${DISTRO_BINARY_COMPAT}|${DISTRO_COMPAT_VERSION}"
  5139.        fi
  5140.  
  5141.        # Fix for Debian executables showing as shared libs in ROX.
  5142.        if [ "$DISTRO_FILE_PREFIX" = "stretch" -o "$DISTRO_FILE_PREFIX" = "ascii" ]; then
  5143.          if [ "$(ps aux | grep ROX |grep -v grep)" ]; then # Other managers are OK
  5144.            if [ "$(which elfedit)" ]; then
  5145.              grep -E '/bin/|/sbin/' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" |
  5146.              while read FLINE
  5147.              do
  5148.                [ "$(file "$FLINE" | grep -i 'shared object')" ] && elfedit --input-type=dyn --output-type=exec $FLINE
  5149.              done
  5150.            else
  5151.              echo -e "${yellow}Warning${endcolour} Recent Debian executables show as shared libraries in ROX,"
  5152.              echo "which causes ROX to fail to open or execute them. To fix that during package "
  5153.              echo "installation you should install elfutils or have devx loaded."
  5154.            fi
  5155.          fi
  5156.        fi
  5157.  
  5158.        # now add the db entry to user-installed-packages
  5159.        echo "$DB_ENTRY" >> "$USER_INST_PKGS_FILE" #130913
  5160.  
  5161.      fi
  5162.  
  5163.      # now delete the petspecs file(s), we already added our PKG info to installed-packages
  5164.      rm /pet.specs &>/dev/null
  5165.      rm /*.pet.specs &>/dev/null
  5166.  
  5167.      # make sure /tmp has correct permission, a pkg may have overwritten it
  5168.      ls -dl /tmp | grep -q '^drwxrwxrwt' || chmod 1777 /tmp #130305 rerwin.
  5169.  
  5170.      #090817
  5171.      if [ "$(is_installed_pkg $PKGNAME)" = true -a "$(cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != '' ]; then
  5172.        echo -e "${green}Installed:${endcolour} $PKGNAME"
  5173.        # show if pkg has menu entry
  5174.        menu_entry_msg "$PKGNAME_ONLY"
  5175.        #080413 do fixmenus, if menu entry found #200713 moved here
  5176.        if [ "$(grep -m1 '/usr/share/applications' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" 2>/dev/null | grep desktop$)" != "" ]; then
  5177.          [ ! -f /tmp/pkg/update_menus_busy ] && update_menus &
  5178.        fi
  5179.        [ "`which logger`" != '' ] && logger "$0 Package $PKGNAME installed by $APP $APPVER"
  5180.      else
  5181.        error "$PKGNAME may not have installed correctly."
  5182.      fi
  5183.  
  5184.      #100817 clean up user-installed-packages (remove duplicates and empty lines
  5185.      cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages_clean"
  5186.      mv "$PKGS_DIR/user-installed-packages_clean" "$USER_INST_PKGS_FILE"
  5187.  
  5188.      # puppy specific fixes for installed package
  5189.      postinstall_hacks "$PKGNAME" "$PKGNAME_ONLY" &
  5190.  
  5191.      #100622 slackware 13.1: just in case any got through, remove c-shell scripts...
  5192.      rm -f /etc/profile.d/*.csh* 2>/dev/null
  5193.  
  5194.      #120523 precise puppy needs this... (refer also rc.update and 3builddistro)
  5195.      if [ "`grep '/usr/share/glib-2.0/schemas' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}*.files" 2>/dev/null`" != "" ]; then
  5196.        [ -e /usr/bin/glib-compile-schemas ] && /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &>/dev/null
  5197.      fi
  5198.  
  5199.      if [ "`grep '/usr/lib/gio/modules' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" 2>/dev/null`" != "" ]; then
  5200.        [ -e /usr/bin/gio-querymodules ] && /usr/bin/gio-querymodules /usr/lib/gio/modules &>/dev/null
  5201.      fi
  5202.  
  5203.      sync
  5204.  
  5205.    fi #if CONFIRM = y #100213,0.9  moved down to here, fixes install, and output msgs
  5206.  
  5207.  else # file doesn't exists, user must download it first
  5208.  
  5209.    if [ "$PKGNAME" != '' ]; then
  5210.  
  5211.      echo "Package '$PKGNAME' not yet downloaded."
  5212.  
  5213.      matching_local_pkgs="`list_downloaded_pkgs $PKGNAME`"
  5214.  
  5215.      # if no matching pkgs downloaded
  5216.      if [ "$matching_local_pkgs" != "" ]; then
  5217.        echo "You could install one of the following packages with \`$SELF -i PKGNAME\`:"
  5218.        echo "`list_downloaded_pkgs $(basename "$PKGNAME" .$pkg_ext 2>/dev/null) 2>/dev/null`"
  5219.  
  5220.      # else if not downloaded, and in the current repo, list the matching repo pkgs
  5221.      elif [ "$matching_local_pkgs" = "" -a "`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null`" != "" ]; then
  5222.        echo "You must first download one of the following packages with \`$SELF -d PKGNAME\`:"
  5223.        echo "`$PKGSEARCH $(basename $PKGNAME .$pkg_ext)`"
  5224.  
  5225.      else
  5226.        not_found "${PKGNAME}"
  5227.      fi
  5228.  
  5229.    else # PKGNAME is empty
  5230.  
  5231.      echo "Package could not be identified."
  5232.  
  5233.    fi
  5234.  
  5235.    exit 1
  5236.  
  5237.  fi
  5238.  
  5239.  # go back to the dir we started in
  5240.  cd "$PREVDIR"
  5241.  
  5242. }
  5243.  
  5244.  
  5245. postinstall_hacks(){              # fix pkgs after installation
  5246.  local PKGNAME="$1"
  5247.  local PKGNAME_ONLY="$2"
  5248.  
  5249.  # remove %u, %U, %f (etc) from Exec lines
  5250.  DESKTOPFILE="`find /usr/share/applications -iname "${PKGNAME_ONLY}*.desktop"`"
  5251.  [ -f "$DESKTOPFILE" ] && \
  5252.    sed -i 's/ %u//' $DESKTOPFILE && \
  5253.    sed -i 's/ %U//' $DESKTOPFILE && \
  5254.    sed -i 's/ %f//' $DESKTOPFILE && \
  5255.    sed -i 's/ %F//' $DESKTOPFILE
  5256.  
  5257.  case $PKGNAME in
  5258.   0ad-*|0ad_*)
  5259.    bbe -e 's/geteuid/getppid/' /usr/games/pyrogenesis > /usr/games/pyrogenesis1 2>/dev/null
  5260.    mv /usr/games/pyrogenesis1 /usr/games/pyrogenesis
  5261.    chmod 755 /usr/games/pyrogenesis
  5262.   ;;
  5263.   openclonk-*|openclonk_*)
  5264.    bbe -e 's/geteuid/getppid/' /usr/games/openclonk > /usr/games/openclonk1 2>/dev/null
  5265.    mv /usr/games/openclonk1 /usr/games/openclonk
  5266.    chmod 755 /usr/games/openclonk
  5267.   ;;
  5268.   vlc_*|vlc-*)
  5269.    VLCDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname 'vlc*.desktop'`"
  5270.    [ -f $VLCDESKTOP ] && sed -i 's/ --started-from-file %U//' $VLCDESKTOP
  5271.    [ -f $VLCDESKTOP ] && sed -i 's/ --started-from-file//' $VLCDESKTOP
  5272.  
  5273.    #120907 vlc in debian/ubuntu configured to not run as root (it is a pre-compile configure option to enable running as root).
  5274.    #this hack will fix it...
  5275.    #note, this code is also in FIXUPHACK in 'vlc' template.
  5276.    if [ -f /usr/bin/bbe ]; then #bbe is a sed-like utility for binary files.
  5277.     if [ -f /usr/bin/vlc  ]; then
  5278.       bbe -e 's/geteuid/getppid/' /usr/bin/vlc > /tmp/vlc-temp1
  5279.       mv -f /tmp/vlc-temp1 /usr/bin/vlc
  5280.       chmod 755 /usr/bin/vlc
  5281.     fi
  5282.    fi
  5283.   ;;
  5284.   google-chrome-*) #130221 pemasu. 130224 pemasu: limit cache size...
  5285.    if [ -f /usr/bin/bbe ]; then #bbe is a sed-like utility for binary files.
  5286.     if [ -f /opt/google/chrome/chrome  ]; then
  5287.    bbe -e 's/geteuid/getppid/' /opt/google/chrome/chrome > /tmp/chrome-temp1
  5288.    mv -f /tmp/chrome-temp1 /opt/google/chrome/chrome
  5289.    chmod 755 /opt/google/chrome/chrome
  5290.    [ -e /usr/bin/google-chrome ] && rm -f /usr/bin/google-chrome
  5291.    echo '#!/bin/sh
  5292.  exec /opt/google/chrome/google-chrome --user-data-dir=/root/.config/chrome --disk-cache-size=10000000 --media-cache-size=10000000 "$@"' > /usr/bin/google-chrome
  5293.    chmod 755 /usr/bin/google-chrome
  5294.    ln -s google-chrome /usr/bin/chrome
  5295.    ln -s /opt/google/chrome/product_logo_48.png /usr/share/pixmaps/google-chrome.png
  5296.    ln -s /opt/google/chrome/product_logo_48.png /usr/share/pixmaps/chrome.png
  5297.    CHROMEDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname '*chrome*.desktop'`"
  5298.    if [ "$CHROMEDESKTOP" = "" ]; then #precaution.
  5299.     echo '[Desktop Entry]
  5300. Encoding=UTF-8
  5301. Version=1.0
  5302. Name=Google Chrome web browser
  5303. GenericName=Google Chrome
  5304. Comment=Google Chrome web browser
  5305. Exec=google-chrome
  5306. Terminal=false
  5307. Type=Application
  5308. Icon=google-chrome.png
  5309. Categories=WebBrowser;' > /usr/share/applications/google-chrome.desktop
  5310.    fi
  5311.     fi
  5312.    fi
  5313.   ;;
  5314.  chromium*) #130221 pemasu. 130224 pemasu: limit cache size...
  5315.    if [ -f /usr/bin/bbe ]; then #bbe is a sed-like utility for binary files.
  5316.     if [ -f /usr/lib/chromium/chromium  ]; then
  5317.    bbe -e 's/geteuid/getppid/' /usr/lib/chromium/chromium > /tmp/chrome-temp1
  5318.    mv -f /tmp/chrome-temp1 /usr/lib/chromium/chromium
  5319.    chmod 755 /usr/lib/chromium/chromium
  5320.    [ -e /usr/bin/chromium ] && rm -f /usr/bin/chromium
  5321.    echo '#!/bin/sh
  5322.  exec /usr/lib/chromium/chromium --user-data-dir=/root/.config/chrome --disk-cache-size=10000000 --media-cache-size=10000000 --audio-buffer-size=2048 "$@"' > /usr/bin/chromium
  5323.    chmod 755 /usr/bin/chromium
  5324.    ln -s /usr/share/icons/hicolor/48x48/apps/chromium.png /usr/share/pixmaps/chromium.png
  5325.    CHROMEDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname '*chromium-br*.desktop'`"
  5326.    if [ "$CHROMEDESKTOP" = "" ]; then #precaution.
  5327.     echo '[Desktop Entry]
  5328. Encoding=UTF-8
  5329. Version=1.0
  5330. Name=Chromium web browser
  5331. GenericName=Chromium
  5332. Comment=Chromium web browser
  5333. Exec=chromium
  5334. Terminal=false
  5335. Type=Application
  5336. Icon=chromium.png
  5337. Categories=WebBrowser;' > /usr/share/applications/chromium.desktop
  5338.    fi
  5339.     fi
  5340.    fi
  5341.   ;;
  5342.   jwm_theme_*)
  5343.    #120924 DejaVu font no good for non-Latin languages...
  5344.    #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5345.    LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5346.    case $LANGUSER in
  5347.     zh*|ja*|ko*) #chinese, japanese, korean
  5348.    sed -i -e 's%DejaVu Sans%Sans%' /etc/xdg/templates/_root_*
  5349.    sed -i -e 's%DejaVu Sans%Sans%' /root/.jwm/themes/*-jwmrc
  5350.    sed -i -e 's%DejaVu Sans%Sans%' /root/.jwm/jwmrc-theme
  5351.     ;;
  5352.    esac
  5353.    #130326 font size fix for 96 dpi...
  5354.    if [ "$PKGNAME_ONLY" ]; then
  5355.     JWMTHEMEFILE="$(grep '^/root/\.jwm/themes/.*-jwmrc$' "$PACKAGE_FILE_LIST_DIR/${PKGNAME_ONLY}.files" | head -n 1)"
  5356.     [ "$JWMTHEMEFILE" ] && hackfontsize "JWMTHEMES='${JWMTHEMEFILE}'"
  5357.    fi
  5358.   ;;
  5359.   openbox*)
  5360.    #120924 DejaVu font no good for non-Latin languages...
  5361.    #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5362.    LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5363.    case $LANGUSER in
  5364.     zh*|ja*|ko*) #chinese, japanese, korean
  5365.    sed -i -e 's%DejaVu Sans%Sans%' /etc/xdg/openbox/*.xml
  5366.    sed -i -e 's%DejaVu Sans%Sans%' /root/.config/openbox/*.xml
  5367.     ;;
  5368.    esac
  5369.   ;;
  5370.   gtk_theme_*)
  5371.    #120924 DejaVu font no good for non-Latin languages...
  5372.    #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5373.    LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5374.    case $LANGUSER in
  5375.     zh*|ja*|ko*) #chinese, japanese, korean
  5376.    GTKRCFILE="$(find /usr/share/themes -type f -name gtkrc | tr '\n' ' ')"
  5377.    for ONEGTKRC in $GTKRCFILE
  5378.    do
  5379.     sed -i -e 's%DejaVu Sans%Sans%' $ONEGTKRC
  5380.    done
  5381.     ;;
  5382.    esac
  5383.    #130326 font size fix for 96 dpi...
  5384.    if [ "$PKGNAME_ONLY" ]; then
  5385.     GTKTHEMEFILE="$(grep '^/usr/share/themes/.*/gtk-2\.0/gtkrc$' "$PACKAGE_FILE_LIST_DIR/${PKGNAME_ONLY}.files" | head -n 1)"
  5386.     [ "$GTKTHEMEFILE" ] && hackfontsize "GTKRCS='${GTKTHEMEFILE}'"
  5387.    fi
  5388.   ;;
  5389.   seamonkey*|firefox*)
  5390.    #120924 DejaVu font no good for non-Latin languages...
  5391.    #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5392.    LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5393.    case $LANGUSER in
  5394.     zh*|ja*|ko*) #chinese, japanese, korean
  5395.    MOZFILE="$(find /root/.mozilla -type f -name prefs.js -o -name '*.css' | tr '\n' ' ')"
  5396.    for ONEMOZ in $MOZFILE
  5397.    do
  5398.     sed -i -e 's%DejaVu Sans%Sans%' $ONEMOZ
  5399.    done
  5400.     ;;
  5401.    esac
  5402.   ;;
  5403.   mc_*) #121206 midnight commander
  5404.    #in ubuntu, won't run from the menu. this fixes it...
  5405.    [ -f /usr/share/applications/mc.desktop ] && sed -i -e 's%^Exec=.*%Exec=TERM=xterm mc%' /usr/share/applications/mc.desktop
  5406.   ;;
  5407.   xsane*) #130122
  5408.    #xsane puts up a warning msg at startup if running as root, remove it...
  5409.    #this code is also in file FIXUPHACK in xsane template (in Woof).
  5410.    #WARNING: this may only work for x86 binary.
  5411.    if [ -f /usr/bin/bbe ]; then #bbe is a sed-like utility for binary files.
  5412.     if [ -f /usr/bin/xsane  ]; then
  5413.    bbe -e 's/\x6b\x00getuid/\x6b\x00getpid/' /usr/bin/xsane > /tmp/xsane-temp1
  5414.    mv -f /tmp/xsane-temp1 /usr/bin/xsane
  5415.    chmod 755 /usr/bin/xsane
  5416.     fi
  5417.    fi
  5418.   ;;
  5419.   kompozer*) #130507
  5420.    [ -f /usr/bin/kompozer ] && [ -d /usr/lib/kompozer ] && sed -i -e 's%^moz_libdir=%export MOZILLA_FIVE_HOME="/usr/lib/kompozer" #BK\nmoz_libdir=%' /usr/bin/kompozer
  5421.   ;;
  5422.  esac
  5423. }
  5424.  
  5425.  
  5426. choose_pkg(){                     # given partial name ($1), choose from a list of matching packages FUNCLIST
  5427.  
  5428.  
  5429.  # exit if no valid options
  5430.  [ ! "$1" -o "$1" = "" -o "$1" = "-" ] && print_usage get && exit 1
  5431.  
  5432.  # get $REPONAME and $EX
  5433.  . ${PKGRC}
  5434.  
  5435.  local REPOEX    # extension of pkgs in the current repo $REPONAME (from rc file)
  5436.  local PKGEX     # pkg extension we get from $1, defaults to $REPOEXT is empty
  5437.  local PKGNAME   # the name of the pkg, we get this from $1
  5438.  local PKGNAME_ONLY  # the pkg name without version, we get this from PKGNAME
  5439.  local PKGS      # the list of PKGS returned matching $1/$PKGNAME
  5440.  local INT=1     # used to provide numbered lists
  5441.  
  5442.  REPOEX=$EX
  5443.  # get pkg extension
  5444.  PKGEX=`get_pkg_ext "$1"`
  5445.  
  5446.  # if no extension, set to extension of current repo
  5447.  [ "$PKGEX" = '' ] && PKGEX=$REPOEX
  5448.  
  5449.  # get pkg name with version, no extension or path
  5450.  PKGNAME="$(basename "$1" .$PKGEX)"
  5451.  
  5452.  # get the full pkg name, to compare against repo pkgs we find
  5453.  PKGNAME_FULL="`get_pkg_name "$PKGNAME"`"
  5454.  
  5455.  # get pkg name only .. without version or suffix
  5456.  PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5457.  
  5458.  # remove any previous user choice lists
  5459.  rm $TMPDIR/PKGLIST &>/dev/null
  5460.  rm $TMPDIR/USRPKGLIST &>/dev/null
  5461.  
  5462.  # get all pkgs that match the given pkgname
  5463.  # returns full pkg names (field1 of repo, pkgname with ver but no extension) each on a new line
  5464.  PKGS="`$PKGSEARCH "${PKGNAME}"`"
  5465.  
  5466.  if [ "$FORCE" = false -a "`is_installed_pkg "$PKGNAME_FULL"`" = true -a "$HIDE_INSTALLED" = true ]; then
  5467.    # remove it from choices
  5468.    PKGS="`echo "$PKGS" | grep -v ^$PKGNAME_FULL\$`"
  5469.  fi
  5470.  
  5471.  # extra steps for ubuntu and debian repos, if multiple choices returned.. remove non-compatible archs, remove dev and dbg pkgs...
  5472.  if [ "$PKGEX" = "deb" -a "`echo "$PKGS" | wc -l`" != "1" ]; then
  5473.  
  5474.    ARCH="`uname -m`"
  5475.    #remove x64 pkgs from choices if not using an x64 cpu
  5476.    [ "$ARCH" != "x86_64" ] && PKG="`echo "$PKGS" | grep -v -E 'amd64|x86_64'`"
  5477.  
  5478.    # set any pkgs matching current arch to top of list
  5479.    for LINE in `echo "$PKGS"  | sort -r` #first pkg found (newest) added to top, then the next, etc, sort use sort -r to keep newest at top of new list
  5480.    do
  5481.      # if not searching for -dev or -dgb pkg, move it to bottom of the list
  5482.      if [ "`is_blacklisted_pkg "$LINE"`" = false -a "`echo "$PKGNAME" | grep -E "\-dbg_|\-dev_"`" = "" -a "`echo "$LINE" | grep -E "\-dbg_|\-dev_"`" != "" ]; then
  5483.        PKGS="`echo "$PKGS" | grep -v  "$LINE"`"
  5484.        PKGS="$PKGS
  5485. $LINE"
  5486.      fi
  5487.      # if pkg is for current cpu arch, move it to top of the list
  5488.      if [ "`echo "$LINE" | grep -m1 "$ARCH"`" != "" ]; then
  5489.        PKGS="`echo "$PKGS" | grep -v  "$LINE"`"
  5490.        PKGS="$LINE
  5491. $PKGS"
  5492.      fi
  5493.    done
  5494.    #remove debug and dev pkgs
  5495.    #PKGS="`echo "$PKGS" | grep -v "\-dbg_"`"
  5496.    #PKGS="`echo "$PKGS" | grep -v "\-dev_"`"
  5497.  fi
  5498.  
  5499.  # get the user to choose which packages they want to install
  5500.  if [ "$ASK" = true -a "$PKGS" != "" ]; then
  5501.    echo "Please choose the package number. For the first package,"
  5502.    echo "enter '1', without quotes. To install multiple packages,"
  5503.    echo "enter the numbers, separated by a comma. Example:  1,3,4"
  5504.    echo
  5505.  fi
  5506.  
  5507.  # if using ubuntu/debian packages, put pkg_* before pkg-* .. else dont
  5508.  [ "$PKGEX" = 'deb' ] && sort='sort -r' || sort='sort'
  5509.  
  5510.  # go through each actual pkg that matches the pkgname search, make it a numbered list
  5511.  echo "$PKGS" | $sort -u | while read LINE
  5512.  do
  5513.    if [ "$LINE" != "" -a "$LINE" != "," -a "$LINE" != " " ]; then
  5514.      [ "$ASK" = true ] && echo "${INT}. $LINE"
  5515.      echo "${INT}. $LINE" >> $TMPDIR/PKGLIST
  5516.      INT=$(($INT + 1))
  5517.    fi
  5518.  done
  5519.  
  5520.  # if pkg list was made
  5521.  if [ -f $TMPDIR/PKGLIST -a "`cat $TMPDIR/PKGLIST 2>/dev/null`" != "" ]; then
  5522.  
  5523.    # set to first pkg only as default
  5524.    if [ "$ASK" = false ]; then
  5525.      USRPKGLIST="$(echo "$PKGS" | $sort | head -1)"
  5526.      echo "$USRPKGLIST" > $TMPDIR/USRPKGLIST
  5527.    fi
  5528.  
  5529.    # user can now input which actual pkgs to get, chosen by number
  5530.    if [ "$ASK" = true ]; then
  5531.      # only ask once
  5532.      ASK=false
  5533.  
  5534.      echo
  5535.      echo "Give the numbers of the packages you want to install,"
  5536.      echo -n "separated by a comma, or hit ENTER only to skip: "
  5537.      read USRPKGLIST1 </dev/tty
  5538.  
  5539.      # if user chose nothing (hit ENTER only), just skip
  5540.      [ "$USRPKGLIST1" = '' ] && continue
  5541.  
  5542.      # split the results into newlines, create the list of chosen pkgs (used by other funcs)
  5543.      echo "${USRPKGLIST1}" | tr ',' '\n' | while read LINE
  5544.      do
  5545.        # set chosen pkg choice(s)
  5546.        echo "`grep "^$LINE. " "$TMPDIR/PKGLIST" 2>/dev/null | cut -f2 -d' '`" >> $TMPDIR/USRPKGLIST
  5547.      done
  5548.    fi
  5549.  
  5550.    # remove temp file.. but keep $TMPDIR/USRPKGLIST, it contains our users choices, and is used by pkg_get() and get_deps()
  5551.    rm $TMPDIR/PKGLIST &>/dev/null
  5552.  fi
  5553. }
  5554.  
  5555.  
  5556. pkg_get(){                        # find, download and install $1 and its deps FUNCLIST
  5557.  
  5558.  # The function `choose_pkg` is run just before this one. It gives us $TMPDIR/USRPKGLIST,
  5559.  # which contains a list of packages the user wants to install or download.
  5560.  # In this func, we will go through the list and download/install the package, as well
  5561.  # as its dependencies (depending on what the user chose to do).
  5562.  
  5563.  . ${PKGRC}
  5564.  
  5565.  # exit if no valid options
  5566.  [ ! "$1" -o "$1" = "" -o "$1" = "-" ] && print_usage get && exit 1
  5567.  
  5568.  local PREVDIR="$CURDIR"
  5569.  local pkg_ext=`get_pkg_ext "$1"`; pkg_ext="${pkg_ext:-$EX}" # fall back to repo extension
  5570.  local PKGNAME="`get_pkg_name $(basename "$1" .$pkg_ext)`"
  5571.  local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5572.  local PKGLIST="${PKGNAME}"
  5573.  local pkg_builtin=''
  5574.  
  5575.  # dont ask to download or install pkg or deps, as choose_pkg() already asked
  5576.  ASK=false
  5577.  
  5578.  # exit if no valid pkg name
  5579.  [ ! "$PKGNAME" -o "$PKGNAME" = "" -o "$PKGNAME" = "-" ] && print_usage get && exit 1
  5580.  
  5581.  # we want to download all pkgs to same place
  5582.  cd "$WORKDIR"
  5583.  CURDIR="$WORKDIR"
  5584.  
  5585.  # use the list of pkgs user has chosen to install, or the given PKGNAME
  5586.  if [ "`cat "$TMPDIR/USRPKGLIST" 2>/dev/null`" != "" ]; then
  5587.    PKGLIST="`cat "$TMPDIR/USRPKGLIST" | grep -v "^\$"`"
  5588.  fi
  5589.  
  5590.  if [ -z "$PKGLIST" ]; then
  5591.    echo "No packages to get, exiting."
  5592.    exit 1
  5593.  fi
  5594.  
  5595.  # skip if any pkgs previously installed during our current loop (of getting 'pkg + recursive deps')
  5596.  echo "$PKGLIST" | while read pkg_in_list
  5597.  do
  5598.    name_only=`get_pkg_name_only "$pkg_in_list"`
  5599.    [ -f $TMPDIR/PKGSDONE -a "`grep "^${name_only}\$" $TMPDIR/PKGSDONE 2>/dev/null`" != '' ] && continue
  5600.  done
  5601.  
  5602.  # list the pkgs and ask to download (and maybe install)
  5603.  echo "$PKGLIST" | while read pkg
  5604.  do
  5605.  
  5606.    [ "$pkg" = '' -o ! "$pkg" ] && continue
  5607.  
  5608.    local pkg_name=`get_pkg_name "$pkg" 2>/dev/null`
  5609.    [ "$pkg_name" = '' -o ! "$pkg_name" ] && continue
  5610.  
  5611.    local pkg_name_only=`get_pkg_name_only "$pkg" 2>/dev/null`
  5612.    [ "`is_blacklisted_pkg "$pkg_name_only"`" = true ] && continue
  5613.  
  5614.    local pkg_already_done=`grep -m1 "^$pkg_name_only\$" $TMPDIR/PKGSDONE 2>/dev/null`
  5615.    [ "$pkg_already_done" != '' ] && continue
  5616.  
  5617.    local pkg_in_repo=`is_repo_pkg $pkg_name_only`
  5618.    local PKGFILE=''
  5619.  
  5620.    # dont even try to download if no matches found
  5621.    if [ "$pkg_in_repo" = true -a "$pkg_name_only" != "" ]; then
  5622.  
  5623.      local pkg_is_builtin=`is_builtin_pkg "$pkg_name_only"`
  5624.      local pkg_is_in_devx=`is_devx_pkg "$pkg_name_only"`
  5625.  
  5626.      # skip getting pkg if its a builtin, unless HIDE_BUILTINS=false
  5627.      if [ "$pkg_is_builtin" = true -a "${HIDE_BUILTINS}" = true ]; then
  5628.        echo "Skipping $pkg_name_only (already built-in).."
  5629.        continue
  5630.      fi
  5631.  
  5632.      # skip getting pkg if its in the devx, unless HIDE_BUILTINS=false
  5633.      if [ "$pkg_is_in_devx" = true -a "${HIDE_BUILTINS}" = true ]; then
  5634.        echo "Skipping $pkg_name_only (already in devx).."
  5635.        continue
  5636.      fi
  5637.  
  5638.      # if we are intending to install the pkg
  5639.      if [ "$NO_INSTALL" = false -a "$FORCE" = false ]; then
  5640.        # skip if package is already installed, unless --force given
  5641.        if [ "$FORCE" = false -a "`is_installed_pkg $pkg_name`" = true ]; then
  5642.          echo -e "Package ${magenta}${pkg_name_only}${endcolour} already installed."
  5643.          echo -e "Use the -f option to force installation: $SELF add $pkg_name_only -f"
  5644.          continue
  5645.        fi
  5646.      fi
  5647.  
  5648.      # get deps early (if any)
  5649.      list_deps "$pkg_name" > ${TMPDIR}/${pkg_name}_dep_list &
  5650.  
  5651.      # DOWNLOAD PKG
  5652.      pkg_download "$pkg_name"
  5653.  
  5654.      [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}.*${pkg_ext}"`"
  5655.      # try grabbing $CURDIR/pkgname.pkg_ext
  5656.      [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}*.${pkg_ext}"`"
  5657.      # now try grabbing $CURDIR/pkgname.*
  5658.      [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}.*"`"
  5659.      # maybe try $CURDIR/pkgname-*.*
  5660.      [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}-*.*"`"
  5661.      # maybe try $CURDIR/pkgname_*.*
  5662.      [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}_*.*"`"
  5663.      # maybe try $CURDIR/pkgname*.*
  5664.      [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}*.*"`"
  5665.  
  5666.      # add extension if Pkg returned an erroneous or user dir
  5667.      [ -d "$PKGFILE" ] && PKGFILE="${PKGFILE}.$pkg_ext"
  5668.  
  5669.      # if we found the package to install in CURDIR
  5670.      if [ -f "${PKGFILE}" ]; then
  5671.  
  5672.        # check if we install or not
  5673.        if [ "${NO_INSTALL}" = false ]; then
  5674.  
  5675.          # if a valid pkg, with files to extract
  5676.          if [ "`pkg_contents "$PKGFILE" 2>/dev/null`" != '' ]; then
  5677.  
  5678.  
  5679.            #INSTALL PKG
  5680.            [ "`is_local_pkg "$PKGFILE"`" = true ] && pkg_install "${PKGFILE}"
  5681.  
  5682.  
  5683.          fi
  5684.  
  5685.        fi
  5686.  
  5687.        # if pkg was installed, or Pkg is simply downloading all deps
  5688.        if [ "`is_installed_pkg "$pkg_name_only"`" = true -o "${NO_INSTALL}" = true ]; then
  5689.  
  5690.          # get the dependencies for this package
  5691.          get_deps "${pkg_name}"
  5692.          #rm /tmp/pkg/list_deps_busy #s243a: we might want to remove list_deps_busy here
  5693.        fi
  5694.  
  5695.      else # PKGFILE not a file
  5696.        echo "Can't find ${PKGNAME} or not a valid pkg.."
  5697.      fi
  5698.  
  5699.    else # no matches in repo found
  5700.      echo "Cannot find ${PKGNAME}.."
  5701.    fi
  5702.  
  5703.    # done with this pkg, add it to done list, will be skipped it seen again, until loop is finished
  5704.    echo "$pkg_name_only" >> $TMPDIR/PKGSDONE
  5705.  done
  5706. }
  5707.  
  5708.  
  5709. pkg_update(){                     # update installed pkgs, $1 is optional filter FUNCLIST
  5710.  
  5711.  # exit if no valid options
  5712.  #[ ! "$1" -o "$1" = "-" ] && print_usage pkg-update && exit 1
  5713.  
  5714.  # get rc file settings
  5715.  . ${PKGRC}
  5716.  
  5717.  local PKGNAME=''
  5718.  local PKGLIST=''
  5719.  local pkg_ext=$EX
  5720.  local BUILTINS=''
  5721.  local separator=''
  5722.  
  5723.  if [ "$1" != '' ]; then
  5724.  
  5725.    PKGNAME=$(basename "$1")
  5726.    PKGNAME=`get_pkg_name "$PKGNAME"`
  5727.    PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5728.  
  5729.    # get installed packages
  5730.    PKGLIST="`HIDE_BUILTINS=false list_installed_pkgs "$PKGNAME_ONLY"`"
  5731.  
  5732.    #is_builtin=`is_builtin_pkg "$PKGNAME"`
  5733.  
  5734.    # dont update builtins unless -F was given
  5735.    #if [ "$is_builtin" = true -a "$HIDE_BUILTINS" = true ]; then
  5736.    #  echo -e "Package ${magenta}${PKGNAME}${endcolour} is built in, not updating."
  5737.    #  #echo -e "Use `$SELF -F --pkg-update $PKGNAME` to update it anyway."
  5738.    #  exit 0
  5739.    #fi
  5740.  else
  5741.    # get installed packages
  5742.    PKGLIST="`HIDE_BUILTINS=false list_installed_pkgs`"
  5743.  fi
  5744.  
  5745.  # iterate over the list
  5746.  echo "$PKGLIST"  | grep -v ^$ | sort -u | while read installed_pkg; do
  5747.  
  5748.    [ ! "$installed_pkg" -o "$installed_pkg" = '' ] && continue
  5749.  
  5750.    # if this pkg ($installed_pkg) is not from a known repo, we cant compare its version to anything else, skip it
  5751.    #[ "`is_repo_pkg "$installed_pkg"`" = false ] && echo -e "Package ${magenta}$installed_pkg${endcolour} not found in any repos." && continue
  5752.  
  5753.    local PNAME=''
  5754.    local latest_repo_pkg=''
  5755.    local ASKREPLY='y'
  5756.    # get pkg name (without version) and version of current PKG
  5757.  
  5758.    PNAME=`get_pkg_name_only $installed_pkg`
  5759.  
  5760.    [ "$PNAME" = '' ] && continue
  5761.  
  5762.    case $DISTRO_BINARY_COMPAT in
  5763.      ubuntu|trisquel|debian|devuan)
  5764.        separator='_'
  5765.        ;;
  5766.      *)
  5767.        separator='-'
  5768.        ;;
  5769.    esac
  5770.  
  5771.    latest_repo_pkg="`grep -m1 "^${PNAME}${separator}" "${ALL_REPO_DB_PATHS[@]}" |cut -f1 -d'|' | head -1 | cut -f2 -d':'`"
  5772.  
  5773.    # skip if we didn't find the right package
  5774.    [ "`echo "$latest_repo_pkg" | grep "^${PNAME}${separator}"`" = '' ] && continue
  5775.  
  5776.    latest_version=`get_pkg_version "$latest_repo_pkg"`
  5777.    installed_version=`get_pkg_version "$installed_pkg"`
  5778.  
  5779.    # get latest versions
  5780.  
  5781.    # check pkg version against installed version
  5782.    if [ "$latest_version" != "" -a "$installed_version" != "" ]; then
  5783.      vercmp $latest_version gt $installed_version 2>/dev/null
  5784.      RESULT=$?
  5785.  
  5786.      if [ "$RESULT" = 0 ]; then #newer version available
  5787.  
  5788.        if [ "$ASK" = true ]; then
  5789.          echo "Do you want to update to ${PNAME}${separator}${latest_version}? [y/N]   "
  5790.          read -n 1 ASKREPLY </dev/tty
  5791.          [ "$ASK" = true ] && echo -ne "\b\b\n"
  5792.        fi
  5793.  
  5794.        if [ "$ASK" = false -o "$ASKREPLY" = "y" ]; then
  5795.          echo -e "${yellow}Update${endcolour}: ${magenta}$PNAME${endcolour} from ${bold}$installed_version${endcolour} to ${bold}$latest_version${endcolour}"
  5796.          cd "$WORKDIR"
  5797.          ASK=$ASK FORCE=$FORCE pkg_get "$latest_repo_pkg"
  5798.          cd "$CURDIR"
  5799.        fi
  5800.  
  5801.      else #280613 inform user if no update found
  5802.        echo -e "${green}Latest${endcolour}: $PNAME${separator}$installed_version"
  5803.      fi #end if vercmp XX gt YY = 0
  5804.  
  5805.    elif [ "$PNAME" = '' ]; then
  5806.      error "${installed_pkg} not found."
  5807.    else #280613
  5808.      error "$installed_pkg package versions could not be compared: ${latest_version:-unknown latest} => ${installed_version:-unknown installed version}"
  5809.      #return 1
  5810.    fi #end if PKGVER != ""
  5811.  done
  5812. }
  5813.  
  5814.  
  5815. pkg_uninstall(){                  # remove an installed package ($1) FUNCLIST
  5816.  
  5817.  # quit if no valid options
  5818.  [ ! "$1" -o "$1" = "-" ] && print_usage uninstall && exit 1
  5819.  
  5820.  local PKGNAME
  5821.  local PKGNAME_ONLY
  5822.  local PKGFILE
  5823.  local pkg_ext
  5824.  
  5825.  # get pkg extension
  5826.  pkg_ext=`get_pkg_ext "$1"`
  5827.  
  5828.  #get pkg name with version, but no extension or path
  5829.  PKGNAME="$(basename "$1" .$pkg_ext)"
  5830.  PKGNAME="$(basename "$PKGNAME" .pet)"
  5831.  PKGNAME="$(basename "$PKGNAME" .deb)"
  5832.  PKGNAME="$(basename "$PKGNAME" .sfs)"
  5833.  PKGNAME="$(basename "$PKGNAME" .tar.gz)"
  5834.  PKGNAME="$(basename "$PKGNAME" .tar.xz)"
  5835.  PKGNAME="$(basename "$PKGNAME" .tgz)"
  5836.  PKGNAME="$(basename "$PKGNAME" .txz)"
  5837.  PKGNAME=`get_pkg_name "$PKGNAME"`
  5838.  
  5839.  # get pkg name only .. without versions or suffix
  5840.  PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  5841.  
  5842.  local pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY"`
  5843.  local is_installed=`is_installed_pkg "$PKGNAME"`
  5844.  
  5845.  # skip pkg if its a builtin
  5846.  [ "$pkg_is_builtin" = true ] && return 1
  5847.  
  5848.  local pkg_is_sfs_file="`sfs_loadr -q -i | grep -v ^sfs_loadr | grep ^$PKGNAME`"
  5849.  
  5850.  # if pkg is SFS, "uninstall" it here
  5851.  if [ "$pkg_is_sfs_file" != "" -o "$pkg_ext" = "sfs" ]; then
  5852.    PKGNAME="$(sfs_loadr -q -i | grep -v ^sfs_loadr | grep ^$PKGNAME | head -1)"
  5853.    sfs_loadr -q --cli -"${CURDIR}/${PKGNAME}" 2>/dev/null
  5854.    is_installed=true # we want to continue
  5855.  fi
  5856.  
  5857.  
  5858.  if [ "$is_installed" = true -o "$FORCE" = true ]; then #250713
  5859.  
  5860.    # get the list of files to be deleted, exact match
  5861.    PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "$PKGNAME.files")"
  5862.  
  5863.    # if no exact match, search for pkgname*
  5864.    [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}"'*.files')"
  5865.    [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}_"'*.files')"
  5866.    [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}-"'*.files')"
  5867.    [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}.files"
  5868.    [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}.sfs.files"
  5869.    [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}-${CP_SUFFIX}.sfs.files"
  5870.  
  5871.    #if PKG.files not found, then remove it from alien packages list
  5872.    if [ ! -f "$PKGFILE" ]; then
  5873.  
  5874.      #error "'${PKGFILE}' not found.. Cleaning up.."
  5875.  
  5876.      # backup the original list of user installed pkgs
  5877.      cp "$USER_INST_PKGS_FILE" $TMPDIR/user-installed-packages.backup
  5878.  
  5879.      # remove $PKGNAME from list of installed pkgs
  5880.      cat "$USER_INST_PKGS_FILE" 2>/dev/null | grep -v "^${PKGNAME}" > "$PKGS_DIR/user-installed-packages.updated"
  5881.  
  5882.      # if we created a new file ok
  5883.      if [ -f "$PKGS_DIR/user-installed-packages.updated" ]; then
  5884.        # replace the user-installed-packages file with our new one
  5885.        mv "$PKGS_DIR/user-installed-packages.updated" "$USER_INST_PKGS_FILE" 2>/dev/null
  5886.      fi
  5887.  
  5888.      # clean up user-installed-packages (remove duplicates and empty lines)
  5889.      cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages.clean"
  5890.      mv "$PKGS_DIR/user-installed-packages.clean" "$USER_INST_PKGS_FILE"
  5891.  
  5892.      # no *.files to process, so if not forcing full uninstall, we can exit here
  5893.      [ "$FORCE" = false ] && return 1
  5894.    fi
  5895.  
  5896.    # if we are here, we have a $PKGS_DIR/***.files to work with (or using --force)
  5897.  
  5898.    # get pkgs that depend on $PKGNAME
  5899.    [ "$FORCE" = false ] && dependents="`list_dependents "$PKGNAME"`" || dependents=''
  5900.  
  5901.    # if we have dependents, we should not uninstall and just exit, unless --force was given
  5902.    if [ "$dependents" != "" -a "`echo "$dependents" | grep 'not installed'`" = '' -a "$FORCE" != true ]; then
  5903.  
  5904.      # inform user of dependent pkgs
  5905.      echo -e "${yellow}Warning${endcolour}: $PKGNAME_ONLY is needed by:  "
  5906.      echo -e "${magenta}$dependents${endcolour}"
  5907.      echo "Uninstall the packages above first, or use:"
  5908.      echo -e "${bold}pkg --force uninstall $PKGNAME${endcolour}."
  5909.      echo
  5910.      return 1
  5911.  
  5912.    fi
  5913.  
  5914.    # ask/inform user before uninstall
  5915.    echo -n "Uninstall the package ${PKGNAME}$QTAG:  "
  5916.    [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  5917.    [ "$ASK" = true ] && echo -ne "\b\b\n"
  5918.  
  5919.    # if user answered yes, we will now uninstall the pkgs
  5920.    if [ "$CONFIRM" = "y" ]; then
  5921.  
  5922.      # print new line if we didnt take any user input on tty
  5923.      [ "$ASK" != true ] && echo
  5924.  
  5925.      # execute uninstall script.
  5926.      if [ -x "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" ]; then
  5927.        "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" &>/dev/null
  5928.        rm -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" &>/dev/null
  5929.      fi
  5930.  
  5931.      # if we have no pkg file (listing of pkg contents), we cant cat/grep it
  5932.      if [ ! -f "$PKGFILE" ]; then
  5933.        echo "Not found: $PKGS_DIR/$PKGNAME.files"
  5934.        return 1
  5935.      fi
  5936.  
  5937.      # check if has menu entry
  5938.      [ "`cat "$PKGFILE" | grep -m1 ".desktop\$"`" != "" ] && HASMENUENTRY=true || HASMENUENTRY=false
  5939.  
  5940.      # remove files listed in *.files
  5941.      cat "$PKGFILE" | while read LINE
  5942.      do
  5943.        # some symlinks may not get removed. '-e' will not work if symlink
  5944.        # is pointing to a non-existent file. So, check for symlink...
  5945.        REMFILE=""
  5946.        [ -h "$LINE" ] && REMFILE="yes"
  5947.        [ -e "$LINE" ] && REMFILE="yes"
  5948.        if [ "$REMFILE" = "yes" ]; then
  5949.          if [ ! -d "$LINE" ]; then
  5950.            if [ -e "/initrd/pup_ro2$LINE" ]; then
  5951.              # deleting the file on the top layer places a ".wh" whiteout file, that hides the original file.
  5952.              # what we want is to remove the installed file, and restore the original pristine file...
  5953.              cp -af "/initrd/pup_ro2${LINE}" "$LINE"
  5954.            else
  5955.              rm -f "$LINE" &>/dev/null
  5956.            fi
  5957.            #delete empty dirs...
  5958.            DELDIR="`dirname "$LINE" 2>/dev/null`"
  5959.            [ "`ls -1 "$DELDIR"`" = "" ] && rmdir "$DELDIR" &>/dev/null
  5960.          fi
  5961.        fi
  5962.      done
  5963.  
  5964.      # go through again and remove any empty dirs...
  5965.      cat "$PKGFILE" 2>/dev/null  | while read LINE
  5966.      do
  5967.        DELDIR="`dirname "$LINE" 2>/dev/null`"
  5968.        [ -d "$DELDIR" ] && [ "`ls -1 "$DELDIR"`" = "" ] && rmdir "$DELDIR"
  5969.        #check one level up... but do not delete top dir, like /opt...
  5970.        DELLEVELS=`echo -n "$DELDIR" | sed -e 's/[^/]//g' | wc -c | sed -e 's/ //g'`
  5971.        if [ $DELLEVELS -gt 2 ]; then
  5972.          DELDIR="`dirname "$DELDIR" 2>/dev/null`"
  5973.          [ -d "$DELDIR" ] && [ "`ls -1 "$DELDIR"`" = "" ] && rmdir $DELDIR
  5974.        fi
  5975.      done
  5976.  
  5977.      # remove $PKGNAME from user-installed-packages
  5978.      NEWUSERPKGS="$(grep -v "^${PKGNAME}" "$USER_INST_PKGS_FILE")"
  5979.      [ "$NEWUSERPKGS" != "" ] && echo "$NEWUSERPKGS" > "$USER_INST_PKGS_FILE"
  5980.  
  5981.      # clean up user-installed-packages (remove duplicates and empty lines)
  5982.      cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages_clean"
  5983.      mv "$PKGS_DIR/user-installed-packages_clean" "$USER_INST_PKGS_FILE"
  5984.  
  5985.      # remove $PKGS_DIR/$PKGNAME.files
  5986.      rm $PKGFILE ${PKGFILE} 2>/dev/null
  5987.  
  5988.      # do fixmenus, if menu entry found
  5989.      if [ "$HASMENUENTRY" = true ]; then
  5990.        [ ! -f /tmp/pkg/update_menus_busy ] && update_menus &
  5991.      fi
  5992.  
  5993.      # UNINSTALL DONE .. print message
  5994.      echo -e "${green}Uninstalled:${endcolour} $PKGNAME"
  5995.  
  5996.      # log uninstall with the system logs
  5997.      [ "`which logger`" != '' ] && logger "$0 Package $PKGNAME uninstalled by $APP $APPVER"
  5998.  
  5999.    fi #end if $CONFIRM=yes
  6000.  
  6001.  else # $PKGNAME is not installed
  6002.  
  6003.    # if any installed pkg matches $PKGNAME
  6004.    if [ "`list_installed_pkgs $PKGNAME`" != "" ]; then #290613
  6005.      # list the matching pkgs
  6006.      echo "These installed packages match '$PKGNAME':"
  6007.      echo "`list_installed_pkgs $PKGNAME`"
  6008.    fi
  6009.  
  6010.    return 1
  6011.  
  6012.  fi # endif installed or not
  6013. }
  6014.  
  6015.  
  6016. pkg_remove(){                     # remove pkg ($1) and its leftover deps FUNC_LIST
  6017.  
  6018.  # quit if no valid options
  6019.  [ ! "$1" -o "$1" = "-" ] && print_usage remove && exit 1
  6020.  
  6021.  local PKGNAME
  6022.  local PKGNAME_ONLY
  6023.  local PKGFILE
  6024.  local pkg_ext
  6025.  
  6026.  # get pkg extension
  6027.  pkg_ext=`get_pkg_ext "$1"`
  6028.  
  6029.  #get pkg name with version, but no extension or path
  6030.  PKGNAME="$(basename "$1" .$pkg_ext)"
  6031.  PKGNAME=`get_pkg_name "$PKGNAME"`
  6032.  
  6033.  # get pkg name only .. without versions or suffix
  6034.  PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  6035.  
  6036.  if [ "`is_installed_pkg "$PKGNAME"`" = false ]; then
  6037.    echo "Package '$1' not installed."
  6038.    return 1
  6039.  fi
  6040.  
  6041.  pkg_uninstall "$PKGNAME"
  6042.  
  6043.  # now we will remove any left over dependencies
  6044.  
  6045.  file="`find $TMPDIR -iname "${1}*_dep_list"`"
  6046.  
  6047.  if [ -f "$file" ]; then
  6048.  
  6049.    # if we have a deps list file, go over it three times, uninstalling all deps
  6050.    # that have no packages that depend on them ... fugly solution, but works ok..
  6051.  
  6052.    for x in 1 2 3 4
  6053.    do
  6054.      cat "$file" | tr ' ' '\n' | while read user_installed_dep
  6055.      do
  6056.        [ "$user_installed_dep" = '' ] && continue
  6057.        ASK=false pkg_uninstall $user_installed_dep &>/dev/null && \
  6058.          echo -e "${green}Uninstalled:${endcolour} $(get_pkg_name $user_installed_dep)"
  6059.      done
  6060.    done
  6061.  
  6062.  fi
  6063.  
  6064.  return 0
  6065. }
  6066.  
  6067.  
  6068. clean_pkgs(){                     # delete downloaded pkg files of installed pkgs FUNCLIST
  6069.  local pkg_to_rm
  6070.  [ "$ASK" = true ] && ASKOPT='--ask'
  6071.  # list all (matching) installed pkgs
  6072.  list_installed_pkgs | while read line;
  6073.  do
  6074.    # get all pkgs except the combined (user-created) pkgs
  6075.    pkg_to_rm="`list_downloaded_pkgs $line | grep -v $CP_SUFFIX`"
  6076.    # if it has a downloaded pkg in $WORKDIR, (offer to) delete it
  6077.    [ "$pkg_to_rm" != '' ] && rm -v "${WORKDIR}/$pkg_to_rm";
  6078.  done
  6079. }
  6080.  
  6081.  
  6082. # dependency funcs
  6083.  
  6084. get_deps_entry(){                 # $1 is PKGNAME, returns dep entry from repo db
  6085.  [ "$1" = '' -o "$1" = "-" ] && print_usage list-deps && exit 1
  6086.  
  6087.  # get current $REPOFILE, $DEPSEARCH
  6088.  #. ${PKGRC}
  6089.  
  6090.  local PKGNAME="$1"
  6091.  local pkg_ext=''
  6092.  local repo_files=''
  6093.  local deps_list=''
  6094.  local deps=''
  6095.  local repo_of_pkg=''
  6096.  local repo_file_of_pkg=''
  6097.  
  6098.  # get pkg extension
  6099.  pkg_ext=`get_pkg_ext "$1"`
  6100.  
  6101.  
  6102.  # get repo file to search from RC file
  6103.  repo_file_of_pkg="$REPOFILE"
  6104.  
  6105.  # if searching dependencies in all repos
  6106.  if [ "$DEPSEARCH" = "list_all_pkg_names" ]; then
  6107.  
  6108.    # get the repo that $PKGNAME lives in
  6109.    repo_of_pkg=`which_repo "$PKGNAME" | cut -f2 -d' ' | head -1`
  6110.    # then get the repo file for that repo.. that is where this pkg lists its deps
  6111.    repo_file_of_pkg=`grep -m1 ^"$repo_of_pkg" ~/.pkg/sources-all | cut -f3 -d'|'`
  6112.  
  6113.  fi
  6114.  
  6115.  # add the full path to the repo file
  6116.  repo_file_of_pkg="$REPO_DB_FILE_DIR/$repo_file_of_pkg"
  6117.  
  6118.  # search for deps entry in repo file.. look for |pkgname.ext|
  6119.  deps_list="`LANG=C grep -m1 "|${PKGNAME}.$pkg_ext|" $repo_file_of_pkg 2>/dev/null | cut -f9 -d'|' | grep '+' | sed -e "s/:any//g" -e "s/&[geql][eqt][0-9a-z._-]*//g" | grep -vE '/ge|/le'`"
  6120.  
  6121.  # try again if needed.. look for ^pkgname|
  6122.  [ "$deps_list" = "" -a "$PKGNAME" != '' ] && deps_list="`LANG=C grep -m1 "^${PKGNAME}|" $repo_file_of_pkg 2>/dev/null | cut -f9 -d'|' | grep '+' | sed -e "s/:any//g" -e "s/&[geql][eqt][0-9a-z._-]*//g" | grep -v '/ge'`"
  6123.  
  6124.  # try again if needed.. look for |pkgname|
  6125.  [ "$deps_list" = "" -a "$PKGNAME" != '' ] && deps_list="`LANG=C grep -m1 "|${PKGNAME}|" $repo_file_of_pkg 2>/dev/null | cut -f9 -d'|' | grep '+' | sed -e "s/:any//g" -e "s/&[geql][eqt][0-9a-z._-]*//g" | grep -vE '/ge|/le'`"
  6126.  
  6127.  # try again, look for dep-*
  6128.  [ "$deps_list" = "" -a "$PKGNAME" != '' ] && deps_list="`LANG=C grep -m1 "^${PKGNAME}-" $repo_file_of_pkg 2>/dev/null | cut -f9 -d'|' | grep '+' | sed -e "s/:any//g" -e "s/&[geql][eqt][0-9a-z._-]*//g" | grep -vE '/ge|/le'`"
  6129.  
  6130.  # try again if needed.. with underscore.. dep_*
  6131.  [ "$deps_list" = "" -a "$PKGNAME" != '' ] && deps_list="`LANG=C grep -m1 "^${PKGNAME}_" $repo_file_of_pkg 2>/dev/null | cut -f9 -d'|' | grep '+' | sed -e "s/:any//g" -e "s/&[geql][eqt][0-9a-z._-]*//g" | grep -vE '/ge|/le'`"
  6132.  
  6133.  # if no deps, exit with error
  6134.  [ "$deps_list" != "" ] && echo "$deps_list"
  6135. }
  6136. list_all_installed_pkgs_old(){        # list inc builtins if HIDE_BUILTINS=false
  6137.  # reset list of installed pkgs
  6138.  echo -n '' > $TMPDIR/installed_pkgs
  6139.  
  6140.  #if [ "${HIDE_INSTALLED}" = true -a "$FORCE" = false ]; then
  6141.  #  # add user installed pkgs to list of pkgs to remove from final output
  6142.    cut -f2 -d'|' "$USER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6143.  #fi
  6144.  
  6145.  #if [ "${HIDE_BUILTINS}" = true ]; then
  6146.  #  # add builtins to list of pkgs to remove from final output
  6147.    cut -f2 -d'|' "$WOOF_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6148.  #fi
  6149.  
  6150.  #if [ -f "$DEVX_INST_PKGS_FILE"  ]; then
  6151.  #  # add devx pkgs to list of pkgs to remove from final output
  6152.    cut -f2 -d'|' "$DEVX_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6153.  #fi
  6154.  
  6155.  #if [ -f "$LAYER_INST_PKGS_FILE" ]; then
  6156.  #  # add layers list of pkgs to remove from final output
  6157.    cut -f2 -d'|' "$LAYER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6158.  #fi
  6159.  
  6160.  if [ -f $TMPDIR/installed_pkgs -a ! -z $TMPDIR/installed_pkgs ]; then
  6161.    sort -u $TMPDIR/installed_pkgs | grep -v ^$ > $TMPDIR/installed_pkgs__sorted
  6162.    mv $TMPDIR/installed_pkgs__sorted $TMPDIR/installed_pkgs
  6163.  fi
  6164. }
  6165.  
  6166. list_all_installed_pkgs(){        # list inc builtins if HIDE_BUILTINS=false
  6167.  # reset list of installed pkgs
  6168.  echo -n '' > $TMPDIR/installed_pkgs
  6169.  
  6170.  if [ "${HIDE_INSTALLED}" != true -o -z "${HIDE_INSTALLED}" ] && [ "$FORCE" != false ]; then
  6171.  #  # add user installed pkgs to list of pkgs to remove from final output
  6172.    cut -f2 -d'|' "$USER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6173.  fi
  6174.  
  6175.  if [ "${HIDE_BUILTINS}" != true -o -z "${HIDE_INSTALLED}" ]; then
  6176.  #  # add builtins to list of pkgs to remove from final output
  6177.    cut -f2 -d'|' "$WOOF_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6178.  fi
  6179.  
  6180.  if [ -f "$DEVX_INST_PKGS_FILE"  ]; then
  6181.  #  # add devx pkgs to list of pkgs to remove from final output
  6182.    cut -f2 -d'|' "$DEVX_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6183.  fi
  6184.  
  6185.  if [ -f "$LAYER_INST_PKGS_FILE" ]; then
  6186.  #  # add layers list of pkgs to remove from final output
  6187.    cut -f2 -d'|' "$LAYER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6188.  fi
  6189.  
  6190.  if [ -f $TMPDIR/installed_pkgs -a ! -z $TMPDIR/installed_pkgs ]; then
  6191.    sort -u $TMPDIR/installed_pkgs | grep -v ^$ > $TMPDIR/installed_pkgs__sorted
  6192.    mv $TMPDIR/installed_pkgs__sorted $TMPDIR/installed_pkgs
  6193.  fi
  6194.  ln -s $TMPDIR/installed_pkgs $TMPDIR/installed_pkgs_finished
  6195. }
  6196.  
  6197.  
  6198. has_deps(){                       # return true if $1 has deps, else false
  6199.  [ "$1" = '' -o "$1" = "-" -o ! "$1" ] && echo false
  6200.  [ "`get_deps_entry $1`" != '' ] && echo true || echo false
  6201. }
  6202.  
  6203.  
  6204. list_deps(){                      # list all deps of PKG ($1), space separated on one line FUNCLIST
  6205.  list_deps_count=$(( list_deps_count + 1 ))
  6206.  [ "$1" = '' -o "$1" = "-" ] && print_usage list-deps && exit 1
  6207.  
  6208.  echo true > /tmp/pkg/list_deps_busy
  6209.  
  6210.  # create list of installed pkgs ($TMPDIR/installed_pkgs) for later
  6211.  [ ! -f $TMPDIR/installed_pkgs ] && list_all_installed_pkgs
  6212.  
  6213.  # get current $REPOFILE, $DEPSEARCH
  6214.  #. ${PKGRC}
  6215.  
  6216.  local PKGNAME=''
  6217.  local PKGNAME_ONLY=''
  6218.  local pkg_ext=''
  6219.  local repo_files=''
  6220.  local deps_list=''
  6221.  local deps=''
  6222.  local repo_of_pkg=''
  6223.  local repo_file_of_pkg=''
  6224.  dep_id=$((dep_id +1))
  6225.  local ldepID=dep_id
  6226.  # get pkg extension
  6227.  pkg_ext=`get_pkg_ext "$1"`
  6228.  
  6229.  #pkg name only ,no path, no extension
  6230.  PKGNAME="$(LANG=C basename "$1" .$pkg_ext)"
  6231.  PKGNAME=`get_pkg_name "$PKGNAME"`
  6232.  PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  6233.  
  6234.  blacklisted_pkgs_list="$(echo $PKG_NAME_IGNORE | sed -e 's/ /|/g')"
  6235.  
  6236.  # get the deps of the pkg, note, in the repo deps are NOT listed by proper pkg names, .. they are +dbus,+glib,+SDL
  6237.  
  6238.  # search for deps entry in repo file.. look for |pkgname.ext|
  6239.  deps_list="`LANG=C get_deps_entry "$PKGNAME"`"
  6240.  
  6241.  # if no deps, exit with error
  6242.  [ "$deps_list" = "" ] && rm /tmp/pkg/list_deps_busy 2>/dev/null && return 1
  6243.  
  6244.  # remove the '+' from the start of each dep
  6245.  deps="${deps_list/+/}" # remove first + at start of line
  6246.  deps="${deps//,+/ }"   # remove others .. DEPS will now be just 'dep1 dep2 dep3'
  6247.  deps="${deps//  / }"   # remove double spaces
  6248.  
  6249.  if [ "$deps" != '' -a "$deps" != ' ' ]; then
  6250.  
  6251.    # put all deps of pkg in a tmp file
  6252.    echo "$deps" | tr ' ' '\n' | tr ',' '\n' | sort -u > $TMPDIR/all_deps_${ldepID}_0
  6253.    #Wait for installed_packages list to be created in list_all_installed_pkgs.
  6254.    while [ ! -f "${TMPDIR}/installed_pkgs_finished" ];do #TODO: s243a: consider adding readlink here
  6255.      echo -n '.'
  6256.      sleep 0.1
  6257.    done
  6258.    # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6259.    comm -23 ${TMPDIR}/all_deps_${ldepID}_0 ${TMPDIR}/installed_pkgs | sort -u | grep -v ^$ > ${TMPDIR}/all_deps_${ldepID}_1
  6260.  
  6261.    # remove all blacklisted packages from the list
  6262.    grep -vE "'$blacklisted_pkgs_list'" ${TMPDIR}/all_deps_${ldepID}_1 2>/dev/null | sort -u > ${TMPDIR}/all_deps_${ldepID}_1_without_blacklisted_packages
  6263.    mv ${TMPDIR}/all_deps_${ldepID}_1_without_blacklisted_packages ${TMPDIR}/all_deps_${ldepID}_1
  6264.  
  6265.    rm -f ${TMPDIR}/DEP_DONE 2>/dev/null
  6266.  
  6267.    if [ -f $TMPDIR/all_deps_${ldepID}_1 -a ! -z $TMPDIR/all_deps_${ldepID}_1 ]; then
  6268.      # recursive search deps of deps
  6269.      for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  6270.      do
  6271.        deps_list_file="${TMPDIR}/all_deps_${ldepID}_${i}"
  6272.  
  6273.  
  6274.        if [ -f $deps_list_file ]; then
  6275.  
  6276.          # remove all blacklisted packages from the list
  6277.          grep -vE "'$blacklisted_pkgs_list'" "$deps_list_file" > ${TMPDIR}/deps_list_file_without_blacklisted_pkgs
  6278.          mv ${TMPDIR}/deps_list_file_without_blacklisted_pkgs  $deps_list_file
  6279.  
  6280.          # remove done packages from the list
  6281.          if [ -f ${TMPDIR}/DEP_DONE ]; then
  6282.            deps_done_list="$(cat ${TMPDIR}/DEP_DONE | tr '\n' '|' | grep -v ^$)"
  6283.            grep -vE "'$deps_done_list'" $deps_list_file > ${TMPDIR}/deps_list_file_without_completed_pkgs
  6284.            mv ${TMPDIR}/deps_list_file_without_completed_pkgs $deps_list_file
  6285.          fi
  6286.  
  6287.          next_deps_list_file="${TMPDIR}/all_deps_${ldepID}_$(($i + 1))"
  6288.  
  6289.          # for each dep in $deps, get their deps too
  6290.          for subdep in `sort -u $deps_list_file | grep -v ^$`
  6291.          do
  6292.            [ "$subdep" = '' -o "$subdep" = ' ' ] && continue
  6293.  
  6294.            local subdeps_entry=''
  6295.            local subdeps=''
  6296.            local subdeps_list=''
  6297.            local is_builtin
  6298.            local is_in_devx
  6299.  
  6300.            local already_done=`grep -m1 "^${subdep}\$" ${TMPDIR}/DEP_DONE 2>/dev/null`
  6301.            [ "$already_done" != '' ] && continue
  6302.  
  6303.            if [ "$HIDE_BUILTINS" = true ] || [ -z "$HIDE_BUILTINS" ]; then
  6304.              is_builtin=`is_builtin_pkg "$subdep"`
  6305.              [ "$is_builtin" = true ] && continue
  6306.              is_in_devx=`is_devx_pkg "$subdep"`
  6307.              [ "$is_in_devx" = true ] && continue
  6308.            fi
  6309.  
  6310.            subdeps_entry="`get_deps_entry "$subdep"`"
  6311.            subdeps="${subdeps_entry/+/}" # remove first + at start of line
  6312.            subdeps="${subdeps//,+/ }"    # remove others .. DEPS will now be just 'dep1 dep2 dep3'
  6313.            subdeps="${subdeps//  / }"    # remove double spaces
  6314.  
  6315.            if [ "$subdeps" != '' ] && [ "$subdeps" != ' ' ]; then
  6316.              # remove everything after the + (if the + is followed by alphanumeric chars), then add to tmp files
  6317.              echo "$subdep" >> ${TMPDIR}/DEP_DONE
  6318.  
  6319.              # create the next deps list file to parse, containing the deps of this $subdep
  6320.              subdeps_list="`echo "${subdeps}" | tr ' ' '\n' | grep -v ^$ | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g' | sort -u`"
  6321.              echo "$subdeps_list" >> $next_deps_list_file
  6322.            fi
  6323.          done
  6324.        fi
  6325.      done
  6326.  
  6327.      # add all deps together, sorted, duplicated removed
  6328.      sort -u ${TMPDIR}/all_deps_${ldepID}_* | grep -v ^$ > ${TMPDIR}/all_deps_${ldepID}_sorted
  6329.      mv ${TMPDIR}/all_deps_${ldepID}_sorted ${TMPDIR}/all_deps_${ldepID}
  6330.  
  6331.    fi
  6332.  
  6333.  fi
  6334.  
  6335.  # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6336.  if [ -f ${TMPDIR}/installed_pkgs -a ! -z  ${TMPDIR}/installed_pkgs ]; then
  6337.    comm -23 ${TMPDIR}/all_deps_${ldepID} ${TMPDIR}/installed_pkgs | sort -u | grep -v ^$ > ${TMPDIR}/missing_deps
  6338.  fi
  6339.  
  6340.  # remove all blacklisted packages from the list
  6341.  grep -vE "'$blacklisted_pkgs_list'" ${TMPDIR}/missing_deps 2>/dev/null | sort -u > ${TMPDIR}/missing_deps_without_blacklisted_pkgs
  6342.  mv ${TMPDIR}/missing_deps_without_blacklisted_pkgs ${TMPDIR}/missing_deps
  6343.  
  6344.  [ ! -f ${TMPDIR}/missing_deps -o -z ${TMPDIR}/missing_deps ] && rm /tmp/pkg/list_deps_busy 2>/dev/null && return 1
  6345.  [ ! -f ${TMPDIR}/missing_deps ] && return 1
  6346.  
  6347.  # get fixed deps list
  6348.  deps="`LANG=C sort -u ${TMPDIR}/missing_deps 2>/dev/null | tr ' ' '\n' | while read dep
  6349.  do
  6350.    echo $(get_pkg_name_only "$dep")
  6351.  done`"
  6352.  
  6353.  [ "$deps" != "" ] && echo "$deps" | sed -e 's/^ //g' | tr ' ' '\n' | sort -u | tr '\n' ' '
  6354.  
  6355.  # clean up
  6356.  if [ $list_deps_count -eq 1 ]; then
  6357.  rm "${TMPDIR}/installed_pkg"* 2>/dev/null
  6358.  fi
  6359.  rm "${TMPDIR}/missing_dep"*  "${TMPDIR}/all_dep"* "${TMPDIR}/DEP_DONE" "/tmp/pkg/list_deps_busy" 2>/dev/null
  6360.  
  6361. }
  6362.  
  6363.  
  6364. find_deps(){                      # given a package name ($1), makes 2 lists: DEPS_INSTALLED and DEPS_MISSING FUNCLIST
  6365.  
  6366.  # This function takes 1 argument: PKGNAME
  6367.  #
  6368.  # PKGNAME should be the name of a package in one of your repos,
  6369.  # such as 'vlc' or 'hardinfo'.
  6370.  #
  6371.  # This function creates 2 files: $TMPDIR/deps_missing and $TMPDIR/deps_installed.
  6372.  # Each file is list the dependencies for PKGNAME, each dependency on a new line.
  6373.  # get_deps() can then go through those files and download/install the missing deps.
  6374.  #
  6375.  # If --force was given, all deps will be treated as missing.
  6376.  
  6377.  # get current repo ($REPOFILE)
  6378.  . ${PKGRC}
  6379.  
  6380.  local PKGNAME=''            # the pkg given ($1), may be full name, or generic name (no version), etc
  6381.  local PKGNAME_ONLY=''       # the pkg given ($1), without version (vlc,htop,etc)
  6382.  local pkg_ext=''            # the pkg extension, blank if not a valid extension or none given
  6383.  local repo_files=''         # the list of repo files to check, may be current only or all
  6384.  local deps_list=''          # deps of PKGNAME in comma-delimited format: dep1,dep2,dep3
  6385.  local deps_on_new_lines=''  # as above, but each dep on a new line
  6386.  local deps_missing=''       # comma separated list of missing deps
  6387.  local deps_installed=''     # comma separated list of deps already installed
  6388.  local dep=''                # dep name scraped from deps_list, usually the same as dep_name_only
  6389.  local dep_match=''          # used to find matches in the repo for $dep
  6390.  local dep_name_only=''      # short (generic) pkg name, no version (vlc,htop,etc)
  6391.  local dep_full_name=''      # pkg name with version (vlc-2.3.3-i686_s700, etc)
  6392.  local loading_indicator     # blank if only a few deps to parse, or .
  6393.  dep_id=$((dep_id +1))
  6394.  local ldepID=dep_id
  6395.  
  6396.  # get pkg extension
  6397.  pkg_ext=`get_pkg_ext "$1"`
  6398.  
  6399.  # pkg name with version, but no path, no extension
  6400.  PKGNAME="$(basename "$1" .$pkg_ext)"
  6401.  
  6402.  # we can't rely on the user input, try to get the right pkg names
  6403.  PKGNAME=`get_pkg_name "$PKGNAME"`       # vlc -> 'vlc-2.3-blah_etc
  6404.  PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`   # vlc-2.3-blah_etc -> vlc
  6405.  
  6406.  # if PKGNAME still empty, we cant find its deps, move on
  6407.  [ -z "$PKGNAME" ] && return 1
  6408.  
  6409.  # didn't exit yet, so remove the old tmp dirs
  6410.  rm $TMPDIR/deps_installed &>/dev/null
  6411.  rm $TMPDIR/deps_missing   &>/dev/null
  6412.  rm $TMPDIR/deps_missing1  &>/dev/null
  6413.  
  6414.  # loop through all repo files, or current repo only, depending on PKGSEARCH in RC file
  6415.  # add the full path to the file(s) while we are getting the list of repo files
  6416.  [ "$DEPSEARCH" = "list_all_pkg_names" ] && repo_files="`repo_file_list | sed -e "s|^|$PKGS_DIR/|g" | tr '\n' ' '`" || repo_files="$REPO_DB_FILE_DIR/$REPOFILE"
  6417.  
  6418.  # get the list of deps from the repo entry of this pkg
  6419.  deps_list="`LANG=C list_deps "$PKGNAME"`"
  6420.  
  6421.  # remove builtins from list unless HIDE_BUILTINS=false
  6422.  if [ "${HIDE_BUILTINS}" = true ]; then
  6423.    echo "$deps_list" | tr ' ' '\n'  | grep -v ^$ > ${TMPDIR}/all_deps_${ldepID}
  6424.    # add woof pkgs to list of pkgs to remove from final output
  6425.    cut -f2 -d'|' "$WOOF_INST_PKGS_FILE" | grep -v ^$ | sort | uniq >> $TMPDIR/installed_pkgs
  6426.    # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6427.  
  6428.    sort -u ${TMPDIR}/all_deps_${ldepID} > ${TMPDIR}/all_deps_${ldepID}_sorted
  6429.    mv ${TMPDIR}/all_deps_${ldepID}_sorted ${TMPDIR}/all_deps_${ldepID}
  6430.  
  6431.    sort -u ${TMPDIR}/installed_pkgs > ${TMPDIR}/installed_pkgs_sorted
  6432.    mv ${TMPDIR}/installed_pkgs_sorted ${TMPDIR}/installed_pkgs
  6433.  
  6434.    comm -23 ${TMPDIR}/all_deps_${ldepID} ${TMPDIR}/installed_pkgs | grep -v ^$ > ${TMPDIR}/missing_deps
  6435.    deps_list="`cat "${TMPDIR}/missing_deps" 2>/dev/null | grep -v ^$ | sort | tr '\n' ' ' `"
  6436.  fi
  6437.  
  6438.  # so now, $deps_list='dep1 dep2 dep3'
  6439.  
  6440.  # now get the deps list with each dep on its own line
  6441.  deps_on_new_lines="`echo "$deps_list" | tr ' ' '\n'`"
  6442.  
  6443.  # exit if no deps to parse
  6444.  [ "$deps_on_new_lines" = '' ] && return 1
  6445.  
  6446.  # set a loading bar (appending dots....) if we have numerous deps to search
  6447.  [ `echo "$deps_on_new_lines" | wc -l` -gt 4 ] && loading_indicator='.' || loading_indicator=''
  6448.  
  6449.  # now.. we go through ALL deps listed, and create a list for installed or not .. $dep will be 'gtkdialog3', for example
  6450.  echo "$deps_on_new_lines" | grep -v ^$ | while read dep
  6451.  do
  6452.    # append dots as we go, like a loading spinner
  6453.    [ "$loading_indicator" = '.' ] && echo -n "$loading_indicator"
  6454.  
  6455.    # $dep is currently
  6456.    dep_full_name=`get_pkg_name "$dep"`     #vlc-2.3.3-i586_s700
  6457.    dep_name_only=`get_pkg_name_only "$dep"`  #vlc
  6458.  
  6459.    # skip these non pkgs
  6460.    [ "`is_repo_pkg "$dep_name_only"`" = false ] && continue
  6461.  
  6462.    # if we added this dep to the list of PKGs already done, skip it
  6463.    [ "`grep -m1 "^$dep_name_only\$" $TMPDIR/PKGSDONE 2>/dev/null`" != '' ] && continue
  6464.  
  6465.    # lets check if the $dep is installed or not
  6466.  
  6467.    # if dep was found in a repo and not installed, add to missing deps list
  6468.    if [ "$FORCE"  = true -o "`is_installed_pkg "$dep_full_name"`" = false ]; then
  6469.      grep -m1 "^$dep_name_only\$" $TMPDIR/deps_missing 2>/dev/null || echo "$dep_name_only" | grep -v "^$PKGNAME" >> $TMPDIR/deps_missing
  6470.  
  6471.    else
  6472.      # else if the dep is already installed, add to installed deps list
  6473.      grep -m1 "^$dep_name_only\$" $TMPDIR/deps_installed 2>/dev/null || echo "$dep_name_only" | grep -v "^$PKGNAME" >> $TMPDIR/deps_installed
  6474.    fi
  6475.  
  6476.    # clean up deps_installed, remove duplicates, etc
  6477.    if [ -f $TMPDIR/deps_installed ]; then
  6478.      cat $TMPDIR/deps_installed 2>/dev/null| sort | uniq >> $TMPDIR/deps_installed1
  6479.      [ -f $TMPDIR/deps_installed1 ] && mv $TMPDIR/deps_installed1 $TMPDIR/deps_installed 2>/dev/null
  6480.    fi
  6481.  
  6482.  done # end of while $dep
  6483.  
  6484.  # make a comma separated list from newlines
  6485.  deps_installed="`cat $TMPDIR/deps_installed 2>/dev/null | sort | uniq | tr '\n' ',' | sed -e 's/,,/,/' -e 's/,$//' -e 's/^,//'`"
  6486.  deps_missing="`cat $TMPDIR/deps_missing 2>/dev/null | sort | uniq | tr '\n' ',' | sed -e 's/,,/,/' -e 's/,$//' -e 's/^,//'`"
  6487.  
  6488.  #120213, fixed, force all deps to be in the download list, if --force was given
  6489.  if [ "$FORCE" = true ]; then
  6490.    # dont skip installed deps (except builtins.. handled elsewhere)
  6491.    if [ "$deps_installed" != "" ]; then
  6492.      deps_missing="${deps_installed},${deps_missing}"
  6493.      deps_missing="`echo "${deps_missing//,,/}" | sed -e 's/,$//' -e 's/^,//'`"
  6494.    fi
  6495.  fi
  6496.  
  6497.  # later, get_deps() will use $DEPS_MISSING and $DEPS_INSTALLED
  6498.  DEPS_MISSING="$deps_missing"
  6499.  DEPS_INSTALLED="$deps_installed"
  6500.  
  6501.  # end appending dots... msg, by printing a new line
  6502.  [ "$loading_indicator" != '' ] && echo
  6503.  
  6504. }
  6505.  
  6506.  
  6507. get_deps(){                       # find, get and install the deps of pkgname ($1) FUNCLIST
  6508.  
  6509.  [ -z "$1" -o ! "$1" -o "$1" = "-" ] && print_usage deps && exit 1
  6510.  
  6511.  . ${PKGRC} #150813
  6512.  
  6513.  local EX
  6514.  local PKGNAME
  6515.  local DEPCONFIRM
  6516.  
  6517.  # get pkg extension
  6518.  local EX=`get_pkg_ext "$1"`
  6519.  
  6520.  # get pkg name with version, but no path, no extension
  6521.  local PKGNAME="$(LANG=C basename "$1" .$EX)"
  6522.  
  6523.  # don't rely on user input, get the name w version from repos
  6524.  local PKGNAME=`get_pkg_name "$PKGNAME" 2>/dev/null`
  6525.  local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME" 2>/dev/null`
  6526.  
  6527.  local pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY" 2>/dev/null`
  6528.  local pkg_already_done=`LANG=C grep -m1 "^$PKGNAME_ONLY\$" $TMPDIR/PKGSDONE 2>/dev/null`
  6529.  
  6530.  local pkg_is_blacklisted=`is_blacklisted_pkg "$PKG_NAME_ONLY" 2>/dev/null`
  6531.  
  6532.  # if pkg is builtin, skip it, we dont need to get its dependencies
  6533.  [ "$pkg_is_builtin" = true -a "$HIDE_BUILTINS" = true ] && continue
  6534.  
  6535.  # if pkg is blacklisted, also skip it
  6536.  [ "$pkg_is_blacklisted" = true ] && continue
  6537.  
  6538.  # skip if already processed, it should be listed in $TMPDIR/PKGSDONE
  6539.  [ "$pkg_already_done" != "" -a "$FORCE" = false ] && continue
  6540.  
  6541.  echo -n "Resolving dependencies.." # find deps will append ... as it goes
  6542.  
  6543.  # wait until list_deps() is finished (if it's running at all...)
  6544.  while [ -f /tmp/pkg/list_deps_busy ];do
  6545.    echo -n '.'
  6546.    sleep 0.75
  6547.  done
  6548.  
  6549.  echo
  6550.  
  6551.  # if list_deps() created a file listing the deps, get it from the file created, else, run list deps to be sure
  6552.  [ -f ${TMPDIR}/${pkg_name}_dep_list ] && DEPS_MISSING="`cat ${TMPDIR}/${pkg_name}_dep_list 2>/dev/null`" || DEPS_MISSING="`list_deps "$PKGNAME" 2>/dev/null`"
  6553.  
  6554.  # if we have missing deps, or are downloading them all regardless (INSTALLDEPS=false), or using --force
  6555.  if [ "$DEPS_MISSING" != "" -o "${NO_INSTALL}" = true -o "$FORCE" = true ]; then
  6556.  
  6557.    # ask to download (and maybe install) the deps
  6558.    DEPCONFIRM=y
  6559.    if [ "$ASK" = true ]; then
  6560.      echo "Missing deps: $DEPS_MISSING"
  6561.      echo -n "Download the missing dependencies$QTAG:  "
  6562.      read -n 1 DEPCONFIRM </dev/tty
  6563.      echo
  6564.      # skip if user chose --ask and didn't answer 'y'
  6565.      [ "$DEPCONFIRM" != "y" ] && return
  6566.    fi
  6567.  
  6568.    # if user answered yes, we will now download (and maybe install) the deps
  6569.    if [ "$DEPCONFIRM" = "y" -o "$FORCE" = true ]; then
  6570.  
  6571.      # only ask once
  6572.      ASK=false
  6573.  
  6574.      # make a list of the deps, each on a new line for each dep/newline
  6575.      WARNLIBS=''; SEP='';
  6576.  
  6577.      # if more than one missing dep, set separator to a comma
  6578.      [ ! -z "$DEPS_MISSING" -a "`echo "$DEPS_MISSING" | wc -l`" != "1" -a "`echo "$DEPS_MISSING" | wc -l`" != "0" ] && SEP=','
  6579.  
  6580.      # clean up our deps list, and make space separated only (no commas)
  6581.      DEPS_MISSING="`LANG=C echo "${DEPS_MISSING//,/ }" | grep -v '^,' | grep -v "^\$"`"
  6582.  
  6583.      # show deps info, if any available
  6584.      [ "${DEPS_MISSING}" != ""  ]   && echo "Dependencies to get: ${DEPS_MISSING//,/, }"
  6585.      [ "$FORCE" = false -a "${DEPS_INSTALLED}" != "" ] && echo "Dependencies installed: `LANG=C grep -v "^\$" $TMPDIR/deps_installed 2>/dev/null | head -1`"
  6586.  
  6587.      # for each missing dep  (or simply for each dep, if $FORCE is true)
  6588.      for DEP in $DEPS_MISSING
  6589.      do
  6590.  
  6591.        [ "$DEP" = "" -o "$DEP" = "${PKGNAME_ONLY}" -o "$DEP" = "${PKGNAME}" ] && continue #skip if the dep is the main package
  6592.  
  6593.        local DEPNAME=`get_pkg_name "$DEP" 2>/dev/null`
  6594.        local DEPNAME_ONLY=`get_pkg_name_only "$DEPNAME" 2>/dev/null`
  6595.        local DEPFILE=''
  6596.  
  6597.        # skip if already processed, it should be listed in $TMPDIR/PKGSDONE
  6598.        local dep_already_done=`LANG=C grep -m1 "^$DEPNAME_ONLY\$" $TMPDIR/PKGSDONE 2>/dev/null`
  6599.        [ "$dep_already_done" != "" -a "$FORCE" = false ] && continue
  6600.  
  6601.        local dep_is_blacklisted=`is_blacklisted_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6602.        local dep_is_builtin=`is_builtin_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6603.        local dep_is_usr_pkg=`is_usr_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6604.        local dep_is_in_devx=`is_devx_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6605.  
  6606.        # skip getting pkg if its blacklisted
  6607.        if [ "$dep_is_blacklisted" = true ]; then
  6608.          echo "Skipping $DEPNAME_ONLY (blacklisted).."
  6609.          continue
  6610.        fi
  6611.  
  6612.        # skip getting pkg if its a builtin, unless HIDE_BUILTINS=false
  6613.        if [ "$dep_is_builtin" = true -a "${HIDE_BUILTINS}" = true ]; then
  6614.          echo "Skipping $DEPNAME_ONLY (already built-in).."
  6615.          continue
  6616.        fi
  6617.  
  6618.        # skip getting pkg if its user installed and not using --force
  6619.        if [ "$dep_is_usr_pkg" = true -a "${FORCE}" != true ]; then
  6620.          echo "Skipping $DEPNAME_ONLY (already installed).."
  6621.          continue
  6622.        fi
  6623.  
  6624.        # skip getting pkg if its in the devx, unless HIDE_BUILTINS=false
  6625.        if [ "$dep_is_in_devx" = true -a "${HIDE_BUILTINS}" = true ]; then
  6626.          echo "Skipping $DEPNAME_ONLY (already built-in).."
  6627.          continue
  6628.        fi
  6629.  
  6630.        #DOWNLOAD THE PKG
  6631.        pkg_download "$DEPNAME" 2>/dev/null
  6632.  
  6633.        # skip install unless NO_INSTALL=true
  6634.        if [ "${NO_INSTALL}" = false ]; then
  6635.  
  6636.          # get the actual file we just downloaded to WORKDIR
  6637.          DEPFILE="`find "$WORKDIR" -maxdepth 1 -type f -name "$DEPNAME*" 2>/dev/null`"
  6638.  
  6639.          #INSTALL THE DEP, if it was downloaded
  6640.          [ "`is_local_pkg "$DEPFILE" 2>/dev/null`" = true ] && pkg_install "$DEPFILE" 2>/dev/null
  6641.  
  6642.          # mark the pkg as done!
  6643.          echo "$DEPNAME_ONLY" >> $TMPDIR/PKGSDONE
  6644.  
  6645.        else # if not installing,
  6646.          # skip dep checking of the deps that dont get installed
  6647.          continue
  6648.        fi
  6649.  
  6650.  
  6651.        # we finished with this dep, mark it done,
  6652.        # .. so we can skip it if it appears again (in a recursive dep check loop for example)
  6653.        echo "$DEPNAME_ONLY" >> $TMPDIR/PKGSDONE #260713
  6654.  
  6655.  
  6656.      done #done for DEP in DEPS_MISSING
  6657.  
  6658.    fi #endif DEPCONFIM=y
  6659.  
  6660.  else
  6661.    echo "No missing dependencies."
  6662.  fi # endif DEPS_MISSING != ''
  6663.  
  6664.  # if some deps were missing (listed but not found), print msg
  6665.  [ "$INSTALLDEPS" = true ] && actioned=installed || actioned=downloaded
  6666.  [ "$WARNLIBS" != "" ]     && echo -e "${yellow}Warning:${endcolour} Not $actioned from repo: $WARNLIBS"
  6667.  #exit 0 #110913
  6668. }
  6669.  
  6670.  
  6671. pkg_ldd_msg(){                    # check given package ($1) for missing deps FUNCLIST
  6672.  
  6673.  # exit if no valid usage
  6674.  [ ! "$1" -o "$1" = "-" ] && print_usage deps-check && exit 1
  6675.  
  6676.  . ${PKGRC}
  6677.  
  6678.  local PKGNAME
  6679.  local FNDFILES
  6680.  local LIST
  6681.  local RES
  6682.  local MISSING
  6683.  
  6684.  # get pkg name
  6685.  PKGNAME=`get_pkg_name "$1"`
  6686.  rm $TMPDIR/pkg-$PKGNAME-MISSING.txt &>/dev/null
  6687.  
  6688.  [ "`is_installed_pkg "$PKGNAME"`" = false ] && print_usage deps-check && exit 1
  6689.  
  6690.  echo "Searching for missing dependencies.. Please wait."
  6691.  
  6692.  local list="$PKGNAME `list_deps $PKGNAME`"
  6693.  
  6694.  for pkg_name in $list
  6695.  do
  6696.    local pkg_name_only=`get_pkg_name_only "$pkg_name"`
  6697.    # get the *.files for this pkg
  6698.    FNDFILES="$(find $PACKAGE_FILE_LIST_DIR/ -iname "${pkg_name}.files" 2>/dev/null)"
  6699.    [ ! -f "$FNDFILES" ] && FNDFILES="$(find "$PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}_*.files" 2>/dev/null)"
  6700.    [ ! -f "$FNDFILES" ] && FNDFILES="$(find "$PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}-*.files" 2>/dev/null)"
  6701.    [ ! -f "$FNDFILES" ] && FNDFILES="$(find "PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}*.files"  2>/dev/null)"
  6702.    [ ! -f "$FNDFILES" ] && continue
  6703.  
  6704.    # get list of ldd-able file
  6705.    cat "$FNDFILES" | grep -E '/lib/|/lib64/|/bin/|/games/|/sbin/' > ${TMPDIR}/ldd_file_list_${pkg_name}
  6706.    [ -z ${TMPDIR}/ldd_file_list_${pkg_name} ] && continue
  6707.  
  6708.    #loop through list
  6709.    for file in `cat ${TMPDIR}/ldd_file_list_${pkg_name}`
  6710.    do
  6711.      [ ! -x "$file" ] && continue
  6712.      RES="`ldd $file 2>/dev/null`"
  6713.      MISSING="`echo "$RES" | grep found`"
  6714.      [ "$MISSING" != "" -a "$MISSING" != " " ] && echo "  $file:
  6715.  $MISSING" >> $TMPDIR/${pkg_name}-MISSINGLIBS.txt
  6716.    done
  6717.  
  6718.    #print message
  6719.    if [ -f $TMPDIR/${pkg_name}-MISSINGLIBS.txt ]; then
  6720.      echo -e "${yellow}WARNING${endcolour}: ${magenta}${pkg_name_only}${endcolour} has missing dependencies: "
  6721.      echo -e "`cat $TMPDIR/${pkg_name}-MISSINGLIBS.txt`"
  6722.    else
  6723.      echo -e "${green}OK:${endcolour} ${pkg_name} has no missing dependencies."
  6724.    fi
  6725.    rm -f ${TMPDIR}/ldd_file_list* $TMPDIR/${pkg_name}-MISSINGLIBS.txt 2>/dev/null
  6726.  done
  6727. }
  6728.  
  6729.  
  6730. get_all_deps(){                   # try to install all missing deps FUNCLIST
  6731. echo "Checking $(list_installed_pkgs | wc -l) installed packages for missing dependencies. Please wait..."
  6732. rm $TMPDIR/pkg_get_all_deps 2>/dev/null
  6733.  
  6734. list_installed_pkgs | while read LINE; do
  6735.  DEPLIST="`LANG=C list_deps "$LINE"`"
  6736.  [ "$DEPLIST" != "" -a "$LINE" != "" ] && echo "$LINE|$DEPLIST" >> $TMPDIR/pkg_get_all_deps
  6737. done
  6738.  
  6739. [ ! -f $TMPDIR/pkg_get_all_deps ]   && echo "No missing dependencies." && exit 0
  6740. ASKOPT='';   [ "$ASK" = true ]   && ASKOPT='--ask ';
  6741. FORCEOPT=''; [ "$FORCE" = true ] && FORCEOPT='--force ';
  6742.  
  6743. cat $TMPDIR/pkg_get_all_deps 2>/dev/null | while read LINE
  6744. do
  6745.  [ "$LINE" = "" -o "`echo "$LINE" | grep -v '|'`" = "" ] && continue
  6746.  # get pkg gname from field 1
  6747.  PKGNAME="${LINE%%|*}"
  6748.  DEPS="${LINE##*|}"
  6749.  
  6750.  echo "Checking $PKGNAME..."
  6751.  
  6752.  for DEP in $DEPS;
  6753.  do
  6754.    # try to get the pkg name
  6755.    DEPPKG="`list_all_pkg_names $DEP- | head -1`" || \
  6756.    DEPPKG="`list_all_pkg_names $DEP_ | head -1`" || \
  6757.    DEPPKG="`list_all_pkg_names $DEP  | head -1`"
  6758.    # if dep not in any repos, skip it
  6759.    [ "$DEPPKG" = "" ] && continue
  6760.    # skip if the dep is already installed
  6761.    [ "`is_installed_pkg $DEPPKG`" = true ] && continue
  6762.    # ask to get dep
  6763.    echo -n "Get the missing package: ${DEPPKG}$QTAG:  "
  6764.    echo
  6765.    [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  6766.    [ "$ASK" = true ] && echo -ne "\b\b\n"
  6767.    # if user answered yes, we will now download the pkgs
  6768.    if [ "$CONFIRM" = "y" ]; then
  6769.      NO_INSTALL=false pkg_get "$DEPPKG" # get the missing dep (and its deps)
  6770.    fi
  6771.  done
  6772. done
  6773. rm -f $TMPDIR/pkg_get_all_deps 2>/dev/null
  6774. }
  6775.  
  6776.  
  6777. list_dependents(){                # list user installed pkgs that depend on $1 FUNCLIST
  6778.  
  6779.  local PKGNAME=''
  6780.  local PKGNAME_ONLY=''
  6781.  
  6782.  if [ "$1" = '' ]; then
  6783.    print_usage what-needs
  6784.    exit 1
  6785.  fi
  6786.  
  6787.  # try to get correct pkg names
  6788.  PKGNAME=`get_pkg_name "$1"`
  6789.  PKGNAME_ONLY=`get_pkg_name_only "$1"`
  6790.  
  6791.  # if pkg is not installed, then nothing depends on it
  6792.  if [ "`is_installed_pkg "$PKGNAME"`" = false ]; then
  6793.    echo "Package $1 not installed, nothing depends on it."
  6794.    exit 1
  6795.  fi
  6796.  
  6797.  # list all pkgs (from all repos) with $PKGNAME_ONLY as a dep
  6798.  cut -f1,2,9 -d'|' "$REPO_DB_FILE_DIR"/Packages-* \
  6799.    | sed -e "s/:any//g" -e "s/&[geql][eqt][0-9a-z._-]*//g" 2>/dev/null \
  6800.    | grep -E "+${PKGNAME_ONLY},|+${PKGNAME_ONLY}\|" 2>/dev/null \
  6801.    | cut -f2 -d'|' 2>/dev/null \
  6802.    | grep -v "^\$" \
  6803.    | grep -v "^#" \
  6804.    | grep -v "^$PKGNAME_ONLY\$" \
  6805.    | sort -u \
  6806.    >> ${TMPDIR}/dependents_list
  6807.  
  6808.  if [ "$HIDE_BUILTINS" = false ]; then
  6809.    # list all builtin and devx packages with $PKGNAME_ONLY as a dependency..
  6810.    cut -f1,2,9 -d'|' "$WOOF_INST_PKGS_FILE"  "$DEVX_INST_PKGS_FILE" \
  6811.      "$DEVX_INST_PKGS_FILE" \
  6812.      | grep -E "+${PKGNAME_ONLY},|+${PKGNAME_ONLY}\|" \
  6813.      | cut -f2 -d'|' \
  6814.      | grep -v "^\$" \
  6815.      | grep -v "^#" \
  6816.      | grep -v "^$PKGNAME_ONLY\$" \
  6817.      | sort -u \
  6818.      >> ${TMPDIR}/dependents_list
  6819.  fi
  6820.  
  6821.  # remove duplicates
  6822.  sort -u ${TMPDIR}/dependents_list > ${TMPDIR}/dependents_list__sorted
  6823.  mv ${TMPDIR}/dependents_list__sorted ${TMPDIR}/dependents_list_tmp
  6824.  rm ${TMPDIR}/dependents_list
  6825.  
  6826.  # only keep the user installed pkgs in the list
  6827.  for pkg in `list_installed_pkgs | grep -v ^$PKGNAME`
  6828.  do
  6829.    [ "`grep -m1 "^$(get_pkg_name_only $pkg)\$" ${TMPDIR}/dependents_list_tmp`" != '' ] && echo "$pkg" >> ${TMPDIR}/dependents_list
  6830.  done
  6831.  
  6832.  # print the list if we have one
  6833.  [ -f ${TMPDIR}/dependents_list -a ! -z ${TMPDIR}/dependents_list ] && cat ${TMPDIR}/dependents_list
  6834.  rm ${TMPDIR}/dependents_lis* 2>/dev/null
  6835. }
  6836.  
  6837.  
  6838. # file conversion
  6839.  
  6840. deb2pet(){                        # $1 must be valid deb file or repo pkg FUNCLIST
  6841.  [ ! -f "$1" ] && print_usage deb2pet && exit 1
  6842.  
  6843.  local DEB="${CURDIR}/$(basename "${1}")"
  6844.  local DIRNAME="${CURDIR}"
  6845.  #create file name we work with
  6846.  [ -f "$1" ] && DEB="$1" && DIRNAME="`dirname "$1"`"
  6847.  
  6848.  #keep old file, download it if needed
  6849.  #[ -f "$(basename "$1" .deb)" ] || ASK=$ASK FORCE=$FORCE pkg_download "$(basename "$1" .deb)"
  6850.  
  6851.  # if the deb exists
  6852.  if [ -e "$DEB" ]; then
  6853.    for i in "$DEB" # for each deb given
  6854.    do
  6855.      #remove the extensions
  6856.      #example, will be something like FOLDR=$HOME/Desktop/atari800_3.1.0-2+b2_i386
  6857.      FOLDR="$(echo "$i"|sed 's/\.deb$//')"
  6858.    done
  6859.  
  6860.    #make the new dir, copy the deb file into it, and ci into it
  6861.    mkdir -p "$FOLDR"; cp "$DEB" "$FOLDR"; cd "$FOLDR";
  6862.  
  6863.    #get the new full path and filename
  6864.    DEB="`ls | grep ".deb"`"
  6865.  
  6866.    # extract into current dir and remov ethe copied deb file
  6867.    pkg_unpack "$DEB" 1>/dev/null
  6868.  
  6869.    #this will be something like  PKGNAME=atari800_3.1.0-2+b2_i386
  6870.    PKGNAME="`basename "$DEB" .deb`"
  6871.  
  6872.    #now we package up the stuff into a pet
  6873.    [ -d "${FOLDR}/$PKGNAME" ] && dir2pet "${FOLDR}/$PKGNAME" || dir2pet "$PKGNAME"
  6874.  
  6875.    [ ! -f "$FOLDR.pet" -a ! -f "${CURDIR}/${PKGNAME}.pet" ] && error "$FOLDR.deb NOT converted to PET package!"
  6876.  
  6877.    #clean up
  6878.    rm -rf "$FOLDR"
  6879.  
  6880.  else
  6881.    echo "Package '$(basename $DEB)' not found in '$CURDIR'."
  6882.    return 1
  6883.  fi
  6884. }
  6885.  
  6886.  
  6887. dir2pet(){                        # dir to PET, $1 must be valid dir FUNCLIST
  6888.  
  6889.  # exit if no options
  6890.  [ ! -d "$1" ] && print_usage dir2pet && exit 1
  6891.  
  6892.  DIR="$1"
  6893.  SUFFIX=''
  6894.  
  6895.  [ "$2" != "" ] && SUFFIX="$2"
  6896.  
  6897.  #[ -d "$DIR" ] && cd `dirname "$DIR"`
  6898.  
  6899.  # get pkg name only,
  6900.  DIR="$(basename "${DIR}")"
  6901.  [ "$SUFFIX" != "" ] && cp -R "$DIR" "${DIR}${SUFFIX}" && DIR="${DIR}${SUFFIX}"
  6902.  
  6903.  echo -e "Converting directory ${lightblue}$DIR${endcolour} to .pet package."
  6904.  
  6905.  # we must have a dir with same name as a valid pkg
  6906.  if [ -d "$DIR" ]; then
  6907.    # move it to the build dir, to work on
  6908.    mkdir -p "$CURDIR/build_pkg/"
  6909.    [ ! -e "$CURDIR/build_pkg/$DIR" ] && cp -R "$DIR" "$CURDIR/build_pkg/"
  6910.  
  6911.    ARCHINDEPENDENT='yes'
  6912.    for ONEEXEC in `find $CURDIR/build_pkg/${DIR}/ -maxdepth 6 -type f -perm -o+x`
  6913.    do
  6914.      [ -f $ONEEXEC ] && [ "`file $ONEEXEC | grep ' ELF '`" != "" ] && ARCHINDEPENDENT='no'
  6915.    done
  6916.  
  6917.    # if it's a _DEV pkg.. it can't be ARCHINDEPENDENT
  6918.    case "${BASEPKG}" in *"_DEV"*) ARCHINDEPENDENT='no' ;; esac
  6919.    [ "`find $CURDIR/build_pkg/${DIR}/ -maxdepth 6 -type f -name '*.a' -o -type f -name 'lib*.so*' -o -type f -name '*.la'`" != "" ] && ARCHINDEPENDENT='no'
  6920.    [ "$ARCHINDEPENDENT" = "no" ] && COMPAT=$DISTRO_BINARY_COMPAT V=$DISTRO_COMPAT_VERSION
  6921.  
  6922.        #...borrowed from dir2pet script
  6923.    #w482 directory may already have a pet.specs, reuse it...
  6924.    NAMEONLY=""
  6925.    PUPMENUDESCR=""
  6926.    PUPOFFICIALDEPS=""
  6927.    PUPCATEGORY=""
  6928.    PUPPATH="" #100201
  6929.    ARCHDEPENDENT="yes" #100201
  6930.    DEFREPO="" #100201
  6931.    if [ -f $CURDIR/build_pkg/${DIR}/pet.specs ]; then #160803
  6932.     #new: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|
  6933.     #optionally on the end: compileddistro|compiledrelease|repo| (fields 11,12,13)
  6934.     PETSPECS="`cat $CURDIR/build_pkg/${DIR}/pet.specs | head -n 1`" #160803
  6935.     while IFS="|" read -r F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 <&3
  6936.     do
  6937.       DB_pkgname="$F1"
  6938.       DB_nameonly="$F2"
  6939.       NAMEONLY="$DB_nameonly"
  6940.       DB_version="$F3"
  6941.       DB_pkgrelease="$F4"
  6942.       DB_category="$F5"
  6943.       PUPCATEGORY="$DB_category"
  6944.       DB_size="$F6"
  6945.       DB_path="$F7"
  6946.       PUPPATH="$DB_path" #100201
  6947.       DB_fullfilename="$F8"
  6948.       DB_dependencies="$F9"
  6949.       PUPOFFICIALDEPS="$DB_dependencies"
  6950.       DB_description="$F10"
  6951.       PUPMENUDESCR="$DB_description"
  6952.       DB_compileddistro="$F11"
  6953.       DB_compiledrelease="$F12"
  6954.       ARCHDEPENDENT="${DB_compileddistro}|${DB_compiledrelease}"
  6955.       DB_repo="$F13"
  6956.       DEFREPO="$DB_repo"
  6957.      done 3< $CURDIR/build_pkg/${DIR}/pet.specs
  6958.    else
  6959.      echo -e "\nCategories:
  6960.  BuildingBlock, Desktop, System, Setup, Utility,
  6961.  Filesystem, Graphic, Document, Business, Personal,
  6962.  Network, Internet, Multimedia, Fun\n"
  6963.      read -p 'Type one of the categories above, then hit ENTER: ' CAT_ENTRY </dev/tty;
  6964.  
  6965.      echo
  6966.      read -p "Add a short description, then hit ENTER: " DESC_ENTRY </dev/tty;
  6967.  
  6968.      echo -e "\nAdd dependencies in this format:  ${bold}+libglib,+ffmpeg${endcolour}\n"
  6969.      read -p 'Enter dependencies (if any), then hit ENTER: ' DEPS_ENTRY </dev/tty;
  6970.  
  6971.      echo "${DIR}|$(get_pkg_name_only "$DIR")|$(get_pkg_version "$DIR")||${CAT_ENTRY:-Utility}|$(du -h "$CURDIR/build_pkg/${DIR}/" | tail -1 | cut -f1)||${DIR}.pet|${DEPS_ENTRY}|${DESC_ENTRY:-No description}|$COMPAT|$V||" > $CURDIR/build_pkg/${DIR}/pet.specs
  6972.    fi
  6973.  
  6974.    # build .pet.specs
  6975.  
  6976.    BASEPKG="`basename $DIR`"
  6977.    DIRPKG="`dirname $DIR`"
  6978.    [ "$DIRPKG" = "/" ] && DIRPKG=""
  6979.  
  6980.    #difficult task, separate package name from version part...
  6981.    #not perfect, some start with non-numeric version info...
  6982.    [ "$NAMEONLY" = "" ] && NAMEONLY=`get_pkg_name_only "$BASEPKG"`
  6983.  
  6984.    # get pet details from the pre-existing pet.specs (if any): deps, category, descr, version, nameonly, arch, distro version
  6985.    PUPOFFICIALDEPS="$DB_dependencies"
  6986.  
  6987.    TOPCAT="$PUPCATEGORY"
  6988.    [ -z "$TOPCAT" ] && TOPCAT=BuildingBlock
  6989.  
  6990.    PUPMENUDESCR="$DB_description"
  6991.    [ -z "${PUPMENUDESCR}" ] && PUPMENUDESCR="No description provided"
  6992.  
  6993.    VERSION="`get_pkg_version "$BASEPKG"`"
  6994.  
  6995.    # build pet spec
  6996.    if [ ! -f $CURDIR/build_pkg/${DIR}/pet.specs ]; then
  6997.      echo "$BASEPKG|${NAMEONLY}|$VERSION|$DB_pkgrelease|$TOPCAT|$DB_size|$REPO_SUBDIR|${BASEPKG}.pet|$PUPOFFICIALDEPS|$PUPMENUDESCR|$COMPAT|$V||" > $CURDIR/build_pkg/${DIR}/pet.specs
  6998.    fi
  6999.  
  7000.    # delete the slackware package management files
  7001.    #if [ -d "$CURDIR/build_pkg/install" ]; then
  7002.    # rm -r "$CURDIR/build_pkg/install"; rmdir "$CURDIR/build_pkg/install";
  7003.    #fi
  7004.  
  7005.    # delete arch pkg stuff
  7006.    #rm -r "$CURDIR/build_pkg/.INSTALL" &>/dev/null
  7007.    #rm "$CURDIR/build_pkg/.PKGINFO" &>/dev/null
  7008.  
  7009.    # now tar up the folder, ready to make into tar.gz, then into .pet
  7010.    cd $CURDIR/build_pkg/
  7011.  
  7012.    # we need to choose xz or gzip pets
  7013.    arch=`uname -m`
  7014.    if [ "${arch:0:3}" = "arm" ]; then
  7015.      TAREXT="gz"
  7016.    else
  7017.      TAREXT="xz"
  7018.    fi
  7019.  
  7020.    # if in a pre-woof puppy then we dont use xz
  7021.    if [ ! -f "$WOOF_INST_PKGS_FILE" -o ! -f /etc/DISTRO_SPECS ]; then
  7022.      # pre woof format
  7023.      echo "PETMENUDESCR='${DIR}'" >  $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  7024.      echo "PETOFFICIALDEPS=''"    >> $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  7025.      echo "PETREGISTER='yes'"     >> $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  7026.      compression=xz
  7027.      TAREXT="xz"
  7028.    fi
  7029.    tar -c -f ${DIR}.tar ${DIR} 1>/dev/null
  7030.    sync
  7031.    [ "`which xz`" = "" ] && TAREXT=gz
  7032.    case "$TAREXT" in
  7033.      xz) xz -z -9 -e ${DIR}.tar; ;;
  7034.      gz) gzip --best ${DIR}.tar; ;;
  7035.    esac
  7036.  
  7037.    # now get info needed to make a pet file
  7038.    TARBALL="${DIR}.tar.$TAREXT"
  7039.    FULLSIZE="`stat --format=%s ${TARBALL}`"
  7040.    MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  7041.  
  7042.    # add the info to the file
  7043.    echo -n "$MD5SUM" >> $TARBALL
  7044.    sync
  7045.  
  7046.    # now rename it to .pet
  7047.    mv -f $TARBALL ${DIR}.pet
  7048.    sync
  7049.  
  7050.    # move the created pet out of build_pkg, into WORK_DIR
  7051.    mv ${DIR}.pet $CURDIR/${DIR}.pet
  7052.    cd $CURDIR
  7053.  
  7054.    # clean up
  7055.    rm -f -R $CURDIR/build_pkg/
  7056.    echo
  7057.    echo -e "Package ${magenta}${DIR}.pet${endcolour} created."
  7058.    echo "The md5sum is: `md5sum ${DIR}.pet | cut -f1 -d' '`."
  7059.  else
  7060.    echo "Directory '$DIR' not found."
  7061.    exit 1
  7062.  fi
  7063. }
  7064.  
  7065.  
  7066. dir2sfs(){                        # $1 must be dir of pkg contents FUNCLIST
  7067.  
  7068.  if [ ! -d "$1" ]; then
  7069.    print_usage dir2sfs
  7070.    exit 1
  7071.  fi
  7072.  
  7073.  # if found, we will append it to the SFS filename
  7074.  [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  7075.  
  7076.  # get sfs name only, no extension or path
  7077.  SFS_DIR="`basename "$1" .sfs`"
  7078.  
  7079.  # if a valid dir
  7080.  if [ -d "$SFS_DIR" ]; then
  7081.    rm "${SFS_DIR}/"*pet*specs 2>/dev/null #240613
  7082.    #start building the sfs file
  7083.    echo "Please wait... building SFS file.."
  7084.    local SFS_NAME="${SFS_DIR/$SFS_SUFFIX/}${SFS_SUFFIX}.sfs"
  7085.    LANG=C mksquashfs "$SFS_DIR" "$SFS_NAME" -noappend &>/dev/null && SUCCESS="y" || SUCCESS=""
  7086.    if [ -z "$SUCCESS" -a ! -f "${SFS_DIR}${SFS_SUFFIX}.sfs" ]; then
  7087.      echo "Failed to create $SFS_NAME."
  7088.      exit 1
  7089.    fi
  7090.    chmod 644 "$SFS_NAME" #shinobar
  7091.    sync
  7092.    #get size, and output msg
  7093.    s=`LANG=C du -m "$SFS_NAME" | sed "s/\s.*//"`
  7094.    MD5SUM=`md5sum "$SFS_NAME" | cut -f1 -d ' '`
  7095.    echo -e "Created ${magenta}$SFS_NAME${endcolour} ( $s MB )"
  7096.    echo -e "The md5 checksum: $MD5SUM"
  7097.  else
  7098.    echo "Cannot create SFS:  '${SFS_DIR}' is not a directory."
  7099.    exit 1
  7100.  fi
  7101.  
  7102.  # clean up
  7103.  #rm -rf "${SFS_DIR}" &>/dev/null
  7104.  #rm -f "${SFS}${SFS_SUFFIX}"*.sfs-md5.txt &>/dev/null
  7105.  rm -f "${SFS}${SFS_SUFFIX}" &>/dev/null
  7106. }
  7107.  
  7108.  
  7109. dir2tgz(){                        # requires $1 as valid dir FUNCLIST
  7110.  
  7111.  [ ! -d "$1" ] && print_usage dir2tgz && exit 1
  7112.  
  7113.  DIR="${1/.t*gz/}"
  7114.  
  7115.  # remove trailing slash
  7116.  DIRNAME="`echo -n $DIR | sed -e 's%/$%%'`"
  7117.  DIRNAME="`basename ${DIRNAME}`" # get name only, no path
  7118.  
  7119.  # make sure any pet specs are named correctly - this new tar file might later be converted to a .pet
  7120.  echo "`ls -1 ${DIRNAME} | grep 'pet.specs'`" | while read LINE
  7121.  do
  7122.    mv "${DIRNAME}/$LINE" "${DIRNAME}/pet.specs" 2>/dev/null;
  7123.  done
  7124.  
  7125.  # create the tar file
  7126.  ##echo "Adding directory to '${DIRNAME}.tar.gz'.."
  7127.  tar -c -f "${DIRNAME}.tar" "${DIRNAME}/"
  7128.  gzip "${DIRNAME}.tar"
  7129.  sync
  7130.  
  7131.  # print message
  7132.  if [ -f "${DIRNAME}.tar.gz" ]; then
  7133.    echo -e "Package ${magenta}${DIRNAME}.tar.gz${endcolour} created."
  7134.    echo "The md5sum is: `md5sum ${DIRNAME}.tar.gz | cut -f1 -d' '`."
  7135.  else
  7136.    echo "Package '${DIRNAME}.tar.gz' NOT created."
  7137.    return 1
  7138.  fi
  7139. }
  7140.  
  7141.  
  7142. pet2sfs(){                        # convert pet to sfs, $1 must be file or repo pkg FUNCLIST
  7143.  
  7144.  # require valid option or quit
  7145.  [ ! -f "$1" ] && print_usage pet2sfs && exit 1
  7146.  
  7147.  pkg_ext=`get_pkg_ext "$1"`
  7148.  
  7149.  [ "$pkg_ext" != pet ] && print_usage pet2sfs && exit 1
  7150.  
  7151.  #110213,0.9.1 we want the file in $WORKDIR
  7152.  #[ ! -f "${WORKDIR}/$(basename "$1" .pet).pet" ] && cp -f "${1/.pet/}.pet" "${WORKDIR}/$(basename "$1" .pet)" 2>/dev/null
  7153.  
  7154.  PKGNAME="$(basename "$1" .pet)" #get pkg name only, no extension or path
  7155.  PKGFILE="${CURDIR}/${PKGNAME}.pet" #the file to install
  7156.  
  7157.  # determine the compression, extend test to 'XZ'
  7158.  file -b "${PKGFILE}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  7159.  [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  7160.  
  7161.  pet2tgz "${PKGFILE}" 1>/dev/null
  7162.  
  7163.  # now extract the files into $CURDIR/$PKGNAME/
  7164.  tar $taropts "${PKGFILE//.pet/.tar.$TAREXT}" 2> $TMPDIR/$SELF-cp-errlog
  7165.  
  7166.  # if DISTRO_VERSION found, the sfs will prob have a suffix
  7167.  [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  7168.  
  7169.  # remove the old one, if needed
  7170.  rm "${PKGNAME}${SFS_SUFFIX}.sfs" 2>/dev/null
  7171.  
  7172.  # create the new one
  7173.  dir2sfs "${CURDIR}/${PKGNAME}" && rm -rf "${CURDIR}/${PKGNAME}"
  7174.  
  7175.  # remove the .tar.$TAREXT file
  7176.  rm -f "${PKGNAME}.tar.$TAREXT"
  7177.  
  7178.  # if pkg put the pet in $CURDIR (not user), remove it
  7179.  #[ -f "${PKGFILE}" -a "`dirname "$1"`" != "$CURDIR" ] && rm -f "${PKGFILE}" 2>/dev/null
  7180.  
  7181.  # print message
  7182.  if [ ! -f "${PKGNAME}.sfs" -a ! -f "${PKGNAME}${SFS_SUFFIX}.sfs" ]; then
  7183.    echo "Package '${PKGNAME}.pet' not converted."
  7184.    return 1
  7185.  fi
  7186. }
  7187.  
  7188.  
  7189. pet2tgz(){                        # convert to tar.gz, $1 must be valid file FUNCLIST
  7190.  
  7191.  # if $1 is not a valid pkg name or a file that exists then exit..
  7192.  [ ! -f "$1" ] && print_usage pet2tgz && exit 1
  7193.  
  7194.  pkg_ext=`get_pkg_ext "$1"`
  7195.  [ "$pkg_ext" != "pet" ] && print_usage pet2tgz && exit 1
  7196.  
  7197.  PKGNAME="$(basename "$1" .pet)" # get pkg name only, no extension or path
  7198.  PKGFILE="$1"          # build the pkg file path
  7199.  
  7200.  # backup the package, to restore it later
  7201.  cp -f "$PKGFILE" "$TMPDIR/`basename $PKGFILE`.backup" 1>/dev/null
  7202.  
  7203.  chmod +w "$PKGFILE" # make it writable.
  7204.  FOOTERSIZE="32"
  7205.  
  7206.  # determine the compression, extend test to 'XZ'
  7207.  finfo=`file -b "$PKGFILE"`
  7208.  case $finfo in
  7209.    gz*|GZ*) EXT=gz ;;
  7210.    xz*|XZ*) EXT=xz ;;
  7211.    *) error "Unsupported compression type, or corrupted package." && exit 1 ;;
  7212.  esac
  7213.  
  7214.  # get the md5
  7215.  MD5SUM="`tail -c $FOOTERSIZE \"$PKGFILE\"`"
  7216.  NEWNAME="`echo -n \"$PKGFILE\" | sed -e "s/\\.pet$/\\.tar\\.$EXT/g"`" #131122
  7217.  head -c -$FOOTERSIZE "$PKGFILE" > $NEWNAME
  7218.  NEWMD5SUM="`md5sum \"$NEWNAME\" | cut -f 1 -d ' '`"
  7219.  sync
  7220.  [ ! "$MD5SUM" = "$NEWMD5SUM" ] && exit 1
  7221.  
  7222.  # restore original pet pkg
  7223.  [ -f "$TMPDIR/`basename $PKGFILE`.backup" ] && mv -f "$TMPDIR/`basename $PKGFILE`.backup" "$PKGFILE"
  7224.  
  7225.  # print message
  7226.  if [ -f "$NEWNAME" ]; then
  7227.    echo -e "${green}Success${endcolour}: Package ${magenta}`basename ${NEWNAME}`${endcolour} created."
  7228.    echo "The md5sum is `md5sum "$NEWNAME" | cut -f1 -d' '`."
  7229.  else
  7230.    error "Package ${PKGNAME}.pet not converted!"
  7231.    return 1
  7232.  fi
  7233. }
  7234.  
  7235.  
  7236. pet2txz(){                        # calls pet2tgz FUNCLIST
  7237.  pet2tgz "$1"
  7238. }
  7239.  
  7240.  
  7241. sfs2pet(){                        # convert sfs to pet, requires $1 as a valid sfs FUNCLIST
  7242.  
  7243.  # exit if no valid options
  7244.  [ ! -f "$1" ] && print_usage sfs2pet && exit 1
  7245.  
  7246.  # exit if user did not give an SFS file, or didnt give a file at all
  7247.  [ "`file "$1" | grep  Squashfs`" = '' ] && print_usage sfs2pet && exit 1
  7248.  
  7249.  # we want the file in $CURDIR
  7250.  #[ ! -f "${WORKDIR}/$(basename "${1}")" ] && cp -f "$1" "${WORKDIR}/$(basename "${1}")" 2>/dev/null
  7251.  
  7252.  SFSNAME="$(basename "$1")"
  7253.  SFSDIR="$(dirname "$1")"
  7254.  SFSEXT="${SFSNAME##*.}"
  7255.  
  7256.  # if DISTRO_VERSION found, the sfs will prob have a suffix
  7257.  [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  7258.  
  7259.  # create the name without path or extension (may include a $SUFFIX)
  7260.  ROOTNAME=`basename "$SFSNAME" ".$SFSEXT"`
  7261.  
  7262.  # build the file name we will work on
  7263.  SFS="${SFSDIR}/${SFSNAME}"
  7264.  
  7265.  if [ -f "$SFS" -a "$SFS" != "" ]; then
  7266.  
  7267.    echo "Unsquashing $SFSNAME.. Please wait.."
  7268.  
  7269.    # remove any older dirs, and unsquash
  7270.    rm -rf "${CURDIR}/squashfs-root/"
  7271.    LANG=C unsquashfs "$SFS"  &>/dev/null
  7272.  
  7273.    # lets remove the SFS suffix, to get back the the 'valid' PET name
  7274.    ROOTNAME_NOSUFFIX=`echo "$ROOTNAME" | sed -e "s/$SFS_SUFFIX//"`
  7275.  
  7276.    # create the folder we will package up
  7277.    mv squashfs-root "${ROOTNAME_NOSUFFIX}/"
  7278.  
  7279.    dir2tgz "${ROOTNAME_NOSUFFIX}" 1>/dev/null
  7280.  
  7281.    tgz2pet "${ROOTNAME_NOSUFFIX}".tar.gz 1>/dev/null
  7282.  
  7283.    # remove the dir and the tgz we just created
  7284.    rm -rf "${ROOTNAME_NOSUFFIX}"
  7285.    rm -f "${ROOTNAME_NOSUFFIX}".tar.gz
  7286.  
  7287.    if [ -f "${ROOTNAME_NOSUFFIX}.pet" ]; then
  7288.      echo -e "${green}Success${endcolour}: Package '${magenta}${ROOTNAME_NOSUFFIX}.pet${endcolour}' created."
  7289.      echo "The md5sum is: `md5sum ${ROOTNAME_NOSUFFIX}.pet | cut -f1 -d' '`"
  7290.    else
  7291.      echo "Package '${ROOTNAME_NOSUFFIX}.pet' not converted."
  7292.      return 1
  7293.    fi
  7294.  fi
  7295. }
  7296.  
  7297.  
  7298. tgz2pet(){                        # convert $1 (a tar.gz or tgz) to .pet FUNCLIST
  7299.  
  7300.  [ ! -f "$1" ] && print_usage tgz2pet && exit 1
  7301.  sync
  7302.  TARBALL="$1"
  7303.  [ ! -f "$TARBALL" ] && echo "The archive '$TARBALL' could not be found." && exit 1
  7304.  
  7305.  cp -f $TARBALL "$TMPDIR/`basename $TARBALL`.backup" 1>/dev/null
  7306.  
  7307.  TARBALL="${CURDIR}/$(basename "${TARBALL}")"
  7308.  chmod 644 "$TARBALL" #make it writable.
  7309.  echo "Converting `basename ${TARBALL}`.."
  7310.  
  7311.  #only accept .tgz or .tar.gz .tar.xz files...
  7312.  EXT=''
  7313.  case ${TARBALL} in
  7314.    *.tar.gz) EXT='.tar.gz' ;;
  7315.    *.tgz)    EXT='.tgz' ;;
  7316.    *.tar.xz) EXT='.tar.xz' ;;
  7317.    *.txz)    EXT='.txz' ;;
  7318.    *) echo "${1##*/}: File extension not allowed" >&2 ; exit 1 ;;
  7319.  esac
  7320.  [ "$EXT" = "" ] && error "$TARBALL must be a .tgz, .tar.gz, .txz or .tar.xz file" && exit 1
  7321.  
  7322.  #split TARBALL path/filename into components...
  7323.  BASEPKG="`basename $TARBALL $EXT`"
  7324.  DIRPKG="$CURDIR"
  7325.  [ "$DIRPKG" = "/" ] && DIRPKG=""
  7326.  case $EXT in
  7327.  *gz)OPT=-z;;
  7328.  *xz)OPT=-J;;
  7329.  esac
  7330.  
  7331.  # move pkg, update extensions (tgz -> .tar.gz, txz -> .tar.xz)
  7332.  # make code later more readable
  7333.  case $EXT in
  7334.  *tgz)mv -f $TARBALL $DIRPKG/${BASEPKG}.tar.gz
  7335.   TARBALL="$DIRPKG/${BASEPKG}.tar.gz"
  7336.   EXT='.tar.gz';;
  7337.  *txz)mv -f $TARBALL $DIRPKG/${BASEPKG}.tar.xz
  7338.   TARBALL="$DIRPKG/${BASEPKG}.tar.xz"
  7339.   EXT='.tar.xz';;
  7340.  esac
  7341.  
  7342.  # if tarball expands direct to '/' want to wrap around it (slackware pkg)... 100628 add -z ...
  7343.  # man bad bug here... the thing isn't expanded! #131122
  7344.  if [ "`tar ${OPT} --list -f ${TARBALL} | head -n 1`" = "./" ]; then
  7345.    tar --one-top-level=${BASEPKG} -xf ${TARBALL}
  7346.    tar --remove-files -c -f ${DIRPKG}/${BASEPKG}.tar ${BASEPKG}/
  7347.    case $EXT in
  7348.    *gz) gzip --force --best ${DIRPKG}/${BASEPKG}.tar ;;
  7349.    *xz) xz --force -z -9 -e ${DIRPKG}/${BASEPKG}.tar ;;
  7350.    esac
  7351.  fi
  7352.  
  7353.  FULLSIZE="`stat --format=%s ${TARBALL}`"
  7354.  MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  7355.  echo -n "$MD5SUM" >> $TARBALL
  7356.  sync
  7357.  mv -f $TARBALL $DIRPKG/${BASEPKG}.pet
  7358.  sync
  7359.  
  7360.  # restore original tar file
  7361.  [ -f "$TMPDIR/`basename $TARBALL`.backup" ] && mv -f "$TMPDIR/`basename $TARBALL`.backup" "$TARBALL"
  7362.  
  7363.  # print msg
  7364.  if [ -f "${DIRPKG}/${BASEPKG}.pet" ]; then
  7365.    echo -e "${green}Success:${endcolour} Created ${magenta}${BASEPKG}.pet${endcolour}."
  7366.    echo "This is the md5sum: `md5sum ${DIRPKG}/${BASEPKG}.pet | cut -f1 -d' '`"
  7367.  else
  7368.    error "Could not convert ${DIRPKG}/${BASEPKG}.$EXT"
  7369.    return 1
  7370.  fi
  7371. }
  7372.  
  7373.  
  7374. txz2pet(){                        # convert txz to pet, requires $1 as valid file FUNCLIST
  7375.  [ ! -f "$1" ] && print_usage txz2pet && exit 1
  7376.  FILE="$1"   # full path, filename and extension
  7377.  #keep old file, download it if needed
  7378.  #[ -f "$(basename "$1" .txz)" ] || pkg_download "$(basename "$1" .txz)" #  200813 try to download it
  7379.  # we want $FILE in $CURDIR
  7380.  [ ! -f "${CURDIR}/$(basename "${FILE}")" ] && cp -f "$FILE" "${CURDIR}/$(basename "${FILE}")" 2>/dev/null
  7381.  FILE="${CURDIR}/$(basename "${FILE}")"
  7382.  #set vars
  7383.  FILENAME="`basename "$FILE"`" # filename and extension only
  7384.  BARENAME="${FILENAME/.t*xz/}" # filename, no extension..
  7385.  PETFILE="${CURDIR}/${BARENAME}.pet" # the full path and filename of the pet file
  7386.  PETNAME="`basename "$PETFILE"`" # the filename of the pet file
  7387.  # create the pet directory, if needed
  7388.  mkdir -p "${CURDIR}/${BARENAME}"
  7389.  [ ! -d "${CURDIR}/${BARENAME}" ] && { echo "PET directory not created or found."; exit 1; }
  7390.  # unpack the file
  7391.  [ -f "$FILENAME" ] && tar -Jxvf "$FILENAME" -C "${BARENAME}/" 1>/dev/null || echo "Cannot untar $FILENAME"
  7392.  # create the pet file
  7393.  dir2pet "$BARENAME" || echo "PET working directory not found"
  7394.  
  7395.  if [ -f "$PETFILE" ]; then # if pet file was created
  7396.    # remove the pet file working directory
  7397.    rm -R "${CURDIR}/${BARENAME}/" 2>/dev/null
  7398.    rmdir "${CURDIR}/${BARENAME}/" 2>/dev/null
  7399.    # report the file was created #nope, no need, dir2pet will do it
  7400.    #echo "Package '$PETNAME' created successfully."
  7401.  else
  7402.    echo "Package "$PETFILE" file not created"
  7403.    return 1
  7404.  fi
  7405.  # delete the original txz file
  7406.  rm -f "$FILE" &>/dev/null
  7407. }
  7408.  
  7409.  
  7410. # other
  7411.  
  7412. menu_entry_msg(){                 # show menu entry details of installed pkg FUNCLIST
  7413.  
  7414.  # exit if not valid usage
  7415.  [ ! "$1" -o "$1" = "-" ] && exit 1
  7416.  
  7417.  . ${PKGRC}
  7418.  
  7419.  local MENUFILE=''
  7420.  local pkg_file_list=''
  7421.  local no_display=''
  7422.  local terminal_only=''
  7423.  local pkg_command=''
  7424.  
  7425.  # get the menu file, if it exists
  7426.  pkg_file_list=$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${1}*.files")
  7427.  
  7428.  [ -f "$pkg_file_list" ] && MENUFILE="`LANG=C grep -m1 '/usr/share/applications/' "$pkg_file_list" | grep -i -m1 ".desktop\$"`" || return 1
  7429.  
  7430.  # if pkg has a .desktop file
  7431.   if [ -f "$MENUFILE" ]; then
  7432.  
  7433.    # exit if the menu item is set to NoDisplay
  7434.    no_display="`grep -m1 ^NoDisplay=true "$MENUFILE" 2>/dev/null`"
  7435.    terminal_only="`grep -m1 ^Terminal=true "$MENUFILE" 2>/dev/null`"
  7436.  
  7437.    # fix menu entries
  7438.    sed -i 's/ %u//g' "$MENUFILE"
  7439.    sed -i 's/ %U//g' "$MENUFILE"
  7440.    sed -i 's/ %f//g' "$MENUFILE"
  7441.    sed -i 's/ %F//g' "$MENUFILE"
  7442.    sed -i 's/ %d//g' "$MENUFILE"
  7443.    sed -i 's/ %D//g' "$MENUFILE"
  7444.  
  7445.    update_menus &
  7446.  
  7447.    # get the details for a final msg
  7448.    MENU_CAT="`LANG=C grep -m1 "^Categories=" $MENUFILE 2>/dev/null | cut -f2 -d'=' | sed -e 's/\(.*\);/\1/g' -e 's/.*;//g' | head -1`"
  7449.    APATTERN="[ ,]${MENU_CAT}" #MHHP
  7450.    TOPMENU="`LANG=C grep -m1 "${APATTERN}" /etc/xdg/menus/hierarchy | cut -f1 -d' ' | head -1`"
  7451.    if [ "$TOPMENU" = "" ]; then
  7452.      APATTERN="[ ,]${MENU_CAT};"
  7453.      TOPMENU="`LANG=C grep -m1 "${APATTERN}" /etc/xdg/menus/hierarchy | cut -f1 -d' ' | head -1`"
  7454.    fi
  7455.    MENU_NAME="`LANG=C grep -m1 "^Name=" $MENUFILE | cut -f2 -d'=' | head -1`"
  7456.  
  7457.    [ "$TOPMENU" = '' ] && TOPMENU="$MENU_CAT"
  7458.  
  7459.    # replace the Categories= line with one which has only the top, main category..
  7460.    # .. this should prevent duplicate menu entries
  7461.    #cat "$MENUFILE" | grep -v ^Categories > ${TMPDIR}/fixed.desktop
  7462.    #echo "Categories=${TOPMENU};" >> ${TMPDIR}/fixed.desktop
  7463.    #mv ${TMPDIR}/fixed.desktop $MENUFILE
  7464.  
  7465.    # print msg
  7466.    if [ "$no_display" != "" -o "$terminal_only" != '' ]; then
  7467.      pkg_command="`grep -m1 ^Exec= "$MENUFILE" | cut -f2 -d'='`"
  7468.      [ "$pkg_command" != '' ] && echo -e "To run, type:  ${bold}${pkg_command}${endcolour}"
  7469.    else
  7470.      echo -e "Menu entry:     ${lightblue}${TOPMENU:-[None]}${endcolour} -> ${lightblue}${MENU_NAME:-[None]}${endcolour}"
  7471.    fi
  7472.  
  7473.    return 0
  7474.  fi
  7475.  return 1
  7476. }
  7477.  
  7478.  
  7479. update_menus() {                  # update menus, calls fixmenus, refreshes WM
  7480.  echo started > /tmp/pkg/update_menus_busy
  7481.  fixmenus &>/dev/null
  7482.  # refresh JWM menus if using JWM window manager
  7483.  [ "`which jwm`" != "" -a "`ps -e | grep jwm`" != "" ] && jwm -reload &>/dev/null
  7484.  rm /tmp/pkg/update_menus_busy 2>/dev/null
  7485.  return 0
  7486. }
  7487.  
  7488.  
  7489. check_net(){                      # check net connection (before downloading) FUNCLIST
  7490.  [ -f $TMPDIR/internetsuccess ] && echo 0 && exit 0 #220613
  7491.  [ ! "$1" -o "$1" = "-" ] && URL="8.8.8.8" || URL="`echo  ${1} | awk -F/ '{print $3}'`"
  7492.  LANG=C ping -4 -c1 -q "$URL" &>/dev/null #220613
  7493.  REPLY=$?
  7494.  [ $REPLY -eq 0 ] && echo -n "ok" > $TMPDIR/internetsuccess #220613
  7495.  echo 0
  7496. }
  7497.  
  7498.  
  7499. get_stdin(){                      # read from stdin (when - is last option) FUNCLIST
  7500.  read -t 0.1 STDINVAR
  7501. }
  7502.  
  7503.  
  7504. not_found(){                      # list alternative packages when no match in repos FUNCLIST
  7505.  PKGNAME="${1/.pet/}"
  7506.  #echo "$APPTITLE"
  7507.  #echo "Package '${PKGNAME}' not found in current repo..  "
  7508.  if [ "$(ls "${WORKDIR}/"| grep "${PKGNAME}")" != "" ]; then
  7509.    [ "`list_downloaded_pkgs "${PKGNAME}"`" != "" ] && echo "These downloaded packages match your search:
  7510. `list_downloaded_pkgs "${PKGNAME}"`"
  7511.  fi
  7512.    [ "`$PKGSEARCH "${PKGNAME}"`" != "" ] && echo "These packages in the repos match your search:
  7513. `$PKGSEARCH "${PKGNAME}"`"
  7514.  return 1
  7515. }
  7516.  
  7517.  
  7518. first_run (){                     # welome message on first run
  7519.  
  7520.  # quit if not the first run
  7521.  [ ! -f ~/.pkg/firstrun ] && return 0
  7522.  # print msg
  7523.  echo '============================================================'
  7524.  echo -e "  ${bold}$APPNAME $APPVER${endcolour} - a command-line package manager"
  7525.  echo '============================================================'
  7526.  echo
  7527.  echo "  pkg repo-update      # update the contents of each installed repo"
  7528.  echo "  pkg repo-list        # list all available repos"
  7529.  echo "  pkg repo <name>      # change to the chosen repo"
  7530.  echo "  pkg show-config      # show current Pkg settings"
  7531.  echo "  pkg workdir <DIR>    # change where to keep downloaded packages"
  7532.  echo
  7533.  echo "  pkg search <term>    # search all fields in the current repo"
  7534.  echo "  pkg names <pkgname>  # search package names in the current repo"
  7535.  echo "  pkg status <pkgname> # print info about the given package"
  7536.  echo "  pkg add <pkgname>    # install & download packages and dependencies"
  7537.  echo
  7538.  echo " You can run the commands below to learn more about Pkg:"
  7539.  echo
  7540.  echo "  pkg help             # help info, all options and some tips"
  7541.  echo "  pkg help-all         # full help info, including advanced usage"
  7542.  echo "  pkg usage [cmd]      # show every command, or info on the given one"
  7543.  echo "  pkg examples         # show lots more example Pkg commands"
  7544.  echo
  7545.  echo " HINT: Use TAB to auto-complete package and repo names (and more).."
  7546.  echo
  7547.  echo '============================================================'
  7548.  
  7549.  # get the right list of repos
  7550.  update_sources &>/dev/null &
  7551.  
  7552.  # delete first run flag
  7553.  rm -f ~/.pkg/firstrun 2>/dev/null
  7554.  
  7555.  # delete other tmp stuff, make it like a first run
  7556.  rm $TMPDIR/func_list        &>/dev/null
  7557.  rm $TMPDIR/curr_repo_url    &>/dev/null
  7558.  rm $TMPDIR/internetsuccess  &>/dev/null
  7559.  rm $TMPDIR/pkg_aliases      &>/dev/null
  7560.  rm $TMPDIR/pkglist          &>/dev/null
  7561.  rm $TMPDIR/pkglist_*        &>/dev/null
  7562.  rm $TMPDIR/USRPKGLIST       &>/dev/null
  7563.  rm $TMPDIR/PKGSDONE         &>/dev/null
  7564.  rm $TMPDIR/deps_installed   &>/dev/null
  7565.  rm $TMPDIR/deps_missing     &>/dev/null
  7566.  rm $TMPDIR/$SELF-cp-errlog  &>/dev/null
  7567.  rm $TMPDIR/*-MISSING.txt    &>/dev/null
  7568.  
  7569.  exit 0
  7570. }
  7571.  
  7572.  
  7573. #====================  main functions  ======================#
  7574.  
  7575.  
  7576.  
  7577. #=====================  final checks  =======================#
  7578.  
  7579. # try to set a default repo if none was found
  7580. if [ ! -f "$REPO_DB_FILE_DIR/$REPOFILE" -o ! -f "$HOME/.pkg/sources" ]; then
  7581.  
  7582.  mkdir -p $HOME/.pkg 2>/dev/null
  7583.  mkdir -p $PKGS_DIR 2>/dev/null
  7584.  [ ! -f "$HOME/.pkg/sources" ] && touch $HOME/.pkg/sources
  7585.  # try to get repo file from /root if it exists
  7586.  if [ -f "$REPO_DB_FILE_DIR/Packages-puppy-noarch-official" ]; then
  7587.    # copy any available Puppy repo files in root to $PKGS_DIR
  7588.    mv "$REPO_DB_FILE_DIR"/Packages-puppy-* $REPO_DB_FILE_DIR/
  7589.  fi
  7590.  
  7591.  ## if repo file was NOT added to home dir, fata error, exit
  7592.  #if [ ! -f $PKGS_DIR/Packages-puppy-noarch-official ]; then
  7593.  #  error "Repo files not found. Check ${magenta}$PKGS_DIR${endcolour}"
  7594.  #  exit 1
  7595.  #fi
  7596.  
  7597.  # if we got here, the noarch repo file is in $PKGS_DIR, lets use it as the default/only repo
  7598.  echo -e "${yellow}Warning:${endcolour} No repo files found. Setting the default repo to 'noarch'."
  7599.  update_sources 1>/dev/null
  7600.  set_current_repo noarch 1>/dev/null
  7601.  # if repos added ok
  7602.  if [ $? -eq 0 ]; then
  7603.    echo -e "${green}Success:${endcolour} 'noarch' added."
  7604.    echo "Re-running: $SELF $@"
  7605.    echo
  7606.    $SELF $@
  7607.    exit 0
  7608.  fi
  7609.  
  7610. fi
  7611.  
  7612. # create the user-installed pkgs file if it doesnt exists
  7613. [ ! -f $PKGS_DIR/user-installed-packages ] && touch $PKGS_DIR/user-installed-packages
  7614.  
  7615. first_run
  7616.  
  7617.  
  7618. #=====================  final checks  =======================#
  7619.  
  7620.  
  7621.  
  7622. #====================  main interface  ======================#
  7623.  
  7624.  
  7625. while [ $# != 0 ]; do # get all options ($# means all options)
  7626.   I=1
  7627.   while [ ! -z $# -a $I -le `echo $# | wc -c` ]; do
  7628.  
  7629.    # accept from stdin, (using dash (-) as final option)
  7630.    for x in "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
  7631.    do
  7632.      case "$x" in
  7633.        -)
  7634.          while true; do
  7635.            read ALINE
  7636.            [ "$ALINE" ] || break
  7637.            [ "$(echo $ALINE| cut -b1)" = '#' ] && continue # skip comment
  7638.            [ "$ALINE" = ':' ] && continue  # skip colon
  7639.            if [ "$ALINE" = "- " -o "$ALINE" = " -" -o "$ALINE" != "-" ]; then
  7640.              OPTS="${@%-}" #get all opts, without last dash
  7641.              OPTS="${OPTS% }" #get all opts, strip last space
  7642.              $SELF $OPTS "$ALINE"
  7643.            fi
  7644.          done
  7645.          break
  7646.        ;;
  7647.        --ask|-a)         ASK=true ; QTAG="?  (y/N)";;
  7648.        --quiet|-q)       QUIET=true ;;
  7649.        --force|-f)       FORCE=true ;;
  7650.        --no-color)       green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7651.        --no-colour|-nc)  green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7652.        '--configure='*)  PKG_CONFIGURE="$(echo "$x" | sed -e 's/^--configure=//')" ;;
  7653.        '--cflags='*)     PKG_CFLAGS="$(echo "$x" | sed -e 's/^--cflags=//')"       ;;
  7654.      esac
  7655.    done
  7656.  
  7657.    # enable passing multiple pkgs separated by comma, space,
  7658.    # works with or without double quotes around pkgs
  7659.    opt="`shift; echo "$@"`"
  7660.    opt="${opt//,/ }"
  7661.    opt="${opt//|/ }"
  7662.    # only keep params up to the next option
  7663.    opt="${opt// -*/}"
  7664.  
  7665.    ## main options
  7666.    case $1 in
  7667.  
  7668.      -) # accept from stdin, pkg -i (defaults to pkg add $1 or pkg -u $1)
  7669.        if [ "$2" = "" ]; then
  7670.          while true; do
  7671.            read ALINE
  7672.            [ "$ALINE" -a "$ALINE" != '-' ] || break
  7673.            [ "$(echo $ALINE| cut -b1)" = '#' ] && continue # skip comment
  7674.            ALINE=`echo $ALINE` #strip spaces
  7675.            if [ "$ALINE" != "-" -a "`$PKGSEARCH "$ALINE"`" != "" ]; then
  7676.              [ "`is_installed_pkg $ALINE`" = false ] && pkg_get "$ALINE" || \
  7677.              pkg_uninstall "$ALINE"
  7678.            fi
  7679.          done
  7680.          shift
  7681.        fi
  7682.      ;;
  7683.  
  7684.      --ask|-a)         ASK=true ; QTAG="?  (y/N)";;
  7685.      --quiet|-q)       QUIET=true ;;
  7686.      --force|-f)       FORCE=true ;;
  7687.      --no-color)       green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7688.      --no-colour|-nc)  green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7689.      '--configure='*)  PKG_CONFIGURE="$(echo "$1" | sed -e 's/^--configure=//')" ;;
  7690.      '--cflags='*)     PKG_CFLAGS="$(echo "$1" | sed -e 's/^--cflags=//')"       ;;
  7691.  
  7692.      # package search
  7693.      --all-pkgs|--all)                 [ ! "$2" ] && cat "$REPO_DB_FILE_DIR/${REPOFILE}" || cat "$REPO_DB_FILE_DIR/${REPOFILE}" | grep "$2"; exit 0;;
  7694.      --search|-s|search|s)             [ ! "$2" ] && search_pkgs          || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_pkgs "$x";          done; ;;
  7695.      -ss)                              [ ! "$2" ] && search_fast          || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_fast "$x";          done; ;;
  7696.      --search-all|-sa|search-all|sa)   [ ! "$2" ] && search_all_pkgs      || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_all_pkgs "$x";      done; ;;
  7697.      -ssa|ssa)                         [ ! "$2" ] && search_all_fast      || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_all_fast "$x";      done; ;;
  7698.      --names|-n|names|n)               [ ! "$2" ] && list_pkg_names       || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_pkg_names "$x";         done; ;;
  7699.      --names-exact|-ne|names-exact|ne) [ ! "$2" ] && list_pkg_names       || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_pkg_names "$x\$";       done; ;;
  7700.      --names-all|-na|names-all|na)     [ ! "$2" ] && list_all_pkg_names   || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_all_pkg_names "$x";     done; ;;
  7701. --list-installed|list-installed|-li|li) [ ! "$2" ] && list_installed_pkgs  || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_installed_pkgs "$x";    done; exit 0 ;;
  7702. --list-downloaded|list-downloaded|-ld|ld) [ ! "$2" ] && list_downloaded_pkgs || list_downloaded_pkgs "$2"; exit 0 ;;
  7703.      -LI|LI)                           [ ! "$2" ] && HIDE_BUILTINS=false list_installed_pkgs || HIDE_BUILTINS=false list_installed_pkgs "$2"; exit 0 ;; # list all installed pkgs inc builtins
  7704.  --names-exact-all|-nea|names-exact-all|nea) [ ! "$2" ] && list_all_pkg_names || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_all_pkg_names "$x\$"; done; exit 0 ;;
  7705.  
  7706.      # get, download, install, remove, pkgs
  7707.      --download|-d|download|d)
  7708.        AUTOCLEAN_override='no'  
  7709.        [ ! "$2" ] && pkg_download || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_download "$x";  done;;
  7710.      --install|-i|install|i)           [ ! "$2" ] && pkg_install  || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_install "$x";   done;;
  7711.      --uninstall|-u|uninstall|u)       [ ! "$2" ] && pkg_uninstall|| for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_uninstall "$x"; done;;
  7712.      --remove|-rm|remove|rm)           [ ! "$2" ] && pkg_remove   || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_remove "$x";    done;;
  7713.      --unpack|--extract|unpack|extract)[ ! "$2" ] && pkg_unpack   || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_unpack "$x";    done;;
  7714.      --clean|clean)                    [ ! "$2" ] && clean_pkgs   || for x in $opt; do [ "$x" -a "$x" != "-" ] && clean_pkgs "$x";    done;;
  7715.      --get|-g|get|g|--add|add|a)       [ ! "$2" ] && pkg_get      || for x in $opt; do [ "$x" -a "$x" != "-" ] && { choose_pkg "$x"; pkg_get "$x"; }; done ;;
  7716.      --get-only|-go|get-only|go)       [ ! "$2" ] && print_usage get-only || for x in $opt; do if [ "$x" -a "$x" != "-" ]; then choose_pkg "$x"; NO_INSTALL=true  pkg_get "$x"; fi; done ;;
  7717.      --delete|-l|delete|l)             [ ! "$2" ] && print_usage delete   || for x in $opt; do [ "$x" = '-' ] && continue; if [ -f "${WORKDIR}/$(basename "$x")" ]; then if [ "$ASK" = true ]; then echo -n "Remove package `basename $x`$QTAG "; read -n 1 CONFIRM </dev/tty; echo; else CONFIRM=y; fi; [ "$CONFIRM" = "y" ] && rm -v "${WORKDIR}/$(basename "$x")"; else not_found "$x"; fi; done ;; #110213,0.9.1  renamed to --delete|-l
  7718.      --delete-all|-la|delete-all|la)   ASK=true; QTAG="?  (y/N)"; if [ "$ASK" = true ]; then echo -en "Remove all downloaded packages in ${lightblue}${WORKDIR}/${endcolour}$QTAG"; read -n 1 CONFIRM </dev/tty; echo; else CONFIRM=y; fi; [ "$CONFIRM" = "y" ] && rm -v ${WORKDIR}/*.pet ${WORKDIR}/*.pkg.* ${WORKDIR}/*.sfs ${WORKDIR}/*.tar.* ${WORKDIR}/*.tcz ${WORKDIR}/*.txz ${WORKDIR}/*.tgz ${WORKDIR}/*.deb ${WORKDIR}/*.rpm ${WORKDIR}/*.apk ${WORKDIR}/*.gz ${WORKDIR}/*.xz 2>/dev/null; exit 0;;
  7719.      --install-all|-ia)                list_downloaded_pkgs | while read pkg; do [ "$pkg" -a "$pkg" != "-" ] && pkg_install "$pkg";   done;;
  7720.      --uninstall-all|-ua)              list_installed_pkgs  | while read pkg; do [ "$pkg" -a "$pkg" != "-" ] && pkg_uninstall "$pkg"; done;;
  7721.  
  7722.      # pkg status, info
  7723.      --pkg-installed|-pi|installed|pi)   [ ! "$2" ] && is_installed_pkg || for x in $opt; do [ "$x" -a "$x" != "-" ] && is_installed_pkg "$x"; done;;
  7724.      --pkg-entry|-pe|entry|pe)           [ ! "$2" ] && pkg_entry   || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_entry "$x";    done;;  # print repo entry, each field on a new line
  7725.      --pkg-status|-ps|status|ps)         [ ! "$2" ] && pkg_status  || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_status "$x";   done;;
  7726.      --contents|-c|contents|c)           [ ! "$2" ] && pkg_contents|| for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_contents "$x" 2>/dev/null; done;;
  7727.      --which|-w|which|w)                 [ ! "$2" ] && which_pkg   || for x in $opt; do [ "$x" -a "$x" != "-" ] && which_pkg "$x";    done;;
  7728.      --which-repo|-wr|which-repo|wr)     [ ! "$2" ] && which_repo  || for x in $opt; do [ "$x" -a "$x" != "-" ] && which_repo "$x";   done;;
  7729.      --pkg-repack|-pr|repack|pr)         [ ! "$2" ] && pkg_repack  || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_repack "$x";   done;;
  7730.      --pkg-update|-pu|update|pu)         [ ! "$2" ] && pkg_update  || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_update "$x";   done;;
  7731.      --pkg-combine|-pc|pkg-combine|pc)   [ ! "$2" ] && pkg_combine || for x in $opt; do [ "$x" -a "$x" != "-" ] && COMBINE2SFS=false pkg_combine "$x"; done;;
  7732.      --pkg-split|split)                  [ ! "$2" ] && split_pkg   || for x in $opt; do [ "$x" -a "$x" != "-" ] && split_pkg "$x"; done;;
  7733.      --pkg-merge|merge)                  [ ! "$2" ] && merge_pkg   || merge_pkg "$2" "$3"; exit 0;;
  7734.      --sfs-combine|-sc|sfs-combine|sc)   [ ! "$2" ] && pkg_combine || for x in $opt; do [ "$x" -a "$x" != "-" ] && COMBINE2SFS=true  pkg_combine "$x"; done;;
  7735.      -PS|PS)                             [ ! "$2" ] && pkg_status  || for x in $opt; do [ "$x" -a "$x" != "-" ] && HIDE_USER_PKGS=false FULL_PKG_STATUS=true pkg_status "$x"; done;; # full pkg status, with sorted deps
  7736.  
  7737.      # pkg compiling
  7738.      --pkg-build|-pb|build|pb)           [ ! "$2" ] && pkg_build || for x in $opt; do [ "$x" -a "$x" != "-" ] && PKG_CONFIGURE="$PKG_CONFIGURE" PKG_CFLAGS="$PKG_CFLAGS" pkg_build "$x"; done;;
  7739.   --pkg-build-list|-pbl|build-list|pbl)  [ ! "$2" ] && list_build_scripts || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_build_scripts "$x"; done;;
  7740.  
  7741.      # dependencies
  7742.      --what-needs|-wn|what-needs|wn)     [ ! "$2" ] && list_dependents; for x in $opt; do [ "$x" -a "$x" != "-" ] && list_dependents "$x";    done ;; # list pkgs depending on $x, not including builtins by default
  7743.      --list-deps|-le|list-deps|le)       [ ! "$2" ] && list_deps; for x in $opt; do [ "$x" -a "$x" != "-" ] && list_deps "$x";                done ;; # list pkg deps, not including builtins
  7744.      --deps|-e|deps|e)                   [ ! "$2" ] && get_deps;  for x in $opt; do [ "$x" -a "$x" != "-" ] && get_deps  "$x";                done ;;
  7745.    --deps-download|-ed|deps-download|ed) [ ! "$2" ] && get_deps;  for x in $opt; do [ "$x" -a "$x" != "-" ] && NO_INSTALL=true get_deps "$x"; done ;;
  7746.      --has-deps|-he|has-deps|he)         [ ! "$2" ] && has_deps;  for x in $opt; do [ "$x" -a "$x" != "-" ] && has_deps  "$x";                done ;;
  7747.      --deps-all|-ea|deps-all|ea)         [ ! "$2" ] && get_deps;  [ "$2" != "-" ] && NO_INSTALL=false get_all_deps "$2" ;;
  7748.      --deps-check|-ec|deps-check|ec|ldd) [ ! "$2" ] && print_usage deps-check || pkg_ldd_msg "$2" ;;
  7749.      -LE|LE)                             [ ! "$2" ] && HIDE_BUILTINS=false list_deps || for x in $opt; do [ "$x" -a "$x" != "-" ] && HIDE_BUILTINS=false list_deps "$x"; done ;;  # list a pkg deps, including builtins
  7750.  
  7751.      # repo
  7752.      --repo|-r|repo|r)                     [ ! "$2" ] && echo $REPONAME || set_current_repo "$2" ;;
  7753.      --repo-convert|-rc|repo-convert|rc)   [ ! "$2" ] && print_usage repo-convert || for x in $opt; do [ "$x" -a "$x" != "-" ]  && convert_repofile "$x"; done ;;
  7754.      --repo-list|-rl|repo-list|rl)         [ "$2" != "-" ] && repo_list "$2"      ;;
  7755.      --repo-info|-ri|repo-info|ri)         [ "$2" != "-" ] && print_repo_info "$2";;
  7756.  --repo-file-list|-rfl|repo-file-list|rfl) [ "$2" != "-" ] && repo_file_list "$2" ;;
  7757.      --repo-update|-ru|repo-update|ru)     update_repo "$2";;
  7758.      --add-source|add-source)              [ "`echo $2|grep '|'`" = '' -o "$2" = '-' ] && print_usage add-source || add_source "$2";;
  7759.      --add-repo|add-repo)                  [ ! "$2" -o "$2" = '-'  ] && print_usage add-repo || shift; add_repo "$@"; exit 0;;
  7760.      --rm-repo|rm-repo)                    [ ! "$2" -o "$2" = '-'  ] && print_usage rm-repo  || rm_repo "$2"; exit 0;;
  7761.      --update-sources|update-sources)      update_sources ;;
  7762.  
  7763.      # set repo settings
  7764.      --repo-pkg-scope|-rps|rps|repo-pkg-scope)  if [ "$2" -a "$2" != "-" ]; then set_pkg_scope "$2";      else echo "$PKGSCOPE"; fi; exit 0;;
  7765.      --repo-dep-scope|-rds|repo-dep-scope|rds)  if [ "$2" -a "$2" != "-" ]; then set_dep_scope "$2";      else echo "$DEPSCOPE"; fi; exit 0;;
  7766.      --bleeding-edge|-be|bleeding-edge|be)      if [ "$2" -a "$2" != "-" ]; then set_bleeding_edge "$2";  else echo "$BLEDGE";   fi; exit 0;;
  7767.      --rdep-check|-rdc|rdep-check|rdc)          if [ "$2" -a "$2" != "-" ]; then set_recursive_deps "$2"; else echo "$RDCHECK";  fi; exit 0;;
  7768.  
  7769.      # convert
  7770.      --deb2pet|deb2pet) [ ! "$2" ] && deb2pet || for x in $opt; do deb2pet "$x"; done ;;
  7771.      --dir2pet|dir2pet) [ ! "$2" ] && dir2pet || for x in $opt; do dir2pet "$x"; done ;;
  7772.      --dir2sfs|dir2sfs) [ ! "$2" ] && dir2sfs || for x in $opt; do dir2sfs "$x"; done ;;
  7773.      --dir2tgz|dir2tgz) [ ! "$2" ] && dir2tgz || for x in $opt; do dir2tgz "$x"; done ;;
  7774.      --pet2sfs|pet2sfs) [ ! "$2" ] && pet2sfs || for x in $opt; do pet2sfs "$x"; done ;;
  7775.      --pet2tgz|pet2tgz) [ ! "$2" ] && pet2tgz || for x in $opt; do pet2tgz "$x"; done ;;
  7776.      --pet2txz|pet2txz) [ ! "$2" ] && pet2txz || for x in $opt; do pet2txz "$x"; done ;;
  7777.      --sfs2pet|sfs2pet) [ ! "$2" ] && sfs2pet || for x in $opt; do sfs2pet "$x"; done ;;
  7778.      --tgz2pet|tgz2pet) [ ! "$2" ] && tgz2pet || for x in $opt; do tgz2pet "$x"; done ;;
  7779.      --txz2pet|txz2pet) [ ! "$2" ] && txz2pet || for x in $opt; do txz2pet "$x"; done ;;
  7780.    --dir2repo|dir2repo) [ ! "$2" ] && dir2repo|| for x in $opt; do dir2repo "$x"; done ;;
  7781.  
  7782.      # other
  7783.      --func-list|func-list)  [ -f $TMPDIR/func_list ] && cat $TMPDIR/func_list || func_list; exit 0;;
  7784.      --workdir|workdir)      [ "$2" != "-" ] && set_workdir "$2"; exit $?;;
  7785.      --autoclean|autoclean)  [ "$2" = "yes" -o "$2" = "no" ] && set_autoclean "$2" || { echo "$AUTOCLEAN"; exit 1; } ;;
  7786.  
  7787.      # usage, help funcs, version info, etc
  7788.      --welcome|welcome)          touch $HOME/.pkg/firstrun; first_run; exit 0;;
  7789.      --show-config|show-config)  show_config; exit 0;;
  7790.      --version|-v|version|v)     echo "$APPNAME $APPVER"; exit 0;;
  7791.      --usage|usage)              print_usage "$2"; exit 0;;
  7792.  
  7793.      --examples|-ex|examples|ex)
  7794.        . /usr/share/pkg/docs/examples.txt;
  7795.        echo -e "$EXAMPLES\n"
  7796.        exit 0
  7797.        ;;
  7798.      --help-all|-H|help-all|H)
  7799.          . /usr/share/pkg/docs/env_vars.txt
  7800.          . /usr/share/pkg/docs/help.txt
  7801.          . /usr/share/pkg/docs/examples.txt
  7802.          . /usr/share/pkg/docs/help-all.txt
  7803.          echo -e "$HELP_ALL\n\n" | less -R
  7804.          exit 0
  7805.          ;;
  7806.  
  7807.      --help|-h|help|h)
  7808.          . /usr/share/pkg/docs/env_vars.txt
  7809.          . /usr/share/pkg/docs/help.txt
  7810.          echo -e "$HELP\n"
  7811.          exit 0
  7812.          ;;
  7813.  
  7814.      # any other options
  7815.      -?*|--?*)
  7816.          # exit if bad options
  7817.          echo "Unknown option '$1'" && exit 1
  7818.        ;;
  7819.  
  7820.      ?*)
  7821.          # all other options .. might be an internal func, if so, execute it with all given options
  7822.          [ "`func_list | tr '\t' ' ' | cut -f2 -d' ' | grep -m1 "^${1}"'()'`" != '' ] && "$@" && exit 0
  7823.        ;;
  7824.  
  7825.      esac
  7826.  
  7827.      shift
  7828.      I=$(($I + 1))
  7829.    done
  7830. done
  7831.  
  7832.  
  7833.  
  7834. #====================  main interface  ======================#
  7835. code=$?
  7836. [ ! -z "$AUTOCLEAN_override" ] && AUTOCLEAN="$AUTOCLEAN_override"
  7837. # if AUTOCLEAN=true silently delete all pkgs in WORKDIR that are already installed
  7838. if [ "$AUTOCLEAN" = 'yes' -a "`HIDE_BUILTINS=true list_installed_pkgs`" != '' ]; then
  7839.   clean_pkgs &>/dev/null
  7840. fi
  7841.  
  7842.  
  7843.  
  7844. # remove tmp dir used by pkg_get and get_deps
  7845. rm $TMPDIR/PKGSDONE 2>/dev/null
  7846.  
  7847. # reset lang options as we found them
  7848. LANG=$USER_LANG
  7849. LC_ALL=$USER_LC_ALL
  7850.  
  7851. exit $code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement