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