Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #================== setup script vars =====================#
- APPNAME="Pkg"
- APPVER="1.9.22"
- APPTITLE="$APPNAME $APPVER"
- 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.
- dep_id=0 #
- # get current locale settings
- USER_LANG=$LANG
- USER_LC_ALL=$LC_ALL
- SELF=$(basename $0) # this script
- QTAG='' # gets set to (y/n) if ASK=-true
- LANG=C # speed up
- LC_ALL=C # speed up
- EDITOR=${EDITOR:-vi} # just in case
- PAGER=${PAGER:-less} # just in case
- CURDIR="${PWD}" # get current dir, before cd to WORKDIR
- whoami=$(whoami) # s243a copied from below. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
- TMPDIR=/tmp/pkg/${whoami} # set the tmp dir
- # set colours true by default
- green="\e[32m"; red="\e[91m"; magenta="\e[95m"; lightblue="\e[36m"; yellow="\e[93m"; bold="\e[1m"; endcolour="\e[0m"
- # ENVIRONMENT VARS, which may be overridden later
- [ -z "$PKGRC" ] && export PKGRC=${HOME}/.pkg/pkgrc # config file for this script
- [ -z "$ASK" ] && ASK=false # if true, ask user before doing stuff. Overridden by --ask
- [ -z "$QUIET" ] && QUIET=false # if true, hide output that doesnt log well in Xdialog, Gtkdialog, etc
- [ -z "$FORCE" ] && FORCE=false # if true, force (re)install/remove pkgs. Overridden by --force
- [ -z "$HIDE_INSTALLED" ] && export HIDE_INSTALLED=false # if true, hide installed pkgs from pkg searches (-n, -na, -ss, -ssa)
- [ -z "$HIDE_BUILTINS" ] && export HIDE_BUILTINS=true # if true, remove builtins pkgs from dep lists, dont download/install them
- [ -z "$HIDE_USER_PKGS" ] && export HIDE_USER_PKGS=true # if true, hide user installed pkgs from dep lists, dont download/install them
- [ -z "$NO_ALIASES" ] && export NO_ALIASES=false # if true, skip searching pkg alias names for pkg alternatives
- [ -z "$NO_INSTALL" ] && export NO_INSTALL=false # if true, skip installing of pkgs
- [ -z "$PKG_NO_COLOURS" ] && export PKG_NO_COLOURS=false # if true, disable coloured output or not
- [ -z "$PKG_CONFIGURE" ] && export PKG_CONFIGURE='' # reset
- [ -z "$PKG_CFLAGS" ] && export PKG_CFLAGS='' # reset
- [ -z "$PKGS_DIR" ] && export PKGS_DIR="$(realpath "${HOME}/.packages")"
- #These are files of the form
- #[ -z "$PET_SPEC_DIR_ROOT" ] && PET_SPEC_DIR_ROOT="$PKGS_DIR"
- if [ -z "$REPO_DB_FILE_DIR" ]; then
- if [ -d "$PKGS_DIR/repo" ]; then #This imples mistfires ppm3 is installed
- export REPO_DB_FILE_DIR="$(realpath "$PKGS_DIR/repo")"
- else
- export REPO_DB_FILE_DIR="$PKGS_DIR"
- fi
- fi
- if [ -z "$PACKAGE_FILE_LIST_DIR" ]; then
- if [ -d "$PKGS_DIR/package-files" ]; then #This imples mistfires ppm3 is installed
- export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR/package-files")"
- else
- export PACKAGE_FILE_LIST_DIR="$(realpath "$PKGS_DIR")"
- fi
- fi
- [ -z "$BUILTIN_FILE_LIST_DIR" ] && BUILTIN_FILE_LIST_DIR="$PKGS_DIR/builtin_files"
- #[ -z "$PET_SPEC_DIR_BUILTIN" ] && PET_SPEC_DIR_BUILTIN=\
- # "$(realpath "$PKGS_DIR/builtin_files")"
- #
- #[ -z "$PET_SPEC_DIR_USR_INST" ] && PET_SPEC_DIR_USR_INST="$PKGS_DIR"
- #mk_spec_file_list_arry(){
- [ -z "#(declare -p $SPEC_DB_PATHS)" ] || declare -ga SPEC_DB_PATHS=()
- #Can't put the loop in the loop in a pipeline if you want to assign array values:
- #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
- #find / -wholename "$PKGS_DIR"/'*-installed-packages' |
- while read SPEC_FILE; do
- bname="`basename "$SPEC_FILE"`"
- case "$bname" in #Consider lowering case
- "layers-installed-packages")
- #Do Nothing
- export LAYER_INST_PKGS_FILE="$SPEC_FILE" ;;
- "woof-installed-packages")
- export WOOF_INST_PKGS_FILE="$SPEC_FILE" ;;
- "user-installed-packages")
- export USER_INST_PKGS_FILE="$SPEC_FILE" ;;
- "devx-only-installed-packages")
- export DEVX_INST_PKGS_FILE="$SPEC_FILE" ;;
- *)
- SPEC_DB_PATHS+=( "$SPEC_FILE" ) ;;
- esac
- #s243a: We don't need realpath for the next four vars but it will provide usefull debugging information.
- #s243a: TODO search for the following files if they don't exist.
- [ -z "$USER_INST_PKGS_FILE" ] && \
- USER_INST_PKGS_FILE="$PKGS_DIR/user-installed-packages"
- [ -z "$WOOF_INST_PKGS_FILE" ] && \
- WOOF_INST_PKGS_FILE="$PKGS_DIR/woof-installed-packages"
- [ -z "$LAYER_INST_PKGS_FILE" ] && \
- LAYER_INST_PKGS_FILE="$PKGS_DIR/layers-installed packages"
- [ -z "$DEVX_INST_PKGS_FILE" ] && \
- DEVX_INST_PKGS_FILE="$PKGS_DIR/devx-only-installed-packages"
- SPEC_DB_PATHS=( "$USER_INST_PKGS_FILE" "$WOOF_INST_PKGS_FILE" "${SPEC_DB_PATHS[@]}" )
- done < <( find "$PKGS_DIR" -name '*-installed-packages' )
- #}
- #mk_spec_file_list_arry
- #echo "SPEC_DB_PATHS=${SPEC_DB_PATHS[@]}"
- #mk_all_repo_file_list_arry(){
- declare -gA ALL_REPO_DB_PATHS=()
- #ALL_REPO_DB_PATHS=()
- bname=''
- #Can't put the loop in the loop in a pipeline if you want to assign array values:
- #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
- #find / -wholename "$REPO_DB_FILE_DIR"/'Packages-*' |
- while read REPO_FILE; do
- #s243a: I was thinking of using realpath but it might cause issues.
- #REPO_FILE="$(realpath "$REPO_FILE")"
- bname="$(basename "$REPO_FILE")"
- ALL_REPO_DB_PATHS+=( ["$bname"]="$REPO_FILE" )
- #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
- #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
- done < <( find "$REPO_DB_FILE_DIR" -name 'Packages-*' )
- #}
- #mk_all_repo_file_list_arry
- #echo "exited: mk_all_repo_file_list_arry()"
- #echo "ALL_REPO_DB_PATHS=${ALL_REPO_DB_PATHS[@]}"
- #Moved after the function repo_file_list
- #mk_repo_file_list_arry
- # but disable colours if called as gpkg, or the ENV variable PKG_NO_COLOURS is true
- if [ "`basename $0`" != "pkg" -o "$PKG_NO_COLOURS" = true ]; then
- green='' red='' magenta='' lightblue='' yellow='' bold='' endcolour=''
- fi
- # report errors better than just echo
- error(){
- echo -e 1>&2 "${red}Error:${endcolour} $1"
- }
- #run as root only
- whoami=$(whoami) #s243a Copied to before line #40. See issue: http://murga-linux.com/puppy/viewtopic.php?p=1030838#1030838
- [ "$whoami" != "root" ] && echo "You must be root to run Pkg." && exit 1
- #080413 make sure all config files are present, copy from /etc if need be
- if [ ! -f ${PKGRC} ]; then
- echo "Restoring default settings from /etc/pkg"
- [ ! -d /etc/pkg/ ] && error "Default config files in /etc/pkg/ not found." && exit 3
- mkdir -p "$HOME/.pkg"
- [ ! -d "$HOME/.pkg" ] && error "Default user config dir '$HOME/.pkg/' could not be created." && exit 3
- cp --force -a /etc/pkg/* "$HOME/.pkg/" || exit 3
- fi
- # get puppy distro env vars
- [ -f /etc/rc.d/PUPSTATE ] && . /etc/rc.d/PUPSTATE #this has PUPMODE and SAVE_LAYER.
- [ -f /etc/DISTRO_SPECS ] && . /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
- [ -f /etc/rc.d/BOOTCONFIG ] && . /etc/rc.d/BOOTCONFIG #has EXTRASFSLIST PREVUNIONRECORD, LASTUNIONRECORD (sfs stuff)
- [ -f /etc/xdg/menus/hierarchy ] && . /etc/xdg/menus/hierarchy #w478 has PUPHIERARCHY variable.
- [ -f $PKGS_DIR/DISTRO_PKGS_SPECS ] && . $PKGS_DIR/DISTRO_PKGS_SPECS #has lot sof essential info
- [ -f $PKGS_DIR/PKGS_MANAGEMENT ] && . $PKGS_DIR/PKGS_MANAGEMENT #has PKG_NAME_IGNORE, PKG_PET_THEN_BLACKLIST_COMPAT_KIDS, PKG_REPOS_ENABLED
- [ -f $PKGS_DIR/DISTRO_COMPAT_REPOS ] && . $PKGS_DIR/DISTRO_COMPAT_REPOS #has repo URL related vars
- # set the package name suffix appended to combined pkgs (pkg+deps)
- CP_SUFFIX="WITHDEPS_${DISTRO_FILE_PREFIX}"
- # set correct arch for repo URLs (used by some slack-pup repos)
- case "$DISTRO_TARGETARCH" in
- x86) DBIN_ARCH=i486 ;;
- x86_64) DBIN_ARCH=x86_64 ; DSUFFIX=64 ;;
- *) DBIN_ARCH=i486 ;;
- esac
- # needed for some debian based repos
- case $DISTRO_COMPAT_VERSION in
- wheezy) DDB_COMP=bz2 ;; # older versions
- *) DDB_COMP=xz ;;
- esac
- # now create 'layers-installed': will contain builtins (and devx packages, if devx is loaded)
- #130511 need to include devx-only-installed-packages, if loaded...
- if which gcc &>/dev/null; then
- [ ! -f /tmp/ppm-layers-installed-packages ] && cp -f "$WOOF_INST_PKGS_FILE" /tmp/ppm-layers-installed-packages &>/dev/null
- cat "$PET_SPEC_DIR_DEFAULT/devx-only-installed-packages" >> /tmp/ppm-layers-installed-packages &>/dev/null
- sort -u /tmp/ppm-layers-installed-packages > "$LAYER_INST_PKGS_FILE" &>/dev/null
- else
- cp -f "$WOOF_INST_PKGS_FILE" "$LAYER_INST_PKGS_FILE" &>/dev/null
- fi
- # set $DIRECTSAVEPATH (where we want to install pkgs)
- if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ]; then
- DIRECTSAVEPATH="/initrd${SAVE_LAYER}" #SAVE_LAYER is in /etc/rc.d/PUPSTATE.
- elif [ "$PUPMODE" = "2" ]; then
- DIRECTSAVEPATH=""
- fi
- # s243a: Need the real path to avoid overwriting sylinks. See:
- # http://murga-linux.com/puppy/viewtopic.php?p=1030958#1030958
- # https://github.com/puppylinux-woof-CE/woof-CE/issues/1469#issuecomment-505706014
- [ -L "$DIRECTSAVEPATH" ] && DIRECTSAVEPATH="$(readlink "$DIRECTSAVEPATH")"
- # get repo details, workdir, search settings and so on.. you could
- # you can also add any ENVIRONMENT VARS above to PKGRC, to override the defaults
- . ${PKGRC}
- # set and create workdir if no valid dir set
- [ ! -d "$WORKDIR" ] && mkdir -p "$WORKDIR"
- if [ ! -d "$WORKDIR" ]; then
- error "Can't create $WORKDIR. Please create it."
- exit 3
- fi
- WORKDIR=~/pkg
- # add to tab completion settings to bashrc and print hint
- if [ -z "$PKG_TAB_COMPLETION" ]; then
- if [ "$(grep 'export PKG_TAB_COMPLETION=true' ~/.bashrc)" = "" ]; then
- # add to bashrc
- echo "" >> ~/.bashrc
- echo "# enable $APPNAME $APPVER TAB completion" >> ~/.bashrc
- echo "export PKG_TAB_COMPLETION=true" >> ~/.bashrc
- echo ". /etc/bash_completion.d/pkg 2>/dev/null" >> ~/.bashrc
- fi
- fi
- # make tmp dir writable by everyone if needed
- if [ ! -d "$TMPDIR" ]; then
- mkdir -p "$TMPDIR" 2>/dev/null
- chmod -R 1777 /tmp/pkg/ 2>/dev/null
- fi
- # if no tmp dir created or accessible, exit
- [ ! -d "$TMPDIR" ] && error "Cannot create temp dir ${lightblue}$TMPDIR${endcolour}" && exit 3
- # support aliases, create ALIASES tmp file
- 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'
- [ ! -f "$TMPDIR/pkg_aliases" ] && echo "$PKG_NAME_ALIASES" | tr ' ' '\n' > $TMPDIR/pkg_aliases
- # remove error code flag if we got here
- rm -f /tmp/pkg/error130 &>/dev/null
- # if not first run, and no options given, print the help
- [ ! -f ~/.pkg/firstrun -a "$1" = "" ] && $SELF -H && exit 1 #200913 more help by default
- #================== setup script vars =====================#
- set -a
- repo_file_list(){ # list available repo files, $1 optional FUNCLIST
- # we need to list these repos in the order defined in the RC file
- # so Pkg can 'fall back' to other repos in that order
- # get current config
- . ${PKGRC}
- # set vars for this func
- local list=''
- local repo_file=''
- local repo_files=`cut -f3 -d'|' ${HOME}/.pkg/sources`
- local current_fallback_list=`grep "^$REPONAME|" ${HOME}/.pkg/sources | cut -f8 -d'|' | grep -v "^\$"`
- # get current repo fallback list order.. note if repo not listed in fallback list, it will be appended after
- for line in $current_fallback_list
- do
- # get the repo file
- repo_file="`grep "^$line|" ${HOME}/.pkg/sources | cut -f3 -d'|'`"
- # add it to the list
- [ "$repo_file" != "" ] && list="$list$repo_file "
- done
- # now add all other avail repos to the end of fallback list
- for repo_file in $repo_files
- do
- #if not blank, not already in the repo list and not the current repo ($REPONAME from rc file) then add to list
- [ "$repo_file" != "" -a "`echo "$list" | grep "$repo_file "`" = "" -a "$repo_file" != "$REPOFILE" ] && list="$list$repo_file "
- done
- # list the current repo first
- echo $REPOFILE
- # then the other repos
- echo "$list" | tr ' ' '\n' | grep -v "^\$"
- }
- declare -ga REPO_DB_PATHS
- #mk_repo_file_list_arry(){
- #REPO_DB_PATHS=()
- #declare -A REPO_DB_PATHS
- #Can't put the loop in the loop in a pipeline if you want to assign array values:
- #https://stackoverflow.com/questions/13091700/why-is-my-array-gone-after-exiting-loop
- # repo_file_list |
- while read REPO_FILE_NAME; do
- #echo "REPO_FILE_NAME=$REPO_FILE_NAME"
- RF_FILE_PATH="${ALL_REPO_DB_PATHS[$REPO_FILE_NAME]}"
- if [ -e "$RF_FILE_PATH" ]; then
- REPO_DB_PATHS+=( "$RF_FILE_PATH" )
- fi
- done < <( repo_file_list )
- list_all_aliases_set_verify(){
- local verify
- declare -a verify_actions
- if [[ $2 = -* ]]; then
- verify=0 #Don't Verify aliases
- #echo "first if"
- #shift 1
- elif [[ -z "$2" ]]; then
- verify=0 #Don't Verify aliases
- #echo "second if"
- else
- verify=$2
- #echo "else"
- #shift 2
- fi
- #echo "exited if"
- case "$verify" in
- true|yes|1) verify=1; ;;
- false|no|0) verify=0; ;;
- fist|2) verify=2; ;; #Verify untill we know the version
- *)
- verify=3 #Specify the verify action.
- 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
- #shift 2
- ;;
- esac
- echo $verify
- if [ $verify=1 ]; then
- echo version
- else
- echo no-version
- fi
- if [ declare -p verify_actions ]; then
- for action in verify_actions; do
- echo "$action"
- done
- fi
- }
- # utility funcs
- #set -- gtk
- mk_AWK_prg(){
- local pkg_name=$1
- local version=$2
- local stripped_match
- declare -a options="$(getopt -o -pvsn --long package:,version:,stripped,--no-strip: -- $@)"
- eval set --"$options"
- while [ $# -gt 0 ]; do
- case "$1" in
- -s|--stripped) stripped_match=1; shift 1 ;; #For no this will be the default
- -n|--no-strip) stripped_match=0; shift 1 ;;
- -p|--package) package=$1; shift 2 ;;
- -v|--version) version=$1; shift 2 ;;
- --) shift 1; break ;;
- *) shift 1 ;;
- esac
- done
- for aArg in "$@"; do
- if [ ! -z "$aArg" ]; then #Not sure if we need to do this
- if [ -z "$pkg_name" ]; then
- pkg_name="$aArg"
- elif [ -z "$version" ]; then
- version="$aArg"
- else
- break
- fi
- fi
- done
- [ -z "$stripped_match" ] && stripped_match=1
- if [[ "$pkg_name" =~ ^[^0-9]*[0-9]*$ ]]; then
- stripped="$(echo $pkg_name | sed -e 's/[0-9]*$//g')"
- if [ -z $version ]; then
- version="$(echo $pkg_name | sed -r 's/[.*[!0-9]([0-9]*$)/\2/')"
- fi
- versioned=1 #Currently we don't do anything with this info.
- else
- stripped="$pkg_name"
- versioned=0
- fi
- #https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html
- if [ $stripped_match -eq 1 ] && [ ! -z "$version" ]; then
- if [ $versioned -eq 1 ]; then
- AWK_PRG=\
- " BEGIN{FS=\"|\"}
- {
- match(\$2,/^(.*[^:digit:])([:digit:]*$|$)/,pkg_split)
- match(\$3,/^[:digit:]*([^:digit:].*|$)/,version_split)
- if( \$2 == \"$pkg_name\" ) {
- print
- }
- else if ( pkg_split[1] == \"$stripped\" && version_split[1] == \"$version\" ) {
- print
- }
- }"
- else
- AWK_PRG=\
- " BEGIN{FS=\"|\"}
- {
- match(\$2,/^(.*[^:digit:])([:digit:]*$|$)/,pkg_split)
- match(\$3,/^[:digit:]*([^:digit:].*|$)/,version_split)
- if ( pkg_split[1] == \"$stripped\" && version_split[1] == \"$version\" ) {
- print
- }
- else if ( length(pkg_split) > 1 ) {
- if ( pkg_split[1] == \"$stripped\" && pkg_split[2] == \"$version\" ) {
- print
- }
- }
- }"
- fi
- elif [ $stripped_match -eq 1 ] && [ -z "$version" ]; then
- #AWK_PRG_No_Version=\
- #
- AWK_PRG=\
- " BEGIN{FS=\"|\"}
- {
- match(\$2,/^(.*[^:digit:])([:digit:]*$|$)/,pkg_split)
- if ( pkg_split[1] == \"$stripped\" ) {
- print
- }
- }"
- else #Exactly match the package name
- AWK_PRG=\
- " BEGIN{FS=\"|\"}
- {
- if ( \$2 == \"$pkg_name\" ) {
- print
- }
- }"
- fi
- echo "$AWK_PRG"
- #if [
- }
- #list_all_aliases(){
- # support pkg name aliases in finding packages
- #case "$i" in
- #1) subdep2="subdep"
- #2)
- # subdep2="$(echo subdep | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
- # if [ "$subdep" = "$subdep2" ]; then
- #
- # fi
- echo "$subdep2"
- #local ALIAS_LIST; local ALIAS; local ALIAS_RES; local subdep
- #local subdep_version; local subdep2; local subdep_stripped
- #local verify; local no_alias
- declare -a options="$(getopt -o v:l:p:m:: --long version:,list:,package:,meta::,verify::,no-alias -- $@)"
- declare -A verify_actions
- eval set -- "$options"
- while true; do
- case $1 in
- -v|--version)
- subdep_version=${2:-'%{version}'}; shift 2 ;;
- -l|--list)
- ALIAS_LIST_in="2"; shift 2; ;;
- -p|--package)
- subdep="$2"; shift 2; ;;
- -m|--meta)
- if [[ "$2" = -* ]] || [ -z "$2" ]]; then
- meta='db-index'; shift 1
- else
- meta="$2"; shift 2
- fi ;;
- --verify)
- while aResult in list_all_aliases_set_verify "$1" "$2"; do
- #verify_actions=("aResult")
- verify_actions[$aResult]=1
- done
- #if [ $verify_actions[version] -eq 1 ]; then
- # verify=1
- # &&
- #echo "WTF!"
- #unset 'verify_actions[0]'
- #shift 1; [[ "$1" = -* ]] && shift 1
- shift 2
- #May set
- #for aAction in version no-version min-version max-version spider download; do
- #
- #done
- ;;
- #--verify-type)
- --no-alias)
- if [[ $2 = -* ]] || [ -z "$2" ]; then
- no_alias=1; shift 1;
- else
- no_alias=$2; shift 2;
- fi
- {
- case "$no_alias" in
- true|yes|1) no_alias=1; ;;
- false|no|0) no_alias=0; ;;
- default|2) no_alias=2; ;;
- esac
- } ;;
- --)
- shift
- break; ;;
- -*|--*) #This should never happen
- echo "list_all_aliases(): unkown option '$1' '$2' "
- shift 2; ;;
- *) #This should never happen
- echo "list_all_aliases(): unkown paramater '$1' " 1>&2
- shift 1; ;;
- esac
- done
- if [ -z "$subdep" ]; then
- subdep="$1"; shift
- fi
- #if [ -z "$subdep_version" ]; then
- # subdep_version=${1:-'%{version}'}; shift
- #fi
- if [ -z "$ALIAS_LIST" ]; then
- ALIAS_LIST_in="$1"; shift
- fi
- [ -z "$verify" ] && verify=0
- if [ -z "$no_alias" ] || [ $no_alias -eq 2 ]; then
- if [ ! -z "$NO_ALIASES" ]; then
- case "$NO_ALIASES" in
- true) no_alias=1 ;;
- false) no_alias=0 ;;
- esac
- else
- no_alias=0;
- fi
- fi
- if [ -z "$ALIAS_LIST_in" ]; then
- if [ -f ${TMPDIR}/pkg_aliases ]; then
- ALIAS_LIST="${TMPDIR}/pkg_aliases"
- else
- ALIAS_LIST="$PKG_NAME_ALIASES"
- fi
- fi
- #We probably don't need to do this unless we are given a file name.
- subdep_stripped="$(echo "$subdep" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')"
- #but we need to strip the trailing number:
- #However, comment out the if condition for now because I don't know if it gives any performance gains
- #if [[ "$pkg_name" =~ ^[^0-9]*[0-9]*$ ]]; then
- subdep_stripped="$(echo $pkg_name | sed -e 's/[0-9]*$//g')"
- if [ -z "$subdep_version" ]; then
- subdep_version="$(echo $pkg_name | sed -r 's/[.*[!0-9]([0-9]*$)/\1/')"
- fi
- #fi
- if [ -e "$ALIAS_LIST" ]; then #ALIAS_LIST is a file
- ALIAS_LIST1=( `grep -E "$subdep_stripped"'([,]|$)' "$ALIAS_LIST" 2>/dev/null | tr ',' ' '` )
- else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string
- ALIAS_LIST1=( $(echo "$ALIAS_LIST" | tr ' ' '\n' | grep -E "$subdep_stripped"'([,]|$)' 2>/dev/null | tr ',' '\n') )
- fi
- subdep_old=subdep_version #We don't use this yet.
- subdep_version="${subdep_version%%.*}"
- if [ ! -z "$subdep_version" ] && [ -z "$ALIAS_LIST2" ]; then
- if [ "$subdep_versioned" != "$subdep" ]; then
- subdep_versioned="$subdep"
- subdep_versioned2="$subdep_stripped$subdep_versioned"
- else
- subdep_versioned="$subdep_stripped$subdep_versioned"
- fi
- if [ -e "$ALIAS_LIST_in" ]; then #ALIAS_LIST is a file
- ALIAS_LIST2=( `grep -E "$subdep_versioned"'([,]|$)' "$ALIAS_LIST" 2>/dev/null | tr ',' ' '` )
- else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string
- ALIAS_LIST2=( $(echo "$ALIAS_LIST_in" | tr ' ' '\n' | grep -E "$subdep_versioned"'([,]|$)' 2>/dev/null | tr ',' '\n') )
- fi
- #for ALIAS in "${ALIAS_LIST2}"; do
- #
- #done
- fi
- if [ ! -z "$subdep_version2" ] && [ -z "$ALIAS_LIST3" ]; then
- if [ -e "$ALIAS_LIST_in" ]; then #ALIAS_LIST is a file
- ALIAS_LIST3=( `grep -E "$subdep_versioned2"'([,]|$)' "$ALIAS_LIST" 2>/dev/null | tr ',' ' '` )
- else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string
- ALIAS_LIST3=( $(echo "$ALIAS_LIST_in" | tr ' ' '\n' | grep -E "$subdep_versioned2"'([,]|$)' 2>/dev/null | tr ',' '\n') )
- fi
- fi
- ###################TODO combine alias lists######################
- if [ "$subdep_stripped" = "$sudep" ]; then
- subdep2="$subdep$subdep_version"
- else
- subbdep2="$subdep_stripped"
- fi
- declare -A result
- declare -A aliases
- echo "no_alias=$no_alias"
- if [ $no_alias -eq 1 ]; then
- result[0]="$subdep"
- result[1]="$subdep2"
- elif [ $no_alias -eq 0 ]; then
- # if we have some results to parse
- # get the list of aliases
- #ALIAS_LIST="`grep -m1 "$1" $TMPDIR/pkg_aliases 2>/dev/null | tr ',' ' '`";
- # for each alias
- #if [ ${verify_actions[version]} -eq 1 ]; then
- alias_index=0
- for ALIAS in "${ALIAS_LIST1[@]}" "${ALIAS_LIST2[@]}" "${ALIAS_LIST3[@]}"; do
- #while read ALIAS; do
- key=md5_`md5sum < <( echo "$ALIAS" ) | cut -f1 -d' '`
- if [ -z "${aliases[$key]}" ]; then
- alias_index=$((alias_index+1))
- remaining_aliases[$key]="$ALIAS"
- alias_keys[$alias_index]=$key
- aliases[$key]="$ALIAS"
- fi
- done
- #done < <( echo $ALIAS_LIST )
- #N_ALIAS=#alias_index
- if [ -z $subdep_version ]; then
- more_aliases=true
- else
- more_aliases=last
- fi
- new_version=0
- db_index=0
- #The Alias list should be sorted by our repo order. In other words the repo order defines the priority.
- while [ $db_index -lt ${#REPO_DB_PATHS[@]} ]; do
- #for aRepoDB in "$REPO_DB_FILE_DIR/${REPOFILE}"; do
- aRepoDB=${REPO_DB_PATHS[$db_index]}
- #while [ ! "$more_aliases" = done ]; do #TODO do we need this loop (see next for loop)#################
- #alias_index=0 #We could use this instead of loop through the keys
- for key in "${!remaining_aliases[@]}"; do
- ALIAS="${remaining_aliases[$key]}"
- alias_index=alias_indexs[$key]
- [ "$ALIAS" = '' ] && continue
- if [ ! -z "${verify_actions[version]}" ] && [ ${verify_actions[version]} -eq 1 ]; then
- AWK_PRG="$(mk_AWK_prg $subdep $subdep_version)"
- else
- AWK_PRG="$(mk_AWK_prg $subdep)"
- fi
- awk_result="$(cat $aRepoDB | awk "$AWK_PRG")"
- if [ ! -z "$awk_result" ]; then
- if [ -z "$subdep_version" ]; then #TODO think about if we should do this when we aren't verifing the version
- subdep_version="${awk_result[3]}"
- subdep_version="${subdep_version%%.*}"
- alias_index2=$N_ALIAS
- #more_aliases=last
- ##########TODO create array of new alasises
- alias_index2=${#aliases[@]}
- new_version=0
- for ALIAS2 in "${ALIAS_LIST[@]}"; do #TODO make sure the variable ALIAS2 doesn't conflict with anything
- ALIAS3="$ALIAS2$subdep_version"
- key2=md5_`md5sum < <( echo "$ALIAS3" ) | cut -f1 -d' '`
- if [ -z "${aliases[$key2]}" ]; then
- new_version=1
- #key=`md5sum < <( echo "$ALIAS" ) | cut -f1 -d' '`
- remaining_aliases[$key]="$ALIAS3"
- alias_keys[$alias_index2]=$key
- aliases[$key]="$ALIAS3"
- alias_index2=$((alias_index++))
- alias_indexs[$key2]=$alias_index2
- fi
- done
- if [ $new_version -eq 1 ]; then
- db_index=-1 #Start over at the first DB.
- break 2
- fi
- fi
- result[$key]="$ALIAS"
- #[ ! -z "alias_indexes[$key]" ] || alias_indexes[$key]=$alias_index
- [ ! -z "db_indexes[$key]" ] || db_indexes[$key]=$db_index
- if [ ! -z "$subdep_version" ] && [ ${verify_actions[$subdep_version]} -eq 1]; then
- checks_done[$key]=entry,version
- else
- checks_done[$key]=entry
- fi
- if [ $i -gt 0 ]; then
- unset "remaining_aliases[$key]"
- var=$((var +1))
- fi
- fi
- done
- db_index=$((db_index + 1))
- done
- fi
- for aKey in ${!result[@]}; do
- echo "akey=$aKey"
- alias="${result[$aKey]}"
- if [ "$ALIAS" != subdep ] || [ $all -eq 1 ]; then
- echo "${result[$aKey]}"
- fi
- done #| sort
- #}
- #list_all_aliases "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement