Advertisement
s243a

mk_dpkg_metadata.sh (draft)

Nov 25th, 2020 (edited)
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.49 KB | None | 0 0
  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="BEGIN{FS=\"|\"}
  47.  {
  48.     PACKAGE=\$2
  49.     print \"Package: \" PACKAGE
  50.     VERSION = \$3
  51.     #TODO make PACKAGE regular expression safe
  52.     gsub(/[+]/,\"\\\\+\",PACKAGE)
  53.     gsub(PACKAGE,\"\",VERSION)
  54.     gsub(/^_/,\"\",VERSION)
  55.     print \"Version: \" \$3
  56.     ARCH = \$1
  57.     gsub(/.*_/,\"\",ARCH)
  58.     if ( ARCH == i386 ){
  59.       print \"Architecture: \" ARCH
  60.     } else if (  ARCH = noarch ){
  61.       print \"Architecture: noarch\"
  62.     }
  63.     #TODO Architecture: \$1 but trimmed after last _ check that it is like i386
  64.     print \"Maintainer: unspecified\"
  65.     print \"Priority: \" PRIORITY
  66.     print \"Section: \" \$5
  67.    
  68.    }
  69.  "
  70. function append_statuses(){
  71.   for aFile in "$@"; do
  72.     aFile=$(realpath -m $aFile)
  73.     if [[ aFile = */woof-installed-packages ]]; then
  74.       PRIORITY=required
  75.       ESSENTIAL=yes
  76.     else
  77.       PRIORITY=optional
  78.       ESSENTIAL=no    
  79.     fi
  80.     cat "$aFile" | awk --assign PRIORITY="$PRIORITY" "$AWK_PRG"  >> "$CHROOT_DIR$ADMIN_DIR/status"
  81.   done
  82.    
  83. }
  84. mv $CHROOT_DIR$ADMIN_DIR/status $CHROOT_DIR$ADMIN_DIR/status_back$$
  85. prepare_dirs
  86. append_statuses /var/packages/woof-installed-packages /var/packages/user-installed-packages
  87. #TODO symlink file lists
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement