s243a

pkg-md5-sums (draft#3)

Dec 26th, 2020 (edited)
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.00 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. directories=( "/var/packages/" "/var/packages/builtin_files" "/var/lib/dpkg" )
  4. outfile=../data-generators/pkg_md5_sums
  5. CWD="$PWD"
  6.  
  7. RP_FN="`which realpath`"
  8. function realpath(){
  9.     case "$RP_TARGET" in
  10.     *busybox*)
  11.       if [ "$1" = -m ]; then
  12.         shift
  13.         A_PATH=$1
  14.         A_PATH=$(echo "$A_path" | sed 's#^./#'"$CWD"'#g' )
  15.         A_PATH=$(echo "$A_path" | sed 's#^../#'"$CWD"'#g' ) && A_PATH=$(dirname $A_PATH)
  16.         echo "Warning simulating '-m' option since xzit isn't supported by busybox" >2
  17.         echo "A_PATH=$A_PATH" >2
  18.         if [ -f  "$A_PATH" ] || [ -d  "$A_PATH" ]; then
  19.           $RP_FN "$@"
  20.         else
  21.           echo "$A_PATH"
  22.         fi
  23.       else
  24.         $RP_FN "$@"
  25.       fi
  26.       ;;
  27.     *)
  28.       $RP_FN "$@"
  29.       ;;
  30.     esac
  31. }
  32. export -f realpath
  33. outfile=$(realpath -m "$outfile")
  34.  
  35. AWK_fn_map_deb='
  36. /^Package:/     { sub(/^Package: /,"");  PKG=$0; }
  37. /^Version:/     { sub(/^Version: /,"");  PKGVER=$0; }
  38. /^Filename:/    { sub(/^Filename: /,""); PKGPATH=$0; sub(/.*\//,""); PKGFILE=$0; }
  39.  
  40.  
  41. /^$/            { print PKG "|" ARCH "|" PKGVER "|" PKGFILE "|" "dpkg" "|"
  42.                  PKG=""; PKGVER=""; PKGFILE=""; PKGPATH=""; PKGPRIO=""; PKGSECTION=""; PKGMD5="";  PKGDEP=""; }
  43. '
  44.  
  45.  
  46. AWK_fn_prepend_file_list='BEGIN {FS = "|"}
  47. {   db_list=$3
  48.     #print "db_list=" db_list
  49.     sub(/\.[^.]+$/, "."ext, db_list)
  50.    print db_list "|" $1 "|" $2 "|" $3 "|" $4 "|" db_dir}
  51. '  
  52.  
  53. #AWK_fn_DISTRO_PKGS_SPECS=
  54.  
  55. for pfx in "1" "2" "3"; do
  56.   [ -f "$outfile"_$pfx ] && rm "$outfile"_$pfx
  57.   touch "$outfile"
  58.   [ -f "$outfile"_$pfx_md5 ] && rm "$outfile"_$pfx_md5
  59.   touch "$outfile"_$pfx_md5
  60.   [ -f "$outfile"_"$pfx"db ] && rm "$outfile"_"$pfx"_db
  61.   touch "$outfile"_"$pfx"_db
  62. done
  63.  
  64.  
  65.  
  66. for a_dir in "${directories[@]}"; do
  67.   bname="$(basename "$a_dir")"
  68.   case "$bname" in
  69.   packages)
  70.     pfx=1
  71.     cd "$a_dir"; dir_bname=$(basename "$a_dir")
  72.     md5sum $(ls -1 *.files) | sed -r 's#^([^[:space:]]+)([[:space:]]+)([^[:space:]].*)$#\3|\1|'"$bname"'#g' | sort >> "$outfile"_"$pfx"_md5
  73.     cut -f2,3,8 -d'|' --output-delimiter="|" "$a_dir"/user-installed-packages | \
  74.       awk -v ext=files -v db_dir=packages "$AWK_fn_prepend_file_list" | sort >> "$outfile"_"$pfx"_db #f1=file_list_name, f2=pkg, f3=version, f4=pkg_file, f5=packages
  75.     join -t "|" -j 1 "$outfile"_"$pfx"_db "$out_file"_"$pfx"_md5 >> "$outfile"_$pfx
  76.     ;;
  77.   builtin_files)
  78.     pfx=2
  79.     cat /var/packages/DISTRO_PKGS_SPECS | \
  80.       "$CWD"/distro_pkgs_specs__to__compat_pkg.awk | sort -k2 -t '|' > ${outfile}"_distro_pkgs_specs" #f1=pkg_name, f2=distro_pkgs_specs_name
  81.     cd "$a_dir"; dir_bname=$(basename "$a_dir")
  82.     md5sum $(ls -1f) | sed -r 's#^([^[:space:]]+)([[:space:]]+)([^[:space:]].*)$#\3|\1|'"$bname"'#g' | \
  83.       sort >> "${outfile}"_"$pfx"_md5 #f1=pkg_name, f2=distro_pkgs_specs_nam
  84.      
  85.     join -t "|" -a1 -1 2 -2 1 ${outfile}"_distro_pkgs_specs" "${outfile}"_"$pfx"_md5 | sort > "${outfile}"_specs_and_md5
  86.      
  87.     cut -f2,3,8 -d'|' --output-delimiter="|" "$a_dir"/../woof-installed-packages | \
  88.       awk -v ext=files -v db_dir=builtin_compat_files "$AWK_fn_prepend_file_list" | sort >> "${outfile}"_"$pfx"_db
  89.     join -t "|" -j 1 "${outfile}"_"$pfx"_db "${out_file}"_specs_and_md5 >> "${outfile}"_$pfx
  90.     ;;    
  91.   dpkg)
  92.     pfx=3
  93.     cd "$a_dir/info"; dir_bname=$(basename "$a_dir")
  94.     md5sum $(ls -1 *.list; ls -1 *.md5sums) \
  95.        | sed -r 's#^([^[:space:]]+)([[:space:]]+)([^[:space:]]+.*)([.])([^.]*)$#\3||dpkg|\3\4|\1|'"$bname"'#g' \
  96.        | sed -r 's#([^:]+)(:?[^\|]*\|)(.*)#\1|||||\2\3#g' \
  97.        | sort > "$out_file"_"$pfx"_dpkg #f1=pkg, f2=:arch, f3=ver, f4=pkgfile, f5=dir_name, f6=filelist, f7=md5sum
  98.     cd ..
  99.     cat status | awk -v db_dir=dpkg "$AWK_fn_map_deb" > "${outfile}"_"$pfx"_db
  100.     bashreduce ../dpkg_mappers/LB_Mapper ../dpkg_reducers/LB_reducer < <(cat "${outfile}"_"$pfx"_db "$out_file"_"$pfx"_dpkg) >> "${outfile}"_$pfx
  101.     #join -t "|" -j 1 "${outfile}"_"$pfx"_db "${out_file}"_specs_and_md5 >> "${outfile}"_$pfx
  102.     ;;      
  103.   esac
  104. done
  105.  
Add Comment
Please, Sign In to add comment