Advertisement
s243a

testcat (2)

Dec 14th, 2019
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.57 KB | None | 0 0
  1. #!/bin/ash
  2. PKG_AWK_slack2pup_ProgramFILE_out=~/AWK_gen_prg
  3. #The defaults are input
  4. [ -z "$outfile" ] && outfile=~/testcat.in
  5. #cat_file=/usr/local/petget/categories.dat
  6. [ -z "$category_file" ] && category_file=~/cat_test_cat.dat
  7. PACKAGES_PATH=~/SLACKO_TEST.in
  8. #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
  9. #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
  10. #to point to the file location. If the file does not exist then it will be generated.
  11. [ -z "$PKG_AWK_slack2pup_ProgramFILE_in" ] && PKG_AWK_slack2pup_ProgramFILE_in="$(realpath "$PKG_AWK_slack2pup_ProgramFILE_out")"
  12.  
  13. #Input the functions (by sourcing build_cannonical):  
  14. #  get_canonical_name(s); // Returns a single name for all packages of the same alias  
  15. #  init_CANONICAL_ARY();  // Maps an alias name (without wildcards) to a cannonical name
  16. #  **As a string named "ALIAS_FNS"
  17. #
  18. #  cat_fallback(s); // Fallback categories for known "deb" categories (translates the PKGSECTION field of the debian repo)
  19. #  get_category(s); // Get's the category based on the package name (fallbacks and aliases are used)
  20. #  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
  21. #  **As a string named CATEGORY_FNS
  22. #  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
  23. . ~/build_cannonical
  24.  
  25.  
  26.            
  27. AWK_PRG=\
  28. 'function fixdepends(s,   p,a,sout) {
  29.     split(s,a,",")
  30.     for (p in a) {
  31.         sout = sout ",+" a[p]
  32.     }
  33.     sub(/^,/,"",sout) ; return sout;
  34. }
  35. function parse_pkg_name(s,        txz_split,arch_build){
  36.     match(s,/^([^\-]*)(\-.*)(\.([^\-]+))$/,txz_split)
  37.  
  38.     PKG=txz_split[1]
  39.     split(txz_split[2],ver_arch_build,"-") 
  40.     PKGVER=ver_arch_build[2]
  41.  
  42.     len=length(ver_arch_build)
  43.    if (len == 4){
  44.         BUILD_NO=ver_arch_build[4]
  45.         ARCH=ver_arch_build[3]
  46.    }
  47.    else if(len == 3){
  48.       if (ver_arch_build[len-1] ~ /^[0-9]+$/){
  49.         BUILD_NO=ver_arch_build[2]
  50.        }
  51.        else{
  52.            ARCH=ver_arch_build[3]
  53.       }
  54.    }  
  55.    
  56. }
  57. function maybe_parse_dec(s,        line_split){
  58.  if( PARSE_DEC_FLAG == 1){
  59.     match($0,/(\S+):\s+(.*)$/,line_split)
  60.     if(length(line_split) > 0){
  61.       if (line_split[1] == PKG){
  62.         PKGINFO=substr(line_split[2],1,200)
  63.         PARSE_DEC_FLAG=0
  64.       }
  65.    }
  66.  }
  67. }'\
  68. "$(cat_macro_fn "$CATEGORY_FNS")"\
  69. "$ALIAS_FNS"\
  70. 'BEGIN { init_CANONICAL_ARY() #MAPS a PKG NAME to a canonical name
  71.       }
  72. #FILENAME = ALIASFILE { }'
  73. "$(cat_macro_fn "$CATEGORIES_INIT_BLOCK")"'
  74. /^PACKAGE NAME:/     { sub(/^PACKAGE NAME:\s*/,""); PKGFILE=$0; parse_pkg_name($0); getline; }
  75. /^PACKAGE LOCATION:/     { sub(/^PACKAGE LOCATION:\s*/,""); sub(/^(.\/)?/,""); PKGPATH=$0; next; }
  76. /^PACKAGE SIZE \(uncompressed\):/ { sub(/^PACKAGE SIZE \(uncompressed\):\s*/,""); sub(/\s/,""); PKGSIZE=$0; next; }
  77. /^PACKAGE DESCRIPTION:/ { PARSE_DEC_FLAG=1; getline;  next; }
  78. /^PACKAGE REQUIRED:/ { sub(/^PACKAGE REQUIRED:\s*/,"");     PKGDEP=fixdepends($0);  next; }
  79. {maybe_parse_dec($0)}                      
  80. /^$/            {
  81.  if (length(PKG)>1){'\
  82. """""$(comment_macro 'Look up the category based on the package name if PKG_FIX_CATEGORIES_in_REPO_DB=true ')\
  83.    $(cat_macro_fn "PKGSECTION=get_category(PKG,PKGVER)")"\
  84. '   print PKG "_" PKGVER "|" PKG "|" PKGVER "|"  BUILD_NO "|" PKGSECTION "|" PKGSIZE "|" PKGPATH "|" PKGFILE  "|" PKGDEP "|" PKGINFO "|" PKGOS "|" PKGOSVER  "|"
  85.  };
  86.    
  87.                  PKG=""; PKGVER=""; PKGSECTION="CATEGORY"; PKGSIZE=""; PKGFILE=""; PKGPATH=""; PKGDEP=""; PKGINFO=""; PKGPRIO="";   BUILD_NO="";  ARCH=""; PARSE_DEC_FLAG=0; }
  88. '
  89.  
  90. if [ -z "$PKG_AWK_slack2pup_ProgramFILE_in" ]; then
  91.  awk -v PKGOS="$distro" -v PKGOSVER="$distro_ver" -v CATFILE="$cat_file" -v ALIASFILE="$alias_file" \
  92.         "$AWK_PRG" "$alias_file" "$category_file" "$PACKAGES_PATH"
  93. else
  94. if [ ! -z "$PKG_AWK_slack2pup_ProgramFILE_out" ]; then
  95.   echo "#!`which gawk` -f" > "$PKG_AWK_slack2pup_ProgramFILE_out"
  96.    echo "$AWK_PRG" >> "$PKG_AWK_slack2pup_ProgramFILE_out"
  97.    chmod +x "$PKG_AWK_slack2pup_ProgramFILE_out"
  98.  fi
  99.  awk -v PKGOS="$distro" -v PKGOSVER="$distro_ver" -v CATFILE="$cat_file" -v ALIASFILE="$alias_file" \
  100.      -f "$PKG_AWK_slack2pup_ProgramFILE_in" "$alias_file" "$category_file" "$PACKAGES_PATH"
  101. fi
  102. #cat "$cat_file"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement