SHARE
TWEET

testcat(3)

s243a Dec 14th, 2019 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/ash
  2. PKG_AWK_slack2pup_ProgramFILE_out=~/AWK_gen_prg
  3. #PKG_AWK_slack2pup_ProgramFILE_in=~/AWK_gen_prg
  4. #The defaults are input
  5. [ -z "$outfile" ] && outfile=~/testcat.in
  6. #cat_file=/usr/local/petget/categories.dat
  7. [ -z "$category_file" ] && category_file=~/cat_test_cat.dat
  8. PACKAGES_PATH=~/SLACKO_TEST.in
  9. [ -z "$distro" ] && distro=slackware
  10. [ -z "$distro_ver" ] && distro_ver="14.2"
  11. #For testing we can write the generated awk function to a file by setting the path to the enviornmental variable: PKG_AWK_slack2pup_ProgramFILE_out
  12. #Alternatively we can use an AWK file we previously created instead of generating a new one by setting the enviornmental variable: PKG_AWK_slack2pup_ProgramFILE_in
  13. #to point to the file location. If the file does not exist then it will be generated.
  14. [ -z "$PKG_AWK_slack2pup_ProgramFILE_in" ] && PKG_AWK_slack2pup_ProgramFILE_in="$(realpath "$PKG_AWK_slack2pup_ProgramFILE_out")"
  15.  
  16. #Input the functions (by sourcing build_cannonical):  
  17. #  get_canonical_name(s); // Returns a single name for all packages of the same alias  
  18. #  init_CANONICAL_ARY();  // Maps an alias name (without wildcards) to a cannonical name
  19. #  **As a string named "ALIAS_FNS"
  20. #
  21. #  cat_fallback(s); // Fallback categories for known "deb" categories (translates the PKGSECTION field of the debian repo)
  22. #  get_category(s); // Get's the category based on the package name (fallbacks and aliases are used)
  23. #  parse_cats(s); Parses one line of /usr/local/petget/categorie.dat, where the package name is put into the key of an assoiative array and the value is the category
  24. #  **As a string named CATEGORY_FNS
  25. #  CATEGORY_BLOCK='FILENAME = CATFILE {parse_cats($0)}' // This is the AWK structure of the form, "Pattern {action}" see:  https://www3.physnet.uni-hamburg.de/physnet/Tru64-Unix/HTML/APS32DTE/WKXXXXXX.HTM?fbclid=IwAR1yoK_NtaAKyR7gZsELg3eiCkpoPIllBbH8q44c6SZykIitwR0MW6zNEnI
  26. . ~/build_cannonical
  27.  
  28.  
  29.            
  30. AWK_PRG=\
  31. 'function fixdepends(s,   p,a,sout,n) {
  32.     split(s,a,",")
  33.     for (p in a) {
  34.       sout = sout ",+" a[p]
  35.     }
  36.     sub(/^,/,"",sout) ; return sout;
  37. }
  38. function parse_pkg_name(s,        txz_split,arch_build){
  39.     match(s,/^([^\-]*)(\-.*)(\.([^\-]+))$/,txz_split)
  40.  
  41.     PKG=txz_split[1]
  42.     split(txz_split[2],ver_arch_build,"-") 
  43.     PKGVER=ver_arch_build[2]
  44.  
  45.     len=length(ver_arch_build)
  46.    if (len == 4){
  47.         BUILD_NO=ver_arch_build[4]
  48.         ARCH=ver_arch_build[3]
  49.    }
  50.    else if(len == 3){
  51.       if (ver_arch_build[len-1] ~ /^[0-9]+$/){
  52.         BUILD_NO=ver_arch_build[2]
  53.        }
  54.        else{
  55.            ARCH=ver_arch_build[3]
  56.       }
  57.    }  
  58.    
  59. }
  60. function maybe_parse_dec(s,        line_split){
  61.  if( PARSE_DEC_FLAG == 1){
  62.     match($0,/(\S+):\s+(.*)$/,line_split)
  63.     if(length(line_split) > 0){
  64.       if (line_split[1] == PKG){
  65.         PKGINFO=substr(line_split[2],1,200)
  66.         PARSE_DEC_FLAG=0
  67.       }
  68.    }
  69.  }
  70. }
  71. '"$(cat_macro_fn "$CATEGORY_FNS")
  72. $ALIAS_FNS
  73. "'BEGIN { init_CANONICAL_ARY() #MAPS a PKG NAME to a canonical name
  74.       }
  75. #FILENAME = ALIASFILE { }
  76. '"$(cat_macro_fn "$CATEGORIES_INIT_BLOCK")
  77. "'/^PACKAGE NAME:/     { sub(/^PACKAGE NAME:\s*/,""); PKGFILE=$0; parse_pkg_name($0); getline; }
  78. /^PACKAGE LOCATION:/     { sub(/^PACKAGE LOCATION:\s*/,""); sub(/^(.\/)?/,""); PKGPATH=$0; next; }
  79. /^PACKAGE SIZE \(uncompressed\):/ { sub(/^PACKAGE SIZE \(uncompressed\):\s*/,""); sub(/\s/,""); PKGSIZE=$0; next; }
  80. /^PACKAGE DESCRIPTION:/ { PARSE_DEC_FLAG=1; getline;  next; }
  81. /^PACKAGE REQUIRED:/ { sub(/^PACKAGE REQUIRED:\s*/,"");     PKGDEP=fixdepends($0);  next; }
  82. {maybe_parse_dec($0)}                      
  83. /^$/            {
  84.  if (length(PKG)>1){
  85. '"""""$(comment_macro 'Look up the category based on the package name if PKG_FIX_CATEGORIES_in_REPO_DB=true ')
  86.      $(cat_macro_fn "PKGSECTION=get_category(PKG,PKGVER,PKGSECTION)")
  87. "'  print PKG "_" PKGVER "|" PKG "|" PKGVER "|"  BUILD_NO "|" PKGSECTION "|" PKGSIZE "|" PKGPATH "|" PKGFILE  "|" PKGDEP "|" PKGINFO "|" PKGOS "|" PKGOSVER  "|"
  88.  };
  89.    
  90.                  PKG=""; PKGVER=""; PKGSECTION=""; PKGSIZE=""; PKGFILE=""; PKGPATH=""; PKGDEP=""; PKGINFO=""; PKGPRIO="";   BUILD_NO="";  ARCH=""; PARSE_DEC_FLAG=0; }
  91. '
  92.  
  93. #echo "$AWK_PRG"
  94. set -x
  95. if [ -z "$PKG_AWK_slack2pup_ProgramFILE_in" ]; then
  96.  awk -v PKGOS="$distro" -v PKGOSVER="$distro_ver" -v CATFILE="$category_file" -v ALIASFILE="$alias_file" \
  97.         "$AWK_PRG" "$alias_file" "$category_file" "$PACKAGES_PATH"
  98. else
  99. if [ ! -z "$PKG_AWK_slack2pup_ProgramFILE_out" ]; then
  100.   echo "#!`which gawk` -f" > "$PKG_AWK_slack2pup_ProgramFILE_out"
  101.    echo "$AWK_PRG" >> "$PKG_AWK_slack2pup_ProgramFILE_out"
  102.    chmod +x "$PKG_AWK_slack2pup_ProgramFILE_out"
  103.  fi
  104.  awk -v PKGOS="$distro" -v PKGOSVER="$distro_ver" -v CATFILE="$category_file" -v ALIASFILE="$alias_file" \
  105.      -f "$PKG_AWK_slack2pup_ProgramFILE_in" -- "$alias_file" "$category_file" "$PACKAGES_PATH"
  106. fi
  107. #cat "$cat_file"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top