First drop of aptitude for Maemo
[aptitude] / aptitude-create-state-bundle
1 #!/bin/bash
2
3 HELP=0
4 PRINT_INPUTS=0
5 FORCE_GZIP=0
6 FORCE_BZIP2=0
7
8 DONE=0
9 while [ $DONE = 0 ]
10 do
11   case "$1" in
12       --force-gzip )
13           FORCE_GZIP=1
14           FORCE_BZIP2=0
15           shift
16           ;;
17       --force-bzip2 )
18           FORCE_GZIP=0
19           FORCE_BZIP2=1
20           shift
21           ;;
22       --help )
23           HELP=1
24           shift
25           ;;
26       --print-inputs )
27           PRINT_INPUTS=1
28           shift
29           ;;
30       * )
31           DONE=1
32           ;;
33   esac
34 done
35
36 if ([ $PRINT_INPUTS = 0 ] && [ "$#" -ne 1 ]) ||
37    ([ $PRINT_INPUTS = 1 ] && [ "$#" -ne 0 ]) ||
38    [ $HELP = 1 ]
39 then
40     echo "Usage: $0 [options ... ] <output-file>"
41     echo
42     echo "This script will collect the copious information needed to"
43     echo "reproduce an aptitude bug, storing it in the given output file."
44     echo
45     echo "Options:"
46     echo "  --force-bzip2     Override autodetection of the comrpession"
47     echo "                    format: use bzip2 even if it appears to be"
48     echo "                    unavailable."
49     echo "  --force-gzip      Override autodetection of the compression"
50     echo "                    format: use gzip even if bzip2 is available."
51     echo "  --help            Print this message, then exit."
52     echo "  --print-inputs    Display the list of files and directories"
53     echo "                    that would be included in the bundle, then exit."
54
55     exit 1
56 fi
57
58 INPUTS[1]="$HOME/.aptitude"
59 INPUTS[2]="/var/lib/aptitude"
60 INPUTS[3]="/var/lib/apt"
61 INPUTS[4]="/var/cache/apt/*.bin"
62 INPUTS[5]="/etc/apt"
63 INPUTS[6]="/var/lib/dpkg/status"
64
65 if [ $PRINT_INPUTS = 1 ]
66 then
67     for x in ${INPUTS[@]}; do echo $x; done
68     exit 0
69 fi
70
71 # Stick "." on the front of all inputs.
72 declare -a REALINPUTS
73 i=1
74 while [ $i -le ${#INPUTS[*]} ]
75 do
76   REALINPUTS[$i]=./${INPUTS[$i]}
77   i=$((i + 1))
78 done
79
80 OUTFILE="$1"
81
82 if [ $FORCE_BZIP2 = 1 ] || ([ $FORCE_GZIP = 0 ] && which bzip2 2> /dev/null > /dev/null)
83 then
84     COMPRESSOR=bzip2
85 else
86     COMPRESSOR=gzip
87 fi
88
89 (cd / && tar c ${REALINPUTS[@]}) | $COMPRESSOR -c > "$OUTFILE"