Advertisement
s243a

pkg-list-aliases_back2

Oct 6th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 40.62 KB | None | 0 0
  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.  [ -z "#(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. repo_file_list(){                 # list available repo files, $1 optional FUNCLIST
  238.  
  239.   # we need to list these repos in the order defined in the RC file
  240.   # so Pkg can 'fall back' to other repos in that order
  241.  
  242.   # get current config
  243.   . ${PKGRC}
  244.  
  245.   # set vars for this func
  246.   local list=''
  247.   local repo_file=''
  248.   local repo_files=`cut -f3 -d'|' ${HOME}/.pkg/sources`
  249.   local current_fallback_list=`grep "^$REPONAME|" ${HOME}/.pkg/sources | cut -f8 -d'|' | grep -v "^\$"`
  250.  
  251.   # get current repo fallback list order.. note if repo not listed in fallback list, it will be appended after
  252.   for line in $current_fallback_list
  253.   do
  254.     # get the repo file
  255.     repo_file="`grep "^$line|" ${HOME}/.pkg/sources | cut -f3 -d'|'`"
  256.     # add it to the list
  257.     [ "$repo_file" != "" ] && list="$list$repo_file "
  258.   done
  259.  
  260.   # now add all other avail repos to the end of fallback list
  261.   for repo_file in $repo_files
  262.   do
  263.     #if not blank, not already in the repo list and not the current repo ($REPONAME from rc file) then add to list
  264.     [ "$repo_file" != "" -a "`echo "$list" | grep "$repo_file "`" = ""  -a "$repo_file" != "$REPOFILE" ] && list="$list$repo_file "
  265.   done
  266.  
  267.   # list the current repo first
  268.   echo $REPOFILE
  269.   # then the other repos
  270.   echo "$list" | tr ' ' '\n' | grep -v "^\$"
  271. }
  272. declare -ga REPO_DB_PATHS
  273. #mk_repo_file_list_arry(){
  274.  
  275.   #REPO_DB_PATHS=()
  276.   #declare -A REPO_DB_PATHS
  277.  
  278.  #Can't put the loop in the loop in a pipeline if you want to assign array values:
  279.  #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
  280.  # repo_file_list |
  281.  while read REPO_FILE_NAME; do
  282.     #echo "REPO_FILE_NAME=$REPO_FILE_NAME"
  283.     RF_FILE_PATH="${ALL_REPO_DB_PATHS[$REPO_FILE_NAME]}"
  284.     if [ -e "$RF_FILE_PATH" ]; then
  285.       REPO_DB_PATHS+=( "$RF_FILE_PATH" )
  286.     fi
  287.  done < <( repo_file_list )
  288. list_all_aliases_set_verify(){
  289.       local verify
  290.       declare -a verify_actions
  291.       if [[ $2 = -* ]]; then
  292.         verify=0 #Don't Verify aliases
  293.         #echo "first if"
  294.        #shift 1
  295.       elif [[ -z "$2" ]]; then
  296.         verify=0 #Don't Verify aliases
  297.          #echo "second if"      
  298.       else
  299.         verify=$2
  300.         #echo "else"
  301.         #shift 2
  302.       fi
  303.       #echo "exited if"
  304.       case "$verify" in
  305.         true|yes|1) verify=1; ;;
  306.         false|no|0) verify=0; ;;
  307.         fist|2) verify=2; ;; #Verify untill we know the version
  308.         *)
  309.           verify=3 #Specify the verify action.
  310.           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
  311.           #shift 2
  312.           ;;
  313.       esac
  314.      echo $verify
  315.      if [ $verify=1 ]; then
  316.        echo lib_version
  317.      else  
  318.        echo no_lib_version
  319.      fi
  320.      if [ declare -p verify_actions ]; then
  321.        for action in verify_actions; do
  322.          echo "$action"
  323.        done
  324.      fi
  325. }
  326.  
  327. # utility funcs
  328. #set -- gtk
  329.  
  330.  
  331. mk_AWK_prg(){
  332.     local pkg_name
  333.     local version
  334.     local stripped_match
  335.     local awk_cmp_ary=''
  336.     local n_cmp=0
  337.     declare -a options="$(getopt -o f:l:m:np:su:v: --long full-version:,lib-version,min-version,--no-strip:,package:,stripped,version:,gt:,ge:,lt:,le: -- $@)"
  338.     eval set --"$options"
  339.     while [ $# -gt 0 ]; do
  340.       case "$1" in
  341.       -f|--full-version) full_version=$1; shift 2;;   #Not yet implemented
  342.       -l|--lib-version) lib_version=$1; shift 2;;  
  343.       -m|--min-version|--ge)
  344.          n_cmp=$((n_cmp+1))
  345.          awk_cmp_ary_op="$awk_cmp_ary_op"$'\n'"awk_cmp_ary_op[$n_cmp]=\"ge\""
  346.          awk_cmp_ary_val="$awk_cmp_ary_val"$'\n'"awk_cmp_ary_val[$n_cmp]=\"$2\""   
  347.          shift 2  ;;    
  348.       -n|--no-strip) stripped_match=0; shift 1 ;;
  349.       -p|--package) package=$1; shift 2 ;;
  350.       -s|--stripped) stripped_match=1; shift 1 ;; #For no this will be the default   
  351.       -u|--upper-version|--max-version|--le)
  352.          n_cmp=$((n_cmp+1))
  353.          awk_cmp_ary_op="$awk_cmp_ary_op$'\n'awk_cmp_ary_op[$n_cmp]=\"le\""
  354.          awk_cmp_ary_val="$awk_cmp_ary_val$'\n'awk_cmp_ary_val[$n_cmp]=\"$2\"" 
  355.          shift 2 ;;          
  356.       -v|--version) #Compare version only to the precsion given
  357.          n_cmp=$((n_cmp+1))
  358.          awk_cmp_ary_op="$awk_cmp_ary_op$'\n'awk_cmp_ary_op[$n_cmp]=\"e\""
  359.          awk_cmp_ary_val="$awk_cmp_ary_val$'\n'awk_cmp_ary_val[$n_cmp]=\"$2\""
  360.          shift 2 ;;  
  361.       --gt)
  362.          n_cmp=$((n_cmp+1))
  363.          awk_cmp_ary_op="$awk_cmp_ary_op$'\n'awk_cmp_ary_op[$n_cmp]=\"gt\""
  364.          awk_cmp_ary_val="$awk_cmp_ary_val$'\n'awk_cmp_ary_val[$n_cmp]=\"$2\""     
  365.          shift 2 ;;  
  366.       -lt)
  367.          n_cmp=$((n_cmp+1))
  368.          awk_cmp_ary_op="$awk_cmp_ary_op$'\n'awk_cmp_ary_op[$n_cmp]=\"lt\""
  369.          awk_cmp_ary_val="$awk_cmp_ary_val$'\n'awk_cmp_ary_val[$n_cmp]=\"$2\""
  370.          shift 2 ;;      
  371.       --) shift 1; break ;;
  372.       *) shift 1 ;;
  373.       esac
  374.     done
  375.     for aArg in "$@"; do
  376.       if [ ! -z "$aArg" ]; then #Not sure if we need to do this
  377.         if [ -z "$pkg_name" ]; then
  378.           pkg_name="$aArg"
  379.         elif [ -z "$version" ]; then
  380.           #version="$aArg"
  381.           lib_version=$1
  382.         else
  383.           break
  384.         fi
  385.       fi
  386.     done
  387.     [ -z "$stripped_match" ] && stripped_match=1
  388.     if [[ "$pkg_name" =~ ^[^0-9]*[0-9]*$ ]]; then
  389.       stripped="$(echo $pkg_name | sed -e 's/[0-9]*$//g')"
  390.       if [ -z $version ]; then
  391.         lib_version="$(echo $pkg_name | sed -r 's/[(.*[!0-9])([0-9]*$)/\2/')"
  392.       fi
  393.       versioned=1 #Currently we don't do anything with this info.
  394.     else
  395.       stripped="$pkg_name"
  396.       versioned=0
  397.     fi
  398.     #TODO write a script to look up the version range from the lib version.
  399.     if [ $n_cmp -gt 0 ]; then
  400.       AWK_Functions="\
  401.          function version_split(version1,version_array,split_chars,       i1,remainder1,matches,num1_epoch_split){
  402.            #print \"version1=\" version1
  403.            match(version1,/([[:digit:]])*:(.*|$)/,num1_epoch_split)
  404.            if (length(num1_epoch_split) > 0 ){
  405.              version_array[1]=num1_epoch_split[1]
  406.              remainder1=num1_epoch_split[2]
  407.            } else {
  408.              version_array[1]=0
  409.              remainder1=version1
  410.            }
  411.            delete num1_epoch_split
  412.            split_chars[1]=\":\"
  413.            i1=2
  414.            #match(remainder1,/^([^+\.\-~:]+)(([+\.~])([^+\.~\-:]+))*((\-)([^+\.~\-:])+)?$/,matches)  
  415.            #match(remainder1,/^([^+\.\-~:]+)(([+\.\-~:])(.*))?$/,matches)
  416.            match(remainder1,/^([[:digit:]]+)(([+\.\-~:])(.*))?$/,matches)          
  417.            while (length(matches) > 0) {
  418.              version_array[i1]=matches[1]  
  419.              #print \"version_array[\" i1 \"]=\" version_array[i1]     
  420.             if (length(matches)>1){      
  421.                split_chars[i1]=matches[3]
  422.               #print \"split_chars[\" i1 \"]=\" split_chars[i1]
  423.               remainder1=matches[4]
  424.               #print \"remainder1=\" remainder1
  425.               #match(remainder1,/^([^+\.\-~:]+)(([+\.\-~:]+)(.*))?$/,matches)
  426.               match(remainder1,/^([[:digit:]]+)(([+\.\-~:]+)(.*))?$/,matches)
  427.             }
  428.             else{
  429.               break
  430.              }     
  431.                  
  432.              i1=i1+1                                     
  433.            }
  434.          }
  435.          function v_le(ver_split, val_split,       len_ver){
  436.            return v_ge(val_split,ver_split)
  437.          }
  438.          function v_ge(ver_split, val_split,       len_ver){
  439.            #print \"v_ge\"
  440.            if (length(ver_split)<length(val_split)){
  441.              len_ver=length(ver_split)
  442.            }
  443.            else{
  444.             len_ver=length(val_split)
  445.            }
  446.           for (i=1; i<=len_ver; i++){
  447.             #print \"ver_split[\" i \"]=\" ver_split[i]
  448.             #print \"val_split[\" i \"]=\" val_split[i]
  449.             if ( ver_split[i] < val_split[i] ) return 0
  450.             if ( ver_split[i] > val_split[i] ) return 1
  451.            }
  452.            #print \"finished ge compare\"
  453.            #print \"length_ver_split=\" length(ver_split)
  454.            #print \"length_val_split=\" length(val_split)
  455.            if ( length(ver_split) >= length(val_split) )
  456.              return 1
  457.            else
  458.              return 0
  459.          }
  460.          function v_gt(num1, num2,    le){
  461.            ge = v_ge(num2,num1)
  462.            if ( ge == 1 ){
  463.              return 0
  464.            }
  465.            else {
  466.              return 1
  467.            }
  468.          }
  469.          function v_lt(num1, num2){
  470.            return v_gt(num2, num1)
  471.          }
  472.          #An equal-ish functions.
  473.          function v_e(ver_split, val_split,       len_ver){
  474.            if (length(ver_split)<length(val_split)) len_ver=length(ver_split)
  475.            else len_ver=length(val_split)
  476.           for (i=1; i<len_ver; i++){
  477.             if (version_array1[i] != version_array2[i])
  478.               return 0
  479.            }
  480.          return 1
  481.          }
  482.          function arry_cmp(version,ops_array,val_array){
  483.            #print \"test\"
  484.            version_split(version,ver_split,ver_split_chars)      
  485.            for (i=1; i<=length(ops_array); i++){
  486.              #print \"Ops_array \" ops_array[i] \" \" val_array[i]
  487.              version_split(val_array[i],val_split,val_split_chars)   
  488.              #https://www.gnu.org/software/gawk/manual/gawk.html#Switch-Statement
  489.              switch(ops_array[i]){
  490.              case \"<\":
  491.              case \"lt\":
  492.                if (v_lt(ver_split,val_split) == 0 ){
  493.                  return 0
  494.                }
  495.                break
  496.              case \">\":
  497.              case \"gt\":
  498.                if (v_gt(ver_split,val_split) == 0 ){
  499.                  return 0
  500.                }
  501.                break
  502.              case \"<=\":
  503.              case \"le\":
  504.                if (v_le(ver_split,val_split) == 0 ){
  505.                  return 0
  506.                }
  507.                break           
  508.              case \">=\":
  509.              case \"ge\":
  510.                if (v_ge(ver_split,val_split) == 0 ){
  511.                  return 0
  512.                }
  513.                break           
  514.              case \"==\":
  515.              case \"e\":
  516.                if (v_e(ver_split,val_split) == 0 ){
  517.                  return 0
  518.                }
  519.                break           
  520.              }
  521.              #https://unix.stackexchange.com/questions/147957/delete-an-array-in-awk
  522.              delete val_split
  523.              delete val_split_chars
  524.            }
  525.            #print \"returning result=1\"
  526.            return 1
  527.          }
  528.       "
  529.       CMP_Function="arry_cmp(\$3,awk_cmp_ary_op,awk_cmp_ary_val)"
  530.     AWK_Print2="\
  531.              if ( $CMP_Function == 1 ){
  532.                print
  533.               }"     
  534.     else
  535.       AWK_Functions=''
  536.       CMP_Function=''
  537.       AWK_Print2="\
  538.              print
  539.               "  
  540.     fi
  541.     AWK_Print2="\
  542.              if ( $CMP_Function ){
  543.                print
  544.               }"   
  545.     #https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html
  546.     if [ $stripped_match -eq 1 ]; then
  547.         AWK_PRG=$AWK_Functions\
  548. "        BEGIN{FS=\"|\"
  549.          $awk_cmp_ary_op
  550.          $awk_cmp_ary_val
  551.        }
  552.        {
  553.          if( \$2 == \"$pkg_name\") {
  554.            $AWK_Print2
  555.          }
  556.          else{
  557.            match(\$2,/^(.*[^[:digit:]])([[:digit:]]*$|$)/,pkg_split)
  558.            if ( pkg_split[1] == \"$stripped\" ) {
  559.              $AWK_Print2
  560.            }
  561.          }
  562.          delete pkg_split
  563.        }"
  564.     else #Exactly match the package name
  565.         AWK_PRG=$AWK_Functions \
  566. "        BEGIN{FS=\"|\"
  567.          $awk_cmp_ary_op
  568.          $awk_cmp_ary_val  
  569.        }
  570.        {
  571.          if ( \$2 == \"$pkg_name\"  ) {
  572.           $AWK_Print2
  573.          }
  574.          delete pkg_split      
  575.        }"            
  576.     fi
  577.     echo "$AWK_PRG"
  578.         #if [  
  579. }
  580. function echo_alias_list(){
  581.     local subdep=$1
  582.     local ALIAS_LIST=$2
  583.     if [ -e "$ALIAS_LIST" ]; then #ALIAS_LIST is a file
  584.          ALIAS_LIST1=( $(grep -E "$subdep"'([,]|$)' "$ALIAS_LIST"  2>/dev/null | tr ',' ' ') )
  585.     else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string
  586.          ALIAS_LIST1=( $(echo "$ALIAS_LIST" | tr ' ' '\n' | grep -E "$subdep"'([,]|$)'  2>/dev/null | tr ',' '\n') )
  587.     fi 
  588.     for aAlias in "${ALIAS_LIST1[@]}"
  589.       echo "$aAlias"
  590.     fi
  591. }
  592. function echo_aliases(){
  593.   local subdep_stripped
  594.   local subdep
  595.   local lib_version
  596.   local ALIAS_LIST_in
  597.   local versioned
  598.   declare -a ALIAS_LIST1
  599.   declare -a ALIAS_LIST2
  600.   declare -a ALIAS_LIST3
  601.   declare -a options="$(getopt --long ,no-strip::,no-self:: --$@)"
  602.   declare -a self
  603.   eval set -- "$options"
  604.   while true; do
  605.     case $1 in
  606.     --no-strip)
  607.       if [[ $2 = -* ]]; then
  608.         no_strip=1; shift 1
  609.       else
  610.         no_strip=$2; shift 2
  611.       else ;;
  612.     --no-self)
  613.       if [[ $2 = -* ]]; then
  614.         no_self=1; shift 1
  615.       else
  616.         no_self=$2; shift 2
  617.       else ;;
  618.     --)
  619.       shift; break; ;;
  620.     *) #This should never happen
  621.       if [[ $2 = -* ]]; then
  622.         shift 1;
  623.       else
  624.         shift 2;
  625.       fi ;;
  626.     esac
  627.   done
  628.   [ -z "$no_self" ] && no_self=0
  629.   [ $no_self -eq 0 ] && self=("$subdep")
  630.   [ -z "$no_strip" ] && no_strip=0
  631.   if [ ! -z "$3" ]; then
  632.     lib_version=$2; ALIAS_LIST=$3
  633.     subdep=$1
  634.     if [[ "$1" =~ ^.*[^0-9][0-9]+$ ]]; then
  635.        versioned=1
  636.        subdep_stripped=${1%"$lib_version"}
  637.     else
  638.        versioned=0
  639.        subdep_vesioned="$subdep$lib_version"
  640.     fi
  641.     #subdep=$subdep_stripped$lib_version
  642.   else
  643.     if [[ "$1" =~ ^.*[^0-9][0-9]+$ ]]; then
  644.       versioned=1
  645.       subdep=$1
  646.       lib_version="$(echo $subdep | sed -r 's/[.*[!0-9]([0-9]*$)/\1/')"
  647.       subdep_stripped="$(echo $subdep | sed -e 's/[0-9]*$//g')"
  648.       if [ ! -z "$2" ]; then
  649.         ALIAS_LIST_in=$2
  650.       else
  651.         ALIAS_LIST_in="$ALIAS_LIST"
  652.       fi  
  653.     else
  654.       versioned=0
  655.       #subdep_stripped=$1
  656.       subdep=$1
  657.       #subdep_stripped=$subdep
  658.       if [[ "$2" =~ ^[0-9]+$ ]]; then
  659.         lib_version=$2
  660.         subdep_versioned="$subdep$lib_version"
  661.         ALIAS_LIST_in="$ALIAS_LIST"        
  662.       else
  663.         ALIAS_LIST_in=$2
  664.       fi
  665.      
  666.     fi
  667.   fi   
  668.  
  669.  
  670.   if [ $no_strip -eq 0 ] || [ $versioned -eq 0 ]; then
  671.     [ -z "$subdep_stripped" ] && subdep_stripped=$subdep
  672.     for aAlias in $(echo_alias_list "$subdep_stripped" "$ALIAS_LIST_in"); do
  673.       ALIAS_LIST1+=($aAlias)
  674.       if [ -z lib_version ]; then
  675.          if [[ "$aAlias" =~ ^.*[^0-9][0-9]+$ ]]; then
  676.            lib_version="$(echo $aAlias | sed -r 's/[.*[!0-9]([0-9]*$)/\1/')"
  677.          fi
  678.       fi
  679.     fi
  680.   fi
  681.   [ -z "$subdep_stripped" ] && subdep_stripped=$subdep
  682.   [ -z "$subdep_versioned" ] && [ ! -z $lib_version ] && subdep_versioned="$subdep_stripped$lib_version"
  683.   #subdep_old=subdep_version #We don't use this yet.
  684.   #subdep_version="${subdep_version%%.*}"  
  685.  
  686.   if [ ! -z "$subdep_versioned" ] || [ $versioned -eq 1 ]; then
  687.     [ -z "$subdep_versioned" ] && subdep_versioned=$subdep    
  688.     if [ -e "$ALIAS_LIST_in" ]; then #ALIAS_LIST is a file
  689.       ALIAS_LIST2=( $(grep -E "$subdep_versioned"'([,]|$)' "$ALIAS_LIST"  2>/dev/null | tr ',' ' ') )
  690.     else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string
  691.       ALIAS_LIST2=( $(echo "$ALIAS_LIST_in" | tr ' ' '\n' | grep -E "$subdep_versioned"'([,]|$)'  2>/dev/null | tr ',' '\n') )
  692.     fi    
  693.     #for ALIAS in "${ALIAS_LIST2}"; do
  694.     #  
  695.     #done
  696.   fi
  697.   if [ ! -z lib_version ] && [ $no_strip -eq 0 ]; then
  698.     for aAlias in "$subdep_stripped" "${ALIAS_LIST1[@]}"; do
  699.       if [[ "$aAlias " =~ ^.*[^0-9][0-9]+$ ]]; then
  700.         continue
  701.       fi
  702.       ALIAS_LIST3+=("$aAlias$lib_version")
  703.     done
  704.   done
  705.   local key
  706.   declare -A result
  707.   for ALIAS in "${self[@]}" "${ALIAS_LIST2[@]}" "${ALIAS_LIST3[@]}" "${ALIAS_LIST1[@]}"; do
  708.     key=md5_$(md5sum < <( echo "$ALIAS" ) | cut -f1 -d' ')
  709.     if [ -z result[$key]; then
  710.       result[$key]="$ALIAS"
  711.     done
  712.   done
  713.   for ALIAS in "${result[@]}"; do
  714.     echo "$ALIAS"
  715.   done
  716.  
  717. }
  718.  
  719. ################################################################
  720.    #list_all_aliases(){
  721.   # support pkg name aliases in finding packages
  722.         #case "$i" in
  723.         #1) subdep2="subdep"
  724.         #2)
  725.         #  subdep2="$(echo subdep | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  726.         #  if [ "$subdep" = "$subdep2" ]; then
  727.         #  
  728.         #  fi
  729.   echo "$subdep2"
  730.   #local ALIAS_LIST; local ALIAS; local ALIAS_RES; local subdep
  731.   #local lib_version; local subdep2; local subdep_stripped
  732.   #local verify; local no_alias
  733.   #local s_ALIAS
  734.   declare -a options="$(getopt -o v:l:p:m:: --long version:,list:,package:,meta::,verify::,no-alias,gt:,lt:,le:,ge: -- $@)"
  735.   declare -A verify_actions
  736.   declare -a awk_args
  737.   declare -A lib_versions
  738.   awk_args=()
  739.   eval set -- "$options"
  740.   while true; do
  741.     case $1 in
  742.     -v|--lib-version)
  743.       #subdep_version=${2:-'%{version}'}; shift 2 ;;  
  744.       lib_version=${2}; shift 2 ;;
  745.     -l|--list)
  746.       ALIAS_LIST_in="2"; shift 2; ;;
  747.     -p|--package)
  748.       subdep="$2"; shift 2; ;;
  749.     -m|--meta)
  750.       if [[ "$2" = -* ]] || [ -z "$2" ]]; then
  751.         meta='db-index'; shift 1
  752.       else
  753.         meta="$2"; shift 2
  754.       fi ;;
  755.     --verify)
  756.       while aResult in list_all_aliases_set_verify "$1" "$2"; do
  757.         #verify_actions=("aResult")
  758.         verify_actions[$aResult]=1
  759.       done
  760.       shift 2      
  761.       ;;
  762.     --no-alias)  
  763.       if [[ $2 = -* ]] || [ -z "$2" ]; then
  764.         no_alias=1; shift 1;      
  765.       else
  766.         no_alias=$2; shift 2;    
  767.       fi
  768.       {
  769.       case "$no_alias" in
  770.         true|yes|1) no_alias=1; ;;
  771.         false|no|0) no_alias=0; ;;
  772.         default|2) no_alias=2; ;;
  773.       esac
  774.       } ;;
  775.     --gt|--lt|--le|--ge)
  776.       awk_args+=($1)
  777.       awk_args+=($2)
  778.       shift 2 ;;
  779.     --)
  780.       shift
  781.       break; ;;
  782.     -*|--*) #This should never happen
  783.        echo "list_all_aliases(): unkown option '$1' '$2' "
  784.        shift 2; ;;      
  785.     *) #This should never happen
  786.        echo "list_all_aliases(): unkown paramater '$1' " 1>&2
  787.        shift 1; ;;
  788.     esac
  789.   done
  790.  
  791.   if [ -z "$subdep" ]; then
  792.     subdep="$1"; shift
  793.   fi
  794.   #if [ -z "$subdep_version" ]; then
  795.   #  subdep_version=${1:-'%{version}'}; shift
  796.   #fi
  797.   if [ -z "$ALIAS_LIST" ]; then
  798.     ALIAS_LIST_in="$1"; shift
  799.   fi
  800.   [ -z "$verify" ] && verify=0
  801.   if [ -z "$no_alias" ] || [ $no_alias -eq 2 ]; then
  802.     if [ ! -z "$NO_ALIASES" ]; then
  803.       case "$NO_ALIASES"  in
  804.       true) no_alias=1 ;;
  805.       false) no_alias=0 ;;
  806.       esac
  807.     else
  808.       no_alias=0;
  809.     fi
  810.   fi
  811.   if [ -z "$ALIAS_LIST_in" ]; then
  812.     if [ -f ${TMPDIR}/pkg_aliases ]; then
  813.       ALIAS_LIST_in="${TMPDIR}/pkg_aliases"
  814.     else
  815.       ALIAS_LIST_in="$PKG_NAME_ALIASES"
  816.     fi
  817.   fi
  818.   #We probably don't need to do this unless we are given a file name.
  819.   subdep_stripped="$(echo "$subdep" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  820.   #but we need to strip the trailing number:
  821.   #However, comment out the if condition for now because I don't know if it gives any performance gains
  822.   #if [[ "$pkg_name" =~ ^[^0-9]*[0-9]*$ ]]; then
  823.     subdep_stripped="$(echo $pkg_name | sed -e 's/[0-9]*$//g')"
  824.     if [ -z "$lib_version" ]; then
  825.       lib_version="$(echo $pkg_name | sed -r 's/[.*[!0-9]([0-9]*$)/\1/')"
  826.     fi
  827.   #fi
  828.        
  829.   ###################TODO combine alias lists######################
  830.   if [ "$subdep_stripped" = "$sudep" ]; then
  831.     subdep2="$subdep$subdep_version"
  832.   else
  833.     subbdep2="$subdep_stripped"
  834.   fi
  835.   declare -A result
  836.   declare -A aliases
  837.   declare -A remaining_s_aliases
  838.   echo "no_alias=$no_alias"
  839.   if [ $no_alias -eq 1 ]; then
  840.     result[0]="$subdep"
  841.     result[1]="$subdep2"
  842.   elif [ $no_alias -eq 0 ]; then
  843.    
  844.     # if we have some results to parse
  845.  
  846.     # get the list of aliases
  847.     #ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases  2>/dev/null | tr ',' ' '`";
  848.     # for each alias
  849.  
  850.     #if [ ${verify_actions[version]} -eq 1 ]; then
  851.       alias_index=-1
  852.       alias_s_index=-1
  853.       for ALIAS in `echo_aliases $subdep $ALIAS_LIST_in`; do
  854.       #while read ALIAS; do
  855.         key=md5_$(md5sum < <( echo "$ALIAS" ) | cut -f1 -d' ')    
  856.         if [ -z "${aliases[$key]}" ]; then  
  857.           alias_stripped="$(echo "$ALIAS" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  858.           skey=md5_$(md5sum < <( echo "$alias_stripped" ) | cut -f1 -d' ')
  859.           if [ -z "${stripped_aliases[$skey]}" ]; then
  860.             stripped_aliases[$skey]="$alias_stripped"
  861.             if [ "$alias_stripped" = "$ALIAS" ]; then
  862.               remaining_s_aliases[$key]=1
  863.             else
  864.               remaining_s_aliases[$key]=2
  865.             fi
  866.              alias_s_index=$((alias_s_index+1))  
  867.              alias_s_keys[$alias_index]=$skey  
  868.              s_aliases[$key]="$alias_stripped"        
  869.           else
  870.             remaining_s_aliases[$key]=$(expr ${remaining_s_aliases[$key]} + 1)
  871.           fi
  872.           alias_index=$((alias_index+1))      
  873.           remaining_aliases[$key]="$ALIAS"
  874.           alias_keys[$alias_index]=$key
  875.           aliases[$key]="$ALIAS"
  876.         fi
  877.       done
  878.       #done < <( echo $ALIAS_LIST )
  879.       #N_ALIAS=#alias_index
  880.     if [ -z $subdep_version ]; then
  881.       more_aliases=true
  882.     else
  883.       more_aliases=last
  884.     fi
  885.     new_version=0
  886.     db_index=0      
  887.     #The Alias list should be sorted by our repo order. In other words the repo order defines the priority.
  888.     local lib_version_index=-1
  889.     local first_lib_version_index
  890.     while [ $db_index -lt ${#REPO_DB_PATHS[@]} ]; do
  891.     lib_version_index=$((lib_version_index + 1))
  892.     #for aRepoDB in "$REPO_DB_FILE_DIR/${REPOFILE}"; do
  893.       aRepoDB=${REPO_DB_PATHS[$db_index]}
  894.       #while [ ! "$more_aliases" = done ]; do #TODO do we need this loop (see next for loop)#################
  895.       #alias_index=0 #We could use this instead of loop through the keys
  896.       #for key in "${!remaining_aliases[@]}"; do
  897.       for s_key in "${!remaining_s_aliases[@]}"; do
  898.         s_ALIAS="${remaining_s_aliases[$s_key]}"
  899.         #alias_index=alias_indexs[$key]
  900.         [ "$ALIAS" = '' ] && continue
  901.         if [ ! -z "${verify_actions[lib_version]}" ] && [ ${verify_actions[lib_version]} -eq 1 ]; then
  902.           AWK_PRG="$(mk_AWK_prg $s_ALIAS ${awk_args[@]})"
  903.         else
  904.           AWK_PRG="$(mk_AWK_prg $s_ALIAS ${awk_args[@]})"
  905.         fi          
  906.         awk_results="$(cat $aRepoDB | awk "$AWK_PRG")"
  907.        
  908.         # https://stackoverflow.com/questions/10586153/split-string-into-an-array-in-bash
  909.         #awk_result=readarray -td '' awk_result < <(awk '{ gsub(/, /,"\0"); print; }' <<<"$awk_result_tmp, "); unset 'a[-1]';
  910.         #      declare -p a;
  911.        
  912.         if [ ! -z "$awk_results" ]; then
  913.           while read a_awk_result; do
  914.             ar_i=1 #Put the awk result into an array
  915.             while read aRecord; do
  916.               awk_result[$ar_i]="$aRecord"
  917.               ar_i=$((ar_i+1))
  918.             done < <(cat <<<"$(echo "$a_awk_result" | tr '|' '\n')")
  919.             ALIAS=awk_result[2] #Fetch the package nmae (2nd field)  
  920.             key=md5_$(md5sum < <( echo "$ALIAS" ) | cut -f1 -d' ')
  921.            
  922.             #TODO don't add new lib version if we specify a specific lib version.
  923.             this_lib_version="$(echo $ALIAS | sed -r 's/(.*[^0-9])([0-9]*$)/\2/')" 2>/dev/null
  924.             if [ -z "${lib_versions[$lib_version]}" ] ||  ] ; then
  925.               lib_versions[$lib_version]="$lib_version_index|${awk_result[1]}|${awk_result[2]}|${awk_result[3]}|\"$aRepoDB\""
  926.               new_lib_version=1
  927.             elif [ "${lib_versions[$lib_version]}" = "NULL" ]; then
  928.               lib_versions[$lib_version]="$lib_version_index|${awk_result[1]}|${awk_result[2]}|${awk_result[3]}|\"$aRepoDB\""                
  929.             else
  930.               lib_versions[$lib_version]="${lib_versions[$lib_version]}"$'\n'"$lib_version_index|${awk_result[1]}|${awk_result[2]}|${awk_result[3]}|\"$aRepoDB\""  
  931.             fi            
  932.            
  933.             #Remove the lib number from the end of the package name
  934.             alias_stripped="$(echo "$ALIAS" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  935.             skey=md5_$(md5sum < <( echo "$alias_stripped" ) | cut -f1 -d' ')
  936.            
  937.             if [ -z result[$key] ]; then
  938.               result[$key]="$ALIAS"
  939.               if [ ! -z "$lib_version" ] && [ ${verify_actions[lib_version]} -eq 1 ]; then
  940.                 checks_done[$key]=entry,lib_version
  941.               else
  942.                 checks_done[$key]=entry
  943.               fi
  944.               if [ $i -gt 0 ]; then
  945.                  unset "remaining_aliases[$key]"
  946.                 var=$((var +1))
  947.               fi              
  948.             fi      
  949.  
  950.            
  951.             #if [ $new_lib_version -eq 1 ]; then
  952.             if [ $new_alias -eq 1 ]; then
  953.                 for ALIAS3 in `echo_aliases $ALIAS --no-strip`; do
  954.                    key2=md5_$(md5sum < <( echo "$ALIAS3" ) | cut -f1 -d' ')
  955.                    if [ -z "${aliases[$key2]}" ]; then
  956.             #        #key=`md5sum < <( echo "$ALIAS" ) | cut -f1 -d' '`
  957.             #        remaining_aliases[$key]="$ALIAS3"
  958.             #        alias_keys[$alias_index2]=$key
  959.             ##        aliases[$key]="$ALIAS3"
  960.             #        alias_index2=$((alias_index++))
  961.             #        alias_indexs[$key2]=$alias_index2
  962.                      alias_stripped2="$(echo "$ALIAS" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  963.                      skey2=md5_$(md5sum < <( echo "$alias_stripped" ) | cut -f1 -d' ')            
  964.                      if [ -z "${stripped_aliases[$skey2]}" ]; then
  965.                        new_s_version=1
  966.                        stripped_aliases[$skey]="$alias_stripped2"
  967.             #          if [ "$alias_stripped" = "$ALIAS" ]; then
  968.             #             remaining_s_aliases[$key]=1
  969.             #          else
  970.             #             remaining_s_aliases[$key]=2
  971.             #          fi
  972.             #          alias_s_index=$((alias_s_index+1))  
  973.             #          alias_s_keys[$alias_index]=$skey  
  974.             #          s_aliases[$key]="$alias_stripped"        
  975.                     else
  976.             #          remaining_s_aliases[$key]=$(expr ${remaining_s_aliases[$key]} + 1)
  977.                     fi
  978.                    fi
  979.                 done
  980.             #  done
  981.             #else
  982.             #  #rema
  983.              
  984.             #if [ $new_lib_version -eq 1 ]; then
  985.             #  for ALIAS2 in "${aliases[@]}"; do #TODO make sure the variable ALIAS2 doesn't conflict with anything
  986.             #    if [[ "$ALIAS2" =~ ^.*[^0-9][0-9]+$ ]]; then
  987.             #      continue
  988.             #    fi
  989.             #    ALIAS3_pre="$ALIAS2$this_lib_version"
  990.             #    for ALIAS3 in `echo_aliases $ALIAS3_pre --no-strip`; do
  991.             #      key2=md5_$(md5sum < <( echo "$ALIAS3" ) | cut -f1 -d' ')
  992.             #      if [ -z "${aliases[$key2]}" ]; then
  993.             #          
  994.             #        #key=`md5sum < <( echo "$ALIAS" ) | cut -f1 -d' '`
  995.             #        remaining_aliases[$key]="$ALIAS3"
  996.             #        alias_keys[$alias_index2]=$key
  997.             ##        aliases[$key]="$ALIAS3"
  998.             #        alias_index2=$((alias_index++))
  999.             #        alias_indexs[$key2]=$alias_index2
  1000.             #        if [ -z "${stripped_aliases[$skey]}" ]; then
  1001.             #          new_version=1
  1002.             #          stripped_aliases[$skey]="$alias_stripped"
  1003.             #          if [ "$alias_stripped" = "$ALIAS" ]; then
  1004.             #             remaining_s_aliases[$key]=1
  1005.             #          else
  1006.             #             remaining_s_aliases[$key]=2
  1007.             #          fi
  1008.             #          alias_s_index=$((alias_s_index+1))  
  1009.             #          alias_s_keys[$alias_index]=$skey  
  1010.             #          s_aliases[$key]="$alias_stripped"        
  1011.             #        else
  1012.             #          remaining_s_aliases[$key]=$(expr ${remaining_s_aliases[$key]} + 1)
  1013.             #        fi
  1014.             #      fi
  1015.             #    done
  1016.             #  done
  1017.             #else
  1018.             #  #remaining_s_aliases[$key]=$(expr ${remaining_s_aliases[$key]} + 1)
  1019.             #fi
  1020.           done <<<"$awk_results"
  1021.           if [ $new_version -eq 1 ]; then
  1022.                 db_index=-1 #Start over at the first DB.
  1023.                 new_lib_version=0
  1024.                 for aResult_key in @{result[!@]}; do
  1025.                   aResult=${result[$aResult_key]}
  1026.                   stripped_result="$(echo "$ALIAS" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
  1027.                   sr_key=md5_$(md5sum < <( echo "$stripped_result" ) | cut -f1 -d' ')
  1028.                     if [ -z "${remaining_s_aliases[$sr_key]}" ]; then
  1029.                       if [ "$alias_stripped" = "$ALIAS" ]; then
  1030.                          remaining_s_aliases[$sr_key]=1
  1031.                       else
  1032.                          remaining_s_aliases[$sr_key]=2
  1033.                       fi    
  1034.                     else
  1035.                       remaining_s_aliases[$key]=$(expr ${remaining_s_aliases[$key]} + 1)
  1036.                     fi
  1037.                 done
  1038.                 unset 'result'
  1039.                 declare -A result
  1040.                 unset 'this_lib_version'
  1041.                 break 2
  1042.           fi    
  1043.          
  1044.           #fi
  1045.          
  1046.           #[ ! -z "alias_indexes[$key]" ] || alias_indexes[$key]=$alias_index
  1047.           [ ! -z "db_indexes[$key]" ] || db_indexes[$key]=$db_index                                  
  1048.  
  1049.         fi
  1050.       done
  1051.       db_index=$((db_index + 1))
  1052.     done  
  1053.   fi
  1054.  
  1055.  
  1056.   for aKey in ${!result[@]}; do
  1057.     echo "akey=$aKey"
  1058.     alias="${result[$aKey]}"
  1059.     if [ "$ALIAS" != subdep ] || [ $all -eq 1 ]; then  
  1060.       echo "${result[$aKey]}"
  1061.     fi
  1062.   done #| sort  
  1063.    
  1064. #}
  1065. #list_all_aliases "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement