SHARE
TWEET

pkg-list-aliases_old2

s243a Sep 20th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. #==================  setup script vars  =====================#
  4.  
  5. APPNAME="Pkg"
  6. APPVER="1.9.22"
  7. APPTITLE="$APPNAME $APPVER"
  8. 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.
  9. dep_id=0 #
  10. # get current locale settings
  11. USER_LANG=$LANG
  12. USER_LC_ALL=$LC_ALL
  13.  
  14. SELF=$(basename $0)        # this script
  15. QTAG=''                    # gets set to (y/n) if ASK=-true
  16. LANG=C                     # speed up
  17. LC_ALL=C                   # speed up
  18. EDITOR=${EDITOR:-vi}       # just in case
  19. PAGER=${PAGER:-less}       # just in case
  20. CURDIR="${PWD}"            # get current dir, before cd to WORKDIR
  21. whoami=$(whoami)           # s243a copied from below. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
  22. TMPDIR=/tmp/pkg/${whoami}  # set the tmp dir
  23.  
  24. # set colours true by default
  25. green="\e[32m"; red="\e[91m"; magenta="\e[95m"; lightblue="\e[36m"; yellow="\e[93m"; bold="\e[1m"; endcolour="\e[0m"
  26.  
  27. # ENVIRONMENT VARS, which may be overridden later
  28. [ -z "$PKGRC" ] && export PKGRC=${HOME}/.pkg/pkgrc      # config file for this script
  29. [ -z "$ASK"   ] && ASK=false                            # if true, ask user before doing stuff. Overridden by --ask
  30. [ -z "$QUIET" ] && QUIET=false                          # if true, hide output that doesnt log well in Xdialog, Gtkdialog, etc
  31. [ -z "$FORCE" ] && FORCE=false                          # if true, force (re)install/remove pkgs. Overridden by --force
  32. [ -z "$HIDE_INSTALLED" ] && export HIDE_INSTALLED=false # if true, hide installed pkgs from pkg searches (-n, -na, -ss, -ssa)
  33. [ -z "$HIDE_BUILTINS"  ] && export HIDE_BUILTINS=true   # if true, remove builtins pkgs from dep lists, dont download/install them
  34. [ -z "$HIDE_USER_PKGS" ] && export HIDE_USER_PKGS=true  # if true, hide user installed pkgs from dep lists, dont download/install them
  35. [ -z "$NO_ALIASES"     ] && export NO_ALIASES=false     # if true, skip searching pkg alias names for pkg alternatives
  36. [ -z "$NO_INSTALL"     ] && export NO_INSTALL=false     # if true, skip installing of pkgs
  37. [ -z "$PKG_NO_COLOURS" ] && export PKG_NO_COLOURS=false # if true, disable coloured output or not
  38. [ -z "$PKG_CONFIGURE"  ] && export PKG_CONFIGURE=''     # reset
  39. [ -z "$PKG_CFLAGS"     ] && export PKG_CFLAGS=''        # reset
  40.  
  41. [ -z "$PKGS_DIR" ] && export PKGS_DIR="$(realpath "${HOME}/.packages")"
  42. #These are files of the form
  43. #[ -z "$PET_SPEC_DIR_ROOT" ] && PET_SPEC_DIR_ROOT="$PKGS_DIR"
  44. if [ -z "$REPO_DB_FILE_DIR" ]; then
  45.   if [ -d "$PKGS_DIR/repo" ]; then #This imples mistfires ppm3 is installed
  46.     export REPO_DB_FILE_DIR="$(realpath "$PKGS_DIR/repo")"
  47.   else
  48.     export REPO_DB_FILE_DIR="$PKGS_DIR"
  49.   fi
  50. fi
  51. if [ -z "$PACKAGE_FILE_LIST_DIR" ]; then
  52.   if [ -d "$PKGS_DIR/package-files" ]; then #This imples mistfires ppm3 is installed
  53.     export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR/package-files")"
  54.   else
  55.     export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR")"
  56.   fi
  57. fi
  58. [ -z "$BUILTIN_FILE_LIST_DIR" ] && BUILTIN_FILE_LIST_DIR="$PKGS_DIR/builtin_files"
  59. #[ -z "$PET_SPEC_DIR_BUILTIN" ] && PET_SPEC_DIR_BUILTIN=\
  60. #  "$(realpath "$PKGS_DIR/builtin_files")"
  61. #
  62. #[ -z "$PET_SPEC_DIR_USR_INST" ] && PET_SPEC_DIR_USR_INST="$PKGS_DIR"
  63.  
  64.  
  65. #mk_spec_file_list_arry(){
  66.  [declare -p $SPEC_DB_PATHS ] || declare -ga SPEC_DB_PATHS=()
  67.  #Can't put the loop in the loop in a pipeline if you want to assign array values:
  68.  #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop  
  69.  #find / -wholename "$PKGS_DIR"/'*-installed-packages' |
  70.  while read SPEC_FILE; do
  71.    bname="`basename "$SPEC_FILE"`"
  72.    case "$bname" in #Consider lowering case
  73.    "layers-installed-packages")
  74.      #Do Nothing
  75.      export LAYER_INST_PKGS_FILE="$SPEC_FILE" ;;
  76.    "woof-installed-packages")
  77.      export WOOF_INST_PKGS_FILE="$SPEC_FILE" ;;
  78.    "user-installed-packages")
  79.      export USER_INST_PKGS_FILE="$SPEC_FILE" ;;
  80.    "devx-only-installed-packages")
  81.      export DEVX_INST_PKGS_FILE="$SPEC_FILE" ;;    
  82.    *)
  83.      SPEC_DB_PATHS+=( "$SPEC_FILE" ) ;;
  84.    esac
  85.    #s243a: We don't need realpath for the next four vars but it will provide usefull debugging information.
  86.    #s243a: TODO search for the following files if they don't exist.
  87.    [ -z "$USER_INST_PKGS_FILE" ] && \
  88.      USER_INST_PKGS_FILE="$PKGS_DIR/user-installed-packages"
  89.    [ -z "$WOOF_INST_PKGS_FILE" ] && \
  90.      WOOF_INST_PKGS_FILE="$PKGS_DIR/woof-installed-packages"
  91.    [ -z "$LAYER_INST_PKGS_FILE" ] && \
  92.      LAYER_INST_PKGS_FILE="$PKGS_DIR/layers-installed packages"
  93.    [ -z "$DEVX_INST_PKGS_FILE" ] && \
  94.      DEVX_INST_PKGS_FILE="$PKGS_DIR/devx-only-installed-packages"
  95.    SPEC_DB_PATHS=( "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${SPEC_DB_PATHS[@]}" )
  96.  done < <( find "$PKGS_DIR" -name '*-installed-packages' )
  97. #}  
  98. #mk_spec_file_list_arry
  99. #echo "SPEC_DB_PATHS=${SPEC_DB_PATHS[@]}"
  100.  
  101. #mk_all_repo_file_list_arry(){
  102.  declare -gA ALL_REPO_DB_PATHS=()
  103.  #ALL_REPO_DB_PATHS=()
  104.  bname=''
  105.  
  106.  #Can't put the loop in the loop in a pipeline if you want to assign array values:
  107.  #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  108.  #find / -wholename "$REPO_DB_FILE_DIR"/'Packages-*' |
  109.  while read REPO_FILE; do
  110.      #s243a: I was thinking of using realpath but it might cause issues.
  111.      #REPO_FILE="$(realpath "$REPO_FILE")"
  112.      bname="$(basename "$REPO_FILE")"  
  113.      ALL_REPO_DB_PATHS+=( ["$bname"]="$REPO_FILE" )
  114.      #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  115.      #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  116.  done < <( find "$REPO_DB_FILE_DIR" -name 'Packages-*' )
  117. #}  
  118. #mk_all_repo_file_list_arry
  119. #echo "exited: mk_all_repo_file_list_arry()"
  120. #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
  121.  
  122. #Moved after the function repo_file_list
  123. #mk_repo_file_list_arry
  124. # but disable colours if called as gpkg, or the ENV variable PKG_NO_COLOURS is true
  125. if [ "`basename $0`" != "pkg" -o "$PKG_NO_COLOURS" = true ]; then
  126.   green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour=''
  127. fi
  128.  
  129. # report errors better than just echo
  130. error(){
  131.   echo -e 1>&2 "${red}Error:${endcolour} $1"
  132. }
  133.  
  134. #run as root only
  135. whoami=$(whoami) #s243a Copied to before line #40. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
  136. [ "$whoami" != "root" ] && echo "You must be root to run Pkg." && exit 1
  137.  
  138. #080413 make sure all config files are present, copy from /etc if need be
  139. if [ ! -f ${PKGRC} ]; then
  140.   echo "Restoring default settings from /etc/pkg"
  141.   [ ! -d /etc/pkg/ ] && error "Default config files  in /etc/pkg/ not found." && exit 3
  142.   mkdir -p "$HOME/.pkg"
  143.   [ ! -d "$HOME/.pkg" ] && error "Default user config dir '$HOME/.pkg/' could not be created." && exit 3
  144.   cp --force -a /etc/pkg/* "$HOME/.pkg/" || exit 3
  145. fi
  146.  
  147. # get puppy distro env vars
  148. [ -f /etc/rc.d/PUPSTATE ]                   && . /etc/rc.d/PUPSTATE                    #this has PUPMODE and SAVE_LAYER.
  149. [ -f /etc/DISTRO_SPECS ]                    && . /etc/DISTRO_SPECS                     #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  150. [ -f /etc/rc.d/BOOTCONFIG ]                 && . /etc/rc.d/BOOTCONFIG                  #has EXTRASFSLIST PREVUNIONRECORD, LASTUNIONRECORD (sfs stuff)
  151. [ -f /etc/xdg/menus/hierarchy ]             && . /etc/xdg/menus/hierarchy              #w478 has PUPHIERARCHY variable.
  152. [ -f $PKGS_DIR/DISTRO_PKGS_SPECS ]    && . $PKGS_DIR/DISTRO_PKGS_SPECS     #has lot sof essential info
  153. [ -f $PKGS_DIR/PKGS_MANAGEMENT ]      && . $PKGS_DIR/PKGS_MANAGEMENT       #has PKG_NAME_IGNORE, PKG_PET_THEN_BLACKLIST_COMPAT_KIDS, PKG_REPOS_ENABLED
  154. [ -f $PKGS_DIR/DISTRO_COMPAT_REPOS ]  && . $PKGS_DIR/DISTRO_COMPAT_REPOS   #has repo URL related vars
  155.  
  156. # set the package name suffix appended to combined pkgs (pkg+deps)
  157. CP_SUFFIX="WITHDEPS_${DISTRO_FILE_PREFIX}"
  158.  
  159. # set correct arch for repo URLs (used by some slack-pup repos)
  160. case "$DISTRO_TARGETARCH" in
  161.   x86)    DBIN_ARCH=i486                ;;
  162.   x86_64) DBIN_ARCH=x86_64 ; DSUFFIX=64 ;;
  163.   *)      DBIN_ARCH=i486                ;;
  164. esac
  165.  
  166. # needed for some debian based repos
  167. case $DISTRO_COMPAT_VERSION in
  168.   wheezy) DDB_COMP=bz2 ;; # older versions
  169.   *)      DDB_COMP=xz  ;;
  170. esac
  171.  
  172. # now create 'layers-installed': will contain builtins (and devx packages, if devx is loaded)
  173. #130511 need to include devx-only-installed-packages, if loaded...
  174. if which gcc &>/dev/null; then
  175.   [ ! -f /tmp/ppm-layers-installed-packages ] && cp -f "$WOOF_INST_PKGS_FILE" /tmp/ppm-layers-installed-packages &>/dev/null
  176.   cat "$PET_SPEC_DIR_DEFAULT/devx-only-installed-packages" >> /tmp/ppm-layers-installed-packages &>/dev/null
  177.   sort -u /tmp/ppm-layers-installed-packages > "$LAYER_INST_PKGS_FILE" &>/dev/null
  178. else
  179.   cp -f "$WOOF_INST_PKGS_FILE" "$LAYER_INST_PKGS_FILE" &>/dev/null
  180. fi
  181.  
  182. # set $DIRECTSAVEPATH (where we want to install pkgs)
  183. if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ]; then
  184.   DIRECTSAVEPATH="/initrd${SAVE_LAYER}" #SAVE_LAYER is in /etc/rc.d/PUPSTATE.
  185. elif [ "$PUPMODE" = "2" ]; then
  186.   DIRECTSAVEPATH=""
  187. fi
  188. # s243a: Need the real path to avoid overwriting sylinks. See:
  189. # http://murga-linux.com/puppy/viewtopic.php?p=1030958#1030958  
  190. # https://github.com/puppylinux-woof-CE/woof-CE/issues/1469#issuecomment-505706014
  191. [ -L "$DIRECTSAVEPATH" ] && DIRECTSAVEPATH="$(readlink "$DIRECTSAVEPATH")"
  192. # get repo details, workdir, search settings and so on.. you could
  193. # you can also add any ENVIRONMENT VARS above to PKGRC, to override the defaults
  194. . ${PKGRC}
  195.  
  196. # set and create workdir if no valid dir set
  197. [ ! -d "$WORKDIR" ] && mkdir -p "$WORKDIR"
  198. if [ ! -d "$WORKDIR" ]; then
  199.   error "Can't create $WORKDIR. Please create it."
  200.   exit 3
  201. fi
  202. WORKDIR=~/pkg
  203.  
  204. # add to tab completion settings to bashrc and print hint
  205. if [ -z "$PKG_TAB_COMPLETION" ]; then
  206.   if [ "$(grep 'export PKG_TAB_COMPLETION=true' ~/.bashrc)" = "" ]; then
  207.     # add to bashrc
  208.     echo "" >> ~/.bashrc
  209.     echo "# enable $APPNAME $APPVER TAB completion" >> ~/.bashrc
  210.     echo "export PKG_TAB_COMPLETION=true" >> ~/.bashrc
  211.     echo ". /etc/bash_completion.d/pkg 2>/dev/null" >> ~/.bashrc
  212.   fi
  213. fi
  214.  
  215. # make tmp dir writable by everyone if needed
  216. if [ ! -d "$TMPDIR" ]; then
  217.   mkdir -p "$TMPDIR" 2>/dev/null
  218.   chmod -R 1777 /tmp/pkg/ 2>/dev/null
  219. fi
  220.  
  221. # if no tmp dir created or accessible, exit
  222. [ ! -d "$TMPDIR" ] && error "Cannot create temp dir ${lightblue}$TMPDIR${endcolour}" && exit 3
  223.  
  224. # support aliases, create ALIASES tmp file
  225. 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'
  226. [ ! -f "$TMPDIR/pkg_aliases" ] && echo "$PKG_NAME_ALIASES" | tr ' ' '\n' > $TMPDIR/pkg_aliases
  227.  
  228. # remove error code flag if we got here
  229. rm -f /tmp/pkg/error130 &>/dev/null
  230.  
  231. # if not first run, and no options given, print the help
  232. [ ! -f ~/.pkg/firstrun -a "$1" = "" ] && $SELF -H && exit 1 #200913 more help by default
  233.  
  234. #==================  setup script vars  =====================#
  235.  
  236. set -a
  237.  
  238. list_all_aliases_set_verify(){
  239.       local verify
  240.       declare -a verify_actions
  241.       if [[ $2 = -* ]]; then
  242.         verify=0 #Don't Verify aliases
  243.         #echo "first if"
  244.        #shift 1
  245.       elif [[ -z "$2" ]]; then
  246.         verify=0 #Don't Verify aliases
  247.          #echo "second if"      
  248.       else
  249.         verify=$2
  250.         #echo "else"
  251.         #shift 2
  252.       fi
  253.       #echo "exited if"
  254.       case "$verify" in
  255.         true|yes|1) verify=1; ;;
  256.         false|no|0) verify=0; ;;
  257.         fist|2) verify=2; ;; #Verify untill we know the version
  258.         *)
  259.           verify=3 #Specify the verify action.
  260.           verify_actions=( ${2//;/ } ) #TODO maybe use a more robust method here: https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash
  261.           #shift 2
  262.           ;;
  263.       esac
  264.      echo $verify
  265.      if [ $verify=1 ]; then
  266.        echo version
  267.      else  
  268.        echo no-version
  269.      fi
  270.      if [ declare -p verify_actions ]; then
  271.        for action in verify_actions; do
  272.          echo "$action"
  273.        done
  274.      fi
  275. }
  276.  
  277. # utility funcs
  278. #set -- gtk
  279.  
  280.  
  281. mk_AWK_prg(){
  282.     local pkg_name=$1
  283.     local version=$2
  284.     local stripped_match=0
  285.     declare -a options="$(getopt -o -pvsn --long package:,version:,stripped,--no-strip: -- $@)"
  286.     eval set --"$options"
  287.     while [ @# -gt 0 ]; do
  288.       case "$1"
  289.       -s|--stripped) stripped_match=1; shift 1 ;; #For no this will be the default
  290.       -n|--no-strip) stripped_match=0; shift 1 ;;
  291.       -p|--package) package=$1; shift 2 ;;
  292.       -v|--version) version=$1; shift 2 ;;
  293.       --) shift 1; break ;;
  294.       *) sift 1 ;;
  295.       esac
  296.     done
  297.     for aArg in "$@"; then
  298.       if [ ! -z "$aArg" ]; then #Not sure if we need to do this
  299.         if [ -z "$pkg_name" ]; then
  300.           pkg_name="$aArg"
  301.         elif [ -z "$version" ]; then
  302.           version=$1
  303.         else
  304.           break
  305.         fi
  306.       fi
  307.     done
  308.     [ -z "$stripped_match" ] && stripped_match=1
  309.     if [[ "$pkg_name" =~ ^[^0-9]*[0-9]*$ ]]; then
  310.       stripped="$(echo $pkg_name | sed -e 's/[0-9]*$//g')"
  311.       if [ -z $version ]; then
  312.         version="$(echo $pkg_name | sed -r 's/[.*[!0-9]([0-9]*$)/\1/')"
  313.       fi
  314.       versioned=1 #Currently we don't do anything with this info.
  315.     else
  316.       stripped="$pkg_name"
  317.       versioned=0
  318.     fi
  319.    
  320.     #https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html
  321.     if [ $stripped_match -eq 1 ] && [ ! -z "$version" ]; then
  322.       if [ versioned -eq 1 ]; then
  323.         AWK_PRG=\
  324.         "BEGIN{FS=\"|\"}
  325.        {
  326.          match(\$2,/^(.*[^:digit:])([:digit:]*$|$)/,pkg_split)
  327.          match(\$3,/^[:digit:]*([^:digit:].*|$)/,version_split)
  328.          if( $2 = \"$pkg_name\" ) {
  329.            print
  330.          }
  331.         elif ( pkg_split[1] = \"$stripped\" and version_split[1] = \"$version\" ) {
  332.            print
  333.         }
  334.      }"
  335.       else
  336.         AWK_PRG=\
  337.         "BEGIN{FS=\"|\"}
  338.        {
  339.          match(\$2,/^(.*[^:digit:])([:digit:]*$|$)/,pkg_split)
  340.          match(\$3,/^[:digit:]*([^:digit:].*|$)/,version_split)
  341.          if ( pkg_split[1] = \"$stripped\" and version_split[1] = \"$version\" ) {
  342.            print
  343.          }
  344.           elif ( length(pkg_split) >    1 ) {
  345.            if( pkg_split[1] = \"$stripped\" and pkg_split[2] = \"$version\" ) {
  346.              print
  347.            }
  348.         }
  349.      }"
  350.       fi
  351.     elif [ $stripped_match -eq 1 ] && [ -z "$version" ]
  352.     #AWK_PRG_No_Version=\        
  353.     #
  354.     AWK_PRG=\  
  355.     "BEGIN{FS=\"|\"}
  356.    {
  357.      match(\$2,/^(.*[^:digit:])([:digit:]*$|$)/,pkg_split)
  358.       if length(matches) > 0 ) {
  359.         if ( \$2 = \"$stripped\" ) {
  360.           print
  361.         }
  362.       }
  363.    }"  
  364.     else #Exactly match the package name
  365.      AWK_PRG=\  
  366.     "BEGIN{FS=\"|\"}
  367.    {
  368.       if ( \$2 = \"$pkg_name\" ) {
  369.         print
  370.       }
  371.      
  372.    }"            
  373.     fi
  374.         #if [  
  375. }
  376. list_all_aliases(){
  377.   # support pkg name aliases in finding packages
  378.         #case "$i" in
  379.         #1) subdep2="subdep"
  380.         #2)
  381.         #  subdep2="$(echo subdep | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  382.         #  if [ "$subdep" = "$subdep2" ]; then
  383.         #  
  384.         #  fi
  385.   echo "$subdep2"
  386.   #local ALIAS_LIST; local ALIAS; local ALIAS_RES; local subdep
  387.   #local subdep_version; local subdep2; local subdep_stripped
  388.   #local verify; local no_alias
  389.   declare -a options="$(getopt -o v:l:p:m:: --long version:,list:,package:,meta::,verify::,no-alias -- $@)"
  390.   declare -A verify_actions
  391.   eval set -- "$options"
  392.   while true; do
  393.     case $1 in
  394.     -v|--version)
  395.       subdep_version=${2:-'%{version}'}; shift 2 ;;  
  396.    -l|--list)
  397.      ALIAS_LIST_in="2"; shift 2; ;;
  398.    -p|--package)
  399.      subdep="$2"; shift 2; ;;
  400.    -m|--meta)
  401.      if [[ "$2" = -* ]] || [ -z "$2" ]]; then
  402.        meta='db-index'
  403.      else
  404.        meta="$2"; shift 2 ;;
  405.      fi
  406.      while
  407.    --verify)
  408.      while aResult in list_all_aliases_set_verify "$1" "$2"; do
  409.        #verify_actions=("aResult")
  410.        verify_actions[$aResult]=1
  411.        
  412.      done
  413.      #if [ $verify_actions[version] -eq 1 ]; then
  414.      #  verify=1
  415.      
  416.      # &&  
  417.      #echo "WTF!"
  418.      #unset 'verify_actions[0]'
  419.      #shift 1; [[ "$1" = -* ]] && shift 1
  420.      shift 2
  421.      
  422.      #May set
  423.      #for aAction in version no-version min-version max-version spider download; do
  424.      #  
  425.      #done
  426.      ;;
  427.    #--verify-type)
  428.    --no-alias)  
  429.      if [[ $2 = -* ]] || [ -z "$2" ]; then
  430.        no_alias=1; shift 1;      
  431.      else
  432.        no_alias=$2; shift 2;    
  433.      fi
  434.      {
  435.      case "$no_alias" in
  436.        true|yes|1) no_alias=1; ;;
  437.        false|no|0) no_alias=0; ;;
  438.        default|2) no_alias=2; ;;
  439.      esac
  440.      } ;;
  441.    --)
  442.      shift
  443.      break; ;;
  444.    -*|--*) #This should never happen
  445.       echo "list_all_aliases(): unkown option '$1' '$2' "
  446.       shift 2; ;;      
  447.    *) #This should never happen
  448.       echo "list_all_aliases(): unkown paramater '$1' " 1>&2
  449.       shift 1; ;;
  450.    esac
  451.  done
  452.  
  453.  if [ -z "$subdep" ]; then
  454.    subdep="$1"; shift
  455.  fi
  456.  #if [ -z "$subdep_version" ]; then
  457.  #  subdep_version=${1:-'%{version}'}; shift
  458.  #fi
  459.  if [ -z "$ALIAS_LIST" ]; then
  460.    ALIAS_LIST_in="$1"; shift
  461.  fi
  462.  [ -z "$verify" ] && verify=0
  463.  if [ -z "$no_alias" ] || [ $no_alias -eq 2 ]; then
  464.    if [ ! -z "$NO_ALIASES" ]; then
  465.      case "$NO_ALIASES"  in
  466.      true) no_alias=1 ;;
  467.      false) no_alias=0 ;;
  468.      esac
  469.    else
  470.      no_alias=0;
  471.    fi
  472.  fi
  473.  if [ -z "$ALIAS_LIST_in" ]; then
  474.    if [ -f ${TMPDIR}/pkg_aliases ]; then
  475.      ALIAS_LIST="${TMPDIR}/pkg_aliases"
  476.    else
  477.      ALIAS_LIST="$PKG_NAME_ALIASES"
  478.    fi
  479.  fi
  480.  #We probably don't need to do this unless we are given a file name.
  481.   subdep_stripped="$(echo "$subdep" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  482.   #but we need to strip the trailing number:
  483.   #However, comment out the if condition for now because I don't know if it gives any performance gains
  484.   #if [[ "$pkg_name" =~ ^[^0-9]*[0-9]*$ ]]; then
  485.     subdep_stripped="$(echo $pkg_name | sed -e 's/[0-9]*$//g')"
  486.     if [ -z $subdep_version ]; then
  487.       subdep_version="$(echo $pkg_name | sed -r 's/[.*[!0-9]([0-9]*$)/\1/')"
  488.     fi
  489.   #fi
  490.        
  491.   if [ -e "$ALIAS_LIST" ]; then #ALIAS_LIST is a file
  492.        ALIAS_LIST=( `grep -E "$subdep_stripped"'([,]|$)' "$ALIAS_LIST"  2>/dev/null | tr ',' ' '` )
  493.   else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string
  494.     ALIAS_LIST=( $(echo "$ALIAS_LIST" | tr ' ' '\n' | grep -E "$subdep_stripped"'([,]|$)'  2>/dev/null | tr ',' '\n') )
  495.   fi
  496.   subdep_old=subdep_version #We don't use this yet.
  497.   subdep_version="${subdep_version%%.*}"  
  498.   if [ ! -z "$subdep_version" ] && [ -z "$ALIAS_LIST2" ]; then
  499.     if [ "$subdep_versioned" != "$subdep" ]; then
  500.       subdep_versioned="$subdep"
  501.       subdep_versioned2="$subdep_stripped$subdep_versioned"
  502.     else
  503.       subdep_versioned="$subdep_stripped$subdep_versioned"
  504.     fi
  505.     if [ -e "$ALIAS_LIST_in" ]; then #ALIAS_LIST is a file
  506.       ALIAS_LIST2=( `grep -E "$subdep_versioned"'([,]|$)' "$ALIAS_LIST"  2>/dev/null | tr ',' ' '` )
  507.     else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string
  508.       ALIAS_LIST2=( $(echo "$ALIAS_LIST_in" | tr ' ' '\n' | grep -E "$subdep_versioned"'([,]|$)'  2>/dev/null | tr ',' '\n') )
  509.     fi    
  510.     #for ALIAS in "${ALIAS_LIST2}"; do
  511.     #  
  512.     #done
  513.   fi  
  514.   if [ ! -z "$subdep_version2" ] && [ -z "$ALIAS_LIST3" ]; then
  515.     if [ -e "$ALIAS_LIST_in" ]; then #ALIAS_LIST is a file
  516.       ALIAS_LIST3=( `grep -E "$subdep_versioned2"'([,]|$)' "$ALIAS_LIST"  2>/dev/null | tr ',' ' '` )
  517.     else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string
  518.       ALIAS_LIST3=( $(echo "$ALIAS_LIST_in" | tr ' ' '\n' | grep -E "$subdep_versioned2"'([,]|$)'  2>/dev/null | tr ',' '\n') )
  519.     fi    
  520.   fi    
  521.   ###################TODO combine alias lists######################
  522.   if [ "$subdep_stripped" = "$sudep" ]; then
  523.     subdep2="$subdep$subdep_version"
  524.   else
  525.     subbdep2="$subdep_stripped"
  526.   fi
  527.   declare -A result
  528.   declare -A aliases
  529.   if [ $no_alias = 1 ]; then
  530.     result[0]="$subdep"
  531.     result[1]="$subdep2"
  532.   elif [ $no_alias = 0 ]; then
  533.    
  534.     # if we have some results to parse
  535.  
  536.     # get the list of aliases
  537.     #ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases  2>/dev/null | tr ',' ' '`";
  538.     # for each alias
  539.  
  540.     #if [ ${verify_actions[version]} -eq 1 ]; then
  541.       alias_index=0
  542.       for ALIAS in "${ALIAS1[@]}" "${ALIAS2[@]}" "${ALIAS3[@]}"; do
  543.       #while read ALIAS; do
  544.         alias_index=$((alias_index+1))      
  545.         key=`md5sum < <( echo "$ALIAS" ) | cut -f1 -d' '`
  546.         remaining_aliases[$key]="$ALIAS"
  547.         alias_keys[$alias_index]=$key
  548.         aliases[$key]="$ALIAS"
  549.       done
  550.       #done < <( echo $ALIAS_LIST )
  551.       N_ALIAS=#alias_index
  552.     if [ -z $subdep_version ]; then
  553.       more_aliases=true
  554.     else
  555.       more_aliases=last
  556.     fi
  557.     new_version=0
  558.     db_index=0      
  559.     #The Alias list should be sorted by our repo order. In other words the repo order defines the priority.
  560.     while [ $db_index -lt ${#REPO_DB_PATHS} ]; do
  561.     #for aRepoDB in "$REPO_DB_FILE_DIR/${REPOFILE}"; do
  562.       aRepoDB=${REPO_DB_PATHS[$db_index]}
  563.       #while [ ! "$more_aliases" = done ]; do #TODO do we need this loop (see next for loop)#################
  564.       #alias_index=0 #We could use this instead of loop through the keys
  565.       for key in "${!remaining_aliases[@]}"
  566.         ALIAS="${remaining_aliases[$key]}"
  567.         alias_index=alias_indexs[$key]
  568.         [ "$ALIAS" = '' ] && continue
  569.         AWK_PRG="$(mk_AWK_prg $subdep $subdep_version)"          
  570.         awk_result="$(echo $aRepoDB | awk "$AWK_PRG")"
  571.         if [ ! -z "$awk_result" ]; then
  572.           if [ -z "$subdep_version" ]; then
  573.             subdep_version="${awk_result[3]}"
  574.             subdep_version="${subdep_version%%.*}"
  575.             alias_index2=$N_ALIAS
  576.               #more_aliases=last
  577.       ##########TODO create array of new alasises
  578.             alias_index2=${#aliases[@]}    
  579.             new_version=0
  580.             for ALIAS2 in "$ALIAS_LIST[@]"; do #TODO make sure the variable ALIAS2 doesn't conflict with anything
  581.               ALIAS3="$ALIAS2$subdep_version"
  582.               key2=`md5sum < <( echo "$ALIAS3" ) | cut -f1 -d' '`
  583.               if [ -z "${aliases[$key2]}" ]; then
  584.                 new version=1  
  585.                 #key=`md5sum < <( echo "$ALIAS" ) | cut -f1 -d' '`
  586.                 remaining_aliases[$key]="$ALIAS3"
  587.                 alias_keys[$alias_index2]=$key
  588.                 aliases[$key]="$ALIAS3"
  589.                 alias_index2=$((alias_index++))
  590.                 alias_indexs[$key2]=$alias_index2
  591.               fi
  592.             done
  593.             if [ $new version -eq 1 ]; then
  594.               db_index=-1 #Start over at the first DB.
  595.               break 2
  596.             fi              
  597.           fi
  598.           result[$key]="$ALIAS"
  599.           #[ ! -z "alias_indexes[$key]" ] || alias_indexes[$key]=$alias_index
  600.           [ ! -z "db_indexes[$key]" ] || db_indexes[$key]=$db_index                                  
  601.           if [ ! -z "$subdep_version" ] && [ ${verify_actions[$subdep_version]} -eq 1]; then
  602.             checks_done[$key]=entry,version
  603.           else
  604.             checks_done[$key]=entry
  605.           fi
  606.           if [ $i -gt 0 ]; then
  607.             unset "remaining_aliases[$key]"
  608.             var=$((var +1))
  609.           fi
  610.         fi
  611.         #alias_index=$((alias_index++))
  612.       done
  613.           #fi
  614.           #break 2
  615.         #fi
  616.         alias_index=$((alias_index + 1))
  617.        
  618.        if [ $new_version -eq 1 ]; then
  619.          #"$more_aliases" = done
  620.          #TODO check for new alasises and add to remaining aliases.
  621.          #TODO Restart db_index
  622.  
  623.          
  624.        elif
  625.          #TODO we are done break out of loop
  626.        fi
  627.       #done
  628.       db_index=$((db_index + 1))
  629.   done
  630.  
  631.  
  632.   for aKey in ${!result[@]}; do
  633.     echo "akey=$aKey"
  634.     alias="${result[$aKey]}"
  635.     if [ "$ALIAS" != subdep ] || [ $all -eq 1 ]; then  
  636.       echo "${result[$aKey]}"
  637.     fi
  638.   done #| sort  
  639.    
  640. }
  641. list_all_aliases "$@"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top