Advertisement
s243a

pkg (fix symlink removal)

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