Advertisement
s243a

pkg (tiny_puduan_ascii-PreA11.1-Remaster

Aug 5th, 2019
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 296.97 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.  
  29. # get current locale settings
  30. USER_LANG=$LANG
  31. USER_LC_ALL=$LC_ALL
  32.  
  33. SELF=$(basename $0)        # this script
  34. QTAG=''                    # gets set to (y/n) if ASK=-true
  35. LANG=C                     # speed up
  36. LC_ALL=C                   # speed up
  37. EDITOR=${EDITOR:-vi}       # just in case
  38. PAGER=${PAGER:-less}       # just in case
  39. CURDIR="${PWD}"            # get current dir, before cd to WORKDIR
  40. whoami=$(whoami)           # s243a copied from below. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
  41. TMPDIR=/tmp/pkg/${whoami}  # set the tmp dir
  42.  
  43. # set colours true by default
  44. green="\e[32m"; red="\e[91m"; magenta="\e[95m"; lightblue="\e[36m"; yellow="\e[93m"; bold="\e[1m"; endcolour="\e[0m"
  45.  
  46. # ENVIRONMENT VARS, which may be overridden later
  47. [ -z "$PKGRC" ] && export PKGRC=${HOME}/.pkg/pkgrc      # config file for this script
  48. [ -z "$ASK"   ] && ASK=false                            # if true, ask user before doing stuff. Overridden by --ask
  49. [ -z "$QUIET" ] && QUIET=false                          # if true, hide output that doesnt log well in Xdialog, Gtkdialog, etc
  50. [ -z "$FORCE" ] && FORCE=false                          # if true, force (re)install/remove pkgs. Overridden by --force
  51. [ -z "$HIDE_INSTALLED" ] && export HIDE_INSTALLED=false # if true, hide installed pkgs from pkg searches (-n, -na, -ss, -ssa)
  52. [ -z "$HIDE_BUILTINS"  ] && export HIDE_BUILTINS=true   # if true, remove builtins pkgs from dep lists, dont download/install them
  53. [ -z "$HIDE_USER_PKGS" ] && export HIDE_USER_PKGS=true  # if true, hide user installed pkgs from dep lists, dont download/install them
  54. [ -z "$NO_ALIASES"     ] && export NO_ALIASES=false     # if true, skip searching pkg alias names for pkg alternatives
  55. [ -z "$NO_INSTALL"     ] && export NO_INSTALL=false     # if true, skip installing of pkgs
  56. [ -z "$PKG_NO_COLOURS" ] && export PKG_NO_COLOURS=false # if true, disable coloured output or not
  57. [ -z "$PKG_CONFIGURE"  ] && export PKG_CONFIGURE=''     # reset
  58. [ -z "$PKG_CFLAGS"     ] && export PKG_CFLAGS=''        # reset
  59.  
  60. [ -z "$PKGS_DIR" ] && export PKGS_DIR="$(realpath "${HOME}/.packages")"
  61. #These are files of the form
  62. #[ -z "$PET_SPEC_DIR_ROOT" ] && PET_SPEC_DIR_ROOT="$PKGS_DIR"
  63. if [ -z "$REPO_DB_FILE_DIR" ]; then
  64.   if [ -d "$PKGS_DIR/repo" ]; then #This imples mistfires ppm3 is installed
  65.     export REPO_DB_FILE_DIR="$(realpath "$PKGS_DIR/repo")"
  66.   else
  67.     export REPO_DB_FILE_DIR="$PKGS_DIR"
  68.   fi
  69. fi
  70. if [ -z "$PACKAGE_FILE_LIST_DIR" ]; then
  71.   if [ -d "$PKGS_DIR/package-files" ]; then #This imples mistfires ppm3 is installed
  72.     export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR/package-files")"
  73.   else
  74.     export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR")"
  75.   fi
  76. fi
  77. [ -z "$BUILTIN_FILE_LIST_DIR" ] && BUILTIN_FILE_LIST_DIR="$PKGS_DIR/builtin_files"
  78. #[ -z "$PET_SPEC_DIR_BUILTIN" ] && PET_SPEC_DIR_BUILTIN=\
  79. #  "$(realpath "$PKGS_DIR/builtin_files")"
  80. #
  81. #[ -z "$PET_SPEC_DIR_USR_INST" ] && PET_SPEC_DIR_USR_INST="$PKGS_DIR"
  82.  
  83.  
  84. #mk_spec_file_list_arry(){
  85.  declare -ga SPEC_DB_PATHS=()
  86.  #Can't put the loop in the loop in a pipeline if you want to assign array values:
  87.  #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop  
  88.  #find / -wholename "$PKGS_DIR"/'*-installed-packages' |
  89.  while read SPEC_FILE; do
  90.    bname="`basename "$SPEC_FILE"`"
  91.    case "$bname" in #Consider lowering case
  92.    "layers-installed-packages")
  93.      #Do Nothing
  94.      export LAYER_INST_PKGS_FILE="$SPEC_FILE" ;;
  95.    "woof-installed-packages")
  96.      export WOOF_INST_PKGS_FILE="$SPEC_FILE" ;;
  97.    "user-installed-packages")
  98.      export USER_INST_PKGS_FILE="$SPEC_FILE" ;;
  99.    "devx-only-installed-packages")
  100.      export DEVX_INST_PKGS_FILE="$SPEC_FILE" ;;    
  101.    *)
  102.      SPEC_DB_PATHS+=( "$SPEC_FILE" ) ;;
  103.    esac
  104.    #s243a: We don't need realpath for the next four vars but it will provide usefull debugging information.
  105.    #s243a: TODO search for the following files if they don't exist.
  106.    [ -z "$USER_INST_PKGS_FILE" ] && \
  107.      USER_INST_PKGS_FILE="$PKGS_DIR/user-installed-packages"
  108.    [ -z "$WOOF_INST_PKGS_FILE" ] && \
  109.      WOOF_INST_PKGS_FILE="$PKGS_DIR/woof-installed-packages"
  110.    [ -z "$LAYER_INST_PKGS_FILE" ] && \
  111.      LAYER_INST_PKGS_FILE="$PKGS_DIR/layers-installed packages"
  112.    [ -z "$DEVX_INST_PKGS_FILE" ] && \
  113.      DEVX_INST_PKGS_FILE="$PKGS_DIR/devx-only-installed-packages"
  114.    SPEC_DB_PATHS=( "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${SPEC_DB_PATHS[@]}" )
  115.  done < <( find "$PKGS_DIR" -name '*-installed-packages' )
  116. #}  
  117. #mk_spec_file_list_arry
  118. #echo "SPEC_DB_PATHS=${SPEC_DB_PATHS[@]}"
  119.  
  120. #mk_all_repo_file_list_arry(){
  121.  declare -gA ALL_REPO_DB_PATHS=()
  122.  #ALL_REPO_DB_PATHS=()
  123.  bname=''
  124.  
  125.  #Can't put the loop in the loop in a pipeline if you want to assign array values:
  126.  #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  127.  #find / -wholename "$REPO_DB_FILE_DIR"/'Packages-*' |
  128.  while read REPO_FILE; do
  129.      #s243a: I was thinking of using realpath but it might cause issues.
  130.      #REPO_FILE="$(realpath "$REPO_FILE")"
  131.      bname="$(basename "$REPO_FILE")"  
  132.      ALL_REPO_DB_PATHS+=( ["$bname"]="$REPO_FILE" )
  133.      #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  134.      #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  135.  done < <( find "$REPO_DB_FILE_DIR" -name 'Packages-*' )
  136. #}  
  137. #mk_all_repo_file_list_arry
  138. #echo "exited: mk_all_repo_file_list_arry()"
  139. #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  140.  
  141. #Moved after the function repo_file_list
  142. #mk_repo_file_list_arry
  143. # but disable colours if called as gpkg, or the ENV variable PKG_NO_COLOURS is true
  144. if [ "`basename $0`" != "pkg" -o "$PKG_NO_COLOURS" = true ];then
  145.   green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour=''
  146. fi
  147.  
  148. # report errors better than just echo
  149. error(){
  150.   echo -e 1>&2 "${red}Error:${endcolour} $1"
  151. }
  152.  
  153. # for correct error output, trap commands early
  154. cleanup(){
  155.   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
  156.   rm -rf /tmp/pkg/build_pkg/ &>/dev/null
  157.  
  158.   # prevent double msg output if error=130 (user Ctrl-C)
  159.   [ -f /tmp/pkg/error130 -a "$2" = '130' ] && exit "$2"
  160.   # make the tmp dir we'll use
  161.   mkdir -p /tmp/pkg &>/dev/null
  162.   # only add line numbers if it was given
  163.   [ "$1" != 'none' ] && lineno="line $1, " || lineno=''
  164.   # get the right error msg
  165.   case "$2" in
  166.   130) echo; msg="User cancelled operation!"; touch /tmp/pkg/error130;;
  167.   8)   msg="Package URL invalid.";;
  168.   7)   msg="Package extraction failed.";;
  169.   6)   msg="Missing package file.";;
  170.   5)   msg="Missing directory.";;
  171.   4)   msg="Copy failed.";;
  172.   3)   msg="Setup failed.";;
  173.   2)   msg="Code error!";;
  174.   1)   exit 1 ;; # user gave wrong options or pkg name, not serious
  175.   *)   msg="Error code = $2" ;;
  176.   esac
  177.   # print msg
  178.   [ "$2" != "0" ]  && echo -e 1>&2 "${red}Error${endcolour} ${2}: ${lineno}$msg"
  179.   exit $2
  180. }
  181. trap 'cleanup ${LINENO:-none} $?' EXIT INT TERM
  182.  
  183. #run as root only
  184. whoami=$(whoami) #s243a Copied to before line #40. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
  185. [ "$whoami" != "root" ] && echo "You must be root to run Pkg." && exit 1
  186.  
  187. #080413 make sure all config files are present, copy from /etc if need be
  188. if [ ! -f ${PKGRC} ];then
  189.   echo "Restoring default settings from /etc/pkg"
  190.   [ ! -d /etc/pkg/ ] && error "Default config files  in /etc/pkg/ not found." && exit 3
  191.   mkdir -p "$HOME/.pkg"
  192.   [ ! -d "$HOME/.pkg" ] && error "Default user config dir '$HOME/.pkg/' could not be created." && exit 3
  193.   cp --force -a /etc/pkg/* "$HOME/.pkg/" || exit 3
  194. fi
  195.  
  196. # get puppy distro env vars
  197. [ -f /etc/rc.d/PUPSTATE ]                   && . /etc/rc.d/PUPSTATE                    #this has PUPMODE and SAVE_LAYER.
  198. [ -f /etc/DISTRO_SPECS ]                    && . /etc/DISTRO_SPECS                     #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  199. [ -f /etc/rc.d/BOOTCONFIG ]                 && . /etc/rc.d/BOOTCONFIG                  #has EXTRASFSLIST PREVUNIONRECORD, LASTUNIONRECORD (sfs stuff)
  200. [ -f /etc/xdg/menus/hierarchy ]             && . /etc/xdg/menus/hierarchy              #w478 has PUPHIERARCHY variable.
  201. [ -f $PKGS_DIR/DISTRO_PKGS_SPECS ]    && . $PKGS_DIR/DISTRO_PKGS_SPECS     #has lot sof essential info
  202. [ -f $PKGS_DIR/PKGS_MANAGEMENT ]      && . $PKGS_DIR/PKGS_MANAGEMENT       #has PKG_NAME_IGNORE, PKG_PET_THEN_BLACKLIST_COMPAT_KIDS, PKG_REPOS_ENABLED
  203. [ -f $PKGS_DIR/DISTRO_COMPAT_REPOS ]  && . $PKGS_DIR/DISTRO_COMPAT_REPOS   #has repo URL related vars
  204.  
  205. # set the package name suffix appended to combined pkgs (pkg+deps)
  206. CP_SUFFIX="WITHDEPS_${DISTRO_FILE_PREFIX}"
  207.  
  208. # set correct arch for repo URLs (used by some slack-pup repos)
  209. case "$DISTRO_TARGETARCH" in
  210.   x86)    DBIN_ARCH=i486                ;;
  211.   x86_64) DBIN_ARCH=x86_64 ; DSUFFIX=64 ;;
  212.   *)      DBIN_ARCH=i486                ;;
  213. esac
  214.  
  215. # needed for some debian based repos
  216. case $DISTRO_COMPAT_VERSION in
  217.   wheezy) DDB_COMP=bz2 ;; # older versions
  218.   *)      DDB_COMP=xz  ;;
  219. esac
  220.  
  221. # now create 'layers-installed': will contain builtins (and devx packages, if devx is loaded)
  222. #130511 need to include devx-only-installed-packages, if loaded...
  223. if which gcc &>/dev/null;then
  224.   [ ! -f /tmp/ppm-layers-installed-packages ] && cp -f "$WOOF_INST_PKGS_FILE" /tmp/ppm-layers-installed-packages &>/dev/null
  225.   cat "$PET_SPEC_DIR_DEFAULT/devx-only-installed-packages" >> /tmp/ppm-layers-installed-packages &>/dev/null
  226.   sort -u /tmp/ppm-layers-installed-packages > "$LAYER_INST_PKGS_FILE" &>/dev/null
  227. else
  228.   cp -f "$WOOF_INST_PKGS_FILE" "$LAYER_INST_PKGS_FILE" &>/dev/null
  229. fi
  230.  
  231. # set $DIRECTSAVEPATH (where we want to install pkgs)
  232. if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ];then
  233.   DIRECTSAVEPATH="/initrd${SAVE_LAYER}" #SAVE_LAYER is in /etc/rc.d/PUPSTATE.
  234. elif [ "$PUPMODE" = "2" ]; then
  235.   DIRECTSAVEPATH=""
  236. fi
  237. # s243a: Need the real path to avoid overwriting sylinks. See:
  238. # http://murga-linux.com/puppy/viewtopic.php?p=1030958#1030958  
  239. # https://github.com/puppylinux-woof-CE/woof-CE/issues/1469#issuecomment-505706014
  240. [ -L "$DIRECTSAVEPATH" ] && DIRECTSAVEPATH="$(readlink "$DIRECTSAVEPATH")"
  241. # get repo details, workdir, search settings and so on.. you could
  242. # you can also add any ENVIRONMENT VARS above to PKGRC, to override the defaults
  243. . ${PKGRC}
  244.  
  245. # set and create workdir if no valid dir set
  246. [ ! -d "$WORKDIR" ] && mkdir -p "$WORKDIR"
  247. if [ ! -d "$WORKDIR" ];then
  248.   error "Can't create $WORKDIR. Please create it."
  249.   exit 3
  250. fi
  251. WORKDIR=~/pkg
  252.  
  253. # add to tab completion settings to bashrc and print hint
  254. if [ -z "$PKG_TAB_COMPLETION" ];then
  255.   if [ "$(grep 'export PKG_TAB_COMPLETION=true' ~/.bashrc)" = "" ];then
  256.     # add to bashrc
  257.     echo "" >> ~/.bashrc
  258.     echo "# enable $APPNAME $APPVER TAB completion" >> ~/.bashrc
  259.     echo "export PKG_TAB_COMPLETION=true" >> ~/.bashrc
  260.     echo ". /etc/bash_completion.d/pkg 2>/dev/null" >> ~/.bashrc
  261.   fi
  262. fi
  263.  
  264. # make tmp dir writable by everyone if needed
  265. if [ ! -d "$TMPDIR" ];then
  266.   mkdir -p "$TMPDIR" 2>/dev/null
  267.   chmod -R 1777 /tmp/pkg/ 2>/dev/null
  268. fi
  269.  
  270. # if no tmp dir created or accessible, exit
  271. [ ! -d "$TMPDIR" ] && error "Cannot create temp dir ${lightblue}$TMPDIR${endcolour}" && exit 3
  272.  
  273. # support aliases, create ALIASES tmp file
  274. 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'
  275. [ ! -f "$TMPDIR/pkg_aliases" ] && echo "$PKG_NAME_ALIASES" | tr ' ' '\n' > $TMPDIR/pkg_aliases
  276.  
  277. # remove error code flag if we got here
  278. rm -f /tmp/pkg/error130 &>/dev/null
  279.  
  280. # if not first run, and no options given, print the help
  281. [ ! -f ~/.pkg/firstrun -a "$1" = "" ] && $SELF -H && exit 1 #200913 more help by default
  282.  
  283. #==================  setup script vars  =====================#
  284.  
  285.  
  286.  
  287. #====================  main functions  ======================#
  288.  
  289. set -a
  290.  
  291. # utility funcs
  292.  
  293. print_usage(){                    # print usage text. Requires $1, a valid Pkg cmd FUNCLIST
  294.  
  295.   local examples_file=/usr/share/pkg/docs/examples.txt
  296.  
  297.   [ -f $examples_file ] && source $examples_file
  298.  
  299.   # get and print the usage info from its usage file
  300.   if [ -f /usr/share/pkg/docs/usage/$1 -a "$1" ];then
  301.     source /usr/share/pkg/docs/usage/$1
  302.     echo -e "\n$USAGE"
  303.     # show examples, taken from $EXAMPLES, if they exist
  304.     if [ "`echo "$EXAMPLES" | grep "$SELF" | grep "\-$1"`" != '' ];then
  305.       echo -e "\n${bold}Usage Examples${endcolour}:\n"
  306.       echo -e "$EXAMPLES" | grep "$SELF " | grep "$1 "
  307.     fi
  308.   else
  309.     echo -e "Usage: ${bold}$SELF usage CMD${endcolour}"
  310.     echo
  311.     echo "Commands:"
  312.     echo -e "add-repo       get-only         repo-convert
  313. add-source     help             repo-dep-scope
  314. all-pkgs       help-all         repo-file-list
  315. add            remove           repo-info
  316. ask            install          repo-list
  317. autoclean      install-all      repo-pkg-scope
  318. bleeding-edge  list-deps        repo-update
  319. clean          list-downloaded  search
  320. contents       list-installed   search-all
  321. deb2pet        names            sfs2pet
  322. delete         names-all        sfs-combine
  323. delete-all     names-exact      show-config
  324. deps           names-exact-all  split
  325. deps-all       pet2sfs          tgz2pet
  326. deps-check     pet2tgz          uninstall
  327. deps-download  pet2txz          uninstall-all
  328. dir2pet        build            unpack
  329. dir2sfs        build-list       update-sources
  330. dir2tgz        pkg-combine      version
  331. download       installed        which
  332. examples       repack           which-repo
  333. extract        status           rdep-check
  334. force          update           what-needs
  335. func-list      workdir          rm-repo
  336. txz2pet        dir2repo
  337.  
  338. Usage: ${bold}$SELF usage CMD${endcolour}"
  339.     #cd /usr/share/pkg/docs/usage/; echo `ls` | fold -w 70 -s
  340.   fi
  341.   exit 1
  342. }
  343.  
  344.  
  345. func_list(){                      # list all functions available in this script FUNCLIST
  346.   [ -f $TMPDIR/func_list ] && cat $TMPDIR/func_list | sort && exit 0
  347.   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
  348.   cat $TMPDIR/func_list | sort
  349.   exit 0
  350. }
  351.  
  352.  
  353. get_pkg_ext(){                    # return file extension of $1 FUNCLIST
  354.  
  355.   # get valid usage or exit
  356.   [ ! "$1" ] && echo 'Usage: get_pkg_ext PKGNAME' && exit 1
  357.  
  358.   local pkg_installed=''
  359.   local pkg_filename=''
  360.   local pkg_ext=''
  361.   local pkg_name=''
  362.  
  363.   # check given file type, see if it matches our supported pkg types
  364.   case "$1" in
  365.     *.bz2)        echo bz2        ;;
  366.     *.pet)        echo pet        ;;
  367.     *.deb)        echo deb        ;;
  368.     *.pkg.tar.gz) echo pkg.tar.gz ;;
  369.     *.pkg.tar.xz) echo pkg.tar.xz ;;
  370.     *.pkg.tgz)    echo pkg.tgz    ;;
  371.     *.pkg.txz)    echo pkg.txz    ;;
  372.     *.tar.bz2)    echo tar.bz2    ;;
  373.     *.tar.lzma)   echo tar.lzma   ;;
  374.     *.tar.gz)     echo tar.gz     ;;
  375.     *.tar.xz)     echo tar.xz     ;;
  376.     *.tbz)        echo tbz        ;;
  377.     *.tgz)        echo tgz        ;;
  378.     *.tlz)        echo tlz        ;;
  379.     *.txz)        echo txz        ;;
  380.     *.gz)         echo gz         ;;
  381.     *.xz)         echo xz         ;;
  382.     *.rpm)        echo rpm        ;;
  383.     *.sfs)        echo sfs        ;;
  384.     #*.tcz)        echo tcz       ;;
  385.     #*.tpkg)       echo tpkg      ;;
  386.     #*.apk)        echo apk       ;;
  387.     *)
  388.       # if it's an installed pkg, get the extension from $PKGS_DIR/*
  389.       pkg_installed=`list_installed_pkgs "$1" | grep -m1 "^$1"`
  390.  
  391.       # if $pkg_check not empty, then $1 is an installed pkg
  392.       if [ "$pkg_installed" != '' ];then
  393.         pkg_filename=`cut -f8 -d'|' "$USER_SPEC_FILE" |grep -m1 ^$1`
  394.         [ "$pkg_filename" = '' ] && pkg_filename=`cut -f8 -d'|' "${SPEC_DB_PATHS[@]}" |grep -m1 ^$1`
  395.         [ "$pkg_filename" != '' ] && pkg_ext=`get_pkg_ext "$pkg_filename"`
  396.       else
  397.         # if it's a repo package, get it's extension from $PKGS_DIR/*
  398.         pkg_filename=`grep -m1 "^$1" "${REPO_DB_PATHS[@]}" |cut -f8 -d'|'`
  399.        [ "$pkg_filename" != '' ] &&  pkg_ext=`get_pkg_ext "$pkg_filename"`
  400.       fi
  401.       [ "$pkg_ext" != '' ] && echo $pkg_ext
  402.       ;;
  403.   esac
  404. }
  405.  
  406.  
  407. get_pkg_version(){                # returns version of PKGNAME ($1) FUNCLIST
  408.  
  409.   # exit if no pkg given
  410.   [ ! "$1" ] && exit 1
  411.  
  412.   local PKGNAME=`get_pkg_name "$1"`
  413.   local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  414.   local pkg_ext=`get_pkg_ext "$PKGNAME"`
  415.   local pkg_version=''
  416.  
  417.   PKGNAME=$(basename "$PKGNAME" .$pkg_ext)
  418.  
  419.   pkg_version=`echo $PKGNAME | sed -e "s/^${PKGNAME_ONLY}_//g"`
  420.   # if $pkg_version is same as $PKGNAME, try cutting again, using '-' instead of '_'
  421.   [ "$pkg_version" = "$PKGNAME" ] && pkg_version=`echo $PKGNAME | sed -e "s/^${PKGNAME_ONLY}-//g"`
  422.  
  423.   # now trim off the other unneeded bits
  424.   pkg_version=`echo  $pkg_version | sed \
  425.     -e "s/^-//g" \
  426.     -e "s/^_//g" \
  427.     -e "s/^DEV-//g" \
  428.     -e "s/^DOC-//g" \
  429.     -e "s/^NLS-//g" \
  430.     -e "s/^dev-//g" \
  431.     -e "s/^doc-//g" \
  432.     -e "s/^nls-//g" \
  433.     -e "s/+deb.*//g" \
  434.     -e "s/+ubuntu.*//g" \
  435.     -e "s/-i[346].*//g" \
  436.     -e "s/-x[86].*//g" \
  437.     -e "s/-pup.*//g" \
  438.     -e "s/-q[0-9].*//g" \
  439.     -e "s/-WITHDEPS.*//g" \
  440.     -e "s/-PLUSDEPS.*//g" \
  441.     -e 's@\\\@@g'`
  442.  
  443.   # get $REPONAME and $EX
  444.   . ${PKGRC}
  445.  
  446.   [ "$pkg_ext" = '' ] && pkg_ext=$EX
  447.  
  448.   echo $pkg_version
  449.   return 0
  450. }
  451.  
  452.  
  453. get_pkg_name_only_from_ext(){     # return package name from $1 (must include file extension)
  454.  
  455.   # get valid usage or exit
  456.   [ ! "$1" ] && echo 'Usage: get_pkg_name_only_from_ext <PKG_FILENAME>' && exit 1
  457.  
  458.   # get the extension of the given package name, if any
  459.   local pkg_ext=`get_pkg_ext "$1"`
  460.   # get the name without path and extension
  461.   local pkg_name=`basename "$1" .$pkg_ext`
  462.   local PKGNAME=''
  463.   local PKGNAME_ONLY=''
  464.   local DB_pkgrelease=''
  465.   local prPATTERN=''
  466.   local DB_version=''
  467.   local xDB_version=''
  468.   local xPATTERN=''
  469.  
  470.   #split PKGMAIN, ex: FULLPKGNAME=xvidtune-1.0.1-i486-1.tgz has PKGNAME=xvidtune-1.0.1
  471.   case $pkg_ext in
  472.     deb)
  473.      #deb ex: xsltproc_1.1.24-1ubuntu2_i386.deb  xserver-common_1.5.2-2ubuntu3_all.deb
  474.      PKGNAME_ONLY="`echo -n "$pkg_name" | cut -f 1 -d '_'`"
  475.      DB_pkgrelease="`echo -n "$pkg_name" | rev | cut -f 2 -d '_' | cut -f 1 -d '-' | rev`"
  476.      prPATTERN="s%\\-${DB_pkgrelease}.*%%"
  477.      PKGNAME="`echo -n "$pkg_name" | sed -e "$prPATTERN" 2>/dev/null`"
  478.     ;;
  479.     pet)
  480.      PKGNAME="$pkg_name"
  481.      DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\-%%'`"
  482.      xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  483.      xPATTERN="s%${xDB_version}%%"
  484.      PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  485.     ;;
  486.     tgz|txz)
  487.      #slack ex: xvidtune-1.0.1-i486-1.tgz  printproto-1.0.4-noarch-1.tgz
  488.      PKGNAME="`echo -n "$pkg_name" | sed -e 's%\\-i[3456]86.*%%' -e 's%\\-noarch.*%%'`"
  489.      DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\\-%%'`"
  490.      xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  491.      xPATTERN="s%${xDB_version}%%"
  492.      PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\-$%%' 2>/dev/null`"
  493.     ;;
  494.     tar.gz)
  495.      #arch ex: xproto-7.0.14-1-i686.pkg.tar.gz  trapproto-3.4.3-1.pkg.tar.gz
  496.      PKGNAME="`echo -n "$pkg_name" | sed -e 's%\\-i[3456]86.*%%' -e 's%\\.pkg$%%' | rev | cut -f 2-9 -d '-' | rev`"
  497.      DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\\-%%'`"
  498.      xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  499.      xPATTERN="s%${xDB_version}%%"
  500.      PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  501.     ;;
  502.     rpm) #110523
  503.      #exs: hunspell-fr-3.4-1.1.el6.noarch.rpm
  504.      PKGNAME="$pkg_name"
  505.      DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\-%%'`"
  506.      xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  507.      xPATTERN="s%${xDB_version}%%"
  508.      PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  509.     ;;
  510.   esac
  511.   [ "$PKGNAME_ONLY" != '' ] && echo $PKGNAME_ONLY || echo "$1"
  512. }
  513.  
  514.  
  515. get_pkg_name_only(){              # return pkg name only from $1, with no version or suffix FUNCLIST
  516.  
  517.   # exit if no valid options
  518.   [ ! "$1" ] && exit 1
  519.  
  520.   # get config settings, inc current repo file
  521.   #. ${PKGRC}
  522.  
  523.   local pkg_name=''
  524.   local pkg_name_only=''
  525.   local name_only=''
  526.   local pkg_ext=`get_pkg_ext "$1"`
  527.   local repo_of_pkg=''
  528.   local repo_pkg_with_ext=''
  529.   local repo_ext=$EX      # from $PKGRC
  530.  
  531.   # check the repos
  532.   local pkg_name_only="`grep -m1 "|${1}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|'`"
  533.   [ "$pkg_name_only" = '' ] && pkg_name_only="`grep -m1 "^${1}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|' | head -1`"
  534.   [ "$pkg_name_only" = '' ] && pkg_name_only="`grep -m1 "|${1}.${pkg_ext}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|' | head -1`"
  535.  
  536.   pkg_name_only=${pkg_name_only// */}
  537.  
  538.   # if we found it, print it and exit
  539.   if [ "$pkg_name_only" != '' ];then
  540.       echo ${pkg_name_only}
  541.       return 0
  542.   fi
  543.  
  544.   # if not, but we have an extension, try  get_pkg_name_only_from_ext()
  545.   case $DISTRO_BINARY_COMPAT in ubuntu|trisquel|debian|devuan)
  546.     name_only=`get_pkg_name_only_from_ext "$(basename "${1}.${repo_ext}")"| head -1`
  547.     name_only=${name_only// */}
  548.     [ "$name_only" != '' -a "$name_only" != "$1" ] && echo $name_only && return 0
  549.     ;;
  550.   esac
  551.  
  552.   ## ...if we didn't find the name using the above, do the horrible checks below
  553.  
  554.   # replace the dash before the version number with an @ symbol.
  555.   # INFO: sed /-[^-][^+][^a-zA-Z][0-9.]*/ (hopefully?) replaces '-$VER' with '@'
  556.   # not including when $VER starts with a number/letter
  557.   pkg_name_only="`echo "$(basename "${1}")" | sed -e 's/-[^-][^+][^a-zA-Z][0-9.]*/@/'`"
  558.  
  559.   # do 'ioquake3+u20130504' => 'oquake3'
  560.   pkg_name_only="`echo "${pkg_name_only}" | sed -e 's/+[a-z]/@/'`"
  561.  
  562.   # note, we haven't cut away version numbers preceeded with underscores (_) yet
  563.  
  564.   # if the version number was preceeded by an underscore, the version
  565.   # will still be in the $pkg_name_only - pkgname_2.3.4 - so cut it out
  566.   if [ "`echo "$pkg_name_only" | grep -o "_[0-9]\."`" != '' ];then
  567.     pkg_name_only="`echo "$pkg_name_only" | sed -e 's/_[^a-z][^A-Z][0-9.]*/@/'`"
  568.  
  569.   # maybe the underscore preceeds a version that starts with a letter
  570.   elif [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][0-9]\."`" != '' ];then
  571.     pkg_name_only="`echo "$pkg_name_only" | sed -e 's/_[a-zA-Z][0-9.]*/@/'`"
  572.   fi
  573.  
  574.   # now cut away everything after the @, that will leave only the package name
  575.   pkg_name_only1="${pkg_name_only/@*/}"
  576.   pkg_name_only="$pkg_name_only1"
  577.  
  578.   # we might still have foo_bar_v1.2.3, so lets chop off * after the last _
  579.   if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][0-9]\."`" != '' ];then
  580.     pkg_name_only="${pkg_name_only/_[a-zA-Z][0-9]*/}"
  581.   fi
  582.  
  583.   # another chop, we might have foo_bar_vv1.2.3, so lets chop off
  584.   # everything after the last underscore, if we still have version numbers
  585.   if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][a-zA-Z][0-9]\."`" != '' ];then
  586.     pkg_name_only="${pkg_name_only/_[a-zA-Z][a-zA-Z][0-9]*/}"
  587.   fi
  588.  
  589.   # we might still have foo_bar_vvv1.2.3, so lets chop off
  590.   # everything after the last underscore, if we still have version numbers
  591.   if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z*][0-9]\."`" != '' ];then
  592.     pkg_name_only="${pkg_name_only/_[a-zA-Z*][0-9]*/}"
  593.   fi
  594.  
  595.   # chop again, we might have abc_xwy-zzz1.2.3-blah-etc, so lets chop off
  596.   # everything after the last dash-before-number
  597.   if [ "`echo "$pkg_name_only" | grep -o "\-[a-zA-Z*]*[0-9]\."`" != '' ];then
  598.     pkg_name_only="${pkg_name_only/-[a-zA-Z*]*[0-9]*/}"
  599.   fi
  600.  
  601.   # another fix, if we still have PKGNAME-1.2, remove the '-1.2'
  602.   if [ "`echo "$pkg_name_only" | grep -o "\-[0-9]"`" != '' ];then
  603.     pkg_name_only="${pkg_name_only/-[0-9]*/}"
  604.   fi
  605.  
  606.   # the sed bit changes 'liblzma5+20120614' to 'liblzma5'
  607.   [ "$pkg_name_only" != '' ] && echo $pkg_name_only | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g' || return 1
  608. }
  609.  
  610.  
  611. get_pkg_name(){                   # return full pkg name (with version) from $1 FUNCLIST
  612.  
  613.   # get config settings, inc current repo file
  614.   #. ${PKGRC}
  615.  
  616.   local pkg_ext=''
  617.   local pkg_name=''
  618.   local full_name=''
  619.   local supported_repo_files=''
  620.   local repo_contents=''
  621.  
  622.   # get the extension of the given package name, if any
  623.   local pkg_ext=`get_pkg_ext "$1"`
  624.   # get the name without path and extension
  625.   local pkg_name="`basename "$1" .$pkg_ext`"
  626.  
  627.   # get the repos files in the correct (fall back) order, then add file paths
  628.  
  629.   #s243a: `repo_file_list` is called in mk_repo_file_list_arry
  630.   #supported_repo_files="`repo_file_list | sed -e "s#^#$PKGS_DIR/#g"`"
  631.  
  632.   # get the relevant repo contents (fields 1,2,8) from all repos,
  633.   # then add pipes to line start/end for easier parsing later, then do
  634.   # a basic search, for $pkg* (we'll refine it later), to avoid 'Argument list too long'..
  635.   #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
  636.   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
  637.   # get fields 1,2 and 8 (the 3 name fields) from all supported repo files, then
  638.   # add '|' to start and end of lines, then find exact match of $pkg_name..
  639.   # if no exact match, look for $pkg_name-*, then $pkg_name_*
  640.   if [ -f ${TMPDIR}repo_contents ];then
  641.     full_name=`cat ${TMPDIR}repo_contents 2>/dev/null| grep -m1 "|${pkg_name}|"` \
  642.       || full_name=`cat ${TMPDIR}repo_contents 2>/dev/null|grep -m1 "|${pkg_name//-*/}|"` \
  643.       || full_name=`cat ${TMPDIR}repo_contents 2>/dev/null|grep -m1 "|${pkg_name//_*/}|"` \
  644.       || full_name=`cat ${TMPDIR}repo_contents 2>/dev/null|grep -m1 "|${pkg_name}-"` \
  645.       || full_name=`cat ${TMPDIR}repo_contents 2>/dev/null|grep -m1 "|${pkg_name}_"` \
  646.       || full_name=`cat ${TMPDIR}repo_contents 2>/dev/null|grep -m1 "|${pkg_name}"` \
  647.       || full_name=`cat ${TMPDIR}repo_contents 2>/dev/null|grep -m1 "^${pkg_name}|"` \
  648.       || full_name=`cat ${TMPDIR}repo_contents 2>/dev/null|grep -m1 "^${pkg_name}-"` \
  649.       || full_name=`cat ${TMPDIR}repo_contents 2>/dev/null|grep -m1 "^${pkg_name}_"`
  650.  
  651.     rm ${TMPDIR}repo_contents &>/dev/null
  652.   fi
  653.  
  654.   # if we found pkg in repo, keep only the package name ('|pkg-123|pkg|blah|' -> 'pkg-123')
  655.   [ "$full_name" != '' ] && full_name=`echo $full_name| cut -f2 -d '|' | tr -d '|'` || full_name=$pkg_name
  656.  
  657.   # if we have a package name, return it here and leave the func
  658.   [ "$full_name" != '' ] && echo $full_name && return 0
  659.  
  660.   # if no pkg found in repos, we cant translate/lookup its longer name,
  661.   # so just return what we got, without path, without pkg extension
  662.   [ "$full_name" = '' ] && echo "`basename "$pkg_name" .$pkg_ext`"
  663. }
  664.  
  665.  
  666. is_blacklisted_pkg(){             # return true if PKGNAME ($1) is blacklisted FUNCLIST
  667.   # exit if no valid options
  668.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-installed && exit 1
  669.  
  670.   local EX=''
  671.   local PKGNAME=''
  672.   local PKGNAME_ONLY=''
  673.  
  674.   # get pkg extension
  675.   EX=`get_pkg_ext "$1"`
  676.  
  677.   # strip away extension and path
  678.   PKGNAME="$(basename "$1" .$EX)"
  679.   #PKGNAME=`get_pkg_name "$PKGNAME"`
  680.  
  681.   # get the package name without version
  682.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  683.  
  684.   [ "`echo "$PKG_NAME_IGNORE" | grep "$PKGNAME_ONLY "`" != '' ] && echo true || echo false
  685. }
  686.  
  687.  
  688. is_installed_pkg(){               # return true if PKGNAME ($1) is installed, else false FUNCLIST
  689.  
  690.   # exit if no valid options
  691.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-installed && exit 1
  692.  
  693.   local EX=''
  694.   local PKGNAME=''
  695.   local PKGNAME_ONLY=''
  696.   local check=''
  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.   # we cant rely on the strings the user passes us, so...
  706.  
  707.   # get the package name without version
  708.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  709.  
  710.   # exit if no valid package name
  711.   [ "$PKGNAME" = '' -o "$PKGNAME_ONLY" = '' ] && print_usage pkg-installed && exit 1
  712.  
  713.   # check the $PKGS_DIR/*.files
  714.   check="$(find "$PACKAGE_FILE_LIST_DIR" -name "$PKGNAME.files")"
  715.   [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'_*.files')"
  716.   [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'-*.files')"
  717.   [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'*.files')"
  718.  
  719.   # slow but reliable & simple: separately check fields 1,2,8 of the various files listing installed pkgs
  720.   [ "$check" = '' ] && check="`cut -f1 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME\$"`"
  721.   [ "$check" = '' ] && check="`cut -f1,2 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME|" | grep -m1 "|$PKGNAME_ONLY\$"`"
  722.   [ "$check" = '' ] && check="`cut -f8 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME"`"
  723.   [ "$check" = '' ] && check="`HIDE_BUILTINS=false list_installed_pkgs | grep -m1 ^"$PKGNAME"`"
  724.  
  725.   # if any checks above returned a result, $check will not be empty (ash didn't like grep -q, not sure why?)
  726.   [ "$check" != '' ] && echo true || echo false
  727. }
  728.  
  729.  
  730. is_builtin_pkg (){                # return true if $1 is a builtin pkg, else false FUNCLIST
  731.  
  732.   # if $1 is an exact match of a pkg short name,
  733.   # long name or file name in woof-installed-packages,
  734.   # we will return true, else we return false
  735.  
  736.   # exit if no valid input
  737.   [ ! "$1"  ] && exit 1
  738.  
  739.   local pkg_builtin=''
  740.   local pkg_name_only=''
  741.  
  742.   pkg_builtin="`cut -f1,2,8 -d '|' "$WOOF_INST_PKGS_FILE" 2>/dev/null\
  743.    | sed -e 's@^@|@' -e 's@$@|@' \
  744.    | grep -m1 "|$1|"`"
  745.  
  746.   # try again.. if user gave only partial name (geany-1.27), the above would fail
  747.   if [ "$pkg_builtin" = '' ];then
  748.     pkg_name_only=`get_pkg_name_only "$1"`
  749.  
  750.     # so search for pkg_name* AND pkg_name_only (exact match, should be in field 2)
  751.     if [ "$pkg_name_only" != '' ];then
  752.       pkg_builtin="`cut -f1,2,8 -d '|' "$WOOF_INST_PKGS_FILE" 2>/dev/null\
  753.        | sed -e 's@^@|@' -e 's@$@|@' \
  754.        | grep "|$1" \
  755.        | grep -m1 "|$pkg_name_only|"`"
  756.     fi
  757.   fi
  758.  
  759.   # print result
  760.   [ "$pkg_builtin" != '' ] && echo true || echo false
  761. }
  762.  
  763.  
  764. is_devx_pkg (){                   # return true if $1 is a pkg in the devx, else false FUNCLIST
  765.  
  766.   # if $1 is an exact match of a pkg short name,
  767.   # long name or file name in devx-only-installed-packages,
  768.   # we will return true, else we return false
  769.  
  770.   # exit if no valid input
  771.   [ ! "$1"  ] && exit 1
  772.  
  773.   local devx_pkg=''
  774.   local pkg_name_only=''
  775.  
  776.   devx_pkg="`cut -f1,2,8 -d '|' "$DEVX_INST_PKGS_FILE" 2>/dev/null\
  777.    | sed -e 's@^@|@' -e 's@$@|@' \
  778.    | grep -m1 "|$1|"`"
  779.  
  780.   # try again.. if user gave only partial name (geany-1.27), the above would fail
  781.   if [ "$devx_pkg" = '' ];then
  782.     pkg_name_only=`get_pkg_name_only "$1"`
  783.  
  784.     # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  785.     if [ "$pkg_name_only" != '' ];then
  786.       devx_pkg="`cut -f1,2,8 -d '|' "$DEVX_INST_PKGS_FILE" 2>/dev/null\
  787.        | sed -e 's@^@|@' -e 's@$@|@' \
  788.        | grep "|$1" \
  789.        | grep -m1 "|$pkg_name_only|"`"
  790.     fi
  791.   fi
  792.  
  793.   # print result
  794.   [ "$devx_pkg" != '' ] && echo true || echo false
  795. }
  796.  
  797.  
  798. is_usr_pkg (){                    # return true if $1 is a user installed pkg, else false FUNCLIST
  799.  
  800.   # if $1 is an exact match of a pkg short name,
  801.   # long name or file name in user-installed-packages,
  802.   # we will return true, else we return false
  803.  
  804.   # exit if no valid input
  805.   [ ! "$1"  ] && exit 1
  806.  
  807.   local usr_pkg=''
  808.   local pkg_name_only=''
  809.  
  810.   usr_pkg="`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" 2>/dev/null\
  811.    | sed -e 's@^@|@' -e 's@$@|@' \
  812.    | grep -m1 "|$1|"`"
  813.  
  814.   # try again.. if user gave only partial name (geany-1.27), the above would fail
  815.   if [ "$usr_pkg" = '' ];then
  816.     pkg_name_only=`get_pkg_name_only "$1"`
  817.  
  818.     # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  819.     if [ "$pkg_name_only" != '' ];then
  820.       usr_pkg="`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" 2>/dev/null\
  821.        | sed -e 's@^@|@' -e 's@$@|@' \
  822.        | grep "|$1" \
  823.        | grep -m1 "|$pkg_name_only|"`"
  824.     fi
  825.   fi
  826.  
  827.   # print result
  828.   [ "$usr_pkg" != '' ] && echo true || echo false
  829. }
  830.  
  831.  
  832. is_repo_pkg (){                   # return true if $1 is a pkg in a supported repo, else false FUNCLIST
  833.  
  834.   # if $1 is an exact match of a pkg short name,
  835.   # long name or file name in Packages-*-
  836.   # we will return true, else we return false
  837.  
  838.   # exit if no valid input
  839.   [ ! "$1"  ] && exit 1
  840.  
  841.   local repo_pkg=''
  842.   local pkg_name_only=''
  843.   local all_supported_repofiles
  844.  
  845.   # all repo files, full paths
  846.   #all_supported_repofiles=`repo_file_list | sed "s#^#$PKGS_DIR/#" | tr '\n' ' '`
  847.  
  848.   #Don't need sed, but could use if you want to do wildcards
  849.   #all_supported_repofiles=`repo_file_list | sed 's#$#*#' | xargs find -name  | tr '\n' ' '`
  850.   #echo "repo_file_list | xargs find \"$PKGS_DIR\" -name  | tr '\n' ' '"
  851.   all_supported_repofiles="$(repo_file_list | while read a; do find "$REPO_DB_FILE_DIR" -name "$a"'*'; done  | tr '\n' ' ')"
  852.   # search all repo files for the $1
  853.   repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  854.    | sed -e 's/ //g' -e 's@^@|@' -e 's@$@|@' \
  855.    | grep -m1 "|${1}|"`"
  856.  
  857.   # search all repo files for the $1*
  858.   [ "$repo_pkg" = '' ] \
  859.     && repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  860.    | sed -e 's/ //g' -e 's@^@|@' -e 's@$@|@' \
  861.    | grep -m1 "|${1}-\?_\?[0-9.a-zA-Z]*|"`"
  862.  
  863.   # try again.. if user gave only partial name (geany-1.27), the above would fail
  864.   if [ "$repo_pkg" = '' ];then
  865.     pkg_name_only=`get_pkg_name_only "$1"`
  866.  
  867.     # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  868.     if [ "$pkg_name_only" != '' ];then
  869.       repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  870.        | sed -e 's@^@|@' -e 's@$@|@' \
  871.        | grep "|$1" \
  872.        | grep -m1 "|$pkg_name_only|"`"
  873.     fi
  874.   fi
  875.  
  876.   # print result
  877.   [ "$repo_pkg" != '' ] && echo true || echo false
  878. }
  879.  
  880.  
  881. is_current_repo_pkg(){            # takes $PKGNAME ($1), returns true or false FUNCLIST
  882.  
  883.   # exit if no valid input
  884.   [ ! "$1"  ] && exit 1
  885.  
  886.   # get current repo ($REPOFILE)
  887.   . ${PKGRC}
  888.  
  889.   local pkg_in_repo
  890.   #s243a: The repo file path
  891.   local RF_PATH="$(realpath "$(find "$REPO_DB_FILE_DIR" -name "$REPOFILE" | head -n 1 )")"
  892.  # check if given pkg ($1) is in the current repo
  893.  pkg_in_repo="`LANG=C cut -f1,2,7,8 -d'|' "$RF_PATH" 2>/dev/null | sed -e "s/^/|/" -e "s/$/|/" | grep -m1 "|${1}|"`"
  894.  
  895.  # print msg
  896.  [ "$pkg_in_repo" != '' ] && echo true || echo false
  897. }
  898.  
  899.  
  900. is_local_pkg(){                   # returns true if $1 is local package file FUNCLIST
  901.  
  902.  # exit if no valid input
  903.  [ ! "$1"  ] && exit 1
  904.  
  905.  . ${PKGRC}
  906.  
  907.  # if $1 is a local file with a supported package extension
  908.  # then we return true, else, we return false
  909.  
  910.  local is_file=''
  911.  local is_local_pkg=false
  912.  
  913.  # first, check we have a local file
  914.  if [ -f "$1" ];then
  915.  
  916.    # file *probably* has an extension, lets try to get it..
  917.    # the func get_pkg_ext() will return empty if not a valid package extension
  918.    file_ext=`get_pkg_ext "$1"`
  919.  
  920.    # if not empty, it must be a local file, with valid pkg ext (a local pkg)
  921.    [ "$file_ext" != '' ] && is_local_pkg=true
  922.  
  923.  elif [ -f "$CURDIR/$1" ];then
  924.  
  925.    file_ext=`get_pkg_ext "$CURDIR/$1"`
  926.    [ "$file_ext" != '' ] && is_local_pkg=true
  927.  
  928.  elif [ -f "$WORKDIR/$1" ];then
  929.  
  930.    file_ext=`get_pkg_ext "$CURDIR/$1"`
  931.    [ "$file_ext" != '' ] && is_local_pkg=true
  932.  
  933.  fi
  934.  
  935.  # print output
  936.  echo $is_local_pkg
  937. }
  938.  
  939.  
  940.  
  941. # RC file funcs
  942.  
  943. set_workdir(){                    # set new WORKDIR in rc file location FUNCLIST
  944.  
  945.  # get latest rc file values
  946.  . ${PKGRC}
  947.  
  948.  # make sure $1 was given and doesn't already exist
  949.  [ ! "$1"  ] && print_usage workdir && exit 1
  950.  [ -e "$1" ] && echo "Error: directory already exists. Choose a new one." && exit 1
  951.  
  952.  # create the dir
  953.  mkdir -p "$1" 2>/dev/null
  954.  
  955.  # if dir not created, exit with error
  956.  [ $? -eq 1  ] && echo "Error: Could not create $1" && exit 1
  957.  [ ! -d "$1" ] && echo "Error: Could not create directory:  $1" && exit 1
  958.  
  959.  # dir was created, so lets copy our pkgs in there
  960.  list_downloaded_pkgs | while read pkg_file
  961.  do
  962.    cp -v "$WORKDIR/$pkg_name" "$1/"
  963.  done
  964.  
  965.  # if copying everything to new dir failed
  966.  if [ $? -eq 1 ];then
  967.    # print msg
  968.    echo -e "${yellow}Warning:${endcolour}Could not copy packages from $WORKDIR to $1.."
  969.    echo "You should copy all packages in $WORKDIR into $1."
  970.  fi
  971.  
  972.  # update the RC file
  973.  WORKDIR="$1"
  974.  set_config
  975.  echo "Success. Work directory updated."
  976.  exit 0
  977. }
  978.  
  979.  
  980. set_pkg_scope(){                  # one|all set search for pkgs in current repo or all FUNCLIST
  981.  
  982.  # get old values, any we dont set here are not overwritten
  983.  . ${PKGRC}
  984.  
  985.  [ "$1" != "" ] && PKGSCOPE="$1" || PKGSCOPE="$PKGSCOPE"
  986.  
  987.  case "$1" in
  988.    all)
  989.    # set pkg search to all
  990.    PKGSEARCH="list_all_pkg_names"
  991.    PKGSEARCHEXACT="$SELF -nea"
  992.    echo -e "${green}Success:${endcolour} Find packages in all repos."
  993.    ;;
  994.    one)
  995.    # set pkg search to current only
  996.    PKGSEARCH="list_pkg_names"
  997.    PKGSEARCHEXACT="$SELF -ne"
  998.    echo -e "${green}Success:${endcolour} Find packages in current repo ($REPONAME) only."
  999.    ;;
  1000.    *)
  1001.    PKGSCOPE="one"
  1002.    # set pkg search to current only
  1003.    PKGSEARCH="list_pkg_names"
  1004.    PKGSEARCHEXACT="$SELF -ne"
  1005.    echo "Find packages in current repo ($REPONAME) only."
  1006.    ;;
  1007.  esac
  1008.  
  1009.  set_config #170213
  1010. }
  1011.  
  1012.  
  1013. set_dep_scope(){                  # all|one set search for deps in current repo or all FUNCLIST
  1014.  
  1015.   # get RC file values, so any we dont set here are not overwritten
  1016.   . ${PKGRC}
  1017.  
  1018.  # make sure we have a valid value
  1019.  [ "$1" != "" ] && DEPSCOPE="$1" || DEPSCOPE="$DEPSCOPE"
  1020.  
  1021.  case "$1" in
  1022.    all)
  1023.    # set pkg search to all
  1024.    DEPSEARCH="list_all_pkg_names"
  1025.    DEPSEARCHEXACT="$SELF -nea"
  1026.    echo -e "${green}Success:${endcolour} Find dependencies in all repos."
  1027.    ;;
  1028.    one)
  1029.    # set pkg search to one
  1030.    DEPSEARCH="list_pkg_names"
  1031.    DEPSEARCHEXACT="$SELF -ne"
  1032.    echo -e "${green}Success:${endcolour} Find dependencies in current repo ($REPONAME) only."
  1033.    ;;
  1034.  esac
  1035.  
  1036.  set_config
  1037. }
  1038.  
  1039.  
  1040. set_recursive_deps(){             # yes|no search for deps of deps or not FUNCLIST
  1041.  [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && print_usage recursive-dep-check && exit 1
  1042.  
  1043.  # get old values, any we dont set here are not overwritten
  1044.  . ${PKGRC}
  1045.  
  1046.  # make sure we have a valid value
  1047.  RDCHECK="$1"
  1048.  [ "$RDCHECK" = "yes" -o "$RDCHECK" = "no" ] || RDCHECK=no
  1049.  
  1050.  set_config
  1051.  
  1052.  # print final msg
  1053.  if [ "$1" = "yes" ];then
  1054.    echo -e "${green}Success:${endcolour} 'Recursive dependency checking' enabled."
  1055.  else
  1056.    echo -e "${green}Success:${endcolour} 'Recursive dependency checking' disabled"
  1057.  fi
  1058. }
  1059.  
  1060.  
  1061. set_bleeding_edge(){              # yes|no get latest pkgs, ignore fall backs FUNCLIST
  1062.  [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && echo usage bleeding-edge && exit 1
  1063.  
  1064.  #get old values, any we dont set here are not overwritten
  1065.  . ${PKGRC}
  1066.  
  1067.  # make sure we have a valid value
  1068.  BLEDGE="$1"
  1069.  [ "$BLEDGE" = "yes" -o "$BLEDGE" = "no" ] || BLEDGE=no
  1070.  
  1071.  set_config
  1072.  
  1073.  # print final msg
  1074.  if [ "$1" = "yes" ];then
  1075.    echo -e "${green}Success:${endcolour} 'Bleeding edge' package search enabled."
  1076.  else
  1077.    echo -e "${green}Success:${endcolour} 'Bleeding edge' package search disabled."
  1078.  fi
  1079. }
  1080.  
  1081.  
  1082. set_autoclean(){                  # yes|no auto delete installed packages from WORKDIR FUNCLIST
  1083.  [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && print_usage autoclean && exit 1
  1084.  
  1085.  #get old values, any we dont set here are not overwritten
  1086.  . ${PKGRC}
  1087.  
  1088.  # make sure we have a valid value
  1089.  AUTOCLEAN="$1"
  1090.  [ "$AUTOCLEAN" = "yes" -o "$AUTOCLEAN" = "no" ] || AUTOCLEAN=no
  1091.  
  1092.  set_config
  1093.  
  1094.  # print final msg
  1095.  if [ "$1" = "yes" ];then
  1096.    echo -e "${green}Success:${endcolour} Auto-remove installed packages ENABLED."
  1097.  else
  1098.    echo -e "${green}Success:${endcolour} Auto-remove installed packages DISABLED."
  1099.  fi
  1100. }
  1101.  
  1102.  
  1103. set_config(){                     # update all options in config file FUNCLIST
  1104.  echo "WORKDIR=$WORKDIR"                    > ${PKGRC}
  1105.  echo "REPONAME=$REPONAME"                 >> ${PKGRC}
  1106.  echo "EX=$EX"                             >> ${PKGRC}
  1107.  echo "REPOFILE=$REPOFILE"                 >> ${PKGRC}
  1108.  echo "REPOURL1=$REPOURL1"                 >> ${PKGRC}
  1109.  echo "REPOURL2=$REPOURL2"                 >> ${PKGRC}
  1110.  #140213 add all urls
  1111.  echo "REPOURL3=$REPOURL3"                 >> ${PKGRC}
  1112.  echo "REPOURL4=$REPOURL4"                 >> ${PKGRC}
  1113.  # seach settings
  1114.  echo "PKGSEARCH=\"$PKGSEARCH\""           >> ${PKGRC}
  1115.  echo "PKGSEARCHEXACT=\"$PKGSEARCHEXACT\"" >> ${PKGRC}
  1116.  echo "DEPSEARCH=\"$DEPSEARCH\""           >> ${PKGRC}
  1117.  echo "DEPSEARCHEXACT=\"$DEPSEARCHEXACT\"" >> ${PKGRC}
  1118.  # multiple repo settings
  1119.  echo "REPOFALLBACKS=\"$REPOFALLBACKS\""   >> ${PKGRC}
  1120.  echo "PKGSCOPE=\"$PKGSCOPE\""             >> ${PKGRC}
  1121.  echo "DEPSCOPE=\"$DEPSCOPE\""             >> ${PKGRC}
  1122.  echo "BLEDGE=\"$BLEDGE\""                 >> ${PKGRC}
  1123.  echo "RDCHECK=\"$RDCHECK\""               >> ${PKGRC} #150813
  1124.  echo "AUTOCLEAN=\"$AUTOCLEAN\""           >> ${PKGRC}
  1125.  echo "BUILDTOOL=$BUILDTOOL"               >> ${PKGRC}
  1126. }
  1127.  
  1128.  
  1129. show_config(){                    # show config settings from ~/.pkg/pkgrc FUNCLIST
  1130.  . ${PKGRC}
  1131.  
  1132.  # set default values
  1133.  PKGSCOPETXT="Search for packages in all repos."
  1134.  DEPSCOPETXT="Search for dependencies in all repos."
  1135.  FALLBACKTXT="Accessing other repos in this order:"
  1136.  FALLBACKTXT="$FALLBACKTXT\n`repo_list | grep -v "^$REPONAME" | tr '\n' ' ' | sed -e "s/ /, /g" -e "s/, $//" | fold -w 54 -s`"
  1137.  RDCHECKTXT="Recursive dependency search is NOT enabled."
  1138.  
  1139.  # update with values from PKGRC file
  1140.  [ "$PKGSCOPE" = "one" ] && PKGSCOPETXT="Search for packages in current repo only."
  1141.  [ "$DEPSCOPE" = "one" ] && DEPSCOPETXT="Search for dependencies in current repo only."
  1142.  [ "$BLEDGE"   = "yes" ] && FALLBACKTXT="Bleeding-edge enabled - searching all repos, for the latest packages versions.."
  1143.  [ "$RDCHECK"  = "yes" ] && RDCHECKTXT="Recursive dependency search is enabled."
  1144.  
  1145.  # print current Pkg config
  1146.  echo "==========================="
  1147.  echo "$APPNAME $APPVER"
  1148.  echo "==========================="
  1149.  echo "Config file:  $PKGRC"
  1150.  echo "Packages dir: ${WORKDIR}/"
  1151.  echo "Autoclean:    $AUTOCLEAN"
  1152.  echo
  1153.  echo "Search settings:"
  1154.  #echo "- $HIDEINSTALLEDTXT"
  1155.  echo "- $PKGSCOPETXT"
  1156.  echo "- $DEPSCOPETXT"
  1157.  echo "- $RDCHECKTXT"
  1158.  echo
  1159.  echo "Package Compiling backend:"
  1160.  echo "- $BUILDTOOL"
  1161.  echo
  1162.  echo "Repo details:"
  1163.  echo "- Current Repo: $REPONAME"
  1164.  echo "- Package type: $EX"
  1165.  echo "- Packages:     $(cat "$REPO_DB_FILE_DIR/${REPOFILE}" | wc -l)"
  1166.  echo "- Mirror 1:     `echo $REPOURL1 | cut -f1-3 -d'/' `"
  1167.  [ "$REPOURL2" != "" ] && echo "- Mirror 2:     `echo $REPOURL2 | cut -f1-3 -d'/' `"
  1168.  [ "$REPOURL3" != "" ] && echo "- Mirror 3:     `echo $REPOURL3 | cut -f1-3 -d'/' `"
  1169.  [ "$REPOURL4" != "" ] && echo "- Mirror 4:     `echo $REPOURL4 | cut -f1-3 -d'/' `"
  1170.  echo
  1171.  echo -e "$FALLBACKTXT"
  1172. }
  1173.  
  1174.  
  1175. # repo and source funcs
  1176.  
  1177. get_repo_info(){                  # return details of given repo name ($1) FUNCLIST
  1178.  [ ! "$1" -o "$1" = "-" ] && print_usage repo-info && exit 1
  1179.  
  1180.  REPOLINE="`list_all_sources $1 | sort -u | uniq`" #170214 always get latest info, not info from rcfile
  1181.  
  1182.  # on first run, this might be needed to set the repo correctly
  1183.  [ "$REPOLINE" = '' ] && REPOLINE="`list_all_sources noarch`"
  1184.  
  1185.  REPONAME="`echo $REPOLINE | cut -f1 -d'|'`"
  1186.        EX="`echo $REPOLINE | cut -f2 -d'|'`"
  1187.  REPOFILE="`echo $REPOLINE | cut -f3 -d'|'`"
  1188.  REPOURL1="`echo $REPOLINE | cut -f4 -d'|'`"
  1189.  REPOURL2="`echo $REPOLINE | cut -f5 -d'|'`"
  1190.  REPOURL3="`echo $REPOLINE | cut -f6 -d'|'`"
  1191.  REPOURL4="`echo $REPOLINE | cut -f7 -d'|'`"
  1192.  REPOFALLBACKS="`echo "$REPOLINE"| cut -f8 -d'|'`"
  1193. }
  1194.  
  1195.  
  1196. set_current_repo(){               # set the current repo to use, give repo name as $1 FUNCLIST
  1197.  
  1198.  # print usage if no valid options
  1199.  [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ] && print_usage repo && exit 1
  1200.  
  1201.  # get repo details from rc file
  1202.  . ${PKGRC}
  1203.  
  1204.  # remove the default mirror tmp file, we're changing repo and mirrors
  1205.  rm $TMPDIR/CURREPOURL 2>/dev/null
  1206.  
  1207.  # remove old repo files list (used in list_source_files)
  1208.  rm -f ${TMPDIR}source_files 2>/dev/null
  1209.  
  1210.  # if not updating the scopes or bleeding-edge,leave them as set in rcfile
  1211.  [ "$PKGSCOPE" = "" ] && PKGSCOPE="$PKGSCOPE"
  1212.  [ "$DEPSCOPE" = "" ] && DEPSCOPE="$DEPSCOPE"
  1213.  [ "$BLEDGE" = "" ]   && BLEDGE="$BLEDGE"
  1214.  
  1215.  # if nothing was found in rcfile, we need to set to default
  1216.  [ "`echo $PKGSCOPE | grep -E "^one\$|^all\$"`" = "" ] && PKGSCOPE="one"
  1217.  [ "`echo $DEPSCOPE | grep -E "^one\$|^all\$"`" = "" ] && DEPSCOPE="one"
  1218.  [ "$BLEDGE" = "" ] && BLEDGE="no"
  1219.  
  1220.  # check if $1 is valid repo
  1221.  if [ "$(LANG=C list_sources "$1")" != "" ];then
  1222.    # set repo details
  1223.    LANG=C get_repo_info "$1"
  1224.    LANG=C set_config #170213
  1225.    LANG=C update_sources 1>/dev/null #update the order of sources to match new fallback list of new current repo
  1226.    LANG=C print_repo_info "$1" #output msg, repo info
  1227.  else
  1228.    # not a valid repo, print message
  1229.    echo "The name '$1' is not a valid repo name. These are:"
  1230.    LANG=C repo_list #250613
  1231.  fi
  1232. }
  1233.  
  1234.  
  1235. repo_list(){                      # list names of all avail repos [optionally matching $1] FUNCLIST
  1236.  
  1237.  # we need to list these repos in the order defined in the RC file
  1238.  # so Pkg can 'fall back' to other repos in that order
  1239.  
  1240.  # get current config
  1241.  . ${PKGRC}
  1242.  
  1243.  # set vars for this func
  1244.  local list=''
  1245.  local repo_file=''
  1246.  local repo_names=`cut -f1 -d'|' ${HOME}/.pkg/sources`
  1247.  local current_fallback_list=`grep "^$REPONAME|" ${HOME}/.pkg/sources | cut -f8 -d'|' | grep -v "^\$"`
  1248.  
  1249.  # get current repo fallback list order.. note if repo not listed in fallback list, it will be appended after
  1250.  for line in $current_fallback_list
  1251.  do
  1252.    # get the repo file
  1253.    repo_file="`grep "^$line|" ${HOME}/.pkg/sources | cut -f3 -d'|'`"
  1254.    # add it to the list
  1255.    [ "$repo_file" != "" ] && list="$list$line "
  1256.  done
  1257.  
  1258.  # now add all other avail repos to the end of fallback list
  1259.  for repo_name in $repo_names
  1260.  do
  1261.    #if not blank, not already in the repo list and not the current repo ($REPONAME from rc file) then add to list
  1262.    [ "$repo_name" != "" -a "`echo "$list" | grep "$repo_name "`" = ""  -a "$repo_name" != "$REPONAME" ] && list="$list$repo_name "
  1263.  done
  1264.  
  1265.  # list the current repo first
  1266.  echo $REPONAME
  1267.  # then the other repos
  1268.  echo "$list" | tr ' ' '\n' | grep -v "^\$"
  1269. }
  1270.  
  1271.  
  1272. repo_file_list(){                 # list available repo files, $1 optional FUNCLIST
  1273.  
  1274.  # we need to list these repos in the order defined in the RC file
  1275.  # so Pkg can 'fall back' to other repos in that order
  1276.  
  1277.  # get current config
  1278.  . ${PKGRC}
  1279.  
  1280.  # set vars for this func
  1281.  local list=''
  1282.  local repo_file=''
  1283.  local repo_files=`cut -f3 -d'|' ${HOME}/.pkg/sources`
  1284.  local current_fallback_list=`grep "^$REPONAME|" ${HOME}/.pkg/sources | cut -f8 -d'|' | grep -v "^\$"`
  1285.  
  1286.  # get current repo fallback list order.. note if repo not listed in fallback list, it will be appended after
  1287.  for line in $current_fallback_list
  1288.  do
  1289.    # get the repo file
  1290.    repo_file="`grep "^$line|" ${HOME}/.pkg/sources | cut -f3 -d'|'`"
  1291.    # add it to the list
  1292.    [ "$repo_file" != "" ] && list="$list$repo_file "
  1293.  done
  1294.  
  1295.  # now add all other avail repos to the end of fallback list
  1296.  for repo_file in $repo_files
  1297.  do
  1298.    #if not blank, not already in the repo list and not the current repo ($REPONAME from rc file) then add to list
  1299.    [ "$repo_file" != "" -a "`echo "$list" | grep "$repo_file "`" = ""  -a "$repo_file" != "$REPOFILE" ] && list="$list$repo_file "
  1300.  done
  1301.  
  1302.  # list the current repo first
  1303.  echo $REPOFILE
  1304.  # then the other repos
  1305.  echo "$list" | tr ' ' '\n' | grep -v "^\$"
  1306. }
  1307. declare -ga REPO_DB_PATHS
  1308. #mk_repo_file_list_arry(){
  1309.  
  1310.  #REPO_DB_PATHS=()
  1311.  #declare -A REPO_DB_PATHS
  1312.  
  1313. #Can't put the loop in the loop in a pipeline if you want to assign array values:
  1314. #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  1315. # repo_file_list |
  1316. while read REPO_FILE_NAME; do
  1317.    #echo "REPO_FILE_NAME=$REPO_FILE_NAME"
  1318.    RF_FILE_PATH="${ALL_REPO_DB_PATHS[$REPO_FILE_NAME]}"
  1319.    if [ -e "$RF_FILE_PATH" ]; then
  1320.      REPO_DB_PATHS+=( "$RF_FILE_PATH" )
  1321.    fi
  1322. done < <( repo_file_list )
  1323. #echo "REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  1324. #echo "REPO_DB_PATHS_keys=${!ALL_REPO_DB_PATHS[@]}"  
  1325. #}
  1326. #mk_repo_file_list_arry
  1327.  
  1328. dir2repo(){                       # create a native-Puppy repo from a dir of packages FUNCLIST
  1329.  
  1330.  # exit if not a valid directory
  1331.  if [ ! -d "$1" ];then
  1332.    print_usage dir2repo && exit 1
  1333.  fi
  1334.  
  1335.  local filename=''
  1336.  local filepath=''
  1337.  local fileext=''
  1338.  local prevext=''
  1339.  local repo_name
  1340.  
  1341.  # get the repo directory
  1342.  local repo_dir="$(realpath "$1")"
  1343.  
  1344.  # create a temp repo_file name
  1345.  local repo_file="${repo_dir}/Packages-$DISTRO_BINARY_COMPAT-$DISTRO_COMPAT_VERSION"
  1346.  
  1347.  # remove any old files
  1348.  rm "${repo_dir}/install" "${repo_dir}/Packages-"* "$repo_file" &>/dev/null
  1349.  
  1350.  echo
  1351.  echo "Creating repo from contents of: $repo_dir"
  1352.  echo
  1353.  
  1354.  # exit if we encounter multiple file extensions
  1355.  for file in $(find "$repo_dir" -maxdepth 5 -type f)
  1356.  do
  1357.    filename=$(basename $file)
  1358.    fileext="$(get_pkg_ext $filename)"
  1359.    if [ "$fileext" != "$prevext" ] && [ "$prevext" != "" ];then
  1360.      echo "All packages must have the same extension."
  1361.      echo "Extensions '$fileext' and '$prevext' don't match."
  1362.      echo "Package '$filename' needs to be converted to $prevext or removed."
  1363.      exit 1
  1364.    fi
  1365.    prevext="$fileext"
  1366.  done
  1367.  
  1368.  
  1369.  # get the packages in $repo_dir
  1370.  local package_list="$(find "$repo_dir" -maxdepth 5 -type f | grep -v ^Packages | grep -v "^install$")"
  1371.  
  1372.  if [ "$package_list" = "" ];then
  1373.    echo "No packages found in ${repo_dir}!"
  1374.    exit 1
  1375.  fi
  1376.  
  1377.  # for each file in the repo dir
  1378.  for file in $package_list
  1379.  do
  1380.    # skip if not a recognised package type
  1381.    [ "$(is_local_pkg "$file")" != true ] && continue
  1382.  
  1383.    # get the package info
  1384.    filename=$(basename $file)
  1385.    fileext="$(get_pkg_ext $filename)"
  1386.    filepath="$(realpath $(dirname $file))"
  1387.    pathname="$(dirname ${filepath})"
  1388.    repopath="$(echo $filepath | sed -e "s#${repo_dir}##" -e "s/^\///")"
  1389.    pkgname=$(basename $filename .$fileext)
  1390.    pkgnameonly="$(get_pkg_name_only $pkgname)"
  1391.    pkgversion="$(get_pkg_version $pkgname)"
  1392.    pkgcat="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f5 -d'|')"
  1393.    pkgsize="$(du "$file" 2>/dev/null | cut -f1)K"
  1394.    [ "$pkgsize" = "" ] && pkgsize="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f6 -d'|')"
  1395.    pkgdeps="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f9 -d'|')"
  1396.    # dont include deps if we're adding a combined package + plus deps (they have $CP_SUFFIX in the name)
  1397.     [ "$(echo "$filename" | grep "$CP_SUFFIX")" != "" ] && pkgdeps=''
  1398.     pkgdesc="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f10 -d'|')"
  1399.     pkgdistro="$DISTRO_BINARY_COMPAT"
  1400.     pkgdistroversion="$DISTRO_COMPAT_VERSION"
  1401.  
  1402.     # if we don't have the required package info, dont add it to the repo file
  1403.     [ "$pkgname" = "" -o "$pkgnameonly" = "" -o "$filename" = "" ] && continue
  1404.  
  1405.     # add this package to the repo file
  1406.     echo "$pkgname|$pkgnameonly|$pkgversion||${pkgcat:-BuildingBlock}|$pkgsize|$repopath|$filename|$pkgdeps|${pkgdesc:-No description}|$pkgdistro|$pkgdistroversion|" >> "$repo_file"
  1407.   done
  1408.  
  1409.   if [ ! -f "$repo_file" ];then
  1410.     echo "Error: file '$repo_file' not created."
  1411.     exit 1
  1412.   fi
  1413.  
  1414.   echo "Step 1 of 3: CHOOSE A REPO NAME"
  1415.   echo "(something like 'distroversion-username-repo', such as 'bionic-bob-main' or 'stretch-sc0ttman-games')"
  1416.   echo
  1417.   bash -c 'read -e -r -p "Type a repo name and hit ENTER: " repo_name; echo "$repo_name" > /tmp/pkg/repo_name'
  1418.   repo_name="$(cat /tmp/pkg/repo_name)"
  1419.  
  1420.   # rename the repo file to the new name
  1421.   mv "$repo_file"   "${repo_dir}/Packages-${DISTRO_BINARY_COMPAT:-puppy}-$repo_name"
  1422.   repo_file="${repo_dir}/Packages-${DISTRO_BINARY_COMPAT:-puppy}-$repo_name"
  1423.  
  1424.   # build repo entry
  1425.   local repo_entry="$repo_name|$fileext|$repo_file|$repo_url||||$repo_fallbacks"
  1426.  
  1427.   # get the URL where the repo file and packages will live
  1428.   echo
  1429.   echo "Step 2 of 3: ADD THE REPO URL"
  1430.   echo "(the full URL where you will upload your repo file and packages)"
  1431.   echo
  1432.   bash -c 'read -e -r -i "http://" -p "Type a repo URL and hit ENTER: " mirror1; echo "$mirror1" > /tmp/pkg/mirror1'
  1433.   mirror1="$(cat /tmp/pkg/mirror1)"
  1434.  
  1435.   # get fallback repos list
  1436.   echo
  1437.   echo "Step 3 of 3: ADD FALLBACK REPOS"
  1438.   echo "(the other repos to fall back to when looking for dependencies)"
  1439.   echo
  1440.   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'
  1441.   fallback_repos="$(cat /tmp/pkg/fallback_repos)"
  1442.  
  1443.   # remove the tmp files which store user input, they're no longer needed
  1444.   rm /tmp/pkg/repo_name /tmp/pkg/mirror1 /tmp/pkg/fallback_repos
  1445.  
  1446.   # add a trailing slash to the URL
  1447.   if [ "$(echo "${mirror1}" | grep "/$")" = "" ];then
  1448.     mirror1="${mirror1}/"
  1449.   fi
  1450.  
  1451.   # create repo installer file in $repo_dir
  1452.   echo "REPONAME=$repo_name
  1453. EX=$fileext
  1454. REPOFILE=$(basename $repo_file)
  1455. URL1=${mirror1}
  1456. URL2=''
  1457. URL3=''
  1458. URL4=''
  1459. FALLBACKS='$fallback_repos'" > "${repo_dir}/install"
  1460.  
  1461.   # print final message
  1462.   echo
  1463.   echo -e "${green}Success${endcolour}: Repo ${yellow}$repo_name${endcolour} created."
  1464.   echo
  1465.   echo -e "You should upload everything in ${lightblue}$repo_dir${endcolour} to:"
  1466.   echo
  1467.   echo "  $mirror1"
  1468.   echo
  1469.   echo "You (and anyone else) can then install the repo using:"
  1470.   echo
  1471.   echo "  pkg add-repo ${mirror1}"
  1472.   echo
  1473.   echo -e "NOTE: You can edit the ${yellow}install${endcolour} and ${yellow}$(basename $repo_file)${endcolour}"
  1474.   echo "files in a text editor, before you upload your new repo."
  1475.   echo
  1476. }
  1477.  
  1478.  
  1479. add_pkg_repo() {                  # add a Pkg-created repo, called by add_repo() FUNCLIST
  1480.   [ ! "$1" ] && return 1
  1481.   mkdir -p /tmp/pkg/
  1482.   # this is probably a Pkg created Puppy repo, get info from 'install' file
  1483.   rm /tmp/pkg/repo_info &>/dev/null
  1484.  
  1485.   # check if the 'install' file we need exists
  1486.   wget --no-check-certificate -O "/tmp/pkg/repo_info" -4 "$1" &>/dev/null
  1487.   if [ ! -f /tmp/pkg/repo_info ];then
  1488.     echo "Error: Repo installer file not downloaded!"
  1489.     return 1
  1490.   elif [ "$(grep -m1 "^REPONAME" /tmp/pkg/repo_info 2>/dev/null)" = "" ];then
  1491.     echo "Error: invalid repo installer file"
  1492.     return 1
  1493.   fi
  1494.  
  1495.   # build a valid repo entry for the ~/.pkg/sources* files
  1496.   # (must have some fallbacks, strip quotes, newlines, no trailing pipes)
  1497.   local repo_entry="$(cat /tmp/pkg/repo_info \
  1498.    | sed -e "s/FALLBACKS=''/FALLBACKS='noarch common32'/" -e 's/.*=//g' \
  1499.    | tr -d '"' \
  1500.    | tr -d "'" \
  1501.    | tr '\n' '|' \
  1502.    | head -c -1)"
  1503.  
  1504.   if [ "$repo_entry" = "" ];then
  1505.     echo "Error: repo entry not created."
  1506.     return 1
  1507.   fi
  1508.  
  1509.   # get repo info
  1510.   local repo_name="$(echo "$repo_entry" | cut -f1 -d'|')"
  1511.   local repo_filename="$(echo "$repo_entry" | cut -f3 -d'|')"
  1512.   local repo_file_url="$(echo ${1} | sed 's#/install$##')/${repo_filename}"
  1513.  
  1514.   # download the repo file
  1515.   wget --no-check-certificate -O "/tmp/pkg/$repo_filename" -4 "$repo_file_url" &>/dev/null
  1516.   if [ -z /tmp/pkg/$repo_filename ] || [ ! -f /tmp/pkg/$repo_filename ];then
  1517.     echo "Error: Repo file $repo_filename not downloaded!"
  1518.     return 1
  1519.   fi
  1520.  
  1521.   # install the repo file
  1522.   mv /tmp/pkg/$repo_filename "$REPO_DB_FILE_DIR/$repo_filename"
  1523.   RETVAL=$?
  1524.  
  1525.   # add repo entry to ~/.pkg/sources
  1526.   echo
  1527.   add_source "${repo_entry}"
  1528.   echo
  1529.  
  1530.   # refresh list of available repos
  1531.   update_sources
  1532.   echo
  1533.   echo "Repo info:"
  1534.   print_repo_info $repo_name
  1535.   echo
  1536.  
  1537.   if [ "$(cat ~/.pkg/sources 2>/dev/null | grep -m1 "^$repo_name|")" != "" ];then
  1538.     echo "Success! Repo added and available to use."
  1539.     echo
  1540.     echo "To use this repo, simply type the following and hit ENTER:"
  1541.     echo "  pkg repo $repo_name"
  1542.     echo
  1543.  
  1544.     # register as a user installed repo, so we can remove it later (using rm_repo)
  1545.     touch ~/.pkg/sources-user
  1546.     echo "$repo_entry" >> ~/.pkg/sources-user
  1547.     local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1548.     echo "$user_repos" > ~/.pkg/sources-user
  1549.  
  1550.   fi
  1551.  
  1552.   return $RETVAL
  1553. }
  1554.  
  1555.  
  1556. add_repo(){                       # add Pkg/Ubuntu/Debian/Slackware third-party repos FUNCLIST
  1557.  
  1558.   local slack_repo_url
  1559.  
  1560.   if [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ];then
  1561.     print_usage add_repo && exit 1
  1562.   fi
  1563.  
  1564.   # work out which kind of repo we are processing
  1565.   case "$1" in
  1566.     'http'*'/PACKAGES.TXT.gz'|'http'*'/PACKAGES.TXT')
  1567.       # strip trailing /PACKAGES.TXT[.gz]
  1568.       slack_repo_url="${1//PACKAGES.TXT.gz/}"
  1569.       slack_repo_url="${slack_repo_url//\/.gz/}"
  1570.       slack_repo_url="${slack_repo_url//.gz\//}"
  1571.       slack_repo_url="${slack_repo_url//PACKAGES.TXT/}"
  1572.       # add trailing slash, if needed
  1573.       if [ "$(echo $slack_repo_url | grep '/$')" = '' ];then
  1574.         slack_repo_url="${slack_repo_url}/"
  1575.       fi
  1576.       slack2pup "$@"
  1577.       retval=$?
  1578.       if [ $retval -eq 0 ];then
  1579.         # register repo, so we know to update it in update_sources()
  1580.         touch ~/.pkg/sources-user
  1581.         echo "$repo_entry" >> ~/.pkg/sources-user
  1582.         local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1583.         echo "$user_repos" > ~/.pkg/sources-user
  1584.  
  1585.         # register in a slack supported file too
  1586.         mkdir -p /etc/slackpkg/
  1587.         touch /etc/slackpkg/mirrors
  1588.         echo "$slack_repo_url" >> /etc/slackpkg/mirrors
  1589.         local slack_repos="$(sort -u /etc/slackpkg/mirrors | uniq)"
  1590.         echo "$slack_repos" > /etc/slackpkg/mirrors
  1591.       fi
  1592.       ;;
  1593.  
  1594.     'http'*'/install')
  1595.       add_pkg_repo "$1"
  1596.       ;;
  1597.  
  1598.     'ppa:'*|'http://'*|'https://'*)
  1599.       wget --quiet --timeout=2 --no-parent --spider "${1}install"
  1600.       REPLY=$?
  1601.       if [ "$REPLY" = 0 ];then
  1602.         add_pkg_repo "${1}install"
  1603.         exit $?
  1604.       fi
  1605.  
  1606.       ppa2pup "$@"
  1607.       retval=$?
  1608.       if [ $retval -eq 0 ];then
  1609.         # register repo, so we know to update it in update_sources()
  1610.         touch ~/.pkg/sources-user
  1611.         echo "$repo_entry" >> ~/.pkg/sources-user
  1612.         local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1613.         echo "$user_repos" > ~/.pkg/sources-user
  1614.  
  1615.         # register in an apt-supported file too
  1616.         mkdir -p /etc/apt/
  1617.         touch /etc/apt/sources.list
  1618.         echo "deb $@" >> /etc/apt/sources.list
  1619.         local deb_repos="$(sort -u /etc/apt/sources.list | uniq)"
  1620.         echo "$deb_repos" > /etc/apt/sources.list
  1621.       fi
  1622.       ;;
  1623.  
  1624.     *)
  1625.       print_usage add_repo && exit 1
  1626.       ;;
  1627.  
  1628.   esac
  1629.  
  1630. }
  1631.  
  1632.  
  1633. rm_repo(){                        # remove an installed repo by name ($1) FUNCLIST
  1634.   if [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ];then
  1635.     print_usage rm_repo
  1636.     exit 1
  1637.   fi
  1638.  
  1639.   # $1 must be a valid, installed repo name
  1640.   if [ "$(repo_list | grep -m1 "^${1}$")" = "" ];then
  1641.     print_usage rm-repo
  1642.     exit 1
  1643.   fi
  1644.  
  1645.   # get the repo file and URL of the given repo
  1646.   local repo_file="$(grep "^$1" ~/.pkg/sources-all | cut -f3 -d'|' )"
  1647.   local repo_url="$(grep "^$1" ~/.pkg/sources-all | cut -f4 -d'|')"
  1648.  
  1649.   # dont allow removal of 'built in' repos, only user-added repos
  1650.   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)"
  1651.   if [ "${matching_user_added_repos}" = "" ];then
  1652.     echo "You can only remove the repositories that you installed yourself."
  1653.     echo -e "Use the command  ${bold}pkg repo-list${endcolour}  to see which repos are installed."
  1654.     exit 1
  1655.   fi
  1656.  
  1657.   # dont allow removal of current repo
  1658.   if [ "$REPONAME" = "$1" ];then
  1659.     echo "Can't remove current repo."
  1660.     echo -e "Switch to another repo first using:  ${bold}pkg repo REPONAME${endcolour}"
  1661.     exit 1
  1662.   fi
  1663.  
  1664.   # remove the repo file
  1665.   echo "Removing '$1'.. Please wait.."
  1666.   [ -f "$REPO_DB_FILE_DIR/$repo_file" ] && rm "$REPO_DB_FILE_DIR/$repo_file"
  1667.  
  1668.   # remove from sources
  1669.   grep -v "^$1|" ~/.pkg/sources > /tmp/pkg/sources
  1670.   grep -v "^$1|" ~/.pkg/sources-all > /tmp/pkg/sources-all
  1671.   [ -f /tmp/pkg/sources-all ] && mv /tmp/pkg/sources-all ~/.pkg/sources-all
  1672.   [ -f /tmp/pkg/sources     ] && mv /tmp/pkg/sources ~/.pkg/sources
  1673.  
  1674.   # remove from third-party lists
  1675.   grep -v  "|${repo_url}|"  ~/.pkg/sources-user > /tmp/pkg/sources-user
  1676.   grep -vE "$repo_url|${repo_name//*-/}" /etc/apt/sources.list > /tmp/pkg/sources.list
  1677.   grep -v  "$repo_url" /etc/slackpkg/mirrors > /tmp/pkg/mirrors
  1678.   [ -f /tmp/pkg/sources-user ] && mv /tmp/pkg/sources-user ~/.pkg/sources-user
  1679.   [ -f /tmp/pkg/sources.list ] && mv /tmp/pkg/sources.list /etc/apt/sources.list
  1680.   [ -f /tmp/pkg/mirrors ] && mv /tmp/pkg/mirrors /etc/slackpkg/mirrors
  1681.  
  1682.   if [ "$(repo_list | grep -m1 "^${1}$")" = "" ];then
  1683.     update_sources &>/dev/null
  1684.     echo -e "${green}Success${endcolour}: Repo removed."
  1685.   fi
  1686.  
  1687. }
  1688.  
  1689.  
  1690. add_source(){                     # add a new repo to your repo 'sources' list FUNCLIST
  1691.   [ ! "$1" \
  1692.     -o "$1" = "-" \
  1693.     -o "$1" = "-h" \
  1694.     -o "$1" = "--help" \
  1695.     -o "`echo "$1" |  grep '|'`" = "" \
  1696.     -o "`echo "$1" | cut -f2 -d'|'`" = "" \
  1697.     -o "`echo "$1" | cut -f4 -d'|'`" = "" \
  1698.     -o "`echo "$1" | cut -f8 -d'|'`" = "" ] && \
  1699.     print_usage add_source && exit 1
  1700.  
  1701.   # get repo file to add to sources
  1702.   REPOTOADD="`echo $1 | cut -f1 -d'|'`"
  1703.   REPOFILETOADD="`echo $1 | cut -f3 -d'|'`"
  1704.  
  1705.   # do checks before adding repo (dont add duplicate, make sure file exists, etc)
  1706.  
  1707.   # check if repo name already in sources-all
  1708.   #if [ "`grep "^$REPOTOADD\$" ~/.pkg/sources-all`" != "" ] || \
  1709.   #   [ "`repo_list | grep "^$REPOTOADD\$"`" != "" ];then
  1710.   #  echo "Repo with the name '$REPOTOADD' already in the list"
  1711.   #fi
  1712.  
  1713.   # check if repo filename already  exists in sources-all
  1714.   #if [ "`repo_file_list | grep -m1 "^$REPOFILETOADD\$"`" != "" ];then
  1715.   #  echo "Repo with database file $PKGS_DIR/'$REPOFILETOADD' already in the list"
  1716.   #fi
  1717.  
  1718.   # check if the repo file exists in $PKGS_DIR
  1719.   #if [ ! -f "`find $PKGS_DIR/ -name "$REPOFILETOADD"`" ];then
  1720.   #  echo "The repo database file '$PKGS_DIR/$REPOFILETOADD' not found."
  1721.   #fi
  1722.  
  1723.   # add the repo to sources-all, if not already there
  1724.   if [ "$(grep -m1 "^$REPOTOADD|" ${HOME}/.pkg/sources-all)" = "" ];then
  1725.     # all good, so add repo entry to sources-all
  1726.     echo "$1" >> ${HOME}/.pkg/sources-all
  1727.   fi
  1728.  
  1729.   # update users repo sources to get the new repo
  1730.   update_sources 1>/dev/null || { echo "Could not update repo sources."; exit 2; }
  1731.  
  1732.   # print msg
  1733.   echo "Repo '$REPOTOADD' added successfully."
  1734. }
  1735.  
  1736.  
  1737. update_sources(){                 # create the list of available repos FUNCLIST
  1738.  
  1739.   # get current repo values and Pkg settings
  1740.   . ${PKGRC}
  1741.  
  1742.   #list current repo first in sources
  1743.   get_repo_info "${REPONAME:-noarch}"
  1744.  
  1745.  
  1746.   # only add the current repo to the list of available sources if it exists
  1747.   if [ "$(find "$REPO_DB_FILE_DIR" -iname "$REPOFILE" )" != '' ];then
  1748.     echo "$REPONAME|$EX|$REPOFILE|$REPOURL1|$REPOURL2|$REPOURL3|$REPOURL4|$REPOFALLBACKS" > ${HOME}/.pkg/sources
  1749.   #elif [ "$(find "$(realpath "/var/packages/")" -iname "$REPOFILE" )" != '' ];then
  1750.   #  echo "$REPONAME|$EX|$REPOFILE|$REPOURL1|$REPOURL2|$REPOURL3|$REPOURL4|$REPOFALLBACKS" > ${HOME}/.pkg/sources
  1751.   fi
  1752.  
  1753.  
  1754.   # get repos in order of fallbacks, pkg will then 'fall back' to each repo in that order
  1755.   FALLBACKS="`grep -m1 "^${REPONAME}|" ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#' | cut -f8 -d'|'`"
  1756.  
  1757.   # for each repo in fallback list
  1758.   for FBACK in $REPOFALLBACKS; do
  1759.     # dont add current repo, its already added
  1760.     [ "$FBACK" = "$REPONAME" ] && continue
  1761.  
  1762.     # check if repo is supported (has entries in sources-all)
  1763.     LINE="`grep -m1 "^$FBACK|" ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#' | grep -v "^${REPONAME}|"`"
  1764.     [ "$LINE" = "" ] && continue
  1765.  
  1766.     # if repo is valid, add to users list of in-use repos (only valid repos from sources-all => sources)
  1767.     if [ -f "$REPO_DB_FILE_DIR/`echo "$LINE" | cut -f3 -d'|'`" ];then
  1768.  
  1769.       if [ "$(grep -m1 "^$FBACK|" ${HOME}/.pkg/sources)" = "" ];then
  1770.         echo "Adding repo: `echo "$LINE"|cut -f1 -d'|'`.."
  1771.         echo "$LINE" >> ${HOME}/.pkg/sources
  1772.       fi
  1773.     fi
  1774.   done
  1775.  
  1776.   cleaned_repo_list="`cat ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#'| grep -v ^$`"
  1777.  
  1778.   # now add any other repos to the list (repos that are installed, but not added from fallback list)
  1779.   echo "$cleaned_repo_list" | uniq | while read repo_entry
  1780.   do
  1781.     # dont add current repo, its already added
  1782.     [ "`echo "$repo_entry" | cut -f1 -d'|'`" = "$REPONAME" ] && echo "Adding repo: $REPONAME.." && continue
  1783.  
  1784.     # get the repo name
  1785.     repo_name="`echo "$repo_entry"|cut -f1 -d'|'`"
  1786.  
  1787.     # build the repo file (full path)
  1788.     repo_file="$REPO_DB_FILE_DIR"/`echo "$repo_entry" | cut -f3 -d'|'`
  1789.  
  1790.     # set a flag true if repo already in repo, false if not
  1791.     already_in_repo=false
  1792.     [ "`grep -m1 "^$repo_entry" ${HOME}/.pkg/sources 2>/dev/null`" != "" ] && already_in_repo=true
  1793.  
  1794.     if [ -f "$repo_file" -a "$already_in_repo" = false ];then
  1795.       echo "Adding repo: $repo_name.."
  1796.       echo "$repo_entry" >> ${HOME}/.pkg/sources
  1797.     fi
  1798.   done
  1799.  
  1800.   # finished, print message
  1801.   [ -f ${HOME}/.pkg/sources ] && echo "Sources updated." && . ${PKGRC}
  1802. }
  1803.  
  1804.  
  1805. update_repo(){                    # update the current repo from a file stored online FUNCLIST
  1806.  
  1807.   # check internet, net connection required
  1808.   NET="`check_net`"; [ $NET -eq 1 ] && echo "You need an internet connection" && exit 1
  1809.  
  1810.   # remove the repo update tmp file
  1811.   rm -f $TMPDIR/update_repo_results 2>/dev/null
  1812.  
  1813.   echo "Updating system repositories, please wait.."
  1814.   echo
  1815.  
  1816.   # use petget for now .. not ideal, petget wont accept $1 and only do that repo,
  1817.   # also petget uses loads of other files pkg doesnt have/need (in $PKGS_DIR)
  1818.   # also, we're limited to updating only the repos that petget supports, not all the ones Pkg supports..
  1819.   # .. on the plus side petget code is way faster than mine
  1820.   mkdir -p /var/local/petget/
  1821.   chmod 777 /var/local/petget/
  1822.   echo 'false' > /var/local/petget/db_verbose
  1823.  
  1824.   # now call petget 0setup.. the ENV options prevent popup windows, and need for user input
  1825.   DISPLAY='' SETUPCALLEDFROM=ppm /usr/local/petget/0setup &>$TMPDIR/update_repo_results
  1826.  
  1827.   # if the repos updated ok
  1828.   if [ $? -eq 0 ];then
  1829.     [ "`which logger`" != '' ] && logger "$0 Repo files updated by $APP $APPVER"
  1830.     echo -e "Repo files updated:"
  1831.     grep ^Processing $TMPDIR/update_repo_results | cut -f2 -d' '
  1832.     # remove the repo update tmp file
  1833.     rm -f $TMPDIR/update_repo_results 2>/dev/null
  1834.   else
  1835.     # repo did not update ok
  1836.     error "Repos NOT updated."
  1837.     cat $TMPDIR/update_repo_results | tail -20
  1838.     exit 2
  1839.   fi
  1840.  
  1841.   # update Pkg created, user-added (third-party) repos
  1842.   if [ -f ~/.pkg/sources-user ] || [ -f /etc/apt/sources.list ] || [ -f /etc/slackpkg/mirrors ];then
  1843.     echo
  1844.     echo "Updating third-party repos.. This may take a while.."
  1845.     echo
  1846.   fi
  1847.  
  1848.   # update Pkg created repos
  1849.   if [ -f ~/.pkg/sources-user ];then
  1850.     pkg_repos="$(sort -u ~/.pkg/sources-user | grep -v ^$ | uniq | cut -f1 -d'|')"
  1851.     for pkg_repo in $pkg_repos
  1852.     do
  1853.       local pkg_repo_url="$(cat ~/.pkg/sources-user | grep -m1 "^$pkg_repo|" | cut -f4 -d'|')"
  1854.       echo "Processing:  $pkg_repo_url"
  1855.  
  1856.       ANSWER=y
  1857.       if [ "$ASK" = true ];then
  1858.         bash -c 'read -r -N 1 -p "Update repo $pkg_repo? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1859.         echo
  1860.         ANSWER="$(cat /tmp/pkg/ANSWER)"
  1861.       fi
  1862.  
  1863.       if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ];then
  1864.         echo "Please wait..."
  1865.         add_pkg_repo ${pkg_repo_url}install 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$pkg_repo'"
  1866.       fi
  1867.     done
  1868.   fi
  1869.  
  1870.   # update third-party non-native repos.. These repos comes 'from source',
  1871.   # and are not in native Puppy format - they need to be downloaded, converted
  1872.   # into the Puppy format, then installed... so this will be slow..
  1873.   if [ -f /etc/apt/sources.list ] || [ -f /etc/slackpkg/mirrors ];then
  1874.  
  1875.     # update third-party Ubuntu/Debian repos
  1876.     # search inside /etc/apt/sources.list /etc/apt/sources.list.d/*.list
  1877.     # ...look for lines starting with 'deb ', ignore others
  1878.     # ...(use grep -h, to remove the preppended filenames if grepping multiple files)
  1879.     # ...remove any arch stuff from the entries, ppa2pup will handle that,
  1880.     # ...convert spaces to | chars, so we can process each line as a whole later
  1881.     local apt_sources_list="$(grep -h '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null \
  1882.      | sed \
  1883.        -e "s/^deb //g" \
  1884.        -e "s/^tor+//g" \
  1885.        -e 's/\[arch=[a-z,0-9].*\] //g' \
  1886.        -e 's/ /|/g'\
  1887.    )"
  1888.  
  1889.     # for each repo in $apt_sources_list, use `ppa2pup` to update the repo
  1890.     for line in $apt_sources_list
  1891.     do
  1892.       [ "$line" = "" ] && continue
  1893.       [ "$line" = "\n" ] && continue
  1894.  
  1895.       local ppa_repo_url="$(echo ${line//|/ } | cut -f1 -d" ")"
  1896.       local ppa_repo_name=$(cat ~/.pkg/sources-all | grep -m1 $ppa_repo_url | cut -f1 -d'|')
  1897.  
  1898.       # if a PPA repo, get a user-friendly repo name from the /etc/sources.list entry
  1899.       if [ "$ppa_repo_name" = "" ];then
  1900.         ppa_repo_name="$(echo ${line} | cut -f3 -d'|')-$(echo $line | cut -f2 -d':' | cut -f1 -d '/' | tr -d '-' | tr -d '_')"
  1901.       fi
  1902.  
  1903.       echo
  1904.       echo "Processing:  ${line//|/ }"
  1905.  
  1906.       ANSWER=y
  1907.       if [ "$ASK" = true ];then
  1908.         # ask user to update repo
  1909.         bash -c 'read -r -N 1 -p "Update repo $ppa_repo_name? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1910.         echo
  1911.         ANSWER="$(cat /tmp/pkg/ANSWER)"
  1912.       fi
  1913.  
  1914.       if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ];then
  1915.         echo "Please wait..."
  1916.         ppa2pup ${line//|/ } 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$ppa_repo_name'"
  1917.         retval=$?
  1918.       fi
  1919.     done
  1920.  
  1921.     # update third-party Slackware repos
  1922.     if [ -f /etc/slackpkg/mirrors ];then
  1923.       local slack_repos="$(sort -u /etc/slackpkg/mirrors | uniq)"
  1924.       local slack_repo_url=""
  1925.  
  1926.       for slack_repo in $slack_repos
  1927.       do
  1928.         slack_repo_url="${slack_repo//PACKAGES.TXT.gz/}"
  1929.         slack_repo_url="${slack_repo_url//\/.gz/}"
  1930.         slack_repo_url="${slack_repo_url//.gz\//}"
  1931.         slack_repo_url="${slack_repo_url//PACKAGES.TXT/}"
  1932.  
  1933.         # add trailing slash, if needed
  1934.         if [ "$(echo $slack_repo_url | grep '/$')" = '' ];then
  1935.           slack_repo_url="${slack_repo_url}/"
  1936.         fi
  1937.  
  1938.         local slack_repo_name=$(cat ~/.pkg/sources-all | grep -m1 $slack_repo_url | cut -f1 -d'|')
  1939.  
  1940.         echo
  1941.         echo "Processing:  $slack_repo_url"
  1942.  
  1943.         ANSWER=y
  1944.         if [ "$ASK" = true ];then
  1945.           # ask user to update repo
  1946.           bash -c 'read -r -N 1 -p "Update repo '"$slack_repo_name"'? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1947.           echo
  1948.           ANSWER="$(cat /tmp/pkg/ANSWER)"
  1949.         fi
  1950.  
  1951.         if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ];then
  1952.           echo "Please wait..."
  1953.           slack2pup "${slack_repo_url}/PACKAGES.TXT" $slack_repo_name 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$slack_repo_name'"
  1954.         fi
  1955.       done
  1956.     fi
  1957.   fi
  1958.  
  1959.   echo
  1960.   exit 0
  1961.  
  1962. }
  1963.  
  1964.  
  1965. list_sources(){                   # return available (matching) repos (~/.pkg/sources) FUNCLIST
  1966.   grep -m1 "^$1" ${HOME}/.pkg/sources ${HOME}/.pkg/sources-user | cut -f2-99 -d':' | uniq
  1967. }
  1968.  
  1969.  
  1970. list_all_sources(){               # return all (or matching) repos (~/.pkg/sources-all) FUNCLIST
  1971.   grep -m1 "^$1" ${HOME}/.pkg/sources-all ${HOME}/.pkg/sources-user | cut -f2-99 -d':' | uniq
  1972. }
  1973.  
  1974.  
  1975. convert_repofile(){               # convert repo files formats (pre-woof/post-woof) FUNCLIST
  1976.  
  1977.   # get the file name (FILENAME) and full path (FILE)
  1978.   FILENAME="`basename "$1"`"
  1979.   FILE="${CURDIR}/${FILENAME}"
  1980.  
  1981.   # check for valid options
  1982.   [ ! -f "$FILE" ] && print_usage repo-convert && exit 1
  1983.  
  1984.   # dont replace repo unless -f was given
  1985.   [ "$FORCE" != true -a -f "$REPO_DB_FILE_DIR/${FILENAME}" ] && echo "File '$REPO_DB_FILE_DIR/$FILENAME' already exists."  && exit 1
  1986.  
  1987.   # remove tmp files
  1988.   rm $TMPDIR/$FILENAME &>/dev/null
  1989.   rm $TMPDIR/${FILENAME}_subdirs &>/dev/null
  1990.  
  1991.   # check repo file format (woof or pre-woof)
  1992.   if [ -f "$FILE" -a "`cat "$FILE" | head -1 | grep -m1 '^"'`" = "" ];then #if is a new format  #'
  1993.  
  1994.     # convert woof repo file to pre-woof repo file.. takes ages..
  1995.     echo "Converting '${FILE}' to pre-woof format.. This might take a while.."
  1996.     cat "$FILE" | while read LINE
  1997.     do
  1998.       PKGNAME="`echo $LINE| cut -f1 -d'|'`"
  1999.       PKGNAME1=''
  2000.       # we need to get the package name, try lots of different extensions
  2001.       [ "`echo $PKGNAME1 | grep ".deb\$"`" != "" ]  && PKGNAME1="`echo $LINE| cut -f8 -d'|'`"
  2002.       [ "`echo $PKGNAME1 | grep ".deb\$"`" != "" ]  && PKGNAME="`basename $PKGNAME1 .deb`"
  2003.       [ "`echo $PKGNAME1 | grep ".rpm\$"`" != "" ]  && PKGNAME="`basename $PKGNAME1 .rpm`"
  2004.       [ "`echo $PKGNAME1 | grep ".txz\$"`" != "" ]  && PKGNAME="`basename $PKGNAME1 .txz`"
  2005.       [ "`echo $PKGNAME1 | grep ".tgz\$"`" != "" ]  && PKGNAME="`basename $PKGNAME1 .tgz`"
  2006.       [ "`echo $PKGNAME1 | grep ".tar.xz\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .tar.xz`"
  2007.       [ "`echo $PKGNAME1 | grep ".tar.gz\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .tar.gz`"
  2008.       # get size
  2009.       SIZE=" `echo $LINE| cut -f6 -d'|'`"
  2010.       # get category
  2011.       CAT="`echo $LINE| cut -f5 -d'|'`"
  2012.       #150813 remove extra categories .. example 'Setup;Installation' .. remove 'Installation'
  2013.       [ "`echo "$CAT" | grep ';'`" != "" ] && CAT="`echo "$CAT" | cut -f1 -d';'`"
  2014.       # get sub dir in repo
  2015.       SUBDIR="`echo $LINE| cut -f7 -d'|'`" #150213
  2016.       # get deps
  2017.       DEPS=" `echo $LINE| cut -f9 -d'|'| grep '+'`"
  2018.       # get desc
  2019.       DESC="`echo $LINE| cut -f10 -d'|'`"
  2020.       # add repo entry to tmp file
  2021.       [ "$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
  2022.       #150213 now do subdirs... slow..
  2023.       [ "`echo $SUBDIR | grep "/"`" != "" -a "`echo $SUBDIR | grep -i pet_packages`" = "" ] && echo "$PKGNAME|/$SUBDIR" >> $TMPDIR/${FILENAME}_subdirs
  2024.     done
  2025.     # done making a pre-woof repo file, print message
  2026.     [ -f $TMPDIR/$FILENAME ] && echo "Finished converting $FILENAME to pre-woof format." || exit 1
  2027.  
  2028.   else
  2029.  
  2030.     # convert pre-woof repo file to woof repo file.. takes ages..
  2031.     echo "Converting '$FILENAME' to a 'woof' compatible repo file. This could take a while..."
  2032.  
  2033.     # parse a pre-woof repo file
  2034.     cat "$FILE" | while read LINE
  2035.     do
  2036.       PKGNAME='' PKGNAMEONLY='' PKGVER='' SIZE='' CAT='' DEPS='' BUILD='' SUBDIR='' PKGEXT='.pet' DESC=''
  2037.  
  2038.       PKGNAME="`echo "$LINE" | cut -d'"' -f2`" #'micro
  2039.       [ "`echo $PKGNAME | grep ".deb\$"`" != "" ]     && PKGEXT='.deb'    && PKGNAME="`basename $PKGNAME1 .deb`"
  2040.       [ "`echo $PKGNAME | grep ".pet\$"`" != "" ]     && PKGEXT='.pet'    && PKGNAME="`basename $PKGNAME1 .pet`"
  2041.       [ "`echo $PKGNAME | grep ".rpm\$"`" != "" ]     && PKGEXT='.rpm'    && PKGNAME="`basename $PKGNAME1 .rpm`"
  2042.       [ "`echo $PKGNAME | grep ".tcz\$"`" != "" ]     && PKGEXT='.tcz'    && PKGNAME="`basename $PKGNAME1 .tcz`"
  2043.       [ "`echo $PKGNAME | grep ".tgz\$"`" != "" ]     && PKGEXT='.tgz'    && PKGNAME="`basename $PKGNAME1 .tgz`"
  2044.       [ "`echo $PKGNAME | grep ".txz\$"`" != "" ]     && PKGEXT='.txz'    && PKGNAME="`basename $PKGNAME1 .txz`"
  2045.       [ "`echo $PKGNAME | grep ".tar.gz\$"`" != "" ]    && PKGEXT='.tar.gz'   && PKGNAME="`basename $PKGNAME1 .tar.gz`"
  2046.       [ "`echo $PKGNAME | grep ".tar.xz\$"`" != "" ]    && PKGEXT='.tar.xz'   && PKGNAME="`basename $PKGNAME1 .tar.xz`"
  2047.       [ "`echo $PKGNAME | grep ".pkg.tar.gz\$"`" != "" ]  && PKGEXT='.pkg.tar.gz' && PKGNAME="`basename $PKGNAME1 .pkg.tar.gz`"
  2048.       [ "`echo $PKGNAME | grep ".pkg.tar.xz\$"`" != "" ]  && PKGEXT='.pkg.tar.xz' && PKGNAME="`basename $PKGNAME1 .pkg.tar.xz`"
  2049.  
  2050.       # get pkg name only .. without versions or suffix
  2051.       PKGNAME_ONLY="`echo "${PKGNAME}" | sed -e 's/-[0-9.]*/-/g' -e 's/-$//'`"
  2052.       # if that didnt work, use the old method
  2053.       if [ "$PKGNAME_ONLY" = '' -o "$PKGNAME_ONLY" = "$PKGNAME" ];then
  2054.         # get pkg name without version
  2055.         PKGNAMEONLY="`echo $PKGNAME | cut -d'-' -f1`"
  2056.       fi
  2057.       PKGNAME_ONLY="${PKGNAME_ONLY//-*/}"
  2058.  
  2059.       # get pkg version
  2060.       PKGVER="`LANG=C echo "$LINE" | sed -e 's/^[^0-9]*-//g' | cut -f1 -d'_' | cut -f1 -d'-'`"
  2061.       # get pkg size
  2062.       SIZE="`echo $LINE| cut -d'"' -f6 | cut -d' ' -f3`" #'micro
  2063.       SIZE=${SIZE## }
  2064.       SIZE=${SIZE%% }
  2065.       # must check again if pkg had no deps
  2066.       [ "$SIZE" = "" ] && SIZE=" `echo $LINE| cut -d'"' -f6|cut -d' ' -f2`"
  2067.       # get pkg category
  2068.       CAT="`echo $LINE | cut -d'"' -f6 | cut -d' ' -f1`"
  2069.       # remove extra categories
  2070.       [ "`echo "$CAT" | grep ';'`" != "" ] && CAT="`echo "$CAT" | cut -f1 -d';'`"
  2071.       # get pkg deps
  2072.       DEPS="`echo "$LINE" | cut -d'"' -f6 | cut -d' ' -f2 | grep ^'+'`"
  2073.       DESC="`echo "$LINE" | cut -f10 -d'|'`" #'micro
  2074.       # build the woof compatible repo file
  2075.       [ "$PKGNAME" != "" ] && echo "$PKGNAME|$PKGNAMEONLY|$VER|$BUILD|$CAT|$SIZE|$SUBDIR|${PKGNAME}${PKGEXT}|$DEPS|$DESC|$DISTRO_BINARY_COMPAT|$DISTRO_COMPAT_VERSION||" >> $TMPDIR/$FILENAME
  2076.     done
  2077.     #done making a woof repo file, print message
  2078.     [ -f $TMPDIR/$FILENAME ] && echo "Finished converting $FILENAME to woof format." || exit 1
  2079.   fi
  2080.  
  2081.   # if we are updating the repo, we dont wanna install the converted file straight over
  2082.   # the actual repo file, we wanna parse it for new pkgs and add only those
  2083.   if [ "$2" != "for_repo_update" ];then
  2084.     # we converted a repo that we actually wanna install, so install it
  2085.     mv $TMPDIR/$FILENAME "$REPO_DB_FILE_DIR/$FILENAME"
  2086.     mv $TMPDIR/${FILENAME}_subdirs "$REPO_DB_FILE_DIR/${FILENAME}_subdirs" 2>/dev/null
  2087.     echo "Repo file '$REPO_DB_FILE_DIR/$FILENAME' created."
  2088.     update_sources #210613 update the list of sources after adding the newly converted repo
  2089.     #exit 0
  2090.   else
  2091.     mv "$TMPDIR/$FILENAME" "$REPO_DB_FILE_DIR/$FILENAME"
  2092.   fi
  2093. }
  2094.  
  2095.  
  2096. print_repo_info(){                # get repo settings, return current repo name FUNCLIST
  2097.  
  2098.   # get latest repo info (from sources file), or from PKGRC if that fails
  2099.   [ "$1" ] && get_repo_info "$1" || . ${PKGRC}
  2100.  
  2101.   local pkg_count=$(cat "$REPO_DB_FILE_DIR/${REPOFILE}" | wc -l)
  2102.  
  2103.   # output the repo info
  2104.   echo "- Repo:          $REPONAME"
  2105.   echo "- Repo file:     $REPOFILE"
  2106.   echo "- Package Type:  $EX"
  2107.   echo "- Packages:      $pkg_count"
  2108.   echo "- URL Mirror 1:  `echo $REPOURL1 | cut -f1-3 -d'/'`"
  2109.   [ "$REPOURL2" != "" ] && echo "- URL Mirror 2:  `echo $REPOURL2  | cut -f1-3 -d'/'`"
  2110.   [ "$REPOURL3" != "" ] && echo "- URL Mirror 3:  `echo $REPOURL3  | cut -f1-3 -d'/'`"
  2111.   [ "$REPOURL4" != "" ] && echo "- URL Mirror 4:  `echo $REPOURL4  | cut -f1-3 -d'/'`"
  2112.   echo
  2113.   echo "- Fall back to:`echo $REPOFALLBACKS | fold -w 50 -s | sed -e "s/ /, /g" -e "s/^/  /g"`"
  2114. }
  2115.  
  2116.  
  2117.  
  2118. # pkg search funcs
  2119.  
  2120. hide_blacklisted_pkgs_from_search_results(){ # hide BUILTIN and installed pkgs from searches NOLIST
  2121.  
  2122.   # dont hide package if using --force (the user may want to force a re-install of already installed pkg, for example)
  2123.   [ "$FORCE" = true ] && return 0
  2124.  
  2125.   # get pkg names (generic names, no versions) of all blacklisted packages in pipe delimited list
  2126.   blacklisted_pkgs_list="$(echo $PKG_NAME_IGNORE | sed -e 's/ /|/g')"
  2127.  
  2128.   # remove blacklisted packages from search list
  2129.   cat $TMPDIR/pkglist | grep -v -E "'$blacklisted_pkgs_list'" > $TMPDIR/pkglist_without_blacklisted
  2130.   mv $TMPDIR/pkglist_without_blacklisted $TMPDIR/pkglist
  2131.  
  2132.   # clean up tmp files
  2133.   rm $TMPDIR/pkglist_* &>/dev/null
  2134. }
  2135.  
  2136.  
  2137. hide_installed_pkgs_from_search_results(){  # hide BUILTIN and installed pkgs from searches NOLIST
  2138.  
  2139.   # dont hide package if using --force (the user may want to force a re-install of already installed pkg, for example)
  2140.   [ "$FORCE" = true ] && return 0
  2141.  
  2142.   # reset tmp file
  2143.   rm $TMPDIR/pkglist_inst &>/dev/null
  2144.  
  2145.   # get pkg names (generic names, no versions) of all installed pkgs (builtins, devx and user installed)
  2146.   inst_pkg_list="`cut -f1 -d'|' "$USER_INST_PKGS_FILE" \
  2147.    "$DEVX_INST_PKGS_FILE" \
  2148.    "$WOOF_INST_PKGS_FILE" 2>/dev/null \
  2149.    | grep -v ^$ \
  2150.    | tr '\n' '|' \
  2151.    | sed -e "s/||/|/g" \
  2152.    | sed -e "s/|\$//g"`"
  2153.  
  2154.   # remove woof and user installed packages from search list
  2155.   cat $TMPDIR/pkglist | grep -v -E "'$inst_pkg_list'" > $TMPDIR/pkglist_without_inst
  2156.   mv $TMPDIR/pkglist_without_inst $TMPDIR/pkglist
  2157.  
  2158.   # clean up tmp files
  2159.   rm $TMPDIR/pkglist_* &>/dev/null
  2160. }
  2161.  
  2162.  
  2163. list_pkg_names(){                 # list pkg names in current repo only ($1 is optional filter) FUNCLIST
  2164.  
  2165.   # remove any previous searches
  2166.   rm $TMPDIR/pkglist* 2>/dev/null
  2167.  
  2168.   # get current repo ($REPOFILE)
  2169.   . ${PKGRC}
  2170.  
  2171.   # create the search results
  2172.   cut -f1 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$1" > $TMPDIR/pkglist
  2173.  
  2174.   # filter out builtin and user installed packages
  2175.   if [ $HIDE_INSTALLED = true ];then
  2176.     hide_installed_pkgs_from_search_results
  2177.   fi
  2178.  
  2179.   hide_blacklisted_pkgs_from_search_results
  2180.  
  2181.   # support pkg name aliases in finding packages
  2182.   if [ $NO_ALIASES = false ];then
  2183.     local ALIAS_LIST
  2184.     local ALIAS
  2185.     local ALIAS_RES
  2186.     # if we have some results to parse
  2187.     if [ "$1" != "" -a -f $TMPDIR/pkg_aliases ];then
  2188.       # get the list of aliases
  2189.       ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases  2>/dev/null | tr ',' ' '`";
  2190.       # for each alias
  2191.       echo $ALIAS_LIST | while read ALIAS
  2192.       do
  2193.         [ "$ALIAS" = '' ] && continue
  2194.         # get the match from the current repo (if any)
  2195.         ALIAS_RES="`LANG=C cut -f1 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$ALIAS"`" #'
  2196.         [ ! "$ALIAS_RES" ] && ALIAS_RES="`LANG=C cut -f2 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$ALIAS"`" #'
  2197.         # if the repo match was found in the search results
  2198.         if [ "$ALIAS_RES" != "" ];then
  2199.           # add the alias results to the search results
  2200.           echo "$ALIAS_RES" >> $TMPDIR/pkglist
  2201.         fi
  2202.       done # for each alias
  2203.       # sort and clean the search results
  2204.       LANG=C cat $TMPDIR/pkglist | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq > $TMPDIR/pkglist1
  2205.       # replace the original search results
  2206.       mv $TMPDIR/pkglist1 $TMPDIR/pkglist
  2207.     fi
  2208.   fi
  2209.  
  2210.   # return the search results
  2211.   [ -s $TMPDIR/pkglist ] && cat $TMPDIR/pkglist 2>/dev/null
  2212.  
  2213.   # clean up
  2214.   [ ! -f $TMPDIR/pkglist ] && exit 1
  2215.   rm $TMPDIR/pkglist* 2>/dev/null
  2216.  
  2217. }
  2218.  
  2219.  
  2220. list_all_pkg_names(){             # list pkg names in any repo  ($1 is optional filter)FUNCLIST
  2221.  
  2222.   # remove any previous search results
  2223.   rm $TMPDIR/pkglist &>/dev/null
  2224.  
  2225.   # if bleeding edge disabled, output the list repo by repo, in the fallback order, current repo first (that order is set in update_sources)
  2226.   repo_file_list | while read repo_file
  2227.   do
  2228.     cut -f1 -d'|' "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep "^$1" | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr >> $TMPDIR/pkglist
  2229.   done
  2230.  
  2231.   # if bleeding edge enabled, re-order the whole list, so Pkg returns the most recent pgk versions from ANY repos
  2232.   if [ "$BLEDGE" = "yes" ];then
  2233.     LANG=C cat $TMPDIR/pkglist  2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr > $TMPDIR/pkglist1
  2234.     mv $TMPDIR/pkglist1 $TMPDIR/pkglist
  2235.   fi
  2236.  
  2237.   # filter out built-in and user installed packages
  2238.   if [ $HIDE_INSTALLED = true ];then
  2239.     hide_installed_pkgs_from_search_results
  2240.   fi
  2241.  
  2242.   hide_blacklisted_pkgs_from_search_results
  2243.  
  2244.   # support pkg name aliases in finding packages
  2245.   if [ $NO_ALIASES = false ];then
  2246.     local ALIAS_LIST
  2247.     local ALIAS
  2248.     local ALIAS_RES
  2249.     # if we have some results to parse
  2250.     if [ "$1" != "" -a -f $TMPDIR/pkg_aliases ];then
  2251.       # get the list of aliases
  2252.       ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases  2>/dev/null | tr ',' ' '`";
  2253.       # for each repo
  2254.       LANG=C repo_file_list | while read RF
  2255.       do
  2256.         # and for each alias
  2257.         for ALIAS in $ALIAS_LIST; do
  2258.           # get the match from the current repo (if any)
  2259.           ALIAS_RES="`LANG=C cut -f1 -d'|' "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -m1 "^$ALIAS"`"
  2260.           [ ! "$ALIAS_RES" ] && ALIAS_RES="`LANG=C cut -f2 -d'|' "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -m1 "^$ALIAS"`"
  2261.           # if the repo match was found in the search results
  2262.           if [ "$ALIAS_RES" != "" ];then
  2263.             # add the alias results to the search results
  2264.             echo "$ALIAS_RES" >> $TMPDIR/pkglist
  2265.           fi
  2266.         done # for each alias
  2267.       done # for each repo
  2268.     fi
  2269.   fi
  2270.  
  2271.   # return the search results
  2272.   [ -s $TMPDIR/pkglist ] && LANG=C cat $TMPDIR/pkglist | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq
  2273.  
  2274.   # clean up
  2275.   [ ! -f $TMPDIR/pkglist ] && exit 1
  2276.   rm $TMPDIR/pkglist &>/dev/null
  2277. }
  2278.  
  2279.  
  2280. list_build_scripts(){             # list available build scripts  ($1 is optional filter)FUNCLIST
  2281.  
  2282.   # get settings from RC file
  2283.   . ${PKGRC}
  2284.  
  2285.   # make sure PetBuild is ready
  2286.   [ "$BUILDTOOL" = "petbuild" ] && prepare_petbuild
  2287.  
  2288.   # if no option given, just sort the results
  2289.   [ "$1" != "" ] && FILTER="grep -i $1" || FILTER="sort"
  2290.  
  2291.   # different build tools have their build scripts in different places.
  2292.   # check which BUILDTOOL we are using and list its build scripts
  2293.   case $BUILDTOOL in
  2294.     petbuild)
  2295.       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 ^$
  2296.     ;;
  2297.     buildpet)
  2298.       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 ^$
  2299.     ;;
  2300.     src2pkg)
  2301.       echo "Use: src2pkg FILE|URL or src2pkg -h"
  2302.     ;;
  2303.     sbopkg)
  2304.       sbopkg
  2305.     ;;
  2306.     *)
  2307.       echo "No build system configured. Set BUILDTOOL in $PKGRC."
  2308.       echo "Supported build tools: petbuild, buildpet, src2pkg, sbopkg"
  2309.     ;;
  2310.   esac
  2311. }
  2312.  
  2313.  
  2314. list_downloaded_pkgs(){           # list packages downloaded in WORKDIR ($1 is optional filter) FUNCLIST
  2315.  
  2316.   . ${PKGRC}
  2317.  
  2318.   cd "$WORKDIR" || { error "Cant cd into $WORKDIR"; exit 3; }
  2319.  
  2320.   local pkg
  2321.  
  2322.   # if no pkg given, list all
  2323.   if [ ! "$1" ];then
  2324.  
  2325.     # get all pkgs in WORKDIR
  2326.     find "${WORKDIR}" -maxdepth 1 -type f | sed -e "s#${WORKDIR}##g" -e "s#^/##g" | grep -v ^'.pkg' | sort \
  2327.       | while read pkg # but go through each and only print it if a valid pkg
  2328.       do
  2329.         [ "`is_local_pkg "$pkg"`" = true ] && echo $pkg || continue
  2330.       done
  2331.  
  2332.     return 0
  2333.  
  2334.   else
  2335.  
  2336.     # $1 might be a pkg, or list of pkgs, loop through them
  2337.     for x in $1; do
  2338.       if [ "$x" != "-" ];then
  2339.  
  2340.         # print the list of packages matching $x
  2341.         find "${WORKDIR}" -maxdepth 1 -type f | sed -e "s#${WORKDIR}##g" -e "s#^/##g" | grep -v ^'.pkg'|grep ^"$x" | sort \
  2342.           | while read pkg # but go through each and only print it if a valid pkg
  2343.           do
  2344.             [ "`is_local_pkg "$pkg"`" = true ] && echo $pkg || continue
  2345.           done
  2346.  
  2347.         return 0
  2348.       fi
  2349.     done
  2350.   fi
  2351.  
  2352.   cd -
  2353. }
  2354.  
  2355.  
  2356. list_installed_pkgs(){            # list user installed packages ($1 is optional filter) FUNCLIST
  2357.  
  2358.   local user_pkgs_list=''
  2359.   local builtins_list=''
  2360.   local devx_pkgs_list=''
  2361.  
  2362.   user_pkgs_list="$USER_INST_PKGS_FILE"
  2363.  
  2364.   if [ "$HIDE_BUILTINS" != true -a -f "$DEVX_INST_PKGS_FILE" ];then
  2365.     devx_pkgs_list="$DEVX_INST_PKGS_FILE"
  2366.   fi
  2367.  
  2368.   [ "$HIDE_BUILTINS" != true ] && builtins_list="$WOOF_INST_PKGS_FILE"
  2369.  
  2370.   # search current repo file only .. $1 is the optional pkg filter.. take field1, remove empty lines, remove dashes, remove Pkg from pkg list too
  2371.   if [ ! "$1" ];then
  2372.     cut -f1 -d'|' $user_pkgs_list $devx_pkgs_list $builtins_list | grep -vE '^\$|^pkg\-'
  2373.     return 0
  2374.   else
  2375.     cut -f1 -d'|' $user_pkgs_list $devx_pkgs_list $builtins_list | grep "^$1" | grep -vE '^\$|^pkg\-'
  2376.     return 0
  2377.   fi
  2378. }
  2379.  
  2380.  
  2381. list_builtin_pkgs(){              # lists builtin packages FUNCLIST
  2382.  
  2383.   local builtins_repo
  2384.  
  2385.   builtins_repo="$WOOF_INST_PKGS_FILE"
  2386.  
  2387.   # 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
  2388.   cut -f1 -d'|' $builtins_repo | grep "^$1" | grep -v ^\$  | grep -v "\-$" | grep -v ^pkg\- | sort
  2389. }
  2390.  
  2391.  
  2392. search_pkgs(){                    # given $1, searches current repo, shows name and desc columns FUNCLIST
  2393.  
  2394.   local name
  2395.   local desc
  2396.   local descfull
  2397.   local search
  2398.  
  2399.   # convert "foo[ -_]bar" into "foo.*bar"
  2400.   search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2401.  
  2402.   # convert repo file to nice columnised output, use cat|grep so empty searches return all results
  2403.   cat "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep -i "$search" | while read repo_line;
  2404.   do
  2405.     name=`echo  "$repo_line"|cut -f2  -d'|'`
  2406.     desc="`echo "$repo_line"|cut -f10 -d'|' | head -c 57`"
  2407.     descfull="`echo "$repo_line"|cut -f10 -d'|'`"
  2408.     [ "$desc" != "$descfull" ] && desc="${desc}.."
  2409.     printf "%-20s" "$name" " ${desc:-No description}"
  2410.     echo
  2411.   done
  2412. }
  2413.  
  2414.  
  2415. search_fast(){                    # given $1, searches current repo, show pkg names only, case sensitive FUNCLIST
  2416.   local RES
  2417.   local search
  2418.  
  2419.   # convert "foo[ -_]bar" into "foo.*bar"
  2420.   search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2421.  
  2422.   # get matching pkgs
  2423.   RES="`LANG=C grep "$search" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f1 -d'|'`"
  2424.   # error if no result
  2425.   [ ! "$RES" ] && exit 1
  2426.  
  2427.   # put results into file
  2428.   echo "$RES" > $TMPDIR/pkglist
  2429.  
  2430.   # hide built-in, devx and user installed packages
  2431.   if [ $HIDE_INSTALLED = true ];then
  2432.     hide_installed_pkgs_from_search_results
  2433.   fi
  2434.  
  2435.   hide_blacklisted_pkgs_from_search_results
  2436.  
  2437.   # now build the search results
  2438.   RES="`grep -v "^\$" $TMPDIR/pkglist 2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq`"
  2439.   rm $TMPDIR/pkglist &>/dev/null
  2440.  
  2441.   #finshed making search results, print results
  2442.   [ "$RES" = "" ] && exit 1
  2443.   echo "$RES"
  2444. }
  2445.  
  2446.  
  2447. search_all_pkgs(){                # given $1, search all repos, show name and desc columns FUNCLIST
  2448.  
  2449.   local name
  2450.   local desc
  2451.   local descfull
  2452.   local search
  2453.  
  2454.   # convert "foo[ -_]bar" into "foo.*bar"
  2455.   search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2456.  
  2457.   for repo_file in `repo_file_list`
  2458.   do #090817
  2459.     # convert repo file to nice columnised output
  2460.     cat "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -i "$search" | while read repo_line;
  2461.     do
  2462.     # get details from repo
  2463.     name=`echo  "$repo_line"|cut -f2  -d'|'`
  2464.     desc="`echo "$repo_line"|cut -f10 -d'|' | head -c 57`"
  2465.     descfull="`echo "$repo_line"|cut -f10 -d'|'`"
  2466.     [ "$desc" != "$descfull" ] && desc="${desc}.."
  2467.     # remove spaces and comments (slackware-extra repo has some dodgy entries.. dogy names, descriptions with comments, etc)
  2468.     name="${name// /}"
  2469.     name="${name//#/}"
  2470.     [ "$name" = '' ] && continue
  2471.     # print columnised output
  2472.     printf "%-20s" "$name" " ${desc:-No description}"
  2473.     echo
  2474.     done
  2475.   done
  2476.  
  2477. }
  2478.  
  2479.  
  2480. search_all_fast(){                # given $1, search all repos, show pkg names only, case sensitive FUNCLIST
  2481.   local RES
  2482.   local search
  2483.  
  2484.   # convert "foo[ -_]bar" into "foo.*bar"
  2485.   search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2486.  
  2487.   #if bleeding edge enabled, combine into 1 list, so
  2488.   # that `pkg -g` etc return most recent from ALL repos
  2489.   rm $TMPDIR/pkglist &>/dev/null
  2490.   if [ "$BLEDGE" = "yes" ];then
  2491.     RES=''
  2492.     for RF in `repo_file_list`
  2493.     do #090817
  2494.       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
  2495.     done
  2496.  
  2497.   else
  2498.     # if bleeding edge disabled, output the list repo by repo, in #
  2499.     # the fallback order, current repo first (that order is set in update_sources)
  2500.     for RF in `repo_file_list`
  2501.     do #090817
  2502.       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
  2503.     done
  2504.  
  2505.   fi
  2506.  
  2507.   #100817 hide built-in, devx and user installed packages
  2508.   if [ $HIDE_INSTALLED = true ];then
  2509.     hide_installed_pkgs_from_search_results
  2510.   fi
  2511.  
  2512.   hide_blacklisted_pkgs_from_search_results
  2513.  
  2514.   # now build the search results
  2515.   RES="`grep -v "^\$" $TMPDIR/pkglist 2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq`"
  2516.   rm $TMPDIR/pkglist &>/dev/null
  2517.  
  2518.   #finshed making search results, print results
  2519.   [ "$RES" = "" ] && exit 1
  2520.  
  2521.   echo "$RES"
  2522. }
  2523.  
  2524.  
  2525. which_repo(){                     # list repo of given package ($1) FUNCLIST
  2526.  
  2527.   # if no valid options, quit
  2528.   [ ! "$1" -o "$1" = "-" -o "$1" = " " ] && print_usage which-repo && exit 1
  2529.  
  2530.   . ${PKGRC}
  2531.  
  2532.   local PKGNAME=''
  2533.   local PKGNAME_ONLY=''
  2534.   local pkg_ext=''
  2535.   local repo_file=''
  2536.   local repo_name=''
  2537.   local pkg_list=''
  2538.  
  2539.   PKGNAME=`get_pkg_name "$1"`
  2540.   PKGNAME_ONLY=`get_pkg_name_only "$1"`
  2541.   pkg_ext=`get_pkg_ext "$PKGNAME"`
  2542.  
  2543.   repo_file="$(grep -l "|$PKGNAME.$pkg_ext|" "$REPO_DB_FILE_DIR"/Packages-*)"
  2544.   if [ "$repo_file" != '' ];then
  2545.     # get the repo name
  2546.     repo_name="`grep -m1 "$(basename $repo_file)|" ${HOME}/.pkg/sources | cut -f1 -d'|'`"
  2547.     pkg_list="$PKGNAME $repo_name"
  2548.   else
  2549.  
  2550.     # for each repo
  2551.     for repo_file in `repo_file_list`
  2552.     do
  2553.       # get the repo name
  2554.       repo_name="`grep -m1 "$repo_file|" ${HOME}/.pkg/sources | cut -f1 -d'|'`"
  2555.       # create the entries, example: "vlc slacko14.2"
  2556.       # (each line shows a matching package, then a SPACE, then the name of repo the package lives in)
  2557.       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"`"
  2558.       [ "$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"`"
  2559.       [ "$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"`"
  2560.       [ "$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"`"
  2561.       [ "$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"`"
  2562.       [ "$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"`"
  2563.       [ "$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"`"
  2564.     done
  2565.   fi
  2566.  
  2567.   # show results
  2568.   LANG=C echo -e "$pkg_list" | sed -e '/^$/d' | uniq
  2569. }
  2570.  
  2571.  
  2572. which_pkg(){                      # find out which pkg FILE ($1) comes from FUNCLIST
  2573.  
  2574.   # exit if no valid opts
  2575.   [ ! "$1" -o "$1" = '-' -o "$1" = '' ] && print_usage which && exit 1
  2576.  
  2577.   local PKGNAME=''
  2578.   local PKG_FILE_LIST=''
  2579.   local FILENAME=''
  2580.   local FILENAME_ONLY=''
  2581.   local DIRNAME=''
  2582.   local builtins_without_busybox="$(find "$BUILTIN_FILE_LIST_DIR"/* -maxdepth 1 -type f | grep -v "/busybox")"
  2583.  
  2584.   # get user input
  2585.   FILENAME="`basename "$1"`"
  2586.   FILENAME_ONLY="$FILENAME"
  2587.   DIRNAME="`dirname "$1"`"
  2588.  
  2589.   # if we don't have a file, the user probably gave a command,
  2590.   # so lets check see
  2591.   if [ ! -f "$1" ];then
  2592.     # if we get a command, then that is our FILENAME
  2593.     cmd=`which "$1"`
  2594.     # if $cmd found, set FILENAME to $cmd (FILENAME now includes full path)
  2595.     [ "$cmd" != '' ] && FILENAME=$cmd && FILENAME_ONLY=`basename "$FILENAME"`
  2596.   fi
  2597.  
  2598.   # dont use relative paths
  2599.   [ "`echo "$DIRNAME" | grep "^\."`" != '' ] && DIRNAME=''
  2600.  
  2601.   # try user installed pkgs contents of $PKGS_DIR/*.files
  2602.  
  2603.   # try '$dir/$file', returns filename (no path) of matching *.files
  2604.   [ "$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`"
  2605.  
  2606.   # try '$dir/$file_*' if needed
  2607.   [ "$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`"
  2608.  
  2609.   # try '$dir/$file-*' if needed
  2610.   [ "$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`"
  2611.  
  2612.   # if we found a package, set the package name to the name of the *.files file that we got
  2613.   [ "$PKG_FILE_LIST" != '' ] && PKGNAME="`basename "$PKG_FILE_LIST" .files`"
  2614.  
  2615.   # maybe we got nothing from *.files.. check builtins/$1* for ' $FILENAME_ONLY',
  2616.   # returns PKGNAME of the matching builtin
  2617.  
  2618.   # if needed, search inside builtin file lists (EXCEPT busybox) for ' $FILENAME_ONLY'
  2619.   [ "$PKG_FILE_LIST" = '' ] && [ "$PKGNAME" = "" ] \
  2620.     && PKGNAME="$(basename `grep -l "^ $FILENAME_ONLY\$" $builtins_without_busybox | sed "s#$BUILTIN_FILE_LIST_DIR/##g"` 2>/dev/null)"
  2621.  
  2622.   # if that didn't work, search inside builtin file lists of busybox for ' $FILENAME_ONLY'
  2623.   [ "$PKG_FILE_LIST" = '' ] && [ "$PKGNAME" = "" ] \
  2624.     && PKGNAME="$(basename `grep -l "^ $FILENAME_ONLY\$" "$BUILTIN_FILE_LIST_DIR/busybox" | sed "s#$BUILTIN_FILE_LIST_DIR/##g"` 2>/dev/null)"
  2625.  
  2626.   # apps in ADRV sfs dont have their files listed in their $PKGS_DIR/builtin_files/$pkgname.. so..
  2627.  
  2628.  
  2629.   # now check pkg names (not pkg contents) of builtins (EXCEPT busybox) for '$file'.. cos maybe we didnt find the file inside the file lists
  2630.   [ "$PKGNAME" = "" ] \
  2631.     && PKGNAME="`echo "$builtins_without_busybox" | grep -m1 "^${FILENAME_ONLY}\$" | sed "s#$BUILTIN_FILE_LIST_DIR/##g" 2>/dev/null`"
  2632.  
  2633.   # now look for '$file' in user installed repo list
  2634.   [ "$PKGNAME" = "" ] \
  2635.     && 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'|'`"
  2636.  
  2637.   # also look for '$file' in user/woof/devx installed repo list
  2638.   [ "$PKGNAME" = "" ] \
  2639.     && 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'|')"
  2640.  
  2641.  
  2642.   # we searched for an exact match in builtins, user installed, woof installed and devx pkgs, now try some fuzzier matches
  2643.  
  2644.   # try /$file_* in builtins
  2645.   [ "$PKGNAME" = "" ] \
  2646.     && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}_" "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2647.  
  2648.   # try $file-* in builtins
  2649.   [ "$PKGNAME" = "" ] \
  2650.     && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}-" "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_DIR/builtin_files/##g"` 2>/dev/null)"
  2651.  
  2652.   # try $file.* in builtins
  2653.   [ "$PKGNAME" = "" ] \
  2654.     && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}\." "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2655.  
  2656.   # try *file in builtin pkgs
  2657.   [ "$PKGNAME" = "" ] \
  2658.     && PKGNAME="$(basename `grep -l "${FILENAME_ONLY}"\$ "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2659.  
  2660.  
  2661.   # if we still didnt find it, look in user installed package lists, for FILENAME
  2662.   [ "$PKGNAME" = "" ] \
  2663.     && PKGNAME=`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" \
  2664.       | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2665.       | grep -m1 "|${FILENAME_ONLY}|" \
  2666.       | cut -f2 -d'|'` 2>/dev/null
  2667.  
  2668.   # if we still didnt find it, look in all installed package lists, for FILENAME
  2669.   [ "$PKGNAME" = "" ] \
  2670.     && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2671.       | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2672.       | grep -m1 "|${FILENAME_ONLY}|" \
  2673.       | cut -f2 -d'|'` 2>/dev/null
  2674.  
  2675.   # if we still didnt find it, look in all installed package lists, for *FILENAME
  2676.   [ "$PKGNAME" = "" ] \
  2677.     && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2678.       | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2679.       | grep -m1 "${FILENAME_ONLY}|" \
  2680.       | cut -f2 -d'|'` 2>/dev/null
  2681.  
  2682.   # if we still didnt find it, look in all installed package lists, for FILENAME*
  2683.   [ "$PKGNAME" = "" ] \
  2684.     && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2685.       | sed -e "s/^/|/" -e "s/\$/|/" \
  2686.       | grep -m1 "|${FILENAME_ONLY}" \
  2687.       | cut -f2 -d'|'` 2>/dev/null
  2688.  
  2689.  
  2690.   # clean up
  2691.   [ "$PKGNAME" = '.files' ] && PKGNAME=''
  2692.   PKGNAME="`echo "$PKGNAME" | head -1`"
  2693.  
  2694.   # now print pkgs which contain the given file ($1)
  2695.   if [ "$PKGNAME" != "" ];then
  2696.     echo "$PKGNAME"
  2697.     return 0
  2698.   else
  2699.     echo "File '$FILENAME' not found in any installed or built-in pkgs."
  2700.     exit 1
  2701.   fi
  2702. }
  2703.  
  2704.  
  2705.  
  2706. # pkg info funcs
  2707.  
  2708. pkg_contents(){                   # list package ($1) contents FUNCLIST
  2709.  
  2710.   # if no valid options, quit
  2711.   [ ! "$1" -o "$1" = "-" -o "$1" = " " ] && print_usage contents && exit 1
  2712.  
  2713.   # get settings
  2714.   . ${PKGRC}
  2715.  
  2716.   local PKGFILE
  2717.   local ext
  2718.   local PKGNAME
  2719.   local PKGNAME_ONLY
  2720.   local pkg_is_local_file
  2721.   local pkg_is_builtin
  2722.   local pkg_is_installed
  2723.   local PKGFLIST=''
  2724.  
  2725.   # get pkg extension
  2726.   ext=`get_pkg_ext "$1"`
  2727.  
  2728.   # get pkg name (includes version), but no extension or path
  2729.   PKGNAME="$(basename "$1" .$ext)"
  2730.   PKGNAME=`get_pkg_name "$PKGNAME"`
  2731.  
  2732.   # get pkg name without version
  2733.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  2734.  
  2735.   pkg_is_local_file=`is_local_pkg "$1"`
  2736.   pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY"`
  2737.   pkg_is_installed=`is_installed_pkg "$PKGNAME_ONLY"`
  2738.  
  2739.   # now we check various ways to find out the contents of
  2740.   # a pkg (either by *.files, user installed, woof, builtin, etc)
  2741.  
  2742.   [ "$pkg_is_local_file" = true ] && PKGFILE="$1"
  2743.  
  2744.   # try a file in the current dir if needed
  2745.   [ ! -f "$PKGFILE" ] && PKGFILE="${CURDIR}/${PKGNAME}.$ext"
  2746.   # check $WORKDIR if needed
  2747.   [ ! -f "$PKGFILE" ] && PKGFILE="${WORKDIR}/${PKGNAME}.$ext"
  2748.  
  2749.   # if the pkg is a local file
  2750.   if [ -f "$PKGFILE" ];then
  2751.     #list contents based on extension
  2752.     case "$ext" in
  2753.     sfs)
  2754.       unsquashfs -l "$PKGFILE"  | cut -f2-99 -d'/'| sed -e 's#^#/#g' 2>/dev/null | grep -v -E 'unsquashfs:|/squashfs-root|) to write' | grep -v "^/$"
  2755.     ;;
  2756.     deb)
  2757.       dpkg-deb -c "$PKGFILE" 2>/dev/null | grep -v "^/$"
  2758.      ;;
  2759.     pet|tar|tar**tcz|*txz|*tgz|*xz|*gz)
  2760.       # remove leading pkg name from each line of file list
  2761.       # (shown if listing *some* pkg file contents)
  2762.       tar -tf "$PKGFILE" 2>/dev/null \
  2763.         | sed -e "s#^./${PKGNAME}/#/#g" -e "s#^${PKGNAME}/#/#g" -e "s#^./##g" 2>/dev/null \
  2764.         | grep -v ^$ 2>/dev/null 2>/dev/null \
  2765.         | grep -v "^/$"
  2766.     ;;
  2767.     rpm)
  2768.       busybox rpm -qlp "$PKGFILE" 2>/dev/null | grep -v "^/$"
  2769.     ;;
  2770.     esac
  2771.     exit $?
  2772.   fi
  2773.  
  2774.   # if we are here, the pkg is not a downloaded pkg, so we build a
  2775.   # list of files by checking  *.files, woof, builtins ..
  2776.  
  2777.   # check if we need to (and can) get our pkg contents from builtins/PKGNAME
  2778.   local  need_to_check_builtins=`echo "$PKG_FLIST" | grep -m1 'packages/builtin_files/'`
  2779.  
  2780.   # if the pkg is a builtin, we will re-format the output of LIST to match the others (full paths on each line)
  2781.   if [ "$need_to_check_builtins" != '' -a "$pkg_is_builtin" = true ];then
  2782.  
  2783.     # reset the list of pkg files, we will re-build it
  2784.     rm $TMPDIR/pkg_file_list 2>/dev/null
  2785.  
  2786.     # first we get the package contents from $PKGS_DIR/builtin_files/$PKGNAME_ONLY
  2787.     cat "$PKG_FLIST" 2>/dev/null | while read line
  2788.     do
  2789.       # parse it, so we get a full path to file on each line
  2790.       if [ "`echo "$line" | grep '^/'`" != '' ];then
  2791.         # set the dir to use in our file list
  2792.         dir="$line"
  2793.       else
  2794.         # keep previous dir
  2795.         dir="$dir"
  2796.       fi
  2797.  
  2798.       # create our new line (a full file path) to $LIST
  2799.       line_to_add="$dir/`echo "$line" | cut -f2 -d' '`"
  2800.  
  2801.       # if only a dir, skip it
  2802.       [ "$line" = "$dir" ] && continue
  2803.  
  2804.       # if its already added, skip it
  2805.       [ "`grep -m1 "$line_to_add" ${TMPDIR}/pkg_file_list 2>/dev/null `" != '' ] && continue
  2806.  
  2807.       # if its not a file on the system (it should be), skip it
  2808.       [ ! -f "$line_to_add" ] && continue
  2809.  
  2810.       # all should be ok, add the line to our list
  2811.       echo "$line_to_add" >> $TMPDIR/pkg_file_list
  2812.  
  2813.     done
  2814.  
  2815.     # now get our pkg contents list, it might have been re-formatted (if a builtin)
  2816.     PKG_FLIST="`cat ${TMPDIR}pkg_file_list 2>/dev/null`"
  2817.  
  2818.     # last resort, if we lost our file list or still dont have, try the basics again
  2819.     [ "$PKG_FLIST" = '' ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}"'*.files' 2>/dev/null)"
  2820.  
  2821.     # clean up the list a bit
  2822.     [ "$PKG_FLIST" != '' ] && PKG_FLIST="`echo "$PKG_FLIST" | grep -v ' ' | grep -v "^\$" | sort | uniq`"
  2823.  
  2824.     # and clean up the tmp files
  2825.     rm ${TMPDIR}pkg_file_list 2>/dev/null
  2826.   fi
  2827.  
  2828.   # try PKGNAME_ONLY.files (exact match)
  2829.   PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}.files" 2>/dev/null)"
  2830.  
  2831.   # try finding PKGNAME.files (exact match)
  2832.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}.files" 2>/dev/null)"
  2833.  
  2834.   # try the builtins files (exact match)
  2835.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$BUILTIN_FILE_LIST_DIR" -maxdepth 1 -type f -name "$PKGNAME_ONLY")"
  2836.  
  2837.   # try PKGNAME (exact match) in user installed pkgs
  2838.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -m1 ^"$PKGNAME\$" 2>/dev/null`.files"
  2839.  
  2840.   # try PKGNAME (exact match) in all installed pkgs
  2841.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME\$" 2>/dev/null`.files"
  2842.  
  2843.   # try PKGNAME_ONLY (exact match) in all installed pkgs
  2844.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f2 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME_ONLY\$" 2>/dev/null`.files"
  2845.  
  2846.  
  2847.   # no exact matches found, try fuzzy searches..
  2848.  
  2849.   # try PKGNAME*.files
  2850.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "/${PKGNAME}"'*.files'  2>/dev/null)"
  2851.  
  2852.   # try finding *PKGNAME.files
  2853.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name '*'"${PKGNAME}.files" 2>/dev/null)"
  2854.  
  2855.   # try ^PKGNAME_ONLY[_-] in user installed pkgs
  2856.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -Em1 "^$PKGNAME_ONLY[_-]" 2>/dev/null`.files"
  2857.  
  2858.   # try PKGNAME_ONLY* in user installed pkgs only
  2859.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -m1 ^"$PKGNAME_ONLY" 2>/dev/null`.files"
  2860.  
  2861.   # try PKGNAME_ONLY-* (any installed pkgs)
  2862.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -Em1 ^"${PKGNAME_ONLY}[_-]" 2>/dev/null`.files"
  2863.  
  2864.   # try PKGNAME_ONLY* (any installed pkgs)
  2865.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME_ONLY" 2>/dev/null`.files"
  2866.  
  2867.   # try PKGNAME_ONLY*.files
  2868.   [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PKGS_DIR" -maxdepth 1 -type f -name "/${PKGNAME_ONLY}"'*.files'  2>/dev/null)"
  2869.  
  2870.  
  2871.  
  2872.   #if we found a list of files
  2873.   if [ "$PKG_FLIST" != "" ];then
  2874.  
  2875.     print_cmd=echo
  2876.     # PKG_FLIST just might contain a path to the pkg contents
  2877.     # themselves (a *.files, or a file in builtin_files/*).. so if
  2878.     # its a file path, we will cat it, if not, its the pkg contents
  2879.     # themselves, we echo it
  2880.     if [ "`echo "$PKG_FLIST" | grep -m1 '/builtin_files/'`" != '' -o "`echo "$PKG_FLIST" | grep -m1 "packages/$PKGNAME"`" != '' ];then
  2881.       print_cmd=cat
  2882.     fi
  2883.  
  2884.     $print_cmd "$PKG_FLIST" | grep -v "^/$" 2>/dev/null
  2885.  
  2886.   else # if no files found
  2887.     if [ "$PKGNAME" != '' ];then
  2888.       INST_CHECK="`is_installed_pkg $PKGNAME 2>/dev/null`"
  2889.       if [ "$INST_CHECK" != true -o "$pkg_is_local_file" = false ];then
  2890.         error "Package must be installed, downloaded or built-in."
  2891.       else
  2892.         error "Could not get package contents, unable to get file list."
  2893.       fi
  2894.     else
  2895.       error "Could not get name of package."
  2896.     fi
  2897.   fi
  2898. }
  2899.  
  2900.  
  2901. pkg_entry(){                      # show pkg ($1) repo entry, each field on a new line FUNCLIST
  2902.  
  2903.   # exit if no valid opts
  2904.   [ ! "$1" -o "$1" = '-' ] && print_usage pkg-entry && exit 1
  2905.  
  2906.   local EX
  2907.   local PKGNAME
  2908.   local PKGNAME_ONLY
  2909.  
  2910.   # get pkg extension
  2911.   EX=`get_pkg_ext "$1"`
  2912.  
  2913.   # get pkg name with version, but no extension or path
  2914.   PKGNAME="$(basename "$1" .$EX)"
  2915.  
  2916.   # dont rely on the string the user gave us, try to get the exact match
  2917.   PKGNAME=`get_pkg_name "$PKGNAME"`
  2918.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  2919.  
  2920.   PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "|$PKGNAME|")"
  2921.   [ "$PKG_ENTRY" = '' ] && PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "^$PKGNAME|")"
  2922.   [ "$PKG_ENTRY" = '' ] && PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "|$PKGNAME_ONLY|")"
  2923.   if [ "$PKG_ENTRY" = '' ];then
  2924.     echo "$1 not found in $REPOFILE"
  2925.     exit 1
  2926.   else
  2927.     echo "$PKG_ENTRY" | tr '|' '\n' | grep -v '^$'
  2928.   fi
  2929.   return 0
  2930. }
  2931.  
  2932.  
  2933. pkg_status(){                     # print package ($1) name, status, deps, etc FUNCLIST
  2934.  
  2935.   # exit if no valid options
  2936.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-status && exit 1
  2937.  
  2938.   # get current repo name
  2939.   . ${PKGRC}
  2940.  
  2941.   local EX
  2942.   local PKGNAME=''
  2943.   local PKGNAME_ONLY=''
  2944.   local PKGFILE=''
  2945.   local MSG=''
  2946.   local install_status=''
  2947.   local pkg_found=false
  2948.   local pkg_repo=''
  2949.   local pkg_repo_file=''
  2950.   local prev_repo=${REPONAME}
  2951.  
  2952.   # get pkg extension
  2953.   EX=`get_pkg_ext "$1"`
  2954.  
  2955.   # get pkg name with version, but no extension or path
  2956.   PKGNAME="$(basename "$1" .$EX)"
  2957.  
  2958.   # dont rely on the string the user gave us, try to get the exact match
  2959.   PKGNAME=`get_pkg_name "$PKGNAME"`
  2960.  
  2961.   # get pkg name without version
  2962.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  2963.  
  2964.   [ "$PKGNAME" = '' ] && error "Can't find $1" && exit 1
  2965.  
  2966.   # get install status of pkg (installed or not)
  2967.   [ "`is_installed_pkg $PKGNAME`" = true ] && install_status="installed" || install_status="not installed"
  2968.  
  2969.   # if pkg is installed, find out from where
  2970.   if [ "$install_status" = "installed" ];then
  2971.  
  2972.     # check user installed pkgs for $PKGNAME
  2973.     pkg_found=`LANG=C is_usr_pkg "${PKGNAME}"`
  2974.     [ "$pkg_found" = true ] && install_status="installed (user)"
  2975.  
  2976.     # if pkg not found yet, check if pkg is from the devx
  2977.     if [ -f "$PKGS_DIR/devx-only-installed-packages" -a "$pkg_found" = false ];then
  2978.       pkg_found=`LANG=C is_devx_pkg "${PKGNAME}"`
  2979.       [ "$pkg_found" = true ] && install_status="installed (in devx)"
  2980.     fi
  2981.  
  2982.     # check builtins for PKGNAME_ONLY, if it exists, its a builtin pkg
  2983.     if [ -d "$BUILTIN_FILE_LIST_DIR/" -a "$pkg_found" = false ];then
  2984.       pkg_found=`LANG=C is_builtin_pkg "${PKGNAME_ONLY}"`
  2985.       [ "$pkg_found" = true ] && install_status="installed (builtin)"
  2986.     fi
  2987.  
  2988.     # last gasp, if pkg not found yet, check if pkg if listed in layers-installed packages
  2989.     if [ -f "$PKGS_DIR/layers-installed-packages" -a "$pkg_found" = false ];then
  2990.       pkg_found=$(LANG=C grep -m1 "^${PKGNAME}|" "$LAYER_INST_PKGS_FILE")
  2991.  
  2992.       [ "$pkg_found" = '' ] && install_status="installed (layers)"
  2993.     fi
  2994.  
  2995.   fi
  2996.  
  2997.   # get the repo of this pkg, if needed
  2998.   [ "$pkg_repo" = '' ] && pkg_repo="`which_repo "$PKGNAME" 2>/dev/null | cut -f2 -d' '`"
  2999.  
  3000.   # if we got a repo name, get the repo file
  3001.   [ "$pkg_repo" != '' ] && pkg_repo_file="$(grep -m1 "^$pkg_repo|" ${HOME}/.pkg/sources | cut -f3 -d'|')"
  3002.  
  3003.   # if we have a repo to search for pkg info
  3004.   if [ "$pkg_repo_file" != "" ];then
  3005.  
  3006.     # get package description from its repo entry
  3007.     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`"
  3008.  
  3009.     if [ "$pkg_desc" = '' ];then
  3010.       pkg_desc="`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$PKGS_DIR/Packages-"* 2>/dev/null| grep -m1 "${PKGNAME}|" | cut -f10 -d'|' | head -1`"
  3011.     fi
  3012.  
  3013.     # get size of pkg
  3014.     pkg_size=`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/$pkg_repo_file" 2>/dev/null | cut -f6 -d'|' | head -1`
  3015.  
  3016.     # add K to end of pkg_size, if not there already
  3017.     [ "$pkg_size" != '' ] && pkg_size="${pkg_size}K" && pkg_size="${pkg_size//KK/K}"
  3018.  
  3019.     # if called with -PS, we get the full info (where we sort deps missing or installed)
  3020.     if [ "$FULL_PKG_STATUS" = true ];then
  3021.  
  3022.       # if pkg has many deps, checking the deps might take a while, print a 'please wait' msg
  3023.       please_wait=false
  3024.       # count deps of pkg
  3025.       [ "`has_deps "$PKGNAME"`" = true ] && please_wait=true
  3026.       [ "$please_wait" = true ] && echo -ne "Please wait.. Gathering dependency information.\n"
  3027.  
  3028.       set_current_repo $pkg_repo 1>/dev/null
  3029.       # sort deps into 2 lists: missing deps and installed deps
  3030.       find_deps "$PKGNAME"
  3031.       set_current_repo $prev_repo 1>/dev/null
  3032.  
  3033.       # create a nicely formatted, coloured list of deps, green for installed, yellow for missing
  3034.       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}"
  3035.       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}"
  3036.  
  3037.       DEPS_ENTRY="Installed deps: ${INSTALLED_DEPS_MSG:-None}
  3038. Missing deps:   ${MISSING_DEPS_MSG:-None}"
  3039.  
  3040.     else
  3041.  
  3042.       DEPS_ENTRY="Dependencies:   `list_deps "$PKGNAME" 2>/dev/null`"
  3043.  
  3044.     fi
  3045.  
  3046.     #250613 added desc
  3047.     MSG="
  3048. Name:           ${PKGNAME}
  3049. Description:    `echo ${pkg_desc:-No description} | fold -w 50 -s | sed '2,10 s/^/                /g'`
  3050. Size:           ${pkg_size:-Unknown}
  3051. Status:         ${install_status:-Unknown}
  3052. In Repo:        ${pkg_repo:-Not in any repos}
  3053. Repo file:      `basename ${pkg_repo_file:-Not in any repositories} 2>/dev/null`
  3054. $DEPS_ENTRY"
  3055.  
  3056.   fi
  3057.  
  3058.   # if not found in any repo, maybe a woof or alien (user-installed) package
  3059.   if [ "$MSG" = "" ];then #if nothing found in any repo
  3060.  
  3061.     PKGFILE="`list_downloaded_pkgs | grep -m1 "^$PKGNAME"`"
  3062.  
  3063.     # if the pkg is a downloaded file (in WORKDIR)
  3064.     if [ -f "$WORKDIR/$PKGFILE" ];then
  3065.  
  3066.       # get the file, and get its file size
  3067.       PKGFILE="$WORKDIR/${PKGFILE}"
  3068.       [ "$pkg_size" = '' ] && pkg_size="`du -s -k "$PKGFILE" | cut -f1`K"
  3069.       [ "$pkg_size" = '' ] && pkg_size="`grep -m1 "|${PKGNAME_ONLY}|" "${SPEC_DB_PATHS[@]" | cut -f6 -d'|' | head -1`"
  3070.  
  3071.  
  3072.       # create msg for downloaded pkgs
  3073.       MSG="Name:           ${PKGNAME}
  3074. Size:           ${pkg_size:-Unknown}
  3075. Status:         Downloaded
  3076. Note:           Downloaded package, not in any repo.
  3077. $DEPS_ENTRY"
  3078.  
  3079.     # else, search for exact match, then pkg-*, then pkg_*, then pkg* in installed pkgs
  3080.     elif [ "$(grep -m1 "|${PKGNAME_ONLY}|" "$USER_INST_PKGS_FILE" 2>/dev/null)"   \
  3081.       -o "$(grep -m1 "^${PKGNAME}|" "$USER_INST_PKGS_FILE" 2>/dev/null)"   \
  3082.       -o "`grep -m1 "^${PKGNAME}|" "${SPEC_DB_PATHS[@]" 2>/dev/null`"   \
  3083.       -o "`grep -m1 "^${PKGNAME}-" "${SPEC_DB_PATHS[@]" 2>/dev/null`" \
  3084.       -o "`grep -m1 "^${PKGNAME}_" "${SPEC_DB_PATHS[@]" 2>/dev/null`" \
  3085.       -o "`grep -m1 "^${PKGNAME}" "${SPEC_DB_PATHS[@]" 2>/dev/null`" ];then
  3086.  
  3087.       # get deps and size from its entry in user-installed-packages
  3088.       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`"
  3089.       [ "$DEPS_ENTRY" = '' ] && DEPS_ENTRY="Dependencies:   `grep -m1 "^$PKGNAME" "${SPEC_DB_PATHS[@]" | cut -f9 -d'|' | sed -e 's/,+/,/' -e 's/^+//' -e 's/,$//' 2>/dev/null`"
  3090.       pkg_size=`LANG=C grep -m1 "|$PKGNAME_ONLY|" "${SPEC_DB_PATHS[@]" | cut -f6 -d'|' | head -1`
  3091.       # add K to end of pkg_size, if not there already
  3092.       [ "$pkg_size" != '' ] && pkg_size="${pkg_size}K" && pkg_size="${pkg_size//KK/K}"
  3093.  
  3094.       # create msg for user installed pkgs
  3095.       MSG="Name:      ${PKGNAME}
  3096. Size:           ${pkg_size:-Unknown}
  3097. Status:         ${install_status}
  3098. Repo:           Alien package, not in any repo.
  3099. $DEPS_ENTRY"
  3100.  
  3101.     else # pkg wasn't found, it's unknown to Pkg
  3102.       MSG="$PKGNAME not found.
  3103.  
  3104. Here are some packages in other repos:"
  3105.       PLIST="`which_repo ${PKGNAME}`"
  3106.       [ "$PLIST" != "" ] && MSG="$MSG
  3107. $PLIST"
  3108.       # create msg for alien pkgs
  3109.       MSG="$MSG
  3110.  
  3111. Name:           ${PKGNAME}
  3112. Status:         ${install_status:-Unknown}
  3113. Repo:           Alien package, not in $REPONAME repo.
  3114. $DEPS_ENTRY"
  3115.  
  3116.     fi
  3117.  
  3118.   fi
  3119.  
  3120.   # print message
  3121.   if [ "$MSG" != "" ];then
  3122.     # now output the final msg
  3123.     echo -e "$MSG" | grep -v ^$
  3124.     menu_entry_msg "$PKGNAME"
  3125.     echo
  3126.   else
  3127.     not_found "${PKGNAME}"
  3128.     exit 1
  3129.   fi
  3130. }
  3131.  
  3132.  
  3133. # pkg creation funcs
  3134.  
  3135. prepare_petbuild(){               # get 01mickos petbuild system from Git, if needed FUNCLIST
  3136.  
  3137.   local gitcheck=`which git`
  3138.  
  3139.   # exit if no devx
  3140.   [ "`which gcc`" = '' ] \
  3141.     && echo "You need the devx SFS installed to compile packages." \
  3142.     && rm /tmp/pkg/petbuild_prepared 2>/dev/null \
  3143.     && exit 3
  3144.  
  3145.   # exit if no git
  3146.   [ "`$gitcheck`" = '' ] \
  3147.     && echo "You need git installed to auto-install petbuild." \
  3148.     && rm /tmp/pkg/petbuild_prepared 2>/dev/null \
  3149.     && exit 3
  3150.  
  3151.   if [ ! -d /usr/share/petbuild ];then
  3152.     rm /tmp/pkg/petbuild_prepared 2>/dev/null && exit 1
  3153.   fi
  3154.  
  3155.   # if petbuild prepared flag not yet set
  3156.   if [ ! -f /tmp/pkg/petbuild_prepared ];then
  3157.  
  3158.     # backup old petbuild if installed
  3159.     [ -d /usr/share/petbuild/ ] && mv /usr/share/petbuild/ /usr/share/petbuild.backup/ 2>/dev/null
  3160.  
  3161.     # remove the original petbuild dir (we have a backup)
  3162.     if [ -d /usr/share/petbuild.backup/ ];then
  3163.       rm -rf /usr/share/petbuild 2>/dev/null
  3164.     fi
  3165.  
  3166.     # clone petbuild into /usr/share/petbuild
  3167.     git clone https://github.com/puppylinux-woof-CE/petbuilds.git /usr/share/petbuild &>/dev/null
  3168.  
  3169.     # if still no petbuild dir in /usr/share, tell user to install themselves
  3170.     if [ ! -d /usr/share/petbuild ];then
  3171.       echo >&2
  3172.       echo "Run this command to download PetBuild:" >&2
  3173.       echo >&2
  3174.       echo -e " ${green}git clone https://github.com/puppylinux-woof-CE/petbuilds /usr/share/petbuild${endcolour}" >&2
  3175.       echo >&2
  3176.       echo "Alternatively, use a different build tool backend by changing BUILDTOOL= " >&2
  3177.       echo "to one of the options below, in the $PKGRC file:" >&2
  3178.       echo "petbuild, buildpet, sbopkg or src2pkg" >&2
  3179.       echo >&2
  3180.  
  3181.       exit 1
  3182.     fi
  3183.  
  3184.     # go into buildpet dir, check which Pup we have ($DISTRO_DB_SUBNAME)
  3185.     # and checkout the right branch for the running system
  3186.     cd /usr/share/petbuild
  3187.  
  3188.     # check the puppy running and checkout the relevant branch
  3189.     if [ "`echo $DISTRO_DB_SUBNAME | grep slacko`" != '' ];then
  3190.       if [ "`echo $DISTRO_DB_SUBNAME | grep '14.2'`" != '' ];then
  3191.         git checkout slacko_142
  3192.       else
  3193.         git checkout slacko_141
  3194.       fi
  3195.     elif [ "`echo $DISTRO_DB_SUBNAME | grep tahrpup`" ];then
  3196.       git checkout tahrpup
  3197.     elif [ "`echo $DISTRO_DB_SUBNAME | grep stretch`" ];then
  3198.       git checkout stretch || git checkout tahrpup
  3199.     elif [ "`echo $DISTRO_DB_SUBNAME | grep xenialpup`" ];then
  3200.       git checkout xenialpup || git checkout tahrpup
  3201.     elif [ "$DISTRO_DB_SUBNAME" != '' ];then
  3202.       git checkout tahrpup
  3203.     else
  3204.       echo "No pet builds available for your system ($DISTRO_DB_SUBNAME),"
  3205.       echo "using buildpet instead.."
  3206.       rm -rf /usr/share/petbuild 2>/dev/null
  3207.     fi
  3208.  
  3209.     # buildpet setup finished, create flag
  3210.     echo 'true' > /tmp/pkg/petbuild_prepared
  3211.  
  3212.     cd "$CURDIR"
  3213.   fi
  3214. }
  3215.  
  3216.  
  3217. pkg_build(){                      # build package ($1) from source (see BUILDTOOL in pkgrc) FUNCLIST
  3218.  
  3219.   # exit if devx not installed
  3220.   [ "`which gcc`" = "" ]   && echo "You need the devx SFS installed to compile." && exit 1
  3221.  
  3222.   # get the settins from RC file
  3223.   . ${PKGRC}
  3224.  
  3225.   # we do a different build method for each supported build tool
  3226.   case $BUILDTOOL in
  3227.  
  3228.     petbuild) # by 01micko
  3229.  
  3230.       # use git to install the latest petbuild
  3231.       prepare_petbuild
  3232.  
  3233.       # if petbuild not installed, quit
  3234.       [ ! -d /usr/share/petbuild ] && error "PetBuild not installed at /usr/share/petbuild." && exit 3
  3235.  
  3236.       # petbuild needs a package name, or exit
  3237.       [ ! "$1" -o "$1" = "-" ] && print_usage pkg-build && exit 1 #220613 #250613
  3238.  
  3239.       # get pkg extension
  3240.       EX=`get_pkg_ext "$1"`
  3241.  
  3242.       # get pkg name only, no extension or path
  3243.       PKGNAME="$(basename "$1" .$EX)"
  3244.  
  3245.       # get petbuild PKGNAME, then build using 01mickos petbuild
  3246.       BUILDSCRIPT="`find /usr/share/petbuild -iname ${PKGNAME}"*.petbuild"| grep -m1 "$PKGNAME"`"
  3247.  
  3248.       # if we got a build script
  3249.       if [ -f "$BUILDSCRIPT" ];then
  3250.         cd `dirname "$BUILDSCRIPT"`
  3251.         # compile the pkg
  3252.         bash *.petbuild
  3253.         # after build, move any pets created to WORKDIR
  3254.         mv /usr/share/petbuild/0pets_out/*.pet "$WORKDIR" 2>/dev/null
  3255.         # back to prev dir (WORKDIR)
  3256.         cd -
  3257.       fi
  3258.  
  3259.       # if build script not found, exit
  3260.       [ ! -f "$BUILDSCRIPT" ] && echo "Build script for '$PKGNAME' not found in /usr/share/petbuild/" && exit 1
  3261.  
  3262.       # get the packages we just moved to WORKDIR
  3263.       PKGFILES="`find "$WORKDIR" -iname "$PKGNAME*.pet"`"
  3264.  
  3265.       # list any packages we just built
  3266.       [ "$PKGFILES" != '' ] && echo -e "${green}Success:${endcolour} Packages in $WORKDIR:" && echo "$PKGFILES"
  3267.     ;;
  3268.  
  3269.     buildpet) # by Tman/iguleder
  3270.  
  3271.       # exit if buildpet dir not found
  3272.       [ ! -d /usr/share/buildpet ] && error "buildpet not installed." && exit 1
  3273.  
  3274.       # buildpet expects a PKGNAME, or exit
  3275.       [ ! "$1" -o "$1" = "-" ] && print_usage pkg-build && exit 1
  3276.  
  3277.       # get pkg extension
  3278.       EX=`get_pkg_ext "$1"`
  3279.  
  3280.       # get pkg name (with version), no extension or path
  3281.       PKGNAME="$(basename "$1" .$EX)"
  3282.  
  3283.       # get the buildpet script of PKGNAME
  3284.       BUILDSCRIPT="`find /usr/share/buildpet/ -name $PKGNAME"*"`"
  3285.  
  3286.       # if build script not found, exit
  3287.       [ ! -f "$BUILDSCRIPT" ] && echo "Build script for '$PKGNAME' not found in /usr/share/buildpet/" && exit 1
  3288.  
  3289.       # now compile the package
  3290.       PKG_CONFIGURE="$PKG_CONFIGURE" PKG_CFLAGS="$PKG_CFLAGS" buildpet $BUILDSCRIPT
  3291.  
  3292.     ;;
  3293.  
  3294.     src2pkg)  # by amigo
  3295.  
  3296.       ### This code is a horribly simple wrapper to a great tool..
  3297.       ### Implement all src2pkg options here at some point..
  3298.       ##
  3299.       ### We should pass all options to src2pkg, and make it build a
  3300.       ### (petbuild|buildpet) buildscipt on successful compile
  3301.  
  3302.       # exit if src2pkg not installed
  3303.       [ "`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
  3304.  
  3305.       # exit if $1 not given or valid
  3306.       [ ! "$1" -o "$1" = "-" ]   && print_usage pkg-build && exit 1
  3307.  
  3308.       # show src2pkg help if user supplied any of the help options
  3309.       if [ "$1" = '-h'  -o "$1" = '-hh'  -o "$1" = '--help' -o "$1" = '--more-help' -o "$1" = '--list' ];then
  3310.         src2pkg $1 | sed -e "s/  src2pkg /  $SELF -pb /g"
  3311.         echo -e "\n   See 'src2pkg' by amigo"
  3312.         exit 0
  3313.       fi
  3314.  
  3315.       # get pkg extension.. not really needed here
  3316.       EX=`get_pkg_ext "$1"`
  3317.  
  3318.       # use amigos src2pkg
  3319.       src2pkg $1
  3320.  
  3321.       # if src2pkg exited without error, copy any pets it made to WORKDIR
  3322.       [ $? -eq 0 ] && mv /tmp/*.pet "$WORKDIR" 2>/dev/null
  3323.  
  3324.     ;;
  3325.  
  3326.     sbopkg)   # slackware peeps
  3327.  
  3328.       # exit if not installed
  3329.       [ "`which sbopkg`" = '' ] && error "Sbopkg not installed." && exit 3
  3330.  
  3331.       # exit if no valid options
  3332.       [ ! "$1" -o "$1" = "-" ]  && print_usage pkg-build && exit 1
  3333.  
  3334.       sbopkg -b "$1"
  3335.  
  3336.       # move any built pkgs to WORKDIR.. need a better way to do this
  3337.       if [ "`find /tmp/* -iname $1*.t*`" != '' ];then
  3338.         mv /tmp/*.tgz "$WORKDIR" 2>/dev/null
  3339.         mv /tmp/*.txz "$WORKDIR" 2>/dev/null
  3340.         mv /tmp/*.tar.xz "$WORKDIR" 2>/dev/null
  3341.         echo -e "DONE... The package should be in $WORKDIR."
  3342.       fi
  3343.  
  3344.     ;;
  3345.  
  3346.   *)
  3347.     # get pkg name only, no extension or path
  3348.     PKGNAME="$(basename "$1" .$EX)"
  3349.  
  3350.     echo "Cannot compile '$PKGNAME', no build system installed."
  3351.     echo
  3352.     echo "Please install one of the following:"
  3353.     echo " * petbuild by 01micko: http://murga-linux.com/puppy/viewtopic.php?t=96027"
  3354.     echo " * buildpet by Tman:    http://murga-linux.com/puppy/viewtopic.php?t=81056"
  3355.     echo " * src2pkg  by amigo:   http://distro.ibiblio.org/amigolinux/download/src2pkg/"
  3356.     echo " * sbopkg   by various: https://www.sbopkg.org/downloads.php"
  3357.     echo
  3358.     echo "Then set BUILDTOOL to either petbuild, buildpet, src2pkg or sbopkg "
  3359.     echo "in $PKGRC to enable building packages from source."
  3360.     echo
  3361.     echo "NOTE:"
  3362.     echo "01mickos petbuild should be installed to /usr/share/petbuild"
  3363.     echo "And Tmans buildpet should be installed to /usr/share/buildpet"
  3364.   ;;
  3365.   esac
  3366. }
  3367.  
  3368.  
  3369. pkg_repack(){                     # create package ($1) from its *.files list FUNCLIST
  3370.  
  3371.   # exit if no valid options
  3372.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-repack && exit 1
  3373.  
  3374.   local list=''
  3375.   local pkg_ext=''
  3376.   local PKGNAME=''
  3377.   local PKGNAME_ONLY=''
  3378.   local dir=''
  3379.   local build_number=''
  3380.  
  3381.   # get pkg extension
  3382.   pkg_ext=`get_pkg_ext "$1"`
  3383.  
  3384.   #get pkg name only, no extension or path
  3385.   PKGNAME="$(LANG=C basename "$1" .$pkg_ext)"
  3386.  
  3387.   # assume the file name from $1
  3388.   PKGFILE="${CURDIR}/${PKGNAME}.$pkg_ext"
  3389.  
  3390.   # don't rely on the given pkg name string, get the full name from repo if poss
  3391.   PKGNAME=`get_pkg_name "$PKGNAME"`
  3392.  
  3393.   # get pkg name without version
  3394.   PKGNAME_ONLY="`get_pkg_name_only "${PKGNAME}"`"
  3395.  
  3396.   # if the list is empty, pkg is not user installed or built in, cant show contents
  3397.   [ "`is_installed_pkg "$PKGNAME"`" = false ] && echo "$PKGNAME needs to be installed." && exit 1
  3398.  
  3399.   # if the package to built already exists, ask user to delete it
  3400.   [ -f "${PKGFILE}" ] && echo "$PKGNAME.$pkg_ext already exists in $CURDIR" && rm -f "${PKGFILE}" 2>/dev/null
  3401.  
  3402.   # if pkg exists, user didn't delete it
  3403.   [ -f "${PKGFILE}" ] && exit 0
  3404.  
  3405.   # get the build number, and increment by one
  3406.   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'|'`"
  3407.   build_number=${build_number:-0}
  3408.   build_number="-$(($build_number + 1))"
  3409.  
  3410.   # process the file list, copy each file to our pkg folder
  3411.   pkg_contents "$PKGNAME_ONLY" | while read line
  3412.   do
  3413.     if [ -f "$line" ]; then
  3414.       linedir="$(dirname "${line}")"
  3415.       [ ! -d "${CURDIR}/$PKGNAME/${linedir}" ] && mkdir -p "${CURDIR}/$PKGNAME/${linedir}"
  3416.       cp -p -P "$line" "${CURDIR}/${PKGNAME}/${linedir}"
  3417.     fi
  3418.   done
  3419.  
  3420.   sync
  3421.  
  3422.   # make sure we populated a pkg folder, ready to package up
  3423.   [ ! -d "${CURDIR}/${PKGNAME}/" ] && error "No '$PKGNAME' directory in $CURDIR" && exit 5
  3424.  
  3425.   # pkg folder should be populated, now package it up and print final msg
  3426.   dir2pet "${CURDIR}/${PKGNAME}/" "$build_number"
  3427.   rm -rf "${CURDIR}/${PKGNAME}/" 2>/dev/null
  3428.   rm -rf "${CURDIR}/${PKGNAME}$build_number/" 2>/dev/null
  3429.   sync
  3430. }
  3431.  
  3432.  
  3433. pkg_unpack(){                     # extract/unpack $1 to current dir FUNCLIST
  3434.  
  3435.   # exit if not valid usage
  3436.   [ ! -f "$1" ] && print_usage unpack && exit 1
  3437.  
  3438.   local PKGNAME
  3439.   local PKGFILE
  3440.   local PKGEXT
  3441.   local comp
  3442.  
  3443.   # get pkg details
  3444.   PKGFILE="$1"
  3445.   PKGNAME=`get_pkg_name "$PKGFILE"`
  3446.   PKGEXT=`get_pkg_ext "$PKGFILE"`
  3447.  
  3448.   # exit if we dont have enough info
  3449.   [ "$PKGEXT" = '' ]  && error "Cant get package extension" && exit 1
  3450.   [ ! -f "$PKGFILE" ] && error "Cant find $1" && exit 6
  3451.   [ "$PKGNAME" = '' ] && error "Cant get PKGNAME" && exit 3
  3452.  
  3453.   # support overriding the output dir with $2
  3454.   if [ "$2" != "" ];then
  3455.     PKGNAME="$2"
  3456.   fi
  3457.  
  3458.   # determine compression utility
  3459.   case $PKGEXT in
  3460.  
  3461.     deb)
  3462.       mkdir "$PKGNAME" 2>/dev/null
  3463.       rm -rf "$PKGNAME"/* 2>/dev/null
  3464.       dpkg-deb -x "$PKGFILE" "$PKGNAME"    # extracts main pkg contents
  3465.       result=$?
  3466.       dpkg-deb -e "$PKGFILE" "$PKGNAME"/DEBIAN # extracts deb control files
  3467.       [ $result -eq 0 ] && echo -e "${green}Extracted${endcolour}: ${magenta}`basename $PKGFILE`${endcolour}" || error -e "${red}Error${endcolour}: Cannot extract $PKGFILE"
  3468.       return $result
  3469.       ;;
  3470.  
  3471.     rpm)
  3472.       mkdir "${PKGNAME}" 2>/dev/null
  3473.       rm -rf "$PKGNAME"/* 2>/dev/null
  3474.       # create dir called $PKGNAME, cd into it, extract the rpm in there
  3475.       cp "$PKGFILE" "$PKGNAME/"
  3476.       cd "$PKGNAME" 1>/dev/null
  3477.       # now extract the rpm contents into current dir
  3478.       exploderpm -x "$PKGFILE" &>/dev/null
  3479.       result=$?
  3480.       # clean up and leave
  3481.       rm -f *.rpm 2>/dev/null
  3482.       cd - 1>/dev/null
  3483.       # final msg
  3484.       [ $result -eq 0 ] && echo -e "${green}Success${endcolour}: File ${magenta}`basename $PKGFILE`${endcolour} extracted." || error "Cannot extract $PKGFILE"
  3485.       return $result
  3486.       ;;
  3487.  
  3488.     sfs)
  3489.  
  3490.       mkdir "/${PKGNAME}" 2>/dev/null
  3491.       rm -rf "$PKGNAME"/* 2>/dev/null
  3492.  
  3493.       # make mnt dir, mount sfs
  3494.       mkdir "/mnt/${PKGNAME}" 2>/dev/null
  3495.       mount -t squashfs "$PKGFILE" /mnt/"$PKGNAME" -o loop 1>/dev/null || { error "Could not mount $PKGFILE"; exit 3; }
  3496.       # copy sfs contents into ./$PKGNAME
  3497.       cp -a -Rf --remove-destination /mnt/"$PKGNAME" "$PKGNAME" || { error "Failed copying files from /mnt/$PKGNAME to ./$PKGNAME"; exit 4; }
  3498.       result=$?
  3499.       # clean up
  3500.       umount "/mnt/${PKGNAME}"
  3501.       rmdir "/mnt/${PKGNAME}"
  3502.       # final msg
  3503.       [ $result -eq 0 ] && echo -e "${green}Success${endcolour}: File ${magenta}`basename $PKGFILE`${endcolour} extracted." || { error "Cannot extract $PKGFILE"; exit 7; }
  3504.       return $result
  3505.       ;;
  3506.     pet)  file -b "$PKGFILE" | grep -i -q "^xz" && comp=xz || comp=gzip ;;
  3507.     tgz)  comp=gzip ;;
  3508.     gz)   comp=gzip ;;
  3509.     tbz)  comp=bzip2 ;;
  3510.     bz2)  comp=bzip2 ;;
  3511.     tlz)  comp=lzma ;;
  3512.     lzma) comp=lzma ;;
  3513.     txz)  comp=xz ;;
  3514.     xz)   comp=xz ;;
  3515.   esac
  3516.   sync
  3517.  
  3518.   # if pkg is extractable with tar, then unpack
  3519.   case $PKGEXT in
  3520.   pet|tgz|gz|tbz|bz2|tlz|lzma|txz|xz)
  3521.     ( 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" )
  3522.     ;;
  3523.   esac
  3524.  
  3525.   # return
  3526.   return ${result:-0}
  3527.  
  3528. }
  3529.  
  3530.  
  3531. pkg_combine(){                    # combine a pkg ($1) and deps into one single pkg FUNCLIST
  3532.  
  3533.   # exit if no valid options
  3534.   [ ! "$1" -o "$1" = "-" ] && print_usage pkg-combine && exit 1
  3535.  
  3536.   . ${PKGRC}
  3537.  
  3538.   local EX=''
  3539.   local PKGNAME=''
  3540.   local PKGNAME_ONLY=''
  3541.   local PKG_FILENAME=''
  3542.   local PKG_FILE=''
  3543.   local ALL_DEPS=''
  3544.   local PKG_DEPLIST=''
  3545.   local SUFFIX="${CP_SUFFIX}"
  3546.   local BUILD_DIR=$TMPDIR/build_pkg
  3547.   local SFS_FILE
  3548.   local please_wait=false
  3549.   local PREVDIR="$CURDIR"
  3550.   local ask_opt=$ASK
  3551.   local force_opt=$FORCE
  3552.  
  3553.   cd "$WORKDIR"
  3554.  
  3555.   # get pkg extension
  3556.   EX=`get_pkg_ext "$1"`
  3557.  
  3558.   # get reliable package names
  3559.   PKGNAME="$(basename "$1" .$EX)"
  3560.   PKGNAME=`get_pkg_name "$PKGNAME"`
  3561.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  3562.  
  3563.   PKG_FILE="${WORKDIR}/${PKGNAME}.$EX" #the file to install
  3564.  
  3565.   # we want to include all deps, except builtins, by default
  3566.   # we dont set HIDE_BUILTINS here, we leave that up to user
  3567.   # when user gives -F, HIDE_BUILTINS= false, and builtin
  3568.   # pkgs will be included in the package created
  3569.   FORCE=true
  3570.   HIDE_USER_PKGS=false
  3571.  
  3572.   # get full pkg filename (inc name-ver.ext).. try repos first
  3573.   PKG_FILENAME="`cut -f8 -d'|' "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "^$PKGNAME"`"
  3574.   # then WORKDIR if needed (dont include the combined pkgs)
  3575.   [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="`ls -1 "$WORKDIR" | grep -v "${SUFFIX}" | grep -v ".sfs\$" | grep -m1 "^$PKGNAME"`"
  3576.  
  3577.   # just in case its empty, revert back to the earlier PKGNAME value
  3578.   [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="$PKGNAME"
  3579.  
  3580.   [ "$PKG_FILENAME" = "" ] && error "Cant find $1" && exit 1
  3581.  
  3582.   # update PKGFILE with new pkg filename (PKG)
  3583.   PKG_FILE="${WORKDIR}/${PKG_FILENAME}"
  3584.  
  3585.   # check if the desired file has already been built
  3586.   [ "$COMBINE2SFS" = true ] && final_ext=sfs || final_ext=pet
  3587.   [ -f "${WORKDIR}/${PKGNAME}-${SUFFIX}.$final_ext" ] && echo -e "File ${magenta}${WORKDIR}/${PKGNAME}-${SUFFIX}.${final_ext}${endcolour} already exists." && continue
  3588.  
  3589.   # get list of deps for PKGNAME, if no deps, exit
  3590.   PKG_DEPLIST="`FORCE=$force_opt list_deps $PKGNAME_ONLY`"
  3591.   [ "$PKG_DEPLIST" = "" ] && echo "No need to combine, $PKGNAME has no dependencies." && exit 1
  3592.  
  3593.   # if exact match of pkgname is found in a repo list
  3594.   if [ "`is_repo_pkg "$PKGNAME"`" = true ];then
  3595.  
  3596.     echo "Please wait.. Gathering dependency information."
  3597.  
  3598.     # get the deps of the pkg, but dont install
  3599.     FORCE=$force_opt find_deps "$PKGNAME"
  3600.     ALL_DEPS="`cat $TMPDIR/deps_installed $TMPDIR/deps_missing 2>/dev/null | sort | uniq`"
  3601.  
  3602.     # download the needed package
  3603.     if [ ! -f "$PKG_FILE" -o "$FORCE" = true ];then
  3604.       ASK=false pkg_download "$PKGNAME"
  3605.     fi
  3606.  
  3607.     # make work dirs
  3608.     mkdir -p "$BUILD_DIR/"
  3609.     mkdir -p "$BUILD_DIR/${PKGNAME}-${SUFFIX}"
  3610.  
  3611.     if [ -f "$PKG_FILE" ];then
  3612.       # copy the main pkg to the tmp dir
  3613.       # and remove the downloade file, we no longer need it
  3614.       cp "$PKG_FILE" "$BUILD_DIR/" 2>/dev/null && rm "$PKG_FILE"
  3615.     else
  3616.        error "Could not add the main package '$PKGNAME_ONLY'"
  3617.     fi
  3618.  
  3619.  
  3620.     # make a cleaned list to go over (sanity check)
  3621.     ALL_DEPS_LIST="`echo "$ALL_DEPS" | tr ',' '\n' | grep -v "^\$" | sort | uniq`"
  3622.  
  3623.     # go through each dep listed
  3624.     echo "$ALL_DEPS_LIST" | while read LINE
  3625.     do
  3626.  
  3627.       [ "$LINE" = "" -o "$LINE" = "-" -o "$LINE" = " " -o "$LINE" = "," -o "$LINE" = ", " ] && continue
  3628.  
  3629.       # only include builtins if HIDE_BUILTINS=true
  3630.       [ "`is_builtin_pkg "$LINE"`" = true -a "$HIDE_BUILTINS" = true ] && continue
  3631.  
  3632.       # only include devx pkgs if user gave the -f option
  3633.       [ "`is_devx_pkg "$LINE"`" = true -a "$force_opt" = false ] && continue
  3634.  
  3635.       # download the matching package(s)
  3636.       [ "`list_downloaded_pkgs "$LINE"`" = "" ] && ASK=false pkg_download "$LINE"
  3637.  
  3638.       # get the downloaded file
  3639.       PKGDEP="`find "$WORKDIR" -maxdepth 1 -type f -name "${LINE}*" | grep -v ".sfs\$" | grep -v "${SUFFIX}" | head -1`"
  3640.  
  3641.       # re-try download in other repos if needed
  3642.       if [ ! -f "$PKGDEP" ];then
  3643.         PKGREPO=''; PKGREPO="`LANG=C which_repo $LINE | cut -f2 -d' ' | head -1`"
  3644.         [ "$PKGREPO" != "" ] && ASK=false pkg_download "$LINE"
  3645.       fi
  3646.  
  3647.       #if downloaded
  3648.       if [ -f "$PKGDEP" -o "$FORCE" = true ];then
  3649.  
  3650.         # copy dep to the tmp dir, with the main pkg
  3651.         if [ ! -f "$BUILD_DIR/$PKGDEP" ];then
  3652.           cp "$PKGDEP" "$BUILD_DIR/$(basename $PKGDEP)" && rm "$PKGDEP"
  3653.         else
  3654.           error "Cannot copy $PKGDEP to $BUILD_DIR/$(basename $PKGDEP)"
  3655.         fi
  3656.  
  3657.       else # dep not found, may be missing, or in another repo
  3658.         echo -e "${yellow}Warning:${endcolour} $LINE not downloaded to $WORKDIR.. Cannot add $LINE.."
  3659.         continue
  3660.       fi
  3661.     done
  3662.  
  3663.     # we should now be ready to make our combined pkg
  3664.     cd "$BUILD_DIR"
  3665.  
  3666.     PARENTPKG=${PKGNAME}
  3667.  
  3668.     # for all pkgs in the tmp dir (nto including any 'combined' pkgs)
  3669.     TMP_PKGS="`find "$BUILD_DIR/" -maxdepth 1 -type f -name "*" | grep -v $SUFFIX | grep -v ^$ | grep -v ' ' | sort | uniq`"
  3670.  
  3671.     local count=1
  3672.  
  3673.     for i in $TMP_PKGS
  3674.     do
  3675.  
  3676.       # skip if not a valid pkg file
  3677.       [ ! "$i" -o "$i" = ' ' -o "$i" = '' -o ! -f "$i" ] && continue
  3678.  
  3679.       # dont include the combined pkgs
  3680.       [ "`echo "$i" | grep -m1 "${SUFFIX}"`" != "" ] && continue
  3681.  
  3682.       # get the extensions of each file .. they might be from different repos, so cant use $EX
  3683.       base="`basename "$i" 2>/dev/null`"
  3684.       FILE_EXT=`get_pkg_ext "$base"`
  3685.  
  3686.       [ ! "$base" -o "$base" = ' ' -o "$base" = '' ] && continue
  3687.  
  3688.       # get name without version for this pkg ($i)
  3689.       name_only=`get_pkg_name_only "$i"`
  3690.  
  3691.       [ ! "$name_only" -o "$name_only" = ' ' -o "$name_only" = '' ] && continue
  3692.  
  3693.       CONFIRM=y
  3694.       if [ "$ask_opt" = true ];then
  3695.         echo -n "Add package: $name_only  ($FILE_EXT)  (y/N):  "
  3696.         read -n 1 CONFIRM </dev/tty
  3697.         echo
  3698.       else
  3699.         echo "Adding package: $name_only  ($FILE_EXT)"
  3700.       fi
  3701.  
  3702.       # skip pkg if user wants to skip it
  3703.       if [ "$CONFIRM" != 'y' ];then
  3704.         rm "$i"
  3705.         continue
  3706.       fi
  3707.  
  3708.       # add each file
  3709.       case $FILE_EXT in
  3710.       pet)
  3711.  
  3712.         # convert and extract
  3713.         pkg_unpack "${i}" 1>/dev/null
  3714.         sync
  3715.  
  3716.         # copy extracted contents (only the stuff inside the extracted folders)
  3717.         if [ ! -d "${i/.pet/}/" ];then
  3718.           error "Dir '${i/.pet/}/' does not exist"
  3719.         fi
  3720.         cp -a --preserve=all -fr -L "${i/.pet/}/"* "${PARENTPKG}-${SUFFIX}/"
  3721.  
  3722.         if [ -f "${i/.pet/}/pinstall.sh" ];then
  3723.           mv "${i/.pet/}/pinstall.sh" "${PARENTPKG}-${SUFFIX}/pinstall_${count}.sh"
  3724.         fi
  3725.  
  3726.         # now remove the pet and extract folder
  3727.         rm "${i}"
  3728.         rm -rf "${i/.pet/}/"
  3729.         sync
  3730.         ;;
  3731.  
  3732.       deb)
  3733.  
  3734.         #cp "$i" "$BUILD_DIR/${PARENTPKG}-${SUFFIX}"
  3735.         pkg_unpack "$i" 2>$TMPDIR/$SELF-cp-errlog
  3736.         dpkg-deb -e "$i" "$BUILD_DIR/${PARENTPKG}-${SUFFIX}/DEBIAN"
  3737.  
  3738.         # .deb package names often have extra stuff at the end of the file name
  3739.         # that does not exist in the root folder name, inside the package.. so
  3740.         # we need to strip off that extra stuff to get the correct unpacked
  3741.         # package dir
  3742.         local pkg_dir="${i/.deb/}/"
  3743.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_all/}"
  3744.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_i386/}"
  3745.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_amd64/}"
  3746.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_x64/}"
  3747.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/~dfsg-[0-9]/}"
  3748.         [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/~dsfg-[0-9]/}"
  3749.  
  3750.         if [ ! -d "$pkg_dir" ];then
  3751.           needle="$(get_pkg_name "$i")"
  3752.           pkg_dir="$(find "${BUILD_DIR}" -type d -iname "$needle" | head -1)"
  3753.         fi
  3754.  
  3755.         if [ ! -d "$pkg_dir" ];then
  3756.           error "Dir '$pkg_dir' does not exist!"
  3757.         fi
  3758.  
  3759.         # copy extracted contents (only the stuff inside the extracted folders)
  3760.         cp -a --preserve=all -fr -L "${pkg_dir}/"* "${PARENTPKG}-${SUFFIX}/"
  3761.  
  3762.         if [ -f "${pkg_dir}DEBIAN/postinst" ];then
  3763.           mv "${pkg_dir}DEBIAN/postinst" "${PARENTPKG}-${SUFFIX}/DEBIAN/postinst_${count}"
  3764.         fi
  3765.  
  3766.         if [ -f "${pkg_dir}DEBIAN/preinst" ];then
  3767.           mv "${pkg_dir}DEBIAN/preinst" "${PARENTPKG}-${SUFFIX}/DEBIAN/preinst_${count}"
  3768.         fi
  3769.  
  3770.         # now remove the deb and extracted folder
  3771.         rm "$i"
  3772.         rm -rf "$pkg_dir"
  3773.         sync
  3774.         ;;
  3775.  
  3776.       *tgz|*txz|*tar.gz|*tar.xz|*xz|*gz)
  3777.  
  3778.         pkg_unpack "$i" 1>/dev/null
  3779.  
  3780.         # now copy $BUILD_DIR/$PKGNAME/* into our output (combined pkg) dir
  3781.         cp -a --preserve=all -fr -L "${name_only}/"* "${PARENTPKG}-${SUFFIX}/" || error "Dir '${name_only}/' does not exist!"
  3782.  
  3783.         if [ -f "${PARENTPKG}-${SUFFIX}/install/doinst.sh" ];then
  3784.           mv "${PARENTPKG}-${SUFFIX}/install/doinst.sh" "${PARENTPKG}-${SUFFIX}/install/doinst_${count}.sh"
  3785.         fi
  3786.  
  3787.         # remove the package and folder we just extracted
  3788.         rm "$i"
  3789.         rm -rf "${i/.*/}/"
  3790.         sync
  3791.         ;;
  3792.  
  3793.       rpm)
  3794.         pkg_unpack "$i" 1>/dev/null
  3795.  
  3796.         # now copy $BUILD_DIR/$PKGNAME/* into our output (combined pkg) dir
  3797.         cp -a --preserve=all -fr -L "${name_only}/"* "${PARENTPKG}-${SUFFIX}/"
  3798.  
  3799.         if [ -f "${PARENTPKG}-${SUFFIX}/install/doinst.sh" ];then
  3800.           mv "${PARENTPKG}-${SUFFIX}/install/doinst.sh" "${PARENTPKG}-${SUFFIX}/install/doinst_${count}.sh"
  3801.         fi
  3802.  
  3803.         # remove the package and folder we just extracted
  3804.         rm "$i"
  3805.         rm -rf "${i/.rpm/}/"
  3806.         ;;
  3807.  
  3808.       esac
  3809.       count=$(($count + 1))
  3810.     done
  3811.  
  3812.     # we have now unpacked the package, lets combine the pre/post install scripts
  3813.     # into one pinstall.sh script
  3814.  
  3815.     local pinstall_file="$BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh"
  3816.  
  3817.     # append this pinstall/postinst/doinst script to a new pinstall.sh
  3818.     echo '#!/bin/sh' > "$pinstall_file"
  3819.  
  3820.     # concat the post install scripts (for puppy, slackware, arch, debian/ubuntu, etc) into 'pinstall.sh'
  3821.     for i in ${PARENTPKG}-${SUFFIX}/pinstall_* ${PARENTPKG}-${SUFFIX}/install/doinst_* ${PARENTPKG}-${SUFFIX}/DEBIAN/postinst_*
  3822.     do
  3823.       [ -z ${PARENTPKG}-${SUFFIX}/${i} ] && continue
  3824.       cd ${PARENTPKG}-${SUFFIX}/ 2>/dev/null
  3825.  
  3826.       files=`find . -type f -iname "$(basename $i)"`
  3827.  
  3828.       for file in $files
  3829.       do
  3830.         if [ -f "$file" ];then
  3831.           echo "Appending ${file} to $pinstall_file"
  3832.           cat ${file} | grep -vE '^#!|^exit|exit 0|exit 1' >> "$pinstall_file"
  3833.           echo '' >> "$pinstall_file"
  3834.         fi
  3835.       done
  3836.       # we have combined the pre/post install stuff in $i into a new, combined file,
  3837.       # so remove the original
  3838.       rm -f ${PARENTPKG}-${SUFFIX}/${i}
  3839.     done
  3840.  
  3841.     chmod +x $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh 2>/dev/null
  3842.  
  3843.     #xmessage "$(cat $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh)"
  3844.  
  3845.     # remove any debian/ubuntu/slackware pre/post install stuff left in the package
  3846.     rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall_*
  3847.     rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/install
  3848.     rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/DEBIAN
  3849.  
  3850.     # fix the symlinks to lib dirs - the linux-gnu-* dirs are symlinks in puppy,
  3851.     # so make sure we dont replace them with dirs (or programs won't load)
  3852.     for libdir in i386-linux-gnu i486-linux-gnu i586-linux-gnu i686-linux-gnu amd64-linux-gnu
  3853.     do
  3854.       if [ -d $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/${libdir}/ ];then
  3855.         mv -n -u $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/${libdir}/* $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/
  3856.         cd $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib
  3857.         rmdir ${libdir}/
  3858.         ln -s ${libdir}/ .
  3859.         cd -
  3860.       fi
  3861.     done
  3862.  
  3863.  
  3864.     # now we are ready to build our combined pkg
  3865.     [ "`pwd`" != "$BUILD_DIR" ] && cd "$BUILD_DIR/"
  3866.  
  3867.  
  3868.     # if not building SFS, build a .pet
  3869.     if [ "$COMBINE2SFS" = false ];then #240613
  3870.       echo "Building PET package.. Please wait.."
  3871.  
  3872.       # build pet package... start with $removing PKGNAME-${SUFFIX}.pet.specs
  3873.       rm ${PKGNAME}-${SUFFIX}/*.specs 2>/dev/null
  3874.  
  3875.       # get compression type
  3876.       file -b "${PKGNAME}-${SUFFIX}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  3877.  
  3878.       # tar up the folder
  3879.       tar -c -f ${PKGNAME}-${SUFFIX}.tar ${PKGNAME}-${SUFFIX} &>/dev/null
  3880.       sync
  3881.  
  3882.       case $TAREXT in
  3883.         xz)xz -z -9 -e ${PKGNAME}-${SUFFIX}.tar ;;
  3884.         gz)gzip --best ${PKGNAME}-${SUFFIX}.tar ;;
  3885.       esac
  3886.  
  3887.       TARBALL="${PKGNAME}-${SUFFIX}.tar.$TAREXT"
  3888.       FULLSIZE="`stat --format=%s ${TARBALL}`"
  3889.       MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  3890.       echo -n "$MD5SUM" >> $TARBALL
  3891.       sync
  3892.  
  3893.       mv -f $TARBALL ${PKGNAME}-${SUFFIX}.pet
  3894.       sync
  3895.  
  3896.       if [ $? -eq 1 ];then
  3897.         echo "Cannot create PET file ${PKGNAME}-${SUFFIX} from dir."
  3898.         error "Please check `pwd`"
  3899.       fi
  3900.  
  3901.       # move our new PET to $WORKDIR
  3902.       mv ${PKGNAME}-${SUFFIX}.pet $WORKDIR/${PKGNAME}-${SUFFIX}.pet
  3903.       # get the size
  3904.       s=`LANG=C du -m "$WORKDIR/${PKGNAME}-${SUFFIX}.pet" | sed "s/\s.*//"`
  3905.  
  3906.     else #240613  build a .sfs
  3907.       echo "Building SFS package.. Please wait.."
  3908.  
  3909.       dir2sfs "${PKGNAME}-${SUFFIX}" 1>/dev/null
  3910.  
  3911.       # get the full file name, it may (or not) have been appended with '-DISTRO_VERSION'
  3912.       SFS_FILE=`find . -maxdepth 1 -type f -name "*${PKGNAME}-${SUFFIX}*.sfs" | head -1`
  3913.  
  3914.       s=`LANG=C du -m "${SFS_FILE}" | sed "s/\s.*//"`
  3915.       MD5SUM=`md5sum "$SFS_FILE" | cut -f1 -d ' '`
  3916.       mv "$SFS_FILE" "$WORKDIR/"
  3917.     fi
  3918.  
  3919.     # done, go back to work dir from WORKDIR/build_pkg
  3920.     cd "$WORKDIR"
  3921.     rm -R  "$BUILD_DIR/" 2>/dev/null
  3922.  
  3923.     # create install command
  3924.     if [ "$COMBINE2SFS" = false ];then
  3925.       PKGEXT=pet
  3926.       PKGCMD="Install command: $SELF install ${WORKDIR}/${PKGNAME}-${SUFFIX}"
  3927.     else
  3928.       PKGEXT=sfs
  3929.       PKGCMD="Install command: sfs_loadr --cli -q \"${WORKDIR}/$(basename $SFS_FILE)\""
  3930.     fi
  3931.  
  3932.     #226013 updated output
  3933.     echo -e "Created package ${magenta}${PKGNAME}-${SUFFIX}.${PKGEXT}${endcolour} (${s}MB)"
  3934.     echo "The md5 checksum: $MD5SUM"
  3935.     echo "$PKGCMD"
  3936.  
  3937.   else # no exact PKGNAME match in repo
  3938.     not_found "${PKGNAME}"
  3939.     exit 1
  3940.   fi
  3941.  
  3942.   cd "$PREVDIR"
  3943. }
  3944.  
  3945.  
  3946. merge_pkg(){                      # merge the given comma-separated packages FUNCLIST
  3947.   # make sure at least 2 packages exist
  3948.  
  3949.   [ ! "$1" ] && print_usage merge && exit 1
  3950.   [ "$(echo "$1" |grep ',')" = "" ] && print_usage merge && exit 1
  3951.  
  3952.   cd "$WORKDIR" 1>/dev/null
  3953.  
  3954.   local PKG_LIST="$(echo "${1}" | tr ',' '\n' | sort -u | uniq)"
  3955.   local SUFFIX=''
  3956.  
  3957.   if [ "$2" = "--with-deps" ];then
  3958.     SUFFIX="-WITHDEPS"
  3959.     echo "Gathering dependencies to include.."
  3960.     echo
  3961.     # add deps of pkgs to list of pkgs to merge
  3962.     for package in $PKG_LIST
  3963.     do
  3964.       PKG_LIST="$PKG_LIST $(pkg le $package)"
  3965.     done
  3966.     PKG_LIST="$(echo "$PKG_LIST" | tr ' ' '\n' | sort -u | uniq)"
  3967.   fi
  3968.  
  3969.   echo "Merging the following packages:"
  3970.   echo
  3971.   echo "${PKG_LIST}" | sed 's/^/  /g'
  3972.   echo
  3973.  
  3974.   # get a new package name for the new, merged package
  3975.   local PKGNAME="`get_pkg_name "$(basename "${1//,*/}")" 2>/dev/null`"
  3976.   bash -c 'read -e -r -p "Enter a package name and hit ENTER: " -i "${PKGNAME}-MERGED${SUFFIX}" NEWPKGNAME; echo $NEWPKGNAME > /tmp/pkg/NEWPKGNAME'
  3977.   echo
  3978.   NEWPKGNAME="$(cat /tmp/pkg/NEWPKGNAME)"
  3979.  
  3980.   if [ "$NEWPKGNAME" = "" ];then
  3981.     echo "You must give a new package name!"
  3982.     return 1
  3983.   fi
  3984.  
  3985.   rm -rf "${NEWPKGNAME}/" &>/dev/null
  3986.   mkdir "${NEWPKGNAME}"
  3987.  
  3988.   # remove any old folders
  3989.   rm -rf ${WORKDIR}${NEWPKGNAME}/ &>/dev/null
  3990.  
  3991.   # for each package to merge
  3992.   for package in $PKG_LIST
  3993.   do
  3994.  
  3995.     # get the package details
  3996.     local PKGNAME="`get_pkg_name "$(basename "$package")" 2>/dev/null`"
  3997.     local PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME" 2>/dev/null`"
  3998.     local PKGEXT="`get_pkg_ext "$PKGNAME"`"
  3999.     local PKGFILE=''
  4000.  
  4001.     [ "$PKGNAME" = "" ] && continue
  4002.     [ "$PKGNAME" = " " ] && continue
  4003.     [ "$PKGNAME" = "-" ] && continue
  4004.  
  4005.     # download it
  4006.     pkg_download "$PKGNAME"
  4007.  
  4008.     retval=$?
  4009.  
  4010.     if [ $retval -eq 1 ];then
  4011.       echo -e "${yellow}Warning${endcolour}: package '$PKGNAME' not downloaded."
  4012.       continue
  4013.     fi
  4014.  
  4015.     # get the downloaded file
  4016.     PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME}*${PKGEXT}")"
  4017.  
  4018.     [ ! -f "$PKGFILE" ] && \
  4019.       PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME_ONLY}_*${PKGEXT}")"
  4020.  
  4021.     [ ! -f "$PKGFILE" ] && \
  4022.       PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME_ONLY}-*${PKGEXT}")"
  4023.  
  4024.     if [ ! -f "$PKGFILE" ];then
  4025.       echo -e "${red}Error${endcolour}: could not find downloaded package '$PKGFILE'"
  4026.       return 1
  4027.     fi
  4028.  
  4029.     # unpack the downloaded file
  4030.     pkg_unpack "$PKGFILE"
  4031.     rm "${PKGFILE}"
  4032.  
  4033.     # move the unpacked files into our new package dir
  4034.     PKGDIR="$(find $WORKDIR -maxdepth 1 -type d -name "${PKGNAME}*" | grep -v ${NEWPKGNAME})"
  4035.  
  4036.     if [ ! -d "$PKGDIR" ];then
  4037.       echo -e "${red}Error${endcolour}: could not find extracted package dir '$PKGDIR'"
  4038.       return 1
  4039.     fi
  4040.  
  4041.     cp -R "$PKGDIR"/* "$NEWPKGNAME"
  4042.     rm -rf "${PKGDIR}/"
  4043.   done
  4044.  
  4045.   if [ ! -d "${WORKDIR}/$NEWPKGNAME" ];then
  4046.     echo -e "${red}Error${endcolour}: Dir ${lightblue}${NEWPKGNAME}${endcolour} NOT created!"
  4047.     return 1
  4048.   fi
  4049.  
  4050.   echo
  4051.   echo "Package contents:"
  4052.   find "${NEWPKGNAME}/"
  4053.   echo '--------------------------------'
  4054.   echo
  4055.  
  4056.   # create the merged PET package
  4057.   dir2pet "${NEWPKGNAME}/" || error "Could not create $NEWPKGNAME} PET file"
  4058.  
  4059.   rm -rf "./${NEWPKGNAME}/" &>/dev/null
  4060.   rm -rf "${WORKDIR}/${NEWPKGNAME}/" &>/dev/null
  4061.  
  4062.   # get the filename of the new PET package
  4063.   NEWPKGFILENAME="$(find . -maxdepth 1 -type f -name "${NEWPKGNAME}*.pet")"
  4064.  
  4065.   # output messages
  4066.   if [ ! -f "$NEWPKGFILENAME" ];then
  4067.     echo
  4068.     echo -e "${red}Error${endcolour}: Package ${yellow}${NEWPKGFILENAME}${endcolour} NOT created!"
  4069.     return 1
  4070.   fi
  4071.  
  4072.   return 0
  4073. }
  4074.  
  4075.  
  4076. split_pkg(){                      # split package ($1) into dev, doc, nls packages FUNCLIST
  4077.  
  4078.   # make sure the package exists
  4079.   [ ! "$1" -o ! -f "$1" ] && print_usage split && exit 1
  4080.  
  4081.   local PKGNAME="`get_pkg_name "$(basename "$1")" 2>/dev/null`"
  4082.   local PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME" 2>/dev/null`"
  4083.   local PKGEXT="pet"
  4084.  
  4085.   # get package extension
  4086.   PKGEXT="`get_pkg_ext "$1"`"
  4087.  
  4088.   pkg_unpack "$1" &>/dev/null
  4089.  
  4090.   # get the package directory we just extracted
  4091.   local PKG_PATH="$(find $(dirname "$PKGNAME") -maxdepth 1 -type d -iname "$PKGNAME" | head -1)"
  4092.  
  4093.   # get the full path to the package dir (dir with contents of pkg to be split)
  4094.   PKG_PATH="$(realpath "$PKG_PATH")"
  4095.  
  4096.   # make sure we have the right package dir
  4097.   [ ! -d "$PKG_PATH" ] && PKG_PATH="$(realpath "$PKGNAME")"
  4098.  
  4099.   # get the base name of the package directory
  4100.   local PKG_DIR_NAME=$(basename "$PKG_PATH")
  4101.  
  4102.   # get the package name
  4103.   local PKG_NAME="$PKGNAME_ONLY"
  4104.  
  4105.   # get the parent directory of the package
  4106.   local PARENT_DIR="$(dirname "$PKG_PATH")"
  4107.  
  4108.   # set the correct package naming style
  4109.   local dev_suffix='_DEV'
  4110.   local doc_suffix='_DOC'
  4111.   local nls_suffix='_NLS'
  4112.   if [ "${PKGEXT:-pet}" = "deb" ];then
  4113.     dev_suffix='-dev'
  4114.     doc_suffix='-doc'
  4115.     nls_suffix='-nls'
  4116.   fi
  4117.  
  4118.   # get the sub-package names
  4119.   local EXE_PKG="$PKGNAME"
  4120.   local DEV_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${dev_suffix}/")"
  4121.   local DOC_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${doc_suffix}/")"
  4122.   local NLS_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${nls_suffix}/")"
  4123.  
  4124.   # remove the target package dirs if they already exist
  4125.   [ -d "$DEV_PKG" ] && rm -rf "$DEV_PKG"
  4126.   [ -d "$DOC_PKG" ] && rm -rf "$DOC_PKG"
  4127.   [ -d "$NLS_PKG" ] && rm -rf "$NLS_PKG"
  4128.   # now create them fresh and empty
  4129.   mkdir -p "$DEV_PKG"
  4130.   mkdir -p "$DOC_PKG"
  4131.   mkdir -p "$NLS_PKG"
  4132.  
  4133.   # make sure the package directory begins with the given package name
  4134.   case $(basename "$PKG_PATH") in
  4135.     $PKG_NAME*)
  4136.         ;;
  4137.     *)
  4138.         echo "Error: $(basename "$PKG_PATH") must match $PKG_NAME"
  4139.         print_usage split
  4140.         exit 1
  4141.         ;;
  4142.   esac
  4143.  
  4144.   cd "$PKG_PATH" &>/dev/null || { echo "Not found: $PKG_PATH"; return 1; }
  4145.  
  4146.   for i in $(find -mindepth 1)
  4147.   do
  4148.     # if the file no longer exists, skip this iteration
  4149.     [ ! -e "$i" ] && continue
  4150.  
  4151.     local FILE_NAME=$(basename "$i")
  4152.  
  4153.     case "$FILE_NAME" in
  4154.         *.la|*.a|*.o|*.prl|pkgconfig|include|*.m4|*.h|*.c|*.cpp)
  4155.             PKGNAME="$DEV_PKG"
  4156.             ;;
  4157.         gdb)
  4158.             [ -d "$i" ] && PKGNAME="$DEV_PKG"
  4159.             ;;
  4160.         dir)
  4161.             [ -f "$i" ] && PKGNAME="$DOC_PKG"
  4162.             ;;
  4163.         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)
  4164.             PKGNAME="$DOC_PKG"
  4165.             ;;
  4166.         help)
  4167.             [ -d "$i" ] && PKGNAME="$DOC_PKG"
  4168.             ;;
  4169.         man|info) # if it's a directory named "man" or "info", move to doc
  4170.             [ -d "$i" ] && PKGNAME="$DOC_PKG"
  4171.              ;;
  4172.         locale|locales|lang|strings) # if it's a directory named "locale", move to nls
  4173.             [ -d "$i" ] && PKGNAME="$NLS_PKG"
  4174.             ;;
  4175.         i18n|nls)
  4176.             PKGNAME="$NLS_PKG"
  4177.             ;;
  4178.         system.profile-*|*.strings|normal.awt-*) # AbiWord stores its locale information in those files
  4179.             [ "$PKGNAME_ONLY" = "abiword" ] && PKGNAME="$NLS_PKG"
  4180.             ;;
  4181.         *)
  4182.             PKGNAME="$EXE_PKG"
  4183.             ;;
  4184.     esac
  4185.  
  4186.     # verbosity, output the redirection for each redirected file
  4187.     case "$PKGNAME" in
  4188.         $DEV_PKG|$DOC_PKG|$NLS_PKG)
  4189.             #local SUFFIX="$(echo $SUFFIX | tr [:lower:] [:upper:])"
  4190.  
  4191.             #echo "$FILE_NAME -> $PKG"
  4192.  
  4193.             # detect the sub_directory inside the package
  4194.             local SUB_DIR="${i%/$FILE_NAME}"
  4195.             SUB_DIR="${SUB_DIR:2}"
  4196.  
  4197.             # create the directory under the sub-package directory
  4198.             mkdir -p "$PARENT_DIR/$PKGNAME/$SUB_DIR"
  4199.  
  4200.             # move the file to the sub-package
  4201.             mv "$i" "$PARENT_DIR/$PKGNAME/$SUB_DIR"
  4202.  
  4203.             # get rid of empty directories in the EXE package
  4204.             rmdir "$SUB_DIR" &>/dev/null
  4205.             ;;
  4206.     esac
  4207.  
  4208.   done
  4209.  
  4210.   # if the EXE package is empty, remove it
  4211.   is_empty="$(find "$PKG_PATH" -maxdepth 2 -type f 2>/dev/null)"
  4212.   [ -z "$is_empty" ] && rm -rf "$PKG_PATH"
  4213.  
  4214.   # go back to where we started (where the main package lives)
  4215.   [ -d "$CURDIR" ] && cd "$CURDIR" &>/dev/null
  4216.  
  4217.   # build each package from the package dir
  4218.   for dir in "$EXE_PKG" "$DEV_PKG" "$DOC_PKG" "$NLS_PKG"
  4219.   do
  4220.     if [ -d "$dir" ];then
  4221.       dir2${PKGEXT//./} "$dir" && rm -rf "$dir"
  4222.     fi
  4223.   done
  4224.  
  4225.   # get a list of the new packages we created
  4226.   new_pkgs="$(find . -maxdepth 1 -type f -name "${PKGNAME}*.$PKGEXT"
  4227.  find . -maxdepth 1 -type f -name "${DEV_PKG}*.$PKGEXT"
  4228.  find . -maxdepth 1 -type f -name "${DOC_PKG}*.$PKGEXT"
  4229.  find . -maxdepth 1 -type f -name "${NLS_PKG}*.$PKGEXT")"
  4230.  
  4231.   if [ "$new_pkgs" != "" ];then
  4232.     echo
  4233.     echo -e "${green}Success${endcolour}: Package split into these new files:"
  4234.     echo "$new_pkgs" | sed 's/^.\// /'
  4235.   fi
  4236.  
  4237.   # cleanup
  4238.   [ -d "$DEV_PKG" ] && rm -rf "$DEV_PKG"
  4239.   [ -d "$DOC_PKG" ] && rm -rf "$DOC_PKG"
  4240.   [ -d "$NLS_PKG" ] && rm -rf "$NLS_PKG"
  4241.  
  4242.   return 0
  4243. }
  4244.  
  4245.  
  4246.  
  4247. # main pkg funcs
  4248.  
  4249. pkg_download(){                   # download a pkg ($1) to WORKDIR FUNCLIST
  4250.  
  4251.   # exit if no valid options
  4252.   [ ! "$1" -o "$1" = "-" ] && print_usage download && exit 1
  4253.  
  4254.   . ${PKGRC}
  4255.  
  4256.   local pkg_ext=''        # extension of pkg, empty if not a supported pkg ext
  4257.   local PKGNAME=''        # the pkgname with version
  4258.   local ORIG_PKGNAME=''   # keeps the original pkg name ($1)
  4259.   local PKG_FILENAME=''   # package file name (field 8 of repo, with extension)
  4260.   local PKGFILE=''        # full path to package file
  4261.   local NET=''            # 1 or 0 if net connection available
  4262.   local curr_repo=''      # name of current repo in the loop
  4263.   local curr_repo_ext=''  # pkg ext for the current repo in the loop
  4264.   local prev_repo_url=''  # holder for the prev checked url we know is working
  4265.   local curr_repo_url=''  # mirror that is used to download the pkg
  4266.   local curr_repo_url1='' # mirror1 for the current repo in the loop
  4267.   local curr_repo_url2='' # mirror2 for the current repo in the loop
  4268.   local curr_repo_url3='' # mirror3 for the current repo in the loop
  4269.   local curr_repo_url4='' # mirror4 for the current repo in the loop
  4270.   local pkg_in_repo=''    # true if pkg found in ANY repo, else false
  4271.  
  4272.   # get pkg extension
  4273.   pkg_ext=`get_pkg_ext "$1"`
  4274.  
  4275.   # get pkg name with version (if given!), no extension or path
  4276.   PKGNAME="$(basename "$1" .$pkg_ext)"
  4277.  
  4278.   # get full package name from given pkg name string .. vlc -> vlc-1.2.3-blah
  4279.   PKGNAME=`get_pkg_name "$PKGNAME"`
  4280.  
  4281.   # the file to save to.. not reliable till we checked the repos
  4282.   PKGFILE="${WORKDIR}/${PKGNAME}.$pkg_ext"
  4283.  
  4284.   # set download options
  4285.   [ "$FORCE" = true  ] && CONTINUE='' || CONTINUE='-c'
  4286.   [ "$ASK"  != true  ] && QTAG=''
  4287.  
  4288.   #if pkg not yet downloaded, or we are downloading all, or we are forcing downloads
  4289.   if [ ! -f "$PKGFILE" -o "$NO_INSTALL" = true -o "$FORCE" = true ];then
  4290.  
  4291.     # mark this pkg as not yet downloaded
  4292.     DONE=false
  4293.  
  4294.     # exit if no internet connection
  4295.     #NET="`check_net`"; [ $NET -eq 1 ] && echo "You need an internet connection" && exit 2
  4296.  
  4297.     # for each repo, starting with current repo
  4298.     repo_file_list | while read repo_file
  4299.     do
  4300.  
  4301.       # the file with our repo URL info
  4302.       sources_file="${HOME}/.pkg/sources"
  4303.  
  4304.       # check if $repo_file contains the given pkg
  4305.       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}|")"
  4306.       [ "$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}")"
  4307.  
  4308.       # if package file found in current repo file
  4309.       if [ "$pkg_in_this_repo" != "" ];then #if true, its an exact match
  4310.  
  4311.         # get name of current repo in loop
  4312.         prev_repo="$curr_repo"
  4313.         curr_repo="`LANG=C grep $repo_file $sources_file 2>/dev/null | cut -f1 -d'|'`"
  4314.  
  4315.         # get ext of cur repo, it might be different
  4316.         curr_repo_ext="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f2 -d'|'`"
  4317.  
  4318.         # keep a copy of the PKGNAME we got from `get_pkg_name $1`
  4319.         ORIG_PKGNAME=$PKGNAME
  4320.  
  4321.         # get proper PKGNAME (inc name-ver) from the repo
  4322.         PKGNAME="`echo "$pkg_in_this_repo" | cut -f3 -d'|'`"
  4323.         # just in case it didn't work, revert back to the old PKGNAME value
  4324.         [ "$PKGNAME" = "" ] && PKGNAME="$ORIG_PKGNAME"
  4325.  
  4326.         # get full pkg FILENAME (inc name-ver.ext) from the repo
  4327.         PKG_FILENAME="`echo "$pkg_in_this_repo" | cut -f5 -d'|'`"
  4328.  
  4329.         # just in case its empty, revert back to the earlier PKGNAME value
  4330.         [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="$PKGNAME"
  4331.  
  4332.         # update the filename to check/download
  4333.         PKGFILE="${WORKDIR}/${PKG_FILENAME}"
  4334.  
  4335.         # skip if downloaded already, print msg
  4336.         [ -f "$PKGFILE" -a "$FORCE" = false ] && DONE=true && echo -e "Already downloaded ${magenta}${PKG_FILENAME}${endcolour}" && continue
  4337.  
  4338.         # update the package name, based on PKG_FILENAME
  4339.         PKGNAME="$(basename "$PKG_FILENAME" .$curr_repo_ext)"
  4340.  
  4341.         # update generic name
  4342.         PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  4343.  
  4344.         if [ "${PKG_FILENAME}" = '' ];then
  4345.           error "Cant find pkg file name, needed to download"
  4346.           return 1
  4347.         fi
  4348.  
  4349.         # skip pings and download if already downloaded.. unless forcing download
  4350.         if [ ! -f "$PKGFILE" -o "$FORCE" = true ];then
  4351.  
  4352.           # ask user to download
  4353.           echo -en "Download ${magenta}${PKGNAME_ONLY}${endcolour} from ${lightblue}${curr_repo}${endcolour} repo$QTAG:  "
  4354.           [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  4355.           [ "$CONFIRM" != 'y' ] && echo
  4356.  
  4357.           # if user answered yes, we will now download the pkgs
  4358.           if [ "$CONFIRM" = "y" ];then #25073
  4359.  
  4360.             # only ask once
  4361.             ASK=false
  4362.  
  4363.             echo # start a new line
  4364.  
  4365.             # get the subdir (from repo line) that the package lives in
  4366.             sub_dir="`echo "$pkg_in_this_repo" | cut -f4 -d'|' | sed 's/^\.//'`"
  4367.  
  4368.             if [ "$sub_dir" = "." ];then
  4369.               sub_dir=''
  4370.             fi
  4371.  
  4372.             #s243a: TODO: figure out what this file is for???
  4373.             # pre-woof get subdir
  4374.             if [ "$sub_dir" != "" ] && [ -f "$PKGS_DIR/${repo_file}_subdirs" ];then
  4375.               sub_dir="`grep -m1 "^$PKGNAME|" "$PKGS_DIR/${repo_file}_subdirs"  2>/dev/null | cut -f7 -d'|'`"
  4376.             fi
  4377.             #s243a: TODO: maybe if the folowing produces a trailing double slash than remove it.
  4378.             # get repo mirrors (only url1 is required .. we also add a final /)
  4379.             curr_repo_url1="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f4 -d'|'`/"
  4380.             curr_repo_url2="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f5 -d'|'`/"
  4381.             curr_repo_url3="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f6 -d'|'`/"
  4382.             curr_repo_url4="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f7 -d'|'`/"
  4383.  
  4384.             # make a space separated list of all our repo URLs
  4385.             curr_repo_url_list="$curr_repo_url1 $curr_repo_url2 $curr_repo_url3 $curr_repo_url4"
  4386.  
  4387.             # clean up the list, remove any double slashes at the end of each URL
  4388.             curr_repo_url_list="`echo "$curr_repo_url_list" | sed -e "s|// |/ |g" -e "s|//\$|/\$|g"`"
  4389.  
  4390.             # update the ext to that of current repo
  4391.             pkg_ext="$curr_repo_ext"
  4392.  
  4393.             # get the best repo mirror
  4394.             #if [ "$prev_repo" != "$current_repo"  -a -f $TMPDIR/curr_repo_url ] || [ ! -f $TMPDIR/curr_repo_url ];then
  4395.               #echo "Checking '$curr_repo' repo mirrors..."
  4396.               for URL in $curr_repo_url_list
  4397.               do
  4398.                 [ -z "$URL" ] && continue
  4399.                 [ "$URL" = '/' ] && continue
  4400.                 [ "$URL" = '' ] && continue
  4401.                 #s243a:TODO: The following additions to the URL doesn't seem to do anything
  4402.                 # add some system values into the repo URL (arch, distro version, etc.. from DISTRO_SPECS)
  4403.                 URL="`echo "$URL"| sed -e 's@${DBIN_ARCH}@'$DBIN_ARCH'@g'`"
  4404.                 URL="`echo "$URL"| sed -e 's@${DISTRO_COMPAT_VERSION}@'$DISTRO_COMPAT_VERSION'@g'`"
  4405.                 URL="`echo "$URL"| sed -e 's@${DDB_COMP}@'$DDB_COMP'@g'`"
  4406.                 URL="`echo "$URL"| sed -e 's@${SLACKWARE}@'$SLACKWARE'@g'`"
  4407.                 URL="`echo "$URL"| sed -e 's@${SLACKARCH}@'$SLACKARCH'@g'`"
  4408.                 URL="`echo "$URL"| sed -e 's@${lxDISTRO_COMPAT_VERSION}@'$lxDISTRO_COMPAT_VERSION'@g'`"
  4409.                 #ping -W2 -c1 -q $(echo  "${URL}" | awk -F/ '{print $3}') &>/dev/null
  4410.                 wget --quiet --timeout=1 --no-parent --spider "${URL}"
  4411.                 REPLY=$?
  4412.                 if [ "$REPLY" = 0 ];then
  4413.                   # set the current URL
  4414.                   curr_repo_url="$URL"
  4415.                   if [ ! -z "$curr_repo_url" ];then
  4416.                     echo "$curr_repo_url" > $TMPDIR/curr_repo_url
  4417.                     break
  4418.                   fi
  4419.                 fi
  4420.               done
  4421.             #else
  4422.             # curr_repo_url="`cat $TMPDIR/curr_repo_url`"
  4423.             #fi
  4424.  
  4425.             # exit if URL is not found or empty
  4426.             if [ -z "$curr_repo_url" ]; then
  4427.               error "Package URL not found"
  4428.               return 8
  4429.             fi
  4430.  
  4431.             # lets build our DOWNLOAD_URL: set it to the working repo mirror we found above
  4432.             DOWNLOAD_URL="${curr_repo_url}"
  4433.  
  4434.             # now add the subdir to DOWNLOAD_URL .. sub_dir may be empty, but we add a trailing '/' anyway
  4435.             DOWNLOAD_URL="${DOWNLOAD_URL}${sub_dir}/"
  4436.  
  4437.             # add some system values into the repo URL (arch, distro version, etc.. from DISTRO_SPECS)
  4438.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DBIN_ARCH}@'$DBIN_ARCH'@g'`"
  4439.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DISTRO_COMPAT_VERSION}@'$DISTRO_COMPAT_VERSION'@g'`"
  4440.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DDB_COMP}@'$DDB_COMP'@g'`"
  4441.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${SLACKWARE}@'$SLACKWARE'@g'`"
  4442.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${SLACKARCH}@'$SLACKARCH'@g'`"
  4443.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${lxDISTRO_COMPAT_VERSION}@'$lxDISTRO_COMPAT_VERSION'@g'`"
  4444.  
  4445.             # add our package to the URL
  4446.             DOWNLOAD_URL="${DOWNLOAD_URL}${PKG_FILENAME}"
  4447.  
  4448.             # 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)
  4449.             DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e "s@//$PKG_FILENAME@/$PKG_FILENAME@g"`"
  4450.  
  4451.             # if sub_dir not empty, lets clean that bit too
  4452.             [ "$sub_dir" != '' ] && DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e "s@//${sub_dir}@/${sub_dir}@g" -e "s@${sub_dir}//@${sub_dir}/@g"`"
  4453.  
  4454.             # exit if URL is not found (if we get a 404 back)
  4455.             if [ -z "$DOWNLOAD_URL" -o "`wget -S --spider "$DOWNLOAD_URL" 2>&1 | grep -m1 'HTTP/1.1 404 Not Found'`" != '' ]; then
  4456.               error "Package URL not found   $DOWNLOAD_URL"
  4457.               return 8
  4458.             fi
  4459.  
  4460.             # we may be using multiple URLs, so each time we change URL,
  4461.             #  remember the new one
  4462.             if [ "$OLDURL" != "$DOWNLOAD_URL" ];then
  4463.               OLDURL="$DOWNLOAD_URL";
  4464.               #echo -e "URL: ${lightblue}${DOWNLOAD_URL}${endcolour}";
  4465.             fi
  4466.  
  4467.             # if --force, remove the package if it already exists
  4468.             [ "$FORCE" = true ] && rm -f "${WORKDIR}/${PKG_FILENAME}" &>/dev/null
  4469.  
  4470.             # if file not downloaded, or forcing downloads
  4471.             if [ ! -f "${WORKDIR}/${PKG_FILENAME}" -o "$FORCE" = true ];then
  4472.  
  4473.               # BEGIN DOWNLOAD file here..
  4474.  
  4475.               # print DOWNLOADING msg
  4476.               echo -en "Downloading ${magenta}${PKG_FILENAME}${endcolour}. Please wait:     "
  4477.  
  4478.               # if called as 'gpkg', give a pop GUI (uses Xdialog) showing download progress..
  4479.               # can be used by X apps to easily start (and show!) downloads
  4480.               if [ "$SELF" = "gpkg" ];then
  4481.  
  4482.                 download_progress "$DOWNLOAD_URL" "${WORKDIR}/${PKG_FILENAME}" 2>/dev/null
  4483.  
  4484.               else # if called as 'pkg', dont use Xdialog, output to terminal
  4485.  
  4486.                 if [ "$QUIET" = true ];then
  4487.                   echo
  4488.                   echo -n "Downloading now..."
  4489.                   LANG=C wget \
  4490.                     --no-check-certificate \
  4491.                     --progress=dot -O "${WORKDIR}/${PKG_FILENAME}" \
  4492.                     -4 $CONTINUE "$DOWNLOAD_URL" &>/dev/null
  4493.                 else
  4494.                   # START DOWNLOAD, show percentage as we go
  4495.                   LANG=C wget \
  4496.                     --no-check-certificate \
  4497.                     --progress=dot -O "${WORKDIR}/${PKG_FILENAME}" \
  4498.                     -4 $CONTINUE "$DOWNLOAD_URL" 2>&1 \
  4499.                     | grep --line-buffered "%" \
  4500.                     | sed -u -e "s#\.##g" \
  4501.                     | awk '{printf("\b\b\b\b%4s", $2)}' #220613
  4502.                 fi
  4503.  
  4504.               fi
  4505.  
  4506.             fi # end if WORKDIR/PKG not a file or FORCE=true
  4507.  
  4508.             # clean up output
  4509.             [ "$QUIET" != true ] && echo -ne "\b\b\b\b"
  4510.             echo
  4511.  
  4512.             # if file downloaded ok
  4513.             if [ -f "${WORKDIR}/${PKG_FILENAME}" ];then
  4514.               echo -e "${green}Downloaded:${endcolour} ${WORKDIR}/${PKG_FILENAME}"
  4515.               DONE=true
  4516.               break
  4517.  
  4518.             else # file NOT downloaded ok
  4519.  
  4520.               error "Failed to download '${WORKDIR}/${PKG_FILENAME}'."
  4521.               echo "Check '$DOWNLOAD_URL'"
  4522.  
  4523.               # remove the page we tried to get pkg from (if exists)
  4524.               rm "${WORKDIR}/index.html" &>/dev/null
  4525.               DONE=true
  4526.               exit 6
  4527.             fi
  4528.  
  4529.           fi # end if CONFIRM=y
  4530.  
  4531.           # user chose not to do anything
  4532.           DONE=true
  4533.           break
  4534.  
  4535.         else # Already downloaded, skip to next iteration
  4536.  
  4537.           #echo "Package $1 already downloaded"
  4538.           DONE=true
  4539.           break
  4540.         fi
  4541.  
  4542.       else # no repo match, nothing to download
  4543.  
  4544.         # go to next repo, try to ge tthe pkg there
  4545.         DONE=false
  4546.  
  4547.       fi # end if repo match was found
  4548.  
  4549.       # if download not successful, keep going to next repo
  4550.       [ "$DONE" = true ] && continue
  4551.  
  4552.     done #done while read list of repo files
  4553.  
  4554.   fi
  4555. }
  4556.  
  4557.  
  4558. pkg_install(){                    # install downloaded package ($1) FUNCLIST
  4559.  
  4560.   . ${PKGRC}
  4561.  
  4562.   # exit if no valid option
  4563.   [ ! "$1" -o "$1" = "-" ] && print_usage install && exit 1
  4564.  
  4565.   # skip if not installing pkgs
  4566.   [ "$NO_INSTALL" = true ] && continue
  4567.  
  4568.   local pkg_ext
  4569.   local PKGNAME
  4570.   local PKGNAME_ONLY
  4571.   local PKGFILE
  4572.   local PREVDIR="$CURDIR"
  4573.   local petspecs
  4574.  
  4575.   # get pkg extension
  4576.   pkg_ext=`get_pkg_ext "$1"`
  4577.   # get pkg name only, no extension or path
  4578.   PKGNAME="$(basename "$1" .$pkg_ext)"
  4579.   # exit if no valid option
  4580.   [ "$PKGNAME" = '' ] && print_usage install && exit 1
  4581.   # get name without version
  4582.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  4583.  
  4584.   [ "`is_installed_pkg "$PKGNAME"`" = true -a "$FORCE" = false ] && echo "Already installed: $PKGNAME" && return 1
  4585.   [ "`is_blacklisted_pkg "$PKGNAME_ONLY"`" = true ] && echo "Blacklisted package: $PKGNAME" && return 1
  4586.  
  4587.   if [ -f "$1" ];then
  4588.     PKGFILE="$1"
  4589.     PKGNAME=`basename "$1" .$pkg_ext`
  4590.   else
  4591.     # get the real file name (inc path) from the given PKGFILE and pkg_ext (which may be empty)
  4592.     PKGFILE=`find "$CURDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${pkg_ext}" | head -1`
  4593.     [ ! -f "$PKGFILE" ] && PKGFILE=`find "$CURDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${EX}" | grep -m1 $EX`
  4594.     [ -f "$PKGFILE" ] && PKGNAME=`basename "$1" .$pkg_ext`
  4595.   fi
  4596.  
  4597.   # maybe the file is not in the current dir, but in WORKDIR, so lets look there too
  4598.   if [ ! -f "$PKGFILE" ];then
  4599.     PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${pkg_ext}" | head -1`
  4600.     [ ! -f "$PKGFILE" ] && PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${EX}" | grep -m1 $EX`
  4601.  
  4602.     # if we found the file in WORKDIR, make that our CURDIR
  4603.     if [ -f "$PKGFILE" ];then
  4604.       PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4605.       CURDIR="$WORKDIR"
  4606.       cd "$WORKDIR"
  4607.     else
  4608.       # if we still didn't find it, do a broader check
  4609.       PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*" | head -1`
  4610.       if [ -f "$PKGFILE" ];then
  4611.         PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4612.         CURDIR="$WORKDIR"
  4613.         cd "$WORKDIR"
  4614.       fi
  4615.     fi
  4616.   fi
  4617.  
  4618.   # if the file exists, or using --force
  4619.   if [ -f "$PKGFILE" -o "$FORCE" = true ];then
  4620.  
  4621.     [ ! -f "$PKGFILE" ] && echo "The file $1 was not found." && return 1
  4622.  
  4623.     # get the extension of this newly found pkg (which we should have found by now)
  4624.     pkg_ext=`get_pkg_ext "$PKGFILE"`
  4625.     # get extension again, we may have been given only a pkg name, find its extension from repo files
  4626.     [ "$pkg_ext" = "" ] && pkg_ext=`get_pkg_ext "$PKGNAME"`
  4627.  
  4628.     [ "$pkg_ext" = '' ] && echo "Not installing $PKGFILE." && error "Invalid file extension ($pkg_ext)." && return 1
  4629.  
  4630.     # remove any previous PET/pkg stuff lying around from previous installs
  4631.     rm -f /pet.specs /pinstall.sh /puninstall.sh /install/doinst.sh
  4632.  
  4633.     # if pkg is not yet installed, or we are force re-installing
  4634.  
  4635.     # get filename from download file
  4636.     PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4637.  
  4638.     # ask/inform user before install
  4639.     echo -n "Install package ${PKGNAME}$QTAG:  "
  4640.     [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  4641.     [ "$ASK" = true ] && echo -ne "\b\b\n"
  4642.  
  4643.     # if user answered yes, we will now download the pkgs
  4644.     if [ "$CONFIRM" = "y" ];then
  4645.  
  4646.       # print new line if we didnt take any user input on tty
  4647.       [ "$ASK" != true ] && echo
  4648.  
  4649.       # only ask once
  4650.       ASK=false
  4651.  
  4652.       #if [ "`pkg_contents "$PKGFILE" 2>/dev/null`" = '' ];then
  4653.       # error "$PKGFILE not a valid package."
  4654.       # exit 1
  4655.       #fi
  4656.  
  4657.       # fallback to repo pkg ext if none found
  4658.       [ "$pkg_ext" = "" ] && pkg_ext="$EX"
  4659.  
  4660.       #remove the old error log
  4661.       rm $TMPDIR/$SELF-cp-errlog 2>/dev/null
  4662.  
  4663.       # extract the archive file into a $CURDIR/$PKGNAME folder
  4664.       case "$pkg_ext" in
  4665.  
  4666.         pet)
  4667.           PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.pet"`"
  4668.           #determine the compression, extend test to 'XZ'
  4669.           file -b "${PKGFILE}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  4670.           [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  4671.  
  4672.           # convert to tar extractable archive
  4673.           pet2tgz "${PKGFILE}" 1>/dev/null
  4674.  
  4675.           # now extract the file
  4676.           tar $taropts "${CURDIR}/${PKGNAME}.tar.${TAREXT}" 2> $TMPDIR/$SELF-cp-errlog
  4677.  
  4678.           # some old types need this extra step
  4679.           if [ -f "${CURDIR}/${PKGNAME}.tar.$TAREXT" ];then
  4680.             cd "${CURDIR}/${PKGNAME}/" 1>/dev/null
  4681.             tar --absolute-names $tarops "./${PKGNAME}.tar.$TAREXT" ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog #260713
  4682.             sync
  4683.             rm -f  "./${PKGNAME}.tar.$TAREXT" 1>/dev/null
  4684.             cd - 1>/dev/null
  4685.           fi
  4686.  
  4687.           # save the uninstall script for later
  4688.           if [ -f "${CURDIR}/${PKGNAME}/puninstall.sh" ];then
  4689.             mv "${CURDIR}/${PKGNAME}/puninstall.sh" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove"
  4690.           fi
  4691.  
  4692.           # create a tgz
  4693.           tgz2pet "${CURDIR}/${PKGNAME}.tar.$TAREXT" 1>/dev/null
  4694.           rm "${CURDIR}/${PKGNAME}.tar.$TAREXT" 2>/dev/null
  4695.         ;;
  4696.  
  4697.         sfs)
  4698.           PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.sfs"`"
  4699.           [ ! -f "$PKGFILE" ] && PKGFILE="`find ${WORKDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.sfs"`"
  4700.           echo sfs_loadr -q --cli +"$PKGFILE" #2>/dev/null
  4701.           sfs_loadr -q --cli +"$PKGFILE" #2>/dev/null
  4702.           rm -f $PACKAGE_FILE_LIST_DIR/${PKGNAME}.files 2>/dev/null
  4703.           # create $PKGS_DIR/$PKGNAME.files
  4704.           pkg_contents "$PKGFILE" | while read line
  4705.           do
  4706.             [ -f "$line" ] && echo "$line" >> $PACKAGE_FILE_LIST_DIR/${PKGNAME}.files
  4707.           done
  4708.           # exit, we dont need to unpack and copy
  4709.           return 0
  4710.         ;;
  4711.  
  4712.         deb)
  4713.  
  4714.           rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4715.           mkdir -p "${CURDIR}/${PKGNAME}"
  4716.           [ ! -f "$PKGFILE" ] && PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.deb"`"
  4717.           cp "${PKGFILE}" "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" || exit 4
  4718.           cd "${CURDIR}/${PKGNAME}/"
  4719.  
  4720.           if [ -f "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" ];then
  4721.             dpkg-deb --contents "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" \
  4722.               | grep -v '/$' \
  4723.               | tr -s ' ' \
  4724.               | cut -f6 -d' ' \
  4725.               | sed -e 's/^.//g' 2>/dev/null \
  4726.               | grep -v '^$' > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4727.           fi
  4728.  
  4729.                     # woofce: NO_MULTIARCH_SYMLINK=1 (DISTRO_SPECS)
  4730.                     if [ -z "$NO_MULTIARCH_SYMLINK" ] ; then
  4731.             if [ -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ];then
  4732.               pkg_has_archdir="$(grep -m1 "$DISTRO_ARCHDIR" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")"
  4733.             fi
  4734.  
  4735.                         # Workaround to avoid overwriting the $DISTRO_ARCHDIR symlink.
  4736.                         if [ "$DISTRO_ARCHDIR" != "" -a -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" -a "$pkg_has_archdir" != "" ]; then
  4737.                           mkdir -p /tmp/$PKGNAME
  4738.                           rm -rf /tmp/$PKGNAME/*
  4739.                           dpkg-deb -x ${CURDIR}/${PKGNAME}.deb /tmp/$PKGNAME/ 2> $TMPDIR/$SELF-cp-errlog
  4740.                           for f in $(find /tmp/$PKGNAME \( -type f -o -type l \))
  4741.                           do
  4742.                               xpath=$(echo "$f" |  cut  -f 4-30 -d "/" | sed "s/$DISTRO_ARCHDIR\///")
  4743.                               mkdir -p ${DIRECTSAVEPATH}/$(dirname "$xpath")
  4744.                               cp -a "$f" ${DIRECTSAVEPATH}/$(dirname "$xpath")/
  4745.                           done
  4746.                           rm -rf /tmp/$PKGNAME &>/dev/null
  4747.                         else
  4748.                           dpkg-deb -x ${CURDIR}/${PKGNAME}.deb ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4749.                         fi
  4750.                     else
  4751.                         dpkg-deb -x ${CURDIR}/${PKGNAME}.deb ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4752.                     fi
  4753.  
  4754.           if [ "`cat $TMPDIR/$SELF-cp-errlog | grep 'tar: Exiting with failure status due to previous errors'`" != "" ];then
  4755.             error "Failed to unpack $PKGNAME.deb"
  4756.             exit 1
  4757.           fi
  4758.           [ -d /DEBIAN ] && rm -rf /DEBIAN #130112 precaution.
  4759.           dpkg-deb -e "${CURDIR}/${PKGNAME}.deb" /DEBIAN #130112 extracts deb control files to dir /DEBIAN. may have a post-install script, see below.
  4760.           rm "${PKGNAME}.deb"
  4761.  
  4762.           cd - 1>/dev/null
  4763.         ;;
  4764.  
  4765.         *tbz|*tar.bz2)
  4766.           rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4767.           mkdir -p "${CURDIR}/${PKGNAME}"
  4768.           cp "${CURDIR}/${PKGNAME}.$pkg_ext" "${CURDIR}/${PKGNAME}/${PKGNAME}.$pkg_ext" || exit 4
  4769.           cd "${CURDIR}/${PKGNAME}/"
  4770.  
  4771.           ( umask 000 ; cat "${PKGNAME}.$pkg_ext" | bzip2 -dc | tar -xf - 2> $TMPDIR/$SELF-cp-errlog )
  4772.  
  4773.           rm "${PKGNAME}.$pkg_ext"
  4774.           cd - 1>/dev/null
  4775.         ;;
  4776.  
  4777.         *tlz|*tar.lzma)
  4778.           rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4779.           mkdir -p "${CURDIR}/${PKGNAME}"
  4780.           PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.${pkg_ext}"`"
  4781.           cp "$PKGFILE" "${CURDIR}/${PKGNAME}/`basename $PKGFILE`" || exit 4
  4782.           cd "${CURDIR}/${PKGNAME}/"
  4783.  
  4784.           ( umask 000 ; cat "${PKGNAME}.$pkg_ext" | lzma -dc | tar -xf - 2> $TMPDIR/$SELF-cp-errlog )
  4785.  
  4786.           rm "${PKGNAME}.$pkg_ext"
  4787.           cd - 1>/dev/null
  4788.         ;;
  4789.  
  4790.         *tgz|*txz|*tar.gz|*tar.xz|*xz|*gz)
  4791.           rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4792.           mkdir -p "${CURDIR}/${PKGNAME}"
  4793.           PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.${pkg_ext}"`"
  4794.           cp "$PKGFILE" "${CURDIR}/${PKGNAME}/`basename $PKGFILE`" || exit 4
  4795.           cd "${CURDIR}/${PKGNAME}/"
  4796.  
  4797.           file -b "${PKGNAME}.$pkg_ext" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  4798.           [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  4799.  
  4800.           tar $taropts "${PKGNAME}.$pkg_ext" 2> $TMPDIR/$SELF-cp-errlog
  4801.           rm "${PKGNAME}.$pkg_ext"
  4802.           cd - 1>/dev/null
  4803.         ;;
  4804.  
  4805.         rpm)
  4806.           PKGNAME="`basename ${PKGFILE} .rpm`"
  4807.           busybox rpm -qp "$PKGFILE" > /dev/null 2>&1
  4808.           [ $? -ne 0 ] && exit 1
  4809.           PFILES="`busybox rpm -qpl $PKGFILE`"
  4810.           [ $? -ne 0 ] && exit 1
  4811.           echo "$PFILES" > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4812.           pkg_unpack "$PKGFILE" 1>/dev/null
  4813.         ;;
  4814.  
  4815.       esac
  4816.  
  4817.       # now extract pkg contents to /
  4818.       [ ! -d "${PKGNAME}/" ] && error "Cannot enter directory '${PKGNAME}/', it doesn't exist." && exit 4
  4819.       cd "${PKGNAME}/" 1>/dev/null
  4820.  
  4821.       cp -a --remove-destination * ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4822.  
  4823.       #source is a directory, target is a symlink...
  4824.       if [ -s $TMPDIR/$SELF-cp-errlog ];then
  4825.         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 '`' |
  4826.         while read ONEDIRSYMLINK
  4827.         do
  4828.           #adding that extra trailing / does the trick...
  4829.           cp -a --remove-destination ${ONEDIRSYMLINK}/* /${ONEDIRSYMLINK}/ 2> $TMPDIR/$SELF-cp-errlog #260713
  4830.         done
  4831.       fi
  4832.       sync
  4833.       cd .. 1>/dev/null
  4834.  
  4835.       if [ ! -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ] || \
  4836.          [ -z "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ];then
  4837.         # add ${HOME}/.packages/${PKGNAME}.files, need to find regular files and links separately... then images..
  4838.         find "./${PKGNAME}/" -mount -mindepth 2 -type f | sed -e "s/\.\/${PKGNAME}//g" -e 's/\/root0\//\/root\//g' > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4839.         find "./${PKGNAME}/" -mount -mindepth 2 -type l | sed -e "s/\.\/${PKGNAME}//g" -e 's/\/root0\//\/root\//g' >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4840.  
  4841.         for ONEIMAGEFILE in `ls -1 /*[0-9].xpm 2>/dev/null`
  4842.         do
  4843.          BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4844.          echo "/usr/local/lib/X11/pixmaps/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4845.         done
  4846.         for ONEIMAGEFILE in `ls -1 /*[0-9].png 2>/dev/null`
  4847.         do
  4848.          BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4849.          echo "/usr/local/lib/X11/pixmaps/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4850.         done
  4851.         for ONEIMAGEFILE in `ls -1 /*[^0-9].xpm 2>/dev/null`
  4852.         do
  4853.          BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4854.          echo "/usr/local/lib/X11/mini-icons/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4855.         done
  4856.         for ONEIMAGEFILE in `ls -1 /*[^0-9].png 2>/dev/null` #v2.16
  4857.         do
  4858.          BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4859.          echo "/usr/local/lib/X11/mini-icons/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4860.         done
  4861.       fi
  4862.  
  4863.       # move the *.files to $PKGS_DIR
  4864.       FILES=''
  4865.       FILES="`find "$CURDIR" -mount -maxdepth 1 -iname "*.files" | head -1`"
  4866.       [ -f "`echo $FILES`" ] && mv "$FILES" "$PACKAGE_FILE_LIST_DIR/" 2>/dev/null #260713
  4867.  
  4868.       #pkgname.files may need to be fixed...
  4869.       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"
  4870.       mv "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4871.  
  4872.       sort -u "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2"
  4873.       mv "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4874.  
  4875.       # some pets add images and icons at / so move them
  4876.       mv /{*.xpm,*.png} /usr/share/pixmaps/ 2>/dev/null
  4877.       mv /*.ico /usr/share/pixmaps/ 2>/dev/null
  4878.  
  4879.       # run the post install scripts (for puppy, slackware, arch, debian/ubuntu, etc)
  4880.       for i in /pinstall.sh /install/doinst.sh /DEBIAN/postinst
  4881.       do
  4882.         [ -z /${i} -o ! -e /${i} ] && continue
  4883.         chmod +x /${i}
  4884.         cd /
  4885.         nohup sh ${i} &>/dev/null
  4886.         sleep 0.2
  4887.         rm -f ${i}
  4888.         cd ${CURDIR}/
  4889.       done
  4890.       rm -rf /install
  4891.       rm -rf /DEBIAN
  4892.  
  4893.       #130314 run arch linux pkg post-install script...
  4894.       if [ -f /.INSTALL -a /usr/local/petget/ArchRunDotInstalls ];then #precaution. see 3builddistro, script created by noryb009.
  4895.         #this code is taken from below...
  4896.         dlPATTERN='|'"`echo -n "${PKGNAME}" | sed -e 's%\\-%\\\\-%'`"'|'
  4897.         archVER="`cat $TMPDIR/petget_missing_dbentries-Packages-* 2>/dev/null | grep "$dlPATTERN" | head -n 1 | cut -f 3 -d '|'`"
  4898.         if [ "$archVER" ];then #precaution.
  4899.           cd /
  4900.           mv -f .INSTALL .INSTALL1-${archVER}
  4901.           cp -a /usr/local/petget/ArchRunDotInstalls ArchRunDotInstalls
  4902.           LANG=$LANG_USER ./ArchRunDotInstalls
  4903.           rm -f ArchRunDotInstalls
  4904.           rm -f .INSTALL*
  4905.           cd ${CURDIR}/
  4906.         fi
  4907.       fi
  4908.  
  4909.       PKGCAT=''
  4910.       PKGSIZE=''
  4911.       PKGDESC=''
  4912.       DEPLIST=''
  4913.  
  4914.       # clean up pet installs
  4915.       if [ "$pkg_ext" = "pet" ];then
  4916.         cd /
  4917.  
  4918.         # get pkg info from pet.spec before we delete it, because the PET may not be a repo pkg
  4919.         petspecs="`cat /pet.specs 2>/dev/null`"
  4920.  
  4921.         if [ "$petspecs" != '' ];then
  4922.           # now get pkg info
  4923.           PKGCAT="`echo $petspecs|  cut -f5  -d'|'`"
  4924.           PKGSIZE="`echo $petspecs| cut -f6  -d'|'`"
  4925.           PKGDESC="`echo $petspecs| cut -f10 -d'|'`"
  4926.           DEPSLIST="`echo $petspecs|cut -f9  -d'|'`"
  4927.         fi
  4928.  
  4929.         cd ${CURDIR}/
  4930.       fi
  4931.  
  4932.       # cleanup a bit
  4933.       rm -R "${PKGNAME}/" 2>/dev/null || echo "${yellow}Warning:${endcolour} Cannot remove directory '${PKGNAME}/'." #150213
  4934.  
  4935.       #120102 install may have overwritten a symlink-to-dir...
  4936.       #tar defaults to not following symlinks, for both dirs and files, but i want to follow symlinks
  4937.       #for dirs but not for files. so, fix here... (note, dir entries in .files have / on end)
  4938.       cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" | grep '[a-zA-Z0-9]/$' | sed -e 's%/$%%' | grep -v '^/mnt' |
  4939.       while read ONESPEC
  4940.       do
  4941.        if [ -d "${DIRECTSAVEPATH}${ONESPEC}" ];then
  4942.         if [ ! -h "${DIRECTSAVEPATH}${ONESPEC}" ];then
  4943.          DIRLINK=""
  4944.          if [ -h "/initrd${PUP_LAYER}${ONESPEC}" ];then #120107
  4945.           DIRLINK="`readlink -m "/initrd${PUP_LAYER}${ONESPEC}" | sed -e "s%/initrd${PUP_LAYER}%%"`" #PUP_LAYER: see /etc/rc.d/PUPSTATE. 120107
  4946.           xDIRLINK="`readlink "/initrd${PUP_LAYER}${ONESPEC}"`" #120107
  4947.          fi
  4948.          if [ ! "$DIRLINK" ];then
  4949.           if [ -h "/initrd${SAVE_LAYER}${ONESPEC}" ];then #120107
  4950.            DIRLINK="`readlink -m "/initrd${SAVE_LAYER}${ONESPEC}" | sed -e "s%/initrd${SAVE_LAYER}%%"`" #SAVE_LAYER: see /etc/rc.d/PUPSTATE. 120107
  4951.            xDIRLINK="`readlink "/initrd${SAVE_LAYER}${ONESPEC}"`" #120107
  4952.           fi
  4953.          fi
  4954.          if [ "$DIRLINK" ];then
  4955.           if [ -d "$DIRLINK"  ];then
  4956.            if [ "$DIRLINK" != "${ONESPEC}" ];then #precaution.
  4957.             mkdir -p "${DIRECTSAVEPATH}${DIRLINK}" #120107
  4958.             cp -a -f --remove-destination ${DIRECTSAVEPATH}"${ONESPEC}"/* "${DIRECTSAVEPATH}${DIRLINK}/" #ha! fails if put double-quotes around entire expression.
  4959.             rm -rf "${DIRECTSAVEPATH}${ONESPEC}"
  4960.             if [ "$DIRECTSAVEPATH" = "" ];then
  4961.              ln -s "$xDIRLINK" "${ONESPEC}"
  4962.             else
  4963.              DSOPATH="`dirname "${DIRECTSAVEPATH}${ONESPEC}"`"
  4964.              DSOBASE="`basename "${DIRECTSAVEPATH}${ONESPEC}"`"
  4965.              rm -f "${DSOPATH}/.wh.${DSOBASE}" #allow underlying symlink to become visible on top.
  4966.             fi
  4967.            fi
  4968.           fi
  4969.          fi
  4970.         fi
  4971.        fi
  4972.       done
  4973.  
  4974.             # woofce: NO_MULTIARCH_SYMLINK=1 (DISTRO_SPECS)
  4975.             if [ -z "$NO_MULTIARCH_SYMLINK" ] ; then
  4976.         #121217 it seems that this problem is occurring in other modes (13 reported)...
  4977.         #121123 having a problem with multiarch symlinks in full-installation...
  4978.         #it seems that the symlink is getting replaced by a directory.
  4979.         if [ "$DISTRO_ARCHDIR" ];then #in /etc/rc.d/DISTRO_SPECS. 130112 change test from DISTRO_ARCHDIR. 130114 revert DISTRO_ARCHDIR_SYMLINKS==yes.
  4980.           if [ -d /usr/lib/${DISTRO_ARCHDIR} ];then
  4981.             if [ ! -h /usr/lib/${DISTRO_ARCHDIR} ];then
  4982.               cp -a -f --remove-destination /usr/lib/${DISTRO_ARCHDIR}/* /usr/lib/
  4983.               sync
  4984.               rm -r -f /usr/lib/${DISTRO_ARCHDIR}
  4985.               ln -s ./ /usr/lib/${DISTRO_ARCHDIR}
  4986.             fi
  4987.           fi
  4988.           if [ -d /lib/${DISTRO_ARCHDIR} ];then
  4989.             if [ ! -h /lib/${DISTRO_ARCHDIR} ];then
  4990.               cp -a -f --remove-destination /lib/${DISTRO_ARCHDIR}/* /lib/
  4991.               sync
  4992.               rm -r -f /lib/${DISTRO_ARCHDIR}
  4993.               ln -s ./ /lib/${DISTRO_ARCHDIR}
  4994.             fi
  4995.           fi
  4996.           if [ -d /usr/bin/${DISTRO_ARCHDIR} ];then
  4997.             if [ ! -h /usr/bin/${DISTRO_ARCHDIR} ];then
  4998.               cp -a -f --remove-destination /usr/bin/${DISTRO_ARCHDIR}/* /usr/bin/
  4999.               sync
  5000.               rm -r -f /usr/bin/${DISTRO_ARCHDIR}
  5001.               ln -s ./ /usr/bin/${DISTRO_ARCHDIR}
  5002.             fi
  5003.           fi
  5004.         fi
  5005.       fi
  5006.  
  5007.       #flush unionfs cache, so files in pup_save layer will appear "on top"...
  5008.       if [ "$DIRECTSAVEPATH" != "" ];then
  5009.        #but first, clean out any bad whiteout files...
  5010.        # 22sep10 shinobar: bugfix was not working clean out whiteout files
  5011.        find /initrd/pup_rw -mount -type f -name .wh.\*  -printf '/%P\n'|
  5012.        while read ONEWHITEOUT
  5013.        do
  5014.         ONEWHITEOUTFILE="`basename "$ONEWHITEOUT"`"
  5015.         ONEWHITEOUTPATH="`dirname "$ONEWHITEOUT"`"
  5016.         if [ "$ONEWHITEOUTFILE" = ".wh.__dir_opaque" ];then
  5017.          [ "$(grep "$ONEWHITEOUTPATH" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != "" ] && rm -f "/initrd/pup_rw/$ONEWHITEOUT"
  5018.          continue
  5019.         fi
  5020.         ONEPATTERN="`echo -n "$ONEWHITEOUT" | sed -e 's%/\\.wh\\.%/%'`"'/*' ;#echo "$ONEPATTERN" >&2
  5021.         [ "$(grep -x "$ONEPATTERN" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != "" ] && rm -f "/initrd/pup_rw/$ONEWHITEOUT"
  5022.        done
  5023.        #111229 /usr/local/petget/removepreview.sh when uninstalling a pkg, may have copied a file from sfs-layer to top, check...
  5024.        cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" |
  5025.        while read ONESPEC
  5026.        do
  5027.         [ "$ONESPEC" = "" ] && continue #precaution.
  5028.         if [ ! -d "$ONESPEC" ];then
  5029.          [ -e "/initrd/pup_rw${ONESPEC}" ] && rm -f "/initrd/pup_rw${ONESPEC}"
  5030.         fi
  5031.        done
  5032.        #now re-evaluate all the layers...
  5033.        busybox mount -t aufs -o remount,udba=reval unionfs / #remount with faster evaluation mode.
  5034.        [ $? -ne 0 ] && logger -s -t "pkg" "Failed to remount aufs / with udba=reval"
  5035.        sync
  5036.       fi
  5037.  
  5038.       # get pkg size, category and description
  5039.       [ "$PKGCAT" = ''  ] && PKGCAT=`LANG=C  grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f5 -d'|' | head -1`
  5040.       [ "$PKGCAT" = ''  ] && PKGCAT=`LANG=C  grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f5 -d'|' | head -1`
  5041.       [ "$PKGDESC" = '' ] && PKGDESC=`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null| cut -f10 -d'|' | head -1`
  5042.       [ "$PKGDESC" = '' ] && PKGDESC=`LANG=C grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null| cut -f10 -d'|' | head -1`
  5043.       [ "$PKGSIZE" = '' ] && PKGSIZE=`LANG=C du -s -k ${CURDIR}/${PKG} 2>/dev/null | cut -f1`
  5044.       # get pkg version
  5045.       PKGVER="`LANG=C  echo "$PKGNAME" | sed -e 's/^[^0-9]*-//g'`"
  5046.       PKGARCH="`LANG=C echo "$PKGNAME" | cut -f3 -d'-' | grep -E 'i[3-9]|x[8-9]|noarch'`"
  5047.  
  5048.       # last check for pkg info
  5049.       [ "$DEPSLIST" = '' ] && DEPSLIST="`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR"/Packages-* 2>/dev/null | cut -f9 -d'|' | grep '+' | head -1`"
  5050.       [ "$PKGDESC" = ''  ] && PKGDESC="No description"
  5051.  
  5052.       #080917 - build woof compatible repo line .. #090817
  5053.       if [ "`cut -f1 -d'|' "$USER_INST_PKGS_FILE" 2>/dev/null | grep -m1 ^${PKGNAME}`" = '' ];then
  5054.  
  5055.         # get the package db entry to add to user-installed-packages...
  5056.         # first, get it from petspecs if possible, or from the pkgs repo, or make one
  5057.         if [ -f /pet.specs ];then
  5058.           DB_ENTRY="`cat /pet.specs | head -n 1`"
  5059.         elif [ "`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/$REPOFILE"`" != "" ];then
  5060.           DB_ENTRY="`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/$REPOFILE"`"
  5061.         else
  5062.           DB_ENTRY="${PKGNAME}|${PKGNAME_ONLY}|${PKGVER}|${BUILD}|${PKGCAT}|${PKGSIZE}|${PKGDIR}|${PKGNAME}.${pkg_ext}|${DEPSLIST}|${PKGDESC}|${DISTRO_BINARY_COMPAT}|${DISTRO_COMPAT_VERSION}"
  5063.         fi
  5064.  
  5065.         # Fix for Debian executables showing as shared libs in ROX.
  5066.         if [ "$DISTRO_FILE_PREFIX" = "stretch" -o "$DISTRO_FILE_PREFIX" = "ascii" ]; then
  5067.           if [ "$(ps aux | grep ROX |grep -v grep)" ]; then # Other managers are OK
  5068.             if [ "$(which elfedit)" ];then
  5069.               grep -E '/bin/|/sbin/' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" |
  5070.               while read FLINE
  5071.               do
  5072.                 [ "$(file "$FLINE" | grep -i 'shared object')" ] && elfedit --input-type=dyn --output-type=exec $FLINE
  5073.               done
  5074.             else
  5075.               echo -e "${yellow}Warning${endcolour} Recent Debian executables show as shared libraries in ROX,"
  5076.               echo "which causes ROX to fail to open or execute them. To fix that during package "
  5077.               echo "installation you should install elfutils or have devx loaded."
  5078.             fi
  5079.           fi
  5080.         fi
  5081.  
  5082.         # now add the db entry to user-installed-packages
  5083.         echo "$DB_ENTRY" >> "$USER_INST_PKGS_FILE" #130913
  5084.  
  5085.       fi
  5086.  
  5087.       # now delete the petspecs file(s), we already added our PKG info to installed-packages
  5088.       rm /pet.specs &>/dev/null
  5089.       rm /*.pet.specs &>/dev/null
  5090.  
  5091.       # make sure /tmp has correct permission, a pkg may have overwritten it
  5092.       ls -dl /tmp | grep -q '^drwxrwxrwt' || chmod 1777 /tmp #130305 rerwin.
  5093.  
  5094.       #090817
  5095.       if [ "$(is_installed_pkg $PKGNAME)" = true -a "$(cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != '' ];then
  5096.         echo -e "${green}Installed:${endcolour} $PKGNAME"
  5097.         # show if pkg has menu entry
  5098.         menu_entry_msg "$PKGNAME_ONLY"
  5099.         #080413 do fixmenus, if menu entry found #200713 moved here
  5100.         if [ "$(grep -m1 '/usr/share/applications' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" 2>/dev/null | grep desktop$)" != "" ];then
  5101.           [ ! -f /tmp/pkg/update_menus_busy ] && update_menus &
  5102.         fi
  5103.         [ "`which logger`" != '' ] && logger "$0 Package $PKGNAME installed by $APP $APPVER"
  5104.       else
  5105.         error "$PKGNAME may not have installed correctly."
  5106.       fi
  5107.  
  5108.       #100817 clean up user-installed-packages (remove duplicates and empty lines
  5109.       cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages_clean"
  5110.       mv "$PKGS_DIR/user-installed-packages_clean" "$USER_INST_PKGS_FILE"
  5111.  
  5112.       # puppy specific fixes for installed package
  5113.       postinstall_hacks "$PKGNAME" "$PKGNAME_ONLY" &
  5114.  
  5115.       #100622 slackware 13.1: just in case any got through, remove c-shell scripts...
  5116.       rm -f /etc/profile.d/*.csh* 2>/dev/null
  5117.  
  5118.       #120523 precise puppy needs this... (refer also rc.update and 3builddistro)
  5119.       if [ "`grep '/usr/share/glib-2.0/schemas' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}*.files" 2>/dev/null`" != "" ];then
  5120.         [ -e /usr/bin/glib-compile-schemas ] && /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &>/dev/null
  5121.       fi
  5122.  
  5123.       if [ "`grep '/usr/lib/gio/modules' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" 2>/dev/null`" != "" ];then
  5124.         [ -e /usr/bin/gio-querymodules ] && /usr/bin/gio-querymodules /usr/lib/gio/modules &>/dev/null
  5125.       fi
  5126.  
  5127.       sync
  5128.  
  5129.     fi #if CONFIRM = y #100213,0.9  moved down to here, fixes install, and output msgs
  5130.  
  5131.   else # file doesn't exists, user must download it first
  5132.  
  5133.     if [ "$PKGNAME" != '' ];then
  5134.  
  5135.       echo "Package '$PKGNAME' not yet downloaded."
  5136.  
  5137.       matching_local_pkgs="`list_downloaded_pkgs $PKGNAME`"
  5138.  
  5139.       # if no matching pkgs downloaded
  5140.       if [ "$matching_local_pkgs" != "" ];then
  5141.         echo "You could install one of the following packages with \`$SELF -i PKGNAME\`:"
  5142.         echo "`list_downloaded_pkgs $(basename "$PKGNAME" .$pkg_ext 2>/dev/null) 2>/dev/null`"
  5143.  
  5144.       # else if not downloaded, and in the current repo, list the matching repo pkgs
  5145.       elif [ "$matching_local_pkgs" = "" -a "`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null`" != "" ];then
  5146.         echo "You must first download one of the following packages with \`$SELF -d PKGNAME\`:"
  5147.         echo "`$PKGSEARCH $(basename $PKGNAME .$pkg_ext)`"
  5148.  
  5149.       else
  5150.         not_found "${PKGNAME}"
  5151.       fi
  5152.  
  5153.     else # PKGNAME is empty
  5154.  
  5155.       echo "Package could not be identified."
  5156.  
  5157.     fi
  5158.  
  5159.     exit 1
  5160.  
  5161.   fi
  5162.  
  5163.   # go back to the dir we started in
  5164.   cd "$PREVDIR"
  5165.  
  5166. }
  5167.  
  5168.  
  5169. postinstall_hacks(){              # fix pkgs after installation
  5170.   local PKGNAME="$1"
  5171.   local PKGNAME_ONLY="$2"
  5172.  
  5173.   # remove %u, %U, %f (etc) from Exec lines
  5174.   DESKTOPFILE="`find /usr/share/applications -iname "${PKGNAME_ONLY}*.desktop"`"
  5175.   [ -f "$DESKTOPFILE" ] && \
  5176.     sed -i 's/ %u//' $DESKTOPFILE && \
  5177.     sed -i 's/ %U//' $DESKTOPFILE && \
  5178.     sed -i 's/ %f//' $DESKTOPFILE && \
  5179.     sed -i 's/ %F//' $DESKTOPFILE
  5180.  
  5181.   case $PKGNAME in
  5182.    0ad-*|0ad_*)
  5183.     bbe -e 's/geteuid/getppid/' /usr/games/pyrogenesis > /usr/games/pyrogenesis1 2>/dev/null
  5184.     mv /usr/games/pyrogenesis1 /usr/games/pyrogenesis
  5185.     chmod 755 /usr/games/pyrogenesis
  5186.    ;;
  5187.    openclonk-*|openclonk_*)
  5188.     bbe -e 's/geteuid/getppid/' /usr/games/openclonk > /usr/games/openclonk1 2>/dev/null
  5189.     mv /usr/games/openclonk1 /usr/games/openclonk
  5190.     chmod 755 /usr/games/openclonk
  5191.    ;;
  5192.    vlc_*|vlc-*)
  5193.     VLCDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname 'vlc*.desktop'`"
  5194.     [ -f $VLCDESKTOP ] && sed -i 's/ --started-from-file %U//' $VLCDESKTOP
  5195.     [ -f $VLCDESKTOP ] && sed -i 's/ --started-from-file//' $VLCDESKTOP
  5196.  
  5197.     #120907 vlc in debian/ubuntu configured to not run as root (it is a pre-compile configure option to enable running as root).
  5198.     #this hack will fix it...
  5199.     #note, this code is also in FIXUPHACK in 'vlc' template.
  5200.     if [ -f /usr/bin/bbe ];then #bbe is a sed-like utility for binary files.
  5201.      if [ -f /usr/bin/vlc  ];then
  5202.        bbe -e 's/geteuid/getppid/' /usr/bin/vlc > /tmp/vlc-temp1
  5203.        mv -f /tmp/vlc-temp1 /usr/bin/vlc
  5204.        chmod 755 /usr/bin/vlc
  5205.      fi
  5206.     fi
  5207.    ;;
  5208.    google-chrome-*) #130221 pemasu. 130224 pemasu: limit cache size...
  5209.     if [ -f /usr/bin/bbe ];then #bbe is a sed-like utility for binary files.
  5210.      if [ -f /opt/google/chrome/chrome  ];then
  5211.     bbe -e 's/geteuid/getppid/' /opt/google/chrome/chrome > /tmp/chrome-temp1
  5212.     mv -f /tmp/chrome-temp1 /opt/google/chrome/chrome
  5213.     chmod 755 /opt/google/chrome/chrome
  5214.     [ -e /usr/bin/google-chrome ] && rm -f /usr/bin/google-chrome
  5215.     echo '#!/bin/sh
  5216.  exec /opt/google/chrome/google-chrome --user-data-dir=/root/.config/chrome --disk-cache-size=10000000 --media-cache-size=10000000 "$@"' > /usr/bin/google-chrome
  5217.     chmod 755 /usr/bin/google-chrome
  5218.     ln -s google-chrome /usr/bin/chrome
  5219.     ln -s /opt/google/chrome/product_logo_48.png /usr/share/pixmaps/google-chrome.png
  5220.     ln -s /opt/google/chrome/product_logo_48.png /usr/share/pixmaps/chrome.png
  5221.     CHROMEDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname '*chrome*.desktop'`"
  5222.     if [ "$CHROMEDESKTOP" = "" ];then #precaution.
  5223.      echo '[Desktop Entry]
  5224. Encoding=UTF-8
  5225. Version=1.0
  5226. Name=Google Chrome web browser
  5227. GenericName=Google Chrome
  5228. Comment=Google Chrome web browser
  5229. Exec=google-chrome
  5230. Terminal=false
  5231. Type=Application
  5232. Icon=google-chrome.png
  5233. Categories=WebBrowser;' > /usr/share/applications/google-chrome.desktop
  5234.     fi
  5235.      fi
  5236.     fi
  5237.    ;;
  5238.   chromium*) #130221 pemasu. 130224 pemasu: limit cache size...
  5239.     if [ -f /usr/bin/bbe ];then #bbe is a sed-like utility for binary files.
  5240.      if [ -f /usr/lib/chromium/chromium  ];then
  5241.     bbe -e 's/geteuid/getppid/' /usr/lib/chromium/chromium > /tmp/chrome-temp1
  5242.     mv -f /tmp/chrome-temp1 /usr/lib/chromium/chromium
  5243.     chmod 755 /usr/lib/chromium/chromium
  5244.     [ -e /usr/bin/chromium ] && rm -f /usr/bin/chromium
  5245.     echo '#!/bin/sh
  5246.  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
  5247.     chmod 755 /usr/bin/chromium
  5248.     ln -s /usr/share/icons/hicolor/48x48/apps/chromium.png /usr/share/pixmaps/chromium.png
  5249.     CHROMEDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname '*chromium-br*.desktop'`"
  5250.     if [ "$CHROMEDESKTOP" = "" ];then #precaution.
  5251.      echo '[Desktop Entry]
  5252. Encoding=UTF-8
  5253. Version=1.0
  5254. Name=Chromium web browser
  5255. GenericName=Chromium
  5256. Comment=Chromium web browser
  5257. Exec=chromium
  5258. Terminal=false
  5259. Type=Application
  5260. Icon=chromium.png
  5261. Categories=WebBrowser;' > /usr/share/applications/chromium.desktop
  5262.     fi
  5263.      fi
  5264.     fi
  5265.    ;;
  5266.    jwm_theme_*)
  5267.     #120924 DejaVu font no good for non-Latin languages...
  5268.     #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5269.     LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5270.     case $LANGUSER in
  5271.      zh*|ja*|ko*) #chinese, japanese, korean
  5272.     sed -i -e 's%DejaVu Sans%Sans%' /etc/xdg/templates/_root_*
  5273.     sed -i -e 's%DejaVu Sans%Sans%' /root/.jwm/themes/*-jwmrc
  5274.     sed -i -e 's%DejaVu Sans%Sans%' /root/.jwm/jwmrc-theme
  5275.      ;;
  5276.     esac
  5277.     #130326 font size fix for 96 dpi...
  5278.     if [ "$PKGNAME_ONLY" ];then
  5279.      JWMTHEMEFILE="$(grep '^/root/\.jwm/themes/.*-jwmrc$' "$PACKAGE_FILE_LIST_DIR/${PKGNAME_ONLY}.files" | head -n 1)"
  5280.      [ "$JWMTHEMEFILE" ] && hackfontsize "JWMTHEMES='${JWMTHEMEFILE}'"
  5281.     fi
  5282.    ;;
  5283.    openbox*)
  5284.     #120924 DejaVu font no good for non-Latin languages...
  5285.     #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5286.     LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5287.     case $LANGUSER in
  5288.      zh*|ja*|ko*) #chinese, japanese, korean
  5289.     sed -i -e 's%DejaVu Sans%Sans%' /etc/xdg/openbox/*.xml
  5290.     sed -i -e 's%DejaVu Sans%Sans%' /root/.config/openbox/*.xml
  5291.      ;;
  5292.     esac
  5293.    ;;
  5294.    gtk_theme_*)
  5295.     #120924 DejaVu font no good for non-Latin languages...
  5296.     #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5297.     LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5298.     case $LANGUSER in
  5299.      zh*|ja*|ko*) #chinese, japanese, korean
  5300.     GTKRCFILE="$(find /usr/share/themes -type f -name gtkrc | tr '\n' ' ')"
  5301.     for ONEGTKRC in $GTKRCFILE
  5302.     do
  5303.      sed -i -e 's%DejaVu Sans%Sans%' $ONEGTKRC
  5304.     done
  5305.      ;;
  5306.     esac
  5307.     #130326 font size fix for 96 dpi...
  5308.     if [ "$PKGNAME_ONLY" ];then
  5309.      GTKTHEMEFILE="$(grep '^/usr/share/themes/.*/gtk-2\.0/gtkrc$' "$PACKAGE_FILE_LIST_DIR/${PKGNAME_ONLY}.files" | head -n 1)"
  5310.      [ "$GTKTHEMEFILE" ] && hackfontsize "GTKRCS='${GTKTHEMEFILE}'"
  5311.     fi
  5312.    ;;
  5313.    seamonkey*|firefox*)
  5314.     #120924 DejaVu font no good for non-Latin languages...
  5315.     #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5316.     LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5317.     case $LANGUSER in
  5318.      zh*|ja*|ko*) #chinese, japanese, korean
  5319.     MOZFILE="$(find /root/.mozilla -type f -name prefs.js -o -name '*.css' | tr '\n' ' ')"
  5320.     for ONEMOZ in $MOZFILE
  5321.     do
  5322.      sed -i -e 's%DejaVu Sans%Sans%' $ONEMOZ
  5323.     done
  5324.      ;;
  5325.     esac
  5326.    ;;
  5327.    mc_*) #121206 midnight commander
  5328.     #in ubuntu, won't run from the menu. this fixes it...
  5329.     [ -f /usr/share/applications/mc.desktop ] && sed -i -e 's%^Exec=.*%Exec=TERM=xterm mc%' /usr/share/applications/mc.desktop
  5330.    ;;
  5331.    xsane*) #130122
  5332.     #xsane puts up a warning msg at startup if running as root, remove it...
  5333.     #this code is also in file FIXUPHACK in xsane template (in Woof).
  5334.     #WARNING: this may only work for x86 binary.
  5335.     if [ -f /usr/bin/bbe ];then #bbe is a sed-like utility for binary files.
  5336.      if [ -f /usr/bin/xsane  ];then
  5337.     bbe -e 's/\x6b\x00getuid/\x6b\x00getpid/' /usr/bin/xsane > /tmp/xsane-temp1
  5338.     mv -f /tmp/xsane-temp1 /usr/bin/xsane
  5339.     chmod 755 /usr/bin/xsane
  5340.      fi
  5341.     fi
  5342.    ;;
  5343.    kompozer*) #130507
  5344.     [ -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
  5345.    ;;
  5346.   esac
  5347. }
  5348.  
  5349.  
  5350. choose_pkg(){                     # given partial name ($1), choose from a list of matching packages FUNCLIST
  5351.  
  5352.  
  5353.   # exit if no valid options
  5354.   [ ! "$1" -o "$1" = "" -o "$1" = "-" ] && print_usage get && exit 1
  5355.  
  5356.   # get $REPONAME and $EX
  5357.   . ${PKGRC}
  5358.  
  5359.   local REPOEX    # extension of pkgs in the current repo $REPONAME (from rc file)
  5360.   local PKGEX     # pkg extension we get from $1, defaults to $REPOEXT is empty
  5361.   local PKGNAME   # the name of the pkg, we get this from $1
  5362.   local PKGNAME_ONLY  # the pkg name without version, we get this from PKGNAME
  5363.   local PKGS      # the list of PKGS returned matching $1/$PKGNAME
  5364.   local INT=1     # used to provide numbered lists
  5365.  
  5366.   REPOEX=$EX
  5367.   # get pkg extension
  5368.   PKGEX=`get_pkg_ext "$1"`
  5369.  
  5370.   # if no extension, set to extension of current repo
  5371.   [ "$PKGEX" = '' ] && PKGEX=$REPOEX
  5372.  
  5373.   # get pkg name with version, no extension or path
  5374.   PKGNAME="$(basename "$1" .$PKGEX)"
  5375.  
  5376.   # get the full pkg name, to compare against repo pkgs we find
  5377.   PKGNAME_FULL="`get_pkg_name "$PKGNAME"`"
  5378.  
  5379.   # get pkg name only .. without version or suffix
  5380.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5381.  
  5382.   # remove any previous user choice lists
  5383.   rm $TMPDIR/PKGLIST &>/dev/null
  5384.   rm $TMPDIR/USRPKGLIST &>/dev/null
  5385.  
  5386.   # get all pkgs that match the given pkgname
  5387.   # returns full pkg names (field1 of repo, pkgname with ver but no extension) each on a new line
  5388.   PKGS="`$PKGSEARCH "${PKGNAME}"`"
  5389.  
  5390.   if [ "$FORCE" = false -a "`is_installed_pkg "$PKGNAME_FULL"`" = true -a "$HIDE_INSTALLED" = true ];then
  5391.     # remove it from choices
  5392.     PKGS="`echo "$PKGS" | grep -v ^$PKGNAME_FULL\$`"
  5393.   fi
  5394.  
  5395.   # extra steps for ubuntu and debian repos, if multiple choices returned.. remove non-compatible archs, remove dev and dbg pkgs...
  5396.   if [ "$PKGEX" = "deb" -a "`echo "$PKGS" | wc -l`" != "1" ];then
  5397.  
  5398.     ARCH="`uname -m`"
  5399.     #remove x64 pkgs from choices if not using an x64 cpu
  5400.     [ "$ARCH" != "x86_64" ] && PKG="`echo "$PKGS" | grep -v -E 'amd64|x86_64'`"
  5401.  
  5402.     # set any pkgs matching current arch to top of list
  5403.     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
  5404.     do
  5405.       # if not searching for -dev or -dgb pkg, move it to bottom of the list
  5406.       if [ "`is_blacklisted_pkg "$LINE"`" = false -a "`echo "$PKGNAME" | grep -E "\-dbg_|\-dev_"`" = "" -a "`echo "$LINE" | grep -E "\-dbg_|\-dev_"`" != "" ];then
  5407.         PKGS="`echo "$PKGS" | grep -v  "$LINE"`"
  5408.         PKGS="$PKGS
  5409. $LINE"
  5410.       fi
  5411.       # if pkg is for current cpu arch, move it to top of the list
  5412.       if [ "`echo "$LINE" | grep -m1 "$ARCH"`" != "" ];then
  5413.         PKGS="`echo "$PKGS" | grep -v  "$LINE"`"
  5414.         PKGS="$LINE
  5415. $PKGS"
  5416.       fi
  5417.     done
  5418.     #remove debug and dev pkgs
  5419.     #PKGS="`echo "$PKGS" | grep -v "\-dbg_"`"
  5420.     #PKGS="`echo "$PKGS" | grep -v "\-dev_"`"
  5421.   fi
  5422.  
  5423.   # get the user to choose which packages they want to install
  5424.   if [ "$ASK" = true -a "$PKGS" != "" ];then
  5425.     echo "Please choose the package number. For the first package,"
  5426.     echo "enter '1', without quotes. To install multiple packages,"
  5427.     echo "enter the numbers, separated by a comma. Example:  1,3,4"
  5428.     echo
  5429.   fi
  5430.  
  5431.   # if using ubuntu/debian packages, put pkg_* before pkg-* .. else dont
  5432.   [ "$PKGEX" = 'deb' ] && sort='sort -r' || sort='sort'
  5433.  
  5434.   # go through each actual pkg that matches the pkgname search, make it a numbered list
  5435.   echo "$PKGS" | $sort -u | while read LINE
  5436.   do
  5437.     if [ "$LINE" != "" -a "$LINE" != "," -a "$LINE" != " " ];then
  5438.       [ "$ASK" = true ] && echo "${INT}. $LINE"
  5439.       echo "${INT}. $LINE" >> $TMPDIR/PKGLIST
  5440.       INT=$(($INT + 1))
  5441.     fi
  5442.   done
  5443.  
  5444.   # if pkg list was made
  5445.   if [ -f $TMPDIR/PKGLIST -a "`cat $TMPDIR/PKGLIST 2>/dev/null`" != "" ];then
  5446.  
  5447.     # set to first pkg only as default
  5448.     if [ "$ASK" = false ];then
  5449.       USRPKGLIST="$(echo "$PKGS" | $sort | head -1)"
  5450.       echo "$USRPKGLIST" > $TMPDIR/USRPKGLIST
  5451.     fi
  5452.  
  5453.     # user can now input which actual pkgs to get, chosen by number
  5454.     if [ "$ASK" = true ];then
  5455.       # only ask once
  5456.       ASK=false
  5457.  
  5458.       echo
  5459.       echo "Give the numbers of the packages you want to install,"
  5460.       echo -n "separated by a comma, or hit ENTER only to skip: "
  5461.       read USRPKGLIST1 </dev/tty
  5462.  
  5463.       # if user chose nothing (hit ENTER only), just skip
  5464.       [ "$USRPKGLIST1" = '' ] && continue
  5465.  
  5466.       # split the results into newlines, create the list of chosen pkgs (used by other funcs)
  5467.       echo "${USRPKGLIST1}" | tr ',' '\n' | while read LINE
  5468.       do
  5469.         # set chosen pkg choice(s)
  5470.         echo "`grep "^$LINE. " "$TMPDIR/PKGLIST" 2>/dev/null | cut -f2 -d' '`" >> $TMPDIR/USRPKGLIST
  5471.       done
  5472.     fi
  5473.  
  5474.     # remove temp file.. but keep $TMPDIR/USRPKGLIST, it contains our users choices, and is used by pkg_get() and get_deps()
  5475.     rm $TMPDIR/PKGLIST &>/dev/null
  5476.   fi
  5477. }
  5478.  
  5479.  
  5480. pkg_get(){                        # find, download and install $1 and its deps FUNCLIST
  5481.  
  5482.   # The function `choose_pkg` is run just before this one. It gives us $TMPDIR/USRPKGLIST,
  5483.   # which contains a list of packages the user wants to install or download.
  5484.   # In this func, we will go through the list and download/install the package, as well
  5485.   # as its dependencies (depending on what the user chose to do).
  5486.  
  5487.   . ${PKGRC}
  5488.  
  5489.   # exit if no valid options
  5490.   [ ! "$1" -o "$1" = "" -o "$1" = "-" ] && print_usage get && exit 1
  5491.  
  5492.   local PREVDIR="$CURDIR"
  5493.   local pkg_ext=`get_pkg_ext "$1"`; pkg_ext="${pkg_ext:-$EX}" # fall back to repo extension
  5494.   local PKGNAME="`get_pkg_name $(basename "$1" .$pkg_ext)`"
  5495.   local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5496.   local PKGLIST="${PKGNAME}"
  5497.   local pkg_builtin=''
  5498.  
  5499.   # dont ask to download or install pkg or deps, as choose_pkg() already asked
  5500.   ASK=false
  5501.  
  5502.   # exit if no valid pkg name
  5503.   [ ! "$PKGNAME" -o "$PKGNAME" = "" -o "$PKGNAME" = "-" ] && print_usage get && exit 1
  5504.  
  5505.   # we want to download all pkgs to same place
  5506.   cd "$WORKDIR"
  5507.   CURDIR="$WORKDIR"
  5508.  
  5509.   # use the list of pkgs user has chosen to install, or the given PKGNAME
  5510.   if [ "`cat "$TMPDIR/USRPKGLIST" 2>/dev/null`" != "" ];then
  5511.     PKGLIST="`cat "$TMPDIR/USRPKGLIST" | grep -v "^\$"`"
  5512.   fi
  5513.  
  5514.   if [ -z "$PKGLIST" ];then
  5515.     echo "No packages to get, exiting."
  5516.     exit 1
  5517.   fi
  5518.  
  5519.   # skip if any pkgs previously installed during our current loop (of getting 'pkg + recursive deps')
  5520.   echo "$PKGLIST" | while read pkg_in_list
  5521.   do
  5522.     name_only=`get_pkg_name_only "$pkg_in_list"`
  5523.     [ -f $TMPDIR/PKGSDONE -a "`grep "^${name_only}\$" $TMPDIR/PKGSDONE 2>/dev/null`" != '' ] && continue
  5524.   done
  5525.  
  5526.   # list the pkgs and ask to download (and maybe install)
  5527.   echo "$PKGLIST" | while read pkg
  5528.   do
  5529.  
  5530.     [ "$pkg" = '' -o ! "$pkg" ] && continue
  5531.  
  5532.     local pkg_name=`get_pkg_name "$pkg" 2>/dev/null`
  5533.     [ "$pkg_name" = '' -o ! "$pkg_name" ] && continue
  5534.  
  5535.     local pkg_name_only=`get_pkg_name_only "$pkg" 2>/dev/null`
  5536.     [ "`is_blacklisted_pkg "$pkg_name_only"`" = true ] && continue
  5537.  
  5538.     local pkg_already_done=`grep -m1 "^$pkg_name_only\$" $TMPDIR/PKGSDONE 2>/dev/null`
  5539.     [ "$pkg_already_done" != '' ] && continue
  5540.  
  5541.     local pkg_in_repo=`is_repo_pkg $pkg_name_only`
  5542.     local PKGFILE=''
  5543.  
  5544.     # dont even try to download if no matches found
  5545.     if [ "$pkg_in_repo" = true -a "$pkg_name_only" != "" ];then
  5546.  
  5547.       local pkg_is_builtin=`is_builtin_pkg "$pkg_name_only"`
  5548.       local pkg_is_in_devx=`is_devx_pkg "$pkg_name_only"`
  5549.  
  5550.       # skip getting pkg if its a builtin, unless HIDE_BUILTINS=false
  5551.       if [ "$pkg_is_builtin" = true -a "${HIDE_BUILTINS}" = true ];then
  5552.         echo "Skipping $pkg_name_only (already built-in).."
  5553.         continue
  5554.       fi
  5555.  
  5556.       # skip getting pkg if its in the devx, unless HIDE_BUILTINS=false
  5557.       if [ "$pkg_is_in_devx" = true -a "${HIDE_BUILTINS}" = true ];then
  5558.         echo "Skipping $pkg_name_only (already in devx).."
  5559.         continue
  5560.       fi
  5561.  
  5562.       # if we are intending to install the pkg
  5563.       if [ "$NO_INSTALL" = false -a "$FORCE" = false ];then
  5564.         # skip if package is already installed, unless --force given
  5565.         if [ "$FORCE" = false -a "`is_installed_pkg $pkg_name`" = true ];then
  5566.           echo -e "Package ${magenta}${pkg_name_only}${endcolour} already installed."
  5567.           echo -e "Use the -f option to force installation: $SELF add $pkg_name_only -f"
  5568.           continue
  5569.         fi
  5570.       fi
  5571.  
  5572.       # get deps early (if any)
  5573.       list_deps "$pkg_name" > ${TMPDIR}/${pkg_name}_dep_list &
  5574.  
  5575.       # DOWNLOAD PKG
  5576.       pkg_download "$pkg_name"
  5577.  
  5578.       [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}.*${pkg_ext}"`"
  5579.       # try grabbing $CURDIR/pkgname.pkg_ext
  5580.       [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}*.${pkg_ext}"`"
  5581.       # now try grabbing $CURDIR/pkgname.*
  5582.       [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}.*"`"
  5583.       # maybe try $CURDIR/pkgname-*.*
  5584.       [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}-*.*"`"
  5585.       # maybe try $CURDIR/pkgname_*.*
  5586.       [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}_*.*"`"
  5587.       # maybe try $CURDIR/pkgname*.*
  5588.       [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}*.*"`"
  5589.  
  5590.       # add extension if Pkg returned an erroneous or user dir
  5591.       [ -d "$PKGFILE" ] && PKGFILE="${PKGFILE}.$pkg_ext"
  5592.  
  5593.       # if we found the package to install in CURDIR
  5594.       if [ -f "${PKGFILE}" ];then
  5595.  
  5596.         # check if we install or not
  5597.         if [ "${NO_INSTALL}" = false ];then
  5598.  
  5599.           # if a valid pkg, with files to extract
  5600.           if [ "`pkg_contents "$PKGFILE" 2>/dev/null`" != '' ];then
  5601.  
  5602.  
  5603.             #INSTALL PKG
  5604.             [ "`is_local_pkg "$PKGFILE"`" = true ] && pkg_install "${PKGFILE}"
  5605.  
  5606.  
  5607.           fi
  5608.  
  5609.         fi
  5610.  
  5611.         # if pkg was installed, or Pkg is simply downloading all deps
  5612.         if [ "`is_installed_pkg "$pkg_name_only"`" = true -o "${NO_INSTALL}" = true ];then
  5613.  
  5614.           # get the dependencies for this package
  5615.           get_deps "${pkg_name}"
  5616.  
  5617.         fi
  5618.  
  5619.       else # PKGFILE not a file
  5620.         echo "Can't find ${PKGNAME} or not a valid pkg.."
  5621.       fi
  5622.  
  5623.     else # no matches in repo found
  5624.       echo "Cannot find ${PKGNAME}.."
  5625.     fi
  5626.  
  5627.     # done with this pkg, add it to done list, will be skipped it seen again, until loop is finished
  5628.     echo "$pkg_name_only" >> $TMPDIR/PKGSDONE
  5629.   done
  5630. }
  5631.  
  5632.  
  5633. pkg_update(){                     # update installed pkgs, $1 is optional filter FUNCLIST
  5634.  
  5635.   # exit if no valid options
  5636.   #[ ! "$1" -o "$1" = "-" ] && print_usage pkg-update && exit 1
  5637.  
  5638.   # get rc file settings
  5639.   . ${PKGRC}
  5640.  
  5641.   local PKGNAME=''
  5642.   local PKGLIST=''
  5643.   local pkg_ext=$EX
  5644.   local BUILTINS=''
  5645.   local separator=''
  5646.  
  5647.   if [ "$1" != '' ];then
  5648.  
  5649.     PKGNAME=$(basename "$1")
  5650.     PKGNAME=`get_pkg_name "$PKGNAME"`
  5651.     PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5652.  
  5653.     # get installed packages
  5654.     PKGLIST="`HIDE_BUILTINS=false list_installed_pkgs "$PKGNAME_ONLY"`"
  5655.  
  5656.     #is_builtin=`is_builtin_pkg "$PKGNAME"`
  5657.  
  5658.     # dont update builtins unless -F was given
  5659.     #if [ "$is_builtin" = true -a "$HIDE_BUILTINS" = true ];then
  5660.     #  echo -e "Package ${magenta}${PKGNAME}${endcolour} is built in, not updating."
  5661.     #  #echo -e "Use `$SELF -F --pkg-update $PKGNAME` to update it anyway."
  5662.     #  exit 0
  5663.     #fi
  5664.   else
  5665.     # get installed packages
  5666.     PKGLIST="`HIDE_BUILTINS=false list_installed_pkgs`"
  5667.   fi
  5668.  
  5669.   # iterate over the list
  5670.   echo "$PKGLIST"  | grep -v ^$ | sort -u | while read installed_pkg; do
  5671.  
  5672.     [ ! "$installed_pkg" -o "$installed_pkg" = '' ] && continue
  5673.  
  5674.     # if this pkg ($installed_pkg) is not from a known repo, we cant compare its version to anything else, skip it
  5675.     #[ "`is_repo_pkg "$installed_pkg"`" = false ] && echo -e "Package ${magenta}$installed_pkg${endcolour} not found in any repos." && continue
  5676.  
  5677.     local PNAME=''
  5678.     local latest_repo_pkg=''
  5679.     local ASKREPLY='y'
  5680.     # get pkg name (without version) and version of current PKG
  5681.  
  5682.     PNAME=`get_pkg_name_only $installed_pkg`
  5683.  
  5684.     [ "$PNAME" = '' ] && continue
  5685.  
  5686.     case $DISTRO_BINARY_COMPAT in
  5687.       ubuntu|trisquel|debian|devuan)
  5688.         separator='_'
  5689.         ;;
  5690.       *)
  5691.         separator='-'
  5692.         ;;
  5693.     esac
  5694.  
  5695.     latest_repo_pkg="`grep -m1 "^${PNAME}${separator}" "${ALL_REPO_DB_PATHS[@]}" |cut -f1 -d'|' | head -1 | cut -f2 -d':'`"
  5696.  
  5697.     # skip if we didn't find the right package
  5698.     [ "`echo "$latest_repo_pkg" | grep "^${PNAME}${separator}"`" = '' ] && continue
  5699.  
  5700.     latest_version=`get_pkg_version "$latest_repo_pkg"`
  5701.     installed_version=`get_pkg_version "$installed_pkg"`
  5702.  
  5703.     # get latest versions
  5704.  
  5705.     # check pkg version against installed version
  5706.     if [ "$latest_version" != "" -a "$installed_version" != "" ];then
  5707.       vercmp $latest_version gt $installed_version 2>/dev/null
  5708.       RESULT=$?
  5709.  
  5710.       if [ "$RESULT" = 0 ];then #newer version available
  5711.  
  5712.         if [ "$ASK" = true ];then
  5713.           echo "Do you want to update to ${PNAME}${separator}${latest_version}? [y/N]   "
  5714.           read -n 1 ASKREPLY </dev/tty
  5715.           [ "$ASK" = true ] && echo -ne "\b\b\n"
  5716.         fi
  5717.  
  5718.         if [ "$ASK" = false -o "$ASKREPLY" = "y" ];then
  5719.           echo -e "${yellow}Update${endcolour}: ${magenta}$PNAME${endcolour} from ${bold}$installed_version${endcolour} to ${bold}$latest_version${endcolour}"
  5720.           cd "$WORKDIR"
  5721.           ASK=$ASK FORCE=$FORCE pkg_get "$latest_repo_pkg"
  5722.           cd "$CURDIR"
  5723.         fi
  5724.  
  5725.       else #280613 inform user if no update found
  5726.         echo -e "${green}Latest${endcolour}: $PNAME${separator}$installed_version"
  5727.       fi #end if vercmp XX gt YY = 0
  5728.  
  5729.     elif [ "$PNAME" = '' ];then
  5730.       error "${installed_pkg} not found."
  5731.     else #280613
  5732.       error "$installed_pkg package versions could not be compared: ${latest_version:-unknown latest} => ${installed_version:-unknown installed version}"
  5733.       #return 1
  5734.     fi #end if PKGVER != ""
  5735.   done
  5736. }
  5737.  
  5738.  
  5739. pkg_uninstall(){                  # remove an installed package ($1) FUNCLIST
  5740.  
  5741.   # quit if no valid options
  5742.   [ ! "$1" -o "$1" = "-" ] && print_usage uninstall && exit 1
  5743.  
  5744.   local PKGNAME
  5745.   local PKGNAME_ONLY
  5746.   local PKGFILE
  5747.   local pkg_ext
  5748.  
  5749.   # get pkg extension
  5750.   pkg_ext=`get_pkg_ext "$1"`
  5751.  
  5752.   #get pkg name with version, but no extension or path
  5753.   PKGNAME="$(basename "$1" .$pkg_ext)"
  5754.   PKGNAME="$(basename "$PKGNAME" .pet)"
  5755.   PKGNAME="$(basename "$PKGNAME" .deb)"
  5756.   PKGNAME="$(basename "$PKGNAME" .sfs)"
  5757.   PKGNAME="$(basename "$PKGNAME" .tar.gz)"
  5758.   PKGNAME="$(basename "$PKGNAME" .tar.xz)"
  5759.   PKGNAME="$(basename "$PKGNAME" .tgz)"
  5760.   PKGNAME="$(basename "$PKGNAME" .txz)"
  5761.   PKGNAME=`get_pkg_name "$PKGNAME"`
  5762.  
  5763.   # get pkg name only .. without versions or suffix
  5764.   PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  5765.  
  5766.   local pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY"`
  5767.   local is_installed=`is_installed_pkg "$PKGNAME"`
  5768.  
  5769.   # skip pkg if its a builtin
  5770.   [ "$pkg_is_builtin" = true ] && return 1
  5771.  
  5772.   local pkg_is_sfs_file="`sfs_loadr -q -i | grep -v ^sfs_loadr | grep ^$PKGNAME`"
  5773.  
  5774.   # if pkg is SFS, "uninstall" it here
  5775.   if [ "$pkg_is_sfs_file" != "" -o "$pkg_ext" = "sfs" ];then
  5776.     PKGNAME="$(sfs_loadr -q -i | grep -v ^sfs_loadr | grep ^$PKGNAME | head -1)"
  5777.     sfs_loadr -q --cli -"${CURDIR}/${PKGNAME}" 2>/dev/null
  5778.     is_installed=true # we want to continue
  5779.   fi
  5780.  
  5781.  
  5782.   if [ "$is_installed" = true -o "$FORCE" = true ];then #250713
  5783.  
  5784.     # get the list of files to be deleted, exact match
  5785.     PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "$PKGNAME.files")"
  5786.  
  5787.     # if no exact match, search for pkgname*
  5788.     [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}"'*.files')"
  5789.     [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}_"'*.files')"
  5790.     [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}-"'*.files')"
  5791.     [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}.files"
  5792.     [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}.sfs.files"
  5793.     [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}-${CP_SUFFIX}.sfs.files"
  5794.  
  5795.     #if PKG.files not found, then remove it from alien packages list
  5796.     if [ ! -f "$PKGFILE" ];then
  5797.  
  5798.       #error "'${PKGFILE}' not found.. Cleaning up.."
  5799.  
  5800.       # backup the original list of user installed pkgs
  5801.       cp "$USER_INST_PKGS_FILE" $TMPDIR/user-installed-packages.backup
  5802.  
  5803.       # remove $PKGNAME from list of installed pkgs
  5804.       cat "$USER_INST_PKGS_FILE" 2>/dev/null | grep -v "^${PKGNAME}" > "$PKGS_DIR/user-installed-packages.updated"
  5805.  
  5806.       # if we created a new file ok
  5807.       if [ -f "$PKGS_DIR/user-installed-packages.updated" ];then
  5808.         # replace the user-installed-packages file with our new one
  5809.         mv "$PKGS_DIR/user-installed-packages.updated" "$USER_INST_PKGS_FILE" 2>/dev/null
  5810.       fi
  5811.  
  5812.       # clean up user-installed-packages (remove duplicates and empty lines)
  5813.       cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages.clean"
  5814.       mv "$PKGS_DIR/user-installed-packages.clean" "$USER_INST_PKGS_FILE"
  5815.  
  5816.       # no *.files to process, so if not forcing full uninstall, we can exit here
  5817.       [ "$FORCE" = false ] && return 1
  5818.     fi
  5819.  
  5820.     # if we are here, we have a $PKGS_DIR/***.files to work with (or using --force)
  5821.  
  5822.     # get pkgs that depend on $PKGNAME
  5823.     [ "$FORCE" = false ] && dependents="`list_dependents "$PKGNAME"`" || dependents=''
  5824.  
  5825.     # if we have dependents, we should not uninstall and just exit, unless --force was given
  5826.     if [ "$dependents" != "" -a "`echo "$dependents" | grep 'not installed'`" = '' -a "$FORCE" != true ];then
  5827.  
  5828.       # inform user of dependent pkgs
  5829.       echo -e "${yellow}Warning${endcolour}: $PKGNAME_ONLY is needed by:  "
  5830.       echo -e "${magenta}$dependents${endcolour}"
  5831.       echo "Uninstall the packages above first, or use:"
  5832.       echo -e "${bold}pkg --force uninstall $PKGNAME${endcolour}."
  5833.       echo
  5834.       return 1
  5835.  
  5836.     fi
  5837.  
  5838.     # ask/inform user before uninstall
  5839.     echo -n "Uninstall the package ${PKGNAME}$QTAG:  "
  5840.     [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  5841.     [ "$ASK" = true ] && echo -ne "\b\b\n"
  5842.  
  5843.     # if user answered yes, we will now uninstall the pkgs
  5844.     if [ "$CONFIRM" = "y" ];then
  5845.  
  5846.       # print new line if we didnt take any user input on tty
  5847.       [ "$ASK" != true ] && echo
  5848.  
  5849.       # execute uninstall script.
  5850.       if [ -x "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" ];then
  5851.         "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" &>/dev/null
  5852.         rm -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" &>/dev/null
  5853.       fi
  5854.  
  5855.       # if we have no pkg file (listing of pkg contents), we cant cat/grep it
  5856.       if [ ! -f "$PKGFILE" ];then
  5857.         echo "Not found: $PKGS_DIR/$PKGNAME.files"
  5858.         return 1
  5859.       fi
  5860.  
  5861.       # check if has menu entry
  5862.       [ "`cat "$PKGFILE" | grep -m1 ".desktop\$"`" != "" ] && HASMENUENTRY=true || HASMENUENTRY=false
  5863.  
  5864.       # remove files listed in *.files
  5865.       cat "$PKGFILE" | while read LINE
  5866.       do
  5867.         # some symlinks may not get removed. '-e' will not work if symlink
  5868.         # is pointing to a non-existent file. So, check for symlink...
  5869.         REMFILE=""
  5870.         [ -h "$LINE" ] && REMFILE="yes"
  5871.         [ -e "$LINE" ] && REMFILE="yes"
  5872.         if [ "$REMFILE" = "yes" ];then
  5873.           if [ ! -d "$LINE" ];then
  5874.             if [ -e "/initrd/pup_ro2$LINE" ];then
  5875.               # deleting the file on the top layer places a ".wh" whiteout file, that hides the original file.
  5876.               # what we want is to remove the installed file, and restore the original pristine file...
  5877.               cp -af "/initrd/pup_ro2${LINE}" "$LINE"
  5878.             else
  5879.               rm -f "$LINE" &>/dev/null
  5880.             fi
  5881.             #delete empty dirs...
  5882.             DELDIR="`dirname "$LINE" 2>/dev/null`"
  5883.             [ "`ls -1 "$DELDIR"`" = "" ] && rmdir "$DELDIR" &>/dev/null
  5884.           fi
  5885.         fi
  5886.       done
  5887.  
  5888.       # go through again and remove any empty dirs...
  5889.       cat "$PKGFILE" 2>/dev/null  | while read LINE
  5890.       do
  5891.         DELDIR="`dirname "$LINE" 2>/dev/null`"
  5892.         [ -d "$DELDIR" ] && [ "`ls -1 "$DELDIR"`" = "" ] && rmdir "$DELDIR"
  5893.         #check one level up... but do not delete top dir, like /opt...
  5894.         DELLEVELS=`echo -n "$DELDIR" | sed -e 's/[^/]//g' | wc -c | sed -e 's/ //g'`
  5895.         if [ $DELLEVELS -gt 2 ];then
  5896.           DELDIR="`dirname "$DELDIR" 2>/dev/null`"
  5897.           [ -d "$DELDIR" ] && [ "`ls -1 "$DELDIR"`" = "" ] && rmdir $DELDIR
  5898.         fi
  5899.       done
  5900.  
  5901.       # remove $PKGNAME from user-installed-packages
  5902.       NEWUSERPKGS="$(grep -v "^${PKGNAME}" "$USER_INST_PKGS_FILE")"
  5903.       [ "$NEWUSERPKGS" != "" ] && echo "$NEWUSERPKGS" > "$USER_INST_PKGS_FILE"
  5904.  
  5905.       # clean up user-installed-packages (remove duplicates and empty lines)
  5906.       cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages_clean"
  5907.       mv "$PKGS_DIR/user-installed-packages_clean" "$USER_INST_PKGS_FILE"
  5908.  
  5909.       # remove $PKGS_DIR/$PKGNAME.files
  5910.       rm $PKGFILE ${PKGFILE} 2>/dev/null
  5911.  
  5912.       # do fixmenus, if menu entry found
  5913.       if [ "$HASMENUENTRY" = true ];then
  5914.         [ ! -f /tmp/pkg/update_menus_busy ] && update_menus &
  5915.       fi
  5916.  
  5917.       # UNINSTALL DONE .. print message
  5918.       echo -e "${green}Uninstalled:${endcolour} $PKGNAME"
  5919.  
  5920.       # log uninstall with the system logs
  5921.       [ "`which logger`" != '' ] && logger "$0 Package $PKGNAME uninstalled by $APP $APPVER"
  5922.  
  5923.     fi #end if $CONFIRM=yes
  5924.  
  5925.   else # $PKGNAME is not installed
  5926.  
  5927.     # if any installed pkg matches $PKGNAME
  5928.     if [ "`list_installed_pkgs $PKGNAME`" != "" ];then #290613
  5929.       # list the matching pkgs
  5930.       echo "These installed packages match '$PKGNAME':"
  5931.       echo "`list_installed_pkgs $PKGNAME`"
  5932.     fi
  5933.  
  5934.     return 1
  5935.  
  5936.   fi # endif installed or not
  5937. }
  5938.  
  5939.  
  5940. pkg_remove(){                     # remove pkg ($1) and its leftover deps FUNC_LIST
  5941.  
  5942.   # quit if no valid options
  5943.   [ ! "$1" -o "$1" = "-" ] && print_usage remove && exit 1
  5944.  
  5945.   local PKGNAME
  5946.   local PKGNAME_ONLY
  5947.   local PKGFILE
  5948.   local pkg_ext
  5949.  
  5950.   # get pkg extension
  5951.   pkg_ext=`get_pkg_ext "$1"`
  5952.  
  5953.   #get pkg name with version, but no extension or path
  5954.   PKGNAME="$(basename "$1" .$pkg_ext)"
  5955.   PKGNAME=`get_pkg_name "$PKGNAME"`
  5956.  
  5957.   # get pkg name only .. without versions or suffix
  5958.   PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  5959.  
  5960.   if [ "`is_installed_pkg "$PKGNAME"`" = false ];then
  5961.     echo "Package '$1' not installed."
  5962.     return 1
  5963.   fi
  5964.  
  5965.   pkg_uninstall "$PKGNAME"
  5966.  
  5967.   # now we will remove any left over dependencies
  5968.  
  5969.   file="`find $TMPDIR -iname "${1}*_dep_list"`"
  5970.  
  5971.   if [ -f "$file" ];then
  5972.  
  5973.     # if we have a deps list file, go over it three times, uninstalling all deps
  5974.     # that have no packages that depend on them ... fugly solution, but works ok..
  5975.  
  5976.     for x in 1 2 3 4
  5977.     do
  5978.       cat "$file" | tr ' ' '\n' | while read user_installed_dep
  5979.       do
  5980.         [ "$user_installed_dep" = '' ] && continue
  5981.         ASK=false pkg_uninstall $user_installed_dep &>/dev/null && \
  5982.           echo -e "${green}Uninstalled:${endcolour} $(get_pkg_name $user_installed_dep)"
  5983.       done
  5984.     done
  5985.  
  5986.   fi
  5987.  
  5988.   return 0
  5989. }
  5990.  
  5991.  
  5992. clean_pkgs(){                     # delete downloaded pkg files of installed pkgs FUNCLIST
  5993.   local pkg_to_rm
  5994.   [ "$ASK" = true ] && ASKOPT='--ask'
  5995.   # list all (matching) installed pkgs
  5996.   list_installed_pkgs | while read line;
  5997.   do
  5998.     # get all pkgs except the combined (user-created) pkgs
  5999.     pkg_to_rm="`list_downloaded_pkgs $line | grep -v $CP_SUFFIX`"
  6000.     # if it has a downloaded pkg in $WORKDIR, (offer to) delete it
  6001.     [ "$pkg_to_rm" != '' ] && rm -v "${WORKDIR}/$pkg_to_rm";
  6002.   done
  6003. }
  6004.  
  6005.  
  6006. # dependency funcs
  6007.  
  6008. get_deps_entry(){                 # $1 is PKGNAME, returns dep entry from repo db
  6009.   [ "$1" = '' -o "$1" = "-" ] && print_usage list-deps && exit 1
  6010.  
  6011.   # get current $REPOFILE, $DEPSEARCH
  6012.   #. ${PKGRC}
  6013.  
  6014.   local PKGNAME="$1"
  6015.   local pkg_ext=''
  6016.   local repo_files=''
  6017.   local deps_list=''
  6018.   local deps=''
  6019.   local repo_of_pkg=''
  6020.   local repo_file_of_pkg=''
  6021.  
  6022.   # get pkg extension
  6023.   pkg_ext=`get_pkg_ext "$1"`
  6024.  
  6025.  
  6026.   # get repo file to search from RC file
  6027.   repo_file_of_pkg="$REPOFILE"
  6028.  
  6029.   # if searching dependencies in all repos
  6030.   if [ "$DEPSEARCH" = "list_all_pkg_names" ];then
  6031.  
  6032.     # get the repo that $PKGNAME lives in
  6033.     repo_of_pkg=`which_repo "$PKGNAME" | cut -f2 -d' ' | head -1`
  6034.     # then get the repo file for that repo.. that is where this pkg lists its deps
  6035.     repo_file_of_pkg=`grep -m1 ^"$repo_of_pkg" ~/.pkg/sources-all | cut -f3 -d'|'`
  6036.  
  6037.   fi
  6038.  
  6039.   # add the full path to the repo file
  6040.   repo_file_of_pkg="$REPO_DB_FILE_DIR/$repo_file_of_pkg"
  6041.  
  6042.   # search for deps entry in repo file.. look for |pkgname.ext|
  6043.   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'`"
  6044.  
  6045.   # try again if needed.. look for ^pkgname|
  6046.   [ "$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'`"
  6047.  
  6048.   # try again if needed.. look for |pkgname|
  6049.   [ "$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'`"
  6050.  
  6051.   # try again, look for dep-*
  6052.   [ "$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'`"
  6053.  
  6054.   # try again if needed.. with underscore.. dep_*
  6055.   [ "$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'`"
  6056.  
  6057.   # if no deps, exit with error
  6058.   [ "$deps_list" != "" ] && echo "$deps_list"
  6059. }
  6060.  
  6061.  
  6062. list_all_installed_pkgs(){        # list inc builtins if HIDE_BUILTINS=false
  6063.   # reset list of installed pkgs
  6064.   echo -n '' > $TMPDIR/installed_pkgs
  6065.  
  6066.   if [ "${HIDE_INSTALLED}" = true -a "$FORCE" = false ];then
  6067.     # add user installed pkgs to list of pkgs to remove from final output
  6068.     cut -f2 -d'|' "$USER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6069.   fi
  6070.  
  6071.   if [ "${HIDE_BUILTINS}" = true ];then
  6072.     # add builtins to list of pkgs to remove from final output
  6073.     cut -f2 -d'|' "$WOOF_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6074.   fi
  6075.  
  6076.   if [ -f "$DEVX_INST_PKGS_FILE"  ];then
  6077.     # add devx pkgs to list of pkgs to remove from final output
  6078.     cut -f2 -d'|' "$DEVX_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6079.   fi
  6080.  
  6081.   if [ -f "$LAYER_INST_PKGS_FILE" ];then
  6082.     # add layers list of pkgs to remove from final output
  6083.     cut -f2 -d'|' "$LAYER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6084.   fi
  6085.  
  6086.   if [ -f $TMPDIR/installed_pkgs -a ! -z $TMPDIR/installed_pkgs ];then
  6087.     sort -u $TMPDIR/installed_pkgs | grep -v ^$ > $TMPDIR/installed_pkgs__sorted
  6088.     mv $TMPDIR/installed_pkgs__sorted $TMPDIR/installed_pkgs
  6089.   fi
  6090. }
  6091.  
  6092.  
  6093. has_deps(){                       # return true if $1 has deps, else false
  6094.   [ "$1" = '' -o "$1" = "-" -o ! "$1" ] && echo false
  6095.   [ "`get_deps_entry $1`" != '' ] && echo true || echo false
  6096. }
  6097.  
  6098.  
  6099. list_deps(){                      # list all deps of PKG ($1), space separated on one line FUNCLIST
  6100.   [ "$1" = '' -o "$1" = "-" ] && print_usage list-deps && exit 1
  6101.  
  6102.   echo true > /tmp/pkg/list_deps_busy
  6103.  
  6104.   # create list of installed pkgs ($TMPDIR/installed_pkgs) for later
  6105.   list_all_installed_pkgs
  6106.  
  6107.   # get current $REPOFILE, $DEPSEARCH
  6108.   #. ${PKGRC}
  6109.  
  6110.   local PKGNAME=''
  6111.   local PKGNAME_ONLY=''
  6112.   local pkg_ext=''
  6113.   local repo_files=''
  6114.   local deps_list=''
  6115.   local deps=''
  6116.   local repo_of_pkg=''
  6117.   local repo_file_of_pkg=''
  6118.  
  6119.   # get pkg extension
  6120.   pkg_ext=`get_pkg_ext "$1"`
  6121.  
  6122.   #pkg name only ,no path, no extension
  6123.   PKGNAME="$(LANG=C basename "$1" .$pkg_ext)"
  6124.   PKGNAME=`get_pkg_name "$PKGNAME"`
  6125.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  6126.  
  6127.   blacklisted_pkgs_list="$(echo $PKG_NAME_IGNORE | sed -e 's/ /|/g')"
  6128.  
  6129.   # get the deps of the pkg, note, in the repo deps are NOT listed by proper pkg names, .. they are +dbus,+glib,+SDL
  6130.  
  6131.   # search for deps entry in repo file.. look for |pkgname.ext|
  6132.   deps_list="`LANG=C get_deps_entry "$PKGNAME"`"
  6133.  
  6134.   # if no deps, exit with error
  6135.   [ "$deps_list" = "" ] && rm /tmp/pkg/list_deps_busy 2>/dev/null && return 1
  6136.  
  6137.   # remove the '+' from the start of each dep
  6138.   deps="${deps_list/+/}" # remove first + at start of line
  6139.   deps="${deps//,+/ }"   # remove others .. DEPS will now be just 'dep1 dep2 dep3'
  6140.   deps="${deps//  / }"   # remove double spaces
  6141.  
  6142.   if [ "$deps" != '' -a "$deps" != ' ' ];then
  6143.  
  6144.     # put all deps of pkg in a tmp file
  6145.     echo "$deps" | tr ' ' '\n' | tr ',' '\n' | sort -u > $TMPDIR/all_deps_0
  6146.  
  6147.     # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6148.     comm -23 ${TMPDIR}all_deps_0 ${TMPDIR}installed_pkgs | sort -u | grep -v ^$ > ${TMPDIR}all_deps_1
  6149.  
  6150.     # remove all blacklisted packages from the list
  6151.     grep -vE "'$blacklisted_pkgs_list'" ${TMPDIR}all_deps_1 2>/dev/null | sort -u > ${TMPDIR}all_deps_1_without_blacklisted_packages
  6152.     mv ${TMPDIR}all_deps_1_without_blacklisted_packages ${TMPDIR}all_deps_1
  6153.  
  6154.     rm -f ${TMPDIR}DEP_DONE 2>/dev/null
  6155.  
  6156.     if [ -f $TMPDIR/all_deps_1 -a ! -z $TMPDIR/all_deps_1 ];then
  6157.       # recursive search deps of deps
  6158.       for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  6159.       do
  6160.         deps_list_file="${TMPDIR}all_deps_${i}"
  6161.  
  6162.  
  6163.         if [ -f $deps_list_file ];then
  6164.  
  6165.           # remove all blacklisted packages from the list
  6166.           grep -vE "'$blacklisted_pkgs_list'" "$deps_list_file" > ${TMPDIR}deps_list_file_without_blacklisted_pkgs
  6167.           mv ${TMPDIR}deps_list_file_without_blacklisted_pkgs  $deps_list_file
  6168.  
  6169.           # remove done packages from the list
  6170.           if [ -f ${TMPDIR}DEP_DONE ];then
  6171.             deps_done_list="$(cat ${TMPDIR}DEP_DONE | tr '\n' '|' | grep -v ^$)"
  6172.             grep -vE "'$deps_done_list'" $deps_list_file > ${TMPDIR}deps_list_file_without_completed_pkgs
  6173.             mv ${TMPDIR}deps_list_file_without_completed_pkgs $deps_list_file
  6174.           fi
  6175.  
  6176.           next_deps_list_file="${TMPDIR}all_deps_$(($i + 1))"
  6177.  
  6178.           # for each dep in $deps, get their deps too
  6179.           for subdep in `sort -u $deps_list_file | grep -v ^$`
  6180.           do
  6181.             [ "$subdep" = '' -o "$subdep" = ' ' ] && continue
  6182.  
  6183.             local subdeps_entry=''
  6184.             local subdeps=''
  6185.             local subdeps_list=''
  6186.             local is_builtin
  6187.             local is_in_devx
  6188.  
  6189.             local already_done=`grep -m1 "^${subdep}\$" ${TMPDIR}DEP_DONE 2>/dev/null`
  6190.             [ "$already_done" != '' ] && continue
  6191.  
  6192.             if [ "$HIDE_BUILTINS" = true ];then
  6193.               is_builtin=`is_builtin_pkg "$subdep"`
  6194.               [ "$is_builtin" = true ] && continue
  6195.               is_in_devx=`is_devx_pkg "$subdep"`
  6196.               [ "$is_in_devx" = true ] && continue
  6197.             fi
  6198.  
  6199.             subdeps_entry="`get_deps_entry "$subdep"`"
  6200.             subdeps="${subdeps_entry/+/}" # remove first + at start of line
  6201.             subdeps="${subdeps//,+/ }"    # remove others .. DEPS will now be just 'dep1 dep2 dep3'
  6202.             subdeps="${subdeps//  / }"    # remove double spaces
  6203.  
  6204.             if [ "$subdeps" != '' ] && [ "$subdeps" != ' ' ];then
  6205.               # remove everything after the + (if the + is followed by alphanumeric chars), then add to tmp files
  6206.               echo "$subdep" >> ${TMPDIR}DEP_DONE
  6207.  
  6208.               # create the next deps list file to parse, containing the deps of this $subdep
  6209.               subdeps_list="`echo "${subdeps}" | tr ' ' '\n' | grep -v ^$ | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g' | sort -u`"
  6210.               echo "$subdeps_list" >> $next_deps_list_file
  6211.             fi
  6212.           done
  6213.         fi
  6214.       done
  6215.  
  6216.       # add all deps together, sorted, duplicated removed
  6217.       sort -u ${TMPDIR}all_deps_* | grep -v ^$ > ${TMPDIR}all_deps_sorted
  6218.       mv ${TMPDIR}all_deps_sorted ${TMPDIR}all_deps
  6219.  
  6220.     fi
  6221.  
  6222.   fi
  6223.  
  6224.   # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6225.   if [ -f ${TMPDIR}installed_pkgs -a ! -z  ${TMPDIR}installed_pkgs ];then
  6226.     comm -23 ${TMPDIR}all_deps ${TMPDIR}installed_pkgs | sort -u | grep -v ^$ > ${TMPDIR}missing_deps
  6227.   fi
  6228.  
  6229.   # remove all blacklisted packages from the list
  6230.   grep -vE "'$blacklisted_pkgs_list'" ${TMPDIR}missing_deps 2>/dev/null | sort -u > ${TMPDIR}missing_deps_without_blacklisted_pkgs
  6231.   mv ${TMPDIR}missing_deps_without_blacklisted_pkgs ${TMPDIR}missing_deps
  6232.  
  6233.   [ ! -f ${TMPDIR}missing_deps -o -z ${TMPDIR}missing_deps ] && rm /tmp/pkg/list_deps_busy 2>/dev/null && return 1
  6234.   [ ! -f ${TMPDIR}missing_deps ] && return 1
  6235.  
  6236.   # get fixed deps list
  6237.   deps="`LANG=C sort -u ${TMPDIR}missing_deps 2>/dev/null | tr ' ' '\n' | while read dep
  6238.  do
  6239.    echo $(get_pkg_name_only "$dep")
  6240.  done`"
  6241.  
  6242.   [ "$deps" != "" ] && echo "$deps" | sed -e 's/^ //g' | tr ' ' '\n' | sort -u | tr '\n' ' '
  6243.  
  6244.   # clean up
  6245.   rm ${TMPDIR}missing_dep* ${TMPDIR}installed_pkg* ${TMPDIR}all_dep* ${TMPDIR}DEP_DONE /tmp/pkg/list_deps_busy 2>/dev/null
  6246. }
  6247.  
  6248.  
  6249. find_deps(){                      # given a package name ($1), makes 2 lists: DEPS_INSTALLED and DEPS_MISSING FUNCLIST
  6250.  
  6251.   # This function takes 1 argument: PKGNAME
  6252.   #
  6253.   # PKGNAME should be the name of a package in one of your repos,
  6254.   # such as 'vlc' or 'hardinfo'.
  6255.   #
  6256.   # This function creates 2 files: $TMPDIR/deps_missing and $TMPDIR/deps_installed.
  6257.   # Each file is list the dependencies for PKGNAME, each dependency on a new line.
  6258.   # get_deps() can then go through those files and download/install the missing deps.
  6259.   #
  6260.   # If --force was given, all deps will be treated as missing.
  6261.  
  6262.   # get current repo ($REPOFILE)
  6263.   . ${PKGRC}
  6264.  
  6265.   local PKGNAME=''            # the pkg given ($1), may be full name, or generic name (no version), etc
  6266.   local PKGNAME_ONLY=''       # the pkg given ($1), without version (vlc,htop,etc)
  6267.   local pkg_ext=''            # the pkg extension, blank if not a valid extension or none given
  6268.   local repo_files=''         # the list of repo files to check, may be current only or all
  6269.   local deps_list=''          # deps of PKGNAME in comma-delimited format: dep1,dep2,dep3
  6270.   local deps_on_new_lines=''  # as above, but each dep on a new line
  6271.   local deps_missing=''       # comma separated list of missing deps
  6272.   local deps_installed=''     # comma separated list of deps already installed
  6273.   local dep=''                # dep name scraped from deps_list, usually the same as dep_name_only
  6274.   local dep_match=''          # used to find matches in the repo for $dep
  6275.   local dep_name_only=''      # short (generic) pkg name, no version (vlc,htop,etc)
  6276.   local dep_full_name=''      # pkg name with version (vlc-2.3.3-i686_s700, etc)
  6277.   local loading_indicator     # blank if only a few deps to parse, or .
  6278.  
  6279.   # get pkg extension
  6280.   pkg_ext=`get_pkg_ext "$1"`
  6281.  
  6282.   # pkg name with version, but no path, no extension
  6283.   PKGNAME="$(basename "$1" .$pkg_ext)"
  6284.  
  6285.   # we can't rely on the user input, try to get the right pkg names
  6286.   PKGNAME=`get_pkg_name "$PKGNAME"`       # vlc -> 'vlc-2.3-blah_etc
  6287.   PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`   # vlc-2.3-blah_etc -> vlc
  6288.  
  6289.   # if PKGNAME still empty, we cant find its deps, move on
  6290.   [ -z "$PKGNAME" ] && return 1
  6291.  
  6292.   # didn't exit yet, so remove the old tmp dirs
  6293.   rm $TMPDIR/deps_installed &>/dev/null
  6294.   rm $TMPDIR/deps_missing   &>/dev/null
  6295.   rm $TMPDIR/deps_missing1  &>/dev/null
  6296.  
  6297.   # loop through all repo files, or current repo only, depending on PKGSEARCH in RC file
  6298.   # add the full path to the file(s) while we are getting the list of repo files
  6299.   [ "$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"
  6300.  
  6301.   # get the list of deps from the repo entry of this pkg
  6302.   deps_list="`LANG=C list_deps "$PKGNAME"`"
  6303.  
  6304.   # remove builtins from list unless HIDE_BUILTINS=false
  6305.   if [ "${HIDE_BUILTINS}" = true ];then
  6306.     echo "$deps_list" | tr ' ' '\n'  | grep -v ^$ > ${TMPDIR}all_deps
  6307.     # add woof pkgs to list of pkgs to remove from final output
  6308.     cut -f2 -d'|' "$WOOF_INST_PKGS_FILE" | grep -v ^$ | sort | uniq >> $TMPDIR/installed_pkgs
  6309.     # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6310.  
  6311.     sort -u ${TMPDIR}all_deps > ${TMPDIR}all_deps_sorted
  6312.     mv ${TMPDIR}all_deps_sorted ${TMPDIR}all_deps
  6313.  
  6314.     sort -u ${TMPDIR}installed_pkgs > ${TMPDIR}installed_pkgs_sorted
  6315.     mv ${TMPDIR}installed_pkgs_sorted ${TMPDIR}installed_pkgs
  6316.  
  6317.     comm -23 ${TMPDIR}all_deps ${TMPDIR}installed_pkgs | grep -v ^$ > ${TMPDIR}missing_deps
  6318.     deps_list="`cat "${TMPDIR}missing_deps" 2>/dev/null | grep -v ^$ | sort | tr '\n' ' ' `"
  6319.   fi
  6320.  
  6321.   # so now, $deps_list='dep1 dep2 dep3'
  6322.  
  6323.   # now get the deps list with each dep on its own line
  6324.   deps_on_new_lines="`echo "$deps_list" | tr ' ' '\n'`"
  6325.  
  6326.   # exit if no deps to parse
  6327.   [ "$deps_on_new_lines" = '' ] && return 1
  6328.  
  6329.   # set a loading bar (appending dots....) if we have numerous deps to search
  6330.   [ `echo "$deps_on_new_lines" | wc -l` -gt 4 ] && loading_indicator='.' || loading_indicator=''
  6331.  
  6332.   # now.. we go through ALL deps listed, and create a list for installed or not .. $dep will be 'gtkdialog3', for example
  6333.   echo "$deps_on_new_lines" | grep -v ^$ | while read dep
  6334.   do
  6335.     # append dots as we go, like a loading spinner
  6336.     [ "$loading_indicator" = '.' ] && echo -n "$loading_indicator"
  6337.  
  6338.     # $dep is currently
  6339.     dep_full_name=`get_pkg_name "$dep"`     #vlc-2.3.3-i586_s700
  6340.     dep_name_only=`get_pkg_name_only "$dep"`  #vlc
  6341.  
  6342.     # skip these non pkgs
  6343.     [ "`is_repo_pkg "$dep_name_only"`" = false ] && continue
  6344.  
  6345.     # if we added this dep to the list of PKGs already done, skip it
  6346.     [ "`grep -m1 "^$dep_name_only\$" $TMPDIR/PKGSDONE 2>/dev/null`" != '' ] && continue
  6347.  
  6348.     # lets check if the $dep is installed or not
  6349.  
  6350.     # if dep was found in a repo and not installed, add to missing deps list
  6351.     if [ "$FORCE"  = true -o "`is_installed_pkg "$dep_full_name"`" = false ];then
  6352.       grep -m1 "^$dep_name_only\$" $TMPDIR/deps_missing 2>/dev/null || echo "$dep_name_only" | grep -v "^$PKGNAME" >> $TMPDIR/deps_missing
  6353.  
  6354.     else
  6355.       # else if the dep is already installed, add to installed deps list
  6356.       grep -m1 "^$dep_name_only\$" $TMPDIR/deps_installed 2>/dev/null || echo "$dep_name_only" | grep -v "^$PKGNAME" >> $TMPDIR/deps_installed
  6357.     fi
  6358.  
  6359.     # clean up deps_installed, remove duplicates, etc
  6360.     if [ -f $TMPDIR/deps_installed ];then
  6361.       cat $TMPDIR/deps_installed 2>/dev/null| sort | uniq >> $TMPDIR/deps_installed1
  6362.       [ -f $TMPDIR/deps_installed1 ] && mv $TMPDIR/deps_installed1 $TMPDIR/deps_installed 2>/dev/null
  6363.     fi
  6364.  
  6365.   done # end of while $dep
  6366.  
  6367.   # make a comma separated list from newlines
  6368.   deps_installed="`cat $TMPDIR/deps_installed 2>/dev/null | sort | uniq | tr '\n' ',' | sed -e 's/,,/,/' -e 's/,$//' -e 's/^,//'`"
  6369.   deps_missing="`cat $TMPDIR/deps_missing 2>/dev/null | sort | uniq | tr '\n' ',' | sed -e 's/,,/,/' -e 's/,$//' -e 's/^,//'`"
  6370.  
  6371.   #120213, fixed, force all deps to be in the download list, if --force was given
  6372.   if [ "$FORCE" = true ];then
  6373.     # dont skip installed deps (except builtins.. handled elsewhere)
  6374.     if [ "$deps_installed" != "" ];then
  6375.       deps_missing="${deps_installed},${deps_missing}"
  6376.       deps_missing="`echo "${deps_missing//,,/}" | sed -e 's/,$//' -e 's/^,//'`"
  6377.     fi
  6378.   fi
  6379.  
  6380.   # later, get_deps() will use $DEPS_MISSING and $DEPS_INSTALLED
  6381.   DEPS_MISSING="$deps_missing"
  6382.   DEPS_INSTALLED="$deps_installed"
  6383.  
  6384.   # end appending dots... msg, by printing a new line
  6385.   [ "$loading_indicator" != '' ] && echo
  6386.  
  6387. }
  6388.  
  6389.  
  6390. get_deps(){                       # find, get and install the deps of pkgname ($1) FUNCLIST
  6391.  
  6392.   [ -z "$1" -o ! "$1" -o "$1" = "-" ] && print_usage deps && exit 1
  6393.  
  6394.   . ${PKGRC} #150813
  6395.  
  6396.   local EX
  6397.   local PKGNAME
  6398.   local DEPCONFIRM
  6399.  
  6400.   # get pkg extension
  6401.   local EX=`get_pkg_ext "$1"`
  6402.  
  6403.   # get pkg name with version, but no path, no extension
  6404.   local PKGNAME="$(LANG=C basename "$1" .$EX)"
  6405.  
  6406.   # don't rely on user input, get the name w version from repos
  6407.   local PKGNAME=`get_pkg_name "$PKGNAME" 2>/dev/null`
  6408.   local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME" 2>/dev/null`
  6409.  
  6410.   local pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY" 2>/dev/null`
  6411.   local pkg_already_done=`LANG=C grep -m1 "^$PKGNAME_ONLY\$" $TMPDIR/PKGSDONE 2>/dev/null`
  6412.  
  6413.   local pkg_is_blacklisted=`is_blacklisted_pkg "$PKG_NAME_ONLY" 2>/dev/null`
  6414.  
  6415.   # if pkg is builtin, skip it, we dont need to get its dependencies
  6416.   [ "$pkg_is_builtin" = true -a "$HIDE_BUILTINS" = true ] && continue
  6417.  
  6418.   # if pkg is blacklisted, also skip it
  6419.   [ "$pkg_is_blacklisted" = true ] && continue
  6420.  
  6421.   # skip if already processed, it should be listed in $TMPDIR/PKGSDONE
  6422.   [ "$pkg_already_done" != "" -a "$FORCE" = false ] && continue
  6423.  
  6424.   echo -n "Resolving dependencies.." # find deps will append ... as it goes
  6425.  
  6426.   # wait until list_deps() is finished (if it's running at all...)
  6427.   while [ -f /tmp/pkg/list_deps_busy ];do
  6428.     echo -n '.'
  6429.     sleep 0.75
  6430.   done
  6431.  
  6432.   echo
  6433.  
  6434.   # if list_deps() created a file listing the deps, get it from the file created, else, run list deps to be sure
  6435.   [ -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`"
  6436.  
  6437.   # if we have missing deps, or are downloading them all regardless (INSTALLDEPS=false), or using --force
  6438.   if [ "$DEPS_MISSING" != "" -o "${NO_INSTALL}" = true -o "$FORCE" = true ];then
  6439.  
  6440.     # ask to download (and maybe install) the deps
  6441.     DEPCONFIRM=y
  6442.     if [ "$ASK" = true ];then
  6443.       echo "Missing deps: $DEPS_MISSING"
  6444.       echo -n "Download the missing dependencies$QTAG:  "
  6445.       read -n 1 DEPCONFIRM </dev/tty
  6446.       echo
  6447.       # skip if user chose --ask and didn't answer 'y'
  6448.       [ "$DEPCONFIRM" != "y" ] && return
  6449.     fi
  6450.  
  6451.     # if user answered yes, we will now download (and maybe install) the deps
  6452.     if [ "$DEPCONFIRM" = "y" -o "$FORCE" = true ];then
  6453.  
  6454.       # only ask once
  6455.       ASK=false
  6456.  
  6457.       # make a list of the deps, each on a new line for each dep/newline
  6458.       WARNLIBS=''; SEP='';
  6459.  
  6460.       # if more than one missing dep, set separator to a comma
  6461.       [ ! -z "$DEPS_MISSING" -a "`echo "$DEPS_MISSING" | wc -l`" != "1" -a "`echo "$DEPS_MISSING" | wc -l`" != "0" ] && SEP=','
  6462.  
  6463.       # clean up our deps list, and make space separated only (no commas)
  6464.       DEPS_MISSING="`LANG=C echo "${DEPS_MISSING//,/ }" | grep -v '^,' | grep -v "^\$"`"
  6465.  
  6466.       # show deps info, if any available
  6467.       [ "${DEPS_MISSING}" != ""  ]   && echo "Dependencies to get: ${DEPS_MISSING//,/, }"
  6468.       [ "$FORCE" = false -a "${DEPS_INSTALLED}" != "" ] && echo "Dependencies installed: `LANG=C grep -v "^\$" $TMPDIR/deps_installed 2>/dev/null | head -1`"
  6469.  
  6470.       # for each missing dep  (or simply for each dep, if $FORCE is true)
  6471.       for DEP in $DEPS_MISSING
  6472.       do
  6473.  
  6474.         [ "$DEP" = "" -o "$DEP" = "${PKGNAME_ONLY}" -o "$DEP" = "${PKGNAME}" ] && continue #skip if the dep is the main package
  6475.  
  6476.         local DEPNAME=`get_pkg_name "$DEP" 2>/dev/null`
  6477.         local DEPNAME_ONLY=`get_pkg_name_only "$DEPNAME" 2>/dev/null`
  6478.         local DEPFILE=''
  6479.  
  6480.         # skip if already processed, it should be listed in $TMPDIR/PKGSDONE
  6481.         local dep_already_done=`LANG=C grep -m1 "^$DEPNAME_ONLY\$" $TMPDIR/PKGSDONE 2>/dev/null`
  6482.         [ "$dep_already_done" != "" -a "$FORCE" = false ] && continue
  6483.  
  6484.         local dep_is_blacklisted=`is_blacklisted_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6485.         local dep_is_builtin=`is_builtin_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6486.         local dep_is_usr_pkg=`is_usr_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6487.         local dep_is_in_devx=`is_devx_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6488.  
  6489.         # skip getting pkg if its blacklisted
  6490.         if [ "$dep_is_blacklisted" = true ];then
  6491.           echo "Skipping $DEPNAME_ONLY (blacklisted).."
  6492.           continue
  6493.         fi
  6494.  
  6495.         # skip getting pkg if its a builtin, unless HIDE_BUILTINS=false
  6496.         if [ "$dep_is_builtin" = true -a "${HIDE_BUILTINS}" = true ];then
  6497.           echo "Skipping $DEPNAME_ONLY (already built-in).."
  6498.           continue
  6499.         fi
  6500.  
  6501.         # skip getting pkg if its user installed and not using --force
  6502.         if [ "$dep_is_usr_pkg" = true -a "${FORCE}" != true ];then
  6503.           echo "Skipping $DEPNAME_ONLY (already installed).."
  6504.           continue
  6505.         fi
  6506.  
  6507.         # skip getting pkg if its in the devx, unless HIDE_BUILTINS=false
  6508.         if [ "$dep_is_in_devx" = true -a "${HIDE_BUILTINS}" = true ];then
  6509.           echo "Skipping $DEPNAME_ONLY (already built-in).."
  6510.           continue
  6511.         fi
  6512.  
  6513.         #DOWNLOAD THE PKG
  6514.         pkg_download "$DEPNAME" 2>/dev/null
  6515.  
  6516.         # skip install unless NO_INSTALL=true
  6517.         if [ "${NO_INSTALL}" = false ];then
  6518.  
  6519.           # get the actual file we just downloaded to WORKDIR
  6520.           DEPFILE="`find "$WORKDIR" -maxdepth 1 -type f -name "$DEPNAME*" 2>/dev/null`"
  6521.  
  6522.           #INSTALL THE DEP, if it was downloaded
  6523.           [ "`is_local_pkg "$DEPFILE" 2>/dev/null`" = true ] && pkg_install "$DEPFILE" 2>/dev/null
  6524.  
  6525.           # mark the pkg as done!
  6526.           echo "$DEPNAME_ONLY" >> $TMPDIR/PKGSDONE
  6527.  
  6528.         else # if not installing,
  6529.           # skip dep checking of the deps that dont get installed
  6530.           continue
  6531.         fi
  6532.  
  6533.  
  6534.         # we finished with this dep, mark it done,
  6535.         # .. so we can skip it if it appears again (in a recursive dep check loop for example)
  6536.         echo "$DEPNAME_ONLY" >> $TMPDIR/PKGSDONE #260713
  6537.  
  6538.  
  6539.       done #done for DEP in DEPS_MISSING
  6540.  
  6541.     fi #endif DEPCONFIM=y
  6542.  
  6543.   else
  6544.     echo "No missing dependencies."
  6545.   fi # endif DEPS_MISSING != ''
  6546.  
  6547.   # if some deps were missing (listed but not found), print msg
  6548.   [ "$INSTALLDEPS" = true ] && actioned=installed || actioned=downloaded
  6549.   [ "$WARNLIBS" != "" ]     && echo -e "${yellow}Warning:${endcolour} Not $actioned from repo: $WARNLIBS"
  6550.   #exit 0 #110913
  6551. }
  6552.  
  6553.  
  6554. pkg_ldd_msg(){                    # check given package ($1) for missing deps FUNCLIST
  6555.  
  6556.   # exit if no valid usage
  6557.   [ ! "$1" -o "$1" = "-" ] && print_usage deps-check && exit 1
  6558.  
  6559.   . ${PKGRC}
  6560.  
  6561.   local PKGNAME
  6562.   local FNDFILES
  6563.   local LIST
  6564.   local RES
  6565.   local MISSING
  6566.  
  6567.   # get pkg name
  6568.   PKGNAME=`get_pkg_name "$1"`
  6569.   rm $TMPDIR/pkg-$PKGNAME-MISSING.txt &>/dev/null
  6570.  
  6571.   [ "`is_installed_pkg "$PKGNAME"`" = false ] && print_usage deps-check && exit 1
  6572.  
  6573.   echo "Searching for missing dependencies.. Please wait."
  6574.  
  6575.   local list="$PKGNAME `list_deps $PKGNAME`"
  6576.  
  6577.   for pkg_name in $list
  6578.   do
  6579.     local pkg_name_only=`get_pkg_name_only "$pkg_name"`
  6580.     # get the *.files for this pkg
  6581.     FNDFILES="$(find $PACKAGE_FILE_LIST_DIR/ -iname "${pkg_name}.files" 2>/dev/null)"
  6582.     [ ! -f "$FNDFILES" ] && FNDFILES="$(find "$PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}_*.files" 2>/dev/null)"
  6583.     [ ! -f "$FNDFILES" ] && FNDFILES="$(find "$PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}-*.files" 2>/dev/null)"
  6584.     [ ! -f "$FNDFILES" ] && FNDFILES="$(find "PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}*.files"  2>/dev/null)"
  6585.     [ ! -f "$FNDFILES" ] && continue
  6586.  
  6587.     # get list of ldd-able file
  6588.     cat "$FNDFILES" | grep -E '/lib/|/lib64/|/bin/|/games/|/sbin/' > ${TMPDIR}ldd_file_list_${pkg_name}
  6589.     [ -z ${TMPDIR}ldd_file_list_${pkg_name} ] && continue
  6590.  
  6591.     #loop through list
  6592.     for file in `cat ${TMPDIR}ldd_file_list_${pkg_name}`
  6593.     do
  6594.       [ ! -x "$file" ] && continue
  6595.       RES="`ldd $file 2>/dev/null`"
  6596.       MISSING="`echo "$RES" | grep found`"
  6597.       [ "$MISSING" != "" -a "$MISSING" != " " ] && echo "  $file:
  6598.  $MISSING" >> $TMPDIR/${pkg_name}-MISSINGLIBS.txt
  6599.     done
  6600.  
  6601.     #print message
  6602.     if [ -f $TMPDIR/${pkg_name}-MISSINGLIBS.txt ];then
  6603.       echo -e "${yellow}WARNING${endcolour}: ${magenta}${pkg_name_only}${endcolour} has missing dependencies: "
  6604.       echo -e "`cat $TMPDIR/${pkg_name}-MISSINGLIBS.txt`"
  6605.     else
  6606.       echo -e "${green}OK:${endcolour} ${pkg_name} has no missing dependencies."
  6607.     fi
  6608.     rm -f ${TMPDIR}ldd_file_list* $TMPDIR/${pkg_name}-MISSINGLIBS.txt 2>/dev/null
  6609.   done
  6610. }
  6611.  
  6612.  
  6613. get_all_deps(){                   # try to install all missing deps FUNCLIST
  6614.  echo "Checking $(list_installed_pkgs | wc -l) installed packages for missing dependencies. Please wait..."
  6615.  rm $TMPDIR/pkg_get_all_deps 2>/dev/null
  6616.  
  6617.  list_installed_pkgs | while read LINE; do
  6618.   DEPLIST="`LANG=C list_deps "$LINE"`"
  6619.   [ "$DEPLIST" != "" -a "$LINE" != "" ] && echo "$LINE|$DEPLIST" >> $TMPDIR/pkg_get_all_deps
  6620.  done
  6621.  
  6622.  [ ! -f $TMPDIR/pkg_get_all_deps ]   && echo "No missing dependencies." && exit 0
  6623.  ASKOPT='';   [ "$ASK" = true ]   && ASKOPT='--ask ';
  6624.  FORCEOPT=''; [ "$FORCE" = true ] && FORCEOPT='--force ';
  6625.  
  6626.  cat $TMPDIR/pkg_get_all_deps 2>/dev/null | while read LINE
  6627.  do
  6628.   [ "$LINE" = "" -o "`echo "$LINE" | grep -v '|'`" = "" ] && continue
  6629.   # get pkg gname from field 1
  6630.   PKGNAME="${LINE%%|*}"
  6631.   DEPS="${LINE##*|}"
  6632.  
  6633.   echo "Checking $PKGNAME..."
  6634.  
  6635.   for DEP in $DEPS;
  6636.   do
  6637.     # try to get the pkg name
  6638.     DEPPKG="`list_all_pkg_names $DEP- | head -1`" || \
  6639.     DEPPKG="`list_all_pkg_names $DEP_ | head -1`" || \
  6640.     DEPPKG="`list_all_pkg_names $DEP  | head -1`"
  6641.     # if dep not in any repos, skip it
  6642.     [ "$DEPPKG" = "" ] && continue
  6643.     # skip if the dep is already installed
  6644.     [ "`is_installed_pkg $DEPPKG`" = true ] && continue
  6645.     # ask to get dep
  6646.     echo -n "Get the missing package: ${DEPPKG}$QTAG:  "
  6647.     echo
  6648.     [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  6649.     [ "$ASK" = true ] && echo -ne "\b\b\n"
  6650.     # if user answered yes, we will now download the pkgs
  6651.     if [ "$CONFIRM" = "y" ];then
  6652.       NO_INSTALL=false pkg_get "$DEPPKG" # get the missing dep (and its deps)
  6653.     fi
  6654.   done
  6655.  done
  6656.  rm -f $TMPDIR/pkg_get_all_deps 2>/dev/null
  6657. }
  6658.  
  6659.  
  6660. list_dependents(){                # list user installed pkgs that depend on $1 FUNCLIST
  6661.  
  6662.   local PKGNAME=''
  6663.   local PKGNAME_ONLY=''
  6664.  
  6665.   if [ "$1" = '' ];then
  6666.     print_usage what-needs
  6667.     exit 1
  6668.   fi
  6669.  
  6670.   # try to get correct pkg names
  6671.   PKGNAME=`get_pkg_name "$1"`
  6672.   PKGNAME_ONLY=`get_pkg_name_only "$1"`
  6673.  
  6674.   # if pkg is not installed, then nothing depends on it
  6675.   if [ "`is_installed_pkg "$PKGNAME"`" = false ];then
  6676.     echo "Package $1 not installed, nothing depends on it."
  6677.     exit 1
  6678.   fi
  6679.  
  6680.   # list all pkgs (from all repos) with $PKGNAME_ONLY as a dep
  6681.   cut -f1,2,9 -d'|' "$REPO_DB_FILE_DIR"/Packages-* \
  6682.     | sed -e "s/:any//g" -e "s/&[geql][eqt][0-9a-z._-]*//g" 2>/dev/null \
  6683.     | grep -E "+${PKGNAME_ONLY},|+${PKGNAME_ONLY}\|" 2>/dev/null \
  6684.     | cut -f2 -d'|' 2>/dev/null \
  6685.     | grep -v "^\$" \
  6686.     | grep -v "^#" \
  6687.     | grep -v "^$PKGNAME_ONLY\$" \
  6688.     | sort -u \
  6689.     >> ${TMPDIR}/dependents_list
  6690.  
  6691.   if [ "$HIDE_BUILTINS" = false ];then
  6692.     # list all builtin and devx packages with $PKGNAME_ONLY as a dependency..
  6693.     cut -f1,2,9 -d'|' "$WOOF_INST_PKGS_FILE"  "$DEVX_INST_PKGS_FILE" \
  6694.       "$DEVX_INST_PKGS_FILE" \
  6695.       | grep -E "+${PKGNAME_ONLY},|+${PKGNAME_ONLY}\|" \
  6696.       | cut -f2 -d'|' \
  6697.       | grep -v "^\$" \
  6698.       | grep -v "^#" \
  6699.       | grep -v "^$PKGNAME_ONLY\$" \
  6700.       | sort -u \
  6701.       >> ${TMPDIR}/dependents_list
  6702.   fi
  6703.  
  6704.   # remove duplicates
  6705.   sort -u ${TMPDIR}/dependents_list > ${TMPDIR}/dependents_list__sorted
  6706.   mv ${TMPDIR}/dependents_list__sorted ${TMPDIR}/dependents_list_tmp
  6707.   rm ${TMPDIR}/dependents_list
  6708.  
  6709.   # only keep the user installed pkgs in the list
  6710.   for pkg in `list_installed_pkgs | grep -v ^$PKGNAME`
  6711.   do
  6712.     [ "`grep -m1 "^$(get_pkg_name_only $pkg)\$" ${TMPDIR}/dependents_list_tmp`" != '' ] && echo "$pkg" >> ${TMPDIR}/dependents_list
  6713.   done
  6714.  
  6715.   # print the list if we have one
  6716.   [ -f ${TMPDIR}/dependents_list -a ! -z ${TMPDIR}/dependents_list ] && cat ${TMPDIR}/dependents_list
  6717.   rm ${TMPDIR}/dependents_lis* 2>/dev/null
  6718. }
  6719.  
  6720.  
  6721. # file conversion
  6722.  
  6723. deb2pet(){                        # $1 must be valid deb file or repo pkg FUNCLIST
  6724.   [ ! -f "$1" ] && print_usage deb2pet && exit 1
  6725.  
  6726.   local DEB="${CURDIR}/$(basename "${1}")"
  6727.   local DIRNAME="${CURDIR}"
  6728.   #create file name we work with
  6729.   [ -f "$1" ] && DEB="$1" && DIRNAME="`dirname "$1"`"
  6730.  
  6731.   #keep old file, download it if needed
  6732.   #[ -f "$(basename "$1" .deb)" ] || ASK=$ASK FORCE=$FORCE pkg_download "$(basename "$1" .deb)"
  6733.  
  6734.   # if the deb exists
  6735.   if [ -e "$DEB" ]; then
  6736.     for i in "$DEB" # for each deb given
  6737.     do
  6738.       #remove the extensions
  6739.       #example, will be something like FOLDR=$HOME/Desktop/atari800_3.1.0-2+b2_i386
  6740.       FOLDR="$(echo "$i"|sed 's/\.deb$//')"
  6741.     done
  6742.  
  6743.     #make the new dir, copy the deb file into it, and ci into it
  6744.     mkdir -p "$FOLDR"; cp "$DEB" "$FOLDR"; cd "$FOLDR";
  6745.  
  6746.     #get the new full path and filename
  6747.     DEB="`ls | grep ".deb"`"
  6748.  
  6749.     # extract into current dir and remov ethe copied deb file
  6750.     pkg_unpack "$DEB" 1>/dev/null
  6751.  
  6752.     #this will be something like  PKGNAME=atari800_3.1.0-2+b2_i386
  6753.     PKGNAME="`basename "$DEB" .deb`"
  6754.  
  6755.     #now we package up the stuff into a pet
  6756.     [ -d "${FOLDR}/$PKGNAME" ] && dir2pet "${FOLDR}/$PKGNAME" || dir2pet "$PKGNAME"
  6757.  
  6758.     [ ! -f "$FOLDR.pet" -a ! -f "${CURDIR}/${PKGNAME}.pet" ] && error "$FOLDR.deb NOT converted to PET package!"
  6759.  
  6760.     #clean up
  6761.     rm -rf "$FOLDR"
  6762.  
  6763.   else
  6764.     echo "Package '$(basename $DEB)' not found in '$CURDIR'."
  6765.     return 1
  6766.   fi
  6767. }
  6768.  
  6769.  
  6770. dir2pet(){                        # dir to PET, $1 must be valid dir FUNCLIST
  6771.  
  6772.   # exit if no options
  6773.   [ ! -d "$1" ] && print_usage dir2pet && exit 1
  6774.  
  6775.   DIR="$1"
  6776.   SUFFIX=''
  6777.  
  6778.   [ "$2" != "" ] && SUFFIX="$2"
  6779.  
  6780.   #[ -d "$DIR" ] && cd `dirname "$DIR"`
  6781.  
  6782.   # get pkg name only,
  6783.   DIR="$(basename "${DIR}")"
  6784.   [ "$SUFFIX" != "" ] && cp -R "$DIR" "${DIR}${SUFFIX}" && DIR="${DIR}${SUFFIX}"
  6785.  
  6786.   echo -e "Converting directory ${lightblue}$DIR${endcolour} to .pet package."
  6787.  
  6788.   # we must have a dir with same name as a valid pkg
  6789.   if [ -d "$DIR" ];then
  6790.     # move it to the build dir, to work on
  6791.     mkdir -p "$CURDIR/build_pkg/"
  6792.     [ ! -e "$CURDIR/build_pkg/$DIR" ] && cp -R "$DIR" "$CURDIR/build_pkg/"
  6793.  
  6794.     ARCHINDEPENDENT='yes'
  6795.     for ONEEXEC in `find $CURDIR/build_pkg/${DIR}/ -maxdepth 6 -type f -perm -o+x`
  6796.     do
  6797.       [ -f $ONEEXEC ] && [ "`file $ONEEXEC | grep ' ELF '`" != "" ] && ARCHINDEPENDENT='no'
  6798.     done
  6799.  
  6800.     # if it's a _DEV pkg.. it can't be ARCHINDEPENDENT
  6801.     case "${BASEPKG}" in *"_DEV"*) ARCHINDEPENDENT='no' ;; esac
  6802.     [ "`find $CURDIR/build_pkg/${DIR}/ -maxdepth 6 -type f -name '*.a' -o -type f -name 'lib*.so*' -o -type f -name '*.la'`" != "" ] && ARCHINDEPENDENT='no'
  6803.     [ "$ARCHINDEPENDENT" = "no" ] && COMPAT=$DISTRO_BINARY_COMPAT V=$DISTRO_COMPAT_VERSION
  6804.  
  6805.         #...borrowed from dir2pet script
  6806.     #w482 directory may already have a pet.specs, reuse it...
  6807.     NAMEONLY=""
  6808.     PUPMENUDESCR=""
  6809.     PUPOFFICIALDEPS=""
  6810.     PUPCATEGORY=""
  6811.     PUPPATH="" #100201
  6812.     ARCHDEPENDENT="yes" #100201
  6813.     DEFREPO="" #100201
  6814.     if [ -f $CURDIR/build_pkg/${DIR}/pet.specs ];then #160803
  6815.      #new: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|
  6816.      #optionally on the end: compileddistro|compiledrelease|repo| (fields 11,12,13)
  6817.      PETSPECS="`cat $CURDIR/build_pkg/${DIR}/pet.specs | head -n 1`" #160803
  6818.      while IFS="|" read -r F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 <&3
  6819.      do
  6820.        DB_pkgname="$F1"
  6821.        DB_nameonly="$F2"
  6822.        NAMEONLY="$DB_nameonly"
  6823.        DB_version="$F3"
  6824.        DB_pkgrelease="$F4"
  6825.        DB_category="$F5"
  6826.        PUPCATEGORY="$DB_category"
  6827.        DB_size="$F6"
  6828.        DB_path="$F7"
  6829.        PUPPATH="$DB_path" #100201
  6830.        DB_fullfilename="$F8"
  6831.        DB_dependencies="$F9"
  6832.        PUPOFFICIALDEPS="$DB_dependencies"
  6833.        DB_description="$F10"
  6834.        PUPMENUDESCR="$DB_description"
  6835.        DB_compileddistro="$F11"
  6836.        DB_compiledrelease="$F12"
  6837.        ARCHDEPENDENT="${DB_compileddistro}|${DB_compiledrelease}"
  6838.        DB_repo="$F13"
  6839.        DEFREPO="$DB_repo"
  6840.       done 3< $CURDIR/build_pkg/${DIR}/pet.specs
  6841.     else
  6842.       echo -e "\nCategories:
  6843.  BuildingBlock, Desktop, System, Setup, Utility,
  6844.  Filesystem, Graphic, Document, Business, Personal,
  6845.  Network, Internet, Multimedia, Fun\n"
  6846.       read -p 'Type one of the categories above, then hit ENTER: ' CAT_ENTRY </dev/tty;
  6847.  
  6848.       echo
  6849.       read -p "Add a short description, then hit ENTER: " DESC_ENTRY </dev/tty;
  6850.  
  6851.       echo -e "\nAdd dependencies in this format:  ${bold}+libglib,+ffmpeg${endcolour}\n"
  6852.       read -p 'Enter dependencies (if any), then hit ENTER: ' DEPS_ENTRY </dev/tty;
  6853.  
  6854.       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
  6855.     fi
  6856.  
  6857.     # build .pet.specs
  6858.  
  6859.     BASEPKG="`basename $DIR`"
  6860.     DIRPKG="`dirname $DIR`"
  6861.     [ "$DIRPKG" = "/" ] && DIRPKG=""
  6862.  
  6863.     #difficult task, separate package name from version part...
  6864.     #not perfect, some start with non-numeric version info...
  6865.     [ "$NAMEONLY" = "" ] && NAMEONLY=`get_pkg_name_only "$BASEPKG"`
  6866.  
  6867.     # get pet details from the pre-existing pet.specs (if any): deps, category, descr, version, nameonly, arch, distro version
  6868.     PUPOFFICIALDEPS="$DB_dependencies"
  6869.  
  6870.     TOPCAT="$PUPCATEGORY"
  6871.     [ -z "$TOPCAT" ] && TOPCAT=BuildingBlock
  6872.  
  6873.     PUPMENUDESCR="$DB_description"
  6874.     [ -z "${PUPMENUDESCR}" ] && PUPMENUDESCR="No description provided"
  6875.  
  6876.     VERSION="`get_pkg_version "$BASEPKG"`"
  6877.  
  6878.     # build pet spec
  6879.     if [ ! -f $CURDIR/build_pkg/${DIR}/pet.specs ];then
  6880.       echo "$BASEPKG|${NAMEONLY}|$VERSION|$DB_pkgrelease|$TOPCAT|$DB_size|$REPO_SUBDIR|${BASEPKG}.pet|$PUPOFFICIALDEPS|$PUPMENUDESCR|$COMPAT|$V||" > $CURDIR/build_pkg/${DIR}/pet.specs
  6881.     fi
  6882.  
  6883.     # delete the slackware package management files
  6884.     #if [ -d "$CURDIR/build_pkg/install" ];then
  6885.     # rm -r "$CURDIR/build_pkg/install"; rmdir "$CURDIR/build_pkg/install";
  6886.     #fi
  6887.  
  6888.     # delete arch pkg stuff
  6889.     #rm -r "$CURDIR/build_pkg/.INSTALL" &>/dev/null
  6890.     #rm "$CURDIR/build_pkg/.PKGINFO" &>/dev/null
  6891.  
  6892.     # now tar up the folder, ready to make into tar.gz, then into .pet
  6893.     cd $CURDIR/build_pkg/
  6894.  
  6895.     # we need to choose xz or gzip pets
  6896.     arch=`uname -m`
  6897.     if [ "${arch:0:3}" = "arm" ];then
  6898.       TAREXT="gz"
  6899.     else
  6900.       TAREXT="xz"
  6901.     fi
  6902.  
  6903.     # if in a pre-woof puppy then we dont use xz
  6904.     if [ ! -f "$WOOF_INST_PKGS_FILE" -o ! -f /etc/DISTRO_SPECS ];then
  6905.       # pre woof format
  6906.       echo "PETMENUDESCR='${DIR}'" >  $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  6907.       echo "PETOFFICIALDEPS=''"    >> $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  6908.       echo "PETREGISTER='yes'"     >> $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  6909.       compression=xz
  6910.       TAREXT="xz"
  6911.     fi
  6912.     tar -c -f ${DIR}.tar ${DIR} 1>/dev/null
  6913.     sync
  6914.     [ "`which xz`" = "" ] && TAREXT=gz
  6915.     case $TAREXT in
  6916.       xz)xz -z -9 -e ${DIR}.tar ;;
  6917.       gz)gzip --best ${DIR}.tar ;;
  6918.     esac
  6919.  
  6920.     # now get info needed to make a pet file
  6921.     TARBALL="${DIR}.tar.$TAREXT"
  6922.     FULLSIZE="`stat --format=%s ${TARBALL}`"
  6923.     MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  6924.  
  6925.     # add the info to the file
  6926.     echo -n "$MD5SUM" >> $TARBALL
  6927.     sync
  6928.  
  6929.     # now rename it to .pet
  6930.     mv -f $TARBALL ${DIR}.pet
  6931.     sync
  6932.  
  6933.     # move the created pet out of build_pkg, into WORK_DIR
  6934.     mv ${DIR}.pet $CURDIR/${DIR}.pet
  6935.     cd $CURDIR
  6936.  
  6937.     # clean up
  6938.     rm -f -R $CURDIR/build_pkg/
  6939.     echo
  6940.     echo -e "Package ${magenta}${DIR}.pet${endcolour} created."
  6941.     echo "The md5sum is: `md5sum ${DIR}.pet | cut -f1 -d' '`."
  6942.   else
  6943.     echo "Directory '$DIR' not found."
  6944.     exit 1
  6945.   fi
  6946. }
  6947.  
  6948.  
  6949. dir2sfs(){                        # $1 must be dir of pkg contents FUNCLIST
  6950.  
  6951.   if [ ! -d "$1" ];then
  6952.     print_usage dir2sfs
  6953.     exit 1
  6954.   fi
  6955.  
  6956.   # if found, we will append it to the SFS filename
  6957.   [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  6958.  
  6959.   # get sfs name only, no extension or path
  6960.   SFS_DIR="`basename "$1" .sfs`"
  6961.  
  6962.   # if a valid dir
  6963.   if [ -d "$SFS_DIR" ];then
  6964.     rm "${SFS_DIR}/"*pet*specs 2>/dev/null #240613
  6965.     #start building the sfs file
  6966.     echo "Please wait... building SFS file.."
  6967.     local SFS_NAME="${SFS_DIR/$SFS_SUFFIX/}${SFS_SUFFIX}.sfs"
  6968.     LANG=C mksquashfs "$SFS_DIR" "$SFS_NAME" -noappend &>/dev/null && SUCCESS="y" || SUCCESS=""
  6969.     if [ -z "$SUCCESS" -a ! -f "${SFS_DIR}${SFS_SUFFIX}.sfs" ]; then
  6970.       echo "Failed to create $SFS_NAME."
  6971.       exit 1
  6972.     fi
  6973.     chmod 644 "$SFS_NAME" #shinobar
  6974.     sync
  6975.     #get size, and output msg
  6976.     s=`LANG=C du -m "$SFS_NAME" | sed "s/\s.*//"`
  6977.     MD5SUM=`md5sum "$SFS_NAME" | cut -f1 -d ' '`
  6978.     echo -e "Created ${magenta}$SFS_NAME${endcolour} ( $s MB )"
  6979.     echo -e "The md5 checksum: $MD5SUM"
  6980.   else
  6981.     echo "Cannot create SFS:  '${SFS_DIR}' is not a directory."
  6982.     exit 1
  6983.   fi
  6984.  
  6985.   # clean up
  6986.   #rm -rf "${SFS_DIR}" &>/dev/null
  6987.   #rm -f "${SFS}${SFS_SUFFIX}"*.sfs-md5.txt &>/dev/null
  6988.   rm -f "${SFS}${SFS_SUFFIX}" &>/dev/null
  6989. }
  6990.  
  6991.  
  6992. dir2tgz(){                        # requires $1 as valid dir FUNCLIST
  6993.  
  6994.   [ ! -d "$1" ] && print_usage dir2tgz && exit 1
  6995.  
  6996.   DIR="${1/.t*gz/}"
  6997.  
  6998.   # remove trailing slash
  6999.   DIRNAME="`echo -n $DIR | sed -e 's%/$%%'`"
  7000.   DIRNAME="`basename ${DIRNAME}`" # get name only, no path
  7001.  
  7002.   # make sure any pet specs are named correctly - this new tar file might later be converted to a .pet
  7003.   echo "`ls -1 ${DIRNAME} | grep 'pet.specs'`" | while read LINE
  7004.   do
  7005.     mv "${DIRNAME}/$LINE" "${DIRNAME}/pet.specs" 2>/dev/null;
  7006.   done
  7007.  
  7008.   # create the tar file
  7009.   ##echo "Adding directory to '${DIRNAME}.tar.gz'.."
  7010.   tar -c -f "${DIRNAME}.tar" "${DIRNAME}/"
  7011.   gzip "${DIRNAME}.tar"
  7012.   sync
  7013.  
  7014.   # print message
  7015.   if [ -f "${DIRNAME}.tar.gz" ];then
  7016.     echo -e "Package ${magenta}${DIRNAME}.tar.gz${endcolour} created."
  7017.     echo "The md5sum is: `md5sum ${DIRNAME}.tar.gz | cut -f1 -d' '`."
  7018.   else
  7019.     echo "Package '${DIRNAME}.tar.gz' NOT created."
  7020.     return 1
  7021.   fi
  7022. }
  7023.  
  7024.  
  7025. pet2sfs(){                        # convert pet to sfs, $1 must be file or repo pkg FUNCLIST
  7026.  
  7027.   # require valid option or quit
  7028.   [ ! -f "$1" ] && print_usage pet2sfs && exit 1
  7029.  
  7030.   pkg_ext=`get_pkg_ext "$1"`
  7031.  
  7032.   [ "$pkg_ext" != pet ] && print_usage pet2sfs && exit 1
  7033.  
  7034.   #110213,0.9.1 we want the file in $WORKDIR
  7035.   #[ ! -f "${WORKDIR}/$(basename "$1" .pet).pet" ] && cp -f "${1/.pet/}.pet" "${WORKDIR}/$(basename "$1" .pet)" 2>/dev/null
  7036.  
  7037.   PKGNAME="$(basename "$1" .pet)" #get pkg name only, no extension or path
  7038.   PKGFILE="${CURDIR}/${PKGNAME}.pet" #the file to install
  7039.  
  7040.   # determine the compression, extend test to 'XZ'
  7041.   file -b "${PKGFILE}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  7042.   [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  7043.  
  7044.   pet2tgz "${PKGFILE}" 1>/dev/null
  7045.  
  7046.   # now extract the files into $CURDIR/$PKGNAME/
  7047.   tar $taropts "${PKGFILE//.pet/.tar.$TAREXT}" 2> $TMPDIR/$SELF-cp-errlog
  7048.  
  7049.   # if DISTRO_VERSION found, the sfs will prob have a suffix
  7050.   [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  7051.  
  7052.   # remove the old one, if needed
  7053.   rm "${PKGNAME}${SFS_SUFFIX}.sfs" 2>/dev/null
  7054.  
  7055.   # create the new one
  7056.   dir2sfs "${CURDIR}/${PKGNAME}" && rm -rf "${CURDIR}/${PKGNAME}"
  7057.  
  7058.   # remove the .tar.$TAREXT file
  7059.   rm -f "${PKGNAME}.tar.$TAREXT"
  7060.  
  7061.   # if pkg put the pet in $CURDIR (not user), remove it
  7062.   #[ -f "${PKGFILE}" -a "`dirname "$1"`" != "$CURDIR" ] && rm -f "${PKGFILE}" 2>/dev/null
  7063.  
  7064.   # print message
  7065.   if [ ! -f "${PKGNAME}.sfs" -a ! -f "${PKGNAME}${SFS_SUFFIX}.sfs" ];then
  7066.     echo "Package '${PKGNAME}.pet' not converted."
  7067.     return 1
  7068.   fi
  7069. }
  7070.  
  7071.  
  7072. pet2tgz(){                        # convert to tar.gz, $1 must be valid file FUNCLIST
  7073.  
  7074.   # if $1 is not a valid pkg name or a file that exists then exit..
  7075.   [ ! -f "$1" ] && print_usage pet2tgz && exit 1
  7076.  
  7077.   pkg_ext=`get_pkg_ext "$1"`
  7078.   [ "$pkg_ext" != "pet" ] && print_usage pet2tgz && exit 1
  7079.  
  7080.   PKGNAME="$(basename "$1" .pet)" # get pkg name only, no extension or path
  7081.   PKGFILE="$1"          # build the pkg file path
  7082.  
  7083.   # backup the package, to restore it later
  7084.   cp -f "$PKGFILE" "$TMPDIR/`basename $PKGFILE`.backup" 1>/dev/null
  7085.  
  7086.   chmod +w "$PKGFILE" # make it writable.
  7087.   FOOTERSIZE="32"
  7088.  
  7089.   # determine the compression, extend test to 'XZ'
  7090.   finfo=`file -b "$PKGFILE"`
  7091.   case $finfo in
  7092.     gz*|GZ*) EXT=gz ;;
  7093.     xz*|XZ*) EXT=xz ;;
  7094.     *) error "Unsupported compression type, or corrupted package." && exit 1 ;;
  7095.   esac
  7096.  
  7097.   # get the md5
  7098.   MD5SUM="`tail -c $FOOTERSIZE \"$PKGFILE\"`"
  7099.   NEWNAME="`echo -n \"$PKGFILE\" | sed -e "s/\\.pet$/\\.tar\\.$EXT/g"`" #131122
  7100.   head -c -$FOOTERSIZE "$PKGFILE" > $NEWNAME
  7101.   NEWMD5SUM="`md5sum \"$NEWNAME\" | cut -f 1 -d ' '`"
  7102.   sync
  7103.   [ ! "$MD5SUM" = "$NEWMD5SUM" ] && exit 1
  7104.  
  7105.   # restore original pet pkg
  7106.   [ -f "$TMPDIR/`basename $PKGFILE`.backup" ] && mv -f "$TMPDIR/`basename $PKGFILE`.backup" "$PKGFILE"
  7107.  
  7108.   # print message
  7109.   if [ -f "$NEWNAME" ];then
  7110.     echo -e "${green}Success${endcolour}: Package ${magenta}`basename ${NEWNAME}`${endcolour} created."
  7111.     echo "The md5sum is `md5sum "$NEWNAME" | cut -f1 -d' '`."
  7112.   else
  7113.     error "Package ${PKGNAME}.pet not converted!"
  7114.     return 1
  7115.   fi
  7116. }
  7117.  
  7118.  
  7119. pet2txz(){                        # calls pet2tgz FUNCLIST
  7120.   pet2tgz "$1"
  7121. }
  7122.  
  7123.  
  7124. sfs2pet(){                        # convert sfs to pet, requires $1 as a valid sfs FUNCLIST
  7125.  
  7126.   # exit if no valid options
  7127.   [ ! -f "$1" ] && print_usage sfs2pet && exit 1
  7128.  
  7129.   # exit if user did not give an SFS file, or didnt give a file at all
  7130.   [ "`file "$1" | grep  Squashfs`" = '' ] && print_usage sfs2pet && exit 1
  7131.  
  7132.   # we want the file in $CURDIR
  7133.   #[ ! -f "${WORKDIR}/$(basename "${1}")" ] && cp -f "$1" "${WORKDIR}/$(basename "${1}")" 2>/dev/null
  7134.  
  7135.   SFSNAME="$(basename "$1")"
  7136.   SFSDIR="$(dirname "$1")"
  7137.   SFSEXT="${SFSNAME##*.}"
  7138.  
  7139.   # if DISTRO_VERSION found, the sfs will prob have a suffix
  7140.   [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  7141.  
  7142.   # create the name without path or extension (may include a $SUFFIX)
  7143.   ROOTNAME=`basename "$SFSNAME" ".$SFSEXT"`
  7144.  
  7145.   # build the file name we will work on
  7146.   SFS="${SFSDIR}/${SFSNAME}"
  7147.  
  7148.   if [ -f "$SFS" -a "$SFS" != "" ];then
  7149.  
  7150.     echo "Unsquashing $SFSNAME.. Please wait.."
  7151.  
  7152.     # remove any older dirs, and unsquash
  7153.     rm -rf "${CURDIR}/squashfs-root/"
  7154.     LANG=C unsquashfs "$SFS"  &>/dev/null
  7155.  
  7156.     # lets remove the SFS suffix, to get back the the 'valid' PET name
  7157.     ROOTNAME_NOSUFFIX=`echo "$ROOTNAME" | sed -e "s/$SFS_SUFFIX//"`
  7158.  
  7159.     # create the folder we will package up
  7160.     mv squashfs-root "${ROOTNAME_NOSUFFIX}/"
  7161.  
  7162.     dir2tgz "${ROOTNAME_NOSUFFIX}" 1>/dev/null
  7163.  
  7164.     tgz2pet "${ROOTNAME_NOSUFFIX}".tar.gz 1>/dev/null
  7165.  
  7166.     # remove the dir and the tgz we just created
  7167.     rm -rf "${ROOTNAME_NOSUFFIX}"
  7168.     rm -f "${ROOTNAME_NOSUFFIX}".tar.gz
  7169.  
  7170.     if [ -f "${ROOTNAME_NOSUFFIX}.pet" ];then
  7171.       echo -e "${green}Success${endcolour}: Package '${magenta}${ROOTNAME_NOSUFFIX}.pet${endcolour}' created."
  7172.       echo "The md5sum is: `md5sum ${ROOTNAME_NOSUFFIX}.pet | cut -f1 -d' '`"
  7173.     else
  7174.       echo "Package '${ROOTNAME_NOSUFFIX}.pet' not converted."
  7175.       return 1
  7176.     fi
  7177.   fi
  7178. }
  7179.  
  7180.  
  7181. tgz2pet(){                        # convert $1 (a tar.gz or tgz) to .pet FUNCLIST
  7182.  
  7183.   [ ! -f "$1" ] && print_usage tgz2pet && exit 1
  7184.   sync
  7185.   TARBALL="$1"
  7186.   [ ! -f "$TARBALL" ] && echo "The archive '$TARBALL' could not be found." && exit 1
  7187.  
  7188.   cp -f $TARBALL "$TMPDIR/`basename $TARBALL`.backup" 1>/dev/null
  7189.  
  7190.   TARBALL="${CURDIR}/$(basename "${TARBALL}")"
  7191.   chmod 644 "$TARBALL" #make it writable.
  7192.   echo "Converting `basename ${TARBALL}`.."
  7193.  
  7194.   #only accept .tgz or .tar.gz .tar.xz files...
  7195.   EXT=''
  7196.   case ${TARBALL} in
  7197.     *.tar.gz) EXT='.tar.gz' ;;
  7198.     *.tgz)    EXT='.tgz' ;;
  7199.     *.tar.xz) EXT='.tar.xz' ;;
  7200.     *.txz)    EXT='.txz' ;;
  7201.     *) echo "${1##*/}: File extension not allowed" >&2 ; exit 1 ;;
  7202.   esac
  7203.   [ "$EXT" = "" ] && error "$TARBALL must be a .tgz, .tar.gz, .txz or .tar.xz file" && exit 1
  7204.  
  7205.   #split TARBALL path/filename into components...
  7206.   BASEPKG="`basename $TARBALL $EXT`"
  7207.   DIRPKG="$CURDIR"
  7208.   [ "$DIRPKG" = "/" ] && DIRPKG=""
  7209.   case $EXT in
  7210.   *gz)OPT=-z;;
  7211.   *xz)OPT=-J;;
  7212.   esac
  7213.  
  7214.   # move pkg, update extensions (tgz -> .tar.gz, txz -> .tar.xz)
  7215.   # make code later more readable
  7216.   case $EXT in
  7217.   *tgz)mv -f $TARBALL $DIRPKG/${BASEPKG}.tar.gz
  7218.    TARBALL="$DIRPKG/${BASEPKG}.tar.gz"
  7219.    EXT='.tar.gz';;
  7220.   *txz)mv -f $TARBALL $DIRPKG/${BASEPKG}.tar.xz
  7221.    TARBALL="$DIRPKG/${BASEPKG}.tar.xz"
  7222.    EXT='.tar.xz';;
  7223.   esac
  7224.  
  7225.   # if tarball expands direct to '/' want to wrap around it (slackware pkg)... 100628 add -z ...
  7226.   # man bad bug here... the thing isn't expanded! #131122
  7227.   if [ "`tar ${OPT} --list -f ${TARBALL} | head -n 1`" = "./" ];then
  7228.     tar --one-top-level=${BASEPKG} -xf ${TARBALL}
  7229.     tar --remove-files -c -f ${DIRPKG}/${BASEPKG}.tar ${BASEPKG}/
  7230.     case $EXT in
  7231.     *gz) gzip --force --best ${DIRPKG}/${BASEPKG}.tar ;;
  7232.     *xz) xz --force -z -9 -e ${DIRPKG}/${BASEPKG}.tar ;;
  7233.     esac
  7234.   fi
  7235.  
  7236.   FULLSIZE="`stat --format=%s ${TARBALL}`"
  7237.   MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  7238.   echo -n "$MD5SUM" >> $TARBALL
  7239.   sync
  7240.   mv -f $TARBALL $DIRPKG/${BASEPKG}.pet
  7241.   sync
  7242.  
  7243.   # restore original tar file
  7244.   [ -f "$TMPDIR/`basename $TARBALL`.backup" ] && mv -f "$TMPDIR/`basename $TARBALL`.backup" "$TARBALL"
  7245.  
  7246.   # print msg
  7247.   if [ -f "${DIRPKG}/${BASEPKG}.pet" ];then
  7248.     echo -e "${green}Success:${endcolour} Created ${magenta}${BASEPKG}.pet${endcolour}."
  7249.     echo "This is the md5sum: `md5sum ${DIRPKG}/${BASEPKG}.pet | cut -f1 -d' '`"
  7250.   else
  7251.     error "Could not convert ${DIRPKG}/${BASEPKG}.$EXT"
  7252.     return 1
  7253.   fi
  7254. }
  7255.  
  7256.  
  7257. txz2pet(){                        # convert txz to pet, requires $1 as valid file FUNCLIST
  7258.   [ ! -f "$1" ] && print_usage txz2pet && exit 1
  7259.   FILE="$1"   # full path, filename and extension
  7260.   #keep old file, download it if needed
  7261.   #[ -f "$(basename "$1" .txz)" ] || pkg_download "$(basename "$1" .txz)" #  200813 try to download it
  7262.   # we want $FILE in $CURDIR
  7263.   [ ! -f "${CURDIR}/$(basename "${FILE}")" ] && cp -f "$FILE" "${CURDIR}/$(basename "${FILE}")" 2>/dev/null
  7264.   FILE="${CURDIR}/$(basename "${FILE}")"
  7265.   #set vars
  7266.   FILENAME="`basename "$FILE"`" # filename and extension only
  7267.   BARENAME="${FILENAME/.t*xz/}" # filename, no extension..
  7268.   PETFILE="${CURDIR}/${BARENAME}.pet" # the full path and filename of the pet file
  7269.   PETNAME="`basename "$PETFILE"`" # the filename of the pet file
  7270.   # create the pet directory, if needed
  7271.   mkdir -p "${CURDIR}/${BARENAME}"
  7272.   [ ! -d "${CURDIR}/${BARENAME}" ] && { echo "PET directory not created or found."; exit 1; }
  7273.   # unpack the file
  7274.   [ -f "$FILENAME" ] && tar -Jxvf "$FILENAME" -C "${BARENAME}/" 1>/dev/null || echo "Cannot untar $FILENAME"
  7275.   # create the pet file
  7276.   dir2pet "$BARENAME" || echo "PET working directory not found"
  7277.  
  7278.   if [ -f "$PETFILE" ];then # if pet file was created
  7279.     # remove the pet file working directory
  7280.     rm -R "${CURDIR}/${BARENAME}/" 2>/dev/null
  7281.     rmdir "${CURDIR}/${BARENAME}/" 2>/dev/null
  7282.     # report the file was created #nope, no need, dir2pet will do it
  7283.     #echo "Package '$PETNAME' created successfully."
  7284.   else
  7285.     echo "Package "$PETFILE" file not created"
  7286.     return 1
  7287.   fi
  7288.   # delete the original txz file
  7289.   rm -f "$FILE" &>/dev/null
  7290. }
  7291.  
  7292.  
  7293. # other
  7294.  
  7295. menu_entry_msg(){                 # show menu entry details of installed pkg FUNCLIST
  7296.  
  7297.   # exit if not valid usage
  7298.   [ ! "$1" -o "$1" = "-" ] && exit 1
  7299.  
  7300.   . ${PKGRC}
  7301.  
  7302.   local MENUFILE=''
  7303.   local pkg_file_list=''
  7304.   local no_display=''
  7305.   local terminal_only=''
  7306.   local pkg_command=''
  7307.  
  7308.   # get the menu file, if it exists
  7309.   pkg_file_list=$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${1}*.files")
  7310.  
  7311.   [ -f "$pkg_file_list" ] && MENUFILE="`LANG=C grep -m1 '/usr/share/applications/' "$pkg_file_list" | grep -i -m1 ".desktop\$"`" || return 1
  7312.  
  7313.   # if pkg has a .desktop file
  7314.    if [ -f "$MENUFILE" ];then
  7315.  
  7316.     # exit if the menu item is set to NoDisplay
  7317.     no_display="`grep -m1 ^NoDisplay=true "$MENUFILE" 2>/dev/null`"
  7318.     terminal_only="`grep -m1 ^Terminal=true "$MENUFILE" 2>/dev/null`"
  7319.  
  7320.     # fix menu entries
  7321.     sed -i 's/ %u//g' "$MENUFILE"
  7322.     sed -i 's/ %U//g' "$MENUFILE"
  7323.     sed -i 's/ %f//g' "$MENUFILE"
  7324.     sed -i 's/ %F//g' "$MENUFILE"
  7325.     sed -i 's/ %d//g' "$MENUFILE"
  7326.     sed -i 's/ %D//g' "$MENUFILE"
  7327.  
  7328.     update_menus &
  7329.  
  7330.     # get the details for a final msg
  7331.     MENU_CAT="`LANG=C grep -m1 "^Categories=" $MENUFILE 2>/dev/null | cut -f2 -d'=' | sed -e 's/\(.*\);/\1/g' -e 's/.*;//g' | head -1`"
  7332.     APATTERN="[ ,]${MENU_CAT}" #MHHP
  7333.     TOPMENU="`LANG=C grep -m1 "${APATTERN}" /etc/xdg/menus/hierarchy | cut -f1 -d' ' | head -1`"
  7334.     if [ "$TOPMENU" = "" ];then
  7335.       APATTERN="[ ,]${MENU_CAT};"
  7336.       TOPMENU="`LANG=C grep -m1 "${APATTERN}" /etc/xdg/menus/hierarchy | cut -f1 -d' ' | head -1`"
  7337.     fi
  7338.     MENU_NAME="`LANG=C grep -m1 "^Name=" $MENUFILE | cut -f2 -d'=' | head -1`"
  7339.  
  7340.     [ "$TOPMENU" = '' ] && TOPMENU="$MENU_CAT"
  7341.  
  7342.     # replace the Categories= line with one which has only the top, main category..
  7343.     # .. this should prevent duplicate menu entries
  7344.     #cat "$MENUFILE" | grep -v ^Categories > ${TMPDIR}fixed.desktop
  7345.     #echo "Categories=${TOPMENU};" >> ${TMPDIR}fixed.desktop
  7346.     #mv ${TMPDIR}fixed.desktop $MENUFILE
  7347.  
  7348.     # print msg
  7349.     if [ "$no_display" != "" -o "$terminal_only" != '' ];then
  7350.       pkg_command="`grep -m1 ^Exec= "$MENUFILE" | cut -f2 -d'='`"
  7351.       [ "$pkg_command" != '' ] && echo -e "To run, type:  ${bold}${pkg_command}${endcolour}"
  7352.     else
  7353.       echo -e "Menu entry:     ${lightblue}${TOPMENU:-[None]}${endcolour} -> ${lightblue}${MENU_NAME:-[None]}${endcolour}"
  7354.     fi
  7355.  
  7356.     return 0
  7357.   fi
  7358.   return 1
  7359. }
  7360.  
  7361.  
  7362. update_menus() {                  # update menus, calls fixmenus, refreshes WM
  7363.   echo started > /tmp/pkg/update_menus_busy
  7364.   fixmenus &>/dev/null
  7365.   # refresh JWM menus if using JWM window manager
  7366.   [ "`which jwm`" != "" -a "`ps -e | grep jwm`" != "" ] && jwm -reload &>/dev/null
  7367.   rm /tmp/pkg/update_menus_busy 2>/dev/null
  7368.   return 0
  7369. }
  7370.  
  7371.  
  7372. check_net(){                      # check net connection (before downloading) FUNCLIST
  7373.   [ -f $TMPDIR/internetsuccess ] && echo 0 && exit 0 #220613
  7374.   [ ! "$1" -o "$1" = "-" ] && URL="8.8.8.8" || URL="`echo  ${1} | awk -F/ '{print $3}'`"
  7375.   LANG=C ping -4 -c1 -q "$URL" &>/dev/null #220613
  7376.   REPLY=$?
  7377.   [ $REPLY -eq 0 ] && echo -n "ok" > $TMPDIR/internetsuccess #220613
  7378.   echo 0
  7379. }
  7380.  
  7381.  
  7382. get_stdin(){                      # read from stdin (when - is last option) FUNCLIST
  7383.   read -t 0.1 STDINVAR
  7384. }
  7385.  
  7386.  
  7387. not_found(){                      # list alternative packages when no match in repos FUNCLIST
  7388.   PKGNAME="${1/.pet/}"
  7389.   #echo "$APPTITLE"
  7390.   #echo "Package '${PKGNAME}' not found in current repo..  "
  7391.   if [ "$(ls "${WORKDIR}/"| grep "${PKGNAME}")" != "" ];then
  7392.     [ "`list_downloaded_pkgs "${PKGNAME}"`" != "" ] && echo "These downloaded packages match your search:
  7393. `list_downloaded_pkgs "${PKGNAME}"`"
  7394.   fi
  7395.     [ "`$PKGSEARCH "${PKGNAME}"`" != "" ] && echo "These packages in the repos match your search:
  7396. `$PKGSEARCH "${PKGNAME}"`"
  7397.   return 1
  7398. }
  7399.  
  7400.  
  7401. first_run (){                     # welome message on first run
  7402.  
  7403.   # quit if not the first run
  7404.   [ ! -f ~/.pkg/firstrun ] && return 0
  7405.   # print msg
  7406.   echo '============================================================'
  7407.   echo -e "  ${bold}$APPNAME $APPVER${endcolour} - a command-line package manager"
  7408.   echo '============================================================'
  7409.   echo
  7410.   echo "  pkg repo-update      # update the contents of each installed repo"
  7411.   echo "  pkg repo-list        # list all available repos"
  7412.   echo "  pkg repo <name>      # change to the chosen repo"
  7413.   echo "  pkg show-config      # show current Pkg settings"
  7414.   echo "  pkg workdir <DIR>    # change where to keep downloaded packages"
  7415.   echo
  7416.   echo "  pkg search <term>    # search all fields in the current repo"
  7417.   echo "  pkg names <pkgname>  # search package names in the current repo"
  7418.   echo "  pkg status <pkgname> # print info about the given package"
  7419.   echo "  pkg add <pkgname>    # install & download packages and dependencies"
  7420.   echo
  7421.   echo " You can run the commands below to learn more about Pkg:"
  7422.   echo
  7423.   echo "  pkg help             # help info, all options and some tips"
  7424.   echo "  pkg help-all         # full help info, including advanced usage"
  7425.   echo "  pkg usage [cmd]      # show every command, or info on the given one"
  7426.   echo "  pkg examples         # show lots more example Pkg commands"
  7427.   echo
  7428.   echo " HINT: Use TAB to auto-complete package and repo names (and more).."
  7429.   echo
  7430.   echo '============================================================'
  7431.  
  7432.   # get the right list of repos
  7433.   update_sources &>/dev/null &
  7434.  
  7435.   # delete first run flag
  7436.   rm -f ~/.pkg/firstrun 2>/dev/null
  7437.  
  7438.   # delete other tmp stuff, make it like a first run
  7439.   rm $TMPDIR/func_list        &>/dev/null
  7440.   rm $TMPDIR/curr_repo_url    &>/dev/null
  7441.   rm $TMPDIR/internetsuccess  &>/dev/null
  7442.   rm $TMPDIR/pkg_aliases      &>/dev/null
  7443.   rm $TMPDIR/pkglist          &>/dev/null
  7444.   rm $TMPDIR/pkglist_*        &>/dev/null
  7445.   rm $TMPDIR/USRPKGLIST       &>/dev/null
  7446.   rm $TMPDIR/PKGSDONE         &>/dev/null
  7447.   rm $TMPDIR/deps_installed   &>/dev/null
  7448.   rm $TMPDIR/deps_missing     &>/dev/null
  7449.   rm $TMPDIR/$SELF-cp-errlog  &>/dev/null
  7450.   rm $TMPDIR/*-MISSING.txt    &>/dev/null
  7451.  
  7452.   exit 0
  7453. }
  7454.  
  7455.  
  7456. #====================  main functions  ======================#
  7457.  
  7458.  
  7459.  
  7460. #=====================  final checks  =======================#
  7461.  
  7462. # try to set a default repo if none was found
  7463. if [ ! -f "$REPO_DB_FILE_DIR/$REPOFILE" -o ! -f "$HOME/.pkg/sources" ];then
  7464.  
  7465.   mkdir -p $HOME/.pkg 2>/dev/null
  7466.   mkdir -p $PKGS_DIR 2>/dev/null
  7467.   [ ! -f "$HOME/.pkg/sources" ] && touch $HOME/.pkg/sources
  7468.   # try to get repo file from /root if it exists
  7469.   if [ -f "$REPO_DB_FILE_DIR/Packages-puppy-noarch-official" ];then
  7470.     # copy any available Puppy repo files in root to $PKGS_DIR
  7471.     mv "$REPO_DB_FILE_DIR"/Packages-puppy-* $REPO_DB_FILE_DIR/
  7472.   fi
  7473.  
  7474.   ## if repo file was NOT added to home dir, fata error, exit
  7475.   #if [ ! -f $PKGS_DIR/Packages-puppy-noarch-official ];then
  7476.   #  error "Repo files not found. Check ${magenta}$PKGS_DIR${endcolour}"
  7477.   #  exit 1
  7478.   #fi
  7479.  
  7480.   # if we got here, the noarch repo file is in $PKGS_DIR, lets use it as the default/only repo
  7481.   echo -e "${yellow}Warning:${endcolour} No repo files found. Setting the default repo to 'noarch'."
  7482.   update_sources 1>/dev/null
  7483.   set_current_repo noarch 1>/dev/null
  7484.   # if repos added ok
  7485.   if [ $? -eq 0 ];then
  7486.     echo -e "${green}Success:${endcolour} 'noarch' added."
  7487.     echo "Re-running: $SELF $@"
  7488.     echo
  7489.     $SELF $@
  7490.     exit 0
  7491.   fi
  7492.  
  7493. fi
  7494.  
  7495. # create the user-installed pkgs file if it doesnt exists
  7496. [ ! -f $PKGS_DIR/user-installed-packages ] && touch $PKGS_DIR/user-installed-packages
  7497.  
  7498. first_run
  7499.  
  7500.  
  7501. #=====================  final checks  =======================#
  7502.  
  7503.  
  7504.  
  7505. #====================  main interface  ======================#
  7506.  
  7507.  
  7508. while [ $# != 0 ]; do # get all options ($# means all options)
  7509.    I=1
  7510.    while [ ! -z $# -a $I -le `echo $# | wc -c` ]; do
  7511.  
  7512.     # accept from stdin, (using dash (-) as final option)
  7513.     for x in "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
  7514.     do
  7515.       case "$x" in
  7516.         -)
  7517.           while true; do
  7518.             read ALINE
  7519.             [ "$ALINE" ] || break
  7520.             [ "$(echo $ALINE| cut -b1)" = '#' ] && continue # skip comment
  7521.             [ "$ALINE" = ':' ] && continue  # skip colon
  7522.             if [ "$ALINE" = "- " -o "$ALINE" = " -" -o "$ALINE" != "-" ];then
  7523.               OPTS="${@%-}" #get all opts, without last dash
  7524.               OPTS="${OPTS% }" #get all opts, strip last space
  7525.               $SELF $OPTS "$ALINE"
  7526.             fi
  7527.           done
  7528.           break
  7529.         ;;
  7530.         --ask|-a)         ASK=true ; QTAG="?  (y/N)";;
  7531.         --quiet|-q)       QUIET=true ;;
  7532.         --force|-f)       FORCE=true ;;
  7533.         --no-color)       green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7534.         --no-colour|-nc)  green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7535.         '--configure='*)  PKG_CONFIGURE="$(echo "$x" | sed -e 's/^--configure=//')" ;;
  7536.         '--cflags='*)     PKG_CFLAGS="$(echo "$x" | sed -e 's/^--cflags=//')"       ;;
  7537.       esac
  7538.     done
  7539.  
  7540.     # enable passing multiple pkgs separated by comma, space,
  7541.     # works with or without double quotes around pkgs
  7542.     opt="`shift; echo "$@"`"
  7543.     opt="${opt//,/ }"
  7544.     opt="${opt//|/ }"
  7545.     # only keep params up to the next option
  7546.     opt="${opt// -*/}"
  7547.  
  7548.     ## main options
  7549.     case $1 in
  7550.  
  7551.       -) # accept from stdin, pkg -i (defaults to pkg add $1 or pkg -u $1)
  7552.         if [ "$2" = "" ];then
  7553.           while true; do
  7554.             read ALINE
  7555.             [ "$ALINE" -a "$ALINE" != '-' ] || break
  7556.             [ "$(echo $ALINE| cut -b1)" = '#' ] && continue # skip comment
  7557.             ALINE=`echo $ALINE` #strip spaces
  7558.             if [ "$ALINE" != "-" -a "`$PKGSEARCH "$ALINE"`" != "" ];then
  7559.               [ "`is_installed_pkg $ALINE`" = false ] && pkg_get "$ALINE" || \
  7560.               pkg_uninstall "$ALINE"
  7561.             fi
  7562.           done
  7563.           shift
  7564.         fi
  7565.       ;;
  7566.  
  7567.       --ask|-a)         ASK=true ; QTAG="?  (y/N)";;
  7568.       --quiet|-q)       QUIET=true ;;
  7569.       --force|-f)       FORCE=true ;;
  7570.       --no-color)       green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7571.       --no-colour|-nc)  green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7572.       '--configure='*)  PKG_CONFIGURE="$(echo "$1" | sed -e 's/^--configure=//')" ;;
  7573.       '--cflags='*)     PKG_CFLAGS="$(echo "$1" | sed -e 's/^--cflags=//')"       ;;
  7574.  
  7575.       # package search
  7576.       --all-pkgs|--all)                 [ ! "$2" ] && cat "$REPO_DB_FILE_DIR/${REPOFILE}" || cat "$REPO_DB_FILE_DIR/${REPOFILE}" | grep "$2"; exit 0;;
  7577.       --search|-s|search|s)             [ ! "$2" ] && search_pkgs          || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_pkgs "$x";          done; ;;
  7578.       -ss)                              [ ! "$2" ] && search_fast          || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_fast "$x";          done; ;;
  7579.       --search-all|-sa|search-all|sa)   [ ! "$2" ] && search_all_pkgs      || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_all_pkgs "$x";      done; ;;
  7580.       -ssa|ssa)                         [ ! "$2" ] && search_all_fast      || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_all_fast "$x";      done; ;;
  7581.       --names|-n|names|n)               [ ! "$2" ] && list_pkg_names       || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_pkg_names "$x";         done; ;;
  7582.       --names-exact|-ne|names-exact|ne) [ ! "$2" ] && list_pkg_names       || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_pkg_names "$x\$";       done; ;;
  7583.       --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; ;;
  7584. --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 ;;
  7585. --list-downloaded|list-downloaded|-ld|ld) [ ! "$2" ] && list_downloaded_pkgs || list_downloaded_pkgs "$2"; exit 0 ;;
  7586.       -LI|LI)                           [ ! "$2" ] && HIDE_BUILTINS=false list_installed_pkgs || HIDE_BUILTINS=false list_installed_pkgs "$2"; exit 0 ;; # list all installed pkgs inc builtins
  7587.   --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 ;;
  7588.  
  7589.       # get, download, install, remove, pkgs
  7590.       --download|-d|download|d)         [ ! "$2" ] && pkg_download || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_download "$x";  done;;
  7591.       --install|-i|install|i)           [ ! "$2" ] && pkg_install  || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_install "$x";   done;;
  7592.       --uninstall|-u|uninstall|u)       [ ! "$2" ] && pkg_uninstall|| for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_uninstall "$x"; done;;
  7593.       --remove|-rm|remove|rm)           [ ! "$2" ] && pkg_remove   || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_remove "$x";    done;;
  7594.       --unpack|--extract|unpack|extract)[ ! "$2" ] && pkg_unpack   || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_unpack "$x";    done;;
  7595.       --clean|clean)                    [ ! "$2" ] && clean_pkgs   || for x in $opt; do [ "$x" -a "$x" != "-" ] && clean_pkgs "$x";    done;;
  7596.       --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 ;;
  7597.       --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 ;;
  7598.       --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
  7599.       --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;;
  7600.       --install-all|-ia)                list_downloaded_pkgs | while read pkg; do [ "$pkg" -a "$pkg" != "-" ] && pkg_install "$pkg";   done;;
  7601.       --uninstall-all|-ua)              list_installed_pkgs  | while read pkg; do [ "$pkg" -a "$pkg" != "-" ] && pkg_uninstall "$pkg"; done;;
  7602.  
  7603.       # pkg status, info
  7604.       --pkg-installed|-pi|installed|pi)   [ ! "$2" ] && is_installed_pkg || for x in $opt; do [ "$x" -a "$x" != "-" ] && is_installed_pkg "$x"; done;;
  7605.       --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
  7606.       --pkg-status|-ps|status|ps)         [ ! "$2" ] && pkg_status  || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_status "$x";   done;;
  7607.       --contents|-c|contents|c)           [ ! "$2" ] && pkg_contents|| for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_contents "$x" 2>/dev/null; done;;
  7608.       --which|-w|which|w)                 [ ! "$2" ] && which_pkg   || for x in $opt; do [ "$x" -a "$x" != "-" ] && which_pkg "$x";    done;;
  7609.       --which-repo|-wr|which-repo|wr)     [ ! "$2" ] && which_repo  || for x in $opt; do [ "$x" -a "$x" != "-" ] && which_repo "$x";   done;;
  7610.       --pkg-repack|-pr|repack|pr)         [ ! "$2" ] && pkg_repack  || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_repack "$x";   done;;
  7611.       --pkg-update|-pu|update|pu)         [ ! "$2" ] && pkg_update  || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_update "$x";   done;;
  7612.       --pkg-combine|-pc|pkg-combine|pc)   [ ! "$2" ] && pkg_combine || for x in $opt; do [ "$x" -a "$x" != "-" ] && COMBINE2SFS=false pkg_combine "$x"; done;;
  7613.       --pkg-split|split)                  [ ! "$2" ] && split_pkg   || for x in $opt; do [ "$x" -a "$x" != "-" ] && split_pkg "$x"; done;;
  7614.       --pkg-merge|merge)                  [ ! "$2" ] && merge_pkg   || merge_pkg "$2" "$3"; exit 0;;
  7615.       --sfs-combine|-sc|sfs-combine|sc)   [ ! "$2" ] && pkg_combine || for x in $opt; do [ "$x" -a "$x" != "-" ] && COMBINE2SFS=true  pkg_combine "$x"; done;;
  7616.       -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
  7617.  
  7618.       # pkg compiling
  7619.       --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;;
  7620.    --pkg-build-list|-pbl|build-list|pbl)  [ ! "$2" ] && list_build_scripts || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_build_scripts "$x"; done;;
  7621.  
  7622.       # dependencies
  7623.       --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
  7624.       --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
  7625.       --deps|-e|deps|e)                   [ ! "$2" ] && get_deps;  for x in $opt; do [ "$x" -a "$x" != "-" ] && get_deps  "$x";                done ;;
  7626.     --deps-download|-ed|deps-download|ed) [ ! "$2" ] && get_deps;  for x in $opt; do [ "$x" -a "$x" != "-" ] && NO_INSTALL=true get_deps "$x"; done ;;
  7627.       --has-deps|-he|has-deps|he)         [ ! "$2" ] && has_deps;  for x in $opt; do [ "$x" -a "$x" != "-" ] && has_deps  "$x";                done ;;
  7628.       --deps-all|-ea|deps-all|ea)         [ ! "$2" ] && get_deps;  [ "$2" != "-" ] && NO_INSTALL=false get_all_deps "$2" ;;
  7629.       --deps-check|-ec|deps-check|ec|ldd) [ ! "$2" ] && print_usage deps-check || pkg_ldd_msg "$2" ;;
  7630.       -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
  7631.  
  7632.       # repo
  7633.       --repo|-r|repo|r)                     [ ! "$2" ] && echo $REPONAME || set_current_repo "$2" ;;
  7634.       --repo-convert|-rc|repo-convert|rc)   [ ! "$2" ] && print_usage repo-convert || for x in $opt; do [ "$x" -a "$x" != "-" ]  && convert_repofile "$x"; done ;;
  7635.       --repo-list|-rl|repo-list|rl)         [ "$2" != "-" ] && repo_list "$2"      ;;
  7636.       --repo-info|-ri|repo-info|ri)         [ "$2" != "-" ] && print_repo_info "$2";;
  7637.   --repo-file-list|-rfl|repo-file-list|rfl) [ "$2" != "-" ] && repo_file_list "$2" ;;
  7638.       --repo-update|-ru|repo-update|ru)     update_repo "$2";;
  7639.       --add-source|add-source)              [ "`echo $2|grep '|'`" = '' -o "$2" = '-' ] && print_usage add-source || add_source "$2";;
  7640.       --add-repo|add-repo)                  [ ! "$2" -o "$2" = '-'  ] && print_usage add-repo || shift; add_repo "$@"; exit 0;;
  7641.       --rm-repo|rm-repo)                    [ ! "$2" -o "$2" = '-'  ] && print_usage rm-repo  || rm_repo "$2"; exit 0;;
  7642.       --update-sources|update-sources)      update_sources ;;
  7643.  
  7644.       # set repo settings
  7645.       --repo-pkg-scope|-rps|rps|repo-pkg-scope)  if [ "$2" -a "$2" != "-" ];then set_pkg_scope "$2";      else echo "$PKGSCOPE"; fi; exit 0;;
  7646.       --repo-dep-scope|-rds|repo-dep-scope|rds)  if [ "$2" -a "$2" != "-" ];then set_dep_scope "$2";      else echo "$DEPSCOPE"; fi; exit 0;;
  7647.       --bleeding-edge|-be|bleeding-edge|be)      if [ "$2" -a "$2" != "-" ];then set_bleeding_edge "$2";  else echo "$BLEDGE";   fi; exit 0;;
  7648.       --rdep-check|-rdc|rdep-check|rdc)          if [ "$2" -a "$2" != "-" ];then set_recursive_deps "$2"; else echo "$RDCHECK";  fi; exit 0;;
  7649.  
  7650.       # convert
  7651.       --deb2pet|deb2pet) [ ! "$2" ] && deb2pet || for x in $opt; do deb2pet "$x"; done ;;
  7652.       --dir2pet|dir2pet) [ ! "$2" ] && dir2pet || for x in $opt; do dir2pet "$x"; done ;;
  7653.       --dir2sfs|dir2sfs) [ ! "$2" ] && dir2sfs || for x in $opt; do dir2sfs "$x"; done ;;
  7654.       --dir2tgz|dir2tgz) [ ! "$2" ] && dir2tgz || for x in $opt; do dir2tgz "$x"; done ;;
  7655.       --pet2sfs|pet2sfs) [ ! "$2" ] && pet2sfs || for x in $opt; do pet2sfs "$x"; done ;;
  7656.       --pet2tgz|pet2tgz) [ ! "$2" ] && pet2tgz || for x in $opt; do pet2tgz "$x"; done ;;
  7657.       --pet2txz|pet2txz) [ ! "$2" ] && pet2txz || for x in $opt; do pet2txz "$x"; done ;;
  7658.       --sfs2pet|sfs2pet) [ ! "$2" ] && sfs2pet || for x in $opt; do sfs2pet "$x"; done ;;
  7659.       --tgz2pet|tgz2pet) [ ! "$2" ] && tgz2pet || for x in $opt; do tgz2pet "$x"; done ;;
  7660.       --txz2pet|txz2pet) [ ! "$2" ] && txz2pet || for x in $opt; do txz2pet "$x"; done ;;
  7661.     --dir2repo|dir2repo) [ ! "$2" ] && dir2repo|| for x in $opt; do dir2repo "$x"; done ;;
  7662.  
  7663.       # other
  7664.       --func-list|func-list)  [ -f $TMPDIR/func_list ] && cat $TMPDIR/func_list || func_list; exit 0;;
  7665.       --workdir|workdir)      [ "$2" != "-" ] && set_workdir "$2"; exit $?;;
  7666.       --autoclean|autoclean)  [ "$2" = "yes" -o "$2" = "no" ] && set_autoclean "$2" || { echo "$AUTOCLEAN"; exit 1; } ;;
  7667.  
  7668.       # usage, help funcs, version info, etc
  7669.       --welcome|welcome)          touch $HOME/.pkg/firstrun; first_run; exit 0;;
  7670.       --show-config|show-config)  show_config; exit 0;;
  7671.       --version|-v|version|v)     echo "$APPNAME $APPVER"; exit 0;;
  7672.       --usage|usage)              print_usage "$2"; exit 0;;
  7673.  
  7674.       --examples|-ex|examples|ex)
  7675.         . /usr/share/pkg/docs/examples.txt;
  7676.         echo -e "$EXAMPLES\n"
  7677.         exit 0
  7678.         ;;
  7679.       --help-all|-H|help-all|H)
  7680.           . /usr/share/pkg/docs/env_vars.txt
  7681.           . /usr/share/pkg/docs/help.txt
  7682.           . /usr/share/pkg/docs/examples.txt
  7683.           . /usr/share/pkg/docs/help-all.txt
  7684.           echo -e "$HELP_ALL\n\n" | less -R
  7685.           exit 0
  7686.           ;;
  7687.  
  7688.       --help|-h|help|h)
  7689.           . /usr/share/pkg/docs/env_vars.txt
  7690.           . /usr/share/pkg/docs/help.txt
  7691.           echo -e "$HELP\n"
  7692.           exit 0
  7693.           ;;
  7694.  
  7695.       # any other options
  7696.       -?*|--?*)
  7697.           # exit if bad options
  7698.           echo "Unknown option '$1'" && exit 1
  7699.         ;;
  7700.  
  7701.       ?*)
  7702.           # all other options .. might be an internal func, if so, execute it with all given options
  7703.           [ "`func_list | tr '\t' ' ' | cut -f2 -d' ' | grep -m1 "^${1}"'()'`" != '' ] && "$@" && exit 0
  7704.         ;;
  7705.  
  7706.       esac
  7707.  
  7708.       shift
  7709.       I=$(($I + 1))
  7710.     done
  7711. done
  7712.  
  7713.  
  7714.  
  7715. #====================  main interface  ======================#
  7716. code=$?
  7717.  
  7718. # if AUTOCLEAN=true silently delete all pkgs in WORKDIR that are already installed
  7719. if [ "$AUTOCLEAN" = 'yes' -a "`HIDE_BUILTINS=true list_installed_pkgs`" != '' ];then
  7720.   clean_pkgs &>/dev/null
  7721. fi
  7722.  
  7723.  
  7724.  
  7725. # remove tmp dir used by pkg_get and get_deps
  7726. rm $TMPDIR/PKGSDONE 2>/dev/null
  7727.  
  7728. # reset lang options as we found them
  7729. LANG=$USER_LANG
  7730. LC_ALL=$USER_LC_ALL
  7731.  
  7732. exit $code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement