Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- directories=( "/var/packages/" "/var/packages/builtin_files" "/var/lib/dpkg" )
- outfile=../data-generators/pkg_md5_sums
- CWD="$PWD"
- RP_FN="`which realpath`"
- function realpath(){
- case "$RP_TARGET" in
- *busybox*)
- if [ "$1" = -m ]; then
- shift
- A_PATH=$1
- A_PATH=$(echo "$A_path" | sed 's#^./#'"$CWD"'#g' )
- A_PATH=$(echo "$A_path" | sed 's#^../#'"$CWD"'#g' ) && A_PATH=$(dirname $A_PATH)
- echo "Warning simulating '-m' option since xzit isn't supported by busybox" >2
- echo "A_PATH=$A_PATH" >2
- if [ -f "$A_PATH" ] || [ -d "$A_PATH" ]; then
- $RP_FN "$@"
- else
- echo "$A_PATH"
- fi
- else
- $RP_FN "$@"
- fi
- ;;
- *)
- $RP_FN "$@"
- ;;
- esac
- }
- export -f realpath
- outfile=$(realpath -m "$outfile")
- AWK_fn='
- /^Package:/ { sub(/^Package: /,""); PKG=$0; }
- /^Version:/ { sub(/^Version: /,""); PKGVER=$0; }
- /^Filename:/ { sub(/^Filename: /,""); PKGPATH=$0; sub(/.*\//,""); PKGFILE=$0; }
- /^$/ { print PKG "|" PKGVER "|" PKGFILE "|" "dpkg";
- PKG=""; PKGVER=""; PKGFILE=""; PKGPATH=""; PKGPRIO=""; PKGSECTION=""; PKGMD5=""; PKGDEP=""; }
- '
- [ -f "outfile" ] && rm "$outfile"
- touch "$outfile"
- [ -f "outfile"_md5 ] && rm "$outfile"_md5
- touch "$outfile"_md5
- [ -f "outfile"_db ] && rm "$outfile"_db
- touch "$outfile"_db
- for a_dir in "${directories[@]}"; do
- bname="$(basename "$a_dir")"
- case "$bname" in
- packages)
- md5sum "$a_dir" | sed -r '/glibc .*/ {s#(glibc6) (.*)#libc6 \2#;n}; /.*/ {s#([^[:blank:]]*)(\.files) (.*)#\1 \1\2 \3#g'| tr ' ' '|' \
- | sed -r 's#$#|'"$bname"'#g' | sort >> "$outfile"_md5
- #f2=pkg(?version), f3=version, f8=filename
- cut -f2,3,8 -d' ' --output-delimiter="|" "a_dir"/user-installed-packages | sed -r 's#^(.*\|)([^|]+\|)(.[a-z]+\|)(.*$)#\2\1\2\3\4#g' | sort >> "$outfile"_db
- join -j 1 "$out_file"_md5 >> "$out_file"
- ;;
- builtin_files)
- md5sum "$a_dir" | sed -r '/glibc .*/ {s#(glibc6) (.*)#libc6 \2#;n}; /.*/ {s#([^[:blank:]]*) (.*)#\1 \1\2#g'| tr ' ' '|' \
- sed -r 's#$#|'"$bname"'#g' -e | sort >> "$out_file"_md5
- cut -f2,3,8 -d' ' --output-delimiter="|" "a_dir"/user-installed-packages | sort >> "$out_file"_packages_db
- join -j 1 "$out_file"_packages >> "$out_file"
- ;;
- #dpkg)
- # md5sum "$a_dir" | sed -r 's#$#|'"$bname"'#g' | sort > "$out_file"_dpkg
- # ;;
- esac
- done
Add Comment
Please, Sign In to add comment