summaryrefslogtreecommitdiff
path: root/localbackuppkglists
blob: 4b9e6aeb65f1bb9fcfb3f2b08394744eb67fd340 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/sbin/localbackuppkglists
  4. # Copyright 2007 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: localbackuppkglists,v 1.2 2007-05-07 12:50:57 jonas Exp $
  7. #
  8. # Depends: aptitude and debconf-utils
  9. set -e
  10. PRG=$(basename "$0")
  11. TEMP="`getopt -s sh -o t:f -l target:,force -n "$PRG" -- "$@"`"
  12. if [ $? != 0 ] ; then echo >&2 "ERROR: Internal getopt error." ; exit 1 ; fi
  13. eval set -- "$TEMP"
  14. targetdir=''
  15. force='no'
  16. while true ; do
  17. case "$1" in
  18. -t|--target) targetdir="$2" ; shift 2 ;;
  19. -f|--force) force="yes" ; shift ;;
  20. --) shift ; break ;;
  21. *) echo >&2 "ERROR: Internal error resolving options." ; exit 1 ;;
  22. esac
  23. done
  24. if [ -n "$targetdir" ]; then
  25. targetdirparent="$(dirname "$targetdir")"
  26. if ! [ -d "$targetdirparent" ]; then
  27. if [ "$force" = "yes" ]; then
  28. mkdir -p "$targetdirparent"
  29. else
  30. echo >&2 "Error: Parent directory for target directory does not exist."
  31. exit 1
  32. fi
  33. elif [ -e "$targetdir" ]; then
  34. if [ "$force" = "yes" ]; then
  35. rm -rf "$targetdir"
  36. else
  37. echo >&2 "Error: Target directory already exists."
  38. exit 1
  39. fi
  40. fi
  41. fi
  42. tempdir="$(mktemp -td localpkglists.XXXXXX)"
  43. origlang="$LANG"
  44. LANG='C'
  45. dpkg --get-selections > "$tempdir/dpkg-selections.txt"
  46. aptitude -F '%p#%v#' search '~i!~M' > "$tempdir/aptitude-installed-explicitly.txt"
  47. aptitude -F '%p#%v#' search '~i!~Odebian' > "$tempdir/aptitude-installed-aliens.txt"
  48. aptitude -F '%p#' search '!~i~Rrecommends:(~i)' > "$tempdir/aptitude-notinstalled-recommended.txt"
  49. debconf-get-selections > "$tempdir/debconf-questions.txt"
  50. debconf-get-selections --installer > "$tempdir/debconf-questions-di.txt" 2> /dev/null || true
  51. LANG="$origlang"
  52. if [ -n "$targetdir" ]; then
  53. mv "$tempdir" "$targetdir"
  54. rm -rf "$tempdir"
  55. fi