Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2. ADMIN_DIR=/var/lib/dpkg
  3. APT_SOURCES_DIR=/etc/apt/sources.list.d
  4. APT_PKGDB_DIR=/var/lib/apt/lists
  5. CHROOT_DIR=""
  6.  
  7. #based on https://github.com/s243a/woof-next/blob/e6590c1044adc0a182a9b299129ed707b7bd95d2/builders/deb-build.sh#L80
  8. prepare_dirs() {
  9.   for aDir in "$CHROOT_DIR" "$CHROOT_DIR$APT_SOURCES_DIR" "$CHROOT_DIR$APT_PKGDB_DIR"; do
  10.     [ ! -z "`which realpath`" ] && aDir=$(realpath -m "$aDir")
  11.     mkdir -p "$aDir"
  12.   done
  13.   ! [ -e $CHROOT_DIR$ADMIN_DIR/status ]    && echo > $CHROOT_DIR$ADMIN_DIR/status
  14.   ! [ -e $CHROOT_DIR$ADMIN_DIR/available ] && echo > $CHROOT_DIR$ADMIN_DIR/available
  15. }
  16.  
  17. #based on https://github.com/s243a/woof-next/blob/e6590c1044adc0a182a9b299129ed707b7bd95d2/builders/deb-build.sh#L457
  18. function update_pkg_status(){
  19. #Probably better just to call remove_pkg_status instead of processing args.
  20. #while [ ! -z $1 ];
  21. #  case $1 in
  22. #    --status=*)
  23. #    shift
  24. #    ;;
  25. #  *)
  26. #    break
  27. #    ;;
  28. #  esac
  29.     {
  30. echo \
  31. "Package: $1
  32. Status: install ok installed
  33. Priority: $2
  34. Section:  $3
  35. Maintainer: unspecified
  36. Architecture: $ARCH
  37. Version: $4"
  38. [ "${5%,}" ] && echo "Depends: ${5%,}"
  39. echo "Description: $1 installed by deb-build.sh
  40. "
  41.     } >> "$CHROOT_DIR$ADMIN_DIR/status"
  42.  
  43. }
  44.  
  45. #based on https://pastebin.com/cRcR6yE2
  46.   AWK_PRG=$(cat <<EOF
  47.   function dep_fix(str,     a,k1,p1,p2,out,seps){
  48.       split(str,a,",")
  49.       out = ""
  50.       #print "str=" str
  51.       for (k1 in a){
  52.           p1=a[k1]
  53.           #print "a[ " k1 "]=" a[k1]
  54.           gsub(/^+/,"",p1)
  55.           split(p1,p2,/\&../,seps) # +libqpdf21&gt8.4 > p2[1]="+libqpdf21" seps[1]="&gt" p2[2]="8.4",
  56.           #print "p2[0]=" p2[0]
  57.           #print "p2[1]=" p2[1]
  58.           #print "p2[2]=" p2[2]
  59.           #print "seps[1]=" seps[1]
  60.           switch (seps[1]) {  
  61.           case "&gt":
  62.             out = out ", " p2[1] " (>" p2[2] ")"
  63.             break
  64.           case "&ge":
  65.             out = out ", " p2[1] " (>=" p2[2] ")"
  66.             break
  67.           case "&lt":
  68.             out = out ", " p2[1] " (<" p2[2] ")"
  69.             break
  70.           case "&le":
  71.             out = out "," p2[1] " (<=" p2[2] ")"
  72.             break
  73.           case "&eq":
  74.             out = out ", " p2[1] " (=" p2[2] ")"
  75.             break
  76.           default:
  77.             out = out ", " p2[1]
  78.             break
  79.          }
  80.          gsub(/^, /,"",out)
  81.          
  82.      }
  83.      return out
  84.   }
  85.   BEGIN{FS="|"}
  86.   {
  87.      PACKAGE=\$2
  88.      print "Package: " PACKAGE
  89.      VERSION = \$3
  90.      #TODO make PACKAGE regular expression safe
  91.      gsub(/[+]/,"\\\\+",PACKAGE)
  92.      gsub(PACKAGE,"",VERSION)
  93.      gsub(/^_/,"",VERSION)
  94.      gsub(/_[^_]*$/,"",VERSION)
  95.      print "Version: " VERSION
  96.      ARCH = \$1
  97.      gsub(/.*_/,"",ARCH)
  98.      if ( ARCH == "i386" ){
  99.        print "Architecture: " ARCH
  100.      } else if (  ARCH = noarch ){
  101.        print "Architecture: noarch"
  102.      }
  103.      #TODO Architecture: \$1 but trimmed after last _ check that it is like i386
  104.      print "Maintainer: unspecified"
  105.      DEPS = \$9
  106.      DEPS = dep_fix(DEPS)
  107.      if (length(DEPS)>0){
  108.        print "Depends: " DEPS
  109.      }
  110.      print "Priority: " PRIORITY
  111.      print "Section: " \$5
  112.      print ""
  113.     }
  114. EOF
  115. )
  116. #echo "$AWK_PRG"
  117. function append_statuses(){
  118.   for aFile in "$@"; do
  119.     aFile=$(realpath -m $aFile)
  120.     if [[ aFile = */woof-installed-packages ]]; then
  121.       PRIORITY=required
  122.       ESSENTIAL=yes
  123.     else
  124.       PRIORITY=optional
  125.       ESSENTIAL=no    
  126.     fi
  127.     cat "$aFile" | awk --assign PRIORITY="$PRIORITY" "$AWK_PRG"  >> "$CHROOT_DIR$ADMIN_DIR/status"
  128.   done
  129.    
  130. }
  131. mv $CHROOT_DIR$ADMIN_DIR/status $CHROOT_DIR$ADMIN_DIR/status_back$$
  132. prepare_dirs
  133. append_statuses /var/packages/woof-installed-packages /var/packages/user-installed-packages
  134. #TODO symlink file lists
  135.