Advertisement
s243a

/usr/sbin/pkg-concurrent-draft

Aug 29th, 2019
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 309.59 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # pkg - a command line package manager for Puppy Linux
  4. #
  5. # By Scott Jarvis (sc0ttman)
  6. # #s243a: modified to use vars instead of explicit paths.
  7. # Copyright (c) 2013 Puppy Linux Community
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 1 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21.  
  22.  
  23. #================== setup script vars =====================#
  24.  
  25. APPNAME="Pkg"
  26. APPVER="1.9.22"
  27. APPTITLE="$APPNAME $APPVER"
  28. list_deps_count=0 #Keeps track of the number of instances of the function list_deps(). Cleanup will be done when the last instance exists.
  29. dep_id=0 #
  30. # get current locale settings
  31. USER_LANG=$LANG
  32. USER_LC_ALL=$LC_ALL
  33.  
  34. SELF=$(basename $0) # this script
  35. QTAG='' # gets set to (y/n) if ASK=-true
  36. LANG=C # speed up
  37. LC_ALL=C # speed up
  38. EDITOR=${EDITOR:-vi} # just in case
  39. PAGER=${PAGER:-less} # just in case
  40. CURDIR="${PWD}" # get current dir, before cd to WORKDIR
  41. whoami=$(whoami) # s243a copied from below. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
  42. TMPDIR=/tmp/pkg/${whoami} # set the tmp dir
  43.  
  44. # set colours true by default
  45. green="\e[32m"; red="\e[91m"; magenta="\e[95m"; lightblue="\e[36m"; yellow="\e[93m"; bold="\e[1m"; endcolour="\e[0m"
  46.  
  47. # ENVIRONMENT VARS, which may be overridden later
  48. [ -z "$PKGRC" ] && export PKGRC=${HOME}/.pkg/pkgrc # config file for this script
  49. [ -z "$ASK" ] && ASK=false # if true, ask user before doing stuff. Overridden by --ask
  50. [ -z "$QUIET" ] && QUIET=false # if true, hide output that doesnt log well in Xdialog, Gtkdialog, etc
  51. [ -z "$FORCE" ] && FORCE=false # if true, force (re)install/remove pkgs. Overridden by --force
  52. [ -z "$HIDE_INSTALLED" ] && export HIDE_INSTALLED=false # if true, hide installed pkgs from pkg searches (-n, -na, -ss, -ssa)
  53. [ -z "$HIDE_BUILTINS" ] && export HIDE_BUILTINS=true # if true, remove builtins pkgs from dep lists, dont download/install them
  54. [ -z "$HIDE_USER_PKGS" ] && export HIDE_USER_PKGS=true # if true, hide user installed pkgs from dep lists, dont download/install them
  55. [ -z "$NO_ALIASES" ] && export NO_ALIASES=false # if true, skip searching pkg alias names for pkg alternatives
  56. [ -z "$NO_INSTALL" ] && export NO_INSTALL=false # if true, skip installing of pkgs
  57. [ -z "$PKG_NO_COLOURS" ] && export PKG_NO_COLOURS=false # if true, disable coloured output or not
  58. [ -z "$PKG_CONFIGURE" ] && export PKG_CONFIGURE='' # reset
  59. [ -z "$PKG_CFLAGS" ] && export PKG_CFLAGS='' # reset
  60.  
  61. [ -z "$PKGS_DIR" ] && export PKGS_DIR="$(realpath "${HOME}/.packages")"
  62. #These are files of the form
  63. #[ -z "$PET_SPEC_DIR_ROOT" ] && PET_SPEC_DIR_ROOT="$PKGS_DIR"
  64. if [ -z "$REPO_DB_FILE_DIR" ]; then
  65. if [ -d "$PKGS_DIR/repo" ]; then #This imples mistfires ppm3 is installed
  66. export REPO_DB_FILE_DIR="$(realpath "$PKGS_DIR/repo")"
  67. else
  68. export REPO_DB_FILE_DIR="$PKGS_DIR"
  69. fi
  70. fi
  71. if [ -z "$PACKAGE_FILE_LIST_DIR" ]; then
  72. if [ -d "$PKGS_DIR/package-files" ]; then #This imples mistfires ppm3 is installed
  73. export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR/package-files")"
  74. else
  75. export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR")"
  76. fi
  77. fi
  78. [ -z "$BUILTIN_FILE_LIST_DIR" ] && BUILTIN_FILE_LIST_DIR="$PKGS_DIR/builtin_files"
  79. #[ -z "$PET_SPEC_DIR_BUILTIN" ] && PET_SPEC_DIR_BUILTIN=\
  80. # "$(realpath "$PKGS_DIR/builtin_files")"
  81. #
  82. #[ -z "$PET_SPEC_DIR_USR_INST" ] && PET_SPEC_DIR_USR_INST="$PKGS_DIR"
  83.  
  84.  
  85. #mk_spec_file_list_arry(){
  86. declare -ga SPEC_DB_PATHS=()
  87. #Can't put the loop in the loop in a pipeline if you want to assign array values:
  88. #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  89. #find / -wholename "$PKGS_DIR"/'*-installed-packages' |
  90. while read SPEC_FILE; do
  91. bname="`basename "$SPEC_FILE"`"
  92. case "$bname" in #Consider lowering case
  93. "layers-installed-packages")
  94. #Do Nothing
  95. export LAYER_INST_PKGS_FILE="$SPEC_FILE" ;;
  96. "woof-installed-packages")
  97. export WOOF_INST_PKGS_FILE="$SPEC_FILE" ;;
  98. "user-installed-packages")
  99. export USER_INST_PKGS_FILE="$SPEC_FILE" ;;
  100. "devx-only-installed-packages")
  101. export DEVX_INST_PKGS_FILE="$SPEC_FILE" ;;
  102. *)
  103. SPEC_DB_PATHS+=( "$SPEC_FILE" ) ;;
  104. esac
  105. #s243a: We don't need realpath for the next four vars but it will provide usefull debugging information.
  106. #s243a: TODO search for the following files if they don't exist.
  107. [ -z "$USER_INST_PKGS_FILE" ] && \
  108. USER_INST_PKGS_FILE="$PKGS_DIR/user-installed-packages"
  109. [ -z "$WOOF_INST_PKGS_FILE" ] && \
  110. WOOF_INST_PKGS_FILE="$PKGS_DIR/woof-installed-packages"
  111. [ -z "$LAYER_INST_PKGS_FILE" ] && \
  112. LAYER_INST_PKGS_FILE="$PKGS_DIR/layers-installed packages"
  113. [ -z "$DEVX_INST_PKGS_FILE" ] && \
  114. DEVX_INST_PKGS_FILE="$PKGS_DIR/devx-only-installed-packages"
  115. SPEC_DB_PATHS=( "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${SPEC_DB_PATHS[@]}" )
  116. done < <( find "$PKGS_DIR" -name '*-installed-packages' )
  117. #}
  118. #mk_spec_file_list_arry
  119. #echo "SPEC_DB_PATHS=${SPEC_DB_PATHS[@]}"
  120.  
  121. #mk_all_repo_file_list_arry(){
  122. declare -gA ALL_REPO_DB_PATHS=()
  123. #ALL_REPO_DB_PATHS=()
  124. bname=''
  125.  
  126. #Can't put the loop in the loop in a pipeline if you want to assign array values:
  127. #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  128. #find / -wholename "$REPO_DB_FILE_DIR"/'Packages-*' |
  129. while read REPO_FILE; do
  130. #s243a: I was thinking of using realpath but it might cause issues.
  131. #REPO_FILE="$(realpath "$REPO_FILE")"
  132. bname="$(basename "$REPO_FILE")"
  133. ALL_REPO_DB_PATHS+=( ["$bname"]="$REPO_FILE" )
  134. #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  135. #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  136. done < <( find "$REPO_DB_FILE_DIR" -name 'Packages-*' )
  137. #}
  138. #mk_all_repo_file_list_arry
  139. #echo "exited: mk_all_repo_file_list_arry()"
  140. #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  141.  
  142. #Moved after the function repo_file_list
  143. #mk_repo_file_list_arry
  144. # but disable colours if called as gpkg, or the ENV variable PKG_NO_COLOURS is true
  145. if [ "`basename $0`" != "pkg" -o "$PKG_NO_COLOURS" = true ]; then
  146. green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour=''
  147. fi
  148.  
  149. # report errors better than just echo
  150. error(){
  151. echo -e 1>&2 "${red}Error:${endcolour} $1"
  152. }
  153.  
  154. # for correct error output, trap commands early
  155. cleanup(){
  156. 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
  157. rm -rf /tmp/pkg/build_pkg/ &>/dev/null
  158.  
  159. # prevent double msg output if error=130 (user Ctrl-C)
  160. [ -f /tmp/pkg/error130 -a "$2" = '130' ] && exit "$2"
  161. # make the tmp dir we'll use
  162. mkdir -p /tmp/pkg &>/dev/null
  163. # only add line numbers if it was given
  164. [ "$1" != 'none' ] && lineno="line $1, " || lineno=''
  165. # get the right error msg
  166. case "$2" in
  167. 130) echo; msg="User cancelled operation!"; touch /tmp/pkg/error130;;
  168. 8) msg="Package URL invalid.";;
  169. 7) msg="Package extraction failed.";;
  170. 6) msg="Missing package file.";;
  171. 5) msg="Missing directory.";;
  172. 4) msg="Copy failed.";;
  173. 3) msg="Setup failed.";;
  174. 2) msg="Code error!";;
  175. 1) exit 1 ;; # user gave wrong options or pkg name, not serious
  176. *) msg="Error code = $2" ;;
  177. esac
  178. # print msg
  179. [ "$2" != "0" ] && echo -e 1>&2 "${red}Error${endcolour} ${2}: ${lineno}$msg"
  180. exit $2
  181. }
  182. trap 'cleanup ${LINENO:-none} $?' EXIT INT TERM
  183.  
  184. #run as root only
  185. whoami=$(whoami) #s243a Copied to before line #40. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
  186. [ "$whoami" != "root" ] && echo "You must be root to run Pkg." && exit 1
  187.  
  188. #080413 make sure all config files are present, copy from /etc if need be
  189. if [ ! -f ${PKGRC} ]; then
  190. echo "Restoring default settings from /etc/pkg"
  191. [ ! -d /etc/pkg/ ] && error "Default config files in /etc/pkg/ not found." && exit 3
  192. mkdir -p "$HOME/.pkg"
  193. [ ! -d "$HOME/.pkg" ] && error "Default user config dir '$HOME/.pkg/' could not be created." && exit 3
  194. cp --force -a /etc/pkg/* "$HOME/.pkg/" || exit 3
  195. fi
  196.  
  197. # get puppy distro env vars
  198. [ -f /etc/rc.d/PUPSTATE ] && . /etc/rc.d/PUPSTATE #this has PUPMODE and SAVE_LAYER.
  199. [ -f /etc/DISTRO_SPECS ] && . /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  200. [ -f /etc/rc.d/BOOTCONFIG ] && . /etc/rc.d/BOOTCONFIG #has EXTRASFSLIST PREVUNIONRECORD, LASTUNIONRECORD (sfs stuff)
  201. [ -f /etc/xdg/menus/hierarchy ] && . /etc/xdg/menus/hierarchy #w478 has PUPHIERARCHY variable.
  202. [ -f $PKGS_DIR/DISTRO_PKGS_SPECS ] && . $PKGS_DIR/DISTRO_PKGS_SPECS #has lot sof essential info
  203. [ -f $PKGS_DIR/PKGS_MANAGEMENT ] && . $PKGS_DIR/PKGS_MANAGEMENT #has PKG_NAME_IGNORE, PKG_PET_THEN_BLACKLIST_COMPAT_KIDS, PKG_REPOS_ENABLED
  204. [ -f $PKGS_DIR/DISTRO_COMPAT_REPOS ] && . $PKGS_DIR/DISTRO_COMPAT_REPOS #has repo URL related vars
  205.  
  206. # set the package name suffix appended to combined pkgs (pkg+deps)
  207. CP_SUFFIX="WITHDEPS_${DISTRO_FILE_PREFIX}"
  208.  
  209. # set correct arch for repo URLs (used by some slack-pup repos)
  210. case "$DISTRO_TARGETARCH" in
  211. x86) DBIN_ARCH=i486 ;;
  212. x86_64) DBIN_ARCH=x86_64 ; DSUFFIX=64 ;;
  213. *) DBIN_ARCH=i486 ;;
  214. esac
  215.  
  216. # needed for some debian based repos
  217. case $DISTRO_COMPAT_VERSION in
  218. wheezy) DDB_COMP=bz2 ;; # older versions
  219. *) DDB_COMP=xz ;;
  220. esac
  221.  
  222. # now create 'layers-installed': will contain builtins (and devx packages, if devx is loaded)
  223. #130511 need to include devx-only-installed-packages, if loaded...
  224. if which gcc &>/dev/null; then
  225. [ ! -f /tmp/ppm-layers-installed-packages ] && cp -f "$WOOF_INST_PKGS_FILE" /tmp/ppm-layers-installed-packages &>/dev/null
  226. cat "$PET_SPEC_DIR_DEFAULT/devx-only-installed-packages" >> /tmp/ppm-layers-installed-packages &>/dev/null
  227. sort -u /tmp/ppm-layers-installed-packages > "$LAYER_INST_PKGS_FILE" &>/dev/null
  228. else
  229. cp -f "$WOOF_INST_PKGS_FILE" "$LAYER_INST_PKGS_FILE" &>/dev/null
  230. fi
  231.  
  232. # set $DIRECTSAVEPATH (where we want to install pkgs)
  233. if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ]; then
  234. DIRECTSAVEPATH="/initrd${SAVE_LAYER}" #SAVE_LAYER is in /etc/rc.d/PUPSTATE.
  235. elif [ "$PUPMODE" = "2" ]; then
  236. DIRECTSAVEPATH=""
  237. fi
  238. # s243a: Need the real path to avoid overwriting sylinks. See:
  239. # http://murga-linux.com/puppy/viewtopic.php?p=1030958#1030958
  240. # https://github.com/puppylinux-woof-CE/woof-CE/issues/1469#issuecomment-505706014
  241. [ -L "$DIRECTSAVEPATH" ] && DIRECTSAVEPATH="$(readlink "$DIRECTSAVEPATH")"
  242. # get repo details, workdir, search settings and so on.. you could
  243. # you can also add any ENVIRONMENT VARS above to PKGRC, to override the defaults
  244. . ${PKGRC}
  245.  
  246. # set and create workdir if no valid dir set
  247. [ ! -d "$WORKDIR" ] && mkdir -p "$WORKDIR"
  248. if [ ! -d "$WORKDIR" ]; then
  249. error "Can't create $WORKDIR. Please create it."
  250. exit 3
  251. fi
  252. WORKDIR=~/pkg
  253.  
  254. # add to tab completion settings to bashrc and print hint
  255. if [ -z "$PKG_TAB_COMPLETION" ]; then
  256. if [ "$(grep 'export PKG_TAB_COMPLETION=true' ~/.bashrc)" = "" ]; then
  257. # add to bashrc
  258. echo "" >> ~/.bashrc
  259. echo "# enable $APPNAME $APPVER TAB completion" >> ~/.bashrc
  260. echo "export PKG_TAB_COMPLETION=true" >> ~/.bashrc
  261. echo ". /etc/bash_completion.d/pkg 2>/dev/null" >> ~/.bashrc
  262. fi
  263. fi
  264.  
  265. # make tmp dir writable by everyone if needed
  266. if [ ! -d "$TMPDIR" ]; then
  267. mkdir -p "$TMPDIR" 2>/dev/null
  268. chmod -R 1777 /tmp/pkg/ 2>/dev/null
  269. fi
  270.  
  271. # if no tmp dir created or accessible, exit
  272. [ ! -d "$TMPDIR" ] && error "Cannot create temp dir ${lightblue}$TMPDIR${endcolour}" && exit 3
  273.  
  274. # support aliases, create ALIASES tmp file
  275. 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'
  276. [ ! -f "$TMPDIR/pkg_aliases" ] && echo "$PKG_NAME_ALIASES" | tr ' ' '\n' > $TMPDIR/pkg_aliases
  277.  
  278. # remove error code flag if we got here
  279. rm -f /tmp/pkg/error130 &>/dev/null
  280.  
  281. # if not first run, and no options given, print the help
  282. [ ! -f ~/.pkg/firstrun -a "$1" = "" ] && $SELF -H && exit 1 #200913 more help by default
  283.  
  284. #================== setup script vars =====================#
  285.  
  286.  
  287.  
  288. #==================== main functions ======================#
  289.  
  290. set -a
  291.  
  292. # utility funcs
  293.  
  294. print_usage(){ # print usage text. Requires $1, a valid Pkg cmd FUNCLIST
  295.  
  296. local examples_file=/usr/share/pkg/docs/examples.txt
  297.  
  298. [ -f $examples_file ] && source $examples_file
  299.  
  300. # get and print the usage info from its usage file
  301. if [ -f /usr/share/pkg/docs/usage/$1 -a "$1" ]; then
  302. source /usr/share/pkg/docs/usage/$1
  303. echo -e "\n$USAGE"
  304. # show examples, taken from $EXAMPLES, if they exist
  305. if [ "`echo "$EXAMPLES" | grep "$SELF" | grep "\-$1"`" != '' ]; then
  306. echo -e "\n${bold}Usage Examples${endcolour}:\n"
  307. echo -e "$EXAMPLES" | grep "$SELF " | grep "$1 "
  308. fi
  309. else
  310. echo -e "Usage: ${bold}$SELF usage CMD${endcolour}"
  311. echo
  312. echo "Commands:"
  313. echo -e "add-repo get-only repo-convert
  314. add-source help repo-dep-scope
  315. all-pkgs help-all repo-file-list
  316. add remove repo-info
  317. ask install repo-list
  318. autoclean install-all repo-pkg-scope
  319. bleeding-edge list-deps repo-update
  320. clean list-downloaded search
  321. contents list-installed search-all
  322. deb2pet names sfs2pet
  323. delete names-all sfs-combine
  324. delete-all names-exact show-config
  325. deps names-exact-all split
  326. deps-all pet2sfs tgz2pet
  327. deps-check pet2tgz uninstall
  328. deps-download pet2txz uninstall-all
  329. dir2pet build unpack
  330. dir2sfs build-list update-sources
  331. dir2tgz pkg-combine version
  332. download installed which
  333. examples repack which-repo
  334. extract status rdep-check
  335. force update what-needs
  336. func-list workdir rm-repo
  337. txz2pet dir2repo
  338.  
  339. Usage: ${bold}$SELF usage CMD${endcolour}"
  340. #cd /usr/share/pkg/docs/usage/; echo `ls` | fold -w 70 -s
  341. fi
  342. exit 1
  343. }
  344.  
  345.  
  346. func_list(){ # list all functions available in this script FUNCLIST
  347. [ -f $TMPDIR/func_list ] && cat $TMPDIR/func_list | sort && exit 0
  348. 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
  349. cat $TMPDIR/func_list | sort
  350. exit 0
  351. }
  352.  
  353.  
  354. get_pkg_ext(){ # return file extension of $1 FUNCLIST
  355.  
  356. # get valid usage or exit
  357. [ ! "$1" ] && echo 'Usage: get_pkg_ext PKGNAME' && exit 1
  358.  
  359. local pkg_installed=''
  360. local pkg_filename=''
  361. local pkg_ext=''
  362. local pkg_name=''
  363.  
  364. # check given file type, see if it matches our supported pkg types
  365. case "$1" in
  366. *.bz2) echo bz2 ;;
  367. *.pet) echo pet ;;
  368. *.deb) echo deb ;;
  369. *.pkg.tar.gz) echo pkg.tar.gz ;;
  370. *.pkg.tar.xz) echo pkg.tar.xz ;;
  371. *.pkg.tgz) echo pkg.tgz ;;
  372. *.pkg.txz) echo pkg.txz ;;
  373. *.tar.bz2) echo tar.bz2 ;;
  374. *.tar.lzma) echo tar.lzma ;;
  375. *.tar.gz) echo tar.gz ;;
  376. *.tar.xz) echo tar.xz ;;
  377. *.tbz) echo tbz ;;
  378. *.tgz) echo tgz ;;
  379. *.tlz) echo tlz ;;
  380. *.txz) echo txz ;;
  381. *.gz) echo gz ;;
  382. *.xz) echo xz ;;
  383. *.rpm) echo rpm ;;
  384. *.sfs) echo sfs ;;
  385. #*.tcz) echo tcz ;;
  386. #*.tpkg) echo tpkg ;;
  387. #*.apk) echo apk ;;
  388. *)
  389. # if it's an installed pkg, get the extension from $PKGS_DIR/*
  390. pkg_installed=`list_installed_pkgs "$1" | grep -m1 "^$1"`
  391.  
  392. # if $pkg_check not empty, then $1 is an installed pkg
  393. if [ "$pkg_installed" != '' ]; then
  394. pkg_filename=`cut -f8 -d'|' "$USER_SPEC_FILE" |grep -m1 ^$1`
  395. [ "$pkg_filename" = '' ] && pkg_filename=`cut -f8 -d'|' "${SPEC_DB_PATHS[@]}" |grep -m1 ^$1`
  396. [ "$pkg_filename" != '' ] && pkg_ext=`get_pkg_ext "$pkg_filename"`
  397. else
  398. # if it's a repo package, get it's extension from $PKGS_DIR/*
  399. pkg_filename=`grep -m1 "^$1" "${REPO_DB_PATHS[@]}" |cut -f8 -d'|'`
  400. [ "$pkg_filename" != '' ] && pkg_ext=`get_pkg_ext "$pkg_filename"`
  401. fi
  402. [ "$pkg_ext" != '' ] && echo $pkg_ext
  403. ;;
  404. esac
  405. }
  406.  
  407.  
  408. get_pkg_version(){ # returns version of PKGNAME ($1) FUNCLIST
  409.  
  410. # exit if no pkg given
  411. [ ! "$1" ] && exit 1
  412.  
  413. local PKGNAME=`get_pkg_name "$1"`
  414. local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  415. local pkg_ext=`get_pkg_ext "$PKGNAME"`
  416. local pkg_version=''
  417.  
  418. PKGNAME=$(basename "$PKGNAME" .$pkg_ext)
  419.  
  420. pkg_version=`echo $PKGNAME | sed -e "s/^${PKGNAME_ONLY}_//g"`
  421. # if $pkg_version is same as $PKGNAME, try cutting again, using '-' instead of '_'
  422. [ "$pkg_version" = "$PKGNAME" ] && pkg_version=`echo $PKGNAME | sed -e "s/^${PKGNAME_ONLY}-//g"`
  423.  
  424. # now trim off the other unneeded bits
  425. pkg_version=`echo $pkg_version | sed \
  426. -e "s/^-//g" \
  427. -e "s/^_//g" \
  428. -e "s/^DEV-//g" \
  429. -e "s/^DOC-//g" \
  430. -e "s/^NLS-//g" \
  431. -e "s/^dev-//g" \
  432. -e "s/^doc-//g" \
  433. -e "s/^nls-//g" \
  434. -e "s/+deb.*//g" \
  435. -e "s/+ubuntu.*//g" \
  436. -e "s/-i[346].*//g" \
  437. -e "s/-x[86].*//g" \
  438. -e "s/-pup.*//g" \
  439. -e "s/-q[0-9].*//g" \
  440. -e "s/-WITHDEPS.*//g" \
  441. -e "s/-PLUSDEPS.*//g" \
  442. -e 's@\\\@@g'`
  443.  
  444. # get $REPONAME and $EX
  445. . ${PKGRC}
  446.  
  447. [ "$pkg_ext" = '' ] && pkg_ext=$EX
  448.  
  449. echo $pkg_version
  450. return 0
  451. }
  452.  
  453.  
  454. get_pkg_name_only_from_ext(){ # return package name from $1 (must include file extension)
  455.  
  456. # get valid usage or exit
  457. [ ! "$1" ] && echo 'Usage: get_pkg_name_only_from_ext <PKG_FILENAME>' && exit 1
  458.  
  459. # get the extension of the given package name, if any
  460. local pkg_ext=`get_pkg_ext "$1"`
  461. # get the name without path and extension
  462. local pkg_name=`basename "$1" .$pkg_ext`
  463. local PKGNAME=''
  464. local PKGNAME_ONLY=''
  465. local DB_pkgrelease=''
  466. local prPATTERN=''
  467. local DB_version=''
  468. local xDB_version=''
  469. local xPATTERN=''
  470.  
  471. #split PKGMAIN, ex: FULLPKGNAME=xvidtune-1.0.1-i486-1.tgz has PKGNAME=xvidtune-1.0.1
  472. case $pkg_ext in
  473. deb)
  474. #deb ex: xsltproc_1.1.24-1ubuntu2_i386.deb xserver-common_1.5.2-2ubuntu3_all.deb
  475. PKGNAME_ONLY="`echo -n "$pkg_name" | cut -f 1 -d '_'`"
  476. DB_pkgrelease="`echo -n "$pkg_name" | rev | cut -f 2 -d '_' | cut -f 1 -d '-' | rev`"
  477. prPATTERN="s%\\-${DB_pkgrelease}.*%%"
  478. PKGNAME="`echo -n "$pkg_name" | sed -e "$prPATTERN" 2>/dev/null`"
  479. ;;
  480. pet)
  481. PKGNAME="$pkg_name"
  482. DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\-%%'`"
  483. xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  484. xPATTERN="s%${xDB_version}%%"
  485. PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  486. ;;
  487. tgz|txz)
  488. #slack ex: xvidtune-1.0.1-i486-1.tgz printproto-1.0.4-noarch-1.tgz
  489. PKGNAME="`echo -n "$pkg_name" | sed -e 's%\\-i[3456]86.*%%' -e 's%\\-noarch.*%%'`"
  490. DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\\-%%'`"
  491. xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  492. xPATTERN="s%${xDB_version}%%"
  493. PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\-$%%' 2>/dev/null`"
  494. ;;
  495. tar.gz)
  496. #arch ex: xproto-7.0.14-1-i686.pkg.tar.gz trapproto-3.4.3-1.pkg.tar.gz
  497. PKGNAME="`echo -n "$pkg_name" | sed -e 's%\\-i[3456]86.*%%' -e 's%\\.pkg$%%' | rev | cut -f 2-9 -d '-' | rev`"
  498. DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\\-%%'`"
  499. xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  500. xPATTERN="s%${xDB_version}%%"
  501. PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  502. ;;
  503. rpm) #110523
  504. #exs: hunspell-fr-3.4-1.1.el6.noarch.rpm
  505. PKGNAME="$pkg_name"
  506. DB_version="`echo -n "$PKGNAME" | grep -o '\\-[0-9].*' | sed -e 's%^\-%%'`"
  507. xDB_version="`echo -n "$DB_version" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g'`"
  508. xPATTERN="s%${xDB_version}%%"
  509. PKGNAME_ONLY="`echo -n "$PKGNAME" | sed -e "$xPATTERN" -e 's%\\-$%%' 2>/dev/null`"
  510. ;;
  511. esac
  512. [ "$PKGNAME_ONLY" != '' ] && echo $PKGNAME_ONLY || echo "$1"
  513. }
  514.  
  515.  
  516. get_pkg_name_only(){ # return pkg name only from $1, with no version or suffix FUNCLIST
  517.  
  518. # exit if no valid options
  519. [ ! "$1" ] && exit 1
  520.  
  521. # get config settings, inc current repo file
  522. #. ${PKGRC}
  523.  
  524. local pkg_name=''
  525. local pkg_name_only=''
  526. local name_only=''
  527. local pkg_ext=`get_pkg_ext "$1"`
  528. local repo_of_pkg=''
  529. local repo_pkg_with_ext=''
  530. local repo_ext=$EX # from $PKGRC
  531.  
  532. # check the repos
  533. local pkg_name_only="`grep -m1 "|${1}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|'`"
  534. [ "$pkg_name_only" = '' ] && pkg_name_only="`grep -m1 "^${1}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|' | head -1`"
  535. [ "$pkg_name_only" = '' ] && pkg_name_only="`grep -m1 "|${1}.${pkg_ext}|" "${REPO_DB_PATHS[@]}" 2>/dev/null | cut -f2 -d'|' | head -1`"
  536.  
  537. pkg_name_only=${pkg_name_only// */}
  538.  
  539. # if we found it, print it and exit
  540. if [ "$pkg_name_only" != '' ]; then
  541. echo ${pkg_name_only}
  542. return 0
  543. fi
  544.  
  545. # if not, but we have an extension, try get_pkg_name_only_from_ext()
  546. case $DISTRO_BINARY_COMPAT in ubuntu|trisquel|debian|devuan)
  547. name_only=`get_pkg_name_only_from_ext "$(basename "${1}.${repo_ext}")"| head -1`
  548. name_only=${name_only// */}
  549. [ "$name_only" != '' -a "$name_only" != "$1" ] && echo $name_only && return 0
  550. ;;
  551. esac
  552.  
  553. ## ...if we didn't find the name using the above, do the horrible checks below
  554.  
  555. # replace the dash before the version number with an @ symbol.
  556. # INFO: sed /-[^-][^+][^a-zA-Z][0-9.]*/ (hopefully?) replaces '-$VER' with '@'
  557. # not including when $VER starts with a number/letter
  558. pkg_name_only="`echo "$(basename "${1}")" | sed -e 's/-[^-][^+][^a-zA-Z][0-9.]*/@/'`"
  559.  
  560. # do 'ioquake3+u20130504' => 'oquake3'
  561. pkg_name_only="`echo "${pkg_name_only}" | sed -e 's/+[a-z]/@/'`"
  562.  
  563. # note, we haven't cut away version numbers preceeded with underscores (_) yet
  564.  
  565. # if the version number was preceeded by an underscore, the version
  566. # will still be in the $pkg_name_only - pkgname_2.3.4 - so cut it out
  567. if [ "`echo "$pkg_name_only" | grep -o "_[0-9]\."`" != '' ]; then
  568. pkg_name_only="`echo "$pkg_name_only" | sed -e 's/_[^a-z][^A-Z][0-9.]*/@/'`"
  569.  
  570. # maybe the underscore preceeds a version that starts with a letter
  571. elif [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][0-9]\."`" != '' ]; then
  572. pkg_name_only="`echo "$pkg_name_only" | sed -e 's/_[a-zA-Z][0-9.]*/@/'`"
  573. fi
  574.  
  575. # now cut away everything after the @, that will leave only the package name
  576. pkg_name_only1="${pkg_name_only/@*/}"
  577. pkg_name_only="$pkg_name_only1"
  578.  
  579. # we might still have foo_bar_v1.2.3, so lets chop off * after the last _
  580. if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][0-9]\."`" != '' ]; then
  581. pkg_name_only="${pkg_name_only/_[a-zA-Z][0-9]*/}"
  582. fi
  583.  
  584. # another chop, we might have foo_bar_vv1.2.3, so lets chop off
  585. # everything after the last underscore, if we still have version numbers
  586. if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z][a-zA-Z][0-9]\."`" != '' ]; then
  587. pkg_name_only="${pkg_name_only/_[a-zA-Z][a-zA-Z][0-9]*/}"
  588. fi
  589.  
  590. # we might still have foo_bar_vvv1.2.3, so lets chop off
  591. # everything after the last underscore, if we still have version numbers
  592. if [ "`echo "$pkg_name_only" | grep -o "_[a-zA-Z*][0-9]\."`" != '' ]; then
  593. pkg_name_only="${pkg_name_only/_[a-zA-Z*][0-9]*/}"
  594. fi
  595.  
  596. # chop again, we might have abc_xwy-zzz1.2.3-blah-etc, so lets chop off
  597. # everything after the last dash-before-number
  598. if [ "`echo "$pkg_name_only" | grep -o "\-[a-zA-Z*]*[0-9]\."`" != '' ]; then
  599. pkg_name_only="${pkg_name_only/-[a-zA-Z*]*[0-9]*/}"
  600. fi
  601.  
  602. # another fix, if we still have PKGNAME-1.2, remove the '-1.2'
  603. if [ "`echo "$pkg_name_only" | grep -o "\-[0-9]"`" != '' ]; then
  604. pkg_name_only="${pkg_name_only/-[0-9]*/}"
  605. fi
  606.  
  607. # the sed bit changes 'liblzma5+20120614' to 'liblzma5'
  608. [ "$pkg_name_only" != '' ] && echo $pkg_name_only | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g' || return 1
  609. }
  610.  
  611.  
  612. get_pkg_name(){ # return full pkg name (with version) from $1 FUNCLIST
  613.  
  614. # get config settings, inc current repo file
  615. #. ${PKGRC}
  616.  
  617. local pkg_ext=''
  618. local pkg_name=''
  619. local full_name=''
  620. local supported_repo_files=''
  621. local repo_contents=''
  622.  
  623. # get the extension of the given package name, if any
  624. local pkg_ext=`get_pkg_ext "$1"`
  625. # get the name without path and extension
  626. local pkg_name="`basename "$1" .$pkg_ext`"
  627.  
  628. # get the repos files in the correct (fall back) order, then add file paths
  629.  
  630. #s243a: `repo_file_list` is called in mk_repo_file_list_arry
  631. #supported_repo_files="`repo_file_list | sed -e "s#^#$PKGS_DIR/#g"`"
  632.  
  633. # get the relevant repo contents (fields 1,2,8) from all repos,
  634. # then add pipes to line start/end for easier parsing later, then do
  635. # a basic search, for $pkg* (we'll refine it later), to avoid 'Argument list too long'..
  636. #cut -f1,2,8 "$USER_SPEC_FILE" "$PET_SPEC_DIR_DEFAULT/woof-installed-packages" $supported_repo_files | sed -e "s/^/|/g" -e "s/$/|/g" 2>/dev/null | grep -i "|$pkg_name" > ${TMPDIR}/repo_contents
  637. cut -f1,2,8 "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${REPO_DB_PATHS[@]}" | sed -e "s/^/|/g" -e "s/$/|/g" 2>/dev/null | grep -i "|$pkg_name" > ${TMPDIR}/repo_contents
  638. # get fields 1,2 and 8 (the 3 name fields) from all supported repo files, then
  639. # add '|' to start and end of lines, then find exact match of $pkg_name..
  640. # if no exact match, look for $pkg_name-*, then $pkg_name_*
  641. if [ -f ${TMPDIR}/repo_contents ]; then
  642. full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null| grep -m1 "|${pkg_name}|"` \
  643. || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name//-*/}|"` \
  644. || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name//_*/}|"` \
  645. || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}-"` \
  646. || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}_"` \
  647. || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "|${pkg_name}"` \
  648. || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}|"` \
  649. || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}-"` \
  650. || full_name=`cat ${TMPDIR}/repo_contents 2>/dev/null|grep -m1 "^${pkg_name}_"`
  651.  
  652. rm ${TMPDIR}/repo_contents &>/dev/null
  653. fi
  654.  
  655. # if we found pkg in repo, keep only the package name ('|pkg-123|pkg|blah|' -> 'pkg-123')
  656. [ "$full_name" != '' ] && full_name=`echo $full_name| cut -f2 -d '|' | tr -d '|'` || full_name=$pkg_name
  657.  
  658. # if we have a package name, return it here and leave the func
  659. [ "$full_name" != '' ] && echo $full_name && return 0
  660.  
  661. # if no pkg found in repos, we cant translate/lookup its longer name,
  662. # so just return what we got, without path, without pkg extension
  663. [ "$full_name" = '' ] && echo "`basename "$pkg_name" .$pkg_ext`"
  664. }
  665.  
  666.  
  667. is_blacklisted_pkg(){ # return true if PKGNAME ($1) is blacklisted FUNCLIST
  668. # exit if no valid options
  669. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-installed && exit 1
  670.  
  671. local EX=''
  672. local PKGNAME=''
  673. local PKGNAME_ONLY=''
  674.  
  675. # get pkg extension
  676. EX=`get_pkg_ext "$1"`
  677.  
  678. # strip away extension and path
  679. PKGNAME="$(basename "$1" .$EX)"
  680. #PKGNAME=`get_pkg_name "$PKGNAME"`
  681.  
  682. # get the package name without version
  683. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  684.  
  685. [ "`echo "$PKG_NAME_IGNORE" | grep "$PKGNAME_ONLY "`" != '' ] && echo true || echo false
  686. }
  687.  
  688.  
  689. is_installed_pkg(){ # return true if PKGNAME ($1) is installed, else false FUNCLIST
  690.  
  691. # exit if no valid options
  692. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-installed && exit 1
  693.  
  694. local EX=''
  695. local PKGNAME=''
  696. local PKGNAME_ONLY=''
  697. local check=''
  698.  
  699. # get pkg extension
  700. EX=`get_pkg_ext "$1"`
  701.  
  702. # strip away extension and path
  703. PKGNAME="$(basename "$1" .$EX)"
  704. PKGNAME=`get_pkg_name "$PKGNAME"`
  705.  
  706. # we cant rely on the strings the user passes us, so...
  707.  
  708. # get the package name without version
  709. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  710.  
  711. # exit if no valid package name
  712. [ "$PKGNAME" = '' -o "$PKGNAME_ONLY" = '' ] && print_usage pkg-installed && exit 1
  713.  
  714. # check the $PKGS_DIR/*.files
  715. check="$(find "$PACKAGE_FILE_LIST_DIR" -name "$PKGNAME.files")"
  716. [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'_*.files')"
  717. [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'-*.files')"
  718. [ "$check" = '' ] && check="$(find "$PACKAGE_FILE_LIST_DIR" -name "${PKGNAME}"'*.files')"
  719.  
  720. # slow but reliable & simple: separately check fields 1,2,8 of the various files listing installed pkgs
  721. [ "$check" = '' ] && check="`cut -f1 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME\$"`"
  722. [ "$check" = '' ] && check="`cut -f1,2 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME|" | grep -m1 "|$PKGNAME_ONLY\$"`"
  723. [ "$check" = '' ] && check="`cut -f8 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null| grep -m1 "^$PKGNAME"`"
  724. [ "$check" = '' ] && check="`HIDE_BUILTINS=false list_installed_pkgs | grep -m1 ^"$PKGNAME"`"
  725.  
  726. # if any checks above returned a result, $check will not be empty (ash didn't like grep -q, not sure why?)
  727. [ "$check" != '' ] && echo true || echo false
  728. }
  729.  
  730.  
  731. is_builtin_pkg (){ # return true if $1 is a builtin pkg, else false FUNCLIST
  732.  
  733. # if $1 is an exact match of a pkg short name,
  734. # long name or file name in woof-installed-packages,
  735. # we will return true, else we return false
  736.  
  737. # exit if no valid input
  738. [ ! "$1" ] && exit 1
  739.  
  740. local pkg_builtin=''
  741. local pkg_name_only=''
  742.  
  743. pkg_builtin="`cut -f1,2,8 -d '|' "$WOOF_INST_PKGS_FILE" 2>/dev/null\
  744. | sed -e 's@^@|@' -e 's@$@|@' \
  745. | grep -m1 "|$1|"`"
  746.  
  747. # try again.. if user gave only partial name (geany-1.27), the above would fail
  748. if [ "$pkg_builtin" = '' ]; then
  749. pkg_name_only=`get_pkg_name_only "$1"`
  750.  
  751. # so search for pkg_name* AND pkg_name_only (exact match, should be in field 2)
  752. if [ "$pkg_name_only" != '' ]; then
  753. pkg_builtin="`cut -f1,2,8 -d '|' "$WOOF_INST_PKGS_FILE" 2>/dev/null\
  754. | sed -e 's@^@|@' -e 's@$@|@' \
  755. | grep "|$1" \
  756. | grep -m1 "|$pkg_name_only|"`"
  757. fi
  758. fi
  759.  
  760. # print result
  761. [ "$pkg_builtin" != '' ] && echo true || echo false
  762. }
  763.  
  764.  
  765. is_devx_pkg (){ # return true if $1 is a pkg in the devx, else false FUNCLIST
  766.  
  767. # if $1 is an exact match of a pkg short name,
  768. # long name or file name in devx-only-installed-packages,
  769. # we will return true, else we return false
  770.  
  771. # exit if no valid input
  772. [ ! "$1" ] && exit 1
  773.  
  774. local devx_pkg=''
  775. local pkg_name_only=''
  776.  
  777. devx_pkg="`cut -f1,2,8 -d '|' "$DEVX_INST_PKGS_FILE" 2>/dev/null\
  778. | sed -e 's@^@|@' -e 's@$@|@' \
  779. | grep -m1 "|$1|"`"
  780.  
  781. # try again.. if user gave only partial name (geany-1.27), the above would fail
  782. if [ "$devx_pkg" = '' ]; then
  783. pkg_name_only=`get_pkg_name_only "$1"`
  784.  
  785. # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  786. if [ "$pkg_name_only" != '' ]; then
  787. devx_pkg="`cut -f1,2,8 -d '|' "$DEVX_INST_PKGS_FILE" 2>/dev/null\
  788. | sed -e 's@^@|@' -e 's@$@|@' \
  789. | grep "|$1" \
  790. | grep -m1 "|$pkg_name_only|"`"
  791. fi
  792. fi
  793.  
  794. # print result
  795. [ "$devx_pkg" != '' ] && echo true || echo false
  796. }
  797.  
  798.  
  799. is_usr_pkg (){ # return true if $1 is a user installed pkg, else false FUNCLIST
  800.  
  801. # if $1 is an exact match of a pkg short name,
  802. # long name or file name in user-installed-packages,
  803. # we will return true, else we return false
  804.  
  805. # exit if no valid input
  806. [ ! "$1" ] && exit 1
  807.  
  808. local usr_pkg=''
  809. local pkg_name_only=''
  810.  
  811. usr_pkg="`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" 2>/dev/null\
  812. | sed -e 's@^@|@' -e 's@$@|@' \
  813. | grep -m1 "|$1|"`"
  814.  
  815. # try again.. if user gave only partial name (geany-1.27), the above would fail
  816. if [ "$usr_pkg" = '' ]; then
  817. pkg_name_only=`get_pkg_name_only "$1"`
  818.  
  819. # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  820. if [ "$pkg_name_only" != '' ]; then
  821. usr_pkg="`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" 2>/dev/null\
  822. | sed -e 's@^@|@' -e 's@$@|@' \
  823. | grep "|$1" \
  824. | grep -m1 "|$pkg_name_only|"`"
  825. fi
  826. fi
  827.  
  828. # print result
  829. [ "$usr_pkg" != '' ] && echo true || echo false
  830. }
  831.  
  832.  
  833. is_repo_pkg (){ # return true if $1 is a pkg in a supported repo, else false FUNCLIST
  834.  
  835. # if $1 is an exact match of a pkg short name,
  836. # long name or file name in Packages-*-
  837. # we will return true, else we return false
  838.  
  839. # exit if no valid input
  840. [ ! "$1" ] && exit 1
  841.  
  842. local repo_pkg=''
  843. local pkg_name_only=''
  844. local all_supported_repofiles
  845.  
  846. # all repo files, full paths
  847. #all_supported_repofiles=`repo_file_list | sed "s#^#$PKGS_DIR/#" | tr '\n' ' '`
  848.  
  849. #Don't need sed, but could use if you want to do wildcards
  850. #all_supported_repofiles=`repo_file_list | sed 's#$#*#' | xargs find -name | tr '\n' ' '`
  851. #echo "repo_file_list | xargs find \"$PKGS_DIR\" -name | tr '\n' ' '"
  852. all_supported_repofiles="$(repo_file_list | while read a; do find "$REPO_DB_FILE_DIR" -name "$a"'*'; done | tr '\n' ' ')"
  853. # search all repo files for the $1
  854. repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  855. | sed -e 's/ //g' -e 's@^@|@' -e 's@$@|@' \
  856. | grep -m1 "|${1}|"`"
  857.  
  858. # search all repo files for the $1*
  859. [ "$repo_pkg" = '' ] \
  860. && repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  861. | sed -e 's/ //g' -e 's@^@|@' -e 's@$@|@' \
  862. | grep -m1 "|${1}-\?_\?[0-9.a-zA-Z]*|"`"
  863.  
  864. # try again.. if user gave only partial name (geany-1.27), the above would fail
  865. if [ "$repo_pkg" = '' ]; then
  866. pkg_name_only=`get_pkg_name_only "$1"`
  867.  
  868. # so search for pkg_name* AND |pkg_name_only| (exact match, should be in field 2)
  869. if [ "$pkg_name_only" != '' ]; then
  870. repo_pkg="`cut -f1,2,8 -d '|' $all_supported_repofiles 2>/dev/null\
  871. | sed -e 's@^@|@' -e 's@$@|@' \
  872. | grep "|$1" \
  873. | grep -m1 "|$pkg_name_only|"`"
  874. fi
  875. fi
  876.  
  877. # print result
  878. [ "$repo_pkg" != '' ] && echo true || echo false
  879. }
  880.  
  881.  
  882. is_current_repo_pkg(){ # takes $PKGNAME ($1), returns true or false FUNCLIST
  883.  
  884. # exit if no valid input
  885. [ ! "$1" ] && exit 1
  886.  
  887. # get current repo ($REPOFILE)
  888. . ${PKGRC}
  889.  
  890. local pkg_in_repo
  891. #s243a: The repo file path
  892. local RF_PATH="$(realpath "$(find "$REPO_DB_FILE_DIR" -name "$REPOFILE" | head -n 1 )")"
  893. # check if given pkg ($1) is in the current repo
  894. pkg_in_repo="`LANG=C cut -f1,2,7,8 -d'|' "$RF_PATH" 2>/dev/null | sed -e "s/^/|/" -e "s/$/|/" | grep -m1 "|${1}|"`"
  895.  
  896. # print msg
  897. [ "$pkg_in_repo" != '' ] && echo true || echo false
  898. }
  899.  
  900.  
  901. is_local_pkg(){ # returns true if $1 is local package file FUNCLIST
  902.  
  903. # exit if no valid input
  904. [ ! "$1" ] && exit 1
  905.  
  906. . ${PKGRC}
  907.  
  908. # if $1 is a local file with a supported package extension
  909. # then we return true, else, we return false
  910.  
  911. local is_file=''
  912. local is_local_pkg=false
  913.  
  914. # first, check we have a local file
  915. if [ -f "$1" ]; then
  916.  
  917. # file *probably* has an extension, lets try to get it..
  918. # the func get_pkg_ext() will return empty if not a valid package extension
  919. file_ext=`get_pkg_ext "$1"`
  920.  
  921. # if not empty, it must be a local file, with valid pkg ext (a local pkg)
  922. [ "$file_ext" != '' ] && is_local_pkg=true
  923.  
  924. elif [ -f "$CURDIR/$1" ]; then
  925.  
  926. file_ext=`get_pkg_ext "$CURDIR/$1"`
  927. [ "$file_ext" != '' ] && is_local_pkg=true
  928.  
  929. elif [ -f "$WORKDIR/$1" ]; then
  930.  
  931. file_ext=`get_pkg_ext "$CURDIR/$1"`
  932. [ "$file_ext" != '' ] && is_local_pkg=true
  933.  
  934. fi
  935.  
  936. # print output
  937. echo $is_local_pkg
  938. }
  939.  
  940.  
  941.  
  942. # RC file funcs
  943.  
  944. set_workdir(){ # set new WORKDIR in rc file location FUNCLIST
  945.  
  946. # get latest rc file values
  947. . ${PKGRC}
  948.  
  949. # make sure $1 was given and doesn't already exist
  950. [ ! "$1" ] && print_usage workdir && exit 1
  951. [ -e "$1" ] && echo "Error: directory already exists. Choose a new one." && exit 1
  952.  
  953. # create the dir
  954. mkdir -p "$1" 2>/dev/null
  955.  
  956. # if dir not created, exit with error
  957. [ $? -eq 1 ] && echo "Error: Could not create $1" && exit 1
  958. [ ! -d "$1" ] && echo "Error: Could not create directory: $1" && exit 1
  959.  
  960. # dir was created, so lets copy our pkgs in there
  961. list_downloaded_pkgs | while read pkg_file
  962. do
  963. cp -v "$WORKDIR/$pkg_name" "$1/"
  964. done
  965.  
  966. # if copying everything to new dir failed
  967. if [ $? -eq 1 ]; then
  968. # print msg
  969. echo -e "${yellow}Warning:${endcolour}Could not copy packages from $WORKDIR to $1.."
  970. echo "You should copy all packages in $WORKDIR into $1."
  971. fi
  972.  
  973. # update the RC file
  974. WORKDIR="$1"
  975. set_config
  976. echo "Success. Work directory updated."
  977. exit 0
  978. }
  979.  
  980.  
  981. set_pkg_scope(){ # one|all set search for pkgs in current repo or all FUNCLIST
  982.  
  983. # get old values, any we dont set here are not overwritten
  984. . ${PKGRC}
  985.  
  986. [ "$1" != "" ] && PKGSCOPE="$1" || PKGSCOPE="$PKGSCOPE"
  987.  
  988. case "$1" in
  989. all)
  990. # set pkg search to all
  991. PKGSEARCH="list_all_pkg_names"
  992. PKGSEARCHEXACT="$SELF -nea"
  993. echo -e "${green}Success:${endcolour} Find packages in all repos."
  994. ;;
  995. one)
  996. # set pkg search to current only
  997. PKGSEARCH="list_pkg_names"
  998. PKGSEARCHEXACT="$SELF -ne"
  999. echo -e "${green}Success:${endcolour} Find packages in current repo ($REPONAME) only."
  1000. ;;
  1001. *)
  1002. PKGSCOPE="one"
  1003. # set pkg search to current only
  1004. PKGSEARCH="list_pkg_names"
  1005. PKGSEARCHEXACT="$SELF -ne"
  1006. echo "Find packages in current repo ($REPONAME) only."
  1007. ;;
  1008. esac
  1009.  
  1010. set_config #170213
  1011. }
  1012.  
  1013.  
  1014. set_dep_scope(){ # all|one set search for deps in current repo or all FUNCLIST
  1015.  
  1016. # get RC file values, so any we dont set here are not overwritten
  1017. . ${PKGRC}
  1018.  
  1019. # make sure we have a valid value
  1020. [ "$1" != "" ] && DEPSCOPE="$1" || DEPSCOPE="$DEPSCOPE"
  1021.  
  1022. case "$1" in
  1023. all)
  1024. # set pkg search to all
  1025. DEPSEARCH="list_all_pkg_names"
  1026. DEPSEARCHEXACT="$SELF -nea"
  1027. echo -e "${green}Success:${endcolour} Find dependencies in all repos."
  1028. ;;
  1029. one)
  1030. # set pkg search to one
  1031. DEPSEARCH="list_pkg_names"
  1032. DEPSEARCHEXACT="$SELF -ne"
  1033. echo -e "${green}Success:${endcolour} Find dependencies in current repo ($REPONAME) only."
  1034. ;;
  1035. esac
  1036.  
  1037. set_config
  1038. }
  1039.  
  1040.  
  1041. set_recursive_deps(){ # yes|no search for deps of deps or not FUNCLIST
  1042. [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && print_usage recursive-dep-check && exit 1
  1043.  
  1044. # get old values, any we dont set here are not overwritten
  1045. . ${PKGRC}
  1046.  
  1047. # make sure we have a valid value
  1048. RDCHECK="$1"
  1049. [ "$RDCHECK" = "yes" -o "$RDCHECK" = "no" ] || RDCHECK=no
  1050.  
  1051. set_config
  1052.  
  1053. # print final msg
  1054. if [ "$1" = "yes" ]; then
  1055. echo -e "${green}Success:${endcolour} 'Recursive dependency checking' enabled."
  1056. else
  1057. echo -e "${green}Success:${endcolour} 'Recursive dependency checking' disabled"
  1058. fi
  1059. }
  1060.  
  1061.  
  1062. set_bleeding_edge(){ # yes|no get latest pkgs, ignore fall backs FUNCLIST
  1063. [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && echo usage bleeding-edge && exit 1
  1064.  
  1065. #get old values, any we dont set here are not overwritten
  1066. . ${PKGRC}
  1067.  
  1068. # make sure we have a valid value
  1069. BLEDGE="$1"
  1070. [ "$BLEDGE" = "yes" -o "$BLEDGE" = "no" ] || BLEDGE=no
  1071.  
  1072. set_config
  1073.  
  1074. # print final msg
  1075. if [ "$1" = "yes" ]; then
  1076. echo -e "${green}Success:${endcolour} 'Bleeding edge' package search enabled."
  1077. else
  1078. echo -e "${green}Success:${endcolour} 'Bleeding edge' package search disabled."
  1079. fi
  1080. }
  1081.  
  1082.  
  1083. set_autoclean(){ # yes|no auto delete installed packages from WORKDIR FUNCLIST
  1084. [ "`echo $1 | grep -E "^yes\$|^no\$"`" = "" ] && print_usage autoclean && exit 1
  1085.  
  1086. #get old values, any we dont set here are not overwritten
  1087. . ${PKGRC}
  1088.  
  1089. # make sure we have a valid value
  1090. AUTOCLEAN="$1"
  1091. [ "$AUTOCLEAN" = "yes" -o "$AUTOCLEAN" = "no" ] || AUTOCLEAN=no
  1092.  
  1093. set_config
  1094.  
  1095. # print final msg
  1096. if [ "$1" = "yes" ]; then
  1097. echo -e "${green}Success:${endcolour} Auto-remove installed packages ENABLED."
  1098. else
  1099. echo -e "${green}Success:${endcolour} Auto-remove installed packages DISABLED."
  1100. fi
  1101. }
  1102.  
  1103.  
  1104. set_config(){ # update all options in config file FUNCLIST
  1105. echo "WORKDIR=$WORKDIR" > ${PKGRC}
  1106. echo "REPONAME=$REPONAME" >> ${PKGRC}
  1107. echo "EX=$EX" >> ${PKGRC}
  1108. echo "REPOFILE=$REPOFILE" >> ${PKGRC}
  1109. echo "REPOURL1=$REPOURL1" >> ${PKGRC}
  1110. echo "REPOURL2=$REPOURL2" >> ${PKGRC}
  1111. #140213 add all urls
  1112. echo "REPOURL3=$REPOURL3" >> ${PKGRC}
  1113. echo "REPOURL4=$REPOURL4" >> ${PKGRC}
  1114. # seach settings
  1115. echo "PKGSEARCH=\"$PKGSEARCH\"" >> ${PKGRC}
  1116. echo "PKGSEARCHEXACT=\"$PKGSEARCHEXACT\"" >> ${PKGRC}
  1117. echo "DEPSEARCH=\"$DEPSEARCH\"" >> ${PKGRC}
  1118. echo "DEPSEARCHEXACT=\"$DEPSEARCHEXACT\"" >> ${PKGRC}
  1119. # multiple repo settings
  1120. echo "REPOFALLBACKS=\"$REPOFALLBACKS\"" >> ${PKGRC}
  1121. echo "PKGSCOPE=\"$PKGSCOPE\"" >> ${PKGRC}
  1122. echo "DEPSCOPE=\"$DEPSCOPE\"" >> ${PKGRC}
  1123. echo "BLEDGE=\"$BLEDGE\"" >> ${PKGRC}
  1124. echo "RDCHECK=\"$RDCHECK\"" >> ${PKGRC} #150813
  1125. echo "AUTOCLEAN=\"$AUTOCLEAN\"" >> ${PKGRC}
  1126. echo "BUILDTOOL=$BUILDTOOL" >> ${PKGRC}
  1127. }
  1128.  
  1129.  
  1130. show_config(){ # show config settings from ~/.pkg/pkgrc FUNCLIST
  1131. . ${PKGRC}
  1132.  
  1133. # set default values
  1134. PKGSCOPETXT="Search for packages in all repos."
  1135. DEPSCOPETXT="Search for dependencies in all repos."
  1136. FALLBACKTXT="Accessing other repos in this order:"
  1137. FALLBACKTXT="$FALLBACKTXT\n`repo_list | grep -v "^$REPONAME" | tr '\n' ' ' | sed -e "s/ /, /g" -e "s/, $//" | fold -w 54 -s`"
  1138. RDCHECKTXT="Recursive dependency search is NOT enabled."
  1139.  
  1140. # update with values from PKGRC file
  1141. [ "$PKGSCOPE" = "one" ] && PKGSCOPETXT="Search for packages in current repo only."
  1142. [ "$DEPSCOPE" = "one" ] && DEPSCOPETXT="Search for dependencies in current repo only."
  1143. [ "$BLEDGE" = "yes" ] && FALLBACKTXT="Bleeding-edge enabled - searching all repos, for the latest packages versions.."
  1144. [ "$RDCHECK" = "yes" ] && RDCHECKTXT="Recursive dependency search is enabled."
  1145.  
  1146. # print current Pkg config
  1147. echo "==========================="
  1148. echo "$APPNAME $APPVER"
  1149. echo "==========================="
  1150. echo "Config file: $PKGRC"
  1151. echo "Packages dir: ${WORKDIR}/"
  1152. echo "Autoclean: $AUTOCLEAN"
  1153. echo
  1154. echo "Search settings:"
  1155. #echo "- $HIDEINSTALLEDTXT"
  1156. echo "- $PKGSCOPETXT"
  1157. echo "- $DEPSCOPETXT"
  1158. echo "- $RDCHECKTXT"
  1159. echo
  1160. echo "Package Compiling backend:"
  1161. echo "- $BUILDTOOL"
  1162. echo
  1163. echo "Repo details:"
  1164. echo "- Current Repo: $REPONAME"
  1165. echo "- Package type: $EX"
  1166. echo "- Packages: $(cat "$REPO_DB_FILE_DIR/${REPOFILE}" | wc -l)"
  1167. echo "- Mirror 1: `echo $REPOURL1 | cut -f1-3 -d'/' `"
  1168. [ "$REPOURL2" != "" ] && echo "- Mirror 2: `echo $REPOURL2 | cut -f1-3 -d'/' `"
  1169. [ "$REPOURL3" != "" ] && echo "- Mirror 3: `echo $REPOURL3 | cut -f1-3 -d'/' `"
  1170. [ "$REPOURL4" != "" ] && echo "- Mirror 4: `echo $REPOURL4 | cut -f1-3 -d'/' `"
  1171. echo
  1172. echo -e "$FALLBACKTXT"
  1173. }
  1174.  
  1175.  
  1176. # repo and source funcs
  1177.  
  1178. get_repo_info(){ # return details of given repo name ($1) FUNCLIST
  1179. [ ! "$1" -o "$1" = "-" ] && print_usage repo-info && exit 1
  1180.  
  1181. REPOLINE="`list_all_sources $1 | sort -u | uniq`" #170214 always get latest info, not info from rcfile
  1182.  
  1183. # on first run, this might be needed to set the repo correctly
  1184. [ "$REPOLINE" = '' ] && REPOLINE="`list_all_sources noarch`"
  1185.  
  1186. REPONAME="`echo $REPOLINE | cut -f1 -d'|'`"
  1187. EX="`echo $REPOLINE | cut -f2 -d'|'`"
  1188. REPOFILE="`echo $REPOLINE | cut -f3 -d'|'`"
  1189. REPOURL1="`echo $REPOLINE | cut -f4 -d'|'`"
  1190. REPOURL2="`echo $REPOLINE | cut -f5 -d'|'`"
  1191. REPOURL3="`echo $REPOLINE | cut -f6 -d'|'`"
  1192. REPOURL4="`echo $REPOLINE | cut -f7 -d'|'`"
  1193. REPOFALLBACKS="`echo "$REPOLINE"| cut -f8 -d'|'`"
  1194. }
  1195.  
  1196.  
  1197. set_current_repo(){ # set the current repo to use, give repo name as $1 FUNCLIST
  1198.  
  1199. # print usage if no valid options
  1200. [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ] && print_usage repo && exit 1
  1201.  
  1202. # get repo details from rc file
  1203. . ${PKGRC}
  1204.  
  1205. # remove the default mirror tmp file, we're changing repo and mirrors
  1206. rm $TMPDIR/CURREPOURL 2>/dev/null
  1207.  
  1208. # remove old repo files list (used in list_source_files)
  1209. rm -f ${TMPDIR}/source_files 2>/dev/null
  1210.  
  1211. # if not updating the scopes or bleeding-edge,leave them as set in rcfile
  1212. [ "$PKGSCOPE" = "" ] && PKGSCOPE="$PKGSCOPE"
  1213. [ "$DEPSCOPE" = "" ] && DEPSCOPE="$DEPSCOPE"
  1214. [ "$BLEDGE" = "" ] && BLEDGE="$BLEDGE"
  1215.  
  1216. # if nothing was found in rcfile, we need to set to default
  1217. [ "`echo $PKGSCOPE | grep -E "^one\$|^all\$"`" = "" ] && PKGSCOPE="one"
  1218. [ "`echo $DEPSCOPE | grep -E "^one\$|^all\$"`" = "" ] && DEPSCOPE="one"
  1219. [ "$BLEDGE" = "" ] && BLEDGE="no"
  1220.  
  1221. # check if $1 is valid repo
  1222. if [ "$(LANG=C list_sources "$1")" != "" ]; then
  1223. # set repo details
  1224. LANG=C get_repo_info "$1"
  1225. LANG=C set_config #170213
  1226. LANG=C update_sources 1>/dev/null #update the order of sources to match new fallback list of new current repo
  1227. LANG=C print_repo_info "$1" #output msg, repo info
  1228. else
  1229. # not a valid repo, print message
  1230. echo "The name '$1' is not a valid repo name. These are:"
  1231. LANG=C repo_list #250613
  1232. fi
  1233. }
  1234.  
  1235.  
  1236. repo_list(){ # list names of all avail repos [optionally matching $1] FUNCLIST
  1237.  
  1238. # we need to list these repos in the order defined in the RC file
  1239. # so Pkg can 'fall back' to other repos in that order
  1240.  
  1241. # get current config
  1242. . ${PKGRC}
  1243.  
  1244. # set vars for this func
  1245. local list=''
  1246. local repo_file=''
  1247. local repo_names=`cut -f1 -d'|' ${HOME}/.pkg/sources`
  1248. local current_fallback_list=`grep "^$REPONAME|" ${HOME}/.pkg/sources | cut -f8 -d'|' | grep -v "^\$"`
  1249.  
  1250. # get current repo fallback list order.. note if repo not listed in fallback list, it will be appended after
  1251. for line in $current_fallback_list
  1252. do
  1253. # get the repo file
  1254. repo_file="`grep "^$line|" ${HOME}/.pkg/sources | cut -f3 -d'|'`"
  1255. # add it to the list
  1256. [ "$repo_file" != "" ] && list="$list$line "
  1257. done
  1258.  
  1259. # now add all other avail repos to the end of fallback list
  1260. for repo_name in $repo_names
  1261. do
  1262. #if not blank, not already in the repo list and not the current repo ($REPONAME from rc file) then add to list
  1263. [ "$repo_name" != "" -a "`echo "$list" | grep "$repo_name "`" = "" -a "$repo_name" != "$REPONAME" ] && list="$list$repo_name "
  1264. done
  1265.  
  1266. # list the current repo first
  1267. echo $REPONAME
  1268. # then the other repos
  1269. echo "$list" | tr ' ' '\n' | grep -v "^\$"
  1270. }
  1271.  
  1272.  
  1273. repo_file_list(){ # list available repo files, $1 optional FUNCLIST
  1274.  
  1275. # we need to list these repos in the order defined in the RC file
  1276. # so Pkg can 'fall back' to other repos in that order
  1277.  
  1278. # get current config
  1279. . ${PKGRC}
  1280.  
  1281. # set vars for this func
  1282. local list=''
  1283. local repo_file=''
  1284. local repo_files=`cut -f3 -d'|' ${HOME}/.pkg/sources`
  1285. local current_fallback_list=`grep "^$REPONAME|" ${HOME}/.pkg/sources | cut -f8 -d'|' | grep -v "^\$"`
  1286.  
  1287. # get current repo fallback list order.. note if repo not listed in fallback list, it will be appended after
  1288. for line in $current_fallback_list
  1289. do
  1290. # get the repo file
  1291. repo_file="`grep "^$line|" ${HOME}/.pkg/sources | cut -f3 -d'|'`"
  1292. # add it to the list
  1293. [ "$repo_file" != "" ] && list="$list$repo_file "
  1294. done
  1295.  
  1296. # now add all other avail repos to the end of fallback list
  1297. for repo_file in $repo_files
  1298. do
  1299. #if not blank, not already in the repo list and not the current repo ($REPONAME from rc file) then add to list
  1300. [ "$repo_file" != "" -a "`echo "$list" | grep "$repo_file "`" = "" -a "$repo_file" != "$REPOFILE" ] && list="$list$repo_file "
  1301. done
  1302.  
  1303. # list the current repo first
  1304. echo $REPOFILE
  1305. # then the other repos
  1306. echo "$list" | tr ' ' '\n' | grep -v "^\$"
  1307. }
  1308. declare -ga REPO_DB_PATHS
  1309. #mk_repo_file_list_arry(){
  1310.  
  1311. #REPO_DB_PATHS=()
  1312. #declare -A REPO_DB_PATHS
  1313.  
  1314. #Can't put the loop in the loop in a pipeline if you want to assign array values:
  1315. #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  1316. # repo_file_list |
  1317. while read REPO_FILE_NAME; do
  1318. #echo "REPO_FILE_NAME=$REPO_FILE_NAME"
  1319. RF_FILE_PATH="${ALL_REPO_DB_PATHS[$REPO_FILE_NAME]}"
  1320. if [ -e "$RF_FILE_PATH" ]; then
  1321. REPO_DB_PATHS+=( "$RF_FILE_PATH" )
  1322. fi
  1323. done < <( repo_file_list )
  1324. #echo "REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  1325. #echo "REPO_DB_PATHS_keys=${!ALL_REPO_DB_PATHS[@]}"
  1326. #}
  1327. #mk_repo_file_list_arry
  1328.  
  1329. dir2repo(){ # create a native-Puppy repo from a dir of packages FUNCLIST
  1330.  
  1331. # exit if not a valid directory
  1332. if [ ! -d "$1" ]; then
  1333. print_usage dir2repo && exit 1
  1334. fi
  1335.  
  1336. local filename=''
  1337. local filepath=''
  1338. local fileext=''
  1339. local prevext=''
  1340. local repo_name
  1341.  
  1342. # get the repo directory
  1343. local repo_dir="$(realpath "$1")"
  1344.  
  1345. # create a temp repo_file name
  1346. local repo_file="${repo_dir}/Packages-$DISTRO_BINARY_COMPAT-$DISTRO_COMPAT_VERSION"
  1347.  
  1348. # remove any old files
  1349. rm "${repo_dir}/install" "${repo_dir}/Packages-"* "$repo_file" &>/dev/null
  1350.  
  1351. echo
  1352. echo "Creating repo from contents of: $repo_dir"
  1353. echo
  1354.  
  1355. # exit if we encounter multiple file extensions
  1356. for file in $(find "$repo_dir" -maxdepth 5 -type f)
  1357. do
  1358. filename=$(basename $file)
  1359. fileext="$(get_pkg_ext $filename)"
  1360. if [ "$fileext" != "$prevext" ] && [ "$prevext" != "" ]; then
  1361. echo "All packages must have the same extension."
  1362. echo "Extensions '$fileext' and '$prevext' don't match."
  1363. echo "Package '$filename' needs to be converted to $prevext or removed."
  1364. exit 1
  1365. fi
  1366. prevext="$fileext"
  1367. done
  1368.  
  1369.  
  1370. # get the packages in $repo_dir
  1371. local package_list="$(find "$repo_dir" -maxdepth 5 -type f | grep -v ^Packages | grep -v "^install$")"
  1372.  
  1373. if [ "$package_list" = "" ]; then
  1374. echo "No packages found in ${repo_dir}!"
  1375. exit 1
  1376. fi
  1377.  
  1378. # for each file in the repo dir
  1379. for file in $package_list
  1380. do
  1381. # skip if not a recognised package type
  1382. [ "$(is_local_pkg "$file")" != true ] && continue
  1383.  
  1384. # get the package info
  1385. filename=$(basename $file)
  1386. fileext="$(get_pkg_ext $filename)"
  1387. filepath="$(realpath $(dirname $file))"
  1388. pathname="$(dirname ${filepath})"
  1389. repopath="$(echo $filepath | sed -e "s#${repo_dir}##" -e "s/^\///")"
  1390. pkgname=$(basename $filename .$fileext)
  1391. pkgnameonly="$(get_pkg_name_only $pkgname)"
  1392. pkgversion="$(get_pkg_version $pkgname)"
  1393. pkgcat="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f5 -d'|')"
  1394. pkgsize="$(du "$file" 2>/dev/null | cut -f1)K"
  1395. [ "$pkgsize" = "" ] && pkgsize="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f6 -d'|')"
  1396. pkgdeps="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f9 -d'|')"
  1397. # dont include deps if we're adding a combined package + plus deps (they have $CP_SUFFIX in the name)
  1398. [ "$(echo "$filename" | grep "$CP_SUFFIX")" != "" ] && pkgdeps=''
  1399. pkgdesc="$(grep -m1 "|$pkgnameonly|" "$REPO_DB_FILE_DIR"/Packages-* | cut -f10 -d'|')"
  1400. pkgdistro="$DISTRO_BINARY_COMPAT"
  1401. pkgdistroversion="$DISTRO_COMPAT_VERSION"
  1402.  
  1403. # if we don't have the required package info, dont add it to the repo file
  1404. [ "$pkgname" = "" -o "$pkgnameonly" = "" -o "$filename" = "" ] && continue
  1405.  
  1406. # add this package to the repo file
  1407. echo "$pkgname|$pkgnameonly|$pkgversion||${pkgcat:-BuildingBlock}|$pkgsize|$repopath|$filename|$pkgdeps|${pkgdesc:-No description}|$pkgdistro|$pkgdistroversion|" >> "$repo_file"
  1408. done
  1409.  
  1410. if [ ! -f "$repo_file" ]; then
  1411. echo "Error: file '$repo_file' not created."
  1412. exit 1
  1413. fi
  1414.  
  1415. echo "Step 1 of 3: CHOOSE A REPO NAME"
  1416. echo "(something like 'distroversion-username-repo', such as 'bionic-bob-main' or 'stretch-sc0ttman-games')"
  1417. echo
  1418. bash -c 'read -e -r -p "Type a repo name and hit ENTER: " repo_name; echo "$repo_name" > /tmp/pkg/repo_name'
  1419. repo_name="$(cat /tmp/pkg/repo_name)"
  1420.  
  1421. # rename the repo file to the new name
  1422. mv "$repo_file" "${repo_dir}/Packages-${DISTRO_BINARY_COMPAT:-puppy}-$repo_name"
  1423. repo_file="${repo_dir}/Packages-${DISTRO_BINARY_COMPAT:-puppy}-$repo_name"
  1424.  
  1425. # build repo entry
  1426. local repo_entry="$repo_name|$fileext|$repo_file|$repo_url||||$repo_fallbacks"
  1427.  
  1428. # get the URL where the repo file and packages will live
  1429. echo
  1430. echo "Step 2 of 3: ADD THE REPO URL"
  1431. echo "(the full URL where you will upload your repo file and packages)"
  1432. echo
  1433. bash -c 'read -e -r -i "http://" -p "Type a repo URL and hit ENTER: " mirror1; echo "$mirror1" > /tmp/pkg/mirror1'
  1434. mirror1="$(cat /tmp/pkg/mirror1)"
  1435.  
  1436. # get fallback repos list
  1437. echo
  1438. echo "Step 3 of 3: ADD FALLBACK REPOS"
  1439. echo "(the other repos to fall back to when looking for dependencies)"
  1440. echo
  1441. 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'
  1442. fallback_repos="$(cat /tmp/pkg/fallback_repos)"
  1443.  
  1444. # remove the tmp files which store user input, they're no longer needed
  1445. rm /tmp/pkg/repo_name /tmp/pkg/mirror1 /tmp/pkg/fallback_repos
  1446.  
  1447. # add a trailing slash to the URL
  1448. if [ "$(echo "${mirror1}" | grep "/$")" = "" ]; then
  1449. mirror1="${mirror1}/"
  1450. fi
  1451.  
  1452. # create repo installer file in $repo_dir
  1453. echo "REPONAME=$repo_name
  1454. EX=$fileext
  1455. REPOFILE=$(basename $repo_file)
  1456. URL1=${mirror1}
  1457. URL2=''
  1458. URL3=''
  1459. URL4=''
  1460. FALLBACKS='$fallback_repos'" > "${repo_dir}/install"
  1461.  
  1462. # print final message
  1463. echo
  1464. echo -e "${green}Success${endcolour}: Repo ${yellow}$repo_name${endcolour} created."
  1465. echo
  1466. echo -e "You should upload everything in ${lightblue}$repo_dir${endcolour} to:"
  1467. echo
  1468. echo " $mirror1"
  1469. echo
  1470. echo "You (and anyone else) can then install the repo using:"
  1471. echo
  1472. echo " pkg add-repo ${mirror1}"
  1473. echo
  1474. echo -e "NOTE: You can edit the ${yellow}install${endcolour} and ${yellow}$(basename $repo_file)${endcolour}"
  1475. echo "files in a text editor, before you upload your new repo."
  1476. echo
  1477. }
  1478.  
  1479.  
  1480. add_pkg_repo() { # add a Pkg-created repo, called by add_repo() FUNCLIST
  1481. [ ! "$1" ] && return 1
  1482. mkdir -p /tmp/pkg/
  1483. # this is probably a Pkg created Puppy repo, get info from 'install' file
  1484. rm /tmp/pkg/repo_info &>/dev/null
  1485.  
  1486. # check if the 'install' file we need exists
  1487. wget --no-check-certificate -O "/tmp/pkg/repo_info" -4 "$1" &>/dev/null
  1488. if [ ! -f /tmp/pkg/repo_info ]; then
  1489. echo "Error: Repo installer file not downloaded!"
  1490. return 1
  1491. elif [ "$(grep -m1 "^REPONAME" /tmp/pkg/repo_info 2>/dev/null)" = "" ]; then
  1492. echo "Error: invalid repo installer file"
  1493. return 1
  1494. fi
  1495.  
  1496. # build a valid repo entry for the ~/.pkg/sources* files
  1497. # (must have some fallbacks, strip quotes, newlines, no trailing pipes)
  1498. local repo_entry="$(cat /tmp/pkg/repo_info \
  1499. | sed -e "s/FALLBACKS=''/FALLBACKS='noarch common32'/" -e 's/.*=//g' \
  1500. | tr -d '"' \
  1501. | tr -d "'" \
  1502. | tr '\n' '|' \
  1503. | head -c -1)"
  1504.  
  1505. if [ "$repo_entry" = "" ]; then
  1506. echo "Error: repo entry not created."
  1507. return 1
  1508. fi
  1509.  
  1510. # get repo info
  1511. local repo_name="$(echo "$repo_entry" | cut -f1 -d'|')"
  1512. local repo_filename="$(echo "$repo_entry" | cut -f3 -d'|')"
  1513. local repo_file_url="$(echo ${1} | sed 's#/install$##')/${repo_filename}"
  1514.  
  1515. # download the repo file
  1516. wget --no-check-certificate -O "/tmp/pkg/$repo_filename" -4 "$repo_file_url" &>/dev/null
  1517. if [ -z /tmp/pkg/$repo_filename ] || [ ! -f /tmp/pkg/$repo_filename ]; then
  1518. echo "Error: Repo file $repo_filename not downloaded!"
  1519. return 1
  1520. fi
  1521.  
  1522. # install the repo file
  1523. mv /tmp/pkg/$repo_filename "$REPO_DB_FILE_DIR/$repo_filename"
  1524. RETVAL=$?
  1525.  
  1526. # add repo entry to ~/.pkg/sources
  1527. echo
  1528. add_source "${repo_entry}"
  1529. echo
  1530.  
  1531. # refresh list of available repos
  1532. update_sources
  1533. echo
  1534. echo "Repo info:"
  1535. print_repo_info $repo_name
  1536. echo
  1537.  
  1538. if [ "$(cat ~/.pkg/sources 2>/dev/null | grep -m1 "^$repo_name|")" != "" ]; then
  1539. echo "Success! Repo added and available to use."
  1540. echo
  1541. echo "To use this repo, simply type the following and hit ENTER:"
  1542. echo " pkg repo $repo_name"
  1543. echo
  1544.  
  1545. # register as a user installed repo, so we can remove it later (using rm_repo)
  1546. touch ~/.pkg/sources-user
  1547. echo "$repo_entry" >> ~/.pkg/sources-user
  1548. local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1549. echo "$user_repos" > ~/.pkg/sources-user
  1550.  
  1551. fi
  1552.  
  1553. return $RETVAL
  1554. }
  1555.  
  1556.  
  1557. add_repo(){ # add Pkg/Ubuntu/Debian/Slackware third-party repos FUNCLIST
  1558.  
  1559. local slack_repo_url
  1560.  
  1561. if [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ]; then
  1562. print_usage add_repo && exit 1
  1563. fi
  1564.  
  1565. # work out which kind of repo we are processing
  1566. case "$1" in
  1567. 'http'*'/PACKAGES.TXT.gz'|'http'*'/PACKAGES.TXT')
  1568. # strip trailing /PACKAGES.TXT[.gz]
  1569. slack_repo_url="${1//PACKAGES.TXT.gz/}"
  1570. slack_repo_url="${slack_repo_url//\/.gz/}"
  1571. slack_repo_url="${slack_repo_url//.gz\//}"
  1572. slack_repo_url="${slack_repo_url//PACKAGES.TXT/}"
  1573. # add trailing slash, if needed
  1574. if [ "$(echo $slack_repo_url | grep '/$')" = '' ]; then
  1575. slack_repo_url="${slack_repo_url}/"
  1576. fi
  1577. slack2pup "$@"
  1578. retval=$?
  1579. if [ $retval -eq 0 ]; then
  1580. # register repo, so we know to update it in update_sources()
  1581. touch ~/.pkg/sources-user
  1582. echo "$repo_entry" >> ~/.pkg/sources-user
  1583. local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1584. echo "$user_repos" > ~/.pkg/sources-user
  1585.  
  1586. # register in a slack supported file too
  1587. mkdir -p /etc/slackpkg/
  1588. touch /etc/slackpkg/mirrors
  1589. echo "$slack_repo_url" >> /etc/slackpkg/mirrors
  1590. local slack_repos="$(sort -u /etc/slackpkg/mirrors | uniq)"
  1591. echo "$slack_repos" > /etc/slackpkg/mirrors
  1592. fi
  1593. ;;
  1594.  
  1595. 'http'*'/install')
  1596. add_pkg_repo "$1"
  1597. ;;
  1598.  
  1599. 'ppa:'*|'http://'*|'https://'*)
  1600. wget --quiet --timeout=2 --no-parent --spider "${1}install"
  1601. REPLY=$?
  1602. if [ "$REPLY" = 0 ]; then
  1603. add_pkg_repo "${1}install"
  1604. exit $?
  1605. fi
  1606.  
  1607. ppa2pup "$@"
  1608. retval=$?
  1609. if [ $retval -eq 0 ]; then
  1610. # register repo, so we know to update it in update_sources()
  1611. touch ~/.pkg/sources-user
  1612. echo "$repo_entry" >> ~/.pkg/sources-user
  1613. local user_repos="$(sort -u ~/.pkg/sources-user | uniq)"
  1614. echo "$user_repos" > ~/.pkg/sources-user
  1615.  
  1616. # register in an apt-supported file too
  1617. mkdir -p /etc/apt/
  1618. touch /etc/apt/sources.list
  1619. echo "deb $@" >> /etc/apt/sources.list
  1620. local deb_repos="$(sort -u /etc/apt/sources.list | uniq)"
  1621. echo "$deb_repos" > /etc/apt/sources.list
  1622. fi
  1623. ;;
  1624.  
  1625. *)
  1626. print_usage add_repo && exit 1
  1627. ;;
  1628.  
  1629. esac
  1630.  
  1631. }
  1632.  
  1633.  
  1634. rm_repo(){ # remove an installed repo by name ($1) FUNCLIST
  1635. if [ ! "$1" -o "$1" = "-" -o "$1" = "-h" -o "$1" = "--help" ]; then
  1636. print_usage rm_repo
  1637. exit 1
  1638. fi
  1639.  
  1640. # $1 must be a valid, installed repo name
  1641. if [ "$(repo_list | grep -m1 "^${1}$")" = "" ]; then
  1642. print_usage rm-repo
  1643. exit 1
  1644. fi
  1645.  
  1646. # get the repo file and URL of the given repo
  1647. local repo_file="$(grep "^$1" ~/.pkg/sources-all | cut -f3 -d'|' )"
  1648. local repo_url="$(grep "^$1" ~/.pkg/sources-all | cut -f4 -d'|')"
  1649.  
  1650. # dont allow removal of 'built in' repos, only user-added repos
  1651. 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)"
  1652. if [ "${matching_user_added_repos}" = "" ]; then
  1653. echo "You can only remove the repositories that you installed yourself."
  1654. echo -e "Use the command ${bold}pkg repo-list${endcolour} to see which repos are installed."
  1655. exit 1
  1656. fi
  1657.  
  1658. # dont allow removal of current repo
  1659. if [ "$REPONAME" = "$1" ]; then
  1660. echo "Can't remove current repo."
  1661. echo -e "Switch to another repo first using: ${bold}pkg repo REPONAME${endcolour}"
  1662. exit 1
  1663. fi
  1664.  
  1665. # remove the repo file
  1666. echo "Removing '$1'.. Please wait.."
  1667. [ -f "$REPO_DB_FILE_DIR/$repo_file" ] && rm "$REPO_DB_FILE_DIR/$repo_file"
  1668.  
  1669. # remove from sources
  1670. grep -v "^$1|" ~/.pkg/sources > /tmp/pkg/sources
  1671. grep -v "^$1|" ~/.pkg/sources-all > /tmp/pkg/sources-all
  1672. [ -f /tmp/pkg/sources-all ] && mv /tmp/pkg/sources-all ~/.pkg/sources-all
  1673. [ -f /tmp/pkg/sources ] && mv /tmp/pkg/sources ~/.pkg/sources
  1674.  
  1675. # remove from third-party lists
  1676. grep -v "|${repo_url}|" ~/.pkg/sources-user > /tmp/pkg/sources-user
  1677. grep -vE "$repo_url|${repo_name//*-/}" /etc/apt/sources.list > /tmp/pkg/sources.list
  1678. grep -v "$repo_url" /etc/slackpkg/mirrors > /tmp/pkg/mirrors
  1679. [ -f /tmp/pkg/sources-user ] && mv /tmp/pkg/sources-user ~/.pkg/sources-user
  1680. [ -f /tmp/pkg/sources.list ] && mv /tmp/pkg/sources.list /etc/apt/sources.list
  1681. [ -f /tmp/pkg/mirrors ] && mv /tmp/pkg/mirrors /etc/slackpkg/mirrors
  1682.  
  1683. if [ "$(repo_list | grep -m1 "^${1}$")" = "" ]; then
  1684. update_sources &>/dev/null
  1685. echo -e "${green}Success${endcolour}: Repo removed."
  1686. fi
  1687.  
  1688. }
  1689.  
  1690.  
  1691. add_source(){ # add a new repo to your repo 'sources' list FUNCLIST
  1692. [ ! "$1" \
  1693. -o "$1" = "-" \
  1694. -o "$1" = "-h" \
  1695. -o "$1" = "--help" \
  1696. -o "`echo "$1" | grep '|'`" = "" \
  1697. -o "`echo "$1" | cut -f2 -d'|'`" = "" \
  1698. -o "`echo "$1" | cut -f4 -d'|'`" = "" \
  1699. -o "`echo "$1" | cut -f8 -d'|'`" = "" ] && \
  1700. print_usage add_source && exit 1
  1701.  
  1702. # get repo file to add to sources
  1703. REPOTOADD="`echo $1 | cut -f1 -d'|'`"
  1704. REPOFILETOADD="`echo $1 | cut -f3 -d'|'`"
  1705.  
  1706. # do checks before adding repo (dont add duplicate, make sure file exists, etc)
  1707.  
  1708. # check if repo name already in sources-all
  1709. #if [ "`grep "^$REPOTOADD\$" ~/.pkg/sources-all`" != "" ] || \
  1710. # [ "`repo_list | grep "^$REPOTOADD\$"`" != "" ]; then
  1711. # echo "Repo with the name '$REPOTOADD' already in the list"
  1712. #fi
  1713.  
  1714. # check if repo filename already exists in sources-all
  1715. #if [ "`repo_file_list | grep -m1 "^$REPOFILETOADD\$"`" != "" ]; then
  1716. # echo "Repo with database file $PKGS_DIR/'$REPOFILETOADD' already in the list"
  1717. #fi
  1718.  
  1719. # check if the repo file exists in $PKGS_DIR
  1720. #if [ ! -f "`find $PKGS_DIR/ -name "$REPOFILETOADD"`" ]; then
  1721. # echo "The repo database file '$PKGS_DIR/$REPOFILETOADD' not found."
  1722. #fi
  1723.  
  1724. # add the repo to sources-all, if not already there
  1725. if [ "$(grep -m1 "^$REPOTOADD|" ${HOME}/.pkg/sources-all)" = "" ]; then
  1726. # all good, so add repo entry to sources-all
  1727. echo "$1" >> ${HOME}/.pkg/sources-all
  1728. fi
  1729.  
  1730. # update users repo sources to get the new repo
  1731. update_sources 1>/dev/null || { echo "Could not update repo sources."; exit 2; }
  1732.  
  1733. # print msg
  1734. echo "Repo '$REPOTOADD' added successfully."
  1735. }
  1736.  
  1737.  
  1738. update_sources(){ # create the list of available repos FUNCLIST
  1739.  
  1740. # get current repo values and Pkg settings
  1741. . ${PKGRC}
  1742.  
  1743. #list current repo first in sources
  1744. get_repo_info "${REPONAME:-noarch}"
  1745.  
  1746.  
  1747. # only add the current repo to the list of available sources if it exists
  1748. if [ "$(find "$REPO_DB_FILE_DIR" -iname "$REPOFILE" )" != '' ]; then
  1749. echo "$REPONAME|$EX|$REPOFILE|$REPOURL1|$REPOURL2|$REPOURL3|$REPOURL4|$REPOFALLBACKS" > ${HOME}/.pkg/sources
  1750. #elif [ "$(find "$(realpath "/var/packages/")" -iname "$REPOFILE" )" != '' ]; then
  1751. # echo "$REPONAME|$EX|$REPOFILE|$REPOURL1|$REPOURL2|$REPOURL3|$REPOURL4|$REPOFALLBACKS" > ${HOME}/.pkg/sources
  1752. fi
  1753.  
  1754.  
  1755. # get repos in order of fallbacks, pkg will then 'fall back' to each repo in that order
  1756. FALLBACKS="`grep -m1 "^${REPONAME}|" ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#' | cut -f8 -d'|'`"
  1757.  
  1758. # for each repo in fallback list
  1759. for FBACK in $REPOFALLBACKS; do
  1760. # dont add current repo, its already added
  1761. [ "$FBACK" = "$REPONAME" ] && continue
  1762.  
  1763. # check if repo is supported (has entries in sources-all)
  1764. LINE="`grep -m1 "^$FBACK|" ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#' | grep -v "^${REPONAME}|"`"
  1765. [ "$LINE" = "" ] && continue
  1766.  
  1767. # if repo is valid, add to users list of in-use repos (only valid repos from sources-all => sources)
  1768. if [ -f "$REPO_DB_FILE_DIR/`echo "$LINE" | cut -f3 -d'|'`" ]; then
  1769.  
  1770. if [ "$(grep -m1 "^$FBACK|" ${HOME}/.pkg/sources)" = "" ]; then
  1771. echo "Adding repo: `echo "$LINE"|cut -f1 -d'|'`.."
  1772. echo "$LINE" >> ${HOME}/.pkg/sources
  1773. fi
  1774. fi
  1775. done
  1776.  
  1777. cleaned_repo_list="`cat ${HOME}/.pkg/sources-all 2>/dev/null | grep -v ^'#'| grep -v ^$`"
  1778.  
  1779. # now add any other repos to the list (repos that are installed, but not added from fallback list)
  1780. echo "$cleaned_repo_list" | uniq | while read repo_entry
  1781. do
  1782. # dont add current repo, its already added
  1783. [ "`echo "$repo_entry" | cut -f1 -d'|'`" = "$REPONAME" ] && echo "Adding repo: $REPONAME.." && continue
  1784.  
  1785. # get the repo name
  1786. repo_name="`echo "$repo_entry"|cut -f1 -d'|'`"
  1787.  
  1788. # build the repo file (full path)
  1789. repo_file="$REPO_DB_FILE_DIR"/`echo "$repo_entry" | cut -f3 -d'|'`
  1790.  
  1791. # set a flag true if repo already in repo, false if not
  1792. already_in_repo=false
  1793. [ "`grep -m1 "^$repo_entry" ${HOME}/.pkg/sources 2>/dev/null`" != "" ] && already_in_repo=true
  1794.  
  1795. if [ -f "$repo_file" -a "$already_in_repo" = false ]; then
  1796. echo "Adding repo: $repo_name.."
  1797. echo "$repo_entry" >> ${HOME}/.pkg/sources
  1798. fi
  1799. done
  1800.  
  1801. # finished, print message
  1802. [ -f ${HOME}/.pkg/sources ] && echo "Sources updated." && . ${PKGRC}
  1803. }
  1804.  
  1805.  
  1806. update_repo(){ # update the current repo from a file stored online FUNCLIST
  1807.  
  1808. # check internet, net connection required
  1809. NET="`check_net`"; [ $NET -eq 1 ] && echo "You need an internet connection" && exit 1
  1810.  
  1811. # remove the repo update tmp file
  1812. rm -f $TMPDIR/update_repo_results 2>/dev/null
  1813.  
  1814. echo "Updating system repositories, please wait.."
  1815. echo
  1816.  
  1817. # use petget for now .. not ideal, petget wont accept $1 and only do that repo,
  1818. # also petget uses loads of other files pkg doesnt have/need (in $PKGS_DIR)
  1819. # also, we're limited to updating only the repos that petget supports, not all the ones Pkg supports..
  1820. # .. on the plus side petget code is way faster than mine
  1821. mkdir -p /var/local/petget/
  1822. chmod 777 /var/local/petget/
  1823. echo 'false' > /var/local/petget/db_verbose
  1824.  
  1825. # now call petget 0setup.. the ENV options prevent popup windows, and need for user input
  1826. DISPLAY='' SETUPCALLEDFROM=ppm /usr/local/petget/0setup &>$TMPDIR/update_repo_results
  1827.  
  1828. # if the repos updated ok
  1829. if [ $? -eq 0 ]; then
  1830. [ "`which logger`" != '' ] && logger "$0 Repo files updated by $APP $APPVER"
  1831. echo -e "Repo files updated:"
  1832. grep ^Processing $TMPDIR/update_repo_results | cut -f2 -d' '
  1833. # remove the repo update tmp file
  1834. rm -f $TMPDIR/update_repo_results 2>/dev/null
  1835. else
  1836. # repo did not update ok
  1837. error "Repos NOT updated."
  1838. cat $TMPDIR/update_repo_results | tail -20
  1839. exit 2
  1840. fi
  1841.  
  1842. # update Pkg created, user-added (third-party) repos
  1843. if [ -f ~/.pkg/sources-user ] || [ -f /etc/apt/sources.list ] || [ -f /etc/slackpkg/mirrors ]; then
  1844. echo
  1845. echo "Updating third-party repos.. This may take a while.."
  1846. echo
  1847. fi
  1848.  
  1849. # update Pkg created repos
  1850. if [ -f ~/.pkg/sources-user ]; then
  1851. pkg_repos="$(sort -u ~/.pkg/sources-user | grep -v ^$ | uniq | cut -f1 -d'|')"
  1852. for pkg_repo in $pkg_repos
  1853. do
  1854. local pkg_repo_url="$(cat ~/.pkg/sources-user | grep -m1 "^$pkg_repo|" | cut -f4 -d'|')"
  1855. echo "Processing: $pkg_repo_url"
  1856.  
  1857. ANSWER=y
  1858. if [ "$ASK" = true ]; then
  1859. bash -c 'read -r -N 1 -p "Update repo $pkg_repo? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1860. echo
  1861. ANSWER="$(cat /tmp/pkg/ANSWER)"
  1862. fi
  1863.  
  1864. if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ]; then
  1865. echo "Please wait..."
  1866. add_pkg_repo ${pkg_repo_url}install 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$pkg_repo'"
  1867. fi
  1868. done
  1869. fi
  1870.  
  1871. # update third-party non-native repos.. These repos comes 'from source',
  1872. # and are not in native Puppy format - they need to be downloaded, converted
  1873. # into the Puppy format, then installed... so this will be slow..
  1874. if [ -f /etc/apt/sources.list ] || [ -f /etc/slackpkg/mirrors ]; then
  1875.  
  1876. # update third-party Ubuntu/Debian repos
  1877. # search inside /etc/apt/sources.list /etc/apt/sources.list.d/*.list
  1878. # ...look for lines starting with 'deb ', ignore others
  1879. # ...(use grep -h, to remove the preppended filenames if grepping multiple files)
  1880. # ...remove any arch stuff from the entries, ppa2pup will handle that,
  1881. # ...convert spaces to | chars, so we can process each line as a whole later
  1882. local apt_sources_list="$(grep -h '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null \
  1883. | sed \
  1884. -e "s/^deb //g" \
  1885. -e "s/^tor+//g" \
  1886. -e 's/\[arch=[a-z,0-9].*\] //g' \
  1887. -e 's/ /|/g'\
  1888. )"
  1889.  
  1890. # for each repo in $apt_sources_list, use `ppa2pup` to update the repo
  1891. for line in $apt_sources_list
  1892. do
  1893. [ "$line" = "" ] && continue
  1894. [ "$line" = "\n" ] && continue
  1895.  
  1896. local ppa_repo_url="$(echo ${line//|/ } | cut -f1 -d" ")"
  1897. local ppa_repo_name=$(cat ~/.pkg/sources-all | grep -m1 $ppa_repo_url | cut -f1 -d'|')
  1898.  
  1899. # if a PPA repo, get a user-friendly repo name from the /etc/sources.list entry
  1900. if [ "$ppa_repo_name" = "" ]; then
  1901. ppa_repo_name="$(echo ${line} | cut -f3 -d'|')-$(echo $line | cut -f2 -d':' | cut -f1 -d '/' | tr -d '-' | tr -d '_')"
  1902. fi
  1903.  
  1904. echo
  1905. echo "Processing: ${line//|/ }"
  1906.  
  1907. ANSWER=y
  1908. if [ "$ASK" = true ]; then
  1909. # ask user to update repo
  1910. bash -c 'read -r -N 1 -p "Update repo $ppa_repo_name? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1911. echo
  1912. ANSWER="$(cat /tmp/pkg/ANSWER)"
  1913. fi
  1914.  
  1915. if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ]; then
  1916. echo "Please wait..."
  1917. ppa2pup ${line//|/ } 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$ppa_repo_name'"
  1918. retval=$?
  1919. fi
  1920. done
  1921.  
  1922. # update third-party Slackware repos
  1923. if [ -f /etc/slackpkg/mirrors ]; then
  1924. local slack_repos="$(sort -u /etc/slackpkg/mirrors | uniq)"
  1925. local slack_repo_url=""
  1926.  
  1927. for slack_repo in $slack_repos
  1928. do
  1929. slack_repo_url="${slack_repo//PACKAGES.TXT.gz/}"
  1930. slack_repo_url="${slack_repo_url//\/.gz/}"
  1931. slack_repo_url="${slack_repo_url//.gz\//}"
  1932. slack_repo_url="${slack_repo_url//PACKAGES.TXT/}"
  1933.  
  1934. # add trailing slash, if needed
  1935. if [ "$(echo $slack_repo_url | grep '/$')" = '' ]; then
  1936. slack_repo_url="${slack_repo_url}/"
  1937. fi
  1938.  
  1939. local slack_repo_name=$(cat ~/.pkg/sources-all | grep -m1 $slack_repo_url | cut -f1 -d'|')
  1940.  
  1941. echo
  1942. echo "Processing: $slack_repo_url"
  1943.  
  1944. ANSWER=y
  1945. if [ "$ASK" = true ]; then
  1946. # ask user to update repo
  1947. bash -c 'read -r -N 1 -p "Update repo '"$slack_repo_name"'? [y/n] " ANSWER; echo $ANSWER > /tmp/pkg/ANSWER'
  1948. echo
  1949. ANSWER="$(cat /tmp/pkg/ANSWER)"
  1950. fi
  1951.  
  1952. if [ "$ANSWER" = 'y' ] || [ "$ANSWER" = 'Y' ]; then
  1953. echo "Please wait..."
  1954. slack2pup "${slack_repo_url}/PACKAGES.TXT" $slack_repo_name 1>/dev/null && echo -e "${green}Success${endcolour}: Updated repo '$slack_repo_name'"
  1955. fi
  1956. done
  1957. fi
  1958. fi
  1959.  
  1960. echo
  1961. exit 0
  1962.  
  1963. }
  1964.  
  1965.  
  1966. list_sources(){ # return available (matching) repos (~/.pkg/sources) FUNCLIST
  1967. grep -m1 "^$1" ${HOME}/.pkg/sources ${HOME}/.pkg/sources-user | cut -f2-99 -d':' | uniq
  1968. }
  1969.  
  1970.  
  1971. list_all_sources(){ # return all (or matching) repos (~/.pkg/sources-all) FUNCLIST
  1972. grep -m1 "^$1" ${HOME}/.pkg/sources-all ${HOME}/.pkg/sources-user | cut -f2-99 -d':' | uniq
  1973. }
  1974.  
  1975.  
  1976. convert_repofile(){ # convert repo files formats (pre-woof/post-woof) FUNCLIST
  1977.  
  1978. # get the file name (FILENAME) and full path (FILE)
  1979. FILENAME="`basename "$1"`"
  1980. FILE="${CURDIR}/${FILENAME}"
  1981.  
  1982. # check for valid options
  1983. [ ! -f "$FILE" ] && print_usage repo-convert && exit 1
  1984.  
  1985. # dont replace repo unless -f was given
  1986. [ "$FORCE" != true -a -f "$REPO_DB_FILE_DIR/${FILENAME}" ] && echo "File '$REPO_DB_FILE_DIR/$FILENAME' already exists." && exit 1
  1987.  
  1988. # remove tmp files
  1989. rm $TMPDIR/$FILENAME &>/dev/null
  1990. rm $TMPDIR/${FILENAME}_subdirs &>/dev/null
  1991.  
  1992. # check repo file format (woof or pre-woof)
  1993. if [ -f "$FILE" -a "`cat "$FILE" | head -1 | grep -m1 '^"'`" = "" ]; then #if is a new format #'
  1994.  
  1995. # convert woof repo file to pre-woof repo file.. takes ages..
  1996. echo "Converting '${FILE}' to pre-woof format.. This might take a while.."
  1997. cat "$FILE" | while read LINE
  1998. do
  1999. PKGNAME="`echo $LINE| cut -f1 -d'|'`"
  2000. PKGNAME1=''
  2001. # we need to get the package name, try lots of different extensions
  2002. [ "`echo $PKGNAME1 | grep ".deb\$"`" != "" ] && PKGNAME1="`echo $LINE| cut -f8 -d'|'`"
  2003. [ "`echo $PKGNAME1 | grep ".deb\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .deb`"
  2004. [ "`echo $PKGNAME1 | grep ".rpm\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .rpm`"
  2005. [ "`echo $PKGNAME1 | grep ".txz\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .txz`"
  2006. [ "`echo $PKGNAME1 | grep ".tgz\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .tgz`"
  2007. [ "`echo $PKGNAME1 | grep ".tar.xz\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .tar.xz`"
  2008. [ "`echo $PKGNAME1 | grep ".tar.gz\$"`" != "" ] && PKGNAME="`basename $PKGNAME1 .tar.gz`"
  2009. # get size
  2010. SIZE=" `echo $LINE| cut -f6 -d'|'`"
  2011. # get category
  2012. CAT="`echo $LINE| cut -f5 -d'|'`"
  2013. #150813 remove extra categories .. example 'Setup;Installation' .. remove 'Installation'
  2014. [ "`echo "$CAT" | grep ';'`" != "" ] && CAT="`echo "$CAT" | cut -f1 -d';'`"
  2015. # get sub dir in repo
  2016. SUBDIR="`echo $LINE| cut -f7 -d'|'`" #150213
  2017. # get deps
  2018. DEPS=" `echo $LINE| cut -f9 -d'|'| grep '+'`"
  2019. # get desc
  2020. DESC="`echo $LINE| cut -f10 -d'|'`"
  2021. # add repo entry to tmp file
  2022. [ "$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
  2023. #150213 now do subdirs... slow..
  2024. [ "`echo $SUBDIR | grep "/"`" != "" -a "`echo $SUBDIR | grep -i pet_packages`" = "" ] && echo "$PKGNAME|/$SUBDIR" >> $TMPDIR/${FILENAME}_subdirs
  2025. done
  2026. # done making a pre-woof repo file, print message
  2027. [ -f $TMPDIR/$FILENAME ] && echo "Finished converting $FILENAME to pre-woof format." || exit 1
  2028.  
  2029. else
  2030.  
  2031. # convert pre-woof repo file to woof repo file.. takes ages..
  2032. echo "Converting '$FILENAME' to a 'woof' compatible repo file. This could take a while..."
  2033.  
  2034. # parse a pre-woof repo file
  2035. cat "$FILE" | while read LINE
  2036. do
  2037. PKGNAME='' PKGNAMEONLY='' PKGVER='' SIZE='' CAT='' DEPS='' BUILD='' SUBDIR='' PKGEXT='.pet' DESC=''
  2038.  
  2039. PKGNAME="`echo "$LINE" | cut -d'"' -f2`" #'micro
  2040. [ "`echo $PKGNAME | grep ".deb\$"`" != "" ] && PKGEXT='.deb' && PKGNAME="`basename $PKGNAME1 .deb`"
  2041. [ "`echo $PKGNAME | grep ".pet\$"`" != "" ] && PKGEXT='.pet' && PKGNAME="`basename $PKGNAME1 .pet`"
  2042. [ "`echo $PKGNAME | grep ".rpm\$"`" != "" ] && PKGEXT='.rpm' && PKGNAME="`basename $PKGNAME1 .rpm`"
  2043. [ "`echo $PKGNAME | grep ".tcz\$"`" != "" ] && PKGEXT='.tcz' && PKGNAME="`basename $PKGNAME1 .tcz`"
  2044. [ "`echo $PKGNAME | grep ".tgz\$"`" != "" ] && PKGEXT='.tgz' && PKGNAME="`basename $PKGNAME1 .tgz`"
  2045. [ "`echo $PKGNAME | grep ".txz\$"`" != "" ] && PKGEXT='.txz' && PKGNAME="`basename $PKGNAME1 .txz`"
  2046. [ "`echo $PKGNAME | grep ".tar.gz\$"`" != "" ] && PKGEXT='.tar.gz' && PKGNAME="`basename $PKGNAME1 .tar.gz`"
  2047. [ "`echo $PKGNAME | grep ".tar.xz\$"`" != "" ] && PKGEXT='.tar.xz' && PKGNAME="`basename $PKGNAME1 .tar.xz`"
  2048. [ "`echo $PKGNAME | grep ".pkg.tar.gz\$"`" != "" ] && PKGEXT='.pkg.tar.gz' && PKGNAME="`basename $PKGNAME1 .pkg.tar.gz`"
  2049. [ "`echo $PKGNAME | grep ".pkg.tar.xz\$"`" != "" ] && PKGEXT='.pkg.tar.xz' && PKGNAME="`basename $PKGNAME1 .pkg.tar.xz`"
  2050.  
  2051. # get pkg name only .. without versions or suffix
  2052. PKGNAME_ONLY="`echo "${PKGNAME}" | sed -e 's/-[0-9.]*/-/g' -e 's/-$//'`"
  2053. # if that didnt work, use the old method
  2054. if [ "$PKGNAME_ONLY" = '' -o "$PKGNAME_ONLY" = "$PKGNAME" ]; then
  2055. # get pkg name without version
  2056. PKGNAMEONLY="`echo $PKGNAME | cut -d'-' -f1`"
  2057. fi
  2058. PKGNAME_ONLY="${PKGNAME_ONLY//-*/}"
  2059.  
  2060. # get pkg version
  2061. PKGVER="`LANG=C echo "$LINE" | sed -e 's/^[^0-9]*-//g' | cut -f1 -d'_' | cut -f1 -d'-'`"
  2062. # get pkg size
  2063. SIZE="`echo $LINE| cut -d'"' -f6 | cut -d' ' -f3`" #'micro
  2064. SIZE=${SIZE## }
  2065. SIZE=${SIZE%% }
  2066. # must check again if pkg had no deps
  2067. [ "$SIZE" = "" ] && SIZE=" `echo $LINE| cut -d'"' -f6|cut -d' ' -f2`"
  2068. # get pkg category
  2069. CAT="`echo $LINE | cut -d'"' -f6 | cut -d' ' -f1`"
  2070. # remove extra categories
  2071. [ "`echo "$CAT" | grep ';'`" != "" ] && CAT="`echo "$CAT" | cut -f1 -d';'`"
  2072. # get pkg deps
  2073. DEPS="`echo "$LINE" | cut -d'"' -f6 | cut -d' ' -f2 | grep ^'+'`"
  2074. DESC="`echo "$LINE" | cut -f10 -d'|'`" #'micro
  2075. # build the woof compatible repo file
  2076. [ "$PKGNAME" != "" ] && echo "$PKGNAME|$PKGNAMEONLY|$VER|$BUILD|$CAT|$SIZE|$SUBDIR|${PKGNAME}${PKGEXT}|$DEPS|$DESC|$DISTRO_BINARY_COMPAT|$DISTRO_COMPAT_VERSION||" >> $TMPDIR/$FILENAME
  2077. done
  2078. #done making a woof repo file, print message
  2079. [ -f $TMPDIR/$FILENAME ] && echo "Finished converting $FILENAME to woof format." || exit 1
  2080. fi
  2081.  
  2082. # if we are updating the repo, we dont wanna install the converted file straight over
  2083. # the actual repo file, we wanna parse it for new pkgs and add only those
  2084. if [ "$2" != "for_repo_update" ]; then
  2085. # we converted a repo that we actually wanna install, so install it
  2086. mv $TMPDIR/$FILENAME "$REPO_DB_FILE_DIR/$FILENAME"
  2087. mv $TMPDIR/${FILENAME}_subdirs "$REPO_DB_FILE_DIR/${FILENAME}_subdirs" 2>/dev/null
  2088. echo "Repo file '$REPO_DB_FILE_DIR/$FILENAME' created."
  2089. update_sources #210613 update the list of sources after adding the newly converted repo
  2090. #exit 0
  2091. else
  2092. mv "$TMPDIR/$FILENAME" "$REPO_DB_FILE_DIR/$FILENAME"
  2093. fi
  2094. }
  2095.  
  2096.  
  2097. print_repo_info(){ # get repo settings, return current repo name FUNCLIST
  2098.  
  2099. # get latest repo info (from sources file), or from PKGRC if that fails
  2100. [ "$1" ] && get_repo_info "$1" || . ${PKGRC}
  2101.  
  2102. local pkg_count=$(cat "$REPO_DB_FILE_DIR/${REPOFILE}" | wc -l)
  2103.  
  2104. # output the repo info
  2105. echo "- Repo: $REPONAME"
  2106. echo "- Repo file: $REPOFILE"
  2107. echo "- Package Type: $EX"
  2108. echo "- Packages: $pkg_count"
  2109. echo "- URL Mirror 1: `echo $REPOURL1 | cut -f1-3 -d'/'`"
  2110. [ "$REPOURL2" != "" ] && echo "- URL Mirror 2: `echo $REPOURL2 | cut -f1-3 -d'/'`"
  2111. [ "$REPOURL3" != "" ] && echo "- URL Mirror 3: `echo $REPOURL3 | cut -f1-3 -d'/'`"
  2112. [ "$REPOURL4" != "" ] && echo "- URL Mirror 4: `echo $REPOURL4 | cut -f1-3 -d'/'`"
  2113. echo
  2114. echo "- Fall back to:`echo $REPOFALLBACKS | fold -w 50 -s | sed -e "s/ /, /g" -e "s/^/ /g"`"
  2115. }
  2116.  
  2117.  
  2118.  
  2119. # pkg search funcs
  2120.  
  2121. hide_blacklisted_pkgs_from_search_results(){ # hide BUILTIN and installed pkgs from searches NOLIST
  2122.  
  2123. # dont hide package if using --force (the user may want to force a re-install of already installed pkg, for example)
  2124. [ "$FORCE" = true ] && return 0
  2125.  
  2126. # get pkg names (generic names, no versions) of all blacklisted packages in pipe delimited list
  2127. blacklisted_pkgs_list="$(echo $PKG_NAME_IGNORE | sed -e 's/ /|/g')"
  2128.  
  2129. # remove blacklisted packages from search list
  2130. cat $TMPDIR/pkglist | grep -v -E "'$blacklisted_pkgs_list'" > $TMPDIR/pkglist_without_blacklisted
  2131. mv $TMPDIR/pkglist_without_blacklisted $TMPDIR/pkglist
  2132.  
  2133. # clean up tmp files
  2134. rm $TMPDIR/pkglist_* &>/dev/null
  2135. }
  2136.  
  2137.  
  2138. hide_installed_pkgs_from_search_results(){ # hide BUILTIN and installed pkgs from searches NOLIST
  2139.  
  2140. # dont hide package if using --force (the user may want to force a re-install of already installed pkg, for example)
  2141. [ "$FORCE" = true ] && return 0
  2142.  
  2143. # reset tmp file
  2144. rm $TMPDIR/pkglist_inst &>/dev/null
  2145.  
  2146. # get pkg names (generic names, no versions) of all installed pkgs (builtins, devx and user installed)
  2147. inst_pkg_list="`cut -f1 -d'|' "$USER_INST_PKGS_FILE" \
  2148. "$DEVX_INST_PKGS_FILE" \
  2149. "$WOOF_INST_PKGS_FILE" 2>/dev/null \
  2150. | grep -v ^$ \
  2151. | tr '\n' '|' \
  2152. | sed -e "s/||/|/g" \
  2153. | sed -e "s/|\$//g"`"
  2154.  
  2155. # remove woof and user installed packages from search list
  2156. cat $TMPDIR/pkglist | grep -v -E "'$inst_pkg_list'" > $TMPDIR/pkglist_without_inst
  2157. mv $TMPDIR/pkglist_without_inst $TMPDIR/pkglist
  2158.  
  2159. # clean up tmp files
  2160. rm $TMPDIR/pkglist_* &>/dev/null
  2161. }
  2162.  
  2163.  
  2164. list_pkg_names(){ # list pkg names in current repo only ($1 is optional filter) FUNCLIST
  2165.  
  2166. # remove any previous searches
  2167. rm $TMPDIR/pkglist* 2>/dev/null
  2168.  
  2169. # get current repo ($REPOFILE)
  2170. . ${PKGRC}
  2171.  
  2172. # create the search results
  2173. cut -f1 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$1" > $TMPDIR/pkglist
  2174.  
  2175. # filter out builtin and user installed packages
  2176. if [ $HIDE_INSTALLED = true ]; then
  2177. hide_installed_pkgs_from_search_results
  2178. fi
  2179.  
  2180. hide_blacklisted_pkgs_from_search_results
  2181.  
  2182. # support pkg name aliases in finding packages
  2183. if [ $NO_ALIASES = false ]; then
  2184. local ALIAS_LIST
  2185. local ALIAS
  2186. local ALIAS_RES
  2187. # if we have some results to parse
  2188. if [ "$1" != "" -a -f $TMPDIR/pkg_aliases ]; then
  2189. # get the list of aliases
  2190. ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases 2>/dev/null | tr ',' ' '`";
  2191. # for each alias
  2192. echo $ALIAS_LIST | while read ALIAS
  2193. do
  2194. [ "$ALIAS" = '' ] && continue
  2195. # get the match from the current repo (if any)
  2196. ALIAS_RES="`LANG=C cut -f1 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$ALIAS"`" #'
  2197. [ ! "$ALIAS_RES" ] && ALIAS_RES="`LANG=C cut -f2 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$ALIAS"`" #'
  2198. # if the repo match was found in the search results
  2199. if [ "$ALIAS_RES" != "" ]; then
  2200. # add the alias results to the search results
  2201. echo "$ALIAS_RES" >> $TMPDIR/pkglist
  2202. fi
  2203. done # for each alias
  2204. # sort and clean the search results
  2205. LANG=C cat $TMPDIR/pkglist | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq > $TMPDIR/pkglist1
  2206. # replace the original search results
  2207. mv $TMPDIR/pkglist1 $TMPDIR/pkglist
  2208. fi
  2209. fi
  2210.  
  2211. # return the search results
  2212. [ -s $TMPDIR/pkglist ] && cat $TMPDIR/pkglist 2>/dev/null
  2213.  
  2214. # clean up
  2215. [ ! -f $TMPDIR/pkglist ] && exit 1
  2216. rm $TMPDIR/pkglist* 2>/dev/null
  2217.  
  2218. }
  2219.  
  2220. list_aliases(){
  2221. # support pkg name aliases in finding packages
  2222. if [ $NO_ALIASES = false ]; then
  2223. local ALIAS_LIST
  2224. local ALIAS
  2225. local ALIAS_RES
  2226. # if we have some results to parse
  2227. if [ "$1" != "" -a -f $TMPDIR/pkg_aliases ]; then
  2228. # get the list of aliases
  2229. ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases 2>/dev/null | tr ',' ' '`";
  2230. # for each alias
  2231. echo $ALIAS_LIST | while read ALIAS
  2232. do
  2233. [ "$ALIAS" = '' ] && continue
  2234. # get the match from the current repo (if any)
  2235. ALIAS_RES="`LANG=C cut -f1 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$ALIAS"`" #'
  2236. [ ! "$ALIAS_RES" ] && ALIAS_RES="`LANG=C cut -f2 -d'|' "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep "^$ALIAS"`" #'
  2237. # if the repo match was found in the search results
  2238. if [ "$ALIAS_RES" != "" ]; then
  2239. # add the alias results to the search results
  2240. echo "$ALIAS_RES" #>> $TMPDIR/pkglist
  2241. fi
  2242. done # for each alias
  2243. # sort and clean the search results
  2244. ##LANG=C cat $TMPDIR/pkglist | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq > $TMPDIR/pkglist1
  2245. ## replace the original search results
  2246. #mv $TMPDIR/pkglist1 $TMPDIR/pkglist
  2247. fi
  2248. fi
  2249. }
  2250.  
  2251. list_all_pkg_names(){ # list pkg names in any repo ($1 is optional filter)FUNCLIST
  2252.  
  2253. # remove any previous search results
  2254. rm $TMPDIR/pkglist &>/dev/null
  2255.  
  2256. # if bleeding edge disabled, output the list repo by repo, in the fallback order, current repo first (that order is set in update_sources)
  2257. repo_file_list | while read repo_file
  2258. do
  2259. cut -f1 -d'|' "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep "^$1" | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr >> $TMPDIR/pkglist
  2260. done
  2261.  
  2262. # if bleeding edge enabled, re-order the whole list, so Pkg returns the most recent pgk versions from ANY repos
  2263. if [ "$BLEDGE" = "yes" ]; then
  2264. LANG=C cat $TMPDIR/pkglist 2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr > $TMPDIR/pkglist1
  2265. mv $TMPDIR/pkglist1 $TMPDIR/pkglist
  2266. fi
  2267.  
  2268. # filter out built-in and user installed packages
  2269. if [ $HIDE_INSTALLED = true ]; then
  2270. hide_installed_pkgs_from_search_results
  2271. fi
  2272.  
  2273. hide_blacklisted_pkgs_from_search_results
  2274.  
  2275. # support pkg name aliases in finding packages
  2276. if [ $NO_ALIASES = false ]; then
  2277. local ALIAS_LIST
  2278. local ALIAS
  2279. local ALIAS_RES
  2280. # if we have some results to parse
  2281. if [ "$1" != "" -a -f $TMPDIR/pkg_aliases ]; then
  2282. # get the list of aliases
  2283. ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases 2>/dev/null | tr ',' ' '`";
  2284. # for each repo
  2285. LANG=C repo_file_list | while read RF
  2286. do
  2287. # and for each alias
  2288. for ALIAS in $ALIAS_LIST; do
  2289. # get the match from the current repo (if any)
  2290. ALIAS_RES="`LANG=C cut -f1 -d'|' "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -m1 "^$ALIAS"`"
  2291. [ ! "$ALIAS_RES" ] && ALIAS_RES="`LANG=C cut -f2 -d'|' "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -m1 "^$ALIAS"`"
  2292. # if the repo match was found in the search results
  2293. if [ "$ALIAS_RES" != "" ]; then
  2294. # add the alias results to the search results
  2295. echo "$ALIAS_RES" >> $TMPDIR/pkglist
  2296. fi
  2297. done # for each alias
  2298. done # for each repo
  2299. fi
  2300. fi
  2301.  
  2302. # return the search results
  2303. [ -s $TMPDIR/pkglist ] && LANG=C cat $TMPDIR/pkglist | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq
  2304.  
  2305. # clean up
  2306. [ ! -f $TMPDIR/pkglist ] && exit 1
  2307. rm $TMPDIR/pkglist &>/dev/null
  2308. }
  2309.  
  2310.  
  2311. list_build_scripts(){ # list available build scripts ($1 is optional filter)FUNCLIST
  2312.  
  2313. # get settings from RC file
  2314. . ${PKGRC}
  2315.  
  2316. # make sure PetBuild is ready
  2317. [ "$BUILDTOOL" = "petbuild" ] && prepare_petbuild
  2318.  
  2319. # if no option given, just sort the results
  2320. [ "$1" != "" ] && FILTER="grep -i $1" || FILTER="sort"
  2321.  
  2322. # different build tools have their build scripts in different places.
  2323. # check which BUILDTOOL we are using and list its build scripts
  2324. case $BUILDTOOL in
  2325. petbuild)
  2326. 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 ^$
  2327. ;;
  2328. buildpet)
  2329. 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 ^$
  2330. ;;
  2331. src2pkg)
  2332. echo "Use: src2pkg FILE|URL or src2pkg -h"
  2333. ;;
  2334. sbopkg)
  2335. sbopkg
  2336. ;;
  2337. *)
  2338. echo "No build system configured. Set BUILDTOOL in $PKGRC."
  2339. echo "Supported build tools: petbuild, buildpet, src2pkg, sbopkg"
  2340. ;;
  2341. esac
  2342. }
  2343.  
  2344.  
  2345. list_downloaded_pkgs(){ # list packages downloaded in WORKDIR ($1 is optional filter) FUNCLIST
  2346.  
  2347. . ${PKGRC}
  2348.  
  2349. cd "$WORKDIR" || { error "Cant cd into $WORKDIR"; exit 3; }
  2350.  
  2351. local pkg
  2352.  
  2353. # if no pkg given, list all
  2354. if [ ! "$1" ]; then
  2355.  
  2356. # get all pkgs in WORKDIR
  2357. find "${WORKDIR}" -maxdepth 1 -type f | sed -e "s#${WORKDIR}##g" -e "s#^/##g" | grep -v ^'.pkg' | sort \
  2358. | while read pkg # but go through each and only print it if a valid pkg
  2359. do
  2360. [ "`is_local_pkg "$pkg"`" = true ] && echo $pkg || continue
  2361. done
  2362.  
  2363. return 0
  2364.  
  2365. else
  2366.  
  2367. # $1 might be a pkg, or list of pkgs, loop through them
  2368. for x in $1; do
  2369. if [ "$x" != "-" ]; then
  2370.  
  2371. # print the list of packages matching $x
  2372. find "${WORKDIR}" -maxdepth 1 -type f | sed -e "s#${WORKDIR}##g" -e "s#^/##g" | grep -v ^'.pkg'|grep ^"$x" | sort \
  2373. | while read pkg # but go through each and only print it if a valid pkg
  2374. do
  2375. [ "`is_local_pkg "$pkg"`" = true ] && echo $pkg || continue
  2376. done
  2377.  
  2378. return 0
  2379. fi
  2380. done
  2381. fi
  2382.  
  2383. cd -
  2384. }
  2385.  
  2386.  
  2387. list_installed_pkgs(){ # list user installed packages ($1 is optional filter) FUNCLIST
  2388.  
  2389. local user_pkgs_list=''
  2390. local builtins_list=''
  2391. local devx_pkgs_list=''
  2392.  
  2393. user_pkgs_list="$USER_INST_PKGS_FILE"
  2394.  
  2395. if [ "$HIDE_BUILTINS" != true -a -f "$DEVX_INST_PKGS_FILE" ]; then
  2396. devx_pkgs_list="$DEVX_INST_PKGS_FILE"
  2397. fi
  2398.  
  2399. [ "$HIDE_BUILTINS" != true ] && builtins_list="$WOOF_INST_PKGS_FILE"
  2400.  
  2401. # search current repo file only .. $1 is the optional pkg filter.. take field1, remove empty lines, remove dashes, remove Pkg from pkg list too
  2402. if [ ! "$1" ]; then
  2403. cut -f1 -d'|' $user_pkgs_list $devx_pkgs_list $builtins_list | grep -vE '^\$|^pkg\-'
  2404. return 0
  2405. else
  2406. cut -f1 -d'|' $user_pkgs_list $devx_pkgs_list $builtins_list | grep "^$1" | grep -vE '^\$|^pkg\-'
  2407. return 0
  2408. fi
  2409. }
  2410.  
  2411.  
  2412. list_builtin_pkgs(){ # lists builtin packages FUNCLIST
  2413.  
  2414. local builtins_repo
  2415.  
  2416. builtins_repo="$WOOF_INST_PKGS_FILE"
  2417.  
  2418. # 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
  2419. cut -f1 -d'|' $builtins_repo | grep "^$1" | grep -v ^\$ | grep -v "\-$" | grep -v ^pkg\- | sort
  2420. }
  2421.  
  2422.  
  2423. search_pkgs(){ # given $1, searches current repo, shows name and desc columns FUNCLIST
  2424.  
  2425. local name
  2426. local desc
  2427. local descfull
  2428. local search
  2429.  
  2430. # convert "foo[ -_]bar" into "foo.*bar"
  2431. search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2432.  
  2433. # convert repo file to nice columnised output, use cat|grep so empty searches return all results
  2434. cat "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | grep -i "$search" | while read repo_line;
  2435. do
  2436. name=`echo "$repo_line"|cut -f2 -d'|'`
  2437. desc="`echo "$repo_line"|cut -f10 -d'|' | head -c 57`"
  2438. descfull="`echo "$repo_line"|cut -f10 -d'|'`"
  2439. [ "$desc" != "$descfull" ] && desc="${desc}.."
  2440. printf "%-20s" "$name" " ${desc:-No description}"
  2441. echo
  2442. done
  2443. }
  2444.  
  2445.  
  2446. search_fast(){ # given $1, searches current repo, show pkg names only, case sensitive FUNCLIST
  2447. local RES
  2448. local search
  2449.  
  2450. # convert "foo[ -_]bar" into "foo.*bar"
  2451. search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2452.  
  2453. # get matching pkgs
  2454. RES="`LANG=C grep "$search" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f1 -d'|'`"
  2455. # error if no result
  2456. [ ! "$RES" ] && exit 1
  2457.  
  2458. # put results into file
  2459. echo "$RES" > $TMPDIR/pkglist
  2460.  
  2461. # hide built-in, devx and user installed packages
  2462. if [ $HIDE_INSTALLED = true ]; then
  2463. hide_installed_pkgs_from_search_results
  2464. fi
  2465.  
  2466. hide_blacklisted_pkgs_from_search_results
  2467.  
  2468. # now build the search results
  2469. RES="`grep -v "^\$" $TMPDIR/pkglist 2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq`"
  2470. rm $TMPDIR/pkglist &>/dev/null
  2471.  
  2472. #finshed making search results, print results
  2473. [ "$RES" = "" ] && exit 1
  2474. echo "$RES"
  2475. }
  2476.  
  2477.  
  2478. search_all_pkgs(){ # given $1, search all repos, show name and desc columns FUNCLIST
  2479.  
  2480. local name
  2481. local desc
  2482. local descfull
  2483. local search
  2484.  
  2485. # convert "foo[ -_]bar" into "foo.*bar"
  2486. search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2487.  
  2488. for repo_file in `repo_file_list`
  2489. do #090817
  2490. # convert repo file to nice columnised output
  2491. cat "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -i "$search" | while read repo_line;
  2492. do
  2493. # get details from repo
  2494. name=`echo "$repo_line"|cut -f2 -d'|'`
  2495. desc="`echo "$repo_line"|cut -f10 -d'|' | head -c 57`"
  2496. descfull="`echo "$repo_line"|cut -f10 -d'|'`"
  2497. [ "$desc" != "$descfull" ] && desc="${desc}.."
  2498. # remove spaces and comments (slackware-extra repo has some dodgy entries.. dogy names, descriptions with comments, etc)
  2499. name="${name// /}"
  2500. name="${name//#/}"
  2501. [ "$name" = '' ] && continue
  2502. # print columnised output
  2503. printf "%-20s" "$name" " ${desc:-No description}"
  2504. echo
  2505. done
  2506. done
  2507.  
  2508. }
  2509.  
  2510.  
  2511. search_all_fast(){ # given $1, search all repos, show pkg names only, case sensitive FUNCLIST
  2512. local RES
  2513. local search
  2514.  
  2515. # convert "foo[ -_]bar" into "foo.*bar"
  2516. search=`echo "$1" | sed -e 's| |.*|g' -e 's|-|.*|g' -e 's|_|.*|g'`
  2517.  
  2518. #if bleeding edge enabled, combine into 1 list, so
  2519. # that `pkg -g` etc return most recent from ALL repos
  2520. rm $TMPDIR/pkglist &>/dev/null
  2521. if [ "$BLEDGE" = "yes" ]; then
  2522. RES=''
  2523. for RF in `repo_file_list`
  2524. do #090817
  2525. cat "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -i "$search" | cut -f1 -d'|' | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq | sed -e '/^$/d' >> $TMPDIR/pkglist
  2526. done
  2527.  
  2528. else
  2529. # if bleeding edge disabled, output the list repo by repo, in #
  2530. # the fallback order, current repo first (that order is set in update_sources)
  2531. for RF in `repo_file_list`
  2532. do #090817
  2533. cat "$REPO_DB_FILE_DIR/${RF}" 2>/dev/null | grep -i "$search"| cut -f1 -d'|' | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq | sed -e '/^$/d' >> $TMPDIR/pkglist
  2534. done
  2535.  
  2536. fi
  2537.  
  2538. #100817 hide built-in, devx and user installed packages
  2539. if [ $HIDE_INSTALLED = true ]; then
  2540. hide_installed_pkgs_from_search_results
  2541. fi
  2542.  
  2543. hide_blacklisted_pkgs_from_search_results
  2544.  
  2545. # now build the search results
  2546. RES="`grep -v "^\$" $TMPDIR/pkglist 2>/dev/null | sort --field-separator='-' -k1,1df -k2gr -k3gr -k4gr | uniq`"
  2547. rm $TMPDIR/pkglist &>/dev/null
  2548.  
  2549. #finshed making search results, print results
  2550. [ "$RES" = "" ] && exit 1
  2551.  
  2552. echo "$RES"
  2553. }
  2554.  
  2555.  
  2556. which_repo(){ # list repo of given package ($1) FUNCLIST
  2557.  
  2558. # if no valid options, quit
  2559. [ ! "$1" -o "$1" = "-" -o "$1" = " " ] && print_usage which-repo && exit 1
  2560.  
  2561. . ${PKGRC}
  2562.  
  2563. local PKGNAME=''
  2564. local PKGNAME_ONLY=''
  2565. local pkg_ext=''
  2566. local repo_file=''
  2567. local repo_name=''
  2568. local pkg_list=''
  2569.  
  2570. PKGNAME=`get_pkg_name "$1"`
  2571. PKGNAME_ONLY=`get_pkg_name_only "$1"`
  2572. pkg_ext=`get_pkg_ext "$PKGNAME"`
  2573.  
  2574. repo_file="$(grep -l "|$PKGNAME.$pkg_ext|" "$REPO_DB_FILE_DIR"/Packages-*)"
  2575. if [ "$repo_file" != '' ]; then
  2576. # get the repo name
  2577. repo_name="`grep -m1 "$(basename $repo_file)|" ${HOME}/.pkg/sources | cut -f1 -d'|'`"
  2578. pkg_list="$PKGNAME $repo_name"
  2579. else
  2580.  
  2581. # for each repo
  2582. for repo_file in `repo_file_list`
  2583. do
  2584. # get the repo name
  2585. repo_name="`grep -m1 "$repo_file|" ${HOME}/.pkg/sources | cut -f1 -d'|'`"
  2586. # create the entries, example: "vlc slacko14.2"
  2587. # (each line shows a matching package, then a SPACE, then the name of repo the package lives in)
  2588. pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "^$PKGNAME|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2589. [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "|$PKGNAME.$EX|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2590. [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "|$1.$EX|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2591. [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "|$PKGNAME_ONLY|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2592. [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "^$PKGNAME_ONLY|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2593. [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "|$1|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2594. [ "$pkg_list" = '' ] && pkg_list="$pkg_list`LANG=C grep "$PKGNAME" "$REPO_DB_FILE_DIR/${repo_file}" 2>/dev/null | grep -m1 "^$1|" | cut -f1 -d'|' | tr '\n' '@' | sed -e "s#@# $repo_name\n#g"`"
  2595. done
  2596. fi
  2597.  
  2598. # show results
  2599. LANG=C echo -e "$pkg_list" | sed -e '/^$/d' | uniq
  2600. }
  2601.  
  2602.  
  2603. which_pkg(){ # find out which pkg FILE ($1) comes from FUNCLIST
  2604.  
  2605. # exit if no valid opts
  2606. [ ! "$1" -o "$1" = '-' -o "$1" = '' ] && print_usage which && exit 1
  2607.  
  2608. local PKGNAME=''
  2609. local PKG_FILE_LIST=''
  2610. local FILENAME=''
  2611. local FILENAME_ONLY=''
  2612. local DIRNAME=''
  2613. local builtins_without_busybox="$(find "$BUILTIN_FILE_LIST_DIR"/* -maxdepth 1 -type f | grep -v "/busybox")"
  2614.  
  2615. # get user input
  2616. FILENAME="`basename "$1"`"
  2617. FILENAME_ONLY="$FILENAME"
  2618. DIRNAME="`dirname "$1"`"
  2619.  
  2620. # if we don't have a file, the user probably gave a command,
  2621. # so lets check see
  2622. if [ ! -f "$1" ]; then
  2623. # if we get a command, then that is our FILENAME
  2624. cmd=`which "$1"`
  2625. # if $cmd found, set FILENAME to $cmd (FILENAME now includes full path)
  2626. [ "$cmd" != '' ] && FILENAME=$cmd && FILENAME_ONLY=`basename "$FILENAME"`
  2627. fi
  2628.  
  2629. # dont use relative paths
  2630. [ "`echo "$DIRNAME" | grep "^\."`" != '' ] && DIRNAME=''
  2631.  
  2632. # try user installed pkgs contents of $PKGS_DIR/*.files
  2633.  
  2634. # try '$dir/$file', returns filename (no path) of matching *.files
  2635. [ "$PKG_FILE_LIST" = '' ] && PKG_FILE_LIST="`grep -l "$DIRNAME/$FILENAME\$" "$PACKAGE_FILE_LIST_DIR"/*.files 2>/dev/null| sed "s#$PKGS_DIR/##g" 2>/dev/null`"
  2636.  
  2637. # try '$dir/$file_*' if needed
  2638. [ "$PKG_FILE_LIST" = '' ] && PKG_FILE_LIST="`grep -l "$DIRNAME/${FILENAME}_" "$PACKAGE_FILE_LIST_DIR"/*.files 2>/dev/null| sed "s#$PKGS_DIR/##g" 2>/dev/null`"
  2639.  
  2640. # try '$dir/$file-*' if needed
  2641. [ "$PKG_FILE_LIST" = '' ] && PKG_FILE_LIST="`grep -l "$DIRNAME/${FILENAME}\-" "$PACKAGE_FILE_LIST_DIR"/*.files 2>/dev/null| sed "s#$PKGS_DIR/##g" 2>/dev/null`"
  2642.  
  2643. # if we found a package, set the package name to the name of the *.files file that we got
  2644. [ "$PKG_FILE_LIST" != '' ] && PKGNAME="`basename "$PKG_FILE_LIST" .files`"
  2645.  
  2646. # maybe we got nothing from *.files.. check builtins/$1* for ' $FILENAME_ONLY',
  2647. # returns PKGNAME of the matching builtin
  2648.  
  2649. # if needed, search inside builtin file lists (EXCEPT busybox) for ' $FILENAME_ONLY'
  2650. [ "$PKG_FILE_LIST" = '' ] && [ "$PKGNAME" = "" ] \
  2651. && PKGNAME="$(basename `grep -l "^ $FILENAME_ONLY\$" $builtins_without_busybox | sed "s#$BUILTIN_FILE_LIST_DIR/##g"` 2>/dev/null)"
  2652.  
  2653. # if that didn't work, search inside builtin file lists of busybox for ' $FILENAME_ONLY'
  2654. [ "$PKG_FILE_LIST" = '' ] && [ "$PKGNAME" = "" ] \
  2655. && PKGNAME="$(basename `grep -l "^ $FILENAME_ONLY\$" "$BUILTIN_FILE_LIST_DIR/busybox" | sed "s#$BUILTIN_FILE_LIST_DIR/##g"` 2>/dev/null)"
  2656.  
  2657. # apps in ADRV sfs dont have their files listed in their $PKGS_DIR/builtin_files/$pkgname.. so..
  2658.  
  2659.  
  2660. # now check pkg names (not pkg contents) of builtins (EXCEPT busybox) for '$file'.. cos maybe we didnt find the file inside the file lists
  2661. [ "$PKGNAME" = "" ] \
  2662. && PKGNAME="`echo "$builtins_without_busybox" | grep -m1 "^${FILENAME_ONLY}\$" | sed "s#$BUILTIN_FILE_LIST_DIR/##g" 2>/dev/null`"
  2663.  
  2664. # now look for '$file' in user installed repo list
  2665. [ "$PKGNAME" = "" ] \
  2666. && PKGNAME="`cut -f1,2,8 -d'|' "$USER_INST_PKGS_FILE" 2>/dev/null | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null| grep -m1 "|$FILENAME_ONLY|" | cut -f2 -d'|'`"
  2667.  
  2668. # also look for '$file' in user/woof/devx installed repo list
  2669. [ "$PKGNAME" = "" ] \
  2670. && PKGNAME="$(cut -f1,2,8 -d'|' "${SPEC_DB_PATHS[@]}" 2>/dev/null | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null | grep -m1 "|$FILENAME_ONLY|" | cut -f2 -d'|')"
  2671.  
  2672.  
  2673. # we searched for an exact match in builtins, user installed, woof installed and devx pkgs, now try some fuzzier matches
  2674.  
  2675. # try /$file_* in builtins
  2676. [ "$PKGNAME" = "" ] \
  2677. && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}_" "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2678.  
  2679. # try $file-* in builtins
  2680. [ "$PKGNAME" = "" ] \
  2681. && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}-" "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_DIR/builtin_files/##g"` 2>/dev/null)"
  2682.  
  2683. # try $file.* in builtins
  2684. [ "$PKGNAME" = "" ] \
  2685. && PKGNAME="$(basename `grep -l " ${FILENAME_ONLY}\." "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2686.  
  2687. # try *file in builtin pkgs
  2688. [ "$PKGNAME" = "" ] \
  2689. && PKGNAME="$(basename `grep -l "${FILENAME_ONLY}"\$ "$PKGS_BUILTIN_DIR"/* | sed "s#$PKGS_BUILTIN_DIR/##g"` 2>/dev/null)"
  2690.  
  2691.  
  2692. # if we still didnt find it, look in user installed package lists, for FILENAME
  2693. [ "$PKGNAME" = "" ] \
  2694. && PKGNAME=`cut -f1,2,8 -d '|' "$USER_INST_PKGS_FILE" \
  2695. | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2696. | grep -m1 "|${FILENAME_ONLY}|" \
  2697. | cut -f2 -d'|'` 2>/dev/null
  2698.  
  2699. # if we still didnt find it, look in all installed package lists, for FILENAME
  2700. [ "$PKGNAME" = "" ] \
  2701. && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2702. | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2703. | grep -m1 "|${FILENAME_ONLY}|" \
  2704. | cut -f2 -d'|'` 2>/dev/null
  2705.  
  2706. # if we still didnt find it, look in all installed package lists, for *FILENAME
  2707. [ "$PKGNAME" = "" ] \
  2708. && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2709. | sed -e "s/^/|/" -e "s/\$/|/" 2>/dev/null \
  2710. | grep -m1 "${FILENAME_ONLY}|" \
  2711. | cut -f2 -d'|'` 2>/dev/null
  2712.  
  2713. # if we still didnt find it, look in all installed package lists, for FILENAME*
  2714. [ "$PKGNAME" = "" ] \
  2715. && PKGNAME=`cut -f1,2,8 -d '|' "${SPEC_DB_PATHS[@]}" \
  2716. | sed -e "s/^/|/" -e "s/\$/|/" \
  2717. | grep -m1 "|${FILENAME_ONLY}" \
  2718. | cut -f2 -d'|'` 2>/dev/null
  2719.  
  2720.  
  2721. # clean up
  2722. [ "$PKGNAME" = '.files' ] && PKGNAME=''
  2723. PKGNAME="`echo "$PKGNAME" | head -1`"
  2724.  
  2725. # now print pkgs which contain the given file ($1)
  2726. if [ "$PKGNAME" != "" ]; then
  2727. echo "$PKGNAME"
  2728. return 0
  2729. else
  2730. echo "File '$FILENAME' not found in any installed or built-in pkgs."
  2731. exit 1
  2732. fi
  2733. }
  2734.  
  2735.  
  2736.  
  2737. # pkg info funcs
  2738.  
  2739. pkg_contents(){ # list package ($1) contents FUNCLIST
  2740.  
  2741. # if no valid options, quit
  2742. [ ! "$1" -o "$1" = "-" -o "$1" = " " ] && print_usage contents && exit 1
  2743.  
  2744. # get settings
  2745. . ${PKGRC}
  2746.  
  2747. local PKGFILE
  2748. local ext
  2749. local PKGNAME
  2750. local PKGNAME_ONLY
  2751. local pkg_is_local_file
  2752. local pkg_is_builtin
  2753. local pkg_is_installed
  2754. local PKGFLIST=''
  2755.  
  2756. # get pkg extension
  2757. ext=`get_pkg_ext "$1"`
  2758.  
  2759. # get pkg name (includes version), but no extension or path
  2760. PKGNAME="$(basename "$1" .$ext)"
  2761. PKGNAME=`get_pkg_name "$PKGNAME"`
  2762.  
  2763. # get pkg name without version
  2764. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  2765.  
  2766. pkg_is_local_file=`is_local_pkg "$1"`
  2767. pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY"`
  2768. pkg_is_installed=`is_installed_pkg "$PKGNAME_ONLY"`
  2769.  
  2770. # now we check various ways to find out the contents of
  2771. # a pkg (either by *.files, user installed, woof, builtin, etc)
  2772.  
  2773. [ "$pkg_is_local_file" = true ] && PKGFILE="$1"
  2774.  
  2775. # try a file in the current dir if needed
  2776. [ ! -f "$PKGFILE" ] && PKGFILE="${CURDIR}/${PKGNAME}.$ext"
  2777. # check $WORKDIR if needed
  2778. [ ! -f "$PKGFILE" ] && PKGFILE="${WORKDIR}/${PKGNAME}.$ext"
  2779.  
  2780. # if the pkg is a local file
  2781. if [ -f "$PKGFILE" ]; then
  2782. #list contents based on extension
  2783. case "$ext" in
  2784. sfs)
  2785. unsquashfs -l "$PKGFILE" | cut -f2-99 -d'/'| sed -e 's#^#/#g' 2>/dev/null | grep -v -E 'unsquashfs:|/squashfs-root|) to write' | grep -v "^/$"
  2786. ;;
  2787. deb)
  2788. dpkg-deb -c "$PKGFILE" 2>/dev/null | grep -v "^/$"
  2789. ;;
  2790. pet|tar|tar**tcz|*txz|*tgz|*xz|*gz)
  2791. # remove leading pkg name from each line of file list
  2792. # (shown if listing *some* pkg file contents)
  2793. tar -tf "$PKGFILE" 2>/dev/null \
  2794. | sed -e "s#^./${PKGNAME}/#/#g" -e "s#^${PKGNAME}/#/#g" -e "s#^./##g" 2>/dev/null \
  2795. | grep -v ^$ 2>/dev/null 2>/dev/null \
  2796. | grep -v "^/$"
  2797. ;;
  2798. rpm)
  2799. busybox rpm -qlp "$PKGFILE" 2>/dev/null | grep -v "^/$"
  2800. ;;
  2801. esac
  2802. exit $?
  2803. fi
  2804.  
  2805. # if we are here, the pkg is not a downloaded pkg, so we build a
  2806. # list of files by checking *.files, woof, builtins ..
  2807.  
  2808. # check if we need to (and can) get our pkg contents from builtins/PKGNAME
  2809. local need_to_check_builtins=`echo "$PKG_FLIST" | grep -m1 'packages/builtin_files/'`
  2810.  
  2811. # if the pkg is a builtin, we will re-format the output of LIST to match the others (full paths on each line)
  2812. if [ "$need_to_check_builtins" != '' -a "$pkg_is_builtin" = true ]; then
  2813.  
  2814. # reset the list of pkg files, we will re-build it
  2815. rm $TMPDIR/pkg_file_list 2>/dev/null
  2816.  
  2817. # first we get the package contents from $PKGS_DIR/builtin_files/$PKGNAME_ONLY
  2818. cat "$PKG_FLIST" 2>/dev/null | while read line
  2819. do
  2820. # parse it, so we get a full path to file on each line
  2821. if [ "`echo "$line" | grep '^/'`" != '' ]; then
  2822. # set the dir to use in our file list
  2823. dir="$line"
  2824. else
  2825. # keep previous dir
  2826. dir="$dir"
  2827. fi
  2828.  
  2829. # create our new line (a full file path) to $LIST
  2830. line_to_add="$dir/`echo "$line" | cut -f2 -d' '`"
  2831.  
  2832. # if only a dir, skip it
  2833. [ "$line" = "$dir" ] && continue
  2834.  
  2835. # if its already added, skip it
  2836. [ "`grep -m1 "$line_to_add" ${TMPDIR}/pkg_file_list 2>/dev/null `" != '' ] && continue
  2837.  
  2838. # if its not a file on the system (it should be), skip it
  2839. [ ! -f "$line_to_add" ] && continue
  2840.  
  2841. # all should be ok, add the line to our list
  2842. echo "$line_to_add" >> $TMPDIR/pkg_file_list
  2843.  
  2844. done
  2845.  
  2846. # now get our pkg contents list, it might have been re-formatted (if a builtin)
  2847. PKG_FLIST="`cat ${TMPDIR}/pkg_file_list 2>/dev/null`"
  2848.  
  2849. # last resort, if we lost our file list or still dont have, try the basics again
  2850. [ "$PKG_FLIST" = '' ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}"'*.files' 2>/dev/null)"
  2851.  
  2852. # clean up the list a bit
  2853. [ "$PKG_FLIST" != '' ] && PKG_FLIST="`echo "$PKG_FLIST" | grep -v ' ' | grep -v "^\$" | sort | uniq`"
  2854.  
  2855. # and clean up the tmp files
  2856. rm ${TMPDIR}/pkg_file_list 2>/dev/null
  2857. fi
  2858.  
  2859. # try PKGNAME_ONLY.files (exact match)
  2860. PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}.files" 2>/dev/null)"
  2861.  
  2862. # try finding PKGNAME.files (exact match)
  2863. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}.files" 2>/dev/null)"
  2864.  
  2865. # try the builtins files (exact match)
  2866. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$BUILTIN_FILE_LIST_DIR" -maxdepth 1 -type f -name "$PKGNAME_ONLY")"
  2867.  
  2868. # try PKGNAME (exact match) in user installed pkgs
  2869. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -m1 ^"$PKGNAME\$" 2>/dev/null`.files"
  2870.  
  2871. # try PKGNAME (exact match) in all installed pkgs
  2872. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME\$" 2>/dev/null`.files"
  2873.  
  2874. # try PKGNAME_ONLY (exact match) in all installed pkgs
  2875. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f2 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME_ONLY\$" 2>/dev/null`.files"
  2876.  
  2877.  
  2878. # no exact matches found, try fuzzy searches..
  2879.  
  2880. # try PKGNAME*.files
  2881. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "/${PKGNAME}"'*.files' 2>/dev/null)"
  2882.  
  2883. # try finding *PKGNAME.files
  2884. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name '*'"${PKGNAME}.files" 2>/dev/null)"
  2885.  
  2886. # try ^PKGNAME_ONLY[_-] in user installed pkgs
  2887. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -Em1 "^$PKGNAME_ONLY[_-]" 2>/dev/null`.files"
  2888.  
  2889. # try PKGNAME_ONLY* in user installed pkgs only
  2890. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' $USER_INST_PKGS_FILE | grep -m1 ^"$PKGNAME_ONLY" 2>/dev/null`.files"
  2891.  
  2892. # try PKGNAME_ONLY-* (any installed pkgs)
  2893. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -Em1 ^"${PKGNAME_ONLY}[_-]" 2>/dev/null`.files"
  2894.  
  2895. # try PKGNAME_ONLY* (any installed pkgs)
  2896. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$PKGS_DIR/`cut -f1 -d'|' "${SPEC_DB_PATHS[@]" | grep -m1 ^"$PKGNAME_ONLY" 2>/dev/null`.files"
  2897.  
  2898. # try PKGNAME_ONLY*.files
  2899. [ ! -f "$PKG_FLIST" ] && PKG_FLIST="$(find "$PKGS_DIR" -maxdepth 1 -type f -name "/${PKGNAME_ONLY}"'*.files' 2>/dev/null)"
  2900.  
  2901.  
  2902.  
  2903. #if we found a list of files
  2904. if [ "$PKG_FLIST" != "" ]; then
  2905.  
  2906. print_cmd=echo
  2907. # PKG_FLIST just might contain a path to the pkg contents
  2908. # themselves (a *.files, or a file in builtin_files/*).. so if
  2909. # its a file path, we will cat it, if not, its the pkg contents
  2910. # themselves, we echo it
  2911. if [ "`echo "$PKG_FLIST" | grep -m1 '/builtin_files/'`" != '' -o "`echo "$PKG_FLIST" | grep -m1 "packages/$PKGNAME"`" != '' ]; then
  2912. print_cmd=cat
  2913. fi
  2914.  
  2915. $print_cmd "$PKG_FLIST" | grep -v "^/$" 2>/dev/null
  2916.  
  2917. else # if no files found
  2918. if [ "$PKGNAME" != '' ]; then
  2919. INST_CHECK="`is_installed_pkg $PKGNAME 2>/dev/null`"
  2920. if [ "$INST_CHECK" != true -o "$pkg_is_local_file" = false ]; then
  2921. error "Package must be installed, downloaded or built-in."
  2922. else
  2923. error "Could not get package contents, unable to get file list."
  2924. fi
  2925. else
  2926. error "Could not get name of package."
  2927. fi
  2928. fi
  2929. }
  2930.  
  2931.  
  2932. pkg_entry(){ # show pkg ($1) repo entry, each field on a new line FUNCLIST
  2933.  
  2934. # exit if no valid opts
  2935. [ ! "$1" -o "$1" = '-' ] && print_usage pkg-entry && exit 1
  2936.  
  2937. local EX
  2938. local PKGNAME
  2939. local PKGNAME_ONLY
  2940.  
  2941. # get pkg extension
  2942. EX=`get_pkg_ext "$1"`
  2943.  
  2944. # get pkg name with version, but no extension or path
  2945. PKGNAME="$(basename "$1" .$EX)"
  2946.  
  2947. # dont rely on the string the user gave us, try to get the exact match
  2948. PKGNAME=`get_pkg_name "$PKGNAME"`
  2949. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  2950.  
  2951. PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "|$PKGNAME|")"
  2952. [ "$PKG_ENTRY" = '' ] && PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "^$PKGNAME|")"
  2953. [ "$PKG_ENTRY" = '' ] && PKG_ENTRY="$(cat "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "|$PKGNAME_ONLY|")"
  2954. if [ "$PKG_ENTRY" = '' ]; then
  2955. echo "$1 not found in $REPOFILE"
  2956. exit 1
  2957. else
  2958. echo "$PKG_ENTRY" | tr '|' '\n' | grep -v '^$'
  2959. fi
  2960. return 0
  2961. }
  2962.  
  2963.  
  2964. pkg_status(){ # print package ($1) name, status, deps, etc FUNCLIST
  2965.  
  2966. # exit if no valid options
  2967. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-status && exit 1
  2968.  
  2969. # get current repo name
  2970. . ${PKGRC}
  2971.  
  2972. local EX
  2973. local PKGNAME=''
  2974. local PKGNAME_ONLY=''
  2975. local PKGFILE=''
  2976. local MSG=''
  2977. local install_status=''
  2978. local pkg_found=false
  2979. local pkg_repo=''
  2980. local pkg_repo_file=''
  2981. local prev_repo=${REPONAME}
  2982.  
  2983. # get pkg extension
  2984. EX=`get_pkg_ext "$1"`
  2985.  
  2986. # get pkg name with version, but no extension or path
  2987. PKGNAME="$(basename "$1" .$EX)"
  2988.  
  2989. # dont rely on the string the user gave us, try to get the exact match
  2990. PKGNAME=`get_pkg_name "$PKGNAME"`
  2991.  
  2992. # get pkg name without version
  2993. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  2994.  
  2995. [ "$PKGNAME" = '' ] && error "Can't find $1" && exit 1
  2996.  
  2997. # get install status of pkg (installed or not)
  2998. [ "`is_installed_pkg $PKGNAME`" = true ] && install_status="installed" || install_status="not installed"
  2999.  
  3000. # if pkg is installed, find out from where
  3001. if [ "$install_status" = "installed" ]; then
  3002.  
  3003. # check user installed pkgs for $PKGNAME
  3004. pkg_found=`LANG=C is_usr_pkg "${PKGNAME}"`
  3005. [ "$pkg_found" = true ] && install_status="installed (user)"
  3006.  
  3007. # if pkg not found yet, check if pkg is from the devx
  3008. if [ -f "$PKGS_DIR/devx-only-installed-packages" -a "$pkg_found" = false ]; then
  3009. pkg_found=`LANG=C is_devx_pkg "${PKGNAME}"`
  3010. [ "$pkg_found" = true ] && install_status="installed (in devx)"
  3011. fi
  3012.  
  3013. # check builtins for PKGNAME_ONLY, if it exists, its a builtin pkg
  3014. if [ -d "$BUILTIN_FILE_LIST_DIR/" -a "$pkg_found" = false ]; then
  3015. pkg_found=`LANG=C is_builtin_pkg "${PKGNAME_ONLY}"`
  3016. [ "$pkg_found" = true ] && install_status="installed (builtin)"
  3017. fi
  3018.  
  3019. # last gasp, if pkg not found yet, check if pkg if listed in layers-installed packages
  3020. if [ -f "$PKGS_DIR/layers-installed-packages" -a "$pkg_found" = false ]; then
  3021. pkg_found=$(LANG=C grep -m1 "^${PKGNAME}|" "$LAYER_INST_PKGS_FILE")
  3022.  
  3023. [ "$pkg_found" = '' ] && install_status="installed (layers)"
  3024. fi
  3025.  
  3026. fi
  3027.  
  3028. # get the repo of this pkg, if needed
  3029. [ "$pkg_repo" = '' ] && pkg_repo="`which_repo "$PKGNAME" 2>/dev/null | cut -f2 -d' '`"
  3030.  
  3031. # if we got a repo name, get the repo file
  3032. [ "$pkg_repo" != '' ] && pkg_repo_file="$(grep -m1 "^$pkg_repo|" ${HOME}/.pkg/sources | cut -f3 -d'|')"
  3033.  
  3034. # if we have a repo to search for pkg info
  3035. if [ "$pkg_repo_file" != "" ]; then
  3036.  
  3037. # get package description from its repo entry
  3038. pkg_desc="`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/$pkg_repo_file" 2>/dev/null| grep -m1 "$PKGNAME" | cut -f10 -d'|' | head -1`"
  3039.  
  3040. if [ "$pkg_desc" = '' ]; then
  3041. pkg_desc="`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$PKGS_DIR/Packages-"* 2>/dev/null| grep -m1 "${PKGNAME}|" | cut -f10 -d'|' | head -1`"
  3042. fi
  3043.  
  3044. # get size of pkg
  3045. pkg_size=`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/$pkg_repo_file" 2>/dev/null | cut -f6 -d'|' | head -1`
  3046.  
  3047. # add K to end of pkg_size, if not there already
  3048. [ "$pkg_size" != '' ] && pkg_size="${pkg_size}K" && pkg_size="${pkg_size//KK/K}"
  3049.  
  3050. # if called with -PS, we get the full info (where we sort deps missing or installed)
  3051. if [ "$FULL_PKG_STATUS" = true ]; then
  3052.  
  3053. # if pkg has many deps, checking the deps might take a while, print a 'please wait' msg
  3054. please_wait=false
  3055. # count deps of pkg
  3056. [ "`has_deps "$PKGNAME"`" = true ] && please_wait=true
  3057. [ "$please_wait" = true ] && echo -ne "Please wait.. Gathering dependency information.\n"
  3058.  
  3059. set_current_repo $pkg_repo 1>/dev/null
  3060. # sort deps into 2 lists: missing deps and installed deps
  3061. find_deps "$PKGNAME"
  3062. set_current_repo $prev_repo 1>/dev/null
  3063.  
  3064. # create a nicely formatted, coloured list of deps, green for installed, yellow for missing
  3065. 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}"
  3066. 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}"
  3067.  
  3068. DEPS_ENTRY="Installed deps: ${INSTALLED_DEPS_MSG:-None}
  3069. Missing deps: ${MISSING_DEPS_MSG:-None}"
  3070.  
  3071. else
  3072.  
  3073. DEPS_ENTRY="Dependencies: `list_deps "$PKGNAME" 2>/dev/null`"
  3074.  
  3075. fi
  3076.  
  3077. #250613 added desc
  3078. MSG="
  3079. Name: ${PKGNAME}
  3080. Description: `echo ${pkg_desc:-No description} | fold -w 50 -s | sed '2,10 s/^/ /g'`
  3081. Size: ${pkg_size:-Unknown}
  3082. Status: ${install_status:-Unknown}
  3083. In Repo: ${pkg_repo:-Not in any repos}
  3084. Repo file: `basename ${pkg_repo_file:-Not in any repositories} 2>/dev/null`
  3085. $DEPS_ENTRY"
  3086.  
  3087. fi
  3088.  
  3089. # if not found in any repo, maybe a woof or alien (user-installed) package
  3090. if [ "$MSG" = "" ]; then #if nothing found in any repo
  3091.  
  3092. PKGFILE="`list_downloaded_pkgs | grep -m1 "^$PKGNAME"`"
  3093.  
  3094. # if the pkg is a downloaded file (in WORKDIR)
  3095. if [ -f "$WORKDIR/$PKGFILE" ]; then
  3096.  
  3097. # get the file, and get its file size
  3098. PKGFILE="$WORKDIR/${PKGFILE}"
  3099. [ "$pkg_size" = '' ] && pkg_size="`du -s -k "$PKGFILE" | cut -f1`K"
  3100. [ "$pkg_size" = '' ] && pkg_size="`grep -m1 "|${PKGNAME_ONLY}|" "${SPEC_DB_PATHS[@]" | cut -f6 -d'|' | head -1`"
  3101.  
  3102.  
  3103. # create msg for downloaded pkgs
  3104. MSG="Name: ${PKGNAME}
  3105. Size: ${pkg_size:-Unknown}
  3106. Status: Downloaded
  3107. Note: Downloaded package, not in any repo.
  3108. $DEPS_ENTRY"
  3109.  
  3110. # else, search for exact match, then pkg-*, then pkg_*, then pkg* in installed pkgs
  3111. elif [ "$(grep -m1 "|${PKGNAME_ONLY}|" "$USER_INST_PKGS_FILE" 2>/dev/null)" \
  3112. -o "$(grep -m1 "^${PKGNAME}|" "$USER_INST_PKGS_FILE" 2>/dev/null)" \
  3113. -o "`grep -m1 "^${PKGNAME}|" "${SPEC_DB_PATHS[@]" 2>/dev/null`" \
  3114. -o "`grep -m1 "^${PKGNAME}-" "${SPEC_DB_PATHS[@]" 2>/dev/null`" \
  3115. -o "`grep -m1 "^${PKGNAME}_" "${SPEC_DB_PATHS[@]" 2>/dev/null`" \
  3116. -o "`grep -m1 "^${PKGNAME}" "${SPEC_DB_PATHS[@]" 2>/dev/null`" ]; then
  3117.  
  3118. # get deps and size from its entry in user-installed-packages
  3119. DEPS_ENTRY="Dependencies: `grep -m1 "^$PKGNAME" "$USER_INST_PKGS_FILE" | cut -f9 -d'|' | sed -e 's/,+/,/g' -e 's/^+//g' -e 's/,$//g' 2>/dev/null`"
  3120. [ "$DEPS_ENTRY" = '' ] && DEPS_ENTRY="Dependencies: `grep -m1 "^$PKGNAME" "${SPEC_DB_PATHS[@]" | cut -f9 -d'|' | sed -e 's/,+/,/' -e 's/^+//' -e 's/,$//' 2>/dev/null`"
  3121. pkg_size=`LANG=C grep -m1 "|$PKGNAME_ONLY|" "${SPEC_DB_PATHS[@]" | cut -f6 -d'|' | head -1`
  3122. # add K to end of pkg_size, if not there already
  3123. [ "$pkg_size" != '' ] && pkg_size="${pkg_size}K" && pkg_size="${pkg_size//KK/K}"
  3124.  
  3125. # create msg for user installed pkgs
  3126. MSG="Name: ${PKGNAME}
  3127. Size: ${pkg_size:-Unknown}
  3128. Status: ${install_status}
  3129. Repo: Alien package, not in any repo.
  3130. $DEPS_ENTRY"
  3131.  
  3132. else # pkg wasn't found, it's unknown to Pkg
  3133. MSG="$PKGNAME not found.
  3134.  
  3135. Here are some packages in other repos:"
  3136. PLIST="`which_repo ${PKGNAME}`"
  3137. [ "$PLIST" != "" ] && MSG="$MSG
  3138. $PLIST"
  3139. # create msg for alien pkgs
  3140. MSG="$MSG
  3141.  
  3142. Name: ${PKGNAME}
  3143. Status: ${install_status:-Unknown}
  3144. Repo: Alien package, not in $REPONAME repo.
  3145. $DEPS_ENTRY"
  3146.  
  3147. fi
  3148.  
  3149. fi
  3150.  
  3151. # print message
  3152. if [ "$MSG" != "" ]; then
  3153. # now output the final msg
  3154. echo -e "$MSG" | grep -v ^$
  3155. menu_entry_msg "$PKGNAME"
  3156. echo
  3157. else
  3158. not_found "${PKGNAME}"
  3159. exit 1
  3160. fi
  3161. }
  3162.  
  3163.  
  3164. # pkg creation funcs
  3165.  
  3166. prepare_petbuild(){ # get 01mickos petbuild system from Git, if needed FUNCLIST
  3167.  
  3168. local gitcheck=`which git`
  3169.  
  3170. # exit if no devx
  3171. [ "`which gcc`" = '' ] \
  3172. && echo "You need the devx SFS installed to compile packages." \
  3173. && rm /tmp/pkg/petbuild_prepared 2>/dev/null \
  3174. && exit 3
  3175.  
  3176. # exit if no git
  3177. [ "`$gitcheck`" = '' ] \
  3178. && echo "You need git installed to auto-install petbuild." \
  3179. && rm /tmp/pkg/petbuild_prepared 2>/dev/null \
  3180. && exit 3
  3181.  
  3182. if [ ! -d /usr/share/petbuild ]; then
  3183. rm /tmp/pkg/petbuild_prepared 2>/dev/null && exit 1
  3184. fi
  3185.  
  3186. # if petbuild prepared flag not yet set
  3187. if [ ! -f /tmp/pkg/petbuild_prepared ]; then
  3188.  
  3189. # backup old petbuild if installed
  3190. [ -d /usr/share/petbuild/ ] && mv /usr/share/petbuild/ /usr/share/petbuild.backup/ 2>/dev/null
  3191.  
  3192. # remove the original petbuild dir (we have a backup)
  3193. if [ -d /usr/share/petbuild.backup/ ]; then
  3194. rm -rf /usr/share/petbuild 2>/dev/null
  3195. fi
  3196.  
  3197. # clone petbuild into /usr/share/petbuild
  3198. git clone https://github.com/puppylinux-woof-CE/petbuilds.git /usr/share/petbuild &>/dev/null
  3199.  
  3200. # if still no petbuild dir in /usr/share, tell user to install themselves
  3201. if [ ! -d /usr/share/petbuild ]; then
  3202. echo >&2
  3203. echo "Run this command to download PetBuild:" >&2
  3204. echo >&2
  3205. echo -e " ${green}git clone https://github.com/puppylinux-woof-CE/petbuilds /usr/share/petbuild${endcolour}" >&2
  3206. echo >&2
  3207. echo "Alternatively, use a different build tool backend by changing BUILDTOOL= " >&2
  3208. echo "to one of the options below, in the $PKGRC file:" >&2
  3209. echo "petbuild, buildpet, sbopkg or src2pkg" >&2
  3210. echo >&2
  3211.  
  3212. exit 1
  3213. fi
  3214.  
  3215. # go into buildpet dir, check which Pup we have ($DISTRO_DB_SUBNAME)
  3216. # and checkout the right branch for the running system
  3217. cd /usr/share/petbuild
  3218.  
  3219. # check the puppy running and checkout the relevant branch
  3220. if [ "`echo $DISTRO_DB_SUBNAME | grep slacko`" != '' ]; then
  3221. if [ "`echo $DISTRO_DB_SUBNAME | grep '14.2'`" != '' ]; then
  3222. git checkout slacko_142
  3223. else
  3224. git checkout slacko_141
  3225. fi
  3226. elif [ "`echo $DISTRO_DB_SUBNAME | grep tahrpup`" ]; then
  3227. git checkout tahrpup
  3228. elif [ "`echo $DISTRO_DB_SUBNAME | grep stretch`" ]; then
  3229. git checkout stretch || git checkout tahrpup
  3230. elif [ "`echo $DISTRO_DB_SUBNAME | grep xenialpup`" ]; then
  3231. git checkout xenialpup || git checkout tahrpup
  3232. elif [ "$DISTRO_DB_SUBNAME" != '' ]; then
  3233. git checkout tahrpup
  3234. else
  3235. echo "No pet builds available for your system ($DISTRO_DB_SUBNAME),"
  3236. echo "using buildpet instead.."
  3237. rm -rf /usr/share/petbuild 2>/dev/null
  3238. fi
  3239.  
  3240. # buildpet setup finished, create flag
  3241. echo 'true' > /tmp/pkg/petbuild_prepared
  3242.  
  3243. cd "$CURDIR"
  3244. fi
  3245. }
  3246.  
  3247.  
  3248. pkg_build(){ # build package ($1) from source (see BUILDTOOL in pkgrc) FUNCLIST
  3249.  
  3250. # exit if devx not installed
  3251. [ "`which gcc`" = "" ] && echo "You need the devx SFS installed to compile." && exit 1
  3252.  
  3253. # get the settins from RC file
  3254. . ${PKGRC}
  3255.  
  3256. # we do a different build method for each supported build tool
  3257. case $BUILDTOOL in
  3258.  
  3259. petbuild) # by 01micko
  3260.  
  3261. # use git to install the latest petbuild
  3262. prepare_petbuild
  3263.  
  3264. # if petbuild not installed, quit
  3265. [ ! -d /usr/share/petbuild ] && error "PetBuild not installed at /usr/share/petbuild." && exit 3
  3266.  
  3267. # petbuild needs a package name, or exit
  3268. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-build && exit 1 #220613 #250613
  3269.  
  3270. # get pkg extension
  3271. EX=`get_pkg_ext "$1"`
  3272.  
  3273. # get pkg name only, no extension or path
  3274. PKGNAME="$(basename "$1" .$EX)"
  3275.  
  3276. # get petbuild PKGNAME, then build using 01mickos petbuild
  3277. BUILDSCRIPT="`find /usr/share/petbuild -iname ${PKGNAME}"*.petbuild"| grep -m1 "$PKGNAME"`"
  3278.  
  3279. # if we got a build script
  3280. if [ -f "$BUILDSCRIPT" ]; then
  3281. cd `dirname "$BUILDSCRIPT"`
  3282. # compile the pkg
  3283. bash *.petbuild
  3284. # after build, move any pets created to WORKDIR
  3285. mv /usr/share/petbuild/0pets_out/*.pet "$WORKDIR" 2>/dev/null
  3286. # back to prev dir (WORKDIR)
  3287. cd -
  3288. fi
  3289.  
  3290. # if build script not found, exit
  3291. [ ! -f "$BUILDSCRIPT" ] && echo "Build script for '$PKGNAME' not found in /usr/share/petbuild/" && exit 1
  3292.  
  3293. # get the packages we just moved to WORKDIR
  3294. PKGFILES="`find "$WORKDIR" -iname "$PKGNAME*.pet"`"
  3295.  
  3296. # list any packages we just built
  3297. [ "$PKGFILES" != '' ] && echo -e "${green}Success:${endcolour} Packages in $WORKDIR:" && echo "$PKGFILES"
  3298. ;;
  3299.  
  3300. buildpet) # by Tman/iguleder
  3301.  
  3302. # exit if buildpet dir not found
  3303. [ ! -d /usr/share/buildpet ] && error "buildpet not installed." && exit 1
  3304.  
  3305. # buildpet expects a PKGNAME, or exit
  3306. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-build && exit 1
  3307.  
  3308. # get pkg extension
  3309. EX=`get_pkg_ext "$1"`
  3310.  
  3311. # get pkg name (with version), no extension or path
  3312. PKGNAME="$(basename "$1" .$EX)"
  3313.  
  3314. # get the buildpet script of PKGNAME
  3315. BUILDSCRIPT="`find /usr/share/buildpet/ -name $PKGNAME"*"`"
  3316.  
  3317. # if build script not found, exit
  3318. [ ! -f "$BUILDSCRIPT" ] && echo "Build script for '$PKGNAME' not found in /usr/share/buildpet/" && exit 1
  3319.  
  3320. # now compile the package
  3321. PKG_CONFIGURE="$PKG_CONFIGURE" PKG_CFLAGS="$PKG_CFLAGS" buildpet $BUILDSCRIPT
  3322.  
  3323. ;;
  3324.  
  3325. src2pkg) # by amigo
  3326.  
  3327. ### This code is a horribly simple wrapper to a great tool..
  3328. ### Implement all src2pkg options here at some point..
  3329. ##
  3330. ### We should pass all options to src2pkg, and make it build a
  3331. ### (petbuild|buildpet) buildscipt on successful compile
  3332.  
  3333. # exit if src2pkg not installed
  3334. [ "`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
  3335.  
  3336. # exit if $1 not given or valid
  3337. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-build && exit 1
  3338.  
  3339. # show src2pkg help if user supplied any of the help options
  3340. if [ "$1" = '-h' -o "$1" = '-hh' -o "$1" = '--help' -o "$1" = '--more-help' -o "$1" = '--list' ]; then
  3341. src2pkg $1 | sed -e "s/ src2pkg / $SELF -pb /g"
  3342. echo -e "\n See 'src2pkg' by amigo"
  3343. exit 0
  3344. fi
  3345.  
  3346. # get pkg extension.. not really needed here
  3347. EX=`get_pkg_ext "$1"`
  3348.  
  3349. # use amigos src2pkg
  3350. src2pkg $1
  3351.  
  3352. # if src2pkg exited without error, copy any pets it made to WORKDIR
  3353. [ $? -eq 0 ] && mv /tmp/*.pet "$WORKDIR" 2>/dev/null
  3354.  
  3355. ;;
  3356.  
  3357. sbopkg) # slackware peeps
  3358.  
  3359. # exit if not installed
  3360. [ "`which sbopkg`" = '' ] && error "Sbopkg not installed." && exit 3
  3361.  
  3362. # exit if no valid options
  3363. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-build && exit 1
  3364.  
  3365. sbopkg -b "$1"
  3366.  
  3367. # move any built pkgs to WORKDIR.. need a better way to do this
  3368. if [ "`find /tmp/* -iname $1*.t*`" != '' ]; then
  3369. mv /tmp/*.tgz "$WORKDIR" 2>/dev/null
  3370. mv /tmp/*.txz "$WORKDIR" 2>/dev/null
  3371. mv /tmp/*.tar.xz "$WORKDIR" 2>/dev/null
  3372. echo -e "DONE... The package should be in $WORKDIR."
  3373. fi
  3374.  
  3375. ;;
  3376.  
  3377. *)
  3378. # get pkg name only, no extension or path
  3379. PKGNAME="$(basename "$1" .$EX)"
  3380.  
  3381. echo "Cannot compile '$PKGNAME', no build system installed."
  3382. echo
  3383. echo "Please install one of the following:"
  3384. echo " * petbuild by 01micko: http://murga-linux.com/puppy/viewtopic.php?t=96027"
  3385. echo " * buildpet by Tman: http://murga-linux.com/puppy/viewtopic.php?t=81056"
  3386. echo " * src2pkg by amigo: http://distro.ibiblio.org/amigolinux/download/src2pkg/"
  3387. echo " * sbopkg by various: https://www.sbopkg.org/downloads.php"
  3388. echo
  3389. echo "Then set BUILDTOOL to either petbuild, buildpet, src2pkg or sbopkg "
  3390. echo "in $PKGRC to enable building packages from source."
  3391. echo
  3392. echo "NOTE:"
  3393. echo "01mickos petbuild should be installed to /usr/share/petbuild"
  3394. echo "And Tmans buildpet should be installed to /usr/share/buildpet"
  3395. ;;
  3396. esac
  3397. }
  3398.  
  3399.  
  3400. pkg_repack(){ # create package ($1) from its *.files list FUNCLIST
  3401.  
  3402. # exit if no valid options
  3403. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-repack && exit 1
  3404.  
  3405. local list=''
  3406. local pkg_ext=''
  3407. local PKGNAME=''
  3408. local PKGNAME_ONLY=''
  3409. local dir=''
  3410. local build_number=''
  3411.  
  3412. # get pkg extension
  3413. pkg_ext=`get_pkg_ext "$1"`
  3414.  
  3415. #get pkg name only, no extension or path
  3416. PKGNAME="$(LANG=C basename "$1" .$pkg_ext)"
  3417.  
  3418. # assume the file name from $1
  3419. PKGFILE="${CURDIR}/${PKGNAME}.$pkg_ext"
  3420.  
  3421. # don't rely on the given pkg name string, get the full name from repo if poss
  3422. PKGNAME=`get_pkg_name "$PKGNAME"`
  3423.  
  3424. # get pkg name without version
  3425. PKGNAME_ONLY="`get_pkg_name_only "${PKGNAME}"`"
  3426.  
  3427. # if the list is empty, pkg is not user installed or built in, cant show contents
  3428. [ "`is_installed_pkg "$PKGNAME"`" = false ] && echo "$PKGNAME needs to be installed." && exit 1
  3429.  
  3430. # if the package to built already exists, ask user to delete it
  3431. [ -f "${PKGFILE}" ] && echo "$PKGNAME.$pkg_ext already exists in $CURDIR" && rm -f "${PKGFILE}" 2>/dev/null
  3432.  
  3433. # if pkg exists, user didn't delete it
  3434. [ -f "${PKGFILE}" ] && exit 0
  3435.  
  3436. # get the build number, and increment by one
  3437. build_number="`grep -m1 "^$PKGNAME|$PKGNAME_ONLY|" "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "$DEVX_INST_PKGS_FILE" "$REPO_DB_FILE_DIR"/Packages-* | cut -f4 -d'|'`"
  3438. build_number=${build_number:-0}
  3439. build_number="-$(($build_number + 1))"
  3440.  
  3441. # process the file list, copy each file to our pkg folder
  3442. pkg_contents "$PKGNAME_ONLY" | while read line
  3443. do
  3444. if [ -f "$line" ]; then
  3445. linedir="$(dirname "${line}")"
  3446. [ ! -d "${CURDIR}/$PKGNAME/${linedir}" ] && mkdir -p "${CURDIR}/$PKGNAME/${linedir}"
  3447. cp -p -P "$line" "${CURDIR}/${PKGNAME}/${linedir}"
  3448. fi
  3449. done
  3450.  
  3451. sync
  3452.  
  3453. # make sure we populated a pkg folder, ready to package up
  3454. [ ! -d "${CURDIR}/${PKGNAME}/" ] && error "No '$PKGNAME' directory in $CURDIR" && exit 5
  3455.  
  3456. # pkg folder should be populated, now package it up and print final msg
  3457. dir2pet "${CURDIR}/${PKGNAME}/" "$build_number"
  3458. rm -rf "${CURDIR}/${PKGNAME}/" 2>/dev/null
  3459. rm -rf "${CURDIR}/${PKGNAME}$build_number/" 2>/dev/null
  3460. sync
  3461. }
  3462.  
  3463.  
  3464. pkg_unpack(){ # extract/unpack $1 to current dir FUNCLIST
  3465.  
  3466. # exit if not valid usage
  3467. [ ! -f "$1" ] && print_usage unpack && exit 1
  3468.  
  3469. local PKGNAME
  3470. local PKGFILE
  3471. local PKGEXT
  3472. local comp
  3473.  
  3474. # get pkg details
  3475. PKGFILE="$1"
  3476. PKGNAME=`get_pkg_name "$PKGFILE"`
  3477. PKGEXT=`get_pkg_ext "$PKGFILE"`
  3478.  
  3479. # exit if we dont have enough info
  3480. [ "$PKGEXT" = '' ] && error "Cant get package extension" && exit 1
  3481. [ ! -f "$PKGFILE" ] && error "Cant find $1" && exit 6
  3482. [ "$PKGNAME" = '' ] && error "Cant get PKGNAME" && exit 3
  3483.  
  3484. # support overriding the output dir with $2
  3485. if [ "$2" != "" ]; then
  3486. PKGNAME="$2"
  3487. fi
  3488.  
  3489. # determine compression utility
  3490. case $PKGEXT in
  3491.  
  3492. deb)
  3493. mkdir "$PKGNAME" 2>/dev/null
  3494. rm -rf "$PKGNAME"/* 2>/dev/null
  3495. dpkg-deb -x "$PKGFILE" "$PKGNAME" # extracts main pkg contents
  3496. result=$?
  3497. dpkg-deb -e "$PKGFILE" "$PKGNAME"/DEBIAN # extracts deb control files
  3498. [ $result -eq 0 ] && echo -e "${green}Extracted${endcolour}: ${magenta}`basename $PKGFILE`${endcolour}" || error -e "${red}Error${endcolour}: Cannot extract $PKGFILE"
  3499. return $result
  3500. ;;
  3501.  
  3502. rpm)
  3503. mkdir "${PKGNAME}" 2>/dev/null
  3504. rm -rf "$PKGNAME"/* 2>/dev/null
  3505. # create dir called $PKGNAME, cd into it, extract the rpm in there
  3506. cp "$PKGFILE" "$PKGNAME/"
  3507. cd "$PKGNAME" 1>/dev/null
  3508. # now extract the rpm contents into current dir
  3509. exploderpm -x "$PKGFILE" &>/dev/null
  3510. result=$?
  3511. # clean up and leave
  3512. rm -f *.rpm 2>/dev/null
  3513. cd - 1>/dev/null
  3514. # final msg
  3515. [ $result -eq 0 ] && echo -e "${green}Success${endcolour}: File ${magenta}`basename $PKGFILE`${endcolour} extracted." || error "Cannot extract $PKGFILE"
  3516. return $result
  3517. ;;
  3518.  
  3519. sfs)
  3520.  
  3521. mkdir "/${PKGNAME}" 2>/dev/null
  3522. rm -rf "$PKGNAME"/* 2>/dev/null
  3523.  
  3524. # make mnt dir, mount sfs
  3525. mkdir "/mnt/${PKGNAME}" 2>/dev/null
  3526. mount -t squashfs "$PKGFILE" /mnt/"$PKGNAME" -o loop 1>/dev/null || { error "Could not mount $PKGFILE"; exit 3; }
  3527. # copy sfs contents into ./$PKGNAME
  3528. cp -a -Rf --remove-destination /mnt/"$PKGNAME" "$PKGNAME" || { error "Failed copying files from /mnt/$PKGNAME to ./$PKGNAME"; exit 4; }
  3529. result=$?
  3530. # clean up
  3531. umount "/mnt/${PKGNAME}"
  3532. rmdir "/mnt/${PKGNAME}"
  3533. # final msg
  3534. [ $result -eq 0 ] && echo -e "${green}Success${endcolour}: File ${magenta}`basename $PKGFILE`${endcolour} extracted." || { error "Cannot extract $PKGFILE"; exit 7; }
  3535. return $result
  3536. ;;
  3537. pet) file -b "$PKGFILE" | grep -i -q "^xz" && comp=xz || comp=gzip ;;
  3538. tgz) comp=gzip ;;
  3539. gz) comp=gzip ;;
  3540. tbz) comp=bzip2 ;;
  3541. bz2) comp=bzip2 ;;
  3542. tlz) comp=lzma ;;
  3543. lzma) comp=lzma ;;
  3544. txz) comp=xz ;;
  3545. xz) comp=xz ;;
  3546. esac
  3547. sync
  3548.  
  3549. # if pkg is extractable with tar, then unpack
  3550. case $PKGEXT in
  3551. pet|tgz|gz|tbz|bz2|tlz|lzma|txz|xz)
  3552. ( 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" )
  3553. ;;
  3554. esac
  3555.  
  3556. # return
  3557. return ${result:-0}
  3558.  
  3559. }
  3560.  
  3561.  
  3562. pkg_combine(){ # combine a pkg ($1) and deps into one single pkg FUNCLIST
  3563.  
  3564. # exit if no valid options
  3565. [ ! "$1" -o "$1" = "-" ] && print_usage pkg-combine && exit 1
  3566.  
  3567. . ${PKGRC}
  3568.  
  3569. local EX=''
  3570. local PKGNAME=''
  3571. local PKGNAME_ONLY=''
  3572. local PKG_FILENAME=''
  3573. local PKG_FILE=''
  3574. local ALL_DEPS=''
  3575. local PKG_DEPLIST=''
  3576. local SUFFIX="${CP_SUFFIX}"
  3577. local BUILD_DIR=$TMPDIR/build_pkg
  3578. local SFS_FILE
  3579. local please_wait=false
  3580. local PREVDIR="$CURDIR"
  3581. local ask_opt=$ASK
  3582. local force_opt=$FORCE
  3583.  
  3584. cd "$WORKDIR"
  3585.  
  3586. # get pkg extension
  3587. EX=`get_pkg_ext "$1"`
  3588.  
  3589. # get reliable package names
  3590. PKGNAME="$(basename "$1" .$EX)"
  3591. PKGNAME=`get_pkg_name "$PKGNAME"`
  3592. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  3593.  
  3594. PKG_FILE="${WORKDIR}/${PKGNAME}.$EX" #the file to install
  3595.  
  3596. # we want to include all deps, except builtins, by default
  3597. # we dont set HIDE_BUILTINS here, we leave that up to user
  3598. # when user gives -F, HIDE_BUILTINS= false, and builtin
  3599. # pkgs will be included in the package created
  3600. FORCE=true
  3601. HIDE_USER_PKGS=false
  3602.  
  3603. # get full pkg filename (inc name-ver.ext).. try repos first
  3604. PKG_FILENAME="`cut -f8 -d'|' "$REPO_DB_FILE_DIR"/Packages-* | grep -m1 "^$PKGNAME"`"
  3605. # then WORKDIR if needed (dont include the combined pkgs)
  3606. [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="`ls -1 "$WORKDIR" | grep -v "${SUFFIX}" | grep -v ".sfs\$" | grep -m1 "^$PKGNAME"`"
  3607.  
  3608. # just in case its empty, revert back to the earlier PKGNAME value
  3609. [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="$PKGNAME"
  3610.  
  3611. [ "$PKG_FILENAME" = "" ] && error "Cant find $1" && exit 1
  3612.  
  3613. # update PKGFILE with new pkg filename (PKG)
  3614. PKG_FILE="${WORKDIR}/${PKG_FILENAME}"
  3615.  
  3616. # check if the desired file has already been built
  3617. [ "$COMBINE2SFS" = true ] && final_ext=sfs || final_ext=pet
  3618. [ -f "${WORKDIR}/${PKGNAME}-${SUFFIX}.$final_ext" ] && echo -e "File ${magenta}${WORKDIR}/${PKGNAME}-${SUFFIX}.${final_ext}${endcolour} already exists." && continue
  3619.  
  3620. # get list of deps for PKGNAME, if no deps, exit
  3621. PKG_DEPLIST="`FORCE=$force_opt list_deps $PKGNAME_ONLY`"
  3622. [ "$PKG_DEPLIST" = "" ] && echo "No need to combine, $PKGNAME has no dependencies." && exit 1
  3623.  
  3624. # if exact match of pkgname is found in a repo list
  3625. if [ "`is_repo_pkg "$PKGNAME"`" = true ]; then
  3626.  
  3627. echo "Please wait.. Gathering dependency information."
  3628.  
  3629. # get the deps of the pkg, but dont install
  3630. FORCE=$force_opt find_deps "$PKGNAME"
  3631. ALL_DEPS="`cat $TMPDIR/deps_installed $TMPDIR/deps_missing 2>/dev/null | sort | uniq`"
  3632.  
  3633. # download the needed package
  3634. if [ ! -f "$PKG_FILE" -o "$FORCE" = true ]; then
  3635. ASK=false pkg_download "$PKGNAME"
  3636. fi
  3637.  
  3638. # make work dirs
  3639. mkdir -p "$BUILD_DIR/"
  3640. mkdir -p "$BUILD_DIR/${PKGNAME}-${SUFFIX}"
  3641.  
  3642. if [ -f "$PKG_FILE" ]; then
  3643. # copy the main pkg to the tmp dir
  3644. # and remove the downloade file, we no longer need it
  3645. cp "$PKG_FILE" "$BUILD_DIR/" 2>/dev/null && rm "$PKG_FILE"
  3646. else
  3647. error "Could not add the main package '$PKGNAME_ONLY'"
  3648. fi
  3649.  
  3650.  
  3651. # make a cleaned list to go over (sanity check)
  3652. ALL_DEPS_LIST="`echo "$ALL_DEPS" | tr ',' '\n' | grep -v "^\$" | sort | uniq`"
  3653.  
  3654. # go through each dep listed
  3655. echo "$ALL_DEPS_LIST" | while read LINE
  3656. do
  3657.  
  3658. [ "$LINE" = "" -o "$LINE" = "-" -o "$LINE" = " " -o "$LINE" = "," -o "$LINE" = ", " ] && continue
  3659.  
  3660. # only include builtins if HIDE_BUILTINS=true
  3661. [ "`is_builtin_pkg "$LINE"`" = true -a "$HIDE_BUILTINS" = true ] && continue
  3662.  
  3663. # only include devx pkgs if user gave the -f option
  3664. [ "`is_devx_pkg "$LINE"`" = true -a "$force_opt" = false ] && continue
  3665.  
  3666. # download the matching package(s)
  3667. [ "`list_downloaded_pkgs "$LINE"`" = "" ] && ASK=false pkg_download "$LINE"
  3668.  
  3669. # get the downloaded file
  3670. PKGDEP="`find "$WORKDIR" -maxdepth 1 -type f -name "${LINE}*" | grep -v ".sfs\$" | grep -v "${SUFFIX}" | head -1`"
  3671.  
  3672. # re-try download in other repos if needed
  3673. if [ ! -f "$PKGDEP" ]; then
  3674. PKGREPO=''; PKGREPO="`LANG=C which_repo $LINE | cut -f2 -d' ' | head -1`"
  3675. [ "$PKGREPO" != "" ] && ASK=false pkg_download "$LINE"
  3676. fi
  3677.  
  3678. #if downloaded
  3679. if [ -f "$PKGDEP" -o "$FORCE" = true ]; then
  3680.  
  3681. # copy dep to the tmp dir, with the main pkg
  3682. if [ ! -f "$BUILD_DIR/$PKGDEP" ]; then
  3683. cp "$PKGDEP" "$BUILD_DIR/$(basename $PKGDEP)" && rm "$PKGDEP"
  3684. else
  3685. error "Cannot copy $PKGDEP to $BUILD_DIR/$(basename $PKGDEP)"
  3686. fi
  3687.  
  3688. else # dep not found, may be missing, or in another repo
  3689. echo -e "${yellow}Warning:${endcolour} $LINE not downloaded to $WORKDIR.. Cannot add $LINE.."
  3690. continue
  3691. fi
  3692. done
  3693.  
  3694. # we should now be ready to make our combined pkg
  3695. cd "$BUILD_DIR"
  3696.  
  3697. PARENTPKG=${PKGNAME}
  3698.  
  3699. # for all pkgs in the tmp dir (nto including any 'combined' pkgs)
  3700. TMP_PKGS="`find "$BUILD_DIR/" -maxdepth 1 -type f -name "*" | grep -v $SUFFIX | grep -v ^$ | grep -v ' ' | sort | uniq`"
  3701.  
  3702. local count=1
  3703.  
  3704. for i in $TMP_PKGS
  3705. do
  3706.  
  3707. # skip if not a valid pkg file
  3708. [ ! "$i" -o "$i" = ' ' -o "$i" = '' -o ! -f "$i" ] && continue
  3709.  
  3710. # dont include the combined pkgs
  3711. [ "`echo "$i" | grep -m1 "${SUFFIX}"`" != "" ] && continue
  3712.  
  3713. # get the extensions of each file .. they might be from different repos, so cant use $EX
  3714. base="`basename "$i" 2>/dev/null`"
  3715. FILE_EXT=`get_pkg_ext "$base"`
  3716.  
  3717. [ ! "$base" -o "$base" = ' ' -o "$base" = '' ] && continue
  3718.  
  3719. # get name without version for this pkg ($i)
  3720. name_only=`get_pkg_name_only "$i"`
  3721.  
  3722. [ ! "$name_only" -o "$name_only" = ' ' -o "$name_only" = '' ] && continue
  3723.  
  3724. CONFIRM=y
  3725. if [ "$ask_opt" = true ]; then
  3726. echo -n "Add package: $name_only ($FILE_EXT) (y/N): "
  3727. read -n 1 CONFIRM </dev/tty
  3728. echo
  3729. else
  3730. echo "Adding package: $name_only ($FILE_EXT)"
  3731. fi
  3732.  
  3733. # skip pkg if user wants to skip it
  3734. if [ "$CONFIRM" != 'y' ]; then
  3735. rm "$i"
  3736. continue
  3737. fi
  3738.  
  3739. # add each file
  3740. case $FILE_EXT in
  3741. pet)
  3742.  
  3743. # convert and extract
  3744. pkg_unpack "${i}" 1>/dev/null
  3745. sync
  3746.  
  3747. # copy extracted contents (only the stuff inside the extracted folders)
  3748. if [ ! -d "${i/.pet/}/" ]; then
  3749. error "Dir '${i/.pet/}/' does not exist"
  3750. fi
  3751. cp -a --preserve=all -fr -L "${i/.pet/}/"* "${PARENTPKG}-${SUFFIX}/"
  3752.  
  3753. if [ -f "${i/.pet/}/pinstall.sh" ]; then
  3754. mv "${i/.pet/}/pinstall.sh" "${PARENTPKG}-${SUFFIX}/pinstall_${count}.sh"
  3755. fi
  3756.  
  3757. # now remove the pet and extract folder
  3758. rm "${i}"
  3759. rm -rf "${i/.pet/}/"
  3760. sync
  3761. ;;
  3762.  
  3763. deb)
  3764.  
  3765. #cp "$i" "$BUILD_DIR/${PARENTPKG}-${SUFFIX}"
  3766. pkg_unpack "$i" 2>$TMPDIR/$SELF-cp-errlog
  3767. dpkg-deb -e "$i" "$BUILD_DIR/${PARENTPKG}-${SUFFIX}/DEBIAN"
  3768.  
  3769. # .deb package names often have extra stuff at the end of the file name
  3770. # that does not exist in the root folder name, inside the package.. so
  3771. # we need to strip off that extra stuff to get the correct unpacked
  3772. # package dir
  3773. local pkg_dir="${i/.deb/}/"
  3774. [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_all/}"
  3775. [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_i386/}"
  3776. [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_amd64/}"
  3777. [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/_x64/}"
  3778. [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/~dfsg-[0-9]/}"
  3779. [ ! -d "$pkg_dir" ] && pkg_dir="${pkg_dir/~dsfg-[0-9]/}"
  3780.  
  3781. if [ ! -d "$pkg_dir" ]; then
  3782. needle="$(get_pkg_name "$i")"
  3783. pkg_dir="$(find "${BUILD_DIR}" -type d -iname "$needle" | head -1)"
  3784. fi
  3785.  
  3786. if [ ! -d "$pkg_dir" ]; then
  3787. error "Dir '$pkg_dir' does not exist!"
  3788. fi
  3789.  
  3790. # copy extracted contents (only the stuff inside the extracted folders)
  3791. cp -a --preserve=all -fr -L "${pkg_dir}/"* "${PARENTPKG}-${SUFFIX}/"
  3792.  
  3793. if [ -f "${pkg_dir}DEBIAN/postinst" ]; then
  3794. mv "${pkg_dir}DEBIAN/postinst" "${PARENTPKG}-${SUFFIX}/DEBIAN/postinst_${count}"
  3795. fi
  3796.  
  3797. if [ -f "${pkg_dir}DEBIAN/preinst" ]; then
  3798. mv "${pkg_dir}DEBIAN/preinst" "${PARENTPKG}-${SUFFIX}/DEBIAN/preinst_${count}"
  3799. fi
  3800.  
  3801. # now remove the deb and extracted folder
  3802. rm "$i"
  3803. rm -rf "$pkg_dir"
  3804. sync
  3805. ;;
  3806.  
  3807. *tgz|*txz|*tar.gz|*tar.xz|*xz|*gz)
  3808.  
  3809. pkg_unpack "$i" 1>/dev/null
  3810.  
  3811. # now copy $BUILD_DIR/$PKGNAME/* into our output (combined pkg) dir
  3812. cp -a --preserve=all -fr -L "${name_only}/"* "${PARENTPKG}-${SUFFIX}/" || error "Dir '${name_only}/' does not exist!"
  3813.  
  3814. if [ -f "${PARENTPKG}-${SUFFIX}/install/doinst.sh" ]; then
  3815. mv "${PARENTPKG}-${SUFFIX}/install/doinst.sh" "${PARENTPKG}-${SUFFIX}/install/doinst_${count}.sh"
  3816. fi
  3817.  
  3818. # remove the package and folder we just extracted
  3819. rm "$i"
  3820. rm -rf "${i/.*/}/"
  3821. sync
  3822. ;;
  3823.  
  3824. rpm)
  3825. pkg_unpack "$i" 1>/dev/null
  3826.  
  3827. # now copy $BUILD_DIR/$PKGNAME/* into our output (combined pkg) dir
  3828. cp -a --preserve=all -fr -L "${name_only}/"* "${PARENTPKG}-${SUFFIX}/"
  3829.  
  3830. if [ -f "${PARENTPKG}-${SUFFIX}/install/doinst.sh" ]; then
  3831. mv "${PARENTPKG}-${SUFFIX}/install/doinst.sh" "${PARENTPKG}-${SUFFIX}/install/doinst_${count}.sh"
  3832. fi
  3833.  
  3834. # remove the package and folder we just extracted
  3835. rm "$i"
  3836. rm -rf "${i/.rpm/}/"
  3837. ;;
  3838.  
  3839. esac
  3840. count=$(($count + 1))
  3841. done
  3842.  
  3843. # we have now unpacked the package, lets combine the pre/post install scripts
  3844. # into one pinstall.sh script
  3845.  
  3846. local pinstall_file="$BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh"
  3847.  
  3848. # append this pinstall/postinst/doinst script to a new pinstall.sh
  3849. echo '#!/bin/sh' > "$pinstall_file"
  3850.  
  3851. # concat the post install scripts (for puppy, slackware, arch, debian/ubuntu, etc) into 'pinstall.sh'
  3852. for i in ${PARENTPKG}-${SUFFIX}/pinstall_* ${PARENTPKG}-${SUFFIX}/install/doinst_* ${PARENTPKG}-${SUFFIX}/DEBIAN/postinst_*
  3853. do
  3854. [ -z ${PARENTPKG}-${SUFFIX}/${i} ] && continue
  3855. cd ${PARENTPKG}-${SUFFIX}/ 2>/dev/null
  3856.  
  3857. files=`find . -type f -iname "$(basename $i)"`
  3858.  
  3859. for file in $files
  3860. do
  3861. if [ -f "$file" ]; then
  3862. echo "Appending ${file} to $pinstall_file"
  3863. cat ${file} | grep -vE '^#!|^exit|exit 0|exit 1' >> "$pinstall_file"
  3864. echo '' >> "$pinstall_file"
  3865. fi
  3866. done
  3867. # we have combined the pre/post install stuff in $i into a new, combined file,
  3868. # so remove the original
  3869. rm -f ${PARENTPKG}-${SUFFIX}/${i}
  3870. done
  3871.  
  3872. chmod +x $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh 2>/dev/null
  3873.  
  3874. #xmessage "$(cat $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall.sh)"
  3875.  
  3876. # remove any debian/ubuntu/slackware pre/post install stuff left in the package
  3877. rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/pinstall_*
  3878. rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/install
  3879. rm -rf $BUILD_DIR/${PARENTPKG}-${SUFFIX}/DEBIAN
  3880.  
  3881. # fix the symlinks to lib dirs - the linux-gnu-* dirs are symlinks in puppy,
  3882. # so make sure we dont replace them with dirs (or programs won't load)
  3883. for libdir in i386-linux-gnu i486-linux-gnu i586-linux-gnu i686-linux-gnu amd64-linux-gnu
  3884. do
  3885. if [ -d $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/${libdir}/ ]; then
  3886. mv -n -u $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/${libdir}/* $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib/
  3887. cd $BUILD_DIR/${PARENTPKG}-${SUFFIX}/usr/lib
  3888. rmdir ${libdir}/
  3889. ln -s ${libdir}/ .
  3890. cd -
  3891. fi
  3892. done
  3893.  
  3894.  
  3895. # now we are ready to build our combined pkg
  3896. [ "`pwd`" != "$BUILD_DIR" ] && cd "$BUILD_DIR/"
  3897.  
  3898.  
  3899. # if not building SFS, build a .pet
  3900. if [ "$COMBINE2SFS" = false ]; then #240613
  3901. echo "Building PET package.. Please wait.."
  3902.  
  3903. # build pet package... start with $removing PKGNAME-${SUFFIX}.pet.specs
  3904. rm ${PKGNAME}-${SUFFIX}/*.specs 2>/dev/null
  3905.  
  3906. # get compression type
  3907. file -b "${PKGNAME}-${SUFFIX}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  3908.  
  3909. # tar up the folder
  3910. tar -c -f ${PKGNAME}-${SUFFIX}.tar ${PKGNAME}-${SUFFIX} &>/dev/null
  3911. sync
  3912.  
  3913. case $TAREXT in
  3914. xz)xz -z -9 -e ${PKGNAME}-${SUFFIX}.tar ;;
  3915. gz)gzip --best ${PKGNAME}-${SUFFIX}.tar ;;
  3916. esac
  3917.  
  3918. TARBALL="${PKGNAME}-${SUFFIX}.tar.$TAREXT"
  3919. FULLSIZE="`stat --format=%s ${TARBALL}`"
  3920. MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  3921. echo -n "$MD5SUM" >> $TARBALL
  3922. sync
  3923.  
  3924. mv -f $TARBALL ${PKGNAME}-${SUFFIX}.pet
  3925. sync
  3926.  
  3927. if [ $? -eq 1 ]; then
  3928. echo "Cannot create PET file ${PKGNAME}-${SUFFIX} from dir."
  3929. error "Please check `pwd`"
  3930. fi
  3931.  
  3932. # move our new PET to $WORKDIR
  3933. mv ${PKGNAME}-${SUFFIX}.pet $WORKDIR/${PKGNAME}-${SUFFIX}.pet
  3934. # get the size
  3935. s=`LANG=C du -m "$WORKDIR/${PKGNAME}-${SUFFIX}.pet" | sed "s/\s.*//"`
  3936.  
  3937. else #240613 build a .sfs
  3938. echo "Building SFS package.. Please wait.."
  3939.  
  3940. dir2sfs "${PKGNAME}-${SUFFIX}" 1>/dev/null
  3941.  
  3942. # get the full file name, it may (or not) have been appended with '-DISTRO_VERSION'
  3943. SFS_FILE=`find . -maxdepth 1 -type f -name "*${PKGNAME}-${SUFFIX}*.sfs" | head -1`
  3944.  
  3945. s=`LANG=C du -m "${SFS_FILE}" | sed "s/\s.*//"`
  3946. MD5SUM=`md5sum "$SFS_FILE" | cut -f1 -d ' '`
  3947. mv "$SFS_FILE" "$WORKDIR/"
  3948. fi
  3949.  
  3950. # done, go back to work dir from WORKDIR/build_pkg
  3951. cd "$WORKDIR"
  3952. rm -R "$BUILD_DIR/" 2>/dev/null
  3953.  
  3954. # create install command
  3955. if [ "$COMBINE2SFS" = false ]; then
  3956. PKGEXT=pet
  3957. PKGCMD="Install command: $SELF install ${WORKDIR}/${PKGNAME}-${SUFFIX}"
  3958. else
  3959. PKGEXT=sfs
  3960. PKGCMD="Install command: sfs_loadr --cli -q \"${WORKDIR}/$(basename $SFS_FILE)\""
  3961. fi
  3962.  
  3963. #226013 updated output
  3964. echo -e "Created package ${magenta}${PKGNAME}-${SUFFIX}.${PKGEXT}${endcolour} (${s}MB)"
  3965. echo "The md5 checksum: $MD5SUM"
  3966. echo "$PKGCMD"
  3967.  
  3968. else # no exact PKGNAME match in repo
  3969. not_found "${PKGNAME}"
  3970. exit 1
  3971. fi
  3972.  
  3973. cd "$PREVDIR"
  3974. }
  3975.  
  3976.  
  3977. merge_pkg(){ # merge the given comma-separated packages FUNCLIST
  3978. # make sure at least 2 packages exist
  3979.  
  3980. [ ! "$1" ] && print_usage merge && exit 1
  3981. [ "$(echo "$1" |grep ',')" = "" ] && print_usage merge && exit 1
  3982.  
  3983. cd "$WORKDIR" 1>/dev/null
  3984.  
  3985. local PKG_LIST="$(echo "${1}" | tr ',' '\n' | sort -u | uniq)"
  3986. local SUFFIX=''
  3987.  
  3988. if [ "$2" = "--with-deps" ]; then
  3989. SUFFIX="-WITHDEPS"
  3990. echo "Gathering dependencies to include.."
  3991. echo
  3992. # add deps of pkgs to list of pkgs to merge
  3993. for package in $PKG_LIST
  3994. do
  3995. PKG_LIST="$PKG_LIST $(pkg le $package)"
  3996. done
  3997. PKG_LIST="$(echo "$PKG_LIST" | tr ' ' '\n' | sort -u | uniq)"
  3998. fi
  3999.  
  4000. echo "Merging the following packages:"
  4001. echo
  4002. echo "${PKG_LIST}" | sed 's/^/ /g'
  4003. echo
  4004.  
  4005. # get a new package name for the new, merged package
  4006. local PKGNAME="`get_pkg_name "$(basename "${1//,*/}")" 2>/dev/null`"
  4007. bash -c 'read -e -r -p "Enter a package name and hit ENTER: " -i "${PKGNAME}-MERGED${SUFFIX}" NEWPKGNAME; echo $NEWPKGNAME > /tmp/pkg/NEWPKGNAME'
  4008. echo
  4009. NEWPKGNAME="$(cat /tmp/pkg/NEWPKGNAME)"
  4010.  
  4011. if [ "$NEWPKGNAME" = "" ]; then
  4012. echo "You must give a new package name!"
  4013. return 1
  4014. fi
  4015.  
  4016. rm -rf "${NEWPKGNAME}/" &>/dev/null
  4017. mkdir "${NEWPKGNAME}"
  4018.  
  4019. # remove any old folders
  4020. rm -rf ${WORKDIR}${NEWPKGNAME}/ &>/dev/null
  4021.  
  4022. # for each package to merge
  4023. for package in $PKG_LIST
  4024. do
  4025.  
  4026. # get the package details
  4027. local PKGNAME="`get_pkg_name "$(basename "$package")" 2>/dev/null`"
  4028. local PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME" 2>/dev/null`"
  4029. local PKGEXT="`get_pkg_ext "$PKGNAME"`"
  4030. local PKGFILE=''
  4031.  
  4032. [ "$PKGNAME" = "" ] && continue
  4033. [ "$PKGNAME" = " " ] && continue
  4034. [ "$PKGNAME" = "-" ] && continue
  4035.  
  4036. # download it
  4037. pkg_download "$PKGNAME"
  4038.  
  4039. retval=$?
  4040.  
  4041. if [ $retval -eq 1 ]; then
  4042. echo -e "${yellow}Warning${endcolour}: package '$PKGNAME' not downloaded."
  4043. continue
  4044. fi
  4045.  
  4046. # get the downloaded file
  4047. PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME}*${PKGEXT}")"
  4048.  
  4049. [ ! -f "$PKGFILE" ] && \
  4050. PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME_ONLY}_*${PKGEXT}")"
  4051.  
  4052. [ ! -f "$PKGFILE" ] && \
  4053. PKGFILE="$(find $WORKDIR -maxdepth 1 -type f -name "${PKGNAME_ONLY}-*${PKGEXT}")"
  4054.  
  4055. if [ ! -f "$PKGFILE" ]; then
  4056. echo -e "${red}Error${endcolour}: could not find downloaded package '$PKGFILE'"
  4057. return 1
  4058. fi
  4059.  
  4060. # unpack the downloaded file
  4061. pkg_unpack "$PKGFILE"
  4062. rm "${PKGFILE}"
  4063.  
  4064. # move the unpacked files into our new package dir
  4065. PKGDIR="$(find $WORKDIR -maxdepth 1 -type d -name "${PKGNAME}*" | grep -v ${NEWPKGNAME})"
  4066.  
  4067. if [ ! -d "$PKGDIR" ]; then
  4068. echo -e "${red}Error${endcolour}: could not find extracted package dir '$PKGDIR'"
  4069. return 1
  4070. fi
  4071.  
  4072. cp -R "$PKGDIR"/* "$NEWPKGNAME"
  4073. rm -rf "${PKGDIR}/"
  4074. done
  4075.  
  4076. if [ ! -d "${WORKDIR}/$NEWPKGNAME" ]; then
  4077. echo -e "${red}Error${endcolour}: Dir ${lightblue}${NEWPKGNAME}${endcolour} NOT created!"
  4078. return 1
  4079. fi
  4080.  
  4081. echo
  4082. echo "Package contents:"
  4083. find "${NEWPKGNAME}/"
  4084. echo '--------------------------------'
  4085. echo
  4086.  
  4087. # create the merged PET package
  4088. dir2pet "${NEWPKGNAME}/" || error "Could not create $NEWPKGNAME} PET file"
  4089.  
  4090. rm -rf "./${NEWPKGNAME}/" &>/dev/null
  4091. rm -rf "${WORKDIR}/${NEWPKGNAME}/" &>/dev/null
  4092.  
  4093. # get the filename of the new PET package
  4094. NEWPKGFILENAME="$(find . -maxdepth 1 -type f -name "${NEWPKGNAME}*.pet")"
  4095.  
  4096. # output messages
  4097. if [ ! -f "$NEWPKGFILENAME" ]; then
  4098. echo
  4099. echo -e "${red}Error${endcolour}: Package ${yellow}${NEWPKGFILENAME}${endcolour} NOT created!"
  4100. return 1
  4101. fi
  4102.  
  4103. return 0
  4104. }
  4105.  
  4106.  
  4107. split_pkg(){ # split package ($1) into dev, doc, nls packages FUNCLIST
  4108.  
  4109. # make sure the package exists
  4110. [ ! "$1" -o ! -f "$1" ] && print_usage split && exit 1
  4111.  
  4112. local PKGNAME="`get_pkg_name "$(basename "$1")" 2>/dev/null`"
  4113. local PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME" 2>/dev/null`"
  4114. local PKGEXT="pet"
  4115.  
  4116. # get package extension
  4117. PKGEXT="`get_pkg_ext "$1"`"
  4118.  
  4119. pkg_unpack "$1" &>/dev/null
  4120.  
  4121. # get the package directory we just extracted
  4122. local PKG_PATH="$(find $(dirname "$PKGNAME") -maxdepth 1 -type d -iname "$PKGNAME" | head -1)"
  4123.  
  4124. # get the full path to the package dir (dir with contents of pkg to be split)
  4125. PKG_PATH="$(realpath "$PKG_PATH")"
  4126.  
  4127. # make sure we have the right package dir
  4128. [ ! -d "$PKG_PATH" ] && PKG_PATH="$(realpath "$PKGNAME")"
  4129.  
  4130. # get the base name of the package directory
  4131. local PKG_DIR_NAME=$(basename "$PKG_PATH")
  4132.  
  4133. # get the package name
  4134. local PKG_NAME="$PKGNAME_ONLY"
  4135.  
  4136. # get the parent directory of the package
  4137. local PARENT_DIR="$(dirname "$PKG_PATH")"
  4138.  
  4139. # set the correct package naming style
  4140. local dev_suffix='_DEV'
  4141. local doc_suffix='_DOC'
  4142. local nls_suffix='_NLS'
  4143. if [ "${PKGEXT:-pet}" = "deb" ]; then
  4144. dev_suffix='-dev'
  4145. doc_suffix='-doc'
  4146. nls_suffix='-nls'
  4147. fi
  4148.  
  4149. # get the sub-package names
  4150. local EXE_PKG="$PKGNAME"
  4151. local DEV_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${dev_suffix}/")"
  4152. local DOC_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${doc_suffix}/")"
  4153. local NLS_PKG="$(echo "$PKG_DIR_NAME" | sed -e "s/^${PKGNAME_ONLY}/${PKGNAME_ONLY}${nls_suffix}/")"
  4154.  
  4155. # remove the target package dirs if they already exist
  4156. [ -d "$DEV_PKG" ] && rm -rf "$DEV_PKG"
  4157. [ -d "$DOC_PKG" ] && rm -rf "$DOC_PKG"
  4158. [ -d "$NLS_PKG" ] && rm -rf "$NLS_PKG"
  4159. # now create them fresh and empty
  4160. mkdir -p "$DEV_PKG"
  4161. mkdir -p "$DOC_PKG"
  4162. mkdir -p "$NLS_PKG"
  4163.  
  4164. # make sure the package directory begins with the given package name
  4165. case $(basename "$PKG_PATH") in
  4166. $PKG_NAME*)
  4167. ;;
  4168. *)
  4169. echo "Error: $(basename "$PKG_PATH") must match $PKG_NAME"
  4170. print_usage split
  4171. exit 1
  4172. ;;
  4173. esac
  4174.  
  4175. cd "$PKG_PATH" &>/dev/null || { echo "Not found: $PKG_PATH"; return 1; }
  4176.  
  4177. for i in $(find -mindepth 1)
  4178. do
  4179. # if the file no longer exists, skip this iteration
  4180. [ ! -e "$i" ] && continue
  4181.  
  4182. local FILE_NAME=$(basename "$i")
  4183.  
  4184. case "$FILE_NAME" in
  4185. *.la|*.a|*.o|*.prl|pkgconfig|include|*.m4|*.h|*.c|*.cpp)
  4186. PKGNAME="$DEV_PKG"
  4187. ;;
  4188. gdb)
  4189. [ -d "$i" ] && PKGNAME="$DEV_PKG"
  4190. ;;
  4191. dir)
  4192. [ -f "$i" ] && PKGNAME="$DOC_PKG"
  4193. ;;
  4194. 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)
  4195. PKGNAME="$DOC_PKG"
  4196. ;;
  4197. help)
  4198. [ -d "$i" ] && PKGNAME="$DOC_PKG"
  4199. ;;
  4200. man|info) # if it's a directory named "man" or "info", move to doc
  4201. [ -d "$i" ] && PKGNAME="$DOC_PKG"
  4202. ;;
  4203. locale|locales|lang|strings) # if it's a directory named "locale", move to nls
  4204. [ -d "$i" ] && PKGNAME="$NLS_PKG"
  4205. ;;
  4206. i18n|nls)
  4207. PKGNAME="$NLS_PKG"
  4208. ;;
  4209. system.profile-*|*.strings|normal.awt-*) # AbiWord stores its locale information in those files
  4210. [ "$PKGNAME_ONLY" = "abiword" ] && PKGNAME="$NLS_PKG"
  4211. ;;
  4212. *)
  4213. PKGNAME="$EXE_PKG"
  4214. ;;
  4215. esac
  4216.  
  4217. # verbosity, output the redirection for each redirected file
  4218. case "$PKGNAME" in
  4219. $DEV_PKG|$DOC_PKG|$NLS_PKG)
  4220. #local SUFFIX="$(echo $SUFFIX | tr [:lower:] [:upper:])"
  4221.  
  4222. #echo "$FILE_NAME -> $PKG"
  4223.  
  4224. # detect the sub_directory inside the package
  4225. local SUB_DIR="${i%/$FILE_NAME}"
  4226. SUB_DIR="${SUB_DIR:2}"
  4227.  
  4228. # create the directory under the sub-package directory
  4229. mkdir -p "$PARENT_DIR/$PKGNAME/$SUB_DIR"
  4230.  
  4231. # move the file to the sub-package
  4232. mv "$i" "$PARENT_DIR/$PKGNAME/$SUB_DIR"
  4233.  
  4234. # get rid of empty directories in the EXE package
  4235. rmdir "$SUB_DIR" &>/dev/null
  4236. ;;
  4237. esac
  4238.  
  4239. done
  4240.  
  4241. # if the EXE package is empty, remove it
  4242. is_empty="$(find "$PKG_PATH" -maxdepth 2 -type f 2>/dev/null)"
  4243. [ -z "$is_empty" ] && rm -rf "$PKG_PATH"
  4244.  
  4245. # go back to where we started (where the main package lives)
  4246. [ -d "$CURDIR" ] && cd "$CURDIR" &>/dev/null
  4247.  
  4248. # build each package from the package dir
  4249. for dir in "$EXE_PKG" "$DEV_PKG" "$DOC_PKG" "$NLS_PKG"
  4250. do
  4251. if [ -d "$dir" ]; then
  4252. dir2${PKGEXT//./} "$dir" && rm -rf "$dir"
  4253. fi
  4254. done
  4255.  
  4256. # get a list of the new packages we created
  4257. new_pkgs="$(find . -maxdepth 1 -type f -name "${PKGNAME}*.$PKGEXT"
  4258. find . -maxdepth 1 -type f -name "${DEV_PKG}*.$PKGEXT"
  4259. find . -maxdepth 1 -type f -name "${DOC_PKG}*.$PKGEXT"
  4260. find . -maxdepth 1 -type f -name "${NLS_PKG}*.$PKGEXT")"
  4261.  
  4262. if [ "$new_pkgs" != "" ]; then
  4263. echo
  4264. echo -e "${green}Success${endcolour}: Package split into these new files:"
  4265. echo "$new_pkgs" | sed 's/^.\// /'
  4266. fi
  4267.  
  4268. # cleanup
  4269. [ -d "$DEV_PKG" ] && rm -rf "$DEV_PKG"
  4270. [ -d "$DOC_PKG" ] && rm -rf "$DOC_PKG"
  4271. [ -d "$NLS_PKG" ] && rm -rf "$NLS_PKG"
  4272.  
  4273. return 0
  4274. }
  4275.  
  4276.  
  4277.  
  4278. # main pkg funcs
  4279.  
  4280. pkg_download(){ # download a pkg ($1) to WORKDIR FUNCLIST
  4281.  
  4282. # exit if no valid options
  4283. [ ! "$1" -o "$1" = "-" ] && print_usage download && exit 1
  4284.  
  4285. . ${PKGRC}
  4286.  
  4287. local pkg_ext='' # extension of pkg, empty if not a supported pkg ext
  4288. local PKGNAME='' # the pkgname with version
  4289. local ORIG_PKGNAME='' # keeps the original pkg name ($1)
  4290. local PKG_FILENAME='' # package file name (field 8 of repo, with extension)
  4291. local PKGFILE='' # full path to package file
  4292. local NET='' # 1 or 0 if net connection available
  4293. local curr_repo='' # name of current repo in the loop
  4294. local curr_repo_ext='' # pkg ext for the current repo in the loop
  4295. local prev_repo_url='' # holder for the prev checked url we know is working
  4296. local curr_repo_url='' # mirror that is used to download the pkg
  4297. local curr_repo_url1='' # mirror1 for the current repo in the loop
  4298. local curr_repo_url2='' # mirror2 for the current repo in the loop
  4299. local curr_repo_url3='' # mirror3 for the current repo in the loop
  4300. local curr_repo_url4='' # mirror4 for the current repo in the loop
  4301. local pkg_in_repo='' # true if pkg found in ANY repo, else false
  4302.  
  4303. # get pkg extension
  4304. pkg_ext=`get_pkg_ext "$1"`
  4305.  
  4306. # get pkg name with version (if given!), no extension or path
  4307. PKGNAME="$(basename "$1" .$pkg_ext)"
  4308.  
  4309. # get full package name from given pkg name string .. vlc -> vlc-1.2.3-blah
  4310. PKGNAME=`get_pkg_name "$PKGNAME"`
  4311.  
  4312. # the file to save to.. not reliable till we checked the repos
  4313. PKGFILE="${WORKDIR}/${PKGNAME}.$pkg_ext"
  4314.  
  4315. # set download options
  4316. [ "$FORCE" = true ] && CONTINUE='' || CONTINUE='-c'
  4317. [ "$ASK" != true ] && QTAG=''
  4318.  
  4319. #if pkg not yet downloaded, or we are downloading all, or we are forcing downloads
  4320. if [ ! -f "$PKGFILE" -o "$NO_INSTALL" = true -o "$FORCE" = true ]; then
  4321.  
  4322. # mark this pkg as not yet downloaded
  4323. DONE=false
  4324.  
  4325. # exit if no internet connection
  4326. #NET="`check_net`"; [ $NET -eq 1 ] && echo "You need an internet connection" && exit 2
  4327.  
  4328. # for each repo, starting with current repo
  4329. repo_file_list | while read repo_file
  4330. do
  4331.  
  4332. # the file with our repo URL info
  4333. sources_file="${HOME}/.pkg/sources"
  4334.  
  4335. # check if $repo_file contains the given pkg
  4336. pkg_in_this_repo="$(LANG=C cut -f1,2,7,8 -d'|' "$REPO_DB_FILE_DIR/$repo_file" 2>/dev/null | sed -e "s/^/|/" -e "s/$/|/" | grep -m1 "|${PKGNAME}|")"
  4337. [ "$pkg_in_this_repo" = '' ] && pkg_in_this_repo="$(LANG=C cut -f1,2,7,8 -d'|' "$REPO_DB_FILE_DIR/$repo_file" 2>/dev/null | sed -e "s/^/|/" -e "s/$/|/" | grep -m1 "|${PKGNAME}")"
  4338.  
  4339. # if package file found in current repo file
  4340. if [ "$pkg_in_this_repo" != "" ]; then #if true, its an exact match
  4341.  
  4342. # get name of current repo in loop
  4343. prev_repo="$curr_repo"
  4344. curr_repo="`LANG=C grep $repo_file $sources_file 2>/dev/null | cut -f1 -d'|'`"
  4345.  
  4346. # get ext of cur repo, it might be different
  4347. curr_repo_ext="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f2 -d'|'`"
  4348.  
  4349. # keep a copy of the PKGNAME we got from `get_pkg_name $1`
  4350. ORIG_PKGNAME=$PKGNAME
  4351.  
  4352. # get proper PKGNAME (inc name-ver) from the repo
  4353. PKGNAME="`echo "$pkg_in_this_repo" | cut -f3 -d'|'`"
  4354. # just in case it didn't work, revert back to the old PKGNAME value
  4355. [ "$PKGNAME" = "" ] && PKGNAME="$ORIG_PKGNAME"
  4356.  
  4357. # get full pkg FILENAME (inc name-ver.ext) from the repo
  4358. PKG_FILENAME="`echo "$pkg_in_this_repo" | cut -f5 -d'|'`"
  4359.  
  4360. # just in case its empty, revert back to the earlier PKGNAME value
  4361. [ "$PKG_FILENAME" = "" ] && PKG_FILENAME="$PKGNAME"
  4362.  
  4363. # update the filename to check/download
  4364. PKGFILE="${WORKDIR}/${PKG_FILENAME}"
  4365.  
  4366. # skip if downloaded already, print msg
  4367. [ -f "$PKGFILE" -a "$FORCE" = false ] && DONE=true && echo -e "Already downloaded ${magenta}${PKG_FILENAME}${endcolour}" && continue
  4368.  
  4369. # update the package name, based on PKG_FILENAME
  4370. PKGNAME="$(basename "$PKG_FILENAME" .$curr_repo_ext)"
  4371.  
  4372. # update generic name
  4373. PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  4374.  
  4375. if [ "${PKG_FILENAME}" = '' ]; then
  4376. error "Cant find pkg file name, needed to download"
  4377. return 1
  4378. fi
  4379.  
  4380. # skip pings and download if already downloaded.. unless forcing download
  4381. if [ ! -f "$PKGFILE" -o "$FORCE" = true ]; then
  4382.  
  4383. # ask user to download
  4384. echo -en "Download ${magenta}${PKGNAME_ONLY}${endcolour} from ${lightblue}${curr_repo}${endcolour} repo$QTAG: "
  4385. [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  4386. [ "$CONFIRM" != 'y' ] && echo
  4387.  
  4388. # if user answered yes, we will now download the pkgs
  4389. if [ "$CONFIRM" = "y" ]; then #25073
  4390.  
  4391. # only ask once
  4392. ASK=false
  4393.  
  4394. echo # start a new line
  4395.  
  4396. # get the subdir (from repo line) that the package lives in
  4397. sub_dir="`echo "$pkg_in_this_repo" | cut -f4 -d'|' | sed 's/^\.//'`"
  4398.  
  4399. if [ "$sub_dir" = "." ]; then
  4400. sub_dir=''
  4401. fi
  4402.  
  4403. #s243a: TODO: figure out what this file is for???
  4404. # pre-woof get subdir
  4405. if [ "$sub_dir" != "" ] && [ -f "$PKGS_DIR/${repo_file}_subdirs" ]; then
  4406. sub_dir="`grep -m1 "^$PKGNAME|" "$PKGS_DIR/${repo_file}_subdirs" 2>/dev/null | cut -f7 -d'|'`"
  4407. fi
  4408. #s243a: TODO: maybe if the folowing produces a trailing double slash than remove it.
  4409. # get repo mirrors (only url1 is required .. we also add a final /)
  4410. curr_repo_url1="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f4 -d'|'`/"
  4411. curr_repo_url2="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f5 -d'|'`/"
  4412. curr_repo_url3="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f6 -d'|'`/"
  4413. curr_repo_url4="`LANG=C grep $repo_file $sources_file 2>/dev/null| cut -f7 -d'|'`/"
  4414.  
  4415. # make a space separated list of all our repo URLs
  4416. curr_repo_url_list="$curr_repo_url1 $curr_repo_url2 $curr_repo_url3 $curr_repo_url4"
  4417.  
  4418. # clean up the list, remove any double slashes at the end of each URL
  4419. curr_repo_url_list="`echo "$curr_repo_url_list" | sed -e "s|// |/ |g" -e "s|//\$|/\$|g"`"
  4420.  
  4421. # update the ext to that of current repo
  4422. pkg_ext="$curr_repo_ext"
  4423.  
  4424. # get the best repo mirror
  4425. #if [ "$prev_repo" != "$current_repo" -a -f $TMPDIR/curr_repo_url ] || [ ! -f $TMPDIR/curr_repo_url ]; then
  4426. #echo "Checking '$curr_repo' repo mirrors..."
  4427. for URL in $curr_repo_url_list
  4428. do
  4429. [ -z "$URL" ] && continue
  4430. [ "$URL" = '/' ] && continue
  4431. [ "$URL" = '' ] && continue
  4432. #s243a:TODO: The following additions to the URL doesn't seem to do anything
  4433. # add some system values into the repo URL (arch, distro version, etc.. from DISTRO_SPECS)
  4434. URL="`echo "$URL"| sed -e 's@${DBIN_ARCH}@'$DBIN_ARCH'@g'`"
  4435. URL="`echo "$URL"| sed -e 's@${DISTRO_COMPAT_VERSION}@'$DISTRO_COMPAT_VERSION'@g'`"
  4436. URL="`echo "$URL"| sed -e 's@${DDB_COMP}@'$DDB_COMP'@g'`"
  4437. URL="`echo "$URL"| sed -e 's@${SLACKWARE}@'$SLACKWARE'@g'`"
  4438. URL="`echo "$URL"| sed -e 's@${SLACKARCH}@'$SLACKARCH'@g'`"
  4439. URL="`echo "$URL"| sed -e 's@${lxDISTRO_COMPAT_VERSION}@'$lxDISTRO_COMPAT_VERSION'@g'`"
  4440. #ping -W2 -c1 -q $(echo "${URL}" | awk -F/ '{print $3}') &>/dev/null
  4441. wget --quiet --timeout=1 --no-parent --spider "${URL}"
  4442. REPLY=$?
  4443. if [ "$REPLY" = 0 ]; then
  4444. # set the current URL
  4445. curr_repo_url="$URL"
  4446. if [ ! -z "$curr_repo_url" ]; then
  4447. echo "$curr_repo_url" > $TMPDIR/curr_repo_url
  4448. break
  4449. fi
  4450. fi
  4451. done
  4452. #else
  4453. # curr_repo_url="`cat $TMPDIR/curr_repo_url`"
  4454. #fi
  4455.  
  4456. # exit if URL is not found or empty
  4457. if [ -z "$curr_repo_url" ]; then
  4458. error "Package URL not found"
  4459. return 8
  4460. fi
  4461.  
  4462. # lets build our DOWNLOAD_URL: set it to the working repo mirror we found above
  4463. DOWNLOAD_URL="${curr_repo_url}"
  4464.  
  4465. # now add the subdir to DOWNLOAD_URL .. sub_dir may be empty, but we add a trailing '/' anyway
  4466. DOWNLOAD_URL="${DOWNLOAD_URL}${sub_dir}/"
  4467.  
  4468. # add some system values into the repo URL (arch, distro version, etc.. from DISTRO_SPECS)
  4469. DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DBIN_ARCH}@'$DBIN_ARCH'@g'`"
  4470. DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DISTRO_COMPAT_VERSION}@'$DISTRO_COMPAT_VERSION'@g'`"
  4471. DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${DDB_COMP}@'$DDB_COMP'@g'`"
  4472. DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${SLACKWARE}@'$SLACKWARE'@g'`"
  4473. DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${SLACKARCH}@'$SLACKARCH'@g'`"
  4474. DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e 's@${lxDISTRO_COMPAT_VERSION}@'$lxDISTRO_COMPAT_VERSION'@g'`"
  4475.  
  4476. # add our package to the URL
  4477. DOWNLOAD_URL="${DOWNLOAD_URL}${PKG_FILENAME}"
  4478.  
  4479. # 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)
  4480. DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e "s@//$PKG_FILENAME@/$PKG_FILENAME@g"`"
  4481.  
  4482. # if sub_dir not empty, lets clean that bit too
  4483. [ "$sub_dir" != '' ] && DOWNLOAD_URL="`echo "$DOWNLOAD_URL"| sed -e "s@//${sub_dir}@/${sub_dir}@g" -e "s@${sub_dir}//@${sub_dir}/@g"`"
  4484.  
  4485. # exit if URL is not found (if we get a 404 back)
  4486. if [ -z "$DOWNLOAD_URL" -o "`wget -S --spider "$DOWNLOAD_URL" 2>&1 | grep -m1 'HTTP/1.1 404 Not Found'`" != '' ]; then
  4487. error "Package URL not found $DOWNLOAD_URL"
  4488. return 8
  4489. fi
  4490.  
  4491. # we may be using multiple URLs, so each time we change URL,
  4492. # remember the new one
  4493. if [ "$OLDURL" != "$DOWNLOAD_URL" ]; then
  4494. OLDURL="$DOWNLOAD_URL";
  4495. #echo -e "URL: ${lightblue}${DOWNLOAD_URL}${endcolour}";
  4496. fi
  4497.  
  4498. # if --force, remove the package if it already exists
  4499. [ "$FORCE" = true ] && rm -f "${WORKDIR}/${PKG_FILENAME}" &>/dev/null
  4500.  
  4501. # if file not downloaded, or forcing downloads
  4502. if [ ! -f "${WORKDIR}/${PKG_FILENAME}" -o "$FORCE" = true ]; then
  4503.  
  4504. # BEGIN DOWNLOAD file here..
  4505.  
  4506. # print DOWNLOADING msg
  4507. echo -en "Downloading ${magenta}${PKG_FILENAME}${endcolour}. Please wait: "
  4508.  
  4509. # if called as 'gpkg', give a pop GUI (uses Xdialog) showing download progress..
  4510. # can be used by X apps to easily start (and show!) downloads
  4511. if [ "$SELF" = "gpkg" ]; then
  4512.  
  4513. download_progress "$DOWNLOAD_URL" "${WORKDIR}/${PKG_FILENAME}" 2>/dev/null
  4514.  
  4515. else # if called as 'pkg', dont use Xdialog, output to terminal
  4516.  
  4517. if [ "$QUIET" = true ]; then
  4518. echo
  4519. echo -n "Downloading now..."
  4520. LANG=C wget \
  4521. --no-check-certificate \
  4522. --progress=dot -O "${WORKDIR}/${PKG_FILENAME}" \
  4523. -4 $CONTINUE "$DOWNLOAD_URL" &>/dev/null
  4524. else
  4525. # START DOWNLOAD, show percentage as we go
  4526. LANG=C wget \
  4527. --no-check-certificate \
  4528. --progress=dot -O "${WORKDIR}/${PKG_FILENAME}" \
  4529. -4 $CONTINUE "$DOWNLOAD_URL" 2>&1 \
  4530. | grep --line-buffered "%" \
  4531. | sed -u -e "s#\.##g" \
  4532. | awk '{printf("\b\b\b\b%4s", $2)}' #220613
  4533. fi
  4534.  
  4535. fi
  4536.  
  4537. fi # end if WORKDIR/PKG not a file or FORCE=true
  4538.  
  4539. # clean up output
  4540. [ "$QUIET" != true ] && echo -ne "\b\b\b\b"
  4541. echo
  4542.  
  4543. # if file downloaded ok
  4544. if [ -f "${WORKDIR}/${PKG_FILENAME}" ]; then
  4545. echo -e "${green}Downloaded:${endcolour} ${WORKDIR}/${PKG_FILENAME}"
  4546. DONE=true
  4547. break
  4548.  
  4549. else # file NOT downloaded ok
  4550.  
  4551. error "Failed to download '${WORKDIR}/${PKG_FILENAME}'."
  4552. echo "Check '$DOWNLOAD_URL'"
  4553.  
  4554. # remove the page we tried to get pkg from (if exists)
  4555. rm "${WORKDIR}/index.html" &>/dev/null
  4556. DONE=true
  4557. exit 6
  4558. fi
  4559.  
  4560. fi # end if CONFIRM=y
  4561.  
  4562. # user chose not to do anything
  4563. DONE=true
  4564. break
  4565.  
  4566. else # Already downloaded, skip to next iteration
  4567.  
  4568. #echo "Package $1 already downloaded"
  4569. DONE=true
  4570. break
  4571. fi
  4572.  
  4573. else # no repo match, nothing to download
  4574.  
  4575. # go to next repo, try to ge tthe pkg there
  4576. DONE=false
  4577.  
  4578. fi # end if repo match was found
  4579.  
  4580. # if download not successful, keep going to next repo
  4581. [ "$DONE" = true ] && continue
  4582.  
  4583. done #done while read list of repo files
  4584.  
  4585. fi
  4586. }
  4587.  
  4588.  
  4589. pkg_install(){ # install downloaded package ($1) FUNCLIST
  4590.  
  4591. . ${PKGRC}
  4592.  
  4593. # exit if no valid option
  4594. [ ! "$1" -o "$1" = "-" ] && print_usage install && exit 1
  4595.  
  4596. # skip if not installing pkgs
  4597. [ "$NO_INSTALL" = true ] && continue
  4598.  
  4599. local pkg_ext
  4600. local PKGNAME
  4601. local PKGNAME_ONLY
  4602. local PKGFILE
  4603. local PREVDIR="$CURDIR"
  4604. local petspecs
  4605.  
  4606. # get pkg extension
  4607. pkg_ext=`get_pkg_ext "$1"`
  4608. # get pkg name only, no extension or path
  4609. PKGNAME="$(basename "$1" .$pkg_ext)"
  4610. # exit if no valid option
  4611. [ "$PKGNAME" = '' ] && print_usage install && exit 1
  4612. # get name without version
  4613. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  4614.  
  4615. [ "`is_installed_pkg "$PKGNAME"`" = true -a "$FORCE" = false ] && echo "Already installed: $PKGNAME" && return 1
  4616. [ "`is_blacklisted_pkg "$PKGNAME_ONLY"`" = true ] && echo "Blacklisted package: $PKGNAME" && return 1
  4617.  
  4618. if [ -f "$1" ]; then
  4619. PKGFILE="$1"
  4620. CURDIR="$(dirname "$(realpath "$1")")"
  4621. PKGNAME=`basename "$1" .$pkg_ext`
  4622. else
  4623. # get the real file name (inc path) from the given PKGFILE and pkg_ext (which may be empty)
  4624. PKGFILE=`find "$CURDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${pkg_ext}" | head -1`
  4625. [ ! -f "$PKGFILE" ] && PKGFILE=`find "$CURDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${EX}" | grep -m1 $EX`
  4626. [ -f "$PKGFILE" ] && PKGNAME=`basename "$1" .$pkg_ext`
  4627. fi
  4628.  
  4629. # maybe the file is not in the current dir, but in WORKDIR, so lets look there too
  4630. if [ ! -f "$PKGFILE" ]; then
  4631. PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${pkg_ext}" | head -1`
  4632. [ ! -f "$PKGFILE" ] && PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*${EX}" | grep -m1 $EX`
  4633.  
  4634. # if we found the file in WORKDIR, make that our CURDIR
  4635. if [ -f "$PKGFILE" ]; then
  4636. PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4637. CURDIR="$WORKDIR"
  4638. cd "$WORKDIR"
  4639. else
  4640. # if we still didn't find it, do a broader check
  4641. PKGFILE=`find "$WORKDIR" -mount -maxdepth 1 -type f -name "${PKGNAME}*" | head -1`
  4642. if [ -f "$PKGFILE" ]; then
  4643. PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4644. CURDIR="$WORKDIR"
  4645. cd "$WORKDIR"
  4646. fi
  4647. fi
  4648. fi
  4649.  
  4650. # if the file exists, or using --force
  4651. if [ -f "$PKGFILE" -o "$FORCE" = true ]; then
  4652.  
  4653. [ ! -f "$PKGFILE" ] && echo "The file $1 was not found." && return 1
  4654.  
  4655. # get the extension of this newly found pkg (which we should have found by now)
  4656. pkg_ext=`get_pkg_ext "$PKGFILE"`
  4657. # get extension again, we may have been given only a pkg name, find its extension from repo files
  4658. [ "$pkg_ext" = "" ] && pkg_ext=`get_pkg_ext "$PKGNAME"`
  4659.  
  4660. [ "$pkg_ext" = '' ] && echo "Not installing $PKGFILE." && error "Invalid file extension ($pkg_ext)." && return 1
  4661.  
  4662. # remove any previous PET/pkg stuff lying around from previous installs
  4663. rm -f /pet.specs /pinstall.sh /puninstall.sh /install/doinst.sh
  4664.  
  4665. # if pkg is not yet installed, or we are force re-installing
  4666.  
  4667. # get filename from download file
  4668. PKGNAME=`basename "$PKGFILE" .$pkg_ext`
  4669.  
  4670. # ask/inform user before install
  4671. echo -n "Install package ${PKGNAME}$QTAG: "
  4672. [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  4673. [ "$ASK" = true ] && echo -ne "\b\b\n"
  4674.  
  4675. # if user answered yes, we will now download the pkgs
  4676. if [ "$CONFIRM" = "y" ]; then
  4677.  
  4678. # print new line if we didnt take any user input on tty
  4679. [ "$ASK" != true ] && echo
  4680.  
  4681. # only ask once
  4682. ASK=false
  4683.  
  4684. #if [ "`pkg_contents "$PKGFILE" 2>/dev/null`" = '' ]; then
  4685. # error "$PKGFILE not a valid package."
  4686. # exit 1
  4687. #fi
  4688.  
  4689. # fallback to repo pkg ext if none found
  4690. [ "$pkg_ext" = "" ] && pkg_ext="$EX"
  4691.  
  4692. #remove the old error log
  4693. rm $TMPDIR/$SELF-cp-errlog 2>/dev/null
  4694.  
  4695. # extract the archive file into a $CURDIR/$PKGNAME folder
  4696. case "$pkg_ext" in
  4697.  
  4698. pet)
  4699. PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.pet"`"
  4700. #determine the compression, extend test to 'XZ'
  4701. file -b "${PKGFILE}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  4702. [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  4703.  
  4704. # convert to tar extractable archive
  4705. pet2tgz "${PKGFILE}" 1>/dev/null
  4706.  
  4707. # now extract the file
  4708. tar $taropts "${CURDIR}/${PKGNAME}.tar.${TAREXT}" 2> $TMPDIR/$SELF-cp-errlog
  4709.  
  4710. # some old types need this extra step
  4711. if [ -f "${CURDIR}/${PKGNAME}.tar.$TAREXT" ]; then
  4712. cd "${CURDIR}/${PKGNAME}/" 1>/dev/null
  4713. tar --absolute-names $tarops "./${PKGNAME}.tar.$TAREXT" ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog #260713
  4714. sync
  4715. rm -f "./${PKGNAME}.tar.$TAREXT" 1>/dev/null
  4716. cd - 1>/dev/null
  4717. fi
  4718.  
  4719. # save the uninstall script for later
  4720. if [ -f "${CURDIR}/${PKGNAME}/puninstall.sh" ]; then
  4721. mv "${CURDIR}/${PKGNAME}/puninstall.sh" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove"
  4722. fi
  4723.  
  4724. # create a tgz
  4725. tgz2pet "${CURDIR}/${PKGNAME}.tar.$TAREXT" 1>/dev/null
  4726. rm "${CURDIR}/${PKGNAME}.tar.$TAREXT" 2>/dev/null
  4727. ;;
  4728.  
  4729. sfs)
  4730. PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.sfs"`"
  4731. [ ! -f "$PKGFILE" ] && PKGFILE="`find ${WORKDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.sfs"`"
  4732. echo sfs_loadr -q --cli +"$PKGFILE" #2>/dev/null
  4733. sfs_loadr -q --cli +"$PKGFILE" #2>/dev/null
  4734. rm -f $PACKAGE_FILE_LIST_DIR/${PKGNAME}.files 2>/dev/null
  4735. # create $PKGS_DIR/$PKGNAME.files
  4736. pkg_contents "$PKGFILE" | while read line
  4737. do
  4738. [ -f "$line" ] && echo "$line" >> $PACKAGE_FILE_LIST_DIR/${PKGNAME}.files
  4739. done
  4740. # exit, we dont need to unpack and copy
  4741. return 0
  4742. ;;
  4743.  
  4744. deb)
  4745.  
  4746. rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4747. mkdir -p "${CURDIR}/${PKGNAME}"
  4748. [ ! -f "$PKGFILE" ] && PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.deb"`"
  4749. cp "${PKGFILE}" "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" || exit 4
  4750. cd "${CURDIR}/${PKGNAME}/"
  4751.  
  4752. if [ -f "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" ]; then
  4753. dpkg-deb --contents "${CURDIR}/${PKGNAME}/${PKGNAME}.deb" \
  4754. | grep -v '/$' \
  4755. | tr -s ' ' \
  4756. | cut -f6 -d' ' \
  4757. | sed -e 's/^.//g' 2>/dev/null \
  4758. | grep -v '^$' > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4759. fi
  4760.  
  4761. # woofce: NO_MULTIARCH_SYMLINK=1 (DISTRO_SPECS)
  4762. if [ -z "$NO_MULTIARCH_SYMLINK" ] ; then
  4763. if [ -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ]; then
  4764. pkg_has_archdir="$(grep -m1 "$DISTRO_ARCHDIR" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")"
  4765. fi
  4766.  
  4767. # Workaround to avoid overwriting the $DISTRO_ARCHDIR symlink.
  4768. if [ "$DISTRO_ARCHDIR" != "" -a -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" -a "$pkg_has_archdir" != "" ]; then
  4769. mkdir -p /tmp/$PKGNAME
  4770. rm -rf /tmp/$PKGNAME/*
  4771. dpkg-deb -x ${CURDIR}/${PKGNAME}.deb /tmp/$PKGNAME/ 2> $TMPDIR/$SELF-cp-errlog
  4772. #set -x
  4773. while read f
  4774. do
  4775. xpath="$(echo "$f" | cut -f 4-30 -d "/" | sed "s/$DISTRO_ARCHDIR\///")"
  4776. mkdir -p ${DIRECTSAVEPATH}/$(dirname "$xpath")
  4777. cp -a "$f" ${DIRECTSAVEPATH}/$(dirname "$xpath")/
  4778. done < <(find "/tmp/$PKGNAME" \( -type f -o -type l \))
  4779. #set +x
  4780. rm -rf /tmp/$PKGNAME &>/dev/null
  4781. else
  4782. dpkg-deb -x ${CURDIR}/${PKGNAME}.deb ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4783. fi
  4784. else
  4785. dpkg-deb -x ${CURDIR}/${PKGNAME}.deb ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4786. fi
  4787.  
  4788. if [ "`cat $TMPDIR/$SELF-cp-errlog | grep 'tar: Exiting with failure status due to previous errors'`" != "" ]; then
  4789. error "Failed to unpack $PKGNAME.deb"
  4790. exit 1
  4791. fi
  4792. [ -d /DEBIAN ] && rm -rf /DEBIAN #130112 precaution.
  4793. dpkg-deb -e "${CURDIR}/${PKGNAME}.deb" /DEBIAN #130112 extracts deb control files to dir /DEBIAN. may have a post-install script, see below.
  4794. rm "${PKGNAME}.deb"
  4795.  
  4796. cd - 1>/dev/null
  4797. ;;
  4798.  
  4799. *tbz|*tar.bz2)
  4800. rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4801. mkdir -p "${CURDIR}/${PKGNAME}"
  4802. cp "${CURDIR}/${PKGNAME}.$pkg_ext" "${CURDIR}/${PKGNAME}/${PKGNAME}.$pkg_ext" || exit 4
  4803. cd "${CURDIR}/${PKGNAME}/"
  4804.  
  4805. ( umask 000 ; cat "${PKGNAME}.$pkg_ext" | bzip2 -dc | tar -xf - 2> $TMPDIR/$SELF-cp-errlog )
  4806.  
  4807. rm "${PKGNAME}.$pkg_ext"
  4808. cd - 1>/dev/null
  4809. ;;
  4810.  
  4811. *tlz|*tar.lzma)
  4812. rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4813. mkdir -p "${CURDIR}/${PKGNAME}"
  4814. PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.${pkg_ext}"`"
  4815. cp "$PKGFILE" "${CURDIR}/${PKGNAME}/`basename $PKGFILE`" || exit 4
  4816. cd "${CURDIR}/${PKGNAME}/"
  4817.  
  4818. ( umask 000 ; cat "${PKGNAME}.$pkg_ext" | lzma -dc | tar -xf - 2> $TMPDIR/$SELF-cp-errlog )
  4819.  
  4820. rm "${PKGNAME}.$pkg_ext"
  4821. cd - 1>/dev/null
  4822. ;;
  4823.  
  4824. *tgz|*txz|*tar.gz|*tar.xz|*xz|*gz)
  4825. rmdir "${CURDIR}/${PKGNAME}" &>/dev/null
  4826. mkdir -p "${CURDIR}/${PKGNAME}"
  4827. PKGFILE="`find ${CURDIR} -mount -maxdepth 1 -type f -name "${PKGNAME}*.${pkg_ext}"`"
  4828. cp "$PKGFILE" "${CURDIR}/${PKGNAME}/`basename $PKGFILE`" || exit 4
  4829. cd "${CURDIR}/${PKGNAME}/"
  4830.  
  4831. file -b "${PKGNAME}.$pkg_ext" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  4832. [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  4833.  
  4834. tar $taropts "${PKGNAME}.$pkg_ext" 2> $TMPDIR/$SELF-cp-errlog
  4835. rm "${PKGNAME}.$pkg_ext"
  4836. cd - 1>/dev/null
  4837. ;;
  4838.  
  4839. rpm)
  4840. PKGNAME="`basename ${PKGFILE} .rpm`"
  4841. busybox rpm -qp "$PKGFILE" > /dev/null 2>&1
  4842. [ $? -ne 0 ] && exit 1
  4843. PFILES="`busybox rpm -qpl $PKGFILE`"
  4844. [ $? -ne 0 ] && exit 1
  4845. echo "$PFILES" > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4846. pkg_unpack "$PKGFILE" 1>/dev/null
  4847. ;;
  4848.  
  4849. esac
  4850.  
  4851. # now extract pkg contents to /
  4852. [ ! -d "${PKGNAME}/" ] && error "Cannot enter directory '${PKGNAME}/', it doesn't exist." && exit 4
  4853. cd "${PKGNAME}/" 1>/dev/null
  4854.  
  4855. cp -a --remove-destination * ${DIRECTSAVEPATH}/ 2> $TMPDIR/$SELF-cp-errlog
  4856.  
  4857. #source is a directory, target is a symlink...
  4858. if [ -s $TMPDIR/$SELF-cp-errlog ]; then
  4859. 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 '`' |
  4860. while read ONEDIRSYMLINK
  4861. do
  4862. #adding that extra trailing / does the trick...
  4863. cp -a --remove-destination ${ONEDIRSYMLINK}/* /${ONEDIRSYMLINK}/ 2> $TMPDIR/$SELF-cp-errlog #260713
  4864. done
  4865. fi
  4866. sync
  4867. cd .. 1>/dev/null
  4868.  
  4869. if [ ! -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ] || \
  4870. [ -z "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" ]; then
  4871. # add ${HOME}/.packages/${PKGNAME}.files, need to find regular files and links separately... then images..
  4872. find "./${PKGNAME}/" -mount -mindepth 2 -type f | sed -e "s/\.\/${PKGNAME}//g" -e 's/\/root0\//\/root\//g' > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4873. find "./${PKGNAME}/" -mount -mindepth 2 -type l | sed -e "s/\.\/${PKGNAME}//g" -e 's/\/root0\//\/root\//g' >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4874.  
  4875. for ONEIMAGEFILE in `ls -1 /*[0-9].xpm 2>/dev/null`
  4876. do
  4877. BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4878. echo "/usr/local/lib/X11/pixmaps/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4879. done
  4880. for ONEIMAGEFILE in `ls -1 /*[0-9].png 2>/dev/null`
  4881. do
  4882. BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4883. echo "/usr/local/lib/X11/pixmaps/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4884. done
  4885. for ONEIMAGEFILE in `ls -1 /*[^0-9].xpm 2>/dev/null`
  4886. do
  4887. BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4888. echo "/usr/local/lib/X11/mini-icons/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4889. done
  4890. for ONEIMAGEFILE in `ls -1 /*[^0-9].png 2>/dev/null` #v2.16
  4891. do
  4892. BASEONEIMAGE="`basename $ONEIMAGEFILE`"
  4893. echo "/usr/local/lib/X11/mini-icons/$BASEONEIMAGE" >> "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4894. done
  4895. fi
  4896.  
  4897. # move the *.files to $PKGS_DIR
  4898. FILES=''
  4899. FILES="`find "$CURDIR" -mount -maxdepth 1 -iname "*.files" | head -1`"
  4900. [ -f "`echo $FILES`" ] && mv "$FILES" "$PACKAGE_FILE_LIST_DIR/" 2>/dev/null #260713
  4901.  
  4902. #pkgname.files may need to be fixed...
  4903. cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" | grep -v '/$' | sed -e 's%^\\.%%' -e 's%^%/%' -e 's%^//%/%' 2>/dev/null > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2"
  4904. mv "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4905.  
  4906. sort -u "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" > "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2"
  4907. mv "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files2" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files"
  4908.  
  4909. # some pets add images and icons at / so move them
  4910. mv /{*.xpm,*.png} /usr/share/pixmaps/ 2>/dev/null
  4911. mv /*.ico /usr/share/pixmaps/ 2>/dev/null
  4912.  
  4913. # run the post install scripts (for puppy, slackware, arch, debian/ubuntu, etc)
  4914. for i in /pinstall.sh /install/doinst.sh /DEBIAN/postinst
  4915. do
  4916. [ -z /${i} -o ! -e /${i} ] && continue
  4917. chmod +x /${i}
  4918. cd /
  4919. nohup sh ${i} &>/dev/null
  4920. sleep 0.2
  4921. rm -f ${i}
  4922. cd ${CURDIR}/
  4923. done
  4924. rm -rf /install
  4925. rm -rf /DEBIAN
  4926.  
  4927. #130314 run arch linux pkg post-install script...
  4928. if [ -f /.INSTALL -a /usr/local/petget/ArchRunDotInstalls ]; then #precaution. see 3builddistro, script created by noryb009.
  4929. #this code is taken from below...
  4930. dlPATTERN='|'"`echo -n "${PKGNAME}" | sed -e 's%\\-%\\\\-%'`"'|'
  4931. archVER="`cat $TMPDIR/petget_missing_dbentries-Packages-* 2>/dev/null | grep "$dlPATTERN" | head -n 1 | cut -f 3 -d '|'`"
  4932. if [ "$archVER" ]; then #precaution.
  4933. cd /
  4934. mv -f .INSTALL .INSTALL1-${archVER}
  4935. cp -a /usr/local/petget/ArchRunDotInstalls ArchRunDotInstalls
  4936. LANG=$LANG_USER ./ArchRunDotInstalls
  4937. rm -f ArchRunDotInstalls
  4938. rm -f .INSTALL*
  4939. cd ${CURDIR}/
  4940. fi
  4941. fi
  4942.  
  4943. PKGCAT=''
  4944. PKGSIZE=''
  4945. PKGDESC=''
  4946. DEPLIST=''
  4947.  
  4948. # clean up pet installs
  4949. if [ "$pkg_ext" = "pet" ]; then
  4950. cd /
  4951.  
  4952. # get pkg info from pet.spec before we delete it, because the PET may not be a repo pkg
  4953. petspecs="`cat /pet.specs 2>/dev/null`"
  4954.  
  4955. if [ "$petspecs" != '' ]; then
  4956. # now get pkg info
  4957. PKGCAT="`echo $petspecs| cut -f5 -d'|'`"
  4958. PKGSIZE="`echo $petspecs| cut -f6 -d'|'`"
  4959. PKGDESC="`echo $petspecs| cut -f10 -d'|'`"
  4960. DEPSLIST="`echo $petspecs|cut -f9 -d'|'`"
  4961. fi
  4962.  
  4963. cd ${CURDIR}/
  4964. fi
  4965.  
  4966. # cleanup a bit
  4967. rm -R "${PKGNAME}/" 2>/dev/null || echo "${yellow}Warning:${endcolour} Cannot remove directory '${PKGNAME}/'." #150213
  4968.  
  4969. #120102 install may have overwritten a symlink-to-dir...
  4970. #tar defaults to not following symlinks, for both dirs and files, but i want to follow symlinks
  4971. #for dirs but not for files. so, fix here... (note, dir entries in .files have / on end)
  4972. cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" | grep '[a-zA-Z0-9]/$' | sed -e 's%/$%%' | grep -v '^/mnt' |
  4973. while read ONESPEC
  4974. do
  4975. if [ -d "${DIRECTSAVEPATH}${ONESPEC}" ]; then
  4976. if [ ! -h "${DIRECTSAVEPATH}${ONESPEC}" ]; then
  4977. DIRLINK=""
  4978. if [ -h "/initrd${PUP_LAYER}${ONESPEC}" ]; then #120107
  4979. DIRLINK="`readlink -m "/initrd${PUP_LAYER}${ONESPEC}" | sed -e "s%/initrd${PUP_LAYER}%%"`" #PUP_LAYER: see /etc/rc.d/PUPSTATE. 120107
  4980. xDIRLINK="`readlink "/initrd${PUP_LAYER}${ONESPEC}"`" #120107
  4981. fi
  4982. if [ ! "$DIRLINK" ]; then
  4983. if [ -h "/initrd${SAVE_LAYER}${ONESPEC}" ]; then #120107
  4984. DIRLINK="`readlink -m "/initrd${SAVE_LAYER}${ONESPEC}" | sed -e "s%/initrd${SAVE_LAYER}%%"`" #SAVE_LAYER: see /etc/rc.d/PUPSTATE. 120107
  4985. xDIRLINK="`readlink "/initrd${SAVE_LAYER}${ONESPEC}"`" #120107
  4986. fi
  4987. fi
  4988. if [ "$DIRLINK" ]; then
  4989. if [ -d "$DIRLINK" ]; then
  4990. if [ "$DIRLINK" != "${ONESPEC}" ]; then #precaution.
  4991. mkdir -p "${DIRECTSAVEPATH}${DIRLINK}" #120107
  4992. cp -a -f --remove-destination ${DIRECTSAVEPATH}"${ONESPEC}"/* "${DIRECTSAVEPATH}${DIRLINK}/" #ha! fails if put double-quotes around entire expression.
  4993. rm -rf "${DIRECTSAVEPATH}${ONESPEC}"
  4994. if [ "$DIRECTSAVEPATH" = "" ]; then
  4995. ln -s "$xDIRLINK" "${ONESPEC}"
  4996. else
  4997. DSOPATH="`dirname "${DIRECTSAVEPATH}${ONESPEC}"`"
  4998. DSOBASE="`basename "${DIRECTSAVEPATH}${ONESPEC}"`"
  4999. rm -f "${DSOPATH}/.wh.${DSOBASE}" #allow underlying symlink to become visible on top.
  5000. fi
  5001. fi
  5002. fi
  5003. fi
  5004. fi
  5005. fi
  5006. done
  5007.  
  5008. # woofce: NO_MULTIARCH_SYMLINK=1 (DISTRO_SPECS)
  5009. if [ -z "$NO_MULTIARCH_SYMLINK" ] ; then
  5010. #121217 it seems that this problem is occurring in other modes (13 reported)...
  5011. #121123 having a problem with multiarch symlinks in full-installation...
  5012. #it seems that the symlink is getting replaced by a directory.
  5013. if [ "$DISTRO_ARCHDIR" ]; then #in /etc/rc.d/DISTRO_SPECS. 130112 change test from DISTRO_ARCHDIR. 130114 revert DISTRO_ARCHDIR_SYMLINKS==yes.
  5014. if [ -d /usr/lib/${DISTRO_ARCHDIR} ]; then
  5015. if [ ! -h /usr/lib/${DISTRO_ARCHDIR} ]; then
  5016. cp -a -f --remove-destination /usr/lib/${DISTRO_ARCHDIR}/* /usr/lib/
  5017. sync
  5018. rm -r -f /usr/lib/${DISTRO_ARCHDIR}
  5019. ln -s ./ /usr/lib/${DISTRO_ARCHDIR}
  5020. fi
  5021. fi
  5022. if [ -d /lib/${DISTRO_ARCHDIR} ]; then
  5023. if [ ! -h /lib/${DISTRO_ARCHDIR} ]; then
  5024. cp -a -f --remove-destination /lib/${DISTRO_ARCHDIR}/* /lib/
  5025. sync
  5026. rm -r -f /lib/${DISTRO_ARCHDIR}
  5027. ln -s ./ /lib/${DISTRO_ARCHDIR}
  5028. fi
  5029. fi
  5030. if [ -d /usr/bin/${DISTRO_ARCHDIR} ]; then
  5031. if [ ! -h /usr/bin/${DISTRO_ARCHDIR} ]; then
  5032. cp -a -f --remove-destination /usr/bin/${DISTRO_ARCHDIR}/* /usr/bin/
  5033. sync
  5034. rm -r -f /usr/bin/${DISTRO_ARCHDIR}
  5035. ln -s ./ /usr/bin/${DISTRO_ARCHDIR}
  5036. fi
  5037. fi
  5038. fi
  5039. fi
  5040.  
  5041. #flush unionfs cache, so files in pup_save layer will appear "on top"...
  5042. if [ "$DIRECTSAVEPATH" != "" ]; then
  5043. #but first, clean out any bad whiteout files...
  5044. # 22sep10 shinobar: bugfix was not working clean out whiteout files
  5045. find /initrd/pup_rw -mount -type f -name .wh.\* -printf '/%P\n'|
  5046. while read ONEWHITEOUT
  5047. do
  5048. ONEWHITEOUTFILE="`basename "$ONEWHITEOUT"`"
  5049. ONEWHITEOUTPATH="`dirname "$ONEWHITEOUT"`"
  5050. if [ "$ONEWHITEOUTFILE" = ".wh.__dir_opaque" ]; then
  5051. [ "$(grep "$ONEWHITEOUTPATH" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != "" ] && rm -f "/initrd/pup_rw/$ONEWHITEOUT"
  5052. continue
  5053. fi
  5054. ONEPATTERN="`echo -n "$ONEWHITEOUT" | sed -e 's%/\\.wh\\.%/%'`"'/*' ;#echo "$ONEPATTERN" >&2
  5055. [ "$(grep -x "$ONEPATTERN" "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != "" ] && rm -f "/initrd/pup_rw/$ONEWHITEOUT"
  5056. done
  5057. #111229 /usr/local/petget/removepreview.sh when uninstalling a pkg, may have copied a file from sfs-layer to top, check...
  5058. cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" |
  5059. while read ONESPEC
  5060. do
  5061. [ "$ONESPEC" = "" ] && continue #precaution.
  5062. if [ ! -d "$ONESPEC" ]; then
  5063. [ -e "/initrd/pup_rw${ONESPEC}" ] && rm -f "/initrd/pup_rw${ONESPEC}"
  5064. fi
  5065. done
  5066. #now re-evaluate all the layers...
  5067. busybox mount -t aufs -o remount,udba=reval unionfs / #remount with faster evaluation mode.
  5068. [ $? -ne 0 ] && logger -s -t "pkg" "Failed to remount aufs / with udba=reval"
  5069. sync
  5070. fi
  5071.  
  5072. # get pkg size, category and description
  5073. [ "$PKGCAT" = '' ] && PKGCAT=`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f5 -d'|' | head -1`
  5074. [ "$PKGCAT" = '' ] && PKGCAT=`LANG=C grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null | cut -f5 -d'|' | head -1`
  5075. [ "$PKGDESC" = '' ] && PKGDESC=`LANG=C grep -m1 "|${PKGNAME_ONLY}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null| cut -f10 -d'|' | head -1`
  5076. [ "$PKGDESC" = '' ] && PKGDESC=`LANG=C grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null| cut -f10 -d'|' | head -1`
  5077. [ "$PKGSIZE" = '' ] && PKGSIZE=`LANG=C du -s -k ${CURDIR}/${PKG} 2>/dev/null | cut -f1`
  5078. # get pkg version
  5079. PKGVER="`LANG=C echo "$PKGNAME" | sed -e 's/^[^0-9]*-//g'`"
  5080. PKGARCH="`LANG=C echo "$PKGNAME" | cut -f3 -d'-' | grep -E 'i[3-9]|x[8-9]|noarch'`"
  5081.  
  5082. # last check for pkg info
  5083. [ "$DEPSLIST" = '' ] && DEPSLIST="`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR"/Packages-* 2>/dev/null | cut -f9 -d'|' | grep '+' | head -1`"
  5084. [ "$PKGDESC" = '' ] && PKGDESC="No description"
  5085.  
  5086. #080917 - build woof compatible repo line .. #090817
  5087. if [ "`cut -f1 -d'|' "$USER_INST_PKGS_FILE" 2>/dev/null | grep -m1 ^${PKGNAME}`" = '' ]; then
  5088.  
  5089. # get the package db entry to add to user-installed-packages...
  5090. # first, get it from petspecs if possible, or from the pkgs repo, or make one
  5091. if [ -f /pet.specs ]; then
  5092. DB_ENTRY="`cat /pet.specs | head -n 1`"
  5093. elif [ "`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/$REPOFILE"`" != "" ]; then
  5094. DB_ENTRY="`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/$REPOFILE"`"
  5095. else
  5096. DB_ENTRY="${PKGNAME}|${PKGNAME_ONLY}|${PKGVER}|${BUILD}|${PKGCAT}|${PKGSIZE}|${PKGDIR}|${PKGNAME}.${pkg_ext}|${DEPSLIST}|${PKGDESC}|${DISTRO_BINARY_COMPAT}|${DISTRO_COMPAT_VERSION}"
  5097. fi
  5098.  
  5099. # Fix for Debian executables showing as shared libs in ROX.
  5100. if [ "$DISTRO_FILE_PREFIX" = "stretch" -o "$DISTRO_FILE_PREFIX" = "ascii" ]; then
  5101. if [ "$(ps aux | grep ROX |grep -v grep)" ]; then # Other managers are OK
  5102. if [ "$(which elfedit)" ]; then
  5103. grep -E '/bin/|/sbin/' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" |
  5104. while read FLINE
  5105. do
  5106. [ "$(file "$FLINE" | grep -i 'shared object')" ] && elfedit --input-type=dyn --output-type=exec $FLINE
  5107. done
  5108. else
  5109. echo -e "${yellow}Warning${endcolour} Recent Debian executables show as shared libraries in ROX,"
  5110. echo "which causes ROX to fail to open or execute them. To fix that during package "
  5111. echo "installation you should install elfutils or have devx loaded."
  5112. fi
  5113. fi
  5114. fi
  5115.  
  5116. # now add the db entry to user-installed-packages
  5117. echo "$DB_ENTRY" >> "$USER_INST_PKGS_FILE" #130913
  5118.  
  5119. fi
  5120.  
  5121. # now delete the petspecs file(s), we already added our PKG info to installed-packages
  5122. rm /pet.specs &>/dev/null
  5123. rm /*.pet.specs &>/dev/null
  5124.  
  5125. # make sure /tmp has correct permission, a pkg may have overwritten it
  5126. ls -dl /tmp | grep -q '^drwxrwxrwt' || chmod 1777 /tmp #130305 rerwin.
  5127.  
  5128. #090817
  5129. if [ "$(is_installed_pkg $PKGNAME)" = true -a "$(cat "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files")" != '' ]; then
  5130. echo -e "${green}Installed:${endcolour} $PKGNAME"
  5131. # show if pkg has menu entry
  5132. menu_entry_msg "$PKGNAME_ONLY"
  5133. #080413 do fixmenus, if menu entry found #200713 moved here
  5134. if [ "$(grep -m1 '/usr/share/applications' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" 2>/dev/null | grep desktop$)" != "" ]; then
  5135. [ ! -f /tmp/pkg/update_menus_busy ] && update_menus &
  5136. fi
  5137. [ "`which logger`" != '' ] && logger "$0 Package $PKGNAME installed by $APP $APPVER"
  5138. else
  5139. error "$PKGNAME may not have installed correctly."
  5140. fi
  5141.  
  5142. #100817 clean up user-installed-packages (remove duplicates and empty lines
  5143. cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages_clean"
  5144. mv "$PKGS_DIR/user-installed-packages_clean" "$USER_INST_PKGS_FILE"
  5145.  
  5146. # puppy specific fixes for installed package
  5147. postinstall_hacks "$PKGNAME" "$PKGNAME_ONLY" &
  5148.  
  5149. #100622 slackware 13.1: just in case any got through, remove c-shell scripts...
  5150. rm -f /etc/profile.d/*.csh* 2>/dev/null
  5151.  
  5152. #120523 precise puppy needs this... (refer also rc.update and 3builddistro)
  5153. if [ "`grep '/usr/share/glib-2.0/schemas' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}*.files" 2>/dev/null`" != "" ]; then
  5154. [ -e /usr/bin/glib-compile-schemas ] && /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &>/dev/null
  5155. fi
  5156.  
  5157. if [ "`grep '/usr/lib/gio/modules' "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.files" 2>/dev/null`" != "" ]; then
  5158. [ -e /usr/bin/gio-querymodules ] && /usr/bin/gio-querymodules /usr/lib/gio/modules &>/dev/null
  5159. fi
  5160.  
  5161. sync
  5162.  
  5163. fi #if CONFIRM = y #100213,0.9 moved down to here, fixes install, and output msgs
  5164.  
  5165. else # file doesn't exists, user must download it first
  5166.  
  5167. if [ "$PKGNAME" != '' ]; then
  5168.  
  5169. echo "Package '$PKGNAME' not yet downloaded."
  5170.  
  5171. matching_local_pkgs="`list_downloaded_pkgs $PKGNAME`"
  5172.  
  5173. # if no matching pkgs downloaded
  5174. if [ "$matching_local_pkgs" != "" ]; then
  5175. echo "You could install one of the following packages with \`$SELF -i PKGNAME\`:"
  5176. echo "`list_downloaded_pkgs $(basename "$PKGNAME" .$pkg_ext 2>/dev/null) 2>/dev/null`"
  5177.  
  5178. # else if not downloaded, and in the current repo, list the matching repo pkgs
  5179. elif [ "$matching_local_pkgs" = "" -a "`grep -m1 "^${PKGNAME}|" "$REPO_DB_FILE_DIR/${REPOFILE}" 2>/dev/null`" != "" ]; then
  5180. echo "You must first download one of the following packages with \`$SELF -d PKGNAME\`:"
  5181. echo "`$PKGSEARCH $(basename $PKGNAME .$pkg_ext)`"
  5182.  
  5183. else
  5184. not_found "${PKGNAME}"
  5185. fi
  5186.  
  5187. else # PKGNAME is empty
  5188.  
  5189. echo "Package could not be identified."
  5190.  
  5191. fi
  5192.  
  5193. exit 1
  5194.  
  5195. fi
  5196.  
  5197. # go back to the dir we started in
  5198. cd "$PREVDIR"
  5199.  
  5200. }
  5201.  
  5202.  
  5203. postinstall_hacks(){ # fix pkgs after installation
  5204. local PKGNAME="$1"
  5205. local PKGNAME_ONLY="$2"
  5206.  
  5207. # remove %u, %U, %f (etc) from Exec lines
  5208. DESKTOPFILE="`find /usr/share/applications -iname "${PKGNAME_ONLY}*.desktop"`"
  5209. [ -f "$DESKTOPFILE" ] && \
  5210. sed -i 's/ %u//' $DESKTOPFILE && \
  5211. sed -i 's/ %U//' $DESKTOPFILE && \
  5212. sed -i 's/ %f//' $DESKTOPFILE && \
  5213. sed -i 's/ %F//' $DESKTOPFILE
  5214.  
  5215. case $PKGNAME in
  5216. 0ad-*|0ad_*)
  5217. bbe -e 's/geteuid/getppid/' /usr/games/pyrogenesis > /usr/games/pyrogenesis1 2>/dev/null
  5218. mv /usr/games/pyrogenesis1 /usr/games/pyrogenesis
  5219. chmod 755 /usr/games/pyrogenesis
  5220. ;;
  5221. openclonk-*|openclonk_*)
  5222. bbe -e 's/geteuid/getppid/' /usr/games/openclonk > /usr/games/openclonk1 2>/dev/null
  5223. mv /usr/games/openclonk1 /usr/games/openclonk
  5224. chmod 755 /usr/games/openclonk
  5225. ;;
  5226. vlc_*|vlc-*)
  5227. VLCDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname 'vlc*.desktop'`"
  5228. [ -f $VLCDESKTOP ] && sed -i 's/ --started-from-file %U//' $VLCDESKTOP
  5229. [ -f $VLCDESKTOP ] && sed -i 's/ --started-from-file//' $VLCDESKTOP
  5230.  
  5231. #120907 vlc in debian/ubuntu configured to not run as root (it is a pre-compile configure option to enable running as root).
  5232. #this hack will fix it...
  5233. #note, this code is also in FIXUPHACK in 'vlc' template.
  5234. if [ -f /usr/bin/bbe ]; then #bbe is a sed-like utility for binary files.
  5235. if [ -f /usr/bin/vlc ]; then
  5236. bbe -e 's/geteuid/getppid/' /usr/bin/vlc > /tmp/vlc-temp1
  5237. mv -f /tmp/vlc-temp1 /usr/bin/vlc
  5238. chmod 755 /usr/bin/vlc
  5239. fi
  5240. fi
  5241. ;;
  5242. google-chrome-*) #130221 pemasu. 130224 pemasu: limit cache size...
  5243. if [ -f /usr/bin/bbe ]; then #bbe is a sed-like utility for binary files.
  5244. if [ -f /opt/google/chrome/chrome ]; then
  5245. bbe -e 's/geteuid/getppid/' /opt/google/chrome/chrome > /tmp/chrome-temp1
  5246. mv -f /tmp/chrome-temp1 /opt/google/chrome/chrome
  5247. chmod 755 /opt/google/chrome/chrome
  5248. [ -e /usr/bin/google-chrome ] && rm -f /usr/bin/google-chrome
  5249. echo '#!/bin/sh
  5250. exec /opt/google/chrome/google-chrome --user-data-dir=/root/.config/chrome --disk-cache-size=10000000 --media-cache-size=10000000 "$@"' > /usr/bin/google-chrome
  5251. chmod 755 /usr/bin/google-chrome
  5252. ln -s google-chrome /usr/bin/chrome
  5253. ln -s /opt/google/chrome/product_logo_48.png /usr/share/pixmaps/google-chrome.png
  5254. ln -s /opt/google/chrome/product_logo_48.png /usr/share/pixmaps/chrome.png
  5255. CHROMEDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname '*chrome*.desktop'`"
  5256. if [ "$CHROMEDESKTOP" = "" ]; then #precaution.
  5257. echo '[Desktop Entry]
  5258. Encoding=UTF-8
  5259. Version=1.0
  5260. Name=Google Chrome web browser
  5261. GenericName=Google Chrome
  5262. Comment=Google Chrome web browser
  5263. Exec=google-chrome
  5264. Terminal=false
  5265. Type=Application
  5266. Icon=google-chrome.png
  5267. Categories=WebBrowser;' > /usr/share/applications/google-chrome.desktop
  5268. fi
  5269. fi
  5270. fi
  5271. ;;
  5272. chromium*) #130221 pemasu. 130224 pemasu: limit cache size...
  5273. if [ -f /usr/bin/bbe ]; then #bbe is a sed-like utility for binary files.
  5274. if [ -f /usr/lib/chromium/chromium ]; then
  5275. bbe -e 's/geteuid/getppid/' /usr/lib/chromium/chromium > /tmp/chrome-temp1
  5276. mv -f /tmp/chrome-temp1 /usr/lib/chromium/chromium
  5277. chmod 755 /usr/lib/chromium/chromium
  5278. [ -e /usr/bin/chromium ] && rm -f /usr/bin/chromium
  5279. echo '#!/bin/sh
  5280. 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
  5281. chmod 755 /usr/bin/chromium
  5282. ln -s /usr/share/icons/hicolor/48x48/apps/chromium.png /usr/share/pixmaps/chromium.png
  5283. CHROMEDESKTOP="`find /usr/share/applications -mindepth 1 -maxdepth 1 -iname '*chromium-br*.desktop'`"
  5284. if [ "$CHROMEDESKTOP" = "" ]; then #precaution.
  5285. echo '[Desktop Entry]
  5286. Encoding=UTF-8
  5287. Version=1.0
  5288. Name=Chromium web browser
  5289. GenericName=Chromium
  5290. Comment=Chromium web browser
  5291. Exec=chromium
  5292. Terminal=false
  5293. Type=Application
  5294. Icon=chromium.png
  5295. Categories=WebBrowser;' > /usr/share/applications/chromium.desktop
  5296. fi
  5297. fi
  5298. fi
  5299. ;;
  5300. jwm_theme_*)
  5301. #120924 DejaVu font no good for non-Latin languages...
  5302. #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5303. LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5304. case $LANGUSER in
  5305. zh*|ja*|ko*) #chinese, japanese, korean
  5306. sed -i -e 's%DejaVu Sans%Sans%' /etc/xdg/templates/_root_*
  5307. sed -i -e 's%DejaVu Sans%Sans%' /root/.jwm/themes/*-jwmrc
  5308. sed -i -e 's%DejaVu Sans%Sans%' /root/.jwm/jwmrc-theme
  5309. ;;
  5310. esac
  5311. #130326 font size fix for 96 dpi...
  5312. if [ "$PKGNAME_ONLY" ]; then
  5313. JWMTHEMEFILE="$(grep '^/root/\.jwm/themes/.*-jwmrc$' "$PACKAGE_FILE_LIST_DIR/${PKGNAME_ONLY}.files" | head -n 1)"
  5314. [ "$JWMTHEMEFILE" ] && hackfontsize "JWMTHEMES='${JWMTHEMEFILE}'"
  5315. fi
  5316. ;;
  5317. openbox*)
  5318. #120924 DejaVu font no good for non-Latin languages...
  5319. #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5320. LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5321. case $LANGUSER in
  5322. zh*|ja*|ko*) #chinese, japanese, korean
  5323. sed -i -e 's%DejaVu Sans%Sans%' /etc/xdg/openbox/*.xml
  5324. sed -i -e 's%DejaVu Sans%Sans%' /root/.config/openbox/*.xml
  5325. ;;
  5326. esac
  5327. ;;
  5328. gtk_theme_*)
  5329. #120924 DejaVu font no good for non-Latin languages...
  5330. #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5331. LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5332. case $LANGUSER in
  5333. zh*|ja*|ko*) #chinese, japanese, korean
  5334. GTKRCFILE="$(find /usr/share/themes -type f -name gtkrc | tr '\n' ' ')"
  5335. for ONEGTKRC in $GTKRCFILE
  5336. do
  5337. sed -i -e 's%DejaVu Sans%Sans%' $ONEGTKRC
  5338. done
  5339. ;;
  5340. esac
  5341. #130326 font size fix for 96 dpi...
  5342. if [ "$PKGNAME_ONLY" ]; then
  5343. GTKTHEMEFILE="$(grep '^/usr/share/themes/.*/gtk-2\.0/gtkrc$' "$PACKAGE_FILE_LIST_DIR/${PKGNAME_ONLY}.files" | head -n 1)"
  5344. [ "$GTKTHEMEFILE" ] && hackfontsize "GTKRCS='${GTKTHEMEFILE}'"
  5345. fi
  5346. ;;
  5347. seamonkey*|firefox*)
  5348. #120924 DejaVu font no good for non-Latin languages...
  5349. #see also langpack_* pinstall.sh (template is in /usr/share/doc/langpack-template/pinstall.sh, read by momanager).
  5350. LANGUSER="`grep '^LANG=' /etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  5351. case $LANGUSER in
  5352. zh*|ja*|ko*) #chinese, japanese, korean
  5353. MOZFILE="$(find /root/.mozilla -type f -name prefs.js -o -name '*.css' | tr '\n' ' ')"
  5354. for ONEMOZ in $MOZFILE
  5355. do
  5356. sed -i -e 's%DejaVu Sans%Sans%' $ONEMOZ
  5357. done
  5358. ;;
  5359. esac
  5360. ;;
  5361. mc_*) #121206 midnight commander
  5362. #in ubuntu, won't run from the menu. this fixes it...
  5363. [ -f /usr/share/applications/mc.desktop ] && sed -i -e 's%^Exec=.*%Exec=TERM=xterm mc%' /usr/share/applications/mc.desktop
  5364. ;;
  5365. xsane*) #130122
  5366. #xsane puts up a warning msg at startup if running as root, remove it...
  5367. #this code is also in file FIXUPHACK in xsane template (in Woof).
  5368. #WARNING: this may only work for x86 binary.
  5369. if [ -f /usr/bin/bbe ]; then #bbe is a sed-like utility for binary files.
  5370. if [ -f /usr/bin/xsane ]; then
  5371. bbe -e 's/\x6b\x00getuid/\x6b\x00getpid/' /usr/bin/xsane > /tmp/xsane-temp1
  5372. mv -f /tmp/xsane-temp1 /usr/bin/xsane
  5373. chmod 755 /usr/bin/xsane
  5374. fi
  5375. fi
  5376. ;;
  5377. kompozer*) #130507
  5378. [ -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
  5379. ;;
  5380. esac
  5381. }
  5382.  
  5383.  
  5384. choose_pkg(){ # given partial name ($1), choose from a list of matching packages FUNCLIST
  5385.  
  5386.  
  5387. # exit if no valid options
  5388. [ ! "$1" -o "$1" = "" -o "$1" = "-" ] && print_usage get && exit 1
  5389.  
  5390. # get $REPONAME and $EX
  5391. . ${PKGRC}
  5392.  
  5393. local REPOEX # extension of pkgs in the current repo $REPONAME (from rc file)
  5394. local PKGEX # pkg extension we get from $1, defaults to $REPOEXT is empty
  5395. local PKGNAME # the name of the pkg, we get this from $1
  5396. local PKGNAME_ONLY # the pkg name without version, we get this from PKGNAME
  5397. local PKGS # the list of PKGS returned matching $1/$PKGNAME
  5398. local INT=1 # used to provide numbered lists
  5399.  
  5400. REPOEX=$EX
  5401. # get pkg extension
  5402. PKGEX=`get_pkg_ext "$1"`
  5403.  
  5404. # if no extension, set to extension of current repo
  5405. [ "$PKGEX" = '' ] && PKGEX=$REPOEX
  5406.  
  5407. # get pkg name with version, no extension or path
  5408. PKGNAME="$(basename "$1" .$PKGEX)"
  5409.  
  5410. # get the full pkg name, to compare against repo pkgs we find
  5411. PKGNAME_FULL="`get_pkg_name "$PKGNAME"`"
  5412.  
  5413. # get pkg name only .. without version or suffix
  5414. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5415.  
  5416. # remove any previous user choice lists
  5417. rm $TMPDIR/PKGLIST &>/dev/null
  5418. rm $TMPDIR/USRPKGLIST &>/dev/null
  5419.  
  5420. # get all pkgs that match the given pkgname
  5421. # returns full pkg names (field1 of repo, pkgname with ver but no extension) each on a new line
  5422. PKGS="`$PKGSEARCH "${PKGNAME}"`"
  5423.  
  5424. if [ "$FORCE" = false -a "`is_installed_pkg "$PKGNAME_FULL"`" = true -a "$HIDE_INSTALLED" = true ]; then
  5425. # remove it from choices
  5426. PKGS="`echo "$PKGS" | grep -v ^$PKGNAME_FULL\$`"
  5427. fi
  5428.  
  5429. # extra steps for ubuntu and debian repos, if multiple choices returned.. remove non-compatible archs, remove dev and dbg pkgs...
  5430. if [ "$PKGEX" = "deb" -a "`echo "$PKGS" | wc -l`" != "1" ]; then
  5431.  
  5432. ARCH="`uname -m`"
  5433. #remove x64 pkgs from choices if not using an x64 cpu
  5434. [ "$ARCH" != "x86_64" ] && PKG="`echo "$PKGS" | grep -v -E 'amd64|x86_64'`"
  5435.  
  5436. # set any pkgs matching current arch to top of list
  5437. 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
  5438. do
  5439. # if not searching for -dev or -dgb pkg, move it to bottom of the list
  5440. if [ "`is_blacklisted_pkg "$LINE"`" = false -a "`echo "$PKGNAME" | grep -E "\-dbg_|\-dev_"`" = "" -a "`echo "$LINE" | grep -E "\-dbg_|\-dev_"`" != "" ]; then
  5441. PKGS="`echo "$PKGS" | grep -v "$LINE"`"
  5442. PKGS="$PKGS
  5443. $LINE"
  5444. fi
  5445. # if pkg is for current cpu arch, move it to top of the list
  5446. if [ "`echo "$LINE" | grep -m1 "$ARCH"`" != "" ]; then
  5447. PKGS="`echo "$PKGS" | grep -v "$LINE"`"
  5448. PKGS="$LINE
  5449. $PKGS"
  5450. fi
  5451. done
  5452. #remove debug and dev pkgs
  5453. #PKGS="`echo "$PKGS" | grep -v "\-dbg_"`"
  5454. #PKGS="`echo "$PKGS" | grep -v "\-dev_"`"
  5455. fi
  5456.  
  5457. # get the user to choose which packages they want to install
  5458. if [ "$ASK" = true -a "$PKGS" != "" ]; then
  5459. echo "Please choose the package number. For the first package,"
  5460. echo "enter '1', without quotes. To install multiple packages,"
  5461. echo "enter the numbers, separated by a comma. Example: 1,3,4"
  5462. echo
  5463. fi
  5464.  
  5465. # if using ubuntu/debian packages, put pkg_* before pkg-* .. else dont
  5466. [ "$PKGEX" = 'deb' ] && sort='sort -r' || sort='sort'
  5467.  
  5468. # go through each actual pkg that matches the pkgname search, make it a numbered list
  5469. echo "$PKGS" | $sort -u | while read LINE
  5470. do
  5471. if [ "$LINE" != "" -a "$LINE" != "," -a "$LINE" != " " ]; then
  5472. [ "$ASK" = true ] && echo "${INT}. $LINE"
  5473. echo "${INT}. $LINE" >> $TMPDIR/PKGLIST
  5474. INT=$(($INT + 1))
  5475. fi
  5476. done
  5477.  
  5478. # if pkg list was made
  5479. if [ -f $TMPDIR/PKGLIST -a "`cat $TMPDIR/PKGLIST 2>/dev/null`" != "" ]; then
  5480.  
  5481. # set to first pkg only as default
  5482. if [ "$ASK" = false ]; then
  5483. USRPKGLIST="$(echo "$PKGS" | $sort | head -1)"
  5484. echo "$USRPKGLIST" > $TMPDIR/USRPKGLIST
  5485. fi
  5486.  
  5487. # user can now input which actual pkgs to get, chosen by number
  5488. if [ "$ASK" = true ]; then
  5489. # only ask once
  5490. ASK=false
  5491.  
  5492. echo
  5493. echo "Give the numbers of the packages you want to install,"
  5494. echo -n "separated by a comma, or hit ENTER only to skip: "
  5495. read USRPKGLIST1 </dev/tty
  5496.  
  5497. # if user chose nothing (hit ENTER only), just skip
  5498. [ "$USRPKGLIST1" = '' ] && continue
  5499.  
  5500. # split the results into newlines, create the list of chosen pkgs (used by other funcs)
  5501. echo "${USRPKGLIST1}" | tr ',' '\n' | while read LINE
  5502. do
  5503. # set chosen pkg choice(s)
  5504. echo "`grep "^$LINE. " "$TMPDIR/PKGLIST" 2>/dev/null | cut -f2 -d' '`" >> $TMPDIR/USRPKGLIST
  5505. done
  5506. fi
  5507.  
  5508. # remove temp file.. but keep $TMPDIR/USRPKGLIST, it contains our users choices, and is used by pkg_get() and get_deps()
  5509. rm $TMPDIR/PKGLIST &>/dev/null
  5510. fi
  5511. }
  5512.  
  5513.  
  5514. pkg_get(){ # find, download and install $1 and its deps FUNCLIST
  5515.  
  5516. # The function `choose_pkg` is run just before this one. It gives us $TMPDIR/USRPKGLIST,
  5517. # which contains a list of packages the user wants to install or download.
  5518. # In this func, we will go through the list and download/install the package, as well
  5519. # as its dependencies (depending on what the user chose to do).
  5520. to_dl_dir=${TMPDIR}/to_dl
  5521. to_inst_dir=${TMPDIR}/to_install
  5522. downloading_dir=${TMPDIR}/downloading
  5523. inst_spec_dir=${TMPDIR}/specs
  5524. deps_dir=${TMPDIR}/deps
  5525. alias_dir=${TMPDIR}/deps_aliases
  5526. order_dir=${TMPDIR}/deps_aliases
  5527. mkdir -p "$to_dl_dir"
  5528. mkdir -p "$downloading_dir"
  5529. mkdir -p "$to_inst_dir"
  5530. mkdir -p "$inst_spec_dir"
  5531. mkdir -p "$deps_dir"
  5532. mkdir -p "$deps_aliases" #Remaining alsisies to try
  5533. . ${PKGRC}
  5534.  
  5535. # exit if no valid options
  5536. [ ! "$1" -o "$1" = "" -o "$1" = "-" ] && print_usage get && exit 1
  5537.  
  5538. local PREVDIR="$CURDIR"
  5539. local pkg_ext=`get_pkg_ext "$1"`; pkg_ext="${pkg_ext:-$EX}" # fall back to repo extension
  5540. local PKGNAME="`get_pkg_name $(basename "$1" .$pkg_ext)`"
  5541. local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5542. local PKGLIST="${PKGNAME}"
  5543. local pkg_builtin=''
  5544.  
  5545. # dont ask to download or install pkg or deps, as choose_pkg() already asked
  5546. ASK=false
  5547.  
  5548. # exit if no valid pkg name
  5549. [ ! "$PKGNAME" -o "$PKGNAME" = "" -o "$PKGNAME" = "-" ] && print_usage get && exit 1
  5550.  
  5551. # we want to download all pkgs to same place
  5552. cd "$WORKDIR"
  5553. CURDIR="$WORKDIR"
  5554.  
  5555. # use the list of pkgs user has chosen to install, or the given PKGNAME
  5556. if [ "`cat "$TMPDIR/USRPKGLIST" 2>/dev/null`" != "" ]; then
  5557. PKGLIST="`cat "$TMPDIR/USRPKGLIST" | grep -v "^\$"`"
  5558. fi
  5559.  
  5560. if [ -z "$PKGLIST" ]; then
  5561. echo "No packages to get, exiting."
  5562. exit 1
  5563. fi
  5564.  
  5565. # skip if any pkgs previously installed during our current loop (of getting 'pkg + recursive deps')
  5566. echo "$PKGLIST" | while read pkg_in_list
  5567. do
  5568. name_only=`get_pkg_name_only "$pkg_in_list"`
  5569. [ -f $TMPDIR/PKGSDONE -a "`grep "^${name_only}\$" $TMPDIR/PKGSDONE 2>/dev/null`" != '' ] && continue
  5570. done
  5571.  
  5572. # list the pkgs and ask to download (and maybe install)
  5573. echo "$PKGLIST" | while read pkg
  5574. do
  5575.  
  5576. [ "$pkg" = '' -o ! "$pkg" ] && continue
  5577.  
  5578. local pkg_name=`get_pkg_name "$pkg" 2>/dev/null`
  5579. [ "$pkg_name" = '' -o ! "$pkg_name" ] && continue
  5580.  
  5581. local pkg_name_only=`get_pkg_name_only "$pkg" 2>/dev/null`
  5582. [ "`is_blacklisted_pkg "$pkg_name_only"`" = true ] && continue
  5583.  
  5584. local pkg_already_done=`grep -m1 "^$pkg_name_only\$" $TMPDIR/PKGSDONE 2>/dev/null`
  5585. [ "$pkg_already_done" != '' ] && continue
  5586.  
  5587. local pkg_in_repo=`is_repo_pkg $pkg_name_only`
  5588. local PKGFILE=''
  5589.  
  5590. # dont even try to download if no matches found
  5591. if [ "$pkg_in_repo" = true -a "$pkg_name_only" != "" ]; then
  5592.  
  5593. local pkg_is_builtin=`is_builtin_pkg "$pkg_name_only"`
  5594. local pkg_is_in_devx=`is_devx_pkg "$pkg_name_only"`
  5595.  
  5596. # skip getting pkg if its a builtin, unless HIDE_BUILTINS=false
  5597. if [ "$pkg_is_builtin" = true -a "${HIDE_BUILTINS}" = true ]; then
  5598. echo "Skipping $pkg_name_only (already built-in).."
  5599. continue
  5600. fi
  5601.  
  5602. # skip getting pkg if its in the devx, unless HIDE_BUILTINS=false
  5603. if [ "$pkg_is_in_devx" = true -a "${HIDE_BUILTINS}" = true ]; then
  5604. echo "Skipping $pkg_name_only (already in devx).."
  5605. continue
  5606. fi
  5607.  
  5608. # if we are intending to install the pkg
  5609. if [ "$NO_INSTALL" = false -a "$FORCE" = false ]; then
  5610. # skip if package is already installed, unless --force given
  5611. if [ "$FORCE" = false -a "`is_installed_pkg $pkg_name`" = true ]; then
  5612. echo -e "Package ${magenta}${pkg_name_only}${endcolour} already installed."
  5613. echo -e "Use the -f option to force installation: $SELF add $pkg_name_only -f"
  5614. continue
  5615. fi
  5616. fi
  5617.  
  5618. # DOWNLOAD PKG
  5619. #pkg_download "$pkg_name"
  5620. touch ${TMPDIR}/to_install/"$pkg_name"
  5621. download_manager "$pkg_name" &
  5622.  
  5623. # get deps early (if any)
  5624. list_deps "$pkg_name" --download --install > ${TMPDIR}/${pkg_name}_dep_list &
  5625.  
  5626.  
  5627.  
  5628. [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}.*${pkg_ext}"`"
  5629. # try grabbing $CURDIR/pkgname.pkg_ext
  5630. [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}*.${pkg_ext}"`"
  5631. # now try grabbing $CURDIR/pkgname.*
  5632. [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}.*"`"
  5633. # maybe try $CURDIR/pkgname-*.*
  5634. [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}-*.*"`"
  5635. # maybe try $CURDIR/pkgname_*.*
  5636. [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}_*.*"`"
  5637. # maybe try $CURDIR/pkgname*.*
  5638. [ ! -f "$PKGFILE" ] && PKGFILE="`find "$CURDIR" -maxdepth 1 -type f -name "${pkg_name}*.*"`"
  5639.  
  5640. # add extension if Pkg returned an erroneous or user dir
  5641. [ -d "$PKGFILE" ] && PKGFILE="${PKGFILE}.$pkg_ext"
  5642.  
  5643. # if we found the package to install in CURDIR
  5644. if [ -f "${PKGFILE}" ]; then
  5645.  
  5646. # check if we install or not
  5647. if [ "${NO_INSTALL}" = false ]; then
  5648.  
  5649. # if a valid pkg, with files to extract
  5650. if [ "`pkg_contents "$PKGFILE" 2>/dev/null`" != '' ]; then
  5651.  
  5652.  
  5653. #INSTALL PKG
  5654. [ "`is_local_pkg "$PKGFILE"`" = true ] && pkg_install "${PKGFILE}"
  5655.  
  5656.  
  5657. fi
  5658.  
  5659. fi
  5660.  
  5661. # if pkg was installed, or Pkg is simply downloading all deps
  5662. if [ "`is_installed_pkg "$pkg_name_only"`" = true -o "${NO_INSTALL}" = true ]; then
  5663.  
  5664. # get the dependencies for this package
  5665. get_deps "${pkg_name}"
  5666. #rm /tmp/pkg/list_deps_busy #s243a: we might want to remove list_deps_busy here
  5667. fi
  5668.  
  5669. else # PKGFILE not a file
  5670. echo "Can't find ${PKGNAME} or not a valid pkg.."
  5671. fi
  5672.  
  5673. else # no matches in repo found
  5674. echo "Cannot find ${PKGNAME}.."
  5675. fi
  5676.  
  5677. # done with this pkg, add it to done list, will be skipped it seen again, until loop is finished
  5678. echo "$pkg_name_only" >> $TMPDIR/PKGSDONE
  5679. done
  5680. }
  5681.  
  5682.  
  5683. pkg_update(){ # update installed pkgs, $1 is optional filter FUNCLIST
  5684.  
  5685. # exit if no valid options
  5686. #[ ! "$1" -o "$1" = "-" ] && print_usage pkg-update && exit 1
  5687.  
  5688. # get rc file settings
  5689. . ${PKGRC}
  5690.  
  5691. local PKGNAME=''
  5692. local PKGLIST=''
  5693. local pkg_ext=$EX
  5694. local BUILTINS=''
  5695. local separator=''
  5696.  
  5697. if [ "$1" != '' ]; then
  5698.  
  5699. PKGNAME=$(basename "$1")
  5700. PKGNAME=`get_pkg_name "$PKGNAME"`
  5701. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  5702.  
  5703. # get installed packages
  5704. PKGLIST="`HIDE_BUILTINS=false list_installed_pkgs "$PKGNAME_ONLY"`"
  5705.  
  5706. #is_builtin=`is_builtin_pkg "$PKGNAME"`
  5707.  
  5708. # dont update builtins unless -F was given
  5709. #if [ "$is_builtin" = true -a "$HIDE_BUILTINS" = true ]; then
  5710. # echo -e "Package ${magenta}${PKGNAME}${endcolour} is built in, not updating."
  5711. # #echo -e "Use `$SELF -F --pkg-update $PKGNAME` to update it anyway."
  5712. # exit 0
  5713. #fi
  5714. else
  5715. # get installed packages
  5716. PKGLIST="`HIDE_BUILTINS=false list_installed_pkgs`"
  5717. fi
  5718.  
  5719. # iterate over the list
  5720. echo "$PKGLIST" | grep -v ^$ | sort -u | while read installed_pkg; do
  5721.  
  5722. [ ! "$installed_pkg" -o "$installed_pkg" = '' ] && continue
  5723.  
  5724. # if this pkg ($installed_pkg) is not from a known repo, we cant compare its version to anything else, skip it
  5725. #[ "`is_repo_pkg "$installed_pkg"`" = false ] && echo -e "Package ${magenta}$installed_pkg${endcolour} not found in any repos." && continue
  5726.  
  5727. local PNAME=''
  5728. local latest_repo_pkg=''
  5729. local ASKREPLY='y'
  5730. # get pkg name (without version) and version of current PKG
  5731.  
  5732. PNAME=`get_pkg_name_only $installed_pkg`
  5733.  
  5734. [ "$PNAME" = '' ] && continue
  5735.  
  5736. case $DISTRO_BINARY_COMPAT in
  5737. ubuntu|trisquel|debian|devuan)
  5738. separator='_'
  5739. ;;
  5740. *)
  5741. separator='-'
  5742. ;;
  5743. esac
  5744.  
  5745. latest_repo_pkg="`grep -m1 "^${PNAME}${separator}" "${ALL_REPO_DB_PATHS[@]}" |cut -f1 -d'|' | head -1 | cut -f2 -d':'`"
  5746.  
  5747. # skip if we didn't find the right package
  5748. [ "`echo "$latest_repo_pkg" | grep "^${PNAME}${separator}"`" = '' ] && continue
  5749.  
  5750. latest_version=`get_pkg_version "$latest_repo_pkg"`
  5751. installed_version=`get_pkg_version "$installed_pkg"`
  5752.  
  5753. # get latest versions
  5754.  
  5755. # check pkg version against installed version
  5756. if [ "$latest_version" != "" -a "$installed_version" != "" ]; then
  5757. vercmp $latest_version gt $installed_version 2>/dev/null
  5758. RESULT=$?
  5759.  
  5760. if [ "$RESULT" = 0 ]; then #newer version available
  5761.  
  5762. if [ "$ASK" = true ]; then
  5763. echo "Do you want to update to ${PNAME}${separator}${latest_version}? [y/N] "
  5764. read -n 1 ASKREPLY </dev/tty
  5765. [ "$ASK" = true ] && echo -ne "\b\b\n"
  5766. fi
  5767.  
  5768. if [ "$ASK" = false -o "$ASKREPLY" = "y" ]; then
  5769. echo -e "${yellow}Update${endcolour}: ${magenta}$PNAME${endcolour} from ${bold}$installed_version${endcolour} to ${bold}$latest_version${endcolour}"
  5770. cd "$WORKDIR"
  5771. ASK=$ASK FORCE=$FORCE pkg_get "$latest_repo_pkg"
  5772. cd "$CURDIR"
  5773. fi
  5774.  
  5775. else #280613 inform user if no update found
  5776. echo -e "${green}Latest${endcolour}: $PNAME${separator}$installed_version"
  5777. fi #end if vercmp XX gt YY = 0
  5778.  
  5779. elif [ "$PNAME" = '' ]; then
  5780. error "${installed_pkg} not found."
  5781. else #280613
  5782. error "$installed_pkg package versions could not be compared: ${latest_version:-unknown latest} => ${installed_version:-unknown installed version}"
  5783. #return 1
  5784. fi #end if PKGVER != ""
  5785. done
  5786. }
  5787.  
  5788.  
  5789. pkg_uninstall(){ # remove an installed package ($1) FUNCLIST
  5790.  
  5791. # quit if no valid options
  5792. [ ! "$1" -o "$1" = "-" ] && print_usage uninstall && exit 1
  5793.  
  5794. local PKGNAME
  5795. local PKGNAME_ONLY
  5796. local PKGFILE
  5797. local pkg_ext
  5798.  
  5799. # get pkg extension
  5800. pkg_ext=`get_pkg_ext "$1"`
  5801.  
  5802. #get pkg name with version, but no extension or path
  5803. PKGNAME="$(basename "$1" .$pkg_ext)"
  5804. PKGNAME="$(basename "$PKGNAME" .pet)"
  5805. PKGNAME="$(basename "$PKGNAME" .deb)"
  5806. PKGNAME="$(basename "$PKGNAME" .sfs)"
  5807. PKGNAME="$(basename "$PKGNAME" .tar.gz)"
  5808. PKGNAME="$(basename "$PKGNAME" .tar.xz)"
  5809. PKGNAME="$(basename "$PKGNAME" .tgz)"
  5810. PKGNAME="$(basename "$PKGNAME" .txz)"
  5811. PKGNAME=`get_pkg_name "$PKGNAME"`
  5812.  
  5813. # get pkg name only .. without versions or suffix
  5814. PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  5815.  
  5816. local pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY"`
  5817. local is_installed=`is_installed_pkg "$PKGNAME"`
  5818.  
  5819. # skip pkg if its a builtin
  5820. [ "$pkg_is_builtin" = true ] && return 1
  5821.  
  5822. local pkg_is_sfs_file="`sfs_loadr -q -i | grep -v ^sfs_loadr | grep ^$PKGNAME`"
  5823.  
  5824. # if pkg is SFS, "uninstall" it here
  5825. if [ "$pkg_is_sfs_file" != "" -o "$pkg_ext" = "sfs" ]; then
  5826. PKGNAME="$(sfs_loadr -q -i | grep -v ^sfs_loadr | grep ^$PKGNAME | head -1)"
  5827. sfs_loadr -q --cli -"${CURDIR}/${PKGNAME}" 2>/dev/null
  5828. is_installed=true # we want to continue
  5829. fi
  5830.  
  5831.  
  5832. if [ "$is_installed" = true -o "$FORCE" = true ]; then #250713
  5833.  
  5834. # get the list of files to be deleted, exact match
  5835. PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "$PKGNAME.files")"
  5836.  
  5837. # if no exact match, search for pkgname*
  5838. [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME}"'*.files')"
  5839. [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}_"'*.files')"
  5840. [ ! -f "$PKGFILE" ] && PKGFILE="$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${PKGNAME_ONLY}-"'*.files')"
  5841. [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}.files"
  5842. [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}.sfs.files"
  5843. [ ! -f "$PKGFILE" ] && PKGFILE="${PKGNAME}-${CP_SUFFIX}.sfs.files"
  5844.  
  5845. #if PKG.files not found, then remove it from alien packages list
  5846. if [ ! -f "$PKGFILE" ]; then
  5847.  
  5848. #error "'${PKGFILE}' not found.. Cleaning up.."
  5849.  
  5850. # backup the original list of user installed pkgs
  5851. cp "$USER_INST_PKGS_FILE" $TMPDIR/user-installed-packages.backup
  5852.  
  5853. # remove $PKGNAME from list of installed pkgs
  5854. cat "$USER_INST_PKGS_FILE" 2>/dev/null | grep -v "^${PKGNAME}" > "$PKGS_DIR/user-installed-packages.updated"
  5855.  
  5856. # if we created a new file ok
  5857. if [ -f "$PKGS_DIR/user-installed-packages.updated" ]; then
  5858. # replace the user-installed-packages file with our new one
  5859. mv "$PKGS_DIR/user-installed-packages.updated" "$USER_INST_PKGS_FILE" 2>/dev/null
  5860. fi
  5861.  
  5862. # clean up user-installed-packages (remove duplicates and empty lines)
  5863. cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages.clean"
  5864. mv "$PKGS_DIR/user-installed-packages.clean" "$USER_INST_PKGS_FILE"
  5865.  
  5866. # no *.files to process, so if not forcing full uninstall, we can exit here
  5867. [ "$FORCE" = false ] && return 1
  5868. fi
  5869.  
  5870. # if we are here, we have a $PKGS_DIR/***.files to work with (or using --force)
  5871.  
  5872. # get pkgs that depend on $PKGNAME
  5873. [ "$FORCE" = false ] && dependents="`list_dependents "$PKGNAME"`" || dependents=''
  5874.  
  5875. # if we have dependents, we should not uninstall and just exit, unless --force was given
  5876. if [ "$dependents" != "" -a "`echo "$dependents" | grep 'not installed'`" = '' -a "$FORCE" != true ]; then
  5877.  
  5878. # inform user of dependent pkgs
  5879. echo -e "${yellow}Warning${endcolour}: $PKGNAME_ONLY is needed by: "
  5880. echo -e "${magenta}$dependents${endcolour}"
  5881. echo "Uninstall the packages above first, or use:"
  5882. echo -e "${bold}pkg --force uninstall $PKGNAME${endcolour}."
  5883. echo
  5884. return 1
  5885.  
  5886. fi
  5887.  
  5888. # ask/inform user before uninstall
  5889. echo -n "Uninstall the package ${PKGNAME}$QTAG: "
  5890. [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  5891. [ "$ASK" = true ] && echo -ne "\b\b\n"
  5892.  
  5893. # if user answered yes, we will now uninstall the pkgs
  5894. if [ "$CONFIRM" = "y" ]; then
  5895.  
  5896. # print new line if we didnt take any user input on tty
  5897. [ "$ASK" != true ] && echo
  5898.  
  5899. # execute uninstall script.
  5900. if [ -x "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" ]; then
  5901. "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" &>/dev/null
  5902. rm -f "$PACKAGE_FILE_LIST_DIR/${PKGNAME}.remove" &>/dev/null
  5903. fi
  5904.  
  5905. # if we have no pkg file (listing of pkg contents), we cant cat/grep it
  5906. if [ ! -f "$PKGFILE" ]; then
  5907. echo "Not found: $PKGS_DIR/$PKGNAME.files"
  5908. return 1
  5909. fi
  5910.  
  5911. # check if has menu entry
  5912. [ "`cat "$PKGFILE" | grep -m1 ".desktop\$"`" != "" ] && HASMENUENTRY=true || HASMENUENTRY=false
  5913.  
  5914. # remove files listed in *.files
  5915. cat "$PKGFILE" | while read LINE
  5916. do
  5917. # some symlinks may not get removed. '-e' will not work if symlink
  5918. # is pointing to a non-existent file. So, check for symlink...
  5919. REMFILE=""
  5920. [ -h "$LINE" ] && REMFILE="yes"
  5921. [ -e "$LINE" ] && REMFILE="yes"
  5922. if [ "$REMFILE" = "yes" ]; then
  5923. if [ ! -d "$LINE" ]; then
  5924. if [ -e "/initrd/pup_ro2$LINE" ]; then
  5925. # deleting the file on the top layer places a ".wh" whiteout file, that hides the original file.
  5926. # what we want is to remove the installed file, and restore the original pristine file...
  5927. cp -af "/initrd/pup_ro2${LINE}" "$LINE"
  5928. else
  5929. rm -f "$LINE" &>/dev/null
  5930. fi
  5931. #delete empty dirs...
  5932. DELDIR="`dirname "$LINE" 2>/dev/null`"
  5933. [ "`ls -1 "$DELDIR"`" = "" ] && rmdir "$DELDIR" &>/dev/null
  5934. fi
  5935. fi
  5936. done
  5937.  
  5938. # go through again and remove any empty dirs...
  5939. cat "$PKGFILE" 2>/dev/null | while read LINE
  5940. do
  5941. DELDIR="`dirname "$LINE" 2>/dev/null`"
  5942. [ -d "$DELDIR" ] && [ "`ls -1 "$DELDIR"`" = "" ] && rmdir "$DELDIR"
  5943. #check one level up... but do not delete top dir, like /opt...
  5944. DELLEVELS=`echo -n "$DELDIR" | sed -e 's/[^/]//g' | wc -c | sed -e 's/ //g'`
  5945. if [ $DELLEVELS -gt 2 ]; then
  5946. DELDIR="`dirname "$DELDIR" 2>/dev/null`"
  5947. [ -d "$DELDIR" ] && [ "`ls -1 "$DELDIR"`" = "" ] && rmdir $DELDIR
  5948. fi
  5949. done
  5950.  
  5951. # remove $PKGNAME from user-installed-packages
  5952. NEWUSERPKGS="$(grep -v "^${PKGNAME}" "$USER_INST_PKGS_FILE")"
  5953. [ "$NEWUSERPKGS" != "" ] && echo "$NEWUSERPKGS" > "$USER_INST_PKGS_FILE"
  5954.  
  5955. # clean up user-installed-packages (remove duplicates and empty lines)
  5956. cat "$USER_INST_PKGS_FILE" | grep -v "^\$" | uniq > "$PKGS_DIR/user-installed-packages_clean"
  5957. mv "$PKGS_DIR/user-installed-packages_clean" "$USER_INST_PKGS_FILE"
  5958.  
  5959. # remove $PKGS_DIR/$PKGNAME.files
  5960. rm $PKGFILE ${PKGFILE} 2>/dev/null
  5961.  
  5962. # do fixmenus, if menu entry found
  5963. if [ "$HASMENUENTRY" = true ]; then
  5964. [ ! -f /tmp/pkg/update_menus_busy ] && update_menus &
  5965. fi
  5966.  
  5967. # UNINSTALL DONE .. print message
  5968. echo -e "${green}Uninstalled:${endcolour} $PKGNAME"
  5969.  
  5970. # log uninstall with the system logs
  5971. [ "`which logger`" != '' ] && logger "$0 Package $PKGNAME uninstalled by $APP $APPVER"
  5972.  
  5973. fi #end if $CONFIRM=yes
  5974.  
  5975. else # $PKGNAME is not installed
  5976.  
  5977. # if any installed pkg matches $PKGNAME
  5978. if [ "`list_installed_pkgs $PKGNAME`" != "" ]; then #290613
  5979. # list the matching pkgs
  5980. echo "These installed packages match '$PKGNAME':"
  5981. echo "`list_installed_pkgs $PKGNAME`"
  5982. fi
  5983.  
  5984. return 1
  5985.  
  5986. fi # endif installed or not
  5987. }
  5988.  
  5989.  
  5990. pkg_remove(){ # remove pkg ($1) and its leftover deps FUNC_LIST
  5991.  
  5992. # quit if no valid options
  5993. [ ! "$1" -o "$1" = "-" ] && print_usage remove && exit 1
  5994.  
  5995. local PKGNAME
  5996. local PKGNAME_ONLY
  5997. local PKGFILE
  5998. local pkg_ext
  5999.  
  6000. # get pkg extension
  6001. pkg_ext=`get_pkg_ext "$1"`
  6002.  
  6003. #get pkg name with version, but no extension or path
  6004. PKGNAME="$(basename "$1" .$pkg_ext)"
  6005. PKGNAME=`get_pkg_name "$PKGNAME"`
  6006.  
  6007. # get pkg name only .. without versions or suffix
  6008. PKGNAME_ONLY="`get_pkg_name_only "$PKGNAME"`"
  6009.  
  6010. if [ "`is_installed_pkg "$PKGNAME"`" = false ]; then
  6011. echo "Package '$1' not installed."
  6012. return 1
  6013. fi
  6014.  
  6015. pkg_uninstall "$PKGNAME"
  6016.  
  6017. # now we will remove any left over dependencies
  6018.  
  6019. file="`find $TMPDIR -iname "${1}*_dep_list"`"
  6020.  
  6021. if [ -f "$file" ]; then
  6022.  
  6023. # if we have a deps list file, go over it three times, uninstalling all deps
  6024. # that have no packages that depend on them ... fugly solution, but works ok..
  6025.  
  6026. for x in 1 2 3 4
  6027. do
  6028. cat "$file" | tr ' ' '\n' | while read user_installed_dep
  6029. do
  6030. [ "$user_installed_dep" = '' ] && continue
  6031. ASK=false pkg_uninstall $user_installed_dep &>/dev/null && \
  6032. echo -e "${green}Uninstalled:${endcolour} $(get_pkg_name $user_installed_dep)"
  6033. done
  6034. done
  6035.  
  6036. fi
  6037.  
  6038. return 0
  6039. }
  6040.  
  6041.  
  6042. clean_pkgs(){ # delete downloaded pkg files of installed pkgs FUNCLIST
  6043. local pkg_to_rm
  6044. [ "$ASK" = true ] && ASKOPT='--ask'
  6045. # list all (matching) installed pkgs
  6046. list_installed_pkgs | while read line;
  6047. do
  6048. # get all pkgs except the combined (user-created) pkgs
  6049. pkg_to_rm="`list_downloaded_pkgs $line | grep -v $CP_SUFFIX`"
  6050. # if it has a downloaded pkg in $WORKDIR, (offer to) delete it
  6051. [ "$pkg_to_rm" != '' ] && rm -v "${WORKDIR}/$pkg_to_rm";
  6052. done
  6053. }
  6054.  
  6055.  
  6056. # dependency funcs
  6057.  
  6058. get_deps_entry(){ # $1 is PKGNAME, returns dep entry from repo db
  6059. [ "$1" = '' -o "$1" = "-" ] && print_usage list-deps && exit 1
  6060.  
  6061. # get current $REPOFILE, $DEPSEARCH
  6062. #. ${PKGRC}
  6063.  
  6064. local PKGNAME="$1"
  6065. local pkg_ext=''
  6066. local repo_files=''
  6067. local deps_list=''
  6068. local deps=''
  6069. local repo_of_pkg=''
  6070. local repo_file_of_pkg=''
  6071.  
  6072. # get pkg extension
  6073. pkg_ext=`get_pkg_ext "$1"`
  6074.  
  6075.  
  6076. # get repo file to search from RC file
  6077. repo_file_of_pkg="$REPOFILE"
  6078.  
  6079. # if searching dependencies in all repos
  6080. if [ "$DEPSEARCH" = "list_all_pkg_names" ]; then
  6081.  
  6082. # get the repo that $PKGNAME lives in
  6083. repo_of_pkg=`which_repo "$PKGNAME" | cut -f2 -d' ' | head -1`
  6084. # then get the repo file for that repo.. that is where this pkg lists its deps
  6085. repo_file_of_pkg=`grep -m1 ^"$repo_of_pkg" ~/.pkg/sources-all | cut -f3 -d'|'`
  6086.  
  6087. fi
  6088.  
  6089. # add the full path to the repo file
  6090. repo_file_of_pkg="$REPO_DB_FILE_DIR/$repo_file_of_pkg"
  6091.  
  6092. # search for deps entry in repo file.. look for |pkgname.ext|
  6093. 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'`"
  6094.  
  6095. # try again if needed.. look for ^pkgname|
  6096. [ "$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'`"
  6097.  
  6098. # try again if needed.. look for |pkgname|
  6099. [ "$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'`"
  6100.  
  6101. # try again, look for dep-*
  6102. [ "$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'`"
  6103.  
  6104. # try again if needed.. with underscore.. dep_*
  6105. [ "$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'`"
  6106.  
  6107. # if no deps, exit with error
  6108. [ "$deps_list" != "" ] && echo "$deps_list"
  6109. }
  6110. list_all_installed_pkgs_old(){ # list inc builtins if HIDE_BUILTINS=false
  6111. # reset list of installed pkgs
  6112. echo -n '' > $TMPDIR/installed_pkgs
  6113.  
  6114. #if [ "${HIDE_INSTALLED}" = true -a "$FORCE" = false ]; then
  6115. # # add user installed pkgs to list of pkgs to remove from final output
  6116. cut -f2 -d'|' "$USER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6117. #fi
  6118.  
  6119. #if [ "${HIDE_BUILTINS}" = true ]; then
  6120. # # add builtins to list of pkgs to remove from final output
  6121. cut -f2 -d'|' "$WOOF_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6122. #fi
  6123.  
  6124. #if [ -f "$DEVX_INST_PKGS_FILE" ]; then
  6125. # # add devx pkgs to list of pkgs to remove from final output
  6126. cut -f2 -d'|' "$DEVX_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6127. #fi
  6128.  
  6129. #if [ -f "$LAYER_INST_PKGS_FILE" ]; then
  6130. # # add layers list of pkgs to remove from final output
  6131. cut -f2 -d'|' "$LAYER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6132. #fi
  6133.  
  6134. if [ -f $TMPDIR/installed_pkgs -a ! -z $TMPDIR/installed_pkgs ]; then
  6135. sort -u $TMPDIR/installed_pkgs | grep -v ^$ > $TMPDIR/installed_pkgs__sorted
  6136. mv $TMPDIR/installed_pkgs__sorted $TMPDIR/installed_pkgs
  6137. fi
  6138. }
  6139.  
  6140. list_all_installed_pkgs(){ # list inc builtins if HIDE_BUILTINS=false
  6141. # reset list of installed pkgs
  6142. echo -n '' > $TMPDIR/installed_pkgs
  6143.  
  6144. if [ "${HIDE_INSTALLED}" != true -o -z "${HIDE_INSTALLED}" ] && [ "$FORCE" != false ]; then
  6145. # # add user installed pkgs to list of pkgs to remove from final output
  6146. cut -f2 -d'|' "$USER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6147. fi
  6148.  
  6149. if [ "${HIDE_BUILTINS}" != true -o -z "${HIDE_INSTALLED}" ]; then
  6150. # # add builtins to list of pkgs to remove from final output
  6151. cut -f2 -d'|' "$WOOF_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6152. fi
  6153.  
  6154. if [ -f "$DEVX_INST_PKGS_FILE" ]; then
  6155. # # add devx pkgs to list of pkgs to remove from final output
  6156. cut -f2 -d'|' "$DEVX_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6157. fi
  6158.  
  6159. if [ -f "$LAYER_INST_PKGS_FILE" ]; then
  6160. # # add layers list of pkgs to remove from final output
  6161. cut -f2 -d'|' "$LAYER_INST_PKGS_FILE" >> $TMPDIR/installed_pkgs
  6162. fi
  6163.  
  6164. if [ -f $TMPDIR/installed_pkgs -a ! -z $TMPDIR/installed_pkgs ]; then
  6165. sort -u $TMPDIR/installed_pkgs | grep -v ^$ > $TMPDIR/installed_pkgs__sorted
  6166. mv $TMPDIR/installed_pkgs__sorted $TMPDIR/installed_pkgs
  6167. fi
  6168. ln -s $TMPDIR/installed_pkgs $TMPDIR/installed_pkgs_finished
  6169. }
  6170.  
  6171.  
  6172. has_deps(){ # return true if $1 has deps, else false
  6173. [ "$1" = '' -o "$1" = "-" -o ! "$1" ] && echo false
  6174. [ "`get_deps_entry $1`" != '' ] && echo true || echo false
  6175. }
  6176. install_manager(){
  6177. install_manager_dir=${TMPDIR}/to_dl
  6178. mkdir -p install_manager_dir
  6179.  
  6180. }
  6181. install_manager_wkr_supdebs_first(){
  6182. local install_manager_dir=${TMPDIR}/to_dl
  6183. local PKGNAME="`get_pkg_name $(basename "$1" .$pkg_ext)`"
  6184. local pkg_name_only=`get_pkg_name_only "$pkg" 2>/dev/null`
  6185. [ "`is_blacklisted_pkg "$pkg_name_only"`" = true ] && continue
  6186.  
  6187. local pkg_already_done=`grep -m1 "^$pkg_name_only\$" $TMPDIR/PKGSDONE 2>/dev/null`
  6188. [ "$pkg_already_done" != '' ] && continue
  6189.  
  6190. local pkg_in_repo=`is_repo_pkg $pkg_name_only`
  6191. local PKGFILE=''
  6192. local pkg_builtin=''
  6193. declare -A deps #This is a local associative array
  6194. local i=1
  6195. while read aDep; do #If we use arrays here than we don't have to wory about cleanup
  6196. deps+=( [$i]="$aDep" )
  6197. i=$((i++))
  6198. done < <(cat "${TMPDIR}/${pkg_name}_dep_list"
  6199. #dep_file=${TMPDIR}/${pkg_name}_dep_list
  6200. while [ ${#deps[@]} -gt 0 ]; then
  6201. for akey in ${!deps[@]}; do
  6202. aDep=${deps[$aKey]}
  6203. if [ -f $install_manager_dir/$aDep ]; then
  6204. if [ "`is_local_pkg "$DEPFILE" 2>/dev/null`" = true ]; then
  6205. if pkg_install "$DEPFILE" 2>/dev/null; then
  6206. rm $install_manager_dir/$aDep
  6207. unset ${deps[$aKey]}
  6208. else #TODO add failure actions and error reporting
  6209. rm $install_manager_dir/$aDep
  6210. unset ${deps[$aKey]}
  6211. fi
  6212. fi
  6213. else
  6214. unset ${deps[$aKey]}
  6215. fi
  6216. done
  6217.  
  6218. fi
  6219. }
  6220. install_manager_wkr_parallel(){
  6221. #local pkg_name="$1"
  6222. #local PREVDIR="$CURDIR"
  6223. #local pkg_ext=`get_pkg_ext "$1"`; pkg_ext="${pkg_ext:-$EX}" # fall back to repo extension
  6224. local install_manager_dir=${TMPDIR}/to_dl
  6225. local PKGNAME="`get_pkg_name $(basename "$1" .$pkg_ext)`"
  6226. local pkg_name_only=`get_pkg_name_only "$pkg" 2>/dev/null`
  6227. [ "`is_blacklisted_pkg "$pkg_name_only"`" = true ] && continue
  6228.  
  6229. local pkg_already_done=`grep -m1 "^$pkg_name_only\$" $TMPDIR/PKGSDONE 2>/dev/null`
  6230. [ "$pkg_already_done" != '' ] && continue
  6231.  
  6232. local pkg_in_repo=`is_repo_pkg $pkg_name_only`
  6233. local PKGFILE=''
  6234. local pkg_builtin=''
  6235. declare -A deps #This is a local associative array
  6236. local i=1
  6237. while read aDep; do #If we use arrays here than we don't have to wory about cleanup
  6238. deps+=( [$i]="$aDep" )
  6239. i=$((i++))
  6240. done < <(cat "${TMPDIR}/${pkg_name}_dep_list"
  6241. #dep_file=${TMPDIR}/${pkg_name}_dep_list
  6242. while [ ${#deps[@]} -gt 0 ]; then
  6243. for akey in ${!deps[@]}; do
  6244. aDep=${deps[$aKey]}
  6245. if [ -f $install_manager_dir/$aDep ]; then
  6246. if [ "`is_local_pkg "$DEPFILE" 2>/dev/null`" = true ]; then
  6247. if pkg_install "$DEPFILE" 2>/dev/null; then
  6248. rm $install_manager_dir/$aDep
  6249. unset ${deps[$aKey]}
  6250. else #TODO add failure actions and error reporting
  6251. rm $install_manager_dir/$aDep
  6252. unset ${deps[$aKey]}
  6253. fi
  6254. fi
  6255. else
  6256. unset ${deps[$aKey]}
  6257. fi
  6258. done
  6259.  
  6260. done
  6261. #cat "$dep_file" | \ #we could loop through this but instead we'll use arrays
  6262. #
  6263. #
  6264. # while [ ${#depsread aFile; do
  6265. # #INSTALL THE DEP, if it was downloaded
  6266. # if [ "`is_local_pkg "$DEPFILE" 2>/dev/null`" = true ]; then
  6267. #
  6268. # fi pkg_install "$DEPFILE" 2>/dev/null
  6269. # done
  6270. }
  6271. download_manager(){
  6272.  
  6273. to_dl_dir=${TMPDIR}/to_dl
  6274. downloading_dir=${TMPDIR}/downloading
  6275. mkdir -p "$to_dl_dir"
  6276. mkdir -p "$downloading_dir"
  6277.  
  6278. local next_dl="$1"
  6279. #local dl_specs="$to_dl_dir/"${2:-"$1"}
  6280.  
  6281. if [ -f /tmp/pkg/download_manager_busy ]; then
  6282. retun
  6283. else
  6284. echo true > /tmp/pkg/download_manager_busy
  6285.  
  6286. fi
  6287. { if [ ! -z "$next_dl" ]; then
  6288. [ ! -z "$next_dl" ] && echo "$next_dl";
  6289. while true; do
  6290. if find "$to_dl_dir" -mindepth 1 -print -quit 2>/dev/null | grep -q .; then
  6291. ls -1 "$(realpath "$to_dl_dir")"
  6292. else
  6293. [ ! -f /tmp/pkg/list_deps_busy ] && break # echo "Target '$target' is empty or not a directory"
  6294. fi
  6295. sleep 0.25
  6296. done
  6297. }| \
  6298. while read aPkg; do
  6299. #eval $(. "$to_dl_dir"/$aPkg;
  6300. # echo dl_status="$dl_status";
  6301. # )
  6302. #
  6303. if [ -f "$to_dl_dir/$aPkg" ]; then #This if condition is a step towards allowsing multipole instances of pkg to run.
  6304. mv "$to_dl_dir/$aPkg" "$downloading_dir/$aPkg"
  6305. pkg_download $aPkg #echo "Not empty, do something"
  6306. fi
  6307. done
  6308.  
  6309. #https://stackoverflow.com/questions/20456666/bash-checking-if-folder-has-contents
  6310.  
  6311. }
  6312. get_subdep_entry_as_file(){
  6313. local subdep=$1
  6314. local subdep_version="$2"
  6315. local out_file="$inst_spec_dir/$subdep"
  6316. local entry=""
  6317. found=0
  6318. for aRepo in "${ALL_REPO_DB_PATHS[@]}"; do
  6319. for i in 1 2; do
  6320. case "$i" in
  6321. 1) subdep2="subdep"
  6322. 2)
  6323. subdep2="$(echo subdep | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  6324. if [ "$subdep" = "$subdep2" ]; then
  6325.  
  6326. fi
  6327. esac
  6328. for aPattern in '|${subdep2}|' '^${subdep2}|' '^${subdep2}|-' '^${subdep2}|_'; do
  6329. #for subdep2 in "$original" "$stripped"; do
  6330. for subdep3 in $subdep2
  6331. if [ found -ne 1 ]; then
  6332. entry="$(grep -m1 "|${aPattern}|" "${aRepo}")"
  6333. [ ! -z $entry ] && continue
  6334. else
  6335. echo "'|${aPattern}|' '${aRepo}'" >> "$remaining_patterns_dir/$subdep"
  6336. fi
  6337. done
  6338. #done
  6339. done
  6340. done < <( list_aliases "$subdep" "$subdep_version"
  6341. done
  6342. echo $entry > "$inst_spec_dir/$subdep"
  6343. }
  6344. get_entry_as_file(){
  6345. local subdep=$1 #We'll rename this var after we test the code enough.
  6346. local out_file="$inst_spec_dir/$subdep"
  6347. local entry=""
  6348. for i in 1 2; do
  6349. case "$i" in
  6350. 2) subdep="$(echo subdep | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  6351. esac
  6352. for "$original" "$stripped"; do
  6353. for aPattern in "^${subdep}|" "|${subdep}|" "^${subdep}|-" "^${subdep}|_"; do
  6354. entry="$(grep -m1 "|${aPattern}|" "${ALL_REPO_DB_PATHS[@]}")"
  6355. [ ! -z $entry ] && continue
  6356. done
  6357. done
  6358. done
  6359. echo $entry > "$inst_spec_dir"
  6360. }
  6361. write_order(){
  6362. local PKGNAME="$1"
  6363. local RECURSION_DEPTH="${2:-0}"
  6364. local order_file="$(cd "$order_dir"; ls ??_${PKGNAME})"
  6365. if [ ! -z "$order_file" ]
  6366. order=$(cut -f1 -d'|')
  6367. if [ $RECURSION_DEPTH -gt $order ]; then
  6368. if RECURSION_DEPTH -gt 9
  6369. mv order_file $order_dir/${RECURSION_DEPTH}_${PKGNAME}
  6370. else
  6371. mv order_file $order_dir/0${RECURSION_DEPTH}_${PKGNAME}
  6372. fi
  6373. fi
  6374. fi
  6375.  
  6376. }
  6377. list_deps(){ # list all deps of PKG ($1), space separated on one line FUNCLIST
  6378. list_deps_count=$(( list_deps_count + 1 ))
  6379. [ "$1" = '' -o "$1" = "-" ] && print_usage list-deps && exit 1
  6380.  
  6381. echo true > /tmp/pkg/list_deps_busy
  6382.  
  6383. # create list of installed pkgs ($TMPDIR/installed_pkgs) for later
  6384. [ ! -f $TMPDIR/installed_pkgs ] && list_all_installed_pkgs
  6385.  
  6386. # get current $REPOFILE, $DEPSEARCH
  6387. #. ${PKGRC}
  6388.  
  6389. local PKGNAME=''
  6390. local PKGNAME_ONLY=''
  6391. local pkg_ext=''
  6392. local repo_files=''
  6393. local deps_list=''
  6394. #local deps=''
  6395. local repo_of_pkg=''
  6396. local repo_file_of_pkg=''
  6397. dep_id=$((dep_id +1))
  6398. local ldepID=dep_id
  6399. # get pkg extension
  6400. pkg_ext=`get_pkg_ext "$1"`
  6401. #pkg name only ,no path, no extension
  6402. PKGNAME="$(LANG=C basename "$1" .$pkg_ext)"
  6403. PKGNAME=`get_pkg_name "$PKGNAME"`
  6404. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"`
  6405. declare -A deps; deps=([$PKGNAME]=0)
  6406.  
  6407. blacklisted_pkgs_list="$(echo $PKG_NAME_IGNORE | sed -e 's/ /|/g')"
  6408.  
  6409. # get the deps of the pkg, note, in the repo deps are NOT listed by proper pkg names, .. they are +dbus,+glib,+SDL
  6410.  
  6411. # search for deps entry in repo file.. look for |pkgname.ext|
  6412. deps_list="`LANG=C get_deps_entry "$PKGNAME"`"
  6413.  
  6414. # if no deps, exit with error
  6415. [ "$deps_list" = "" ] && rm /tmp/pkg/list_deps_busy 2>/dev/null && return 1
  6416.  
  6417. # remove the '+' from the start of each dep
  6418. deps="${deps_list/+/}" # remove first + at start of line
  6419. deps="${deps//,+/ }" # remove others .. DEPS will now be just 'dep1 dep2 dep3'
  6420. deps="${deps// / }" # remove double spaces
  6421.  
  6422. if [ "$deps" != '' -a "$deps" != ' ' ]; then
  6423.  
  6424. # put all deps of pkg in a tmp file
  6425. echo "$deps" | tr ' ' '\n' | tr ',' '\n' | sort -u > $TMPDIR/all_deps_${ldepID}_0
  6426. #Wait for installed_packages list to be created in list_all_installed_pkgs.
  6427. while [ ! -f "${TMPDIR}/installed_pkgs_finished" ];do #TODO: s243a: consider adding readlink here
  6428. echo -n '.'
  6429. sleep 0.1
  6430. done
  6431. # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6432. comm -23 ${TMPDIR}/all_deps_${ldepID}_0 ${TMPDIR}/installed_pkgs | sort -u | grep -v ^$ > ${TMPDIR}/all_deps_${ldepID}_1
  6433.  
  6434. # remove all blacklisted packages from the list
  6435. grep -vE "'$blacklisted_pkgs_list'" ${TMPDIR}/all_deps_${ldepID}_1 2>/dev/null | sort -u > ${TMPDIR}/all_deps_${ldepID}_1_without_blacklisted_packages
  6436. mv ${TMPDIR}/all_deps_${ldepID}_1_without_blacklisted_packages ${TMPDIR}/all_deps_${ldepID}_1
  6437.  
  6438. rm -f ${TMPDIR}/DEP_DONE 2>/dev/null
  6439.  
  6440. if [ -f $TMPDIR/all_deps_${ldepID}_1 -a ! -z $TMPDIR/all_deps_${ldepID}_1 ]; then
  6441. # recursive search deps of deps
  6442. for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  6443. do
  6444. deps_list_file="${TMPDIR}/all_deps_${ldepID}_${i}"
  6445.  
  6446.  
  6447. if [ -f $deps_list_file ]; then
  6448.  
  6449. # remove all blacklisted packages from the list
  6450. grep -vE "'$blacklisted_pkgs_list'" "$deps_list_file" > ${TMPDIR}/deps_list_file_without_blacklisted_pkgs
  6451. mv ${TMPDIR}/deps_list_file_without_blacklisted_pkgs $deps_list_file
  6452.  
  6453. # remove done packages from the list
  6454. if [ -f ${TMPDIR}/DEP_DONE ]; then
  6455. deps_done_list="$(cat ${TMPDIR}/DEP_DONE | tr '\n' '|' | grep -v ^$)"
  6456. grep -vE "'$deps_done_list'" $deps_list_file > ${TMPDIR}/deps_list_file_without_completed_pkgs
  6457. mv ${TMPDIR}/deps_list_file_without_completed_pkgs $deps_list_file
  6458. fi
  6459.  
  6460. next_deps_list_file="${TMPDIR}/all_deps_${ldepID}_$(($i + 1))"
  6461. rm -f "${TMPDIR}/all_deps_${ldepID}_$(($i + 1))"
  6462. # for each dep in $deps, get their deps too
  6463. for subdep in `sort -u $deps_list_file | grep -v ^$`
  6464. do
  6465. [ "$subdep" = '' -o "$subdep" = ' ' ] && continue
  6466.  
  6467. local subdeps_entry=''
  6468. local subdeps=''
  6469. local subdeps_list=''
  6470. local is_builtin
  6471. local is_in_devx
  6472.  
  6473. local already_done=`grep -m1 "^${subdep}\$" ${TMPDIR}/DEP_DONE 2>/dev/null`
  6474. [ "$already_done" != '' ] && continue
  6475.  
  6476. if [ "$HIDE_BUILTINS" = true ] || [ -z "$HIDE_BUILTINS" ]; then
  6477. is_builtin=`is_builtin_pkg "$subdep"`
  6478. [ "$is_builtin" = true ] && continue
  6479. is_in_devx=`is_devx_pkg "$subdep"`
  6480. [ "$is_in_devx" = true ] && continue
  6481. fi
  6482.  
  6483. subdeps_entry="`get_deps_entry "$subdep"`"
  6484. subdeps="${subdeps_entry/+/}" # remove first + at start of line
  6485. subdeps="${subdeps//,+/ }" # remove others .. DEPS will now be just 'dep1 dep2 dep3'
  6486. subdeps="${subdeps// / }" # remove double spaces
  6487.  
  6488. if [ "$subdeps" != '' ] && [ "$subdeps" != ' ' ]; then
  6489. # remove everything after the + (if the + is followed by alphanumeric chars), then add to tmp files
  6490. echo "$subdep" >> ${TMPDIR}/DEP_DONE
  6491.  
  6492. #subdep_arry=()
  6493. while read subdep2; do
  6494. #subdep2_entry="$(grep -m1 "|$subdep2|" "${ALL_REPO_DB_PATHS[@]}")"
  6495.  
  6496. #Creat the subdep entry if it doesn't exist.
  6497. if [ ! -e "$inst_spec_dir/$subdep2" ]; then
  6498. [ -h "$inst_spec_dir/$subdep2" ] && rm "$inst_spec_dir/$subdep2"
  6499. get_subdep_entry_as_file
  6500. fi
  6501.  
  6502. subdep_name="$(cat "$inst_spec_dir/$subdep2" | cut -f2 -d'|')"
  6503. if [ ! -z "$subdep_name" ]; then
  6504. #Not sure if we should rename or not.
  6505. mv "$inst_spec_dir/$subdep2" "$inst_spec_dir/$subdep_name"
  6506. ln -s "$inst_spec_dir/$subdep_name" "$inst_spec_dir/$subdep2"
  6507. subdep2="$subdep_name"
  6508. if [ -e "$to_dl_dir/$subdep2" ]; then
  6509. rm "$to_dl_dir/$subdep2"
  6510. ln -s "$inst_spec_dir/$subdep2" "$downloading_dir/$subdep2"
  6511. fi
  6512. if [ -e "$to_inst_dir/$subdep2" ]; then
  6513. rm "$to_inst_dir/$subdep2"
  6514. ln -s "$inst_spec_dir/$subdep2" "$to_inst_dir/$subdep2"
  6515. fi
  6516. # subdep_arry+=("$subdep2")
  6517. #echo subdep2 >> $next_deps_list_file
  6518. echo subdep2 >> $next_deps_list_file
  6519. fi
  6520. done < <( `echo "${subdeps}" | tr ' ' '\n' | grep -v ^$` )
  6521. #echo "$subdeps_list" >> $next_deps_list_file
  6522. echo "$subdep_name" >> $n ext_deps_list_file
  6523. fi
  6524. done
  6525. fi
  6526. done
  6527.  
  6528. # add all deps together, sorted, duplicated removed
  6529. sort -u ${TMPDIR}/all_deps_${ldepID}_* | grep -v ^$ > ${TMPDIR}/all_deps_${ldepID}_sorted
  6530. mv ${TMPDIR}/all_deps_${ldepID}_sorted ${TMPDIR}/all_deps_${ldepID}
  6531.  
  6532. fi
  6533.  
  6534. fi
  6535.  
  6536. # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6537. if [ -f ${TMPDIR}/installed_pkgs -a ! -z ${TMPDIR}/installed_pkgs ]; then
  6538. comm -23 ${TMPDIR}/all_deps_${ldepID} ${TMPDIR}/installed_pkgs | sort -u | grep -v ^$ > ${TMPDIR}/missing_deps
  6539. fi
  6540.  
  6541. # remove all blacklisted packages from the list
  6542. grep -vE "'$blacklisted_pkgs_list'" ${TMPDIR}/missing_deps 2>/dev/null | sort -u > ${TMPDIR}/missing_deps_without_blacklisted_pkgs
  6543. mv ${TMPDIR}/missing_deps_without_blacklisted_pkgs ${TMPDIR}/missing_deps
  6544.  
  6545. [ ! -f ${TMPDIR}/missing_deps -o -z ${TMPDIR}/missing_deps ] && rm /tmp/pkg/list_deps_busy 2>/dev/null && return 1
  6546. [ ! -f ${TMPDIR}/missing_deps ] && return 1
  6547.  
  6548. # get fixed deps list
  6549. deps="`LANG=C sort -u ${TMPDIR}/missing_deps 2>/dev/null | tr ' ' '\n' | while read dep
  6550. do
  6551. echo $(get_pkg_name_only "$dep")
  6552. done`"
  6553.  
  6554. [ "$deps" != "" ] && echo "$deps" | sed -e 's/^ //g' | tr ' ' '\n' | sort -u | tr '\n' ' '
  6555.  
  6556. # clean up
  6557. if [ $list_deps_count -eq 1 ]; then
  6558. rm "${TMPDIR}/installed_pkg"* 2>/dev/null
  6559. fi
  6560. rm "${TMPDIR}/missing_dep"* "${TMPDIR}/all_dep"* "${TMPDIR}/DEP_DONE" "/tmp/pkg/list_deps_busy" 2>/dev/null
  6561.  
  6562. }
  6563.  
  6564.  
  6565. find_deps(){ # given a package name ($1), makes 2 lists: DEPS_INSTALLED and DEPS_MISSING FUNCLIST
  6566.  
  6567. # This function takes 1 argument: PKGNAME
  6568. #
  6569. # PKGNAME should be the name of a package in one of your repos,
  6570. # such as 'vlc' or 'hardinfo'.
  6571. #
  6572. # This function creates 2 files: $TMPDIR/deps_missing and $TMPDIR/deps_installed.
  6573. # Each file is list the dependencies for PKGNAME, each dependency on a new line.
  6574. # get_deps() can then go through those files and download/install the missing deps.
  6575. #
  6576. # If --force was given, all deps will be treated as missing.
  6577.  
  6578. # get current repo ($REPOFILE)
  6579. . ${PKGRC}
  6580.  
  6581. local PKGNAME='' # the pkg given ($1), may be full name, or generic name (no version), etc
  6582. local PKGNAME_ONLY='' # the pkg given ($1), without version (vlc,htop,etc)
  6583. local pkg_ext='' # the pkg extension, blank if not a valid extension or none given
  6584. local repo_files='' # the list of repo files to check, may be current only or all
  6585. local deps_list='' # deps of PKGNAME in comma-delimited format: dep1,dep2,dep3
  6586. local deps_on_new_lines='' # as above, but each dep on a new line
  6587. local deps_missing='' # comma separated list of missing deps
  6588. local deps_installed='' # comma separated list of deps already installed
  6589. local dep='' # dep name scraped from deps_list, usually the same as dep_name_only
  6590. local dep_match='' # used to find matches in the repo for $dep
  6591. local dep_name_only='' # short (generic) pkg name, no version (vlc,htop,etc)
  6592. local dep_full_name='' # pkg name with version (vlc-2.3.3-i686_s700, etc)
  6593. local loading_indicator # blank if only a few deps to parse, or .
  6594. dep_id=$((dep_id +1))
  6595. local ldepID=dep_id
  6596.  
  6597. # get pkg extension
  6598. pkg_ext=`get_pkg_ext "$1"`
  6599.  
  6600. # pkg name with version, but no path, no extension
  6601. PKGNAME="$(basename "$1" .$pkg_ext)"
  6602.  
  6603. # we can't rely on the user input, try to get the right pkg names
  6604. PKGNAME=`get_pkg_name "$PKGNAME"` # vlc -> 'vlc-2.3-blah_etc
  6605. PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME"` # vlc-2.3-blah_etc -> vlc
  6606.  
  6607. # if PKGNAME still empty, we cant find its deps, move on
  6608. [ -z "$PKGNAME" ] && return 1
  6609.  
  6610. # didn't exit yet, so remove the old tmp dirs
  6611. rm $TMPDIR/deps_installed &>/dev/null
  6612. rm $TMPDIR/deps_missing &>/dev/null
  6613. rm $TMPDIR/deps_missing1 &>/dev/null
  6614.  
  6615. # loop through all repo files, or current repo only, depending on PKGSEARCH in RC file
  6616. # add the full path to the file(s) while we are getting the list of repo files
  6617. [ "$DEPSEARCH" = "list_all_pkg_names" ] && repo_files="`repo_file_list | sed -e "s|^|$PKGS_DIR/|g" | tr '\n' ' '`" || repo_files="$REPO_DB_FILE_DIR/$REPOFILE"
  6618.  
  6619. # get the list of deps from the repo entry of this pkg
  6620. deps_list="`LANG=C list_deps "$PKGNAME"`"
  6621.  
  6622. # remove builtins from list unless HIDE_BUILTINS=false
  6623. if [ "${HIDE_BUILTINS}" = true ]; then
  6624. echo "$deps_list" | tr ' ' '\n' | grep -v ^$ > ${TMPDIR}/all_deps_${ldepID}
  6625. # add woof pkgs to list of pkgs to remove from final output
  6626. cut -f2 -d'|' "$WOOF_INST_PKGS_FILE" | grep -v ^$ | sort | uniq >> $TMPDIR/installed_pkgs
  6627. # remove any deps in installed pkgs list from all deps.. to leave only missing deps
  6628.  
  6629. sort -u ${TMPDIR}/all_deps_${ldepID} > ${TMPDIR}/all_deps_${ldepID}_sorted
  6630. mv ${TMPDIR}/all_deps_${ldepID}_sorted ${TMPDIR}/all_deps_${ldepID}
  6631.  
  6632. sort -u ${TMPDIR}/installed_pkgs > ${TMPDIR}/installed_pkgs_sorted
  6633. mv ${TMPDIR}/installed_pkgs_sorted ${TMPDIR}/installed_pkgs
  6634.  
  6635. comm -23 ${TMPDIR}/all_deps_${ldepID} ${TMPDIR}/installed_pkgs | grep -v ^$ > ${TMPDIR}/missing_deps
  6636. deps_list="`cat "${TMPDIR}/missing_deps" 2>/dev/null | grep -v ^$ | sort | tr '\n' ' ' `"
  6637. fi
  6638.  
  6639. # so now, $deps_list='dep1 dep2 dep3'
  6640.  
  6641. # now get the deps list with each dep on its own line
  6642. deps_on_new_lines="`echo "$deps_list" | tr ' ' '\n'`"
  6643.  
  6644. # exit if no deps to parse
  6645. [ "$deps_on_new_lines" = '' ] && return 1
  6646.  
  6647. # set a loading bar (appending dots....) if we have numerous deps to search
  6648. [ `echo "$deps_on_new_lines" | wc -l` -gt 4 ] && loading_indicator='.' || loading_indicator=''
  6649.  
  6650. # now.. we go through ALL deps listed, and create a list for installed or not .. $dep will be 'gtkdialog3', for example
  6651. echo "$deps_on_new_lines" | grep -v ^$ | while read dep
  6652. do
  6653. # append dots as we go, like a loading spinner
  6654. [ "$loading_indicator" = '.' ] && echo -n "$loading_indicator"
  6655.  
  6656. # $dep is currently
  6657. dep_full_name=`get_pkg_name "$dep"` #vlc-2.3.3-i586_s700
  6658. dep_name_only=`get_pkg_name_only "$dep"` #vlc
  6659.  
  6660. # skip these non pkgs
  6661. [ "`is_repo_pkg "$dep_name_only"`" = false ] && continue
  6662.  
  6663. # if we added this dep to the list of PKGs already done, skip it
  6664. [ "`grep -m1 "^$dep_name_only\$" $TMPDIR/PKGSDONE 2>/dev/null`" != '' ] && continue
  6665.  
  6666. # lets check if the $dep is installed or not
  6667.  
  6668. # if dep was found in a repo and not installed, add to missing deps list
  6669. if [ "$FORCE" = true -o "`is_installed_pkg "$dep_full_name"`" = false ]; then
  6670. grep -m1 "^$dep_name_only\$" $TMPDIR/deps_missing 2>/dev/null || echo "$dep_name_only" | grep -v "^$PKGNAME" >> $TMPDIR/deps_missing
  6671.  
  6672. else
  6673. # else if the dep is already installed, add to installed deps list
  6674. grep -m1 "^$dep_name_only\$" $TMPDIR/deps_installed 2>/dev/null || echo "$dep_name_only" | grep -v "^$PKGNAME" >> $TMPDIR/deps_installed
  6675. fi
  6676.  
  6677. # clean up deps_installed, remove duplicates, etc
  6678. if [ -f $TMPDIR/deps_installed ]; then
  6679. cat $TMPDIR/deps_installed 2>/dev/null| sort | uniq >> $TMPDIR/deps_installed1
  6680. [ -f $TMPDIR/deps_installed1 ] && mv $TMPDIR/deps_installed1 $TMPDIR/deps_installed 2>/dev/null
  6681. fi
  6682.  
  6683. done # end of while $dep
  6684.  
  6685. # make a comma separated list from newlines
  6686. deps_installed="`cat $TMPDIR/deps_installed 2>/dev/null | sort | uniq | tr '\n' ',' | sed -e 's/,,/,/' -e 's/,$//' -e 's/^,//'`"
  6687. deps_missing="`cat $TMPDIR/deps_missing 2>/dev/null | sort | uniq | tr '\n' ',' | sed -e 's/,,/,/' -e 's/,$//' -e 's/^,//'`"
  6688.  
  6689. #120213, fixed, force all deps to be in the download list, if --force was given
  6690. if [ "$FORCE" = true ]; then
  6691. # dont skip installed deps (except builtins.. handled elsewhere)
  6692. if [ "$deps_installed" != "" ]; then
  6693. deps_missing="${deps_installed},${deps_missing}"
  6694. deps_missing="`echo "${deps_missing//,,/}" | sed -e 's/,$//' -e 's/^,//'`"
  6695. fi
  6696. fi
  6697.  
  6698. # later, get_deps() will use $DEPS_MISSING and $DEPS_INSTALLED
  6699. DEPS_MISSING="$deps_missing"
  6700. DEPS_INSTALLED="$deps_installed"
  6701.  
  6702. # end appending dots... msg, by printing a new line
  6703. [ "$loading_indicator" != '' ] && echo
  6704.  
  6705. }
  6706.  
  6707.  
  6708. get_deps(){ # find, get and install the deps of pkgname ($1) FUNCLIST
  6709.  
  6710. [ -z "$1" -o ! "$1" -o "$1" = "-" ] && print_usage deps && exit 1
  6711.  
  6712. . ${PKGRC} #150813
  6713.  
  6714. local EX
  6715. local PKGNAME
  6716. local DEPCONFIRM
  6717.  
  6718. # get pkg extension
  6719. local EX=`get_pkg_ext "$1"`
  6720.  
  6721. # get pkg name with version, but no path, no extension
  6722. local PKGNAME="$(LANG=C basename "$1" .$EX)"
  6723.  
  6724. # don't rely on user input, get the name w version from repos
  6725. local PKGNAME=`get_pkg_name "$PKGNAME" 2>/dev/null`
  6726. local PKGNAME_ONLY=`get_pkg_name_only "$PKGNAME" 2>/dev/null`
  6727.  
  6728. local pkg_is_builtin=`is_builtin_pkg "$PKGNAME_ONLY" 2>/dev/null`
  6729. local pkg_already_done=`LANG=C grep -m1 "^$PKGNAME_ONLY\$" $TMPDIR/PKGSDONE 2>/dev/null`
  6730.  
  6731. local pkg_is_blacklisted=`is_blacklisted_pkg "$PKG_NAME_ONLY" 2>/dev/null`
  6732.  
  6733. # if pkg is builtin, skip it, we dont need to get its dependencies
  6734. [ "$pkg_is_builtin" = true -a "$HIDE_BUILTINS" = true ] && continue
  6735.  
  6736. # if pkg is blacklisted, also skip it
  6737. [ "$pkg_is_blacklisted" = true ] && continue
  6738.  
  6739. # skip if already processed, it should be listed in $TMPDIR/PKGSDONE
  6740. [ "$pkg_already_done" != "" -a "$FORCE" = false ] && continue
  6741.  
  6742. echo -n "Resolving dependencies.." # find deps will append ... as it goes
  6743.  
  6744. # wait until list_deps() is finished (if it's running at all...)
  6745. while [ -f /tmp/pkg/list_deps_busy ];do
  6746. echo -n '.'
  6747. sleep 0.75
  6748. done
  6749.  
  6750. echo
  6751.  
  6752. # if list_deps() created a file listing the deps, get it from the file created, else, run list deps to be sure
  6753. [ -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`"
  6754.  
  6755. # if we have missing deps, or are downloading them all regardless (INSTALLDEPS=false), or using --force
  6756. if [ "$DEPS_MISSING" != "" -o "${NO_INSTALL}" = true -o "$FORCE" = true ]; then
  6757.  
  6758. # ask to download (and maybe install) the deps
  6759. DEPCONFIRM=y
  6760. if [ "$ASK" = true ]; then
  6761. echo "Missing deps: $DEPS_MISSING"
  6762. echo -n "Download the missing dependencies$QTAG: "
  6763. read -n 1 DEPCONFIRM </dev/tty
  6764. echo
  6765. # skip if user chose --ask and didn't answer 'y'
  6766. [ "$DEPCONFIRM" != "y" ] && return
  6767. fi
  6768.  
  6769. # if user answered yes, we will now download (and maybe install) the deps
  6770. if [ "$DEPCONFIRM" = "y" -o "$FORCE" = true ]; then
  6771.  
  6772. # only ask once
  6773. ASK=false
  6774.  
  6775. # make a list of the deps, each on a new line for each dep/newline
  6776. WARNLIBS=''; SEP='';
  6777.  
  6778. # if more than one missing dep, set separator to a comma
  6779. [ ! -z "$DEPS_MISSING" -a "`echo "$DEPS_MISSING" | wc -l`" != "1" -a "`echo "$DEPS_MISSING" | wc -l`" != "0" ] && SEP=','
  6780.  
  6781. # clean up our deps list, and make space separated only (no commas)
  6782. DEPS_MISSING="`LANG=C echo "${DEPS_MISSING//,/ }" | grep -v '^,' | grep -v "^\$"`"
  6783.  
  6784. # show deps info, if any available
  6785. [ "${DEPS_MISSING}" != "" ] && echo "Dependencies to get: ${DEPS_MISSING//,/, }"
  6786. [ "$FORCE" = false -a "${DEPS_INSTALLED}" != "" ] && echo "Dependencies installed: `LANG=C grep -v "^\$" $TMPDIR/deps_installed 2>/dev/null | head -1`"
  6787.  
  6788. # for each missing dep (or simply for each dep, if $FORCE is true)
  6789. for DEP in $DEPS_MISSING
  6790. do
  6791.  
  6792. [ "$DEP" = "" -o "$DEP" = "${PKGNAME_ONLY}" -o "$DEP" = "${PKGNAME}" ] && continue #skip if the dep is the main package
  6793.  
  6794. local DEPNAME=`get_pkg_name "$DEP" 2>/dev/null`
  6795. local DEPNAME_ONLY=`get_pkg_name_only "$DEPNAME" 2>/dev/null`
  6796. local DEPFILE=''
  6797.  
  6798. # skip if already processed, it should be listed in $TMPDIR/PKGSDONE
  6799. local dep_already_done=`LANG=C grep -m1 "^$DEPNAME_ONLY\$" $TMPDIR/PKGSDONE 2>/dev/null`
  6800. [ "$dep_already_done" != "" -a "$FORCE" = false ] && continue
  6801.  
  6802. local dep_is_blacklisted=`is_blacklisted_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6803. local dep_is_builtin=`is_builtin_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6804. local dep_is_usr_pkg=`is_usr_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6805. local dep_is_in_devx=`is_devx_pkg "$DEPNAME_ONLY" 2>/dev/null`
  6806.  
  6807. # skip getting pkg if its blacklisted
  6808. if [ "$dep_is_blacklisted" = true ]; then
  6809. echo "Skipping $DEPNAME_ONLY (blacklisted).."
  6810. continue
  6811. fi
  6812.  
  6813. # skip getting pkg if its a builtin, unless HIDE_BUILTINS=false
  6814. if [ "$dep_is_builtin" = true -a "${HIDE_BUILTINS}" = true ]; then
  6815. echo "Skipping $DEPNAME_ONLY (already built-in).."
  6816. continue
  6817. fi
  6818.  
  6819. # skip getting pkg if its user installed and not using --force
  6820. if [ "$dep_is_usr_pkg" = true -a "${FORCE}" != true ]; then
  6821. echo "Skipping $DEPNAME_ONLY (already installed).."
  6822. continue
  6823. fi
  6824.  
  6825. # skip getting pkg if its in the devx, unless HIDE_BUILTINS=false
  6826. if [ "$dep_is_in_devx" = true -a "${HIDE_BUILTINS}" = true ]; then
  6827. echo "Skipping $DEPNAME_ONLY (already built-in).."
  6828. continue
  6829. fi
  6830.  
  6831. #DOWNLOAD THE PKG
  6832. pkg_download "$DEPNAME" 2>/dev/null
  6833.  
  6834. # skip install unless NO_INSTALL=true
  6835. if [ "${NO_INSTALL}" = false ]; then
  6836.  
  6837. # get the actual file we just downloaded to WORKDIR
  6838. DEPFILE="`find "$WORKDIR" -maxdepth 1 -type f -name "$DEPNAME*" 2>/dev/null`"
  6839.  
  6840. #INSTALL THE DEP, if it was downloaded
  6841. [ "`is_local_pkg "$DEPFILE" 2>/dev/null`" = true ] && pkg_install "$DEPFILE" 2>/dev/null
  6842.  
  6843. # mark the pkg as done!
  6844. echo "$DEPNAME_ONLY" >> $TMPDIR/PKGSDONE
  6845.  
  6846. else # if not installing,
  6847. # skip dep checking of the deps that dont get installed
  6848. continue
  6849. fi
  6850.  
  6851.  
  6852. # we finished with this dep, mark it done,
  6853. # .. so we can skip it if it appears again (in a recursive dep check loop for example)
  6854. echo "$DEPNAME_ONLY" >> $TMPDIR/PKGSDONE #260713
  6855.  
  6856.  
  6857. done #done for DEP in DEPS_MISSING
  6858.  
  6859. fi #endif DEPCONFIM=y
  6860.  
  6861. else
  6862. echo "No missing dependencies."
  6863. fi # endif DEPS_MISSING != ''
  6864.  
  6865. # if some deps were missing (listed but not found), print msg
  6866. [ "$INSTALLDEPS" = true ] && actioned=installed || actioned=downloaded
  6867. [ "$WARNLIBS" != "" ] && echo -e "${yellow}Warning:${endcolour} Not $actioned from repo: $WARNLIBS"
  6868. #exit 0 #110913
  6869. }
  6870.  
  6871.  
  6872. pkg_ldd_msg(){ # check given package ($1) for missing deps FUNCLIST
  6873.  
  6874. # exit if no valid usage
  6875. [ ! "$1" -o "$1" = "-" ] && print_usage deps-check && exit 1
  6876.  
  6877. . ${PKGRC}
  6878.  
  6879. local PKGNAME
  6880. local FNDFILES
  6881. local LIST
  6882. local RES
  6883. local MISSING
  6884.  
  6885. # get pkg name
  6886. PKGNAME=`get_pkg_name "$1"`
  6887. rm $TMPDIR/pkg-$PKGNAME-MISSING.txt &>/dev/null
  6888.  
  6889. [ "`is_installed_pkg "$PKGNAME"`" = false ] && print_usage deps-check && exit 1
  6890.  
  6891. echo "Searching for missing dependencies.. Please wait."
  6892.  
  6893. local list="$PKGNAME `list_deps $PKGNAME`"
  6894.  
  6895. for pkg_name in $list
  6896. do
  6897. local pkg_name_only=`get_pkg_name_only "$pkg_name"`
  6898. # get the *.files for this pkg
  6899. FNDFILES="$(find $PACKAGE_FILE_LIST_DIR/ -iname "${pkg_name}.files" 2>/dev/null)"
  6900. [ ! -f "$FNDFILES" ] && FNDFILES="$(find "$PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}_*.files" 2>/dev/null)"
  6901. [ ! -f "$FNDFILES" ] && FNDFILES="$(find "$PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}-*.files" 2>/dev/null)"
  6902. [ ! -f "$FNDFILES" ] && FNDFILES="$(find "PACKAGE_FILE_LIST_DIR" -iname "${pkg_name}*.files" 2>/dev/null)"
  6903. [ ! -f "$FNDFILES" ] && continue
  6904.  
  6905. # get list of ldd-able file
  6906. cat "$FNDFILES" | grep -E '/lib/|/lib64/|/bin/|/games/|/sbin/' > ${TMPDIR}/ldd_file_list_${pkg_name}
  6907. [ -z ${TMPDIR}/ldd_file_list_${pkg_name} ] && continue
  6908.  
  6909. #loop through list
  6910. for file in `cat ${TMPDIR}/ldd_file_list_${pkg_name}`
  6911. do
  6912. [ ! -x "$file" ] && continue
  6913. RES="`ldd $file 2>/dev/null`"
  6914. MISSING="`echo "$RES" | grep found`"
  6915. [ "$MISSING" != "" -a "$MISSING" != " " ] && echo " $file:
  6916. $MISSING" >> $TMPDIR/${pkg_name}-MISSINGLIBS.txt
  6917. done
  6918.  
  6919. #print message
  6920. if [ -f $TMPDIR/${pkg_name}-MISSINGLIBS.txt ]; then
  6921. echo -e "${yellow}WARNING${endcolour}: ${magenta}${pkg_name_only}${endcolour} has missing dependencies: "
  6922. echo -e "`cat $TMPDIR/${pkg_name}-MISSINGLIBS.txt`"
  6923. else
  6924. echo -e "${green}OK:${endcolour} ${pkg_name} has no missing dependencies."
  6925. fi
  6926. rm -f ${TMPDIR}/ldd_file_list* $TMPDIR/${pkg_name}-MISSINGLIBS.txt 2>/dev/null
  6927. done
  6928. }
  6929.  
  6930.  
  6931. get_all_deps(){ # try to install all missing deps FUNCLIST
  6932. echo "Checking $(list_installed_pkgs | wc -l) installed packages for missing dependencies. Please wait..."
  6933. rm $TMPDIR/pkg_get_all_deps 2>/dev/null
  6934.  
  6935. list_installed_pkgs | while read LINE; do
  6936. DEPLIST="`LANG=C list_deps "$LINE"`"
  6937. [ "$DEPLIST" != "" -a "$LINE" != "" ] && echo "$LINE|$DEPLIST" >> $TMPDIR/pkg_get_all_deps
  6938. done
  6939.  
  6940. [ ! -f $TMPDIR/pkg_get_all_deps ] && echo "No missing dependencies." && exit 0
  6941. ASKOPT=''; [ "$ASK" = true ] && ASKOPT='--ask ';
  6942. FORCEOPT=''; [ "$FORCE" = true ] && FORCEOPT='--force ';
  6943.  
  6944. cat $TMPDIR/pkg_get_all_deps 2>/dev/null | while read LINE
  6945. do
  6946. [ "$LINE" = "" -o "`echo "$LINE" | grep -v '|'`" = "" ] && continue
  6947. # get pkg gname from field 1
  6948. PKGNAME="${LINE%%|*}"
  6949. DEPS="${LINE##*|}"
  6950.  
  6951. echo "Checking $PKGNAME..."
  6952.  
  6953. for DEP in $DEPS;
  6954. do
  6955. # try to get the pkg name
  6956. DEPPKG="`list_all_pkg_names $DEP- | head -1`" || \
  6957. DEPPKG="`list_all_pkg_names $DEP_ | head -1`" || \
  6958. DEPPKG="`list_all_pkg_names $DEP | head -1`"
  6959. # if dep not in any repos, skip it
  6960. [ "$DEPPKG" = "" ] && continue
  6961. # skip if the dep is already installed
  6962. [ "`is_installed_pkg $DEPPKG`" = true ] && continue
  6963. # ask to get dep
  6964. echo -n "Get the missing package: ${DEPPKG}$QTAG: "
  6965. echo
  6966. [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  6967. [ "$ASK" = true ] && echo -ne "\b\b\n"
  6968. # if user answered yes, we will now download the pkgs
  6969. if [ "$CONFIRM" = "y" ]; then
  6970. NO_INSTALL=false pkg_get "$DEPPKG" # get the missing dep (and its deps)
  6971. fi
  6972. done
  6973. done
  6974. rm -f $TMPDIR/pkg_get_all_deps 2>/dev/null
  6975. }
  6976.  
  6977.  
  6978. list_dependents(){ # list user installed pkgs that depend on $1 FUNCLIST
  6979.  
  6980. local PKGNAME=''
  6981. local PKGNAME_ONLY=''
  6982.  
  6983. if [ "$1" = '' ]; then
  6984. print_usage what-needs
  6985. exit 1
  6986. fi
  6987.  
  6988. # try to get correct pkg names
  6989. PKGNAME=`get_pkg_name "$1"`
  6990. PKGNAME_ONLY=`get_pkg_name_only "$1"`
  6991.  
  6992. # if pkg is not installed, then nothing depends on it
  6993. if [ "`is_installed_pkg "$PKGNAME"`" = false ]; then
  6994. echo "Package $1 not installed, nothing depends on it."
  6995. exit 1
  6996. fi
  6997.  
  6998. # list all pkgs (from all repos) with $PKGNAME_ONLY as a dep
  6999. cut -f1,2,9 -d'|' "$REPO_DB_FILE_DIR"/Packages-* \
  7000. | sed -e "s/:any//g" -e "s/&[geql][eqt][0-9a-z._-]*//g" 2>/dev/null \
  7001. | grep -E "+${PKGNAME_ONLY},|+${PKGNAME_ONLY}\|" 2>/dev/null \
  7002. | cut -f2 -d'|' 2>/dev/null \
  7003. | grep -v "^\$" \
  7004. | grep -v "^#" \
  7005. | grep -v "^$PKGNAME_ONLY\$" \
  7006. | sort -u \
  7007. >> ${TMPDIR}/dependents_list
  7008.  
  7009. if [ "$HIDE_BUILTINS" = false ]; then
  7010. # list all builtin and devx packages with $PKGNAME_ONLY as a dependency..
  7011. cut -f1,2,9 -d'|' "$WOOF_INST_PKGS_FILE" "$DEVX_INST_PKGS_FILE" \
  7012. "$DEVX_INST_PKGS_FILE" \
  7013. | grep -E "+${PKGNAME_ONLY},|+${PKGNAME_ONLY}\|" \
  7014. | cut -f2 -d'|' \
  7015. | grep -v "^\$" \
  7016. | grep -v "^#" \
  7017. | grep -v "^$PKGNAME_ONLY\$" \
  7018. | sort -u \
  7019. >> ${TMPDIR}/dependents_list
  7020. fi
  7021.  
  7022. # remove duplicates
  7023. sort -u ${TMPDIR}/dependents_list > ${TMPDIR}/dependents_list__sorted
  7024. mv ${TMPDIR}/dependents_list__sorted ${TMPDIR}/dependents_list_tmp
  7025. rm ${TMPDIR}/dependents_list
  7026.  
  7027. # only keep the user installed pkgs in the list
  7028. for pkg in `list_installed_pkgs | grep -v ^$PKGNAME`
  7029. do
  7030. [ "`grep -m1 "^$(get_pkg_name_only $pkg)\$" ${TMPDIR}/dependents_list_tmp`" != '' ] && echo "$pkg" >> ${TMPDIR}/dependents_list
  7031. done
  7032.  
  7033. # print the list if we have one
  7034. [ -f ${TMPDIR}/dependents_list -a ! -z ${TMPDIR}/dependents_list ] && cat ${TMPDIR}/dependents_list
  7035. rm ${TMPDIR}/dependents_lis* 2>/dev/null
  7036. }
  7037.  
  7038.  
  7039. # file conversion
  7040.  
  7041. deb2pet(){ # $1 must be valid deb file or repo pkg FUNCLIST
  7042. [ ! -f "$1" ] && print_usage deb2pet && exit 1
  7043.  
  7044. local DEB="${CURDIR}/$(basename "${1}")"
  7045. local DIRNAME="${CURDIR}"
  7046. #create file name we work with
  7047. [ -f "$1" ] && DEB="$1" && DIRNAME="`dirname "$1"`"
  7048.  
  7049. #keep old file, download it if needed
  7050. #[ -f "$(basename "$1" .deb)" ] || ASK=$ASK FORCE=$FORCE pkg_download "$(basename "$1" .deb)"
  7051.  
  7052. # if the deb exists
  7053. if [ -e "$DEB" ]; then
  7054. for i in "$DEB" # for each deb given
  7055. do
  7056. #remove the extensions
  7057. #example, will be something like FOLDR=$HOME/Desktop/atari800_3.1.0-2+b2_i386
  7058. FOLDR="$(echo "$i"|sed 's/\.deb$//')"
  7059. done
  7060.  
  7061. #make the new dir, copy the deb file into it, and ci into it
  7062. mkdir -p "$FOLDR"; cp "$DEB" "$FOLDR"; cd "$FOLDR";
  7063.  
  7064. #get the new full path and filename
  7065. DEB="`ls | grep ".deb"`"
  7066.  
  7067. # extract into current dir and remov ethe copied deb file
  7068. pkg_unpack "$DEB" 1>/dev/null
  7069.  
  7070. #this will be something like PKGNAME=atari800_3.1.0-2+b2_i386
  7071. PKGNAME="`basename "$DEB" .deb`"
  7072.  
  7073. #now we package up the stuff into a pet
  7074. [ -d "${FOLDR}/$PKGNAME" ] && dir2pet "${FOLDR}/$PKGNAME" || dir2pet "$PKGNAME"
  7075.  
  7076. [ ! -f "$FOLDR.pet" -a ! -f "${CURDIR}/${PKGNAME}.pet" ] && error "$FOLDR.deb NOT converted to PET package!"
  7077.  
  7078. #clean up
  7079. rm -rf "$FOLDR"
  7080.  
  7081. else
  7082. echo "Package '$(basename $DEB)' not found in '$CURDIR'."
  7083. return 1
  7084. fi
  7085. }
  7086.  
  7087.  
  7088. dir2pet(){ # dir to PET, $1 must be valid dir FUNCLIST
  7089.  
  7090. # exit if no options
  7091. [ ! -d "$1" ] && print_usage dir2pet && exit 1
  7092.  
  7093. DIR="$1"
  7094. SUFFIX=''
  7095.  
  7096. [ "$2" != "" ] && SUFFIX="$2"
  7097.  
  7098. #[ -d "$DIR" ] && cd `dirname "$DIR"`
  7099.  
  7100. # get pkg name only,
  7101. DIR="$(basename "${DIR}")"
  7102. [ "$SUFFIX" != "" ] && cp -R "$DIR" "${DIR}${SUFFIX}" && DIR="${DIR}${SUFFIX}"
  7103.  
  7104. echo -e "Converting directory ${lightblue}$DIR${endcolour} to .pet package."
  7105.  
  7106. # we must have a dir with same name as a valid pkg
  7107. if [ -d "$DIR" ]; then
  7108. # move it to the build dir, to work on
  7109. mkdir -p "$CURDIR/build_pkg/"
  7110. [ ! -e "$CURDIR/build_pkg/$DIR" ] && cp -R "$DIR" "$CURDIR/build_pkg/"
  7111.  
  7112. ARCHINDEPENDENT='yes'
  7113. for ONEEXEC in `find $CURDIR/build_pkg/${DIR}/ -maxdepth 6 -type f -perm -o+x`
  7114. do
  7115. [ -f $ONEEXEC ] && [ "`file $ONEEXEC | grep ' ELF '`" != "" ] && ARCHINDEPENDENT='no'
  7116. done
  7117.  
  7118. # if it's a _DEV pkg.. it can't be ARCHINDEPENDENT
  7119. case "${BASEPKG}" in *"_DEV"*) ARCHINDEPENDENT='no' ;; esac
  7120. [ "`find $CURDIR/build_pkg/${DIR}/ -maxdepth 6 -type f -name '*.a' -o -type f -name 'lib*.so*' -o -type f -name '*.la'`" != "" ] && ARCHINDEPENDENT='no'
  7121. [ "$ARCHINDEPENDENT" = "no" ] && COMPAT=$DISTRO_BINARY_COMPAT V=$DISTRO_COMPAT_VERSION
  7122.  
  7123. #...borrowed from dir2pet script
  7124. #w482 directory may already have a pet.specs, reuse it...
  7125. NAMEONLY=""
  7126. PUPMENUDESCR=""
  7127. PUPOFFICIALDEPS=""
  7128. PUPCATEGORY=""
  7129. PUPPATH="" #100201
  7130. ARCHDEPENDENT="yes" #100201
  7131. DEFREPO="" #100201
  7132. if [ -f $CURDIR/build_pkg/${DIR}/pet.specs ]; then #160803
  7133. #new: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|
  7134. #optionally on the end: compileddistro|compiledrelease|repo| (fields 11,12,13)
  7135. PETSPECS="`cat $CURDIR/build_pkg/${DIR}/pet.specs | head -n 1`" #160803
  7136. while IFS="|" read -r F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 <&3
  7137. do
  7138. DB_pkgname="$F1"
  7139. DB_nameonly="$F2"
  7140. NAMEONLY="$DB_nameonly"
  7141. DB_version="$F3"
  7142. DB_pkgrelease="$F4"
  7143. DB_category="$F5"
  7144. PUPCATEGORY="$DB_category"
  7145. DB_size="$F6"
  7146. DB_path="$F7"
  7147. PUPPATH="$DB_path" #100201
  7148. DB_fullfilename="$F8"
  7149. DB_dependencies="$F9"
  7150. PUPOFFICIALDEPS="$DB_dependencies"
  7151. DB_description="$F10"
  7152. PUPMENUDESCR="$DB_description"
  7153. DB_compileddistro="$F11"
  7154. DB_compiledrelease="$F12"
  7155. ARCHDEPENDENT="${DB_compileddistro}|${DB_compiledrelease}"
  7156. DB_repo="$F13"
  7157. DEFREPO="$DB_repo"
  7158. done 3< $CURDIR/build_pkg/${DIR}/pet.specs
  7159. else
  7160. echo -e "\nCategories:
  7161. BuildingBlock, Desktop, System, Setup, Utility,
  7162. Filesystem, Graphic, Document, Business, Personal,
  7163. Network, Internet, Multimedia, Fun\n"
  7164. read -p 'Type one of the categories above, then hit ENTER: ' CAT_ENTRY </dev/tty;
  7165.  
  7166. echo
  7167. read -p "Add a short description, then hit ENTER: " DESC_ENTRY </dev/tty;
  7168.  
  7169. echo -e "\nAdd dependencies in this format: ${bold}+libglib,+ffmpeg${endcolour}\n"
  7170. read -p 'Enter dependencies (if any), then hit ENTER: ' DEPS_ENTRY </dev/tty;
  7171.  
  7172. 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
  7173. fi
  7174.  
  7175. # build .pet.specs
  7176.  
  7177. BASEPKG="`basename $DIR`"
  7178. DIRPKG="`dirname $DIR`"
  7179. [ "$DIRPKG" = "/" ] && DIRPKG=""
  7180.  
  7181. #difficult task, separate package name from version part...
  7182. #not perfect, some start with non-numeric version info...
  7183. [ "$NAMEONLY" = "" ] && NAMEONLY=`get_pkg_name_only "$BASEPKG"`
  7184.  
  7185. # get pet details from the pre-existing pet.specs (if any): deps, category, descr, version, nameonly, arch, distro version
  7186. PUPOFFICIALDEPS="$DB_dependencies"
  7187.  
  7188. TOPCAT="$PUPCATEGORY"
  7189. [ -z "$TOPCAT" ] && TOPCAT=BuildingBlock
  7190.  
  7191. PUPMENUDESCR="$DB_description"
  7192. [ -z "${PUPMENUDESCR}" ] && PUPMENUDESCR="No description provided"
  7193.  
  7194. VERSION="`get_pkg_version "$BASEPKG"`"
  7195.  
  7196. # build pet spec
  7197. if [ ! -f $CURDIR/build_pkg/${DIR}/pet.specs ]; then
  7198. echo "$BASEPKG|${NAMEONLY}|$VERSION|$DB_pkgrelease|$TOPCAT|$DB_size|$REPO_SUBDIR|${BASEPKG}.pet|$PUPOFFICIALDEPS|$PUPMENUDESCR|$COMPAT|$V||" > $CURDIR/build_pkg/${DIR}/pet.specs
  7199. fi
  7200.  
  7201. # delete the slackware package management files
  7202. #if [ -d "$CURDIR/build_pkg/install" ]; then
  7203. # rm -r "$CURDIR/build_pkg/install"; rmdir "$CURDIR/build_pkg/install";
  7204. #fi
  7205.  
  7206. # delete arch pkg stuff
  7207. #rm -r "$CURDIR/build_pkg/.INSTALL" &>/dev/null
  7208. #rm "$CURDIR/build_pkg/.PKGINFO" &>/dev/null
  7209.  
  7210. # now tar up the folder, ready to make into tar.gz, then into .pet
  7211. cd $CURDIR/build_pkg/
  7212.  
  7213. # we need to choose xz or gzip pets
  7214. arch=`uname -m`
  7215. if [ "${arch:0:3}" = "arm" ]; then
  7216. TAREXT="gz"
  7217. else
  7218. TAREXT="xz"
  7219. fi
  7220.  
  7221. # if in a pre-woof puppy then we dont use xz
  7222. if [ ! -f "$WOOF_INST_PKGS_FILE" -o ! -f /etc/DISTRO_SPECS ]; then
  7223. # pre woof format
  7224. echo "PETMENUDESCR='${DIR}'" > $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  7225. echo "PETOFFICIALDEPS=''" >> $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  7226. echo "PETREGISTER='yes'" >> $CURDIR/build_pkg/${DIR}/${DIR}.pet.specs
  7227. compression=xz
  7228. TAREXT="xz"
  7229. fi
  7230. tar -c -f ${DIR}.tar ${DIR} 1>/dev/null
  7231. sync
  7232. [ "`which xz`" = "" ] && TAREXT=gz
  7233. case "$TAREXT" in
  7234. xz) xz -z -9 -e ${DIR}.tar; ;;
  7235. gz) gzip --best ${DIR}.tar; ;;
  7236. esac
  7237.  
  7238. # now get info needed to make a pet file
  7239. TARBALL="${DIR}.tar.$TAREXT"
  7240. FULLSIZE="`stat --format=%s ${TARBALL}`"
  7241. MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  7242.  
  7243. # add the info to the file
  7244. echo -n "$MD5SUM" >> $TARBALL
  7245. sync
  7246.  
  7247. # now rename it to .pet
  7248. mv -f $TARBALL ${DIR}.pet
  7249. sync
  7250.  
  7251. # move the created pet out of build_pkg, into WORK_DIR
  7252. mv ${DIR}.pet $CURDIR/${DIR}.pet
  7253. cd $CURDIR
  7254.  
  7255. # clean up
  7256. rm -f -R $CURDIR/build_pkg/
  7257. echo
  7258. echo -e "Package ${magenta}${DIR}.pet${endcolour} created."
  7259. echo "The md5sum is: `md5sum ${DIR}.pet | cut -f1 -d' '`."
  7260. else
  7261. echo "Directory '$DIR' not found."
  7262. exit 1
  7263. fi
  7264. }
  7265.  
  7266.  
  7267. dir2sfs(){ # $1 must be dir of pkg contents FUNCLIST
  7268.  
  7269. if [ ! -d "$1" ]; then
  7270. print_usage dir2sfs
  7271. exit 1
  7272. fi
  7273.  
  7274. # if found, we will append it to the SFS filename
  7275. [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  7276.  
  7277. # get sfs name only, no extension or path
  7278. SFS_DIR="`basename "$1" .sfs`"
  7279.  
  7280. # if a valid dir
  7281. if [ -d "$SFS_DIR" ]; then
  7282. rm "${SFS_DIR}/"*pet*specs 2>/dev/null #240613
  7283. #start building the sfs file
  7284. echo "Please wait... building SFS file.."
  7285. local SFS_NAME="${SFS_DIR/$SFS_SUFFIX/}${SFS_SUFFIX}.sfs"
  7286. LANG=C mksquashfs "$SFS_DIR" "$SFS_NAME" -noappend &>/dev/null && SUCCESS="y" || SUCCESS=""
  7287. if [ -z "$SUCCESS" -a ! -f "${SFS_DIR}${SFS_SUFFIX}.sfs" ]; then
  7288. echo "Failed to create $SFS_NAME."
  7289. exit 1
  7290. fi
  7291. chmod 644 "$SFS_NAME" #shinobar
  7292. sync
  7293. #get size, and output msg
  7294. s=`LANG=C du -m "$SFS_NAME" | sed "s/\s.*//"`
  7295. MD5SUM=`md5sum "$SFS_NAME" | cut -f1 -d ' '`
  7296. echo -e "Created ${magenta}$SFS_NAME${endcolour} ( $s MB )"
  7297. echo -e "The md5 checksum: $MD5SUM"
  7298. else
  7299. echo "Cannot create SFS: '${SFS_DIR}' is not a directory."
  7300. exit 1
  7301. fi
  7302.  
  7303. # clean up
  7304. #rm -rf "${SFS_DIR}" &>/dev/null
  7305. #rm -f "${SFS}${SFS_SUFFIX}"*.sfs-md5.txt &>/dev/null
  7306. rm -f "${SFS}${SFS_SUFFIX}" &>/dev/null
  7307. }
  7308.  
  7309.  
  7310. dir2tgz(){ # requires $1 as valid dir FUNCLIST
  7311.  
  7312. [ ! -d "$1" ] && print_usage dir2tgz && exit 1
  7313.  
  7314. DIR="${1/.t*gz/}"
  7315.  
  7316. # remove trailing slash
  7317. DIRNAME="`echo -n $DIR | sed -e 's%/$%%'`"
  7318. DIRNAME="`basename ${DIRNAME}`" # get name only, no path
  7319.  
  7320. # make sure any pet specs are named correctly - this new tar file might later be converted to a .pet
  7321. echo "`ls -1 ${DIRNAME} | grep 'pet.specs'`" | while read LINE
  7322. do
  7323. mv "${DIRNAME}/$LINE" "${DIRNAME}/pet.specs" 2>/dev/null;
  7324. done
  7325.  
  7326. # create the tar file
  7327. ##echo "Adding directory to '${DIRNAME}.tar.gz'.."
  7328. tar -c -f "${DIRNAME}.tar" "${DIRNAME}/"
  7329. gzip "${DIRNAME}.tar"
  7330. sync
  7331.  
  7332. # print message
  7333. if [ -f "${DIRNAME}.tar.gz" ]; then
  7334. echo -e "Package ${magenta}${DIRNAME}.tar.gz${endcolour} created."
  7335. echo "The md5sum is: `md5sum ${DIRNAME}.tar.gz | cut -f1 -d' '`."
  7336. else
  7337. echo "Package '${DIRNAME}.tar.gz' NOT created."
  7338. return 1
  7339. fi
  7340. }
  7341.  
  7342.  
  7343. pet2sfs(){ # convert pet to sfs, $1 must be file or repo pkg FUNCLIST
  7344.  
  7345. # require valid option or quit
  7346. [ ! -f "$1" ] && print_usage pet2sfs && exit 1
  7347.  
  7348. pkg_ext=`get_pkg_ext "$1"`
  7349.  
  7350. [ "$pkg_ext" != pet ] && print_usage pet2sfs && exit 1
  7351.  
  7352. #110213,0.9.1 we want the file in $WORKDIR
  7353. #[ ! -f "${WORKDIR}/$(basename "$1" .pet).pet" ] && cp -f "${1/.pet/}.pet" "${WORKDIR}/$(basename "$1" .pet)" 2>/dev/null
  7354.  
  7355. PKGNAME="$(basename "$1" .pet)" #get pkg name only, no extension or path
  7356. PKGFILE="${CURDIR}/${PKGNAME}.pet" #the file to install
  7357.  
  7358. # determine the compression, extend test to 'XZ'
  7359. file -b "${PKGFILE}" | grep -i -q "^xz" && TAREXT=xz || TAREXT=gz
  7360. [ "$TAREXT" = 'xz' ] && taropts='-xJf' || taropts='-zxf'
  7361.  
  7362. pet2tgz "${PKGFILE}" 1>/dev/null
  7363.  
  7364. # now extract the files into $CURDIR/$PKGNAME/
  7365. tar $taropts "${PKGFILE//.pet/.tar.$TAREXT}" 2> $TMPDIR/$SELF-cp-errlog
  7366.  
  7367. # if DISTRO_VERSION found, the sfs will prob have a suffix
  7368. [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  7369.  
  7370. # remove the old one, if needed
  7371. rm "${PKGNAME}${SFS_SUFFIX}.sfs" 2>/dev/null
  7372.  
  7373. # create the new one
  7374. dir2sfs "${CURDIR}/${PKGNAME}" && rm -rf "${CURDIR}/${PKGNAME}"
  7375.  
  7376. # remove the .tar.$TAREXT file
  7377. rm -f "${PKGNAME}.tar.$TAREXT"
  7378.  
  7379. # if pkg put the pet in $CURDIR (not user), remove it
  7380. #[ -f "${PKGFILE}" -a "`dirname "$1"`" != "$CURDIR" ] && rm -f "${PKGFILE}" 2>/dev/null
  7381.  
  7382. # print message
  7383. if [ ! -f "${PKGNAME}.sfs" -a ! -f "${PKGNAME}${SFS_SUFFIX}.sfs" ]; then
  7384. echo "Package '${PKGNAME}.pet' not converted."
  7385. return 1
  7386. fi
  7387. }
  7388.  
  7389.  
  7390. pet2tgz(){ # convert to tar.gz, $1 must be valid file FUNCLIST
  7391.  
  7392. # if $1 is not a valid pkg name or a file that exists then exit..
  7393. [ ! -f "$1" ] && print_usage pet2tgz && exit 1
  7394.  
  7395. pkg_ext=`get_pkg_ext "$1"`
  7396. [ "$pkg_ext" != "pet" ] && print_usage pet2tgz && exit 1
  7397.  
  7398. PKGNAME="$(basename "$1" .pet)" # get pkg name only, no extension or path
  7399. PKGFILE="$1" # build the pkg file path
  7400.  
  7401. # backup the package, to restore it later
  7402. cp -f "$PKGFILE" "$TMPDIR/`basename $PKGFILE`.backup" 1>/dev/null
  7403.  
  7404. chmod +w "$PKGFILE" # make it writable.
  7405. FOOTERSIZE="32"
  7406.  
  7407. # determine the compression, extend test to 'XZ'
  7408. finfo=`file -b "$PKGFILE"`
  7409. case $finfo in
  7410. gz*|GZ*) EXT=gz ;;
  7411. xz*|XZ*) EXT=xz ;;
  7412. *) error "Unsupported compression type, or corrupted package." && exit 1 ;;
  7413. esac
  7414.  
  7415. # get the md5
  7416. MD5SUM="`tail -c $FOOTERSIZE \"$PKGFILE\"`"
  7417. NEWNAME="`echo -n \"$PKGFILE\" | sed -e "s/\\.pet$/\\.tar\\.$EXT/g"`" #131122
  7418. head -c -$FOOTERSIZE "$PKGFILE" > $NEWNAME
  7419. NEWMD5SUM="`md5sum \"$NEWNAME\" | cut -f 1 -d ' '`"
  7420. sync
  7421. [ ! "$MD5SUM" = "$NEWMD5SUM" ] && exit 1
  7422.  
  7423. # restore original pet pkg
  7424. [ -f "$TMPDIR/`basename $PKGFILE`.backup" ] && mv -f "$TMPDIR/`basename $PKGFILE`.backup" "$PKGFILE"
  7425.  
  7426. # print message
  7427. if [ -f "$NEWNAME" ]; then
  7428. echo -e "${green}Success${endcolour}: Package ${magenta}`basename ${NEWNAME}`${endcolour} created."
  7429. echo "The md5sum is `md5sum "$NEWNAME" | cut -f1 -d' '`."
  7430. else
  7431. error "Package ${PKGNAME}.pet not converted!"
  7432. return 1
  7433. fi
  7434. }
  7435.  
  7436.  
  7437. pet2txz(){ # calls pet2tgz FUNCLIST
  7438. pet2tgz "$1"
  7439. }
  7440.  
  7441.  
  7442. sfs2pet(){ # convert sfs to pet, requires $1 as a valid sfs FUNCLIST
  7443.  
  7444. # exit if no valid options
  7445. [ ! -f "$1" ] && print_usage sfs2pet && exit 1
  7446.  
  7447. # exit if user did not give an SFS file, or didnt give a file at all
  7448. [ "`file "$1" | grep Squashfs`" = '' ] && print_usage sfs2pet && exit 1
  7449.  
  7450. # we want the file in $CURDIR
  7451. #[ ! -f "${WORKDIR}/$(basename "${1}")" ] && cp -f "$1" "${WORKDIR}/$(basename "${1}")" 2>/dev/null
  7452.  
  7453. SFSNAME="$(basename "$1")"
  7454. SFSDIR="$(dirname "$1")"
  7455. SFSEXT="${SFSNAME##*.}"
  7456.  
  7457. # if DISTRO_VERSION found, the sfs will prob have a suffix
  7458. [ "$DISTRO_VERSION" != "" ] && SFS_SUFFIX="_${DISTRO_VERSION}" || SFS_SUFFIX=''
  7459.  
  7460. # create the name without path or extension (may include a $SUFFIX)
  7461. ROOTNAME=`basename "$SFSNAME" ".$SFSEXT"`
  7462.  
  7463. # build the file name we will work on
  7464. SFS="${SFSDIR}/${SFSNAME}"
  7465.  
  7466. if [ -f "$SFS" -a "$SFS" != "" ]; then
  7467.  
  7468. echo "Unsquashing $SFSNAME.. Please wait.."
  7469.  
  7470. # remove any older dirs, and unsquash
  7471. rm -rf "${CURDIR}/squashfs-root/"
  7472. LANG=C unsquashfs "$SFS" &>/dev/null
  7473.  
  7474. # lets remove the SFS suffix, to get back the the 'valid' PET name
  7475. ROOTNAME_NOSUFFIX=`echo "$ROOTNAME" | sed -e "s/$SFS_SUFFIX//"`
  7476.  
  7477. # create the folder we will package up
  7478. mv squashfs-root "${ROOTNAME_NOSUFFIX}/"
  7479.  
  7480. dir2tgz "${ROOTNAME_NOSUFFIX}" 1>/dev/null
  7481.  
  7482. tgz2pet "${ROOTNAME_NOSUFFIX}".tar.gz 1>/dev/null
  7483.  
  7484. # remove the dir and the tgz we just created
  7485. rm -rf "${ROOTNAME_NOSUFFIX}"
  7486. rm -f "${ROOTNAME_NOSUFFIX}".tar.gz
  7487.  
  7488. if [ -f "${ROOTNAME_NOSUFFIX}.pet" ]; then
  7489. echo -e "${green}Success${endcolour}: Package '${magenta}${ROOTNAME_NOSUFFIX}.pet${endcolour}' created."
  7490. echo "The md5sum is: `md5sum ${ROOTNAME_NOSUFFIX}.pet | cut -f1 -d' '`"
  7491. else
  7492. echo "Package '${ROOTNAME_NOSUFFIX}.pet' not converted."
  7493. return 1
  7494. fi
  7495. fi
  7496. }
  7497.  
  7498.  
  7499. tgz2pet(){ # convert $1 (a tar.gz or tgz) to .pet FUNCLIST
  7500.  
  7501. [ ! -f "$1" ] && print_usage tgz2pet && exit 1
  7502. sync
  7503. TARBALL="$1"
  7504. [ ! -f "$TARBALL" ] && echo "The archive '$TARBALL' could not be found." && exit 1
  7505.  
  7506. cp -f $TARBALL "$TMPDIR/`basename $TARBALL`.backup" 1>/dev/null
  7507.  
  7508. TARBALL="${CURDIR}/$(basename "${TARBALL}")"
  7509. chmod 644 "$TARBALL" #make it writable.
  7510. echo "Converting `basename ${TARBALL}`.."
  7511.  
  7512. #only accept .tgz or .tar.gz .tar.xz files...
  7513. EXT=''
  7514. case ${TARBALL} in
  7515. *.tar.gz) EXT='.tar.gz' ;;
  7516. *.tgz) EXT='.tgz' ;;
  7517. *.tar.xz) EXT='.tar.xz' ;;
  7518. *.txz) EXT='.txz' ;;
  7519. *) echo "${1##*/}: File extension not allowed" >&2 ; exit 1 ;;
  7520. esac
  7521. [ "$EXT" = "" ] && error "$TARBALL must be a .tgz, .tar.gz, .txz or .tar.xz file" && exit 1
  7522.  
  7523. #split TARBALL path/filename into components...
  7524. BASEPKG="`basename $TARBALL $EXT`"
  7525. DIRPKG="$CURDIR"
  7526. [ "$DIRPKG" = "/" ] && DIRPKG=""
  7527. case $EXT in
  7528. *gz)OPT=-z;;
  7529. *xz)OPT=-J;;
  7530. esac
  7531.  
  7532. # move pkg, update extensions (tgz -> .tar.gz, txz -> .tar.xz)
  7533. # make code later more readable
  7534. case $EXT in
  7535. *tgz)mv -f $TARBALL $DIRPKG/${BASEPKG}.tar.gz
  7536. TARBALL="$DIRPKG/${BASEPKG}.tar.gz"
  7537. EXT='.tar.gz';;
  7538. *txz)mv -f $TARBALL $DIRPKG/${BASEPKG}.tar.xz
  7539. TARBALL="$DIRPKG/${BASEPKG}.tar.xz"
  7540. EXT='.tar.xz';;
  7541. esac
  7542.  
  7543. # if tarball expands direct to '/' want to wrap around it (slackware pkg)... 100628 add -z ...
  7544. # man bad bug here... the thing isn't expanded! #131122
  7545. if [ "`tar ${OPT} --list -f ${TARBALL} | head -n 1`" = "./" ]; then
  7546. tar --one-top-level=${BASEPKG} -xf ${TARBALL}
  7547. tar --remove-files -c -f ${DIRPKG}/${BASEPKG}.tar ${BASEPKG}/
  7548. case $EXT in
  7549. *gz) gzip --force --best ${DIRPKG}/${BASEPKG}.tar ;;
  7550. *xz) xz --force -z -9 -e ${DIRPKG}/${BASEPKG}.tar ;;
  7551. esac
  7552. fi
  7553.  
  7554. FULLSIZE="`stat --format=%s ${TARBALL}`"
  7555. MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  7556. echo -n "$MD5SUM" >> $TARBALL
  7557. sync
  7558. mv -f $TARBALL $DIRPKG/${BASEPKG}.pet
  7559. sync
  7560.  
  7561. # restore original tar file
  7562. [ -f "$TMPDIR/`basename $TARBALL`.backup" ] && mv -f "$TMPDIR/`basename $TARBALL`.backup" "$TARBALL"
  7563.  
  7564. # print msg
  7565. if [ -f "${DIRPKG}/${BASEPKG}.pet" ]; then
  7566. echo -e "${green}Success:${endcolour} Created ${magenta}${BASEPKG}.pet${endcolour}."
  7567. echo "This is the md5sum: `md5sum ${DIRPKG}/${BASEPKG}.pet | cut -f1 -d' '`"
  7568. else
  7569. error "Could not convert ${DIRPKG}/${BASEPKG}.$EXT"
  7570. return 1
  7571. fi
  7572. }
  7573.  
  7574.  
  7575. txz2pet(){ # convert txz to pet, requires $1 as valid file FUNCLIST
  7576. [ ! -f "$1" ] && print_usage txz2pet && exit 1
  7577. FILE="$1" # full path, filename and extension
  7578. #keep old file, download it if needed
  7579. #[ -f "$(basename "$1" .txz)" ] || pkg_download "$(basename "$1" .txz)" # 200813 try to download it
  7580. # we want $FILE in $CURDIR
  7581. [ ! -f "${CURDIR}/$(basename "${FILE}")" ] && cp -f "$FILE" "${CURDIR}/$(basename "${FILE}")" 2>/dev/null
  7582. FILE="${CURDIR}/$(basename "${FILE}")"
  7583. #set vars
  7584. FILENAME="`basename "$FILE"`" # filename and extension only
  7585. BARENAME="${FILENAME/.t*xz/}" # filename, no extension..
  7586. PETFILE="${CURDIR}/${BARENAME}.pet" # the full path and filename of the pet file
  7587. PETNAME="`basename "$PETFILE"`" # the filename of the pet file
  7588. # create the pet directory, if needed
  7589. mkdir -p "${CURDIR}/${BARENAME}"
  7590. [ ! -d "${CURDIR}/${BARENAME}" ] && { echo "PET directory not created or found."; exit 1; }
  7591. # unpack the file
  7592. [ -f "$FILENAME" ] && tar -Jxvf "$FILENAME" -C "${BARENAME}/" 1>/dev/null || echo "Cannot untar $FILENAME"
  7593. # create the pet file
  7594. dir2pet "$BARENAME" || echo "PET working directory not found"
  7595.  
  7596. if [ -f "$PETFILE" ]; then # if pet file was created
  7597. # remove the pet file working directory
  7598. rm -R "${CURDIR}/${BARENAME}/" 2>/dev/null
  7599. rmdir "${CURDIR}/${BARENAME}/" 2>/dev/null
  7600. # report the file was created #nope, no need, dir2pet will do it
  7601. #echo "Package '$PETNAME' created successfully."
  7602. else
  7603. echo "Package "$PETFILE" file not created"
  7604. return 1
  7605. fi
  7606. # delete the original txz file
  7607. rm -f "$FILE" &>/dev/null
  7608. }
  7609.  
  7610.  
  7611. # other
  7612.  
  7613. menu_entry_msg(){ # show menu entry details of installed pkg FUNCLIST
  7614.  
  7615. # exit if not valid usage
  7616. [ ! "$1" -o "$1" = "-" ] && exit 1
  7617.  
  7618. . ${PKGRC}
  7619.  
  7620. local MENUFILE=''
  7621. local pkg_file_list=''
  7622. local no_display=''
  7623. local terminal_only=''
  7624. local pkg_command=''
  7625.  
  7626. # get the menu file, if it exists
  7627. pkg_file_list=$(find "$PACKAGE_FILE_LIST_DIR" -maxdepth 1 -type f -name "${1}*.files")
  7628.  
  7629. [ -f "$pkg_file_list" ] && MENUFILE="`LANG=C grep -m1 '/usr/share/applications/' "$pkg_file_list" | grep -i -m1 ".desktop\$"`" || return 1
  7630.  
  7631. # if pkg has a .desktop file
  7632. if [ -f "$MENUFILE" ]; then
  7633.  
  7634. # exit if the menu item is set to NoDisplay
  7635. no_display="`grep -m1 ^NoDisplay=true "$MENUFILE" 2>/dev/null`"
  7636. terminal_only="`grep -m1 ^Terminal=true "$MENUFILE" 2>/dev/null`"
  7637.  
  7638. # fix menu entries
  7639. sed -i 's/ %u//g' "$MENUFILE"
  7640. sed -i 's/ %U//g' "$MENUFILE"
  7641. sed -i 's/ %f//g' "$MENUFILE"
  7642. sed -i 's/ %F//g' "$MENUFILE"
  7643. sed -i 's/ %d//g' "$MENUFILE"
  7644. sed -i 's/ %D//g' "$MENUFILE"
  7645.  
  7646. update_menus &
  7647.  
  7648. # get the details for a final msg
  7649. MENU_CAT="`LANG=C grep -m1 "^Categories=" $MENUFILE 2>/dev/null | cut -f2 -d'=' | sed -e 's/\(.*\);/\1/g' -e 's/.*;//g' | head -1`"
  7650. APATTERN="[ ,]${MENU_CAT}" #MHHP
  7651. TOPMENU="`LANG=C grep -m1 "${APATTERN}" /etc/xdg/menus/hierarchy | cut -f1 -d' ' | head -1`"
  7652. if [ "$TOPMENU" = "" ]; then
  7653. APATTERN="[ ,]${MENU_CAT};"
  7654. TOPMENU="`LANG=C grep -m1 "${APATTERN}" /etc/xdg/menus/hierarchy | cut -f1 -d' ' | head -1`"
  7655. fi
  7656. MENU_NAME="`LANG=C grep -m1 "^Name=" $MENUFILE | cut -f2 -d'=' | head -1`"
  7657.  
  7658. [ "$TOPMENU" = '' ] && TOPMENU="$MENU_CAT"
  7659.  
  7660. # replace the Categories= line with one which has only the top, main category..
  7661. # .. this should prevent duplicate menu entries
  7662. #cat "$MENUFILE" | grep -v ^Categories > ${TMPDIR}/fixed.desktop
  7663. #echo "Categories=${TOPMENU};" >> ${TMPDIR}/fixed.desktop
  7664. #mv ${TMPDIR}/fixed.desktop $MENUFILE
  7665.  
  7666. # print msg
  7667. if [ "$no_display" != "" -o "$terminal_only" != '' ]; then
  7668. pkg_command="`grep -m1 ^Exec= "$MENUFILE" | cut -f2 -d'='`"
  7669. [ "$pkg_command" != '' ] && echo -e "To run, type: ${bold}${pkg_command}${endcolour}"
  7670. else
  7671. echo -e "Menu entry: ${lightblue}${TOPMENU:-[None]}${endcolour} -> ${lightblue}${MENU_NAME:-[None]}${endcolour}"
  7672. fi
  7673.  
  7674. return 0
  7675. fi
  7676. return 1
  7677. }
  7678.  
  7679.  
  7680. update_menus() { # update menus, calls fixmenus, refreshes WM
  7681. echo started > /tmp/pkg/update_menus_busy
  7682. fixmenus &>/dev/null
  7683. # refresh JWM menus if using JWM window manager
  7684. [ "`which jwm`" != "" -a "`ps -e | grep jwm`" != "" ] && jwm -reload &>/dev/null
  7685. rm /tmp/pkg/update_menus_busy 2>/dev/null
  7686. return 0
  7687. }
  7688.  
  7689.  
  7690. check_net(){ # check net connection (before downloading) FUNCLIST
  7691. [ -f $TMPDIR/internetsuccess ] && echo 0 && exit 0 #220613
  7692. [ ! "$1" -o "$1" = "-" ] && URL="8.8.8.8" || URL="`echo ${1} | awk -F/ '{print $3}'`"
  7693. LANG=C ping -4 -c1 -q "$URL" &>/dev/null #220613
  7694. REPLY=$?
  7695. [ $REPLY -eq 0 ] && echo -n "ok" > $TMPDIR/internetsuccess #220613
  7696. echo 0
  7697. }
  7698.  
  7699.  
  7700. get_stdin(){ # read from stdin (when - is last option) FUNCLIST
  7701. read -t 0.1 STDINVAR
  7702. }
  7703.  
  7704.  
  7705. not_found(){ # list alternative packages when no match in repos FUNCLIST
  7706. PKGNAME="${1/.pet/}"
  7707. #echo "$APPTITLE"
  7708. #echo "Package '${PKGNAME}' not found in current repo.. "
  7709. if [ "$(ls "${WORKDIR}/"| grep "${PKGNAME}")" != "" ]; then
  7710. [ "`list_downloaded_pkgs "${PKGNAME}"`" != "" ] && echo "These downloaded packages match your search:
  7711. `list_downloaded_pkgs "${PKGNAME}"`"
  7712. fi
  7713. [ "`$PKGSEARCH "${PKGNAME}"`" != "" ] && echo "These packages in the repos match your search:
  7714. `$PKGSEARCH "${PKGNAME}"`"
  7715. return 1
  7716. }
  7717.  
  7718.  
  7719. first_run (){ # welome message on first run
  7720.  
  7721. # quit if not the first run
  7722. [ ! -f ~/.pkg/firstrun ] && return 0
  7723. # print msg
  7724. echo '============================================================'
  7725. echo -e " ${bold}$APPNAME $APPVER${endcolour} - a command-line package manager"
  7726. echo '============================================================'
  7727. echo
  7728. echo " pkg repo-update # update the contents of each installed repo"
  7729. echo " pkg repo-list # list all available repos"
  7730. echo " pkg repo <name> # change to the chosen repo"
  7731. echo " pkg show-config # show current Pkg settings"
  7732. echo " pkg workdir <DIR> # change where to keep downloaded packages"
  7733. echo
  7734. echo " pkg search <term> # search all fields in the current repo"
  7735. echo " pkg names <pkgname> # search package names in the current repo"
  7736. echo " pkg status <pkgname> # print info about the given package"
  7737. echo " pkg add <pkgname> # install & download packages and dependencies"
  7738. echo
  7739. echo " You can run the commands below to learn more about Pkg:"
  7740. echo
  7741. echo " pkg help # help info, all options and some tips"
  7742. echo " pkg help-all # full help info, including advanced usage"
  7743. echo " pkg usage [cmd] # show every command, or info on the given one"
  7744. echo " pkg examples # show lots more example Pkg commands"
  7745. echo
  7746. echo " HINT: Use TAB to auto-complete package and repo names (and more).."
  7747. echo
  7748. echo '============================================================'
  7749.  
  7750. # get the right list of repos
  7751. update_sources &>/dev/null &
  7752.  
  7753. # delete first run flag
  7754. rm -f ~/.pkg/firstrun 2>/dev/null
  7755.  
  7756. # delete other tmp stuff, make it like a first run
  7757. rm $TMPDIR/func_list &>/dev/null
  7758. rm $TMPDIR/curr_repo_url &>/dev/null
  7759. rm $TMPDIR/internetsuccess &>/dev/null
  7760. rm $TMPDIR/pkg_aliases &>/dev/null
  7761. rm $TMPDIR/pkglist &>/dev/null
  7762. rm $TMPDIR/pkglist_* &>/dev/null
  7763. rm $TMPDIR/USRPKGLIST &>/dev/null
  7764. rm $TMPDIR/PKGSDONE &>/dev/null
  7765. rm $TMPDIR/deps_installed &>/dev/null
  7766. rm $TMPDIR/deps_missing &>/dev/null
  7767. rm $TMPDIR/$SELF-cp-errlog &>/dev/null
  7768. rm $TMPDIR/*-MISSING.txt &>/dev/null
  7769.  
  7770. exit 0
  7771. }
  7772.  
  7773.  
  7774. #==================== main functions ======================#
  7775.  
  7776.  
  7777.  
  7778. #===================== final checks =======================#
  7779.  
  7780. # try to set a default repo if none was found
  7781. if [ ! -f "$REPO_DB_FILE_DIR/$REPOFILE" -o ! -f "$HOME/.pkg/sources" ]; then
  7782.  
  7783. mkdir -p $HOME/.pkg 2>/dev/null
  7784. mkdir -p $PKGS_DIR 2>/dev/null
  7785. [ ! -f "$HOME/.pkg/sources" ] && touch $HOME/.pkg/sources
  7786. # try to get repo file from /root if it exists
  7787. if [ -f "$REPO_DB_FILE_DIR/Packages-puppy-noarch-official" ]; then
  7788. # copy any available Puppy repo files in root to $PKGS_DIR
  7789. mv "$REPO_DB_FILE_DIR"/Packages-puppy-* $REPO_DB_FILE_DIR/
  7790. fi
  7791.  
  7792. ## if repo file was NOT added to home dir, fata error, exit
  7793. #if [ ! -f $PKGS_DIR/Packages-puppy-noarch-official ]; then
  7794. # error "Repo files not found. Check ${magenta}$PKGS_DIR${endcolour}"
  7795. # exit 1
  7796. #fi
  7797.  
  7798. # if we got here, the noarch repo file is in $PKGS_DIR, lets use it as the default/only repo
  7799. echo -e "${yellow}Warning:${endcolour} No repo files found. Setting the default repo to 'noarch'."
  7800. update_sources 1>/dev/null
  7801. set_current_repo noarch 1>/dev/null
  7802. # if repos added ok
  7803. if [ $? -eq 0 ]; then
  7804. echo -e "${green}Success:${endcolour} 'noarch' added."
  7805. echo "Re-running: $SELF $@"
  7806. echo
  7807. $SELF $@
  7808. exit 0
  7809. fi
  7810.  
  7811. fi
  7812.  
  7813. # create the user-installed pkgs file if it doesnt exists
  7814. [ ! -f $PKGS_DIR/user-installed-packages ] && touch $PKGS_DIR/user-installed-packages
  7815.  
  7816. first_run
  7817.  
  7818.  
  7819. #===================== final checks =======================#
  7820.  
  7821.  
  7822.  
  7823. #==================== main interface ======================#
  7824.  
  7825.  
  7826. while [ $# != 0 ]; do # get all options ($# means all options)
  7827. I=1
  7828. while [ ! -z $# -a $I -le `echo $# | wc -c` ]; do
  7829.  
  7830. # accept from stdin, (using dash (-) as final option)
  7831. for x in "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
  7832. do
  7833. case "$x" in
  7834. -)
  7835. while true; do
  7836. read ALINE
  7837. [ "$ALINE" ] || break
  7838. [ "$(echo $ALINE| cut -b1)" = '#' ] && continue # skip comment
  7839. [ "$ALINE" = ':' ] && continue # skip colon
  7840. if [ "$ALINE" = "- " -o "$ALINE" = " -" -o "$ALINE" != "-" ]; then
  7841. OPTS="${@%-}" #get all opts, without last dash
  7842. OPTS="${OPTS% }" #get all opts, strip last space
  7843. $SELF $OPTS "$ALINE"
  7844. fi
  7845. done
  7846. break
  7847. ;;
  7848. --ask|-a) ASK=true ; QTAG="? (y/N)";;
  7849. --quiet|-q) QUIET=true ;;
  7850. --force|-f) FORCE=true ;;
  7851. --no-color) green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7852. --no-colour|-nc) green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7853. '--configure='*) PKG_CONFIGURE="$(echo "$x" | sed -e 's/^--configure=//')" ;;
  7854. '--cflags='*) PKG_CFLAGS="$(echo "$x" | sed -e 's/^--cflags=//')" ;;
  7855. esac
  7856. done
  7857.  
  7858. # enable passing multiple pkgs separated by comma, space,
  7859. # works with or without double quotes around pkgs
  7860. opt="`shift; echo "$@"`"
  7861. opt="${opt//,/ }"
  7862. opt="${opt//|/ }"
  7863. # only keep params up to the next option
  7864. opt="${opt// -*/}"
  7865.  
  7866. ## main options
  7867. case $1 in
  7868.  
  7869. -) # accept from stdin, pkg -i (defaults to pkg add $1 or pkg -u $1)
  7870. if [ "$2" = "" ]; then
  7871. while true; do
  7872. read ALINE
  7873. [ "$ALINE" -a "$ALINE" != '-' ] || break
  7874. [ "$(echo $ALINE| cut -b1)" = '#' ] && continue # skip comment
  7875. ALINE=`echo $ALINE` #strip spaces
  7876. if [ "$ALINE" != "-" -a "`$PKGSEARCH "$ALINE"`" != "" ]; then
  7877. [ "`is_installed_pkg $ALINE`" = false ] && pkg_get "$ALINE" || \
  7878. pkg_uninstall "$ALINE"
  7879. fi
  7880. done
  7881. shift
  7882. fi
  7883. ;;
  7884.  
  7885. --ask|-a) ASK=true ; QTAG="? (y/N)";;
  7886. --quiet|-q) QUIET=true ;;
  7887. --force|-f) FORCE=true ;;
  7888. --no-color) green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7889. --no-colour|-nc) green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour='' ;;
  7890. '--configure='*) PKG_CONFIGURE="$(echo "$1" | sed -e 's/^--configure=//')" ;;
  7891. '--cflags='*) PKG_CFLAGS="$(echo "$1" | sed -e 's/^--cflags=//')" ;;
  7892.  
  7893. # package search
  7894. --all-pkgs|--all) [ ! "$2" ] && cat "$REPO_DB_FILE_DIR/${REPOFILE}" || cat "$REPO_DB_FILE_DIR/${REPOFILE}" | grep "$2"; exit 0;;
  7895. --search|-s|search|s) [ ! "$2" ] && search_pkgs || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_pkgs "$x"; done; ;;
  7896. -ss) [ ! "$2" ] && search_fast || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_fast "$x"; done; ;;
  7897. --search-all|-sa|search-all|sa) [ ! "$2" ] && search_all_pkgs || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_all_pkgs "$x"; done; ;;
  7898. -ssa|ssa) [ ! "$2" ] && search_all_fast || for x in "$opt"; do [ "$x" -a "$x" != "-" ] && search_all_fast "$x"; done; ;;
  7899. --names|-n|names|n) [ ! "$2" ] && list_pkg_names || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_pkg_names "$x"; done; ;;
  7900. --names-exact|-ne|names-exact|ne) [ ! "$2" ] && list_pkg_names || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_pkg_names "$x\$"; done; ;;
  7901. --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; ;;
  7902. --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 ;;
  7903. --list-downloaded|list-downloaded|-ld|ld) [ ! "$2" ] && list_downloaded_pkgs || list_downloaded_pkgs "$2"; exit 0 ;;
  7904. -LI|LI) [ ! "$2" ] && HIDE_BUILTINS=false list_installed_pkgs || HIDE_BUILTINS=false list_installed_pkgs "$2"; exit 0 ;; # list all installed pkgs inc builtins
  7905. --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 ;;
  7906.  
  7907. # get, download, install, remove, pkgs
  7908. --download|-d|download|d)
  7909. AUTOCLEAN_override='no'
  7910. [ ! "$2" ] && pkg_download || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_download "$x"; done;;
  7911. --install|-i|install|i) [ ! "$2" ] && pkg_install || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_install "$x"; done;;
  7912. --uninstall|-u|uninstall|u) [ ! "$2" ] && pkg_uninstall|| for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_uninstall "$x"; done;;
  7913. --remove|-rm|remove|rm) [ ! "$2" ] && pkg_remove || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_remove "$x"; done;;
  7914. --unpack|--extract|unpack|extract)[ ! "$2" ] && pkg_unpack || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_unpack "$x"; done;;
  7915. --clean|clean) [ ! "$2" ] && clean_pkgs || for x in $opt; do [ "$x" -a "$x" != "-" ] && clean_pkgs "$x"; done;;
  7916. --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 ;;
  7917. --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 ;;
  7918. --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
  7919. --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;;
  7920. --install-all|-ia) list_downloaded_pkgs | while read pkg; do [ "$pkg" -a "$pkg" != "-" ] && pkg_install "$pkg"; done;;
  7921. --uninstall-all|-ua) list_installed_pkgs | while read pkg; do [ "$pkg" -a "$pkg" != "-" ] && pkg_uninstall "$pkg"; done;;
  7922.  
  7923. # pkg status, info
  7924. --pkg-installed|-pi|installed|pi) [ ! "$2" ] && is_installed_pkg || for x in $opt; do [ "$x" -a "$x" != "-" ] && is_installed_pkg "$x"; done;;
  7925. --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
  7926. --pkg-status|-ps|status|ps) [ ! "$2" ] && pkg_status || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_status "$x"; done;;
  7927. --contents|-c|contents|c) [ ! "$2" ] && pkg_contents|| for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_contents "$x" 2>/dev/null; done;;
  7928. --which|-w|which|w) [ ! "$2" ] && which_pkg || for x in $opt; do [ "$x" -a "$x" != "-" ] && which_pkg "$x"; done;;
  7929. --which-repo|-wr|which-repo|wr) [ ! "$2" ] && which_repo || for x in $opt; do [ "$x" -a "$x" != "-" ] && which_repo "$x"; done;;
  7930. --pkg-repack|-pr|repack|pr) [ ! "$2" ] && pkg_repack || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_repack "$x"; done;;
  7931. --pkg-update|-pu|update|pu) [ ! "$2" ] && pkg_update || for x in $opt; do [ "$x" -a "$x" != "-" ] && pkg_update "$x"; done;;
  7932. --pkg-combine|-pc|pkg-combine|pc) [ ! "$2" ] && pkg_combine || for x in $opt; do [ "$x" -a "$x" != "-" ] && COMBINE2SFS=false pkg_combine "$x"; done;;
  7933. --pkg-split|split) [ ! "$2" ] && split_pkg || for x in $opt; do [ "$x" -a "$x" != "-" ] && split_pkg "$x"; done;;
  7934. --pkg-merge|merge) [ ! "$2" ] && merge_pkg || merge_pkg "$2" "$3"; exit 0;;
  7935. --sfs-combine|-sc|sfs-combine|sc) [ ! "$2" ] && pkg_combine || for x in $opt; do [ "$x" -a "$x" != "-" ] && COMBINE2SFS=true pkg_combine "$x"; done;;
  7936. -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
  7937.  
  7938. # pkg compiling
  7939. --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;;
  7940. --pkg-build-list|-pbl|build-list|pbl) [ ! "$2" ] && list_build_scripts || for x in $opt; do [ "$x" -a "$x" != "-" ] && list_build_scripts "$x"; done;;
  7941.  
  7942. # dependencies
  7943. --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
  7944. --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
  7945. --deps|-e|deps|e) [ ! "$2" ] && get_deps; for x in $opt; do [ "$x" -a "$x" != "-" ] && get_deps "$x"; done ;;
  7946. --deps-download|-ed|deps-download|ed) [ ! "$2" ] && get_deps; for x in $opt; do [ "$x" -a "$x" != "-" ] && NO_INSTALL=true get_deps "$x"; done ;;
  7947. --has-deps|-he|has-deps|he) [ ! "$2" ] && has_deps; for x in $opt; do [ "$x" -a "$x" != "-" ] && has_deps "$x"; done ;;
  7948. --deps-all|-ea|deps-all|ea) [ ! "$2" ] && get_deps; [ "$2" != "-" ] && NO_INSTALL=false get_all_deps "$2" ;;
  7949. --deps-check|-ec|deps-check|ec|ldd) [ ! "$2" ] && print_usage deps-check || pkg_ldd_msg "$2" ;;
  7950. -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
  7951.  
  7952. # repo
  7953. --repo|-r|repo|r) [ ! "$2" ] && echo $REPONAME || set_current_repo "$2" ;;
  7954. --repo-convert|-rc|repo-convert|rc) [ ! "$2" ] && print_usage repo-convert || for x in $opt; do [ "$x" -a "$x" != "-" ] && convert_repofile "$x"; done ;;
  7955. --repo-list|-rl|repo-list|rl) [ "$2" != "-" ] && repo_list "$2" ;;
  7956. --repo-info|-ri|repo-info|ri) [ "$2" != "-" ] && print_repo_info "$2";;
  7957. --repo-file-list|-rfl|repo-file-list|rfl) [ "$2" != "-" ] && repo_file_list "$2" ;;
  7958. --repo-update|-ru|repo-update|ru) update_repo "$2";;
  7959. --add-source|add-source) [ "`echo $2|grep '|'`" = '' -o "$2" = '-' ] && print_usage add-source || add_source "$2";;
  7960. --add-repo|add-repo) [ ! "$2" -o "$2" = '-' ] && print_usage add-repo || shift; add_repo "$@"; exit 0;;
  7961. --rm-repo|rm-repo) [ ! "$2" -o "$2" = '-' ] && print_usage rm-repo || rm_repo "$2"; exit 0;;
  7962. --update-sources|update-sources) update_sources ;;
  7963.  
  7964. # set repo settings
  7965. --repo-pkg-scope|-rps|rps|repo-pkg-scope) if [ "$2" -a "$2" != "-" ]; then set_pkg_scope "$2"; else echo "$PKGSCOPE"; fi; exit 0;;
  7966. --repo-dep-scope|-rds|repo-dep-scope|rds) if [ "$2" -a "$2" != "-" ]; then set_dep_scope "$2"; else echo "$DEPSCOPE"; fi; exit 0;;
  7967. --bleeding-edge|-be|bleeding-edge|be) if [ "$2" -a "$2" != "-" ]; then set_bleeding_edge "$2"; else echo "$BLEDGE"; fi; exit 0;;
  7968. --rdep-check|-rdc|rdep-check|rdc) if [ "$2" -a "$2" != "-" ]; then set_recursive_deps "$2"; else echo "$RDCHECK"; fi; exit 0;;
  7969.  
  7970. # convert
  7971. --deb2pet|deb2pet) [ ! "$2" ] && deb2pet || for x in $opt; do deb2pet "$x"; done ;;
  7972. --dir2pet|dir2pet) [ ! "$2" ] && dir2pet || for x in $opt; do dir2pet "$x"; done ;;
  7973. --dir2sfs|dir2sfs) [ ! "$2" ] && dir2sfs || for x in $opt; do dir2sfs "$x"; done ;;
  7974. --dir2tgz|dir2tgz) [ ! "$2" ] && dir2tgz || for x in $opt; do dir2tgz "$x"; done ;;
  7975. --pet2sfs|pet2sfs) [ ! "$2" ] && pet2sfs || for x in $opt; do pet2sfs "$x"; done ;;
  7976. --pet2tgz|pet2tgz) [ ! "$2" ] && pet2tgz || for x in $opt; do pet2tgz "$x"; done ;;
  7977. --pet2txz|pet2txz) [ ! "$2" ] && pet2txz || for x in $opt; do pet2txz "$x"; done ;;
  7978. --sfs2pet|sfs2pet) [ ! "$2" ] && sfs2pet || for x in $opt; do sfs2pet "$x"; done ;;
  7979. --tgz2pet|tgz2pet) [ ! "$2" ] && tgz2pet || for x in $opt; do tgz2pet "$x"; done ;;
  7980. --txz2pet|txz2pet) [ ! "$2" ] && txz2pet || for x in $opt; do txz2pet "$x"; done ;;
  7981. --dir2repo|dir2repo) [ ! "$2" ] && dir2repo|| for x in $opt; do dir2repo "$x"; done ;;
  7982.  
  7983. # other
  7984. --func-list|func-list) [ -f $TMPDIR/func_list ] && cat $TMPDIR/func_list || func_list; exit 0;;
  7985. --workdir|workdir) [ "$2" != "-" ] && set_workdir "$2"; exit $?;;
  7986. --autoclean|autoclean) [ "$2" = "yes" -o "$2" = "no" ] && set_autoclean "$2" || { echo "$AUTOCLEAN"; exit 1; } ;;
  7987.  
  7988. # usage, help funcs, version info, etc
  7989. --welcome|welcome) touch $HOME/.pkg/firstrun; first_run; exit 0;;
  7990. --show-config|show-config) show_config; exit 0;;
  7991. --version|-v|version|v) echo "$APPNAME $APPVER"; exit 0;;
  7992. --usage|usage) print_usage "$2"; exit 0;;
  7993.  
  7994. --examples|-ex|examples|ex)
  7995. . /usr/share/pkg/docs/examples.txt;
  7996. echo -e "$EXAMPLES\n"
  7997. exit 0
  7998. ;;
  7999. --help-all|-H|help-all|H)
  8000. . /usr/share/pkg/docs/env_vars.txt
  8001. . /usr/share/pkg/docs/help.txt
  8002. . /usr/share/pkg/docs/examples.txt
  8003. . /usr/share/pkg/docs/help-all.txt
  8004. echo -e "$HELP_ALL\n\n" | less -R
  8005. exit 0
  8006. ;;
  8007.  
  8008. --help|-h|help|h)
  8009. . /usr/share/pkg/docs/env_vars.txt
  8010. . /usr/share/pkg/docs/help.txt
  8011. echo -e "$HELP\n"
  8012. exit 0
  8013. ;;
  8014.  
  8015. # any other options
  8016. -?*|--?*)
  8017. # exit if bad options
  8018. echo "Unknown option '$1'" && exit 1
  8019. ;;
  8020.  
  8021. ?*)
  8022. # all other options .. might be an internal func, if so, execute it with all given options
  8023. [ "`func_list | tr '\t' ' ' | cut -f2 -d' ' | grep -m1 "^${1}"'()'`" != '' ] && "$@" && exit 0
  8024. ;;
  8025.  
  8026. esac
  8027.  
  8028. shift
  8029. I=$(($I + 1))
  8030. done
  8031. done
  8032.  
  8033.  
  8034.  
  8035. #==================== main interface ======================#
  8036. code=$?
  8037. [ ! -z "$AUTOCLEAN_override" ] && AUTOCLEAN="$AUTOCLEAN_override"
  8038. # if AUTOCLEAN=true silently delete all pkgs in WORKDIR that are already installed
  8039. if [ "$AUTOCLEAN" = 'yes' -a "`HIDE_BUILTINS=true list_installed_pkgs`" != '' ]; then
  8040. clean_pkgs &>/dev/null
  8041. fi
  8042.  
  8043.  
  8044.  
  8045. # remove tmp dir used by pkg_get and get_deps
  8046. rm $TMPDIR/PKGSDONE 2>/dev/null
  8047.  
  8048. # reset lang options as we found them
  8049. LANG=$USER_LANG
  8050. LC_ALL=$USER_LC_ALL
  8051.  
  8052. exit $code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement