Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#!/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 lib_version else echo no_lib_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 local version local stripped_match local awk_cmp_ary='' local n_cmp=0 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: -- $@)" eval set --"$options" while [ $# -gt 0 ]; do case "$1" in -f|--full-version) full_version=$1; shift 2;; #Not yet implemented -l|--lib-version) lib_version=$1; shift 2;; -m|--min-version|--ge) n_cmp=$((n_cmp+1)) awk_cmp_ary_op="$awk_cmp_ary_op"$'\n'"awk_cmp_ary_op[$n_cmp]=\"ge\"" awk_cmp_ary_val="$awk_cmp_ary_val"$'\n'"awk_cmp_ary_val[$n_cmp]=\"$2\"" shift 2 ;; -n|--no-strip) stripped_match=0; shift 1 ;; -p|--package) package=$1; shift 2 ;; -s|--stripped) stripped_match=1; shift 1 ;; #For no this will be the default -u|--upper-version|--max-version|--le) n_cmp=$((n_cmp+1)) awk_cmp_ary_op="$awk_cmp_ary_op$'\n'awk_cmp_ary_op[$n_cmp]=\"le\"" awk_cmp_ary_val="$awk_cmp_ary_val$'\n'awk_cmp_ary_val[$n_cmp]=\"$2\"" shift 2 ;; -v|--version) #Compare version only to the precsion given n_cmp=$((n_cmp+1)) awk_cmp_ary_op="$awk_cmp_ary_op$'\n'awk_cmp_ary_op[$n_cmp]=\"e\"" awk_cmp_ary_val="$awk_cmp_ary_val$'\n'awk_cmp_ary_val[$n_cmp]=\"$2\"" shift 2 ;; --gt) n_cmp=$((n_cmp+1)) awk_cmp_ary_op="$awk_cmp_ary_op$'\n'awk_cmp_ary_op[$n_cmp]=\"gt\"" awk_cmp_ary_val="$awk_cmp_ary_val$'\n'awk_cmp_ary_val[$n_cmp]=\"$2\"" shift 2 ;; -lt) n_cmp=$((n_cmp+1)) awk_cmp_ary_op="$awk_cmp_ary_op$'\n'awk_cmp_ary_op[$n_cmp]=\"lt\"" awk_cmp_ary_val="$awk_cmp_ary_val$'\n'awk_cmp_ary_val[$n_cmp]=\"$2\"" 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" lib_version=$1 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 lib_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 #TODO write a script to look up the version range from the lib version. if [ $n_cmp -gt 0 ]; then AWK_Functions="\ function version_split(version1,version_array,split_chars, i1,remainder1,matches,num1_epoch_split){ #print \"version1=\" version1 match(version1,/([[:digit:]])*:(.*|$)/,num1_epoch_split) if (length(num1_epoch_split) > 0 ){ version_array[1]=num1_epoch_split[1] remainder1=num1_epoch_split[2] } else { version_array[1]=0 remainder1=version1 } delete num1_epoch_split split_chars[1]=\":\" i1=2 #match(remainder1,/^([^+\.\-~:]+)(([+\.~])([^+\.~\-:]+))*((\-)([^+\.~\-:])+)?$/,matches) #match(remainder1,/^([^+\.\-~:]+)(([+\.\-~:])(.*))?$/,matches) match(remainder1,/^([[:digit:]]+)(([+\.\-~:])(.*))?$/,matches) while (length(matches) > 0) { version_array[i1]=matches[1] #print \"version_array[\" i1 \"]=\" version_array[i1] if (length(matches)>1){ split_chars[i1]=matches[3] #print \"split_chars[\" i1 \"]=\" split_chars[i1] remainder1=matches[4] #print \"remainder1=\" remainder1 #match(remainder1,/^([^+\.\-~:]+)(([+\.\-~:]+)(.*))?$/,matches) match(remainder1,/^([[:digit:]]+)(([+\.\-~:]+)(.*))?$/,matches) } else{ break } i1=i1+1 } } function v_le(ver_split, val_split, len_ver){ return v_ge(val_split,ver_split) } function v_ge(ver_split, val_split, len_ver){ #print \"v_ge\" if (length(ver_split)<length(val_split)){ len_ver=length(ver_split) } else{ len_ver=length(val_split) } for (i=1; i<=len_ver; i++){ #print \"ver_split[\" i \"]=\" ver_split[i] #print \"val_split[\" i \"]=\" val_split[i] if ( ver_split[i] < val_split[i] ) return 0 if ( ver_split[i] > val_split[i] ) return 1 } #print \"finished ge compare\" #print \"length_ver_split=\" length(ver_split) #print \"length_val_split=\" length(val_split) if ( length(ver_split) >= length(val_split) ) return 1 else return 0 } function v_gt(num1, num2, le){ ge = v_ge(num2,num1) if ( ge == 1 ){ return 0 } else { return 1 } } function v_lt(num1, num2){ return v_gt(num2, num1) } #An equal-ish functions. function v_e(ver_split, val_split, len_ver){ if (length(ver_split)<length(val_split)) len_ver=length(ver_split) else len_ver=length(val_split) for (i=1; i<len_ver; i++){ if (version_array1[i] != version_array2[i]) return 0 } return 1 } function arry_cmp(version,ops_array,val_array){ #print \"test\" version_split(version,ver_split,ver_split_chars) for (i=1; i<=length(ops_array); i++){ #print \"Ops_array \" ops_array[i] \" \" val_array[i] version_split(val_array[i],val_split,val_split_chars) #https://www.gnu.org/software/gawk/manual/gawk.html#Switch-Statement switch(ops_array[i]){ case \"<\": case \"lt\": if (v_lt(ver_split,val_split) == 0 ){ return 0 } break case \">\": case \"gt\": if (v_gt(ver_split,val_split) == 0 ){ return 0 } break case \"<=\": case \"le\": if (v_le(ver_split,val_split) == 0 ){ return 0 } break case \">=\": case \"ge\": if (v_ge(ver_split,val_split) == 0 ){ return 0 } break case \"==\": case \"e\": if (v_e(ver_split,val_split) == 0 ){ return 0 } break } #https://unix.stackexchange.com/questions/147957/delete-an-array-in-awk delete val_split delete val_split_chars } #print \"returning result=1\" return 1 } " CMP_Function="arry_cmp(\$3,awk_cmp_ary_op,awk_cmp_ary_val)" AWK_Print2="\ if ( $CMP_Function == 1 ){ print }" else AWK_Functions='' CMP_Function='' AWK_Print2="\ print " fi AWK_Print2="\ if ( $CMP_Function ){ print }" #https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html if [ $stripped_match -eq 1 ]; then AWK_PRG=$AWK_Functions\ " BEGIN{FS=\"|\" $awk_cmp_ary_op $awk_cmp_ary_val } { if( \$2 == \"$pkg_name\") { $AWK_Print2 } else{ match(\$2,/^(.*[^[:digit:]])([[:digit:]]*$|$)/,pkg_split) if ( pkg_split[1] == \"$stripped\" ) { $AWK_Print2 } } delete pkg_split }" else #Exactly match the package name AWK_PRG=$AWK_Functions \ " BEGIN{FS=\"|\" $awk_cmp_ary_op $awk_cmp_ary_val } { if ( \$2 == \"$pkg_name\" ) { $AWK_Print2 } delete pkg_split }" fi echo "$AWK_PRG" #if [ } function echo_alias_list(){ local subdep=$1 local ALIAS_LIST=$2 if [ -e "$ALIAS_LIST" ]; then #ALIAS_LIST is a file ALIAS_LIST1=( $(grep -E "$subdep"'([,]|$)' "$ALIAS_LIST" 2>/dev/null | tr ',' ' ') ) else #[[ "$ALIAS_LIST" = *,* ]]; then #ALIAS_LIST is string ALIAS_LIST1=( $(echo "$ALIAS_LIST" | tr ' ' '\n' | grep -E "$subdep"'([,]|$)' 2>/dev/null | tr ',' '\n') ) fi for aAlias in "${ALIAS_LIST1[@]}"; do echo "$aAlias" done } function echo_aliases(){ local subdep_stripped local subdep local lib_version local ALIAS_LIST_in local versioned declare -a ALIAS_LIST1 declare -a ALIAS_LIST2 declare -a ALIAS_LIST3 declare -a options while read option; do options+=( "$option" ) done < <(getopt --long no-strip::,no-self:: -o '' -- "$@") declare -a self eval set -- "${options[@]}" while [ $# -gt 0 ]; do case $1 in --no-strip) if [[ $2 = -* ]]; then no_strip=1; shift 1 else no_strip=$2; shift 2 fi ;; --no-self) if [[ $2 = -* ]]; then no_self=1; shift 1 else no_self=$2; shift 2 fi ;; --) shift; break; ;; *) #This should never happen if [[ $2 = -* ]]; then shift 1; else shift 2; fi ;; esac done [ -z "$no_self" ] && no_self=0 [ $no_self -eq 0 ] && self=("$subdep") [ -z "$no_strip" ] && no_strip=0 if [ ! -z "$3" ]; then lib_version=$2; ALIAS_LIST=$3 subdep=$1 if [[ "$1" =~ ^.*[^0-9][0-9]+$ ]]; then versioned=1 subdep_stripped=${1%"$lib_version"} else versioned=0 subdep_vesioned="$subdep$lib_version" fi #subdep=$subdep_stripped$lib_version else if [[ "$1" =~ ^.*[^0-9][0-9]+$ ]]; then versioned=1 subdep=$1 lib_version="$(echo $subdep | sed -r 's/.*[^0-9]([0-9]*)$/\1/')" subdep_stripped="$(echo $subdep | sed -r 's/(^.*[^0-9])([0-9]+)$/\1/')" if [ ! -z "$2" ]; then ALIAS_LIST_in=$2 else ALIAS_LIST_in="$ALIAS_LIST" fi else versioned=0 #subdep_stripped=$1 subdep=$1 #subdep_stripped=$subdep if [[ "$2" =~ ^[0-9]+$ ]]; then lib_version=$2 subdep_versioned="$subdep$lib_version" ALIAS_LIST_in="$ALIAS_LIST" else ALIAS_LIST_in="$2" fi fi fi if [ $no_strip -eq 0 ] || [ $versioned -eq 0 ]; then [ -z "$subdep_stripped" ] && subdep_stripped=$subdep for aAlias in $(echo_alias_list "$subdep_stripped" "$ALIAS_LIST_in"); do ALIAS_LIST1+=($aAlias) if [ -z lib_version ]; then if [[ "$aAlias" =~ ^.*[^0-9][0-9]+$ ]]; then lib_version="$(echo $aAlias | sed -r 's/[.*[!0-9]([0-9]*$)/\1/')" fi fi done fi [ -z "$subdep_stripped" ] && subdep_stripped=$subdep [ -z "$subdep_versioned" ] && [ ! -z $lib_version ] && subdep_versioned="$subdep_stripped$lib_version" #subdep_old=subdep_version #We don't use this yet. #subdep_version="${subdep_version%%.*}" if [ ! -z "$subdep_versioned" ] || [ $versioned -eq 1 ]; then [ -z "$subdep_versioned" ] && subdep_versioned=$subdep 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 lib_version ] && [ $no_strip -eq 0 ]; then for aAlias in "$subdep_stripped" "${ALIAS_LIST1[@]}"; do if [[ "$aAlias " =~ ^.*[^0-9][0-9]+$ ]]; then continue fi ALIAS_LIST3+=("$aAlias$lib_version") done fi local key declare -A result for ALIAS in "${self[@]}" "${ALIAS_LIST2[@]}" "${ALIAS_LIST3[@]}" "${ALIAS_LIST1[@]}"; do key=md5_$(md5sum < <( echo "$ALIAS" ) | cut -f1 -d' ') if [ -z "${result[$key]}" ]; then result[$key]="$ALIAS" fi done for ALIAS in "${result[@]}"; do echo "$ALIAS" done } ################################################################ 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 lib_version; local subdep2; local subdep_stripped local verify; local no_alias local s_ALIAS declare -a options="$(getopt -o v:l:p:m:: --long version:,list:,package:,meta::,verify::,no-alias,gt:,lt:,le:,ge: -- "$@")" declare -A verify_actions declare -a awk_args declare -A lib_versions awk_args=() eval set -- "${options[@]}" while [ $# -gt 0 ]; do case $1 in -v|--lib-version) #subdep_version=${2:-'%{version}'}; shift 2 ;; lib_version=${2}; 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 shift 2 ;; --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 } ;; --gt|--lt|--le|--ge) awk_args+=($1) awk_args+=($2) shift 2 ;; --) 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 [ ${#verify_actions[@]} -eq 0 ]; then #verify_actions[lib_version]=1 verify_actions[entry]=1 if [ ! -z $lib_version ]; then verify_actions[lib_version]=1 fi fi 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_in="${TMPDIR}/pkg_aliases" else ALIAS_LIST_in="$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 "$lib_version" ]; then lib_version="$(echo $pkg_name | sed -r 's/[.*[!0-9]([0-9]*$)/\1/')" 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 declare -A remaining_s_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=-1 alias_s_index=-1 for ALIAS in `echo_aliases $subdep $ALIAS_LIST_in`; do #while read ALIAS; do key=md5_$(md5sum < <( echo "$ALIAS" ) | cut -f1 -d' ') if [ -z "${aliases[$key]}" ]; then alias_stripped="$(echo "$ALIAS" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')" skey=md5_$(md5sum < <( echo "$alias_stripped" ) | cut -f1 -d' ') if [ -z "${stripped_aliases[$skey]}" ]; then stripped_aliases[$skey]="$alias_stripped" alias_s_index=$((alias_s_index+1)) alias_s_keys[$alias_index]=$skey s_aliases[$key]="$alias_stripped" fi alias_index=$((alias_index+1)) 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. local lib_version_index=-1 local first_lib_version_index while [ $db_index -lt ${#REPO_DB_PATHS[@]} ]; do if [ $db_index -eq 0 ]; then unset 'remaining_aliases' unset 'remaining_s_aliases' declare -A remaining_aliases declare -A remaining_s_aliases for key_i in ${aliases[!@]}; do remaining_aliases[$skey_i]=aliases[$key_i] aAlias=${aliases[$key_i]} stripped_alias="$(echo "$aAlias" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')" skey_i=md5_$(md5sum < <( echo "$stripped_alias" ) | cut -f1 -d' ') if [ -z "${remaining_s_aliases[$skey_i]}" ]; then if [ "$stripped_alias" = "$aAlias" ]; then remaining_s_aliases[$skey_i]=1 else remaining_s_aliases[$skey_i]=2 fi else remaining_s_aliases[$skey_i]=$(expr ${remaining_s_aliases[$skey_i]} + 1) fi done unset 'result' declare -A result fi lib_version_index=$((lib_version_index + 1)) #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 for s_key in "${!remaining_s_aliases[@]}"; do s_ALIAS="${remaining_s_aliases[$s_key]}" #alias_index=alias_indexs[$key] [ "$s_ALIAS" = '' ] && continue #We probably don't need this statment. #TODO figure out why I"m using an if here. if [ ! -z "${verify_actions[lib_version]}" ] && [ ${verify_actions[lib_version]} -eq 1 ]; then AWK_PRG="$(mk_AWK_prg $s_ALIAS ${awk_args[@]})" else AWK_PRG="$(mk_AWK_prg $s_ALIAS ${awk_args[@]})" fi awk_results="$(cat $aRepoDB | awk "$ AWK_PRG")" # https://stackoverflow.com/questions/10586153/split-string-into-an-array-in-bash #awk_result=readarray -td '' awk_result < <(awk '{ gsub(/, /,"\0"); print; }' <<<"$awk_result_tmp, "); unset 'a[-1]'; # declare -p a; if [ ! -z "$awk_results" ]; then while read a_awk_result; do ar_i=1 #Put the awk result into an array while read aRecord; do awk_result[$ar_i]="$aRecord" ar_i=$((ar_i+1)) done < <(cat <<<"$(echo "$a_awk_result" | tr '|' '\n')") ALIAS=awk_result[2] #Fetch the package nmae (2nd field) key=md5_$(md5sum < <( echo "$ALIAS" ) | cut -f1 -d' ') #TODO don't add new lib version if we specify a specific lib version. this_lib_version="$(echo $ALIAS | sed -r 's/(.*[^0-9])([0-9]*$)/\2/')" 2>/dev/null if [ -z "${lib_versions[$lib_version]}" ] || ] ; then lib_versions[$lib_version]="$lib_version_index|${awk_result[1]}|${awk_result[2]}|${awk_result[3]}|\"$aRepoDB\"" new_lib_version=1 elif [ "${lib_versions[$lib_version]}" = "NULL" ]; then lib_versions[$lib_version]="$lib_version_index|${awk_result[1]}|${awk_result[2]}|${awk_result[3]}|\"$aRepoDB\"" else lib_versions[$lib_version]="${lib_versions[$lib_version]}"$'\n'"$lib_version_index|${awk_result[1]}|${awk_result[2]}|${awk_result[3]}|\"$aRepoDB\"" fi #Remove the lib number from the end of the package name alias_stripped="$(echo "$ALIAS" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')" skey=md5_$(md5sum < <( echo "$alias_stripped" ) | cut -f1 -d' ') if [ -z result[$key] ]; then result[$key]="$ALIAS" if [ ! -z "$lib_version" ] && [ ${verify_actions[lib_version]} -eq 1 ]; then checks_done[$key]=entry,lib_version else checks_done[$key]=entry fi if [ $i -gt 0 ]; then unset "remaining_aliases[$key]" var=$((var +1)) fi fi #if [ $new_lib_version -eq 1 ]; then if [ $new_alias -eq 1 ]; then for ALIAS3 in `echo_aliases $ALIAS --no-strip`; do key2=md5_$(md5sum < <( echo "$ALIAS3" ) | cut -f1 -d' ') if [ -z "${aliases[$key2]}" ]; then aliases[$key2]="$ALIAS3" alias_stripped2="$(echo "$ALIAS" | sed -e 's/++/+++/g' -e 's/+[a-z0-9].*//g')" skey2=md5_$(md5sum < <( echo "$alias_stripped2" ) | cut -f1 -d' ') if [ -z "${stripped_aliases[$skey2]}" ]; then new_s_version=1 stripped_aliases[$skey]="$alias_stripped2" fi fi done fi done <<<"$awk_results" if [ $new_version -eq 1 ]; then db_index=-1 #Start over at the first DB. new_lib_version=0 unset 'this_lib_version' break 2 fi #fi #[ ! -z "alias_indexes[$key]" ] || alias_indexes[$key]=$alias_index [ ! -z "db_indexes[$key]" ] || db_indexes[$key]=$db_index 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 "$@"
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
⭐⭐ Crypto Swap Glitch ✅ Easy money ⭐⭐
JavaScript | 5 min ago | 0.67 KB
⭐⭐ Free Crypto Method ⭐⭐ ✅
JavaScript | 15 min ago | 0.67 KB
Nano_button_led_hc05
C++ | 23 min ago | 1.50 KB
Infinite Money Glitch
JavaScript | 25 min ago | 0.67 KB
🔥🔥🔥 Swapzone Trading Glitch 🔥🔥🔥
JavaScript | 35 min ago | 0.67 KB
⭐⭐ Instant Money Method ⭐⭐ ✅
JavaScript | 46 min ago | 0.67 KB
⭐⭐ FREE BTC GUIDE ✅ Working ⭐⭐
JavaScript | 56 min ago | 0.67 KB
VanillaAmmoCraftsRecipes.json
JSON | 59 min ago | 78.72 KB
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
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!