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