s243a

/usr/sbin/pkg

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