Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/ash
- PKG_AWK_slack2pup_ProgramFILE_out=~/AWK_gen_prg
- #The defaults are input
- [ -z "$outfile" ] && outfile=~/testcat.in
- #cat_file=/usr/local/petget/categories.dat
- [ -z "$category_file" ] && category_file=~/cat_test_cat.dat
- PACKAGES_PATH=~/SLACKO_TEST.in
- #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
- #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
- #to point to the file location. If the file does not exist then it will be generated.
- [ -z "$PKG_AWK_slack2pup_ProgramFILE_in" ] && PKG_AWK_slack2pup_ProgramFILE_in="$(realpath "$PKG_AWK_slack2pup_ProgramFILE_out")"
- #Input the functions (by sourcing build_cannonical):
- # get_canonical_name(s); // Returns a single name for all packages of the same alias
- # init_CANONICAL_ARY(); // Maps an alias name (without wildcards) to a cannonical name
- # **As a string named "ALIAS_FNS"
- #
- # cat_fallback(s); // Fallback categories for known "deb" categories (translates the PKGSECTION field of the debian repo)
- # get_category(s); // Get's the category based on the package name (fallbacks and aliases are used)
- # 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
- # **As a string named CATEGORY_FNS
- # 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
- . ~/build_cannonical
- AWK_PRG=\
- 'function fixdepends(s, p,a,sout) {
- split(s,a,",")
- for (p in a) {
- sout = sout ",+" a[p]
- }
- sub(/^,/,"",sout) ; return sout;
- }
- function parse_pkg_name(s, txz_split,arch_build){
- match(s,/^([^\-]*)(\-.*)(\.([^\-]+))$/,txz_split)
- PKG=txz_split[1]
- split(txz_split[2],ver_arch_build,"-")
- PKGVER=ver_arch_build[2]
- len=length(ver_arch_build)
- if (len == 4){
- BUILD_NO=ver_arch_build[4]
- ARCH=ver_arch_build[3]
- }
- else if(len == 3){
- if (ver_arch_build[len-1] ~ /^[0-9]+$/){
- BUILD_NO=ver_arch_build[2]
- }
- else{
- ARCH=ver_arch_build[3]
- }
- }
- }
- function maybe_parse_dec(s, line_split){
- if( PARSE_DEC_FLAG == 1){
- match($0,/(\S+):\s+(.*)$/,line_split)
- if(length(line_split) > 0){
- if (line_split[1] == PKG){
- PKGINFO=substr(line_split[2],1,200)
- PARSE_DEC_FLAG=0
- }
- }
- }
- }'\
- "$(cat_macro_fn "$CATEGORY_FNS")"\
- "$ALIAS_FNS"\
- 'BEGIN { init_CANONICAL_ARY() #MAPS a PKG NAME to a canonical name
- }
- #FILENAME = ALIASFILE { }'
- "$(cat_macro_fn "$CATEGORIES_INIT_BLOCK")"'
- /^PACKAGE NAME:/ { sub(/^PACKAGE NAME:\s*/,""); PKGFILE=$0; parse_pkg_name($0); getline; }
- /^PACKAGE LOCATION:/ { sub(/^PACKAGE LOCATION:\s*/,""); sub(/^(.\/)?/,""); PKGPATH=$0; next; }
- /^PACKAGE SIZE \(uncompressed\):/ { sub(/^PACKAGE SIZE \(uncompressed\):\s*/,""); sub(/\s/,""); PKGSIZE=$0; next; }
- /^PACKAGE DESCRIPTION:/ { PARSE_DEC_FLAG=1; getline; next; }
- /^PACKAGE REQUIRED:/ { sub(/^PACKAGE REQUIRED:\s*/,""); PKGDEP=fixdepends($0); next; }
- {maybe_parse_dec($0)}
- /^$/ {
- if (length(PKG)>1){'\
- """""$(comment_macro 'Look up the category based on the package name if PKG_FIX_CATEGORIES_in_REPO_DB=true ')\
- $(cat_macro_fn "PKGSECTION=get_category(PKG,PKGVER)")"\
- ' print PKG "_" PKGVER "|" PKG "|" PKGVER "|" BUILD_NO "|" PKGSECTION "|" PKGSIZE "|" PKGPATH "|" PKGFILE "|" PKGDEP "|" PKGINFO "|" PKGOS "|" PKGOSVER "|"
- };
- PKG=""; PKGVER=""; PKGSECTION="CATEGORY"; PKGSIZE=""; PKGFILE=""; PKGPATH=""; PKGDEP=""; PKGINFO=""; PKGPRIO=""; BUILD_NO=""; ARCH=""; PARSE_DEC_FLAG=0; }
- '
- if [ -z "$PKG_AWK_slack2pup_ProgramFILE_in" ]; then
- awk -v PKGOS="$distro" -v PKGOSVER="$distro_ver" -v CATFILE="$cat_file" -v ALIASFILE="$alias_file" \
- "$AWK_PRG" "$alias_file" "$category_file" "$PACKAGES_PATH"
- else
- if [ ! -z "$PKG_AWK_slack2pup_ProgramFILE_out" ]; then
- echo "#!`which gawk` -f" > "$PKG_AWK_slack2pup_ProgramFILE_out"
- echo "$AWK_PRG" >> "$PKG_AWK_slack2pup_ProgramFILE_out"
- chmod +x "$PKG_AWK_slack2pup_ProgramFILE_out"
- fi
- awk -v PKGOS="$distro" -v PKGOSVER="$distro_ver" -v CATFILE="$cat_file" -v ALIASFILE="$alias_file" \
- -f "$PKG_AWK_slack2pup_ProgramFILE_in" "$alias_file" "$category_file" "$PACKAGES_PATH"
- fi
- #cat "$cat_file"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement