File: tripwire_uninstall

package info (click to toggle)
tripwire 2.4.3.7-6
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie, trixie-proposed-updates
  • size: 7,220 kB
  • sloc: cpp: 57,898; sh: 6,006; perl: 2,735; yacc: 497; makefile: 439; lex: 356; ansic: 10
file content (152 lines) | stat: -rwxr-xr-x 3,615 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
set -e

unset NO_CONFIRM
unset NO_REMOVE
unset REMOVE_REPORTS
unset REMOVE_LOGS
unset REMOVE_DB
unset REMOVE_KEYS
unset RM

UNAME=`uname`

help() {
  cat >&2 << 'HELP'

    tripwire_uninstall [-y] [-N] [ [-R] [-L] [-D] [-K] | [-A] ]

          -y no confirmation (unattended operation)
          -N dont remove binaries, docs and man pages
          -A remove everything (logs, reports, db and keys)
          -R remove reports
          -L remove logs
          -D remove db
          -K remove keys

          -N with -Y is valid

  
HELP
}

while [ "$#" != 0 ]; do
  case "$1" in
  -y) NO_CONFIRM=1 ;;
  -N) NO_REMOVE=1 ;;
  -L) REMOVE_LOGS=1 ;;
  -D) REMOVE_DB=1 ;;
  -K) REMOVE_KEYS=1 ;;
  -A) REMOVE_LOGS=1
      REMOVE_KEYS=1
      REMOVE_DB=1
      ;;
  *) help ; exit 1
  esac
  shift
done

secure_rm() {
case $UNAME in
  Darwin)
    /usr/bin/srm -vf -- "$@"
    ;;
  Linux)
    /usr/bin/shred -vfu -- "$@"
    ;;
  FreeBSD|*)
    # 3x wipe
    for FILE in "$@"; do
      /bin/dd if=/dev/random of="$FILE" bs=1 count=$(/usr/bin/wc -c < "$FILE" | /usr/bin/sed "s/[^0-9]//g")
      /bin/dd if=/dev/random of="$FILE" bs=1 count=$(/usr/bin/wc -c < "$FILE" | /usr/bin/sed "s/[^0-9]//g")
      /bin/dd if=/dev/random of="$FILE" bs=1 count=$(/usr/bin/wc -c < "$FILE" | /usr/bin/sed "s/[^0-9]//g")
    done
    rm -vf "$@"
    ;;
esac
}

secure_rm_rf() {
case $UNAME in
  Darwin)
    /usr/bin/srm -vrf -- "$@"
    ;;
  Linux)
    /usr/bin/find "$@" -type f -exec /usr/bin/shred -vfu -- {} \;
    rm -vrf "$@"
    ;;
  FreeBSD|*)
    # 3x wipe
    /usr/bin/find "$@" -type f | xargs -I% sh -c '/bin/dd if=/dev/random of="%" bs=1 count=$(/usr/bin/wc -c < "%" | /usr/bin/sed "s/[^0-9]//g")'
    /usr/bin/find "$@" -type f | xargs -I% sh -c '/bin/dd if=/dev/random of="%" bs=1 count=$(/usr/bin/wc -c < "%" | /usr/bin/sed "s/[^0-9]//g")'
    /usr/bin/find "$@" -type f | xargs -I% sh -c '/bin/dd if=/dev/random of="%" bs=1 count=$(/usr/bin/wc -c < "%" | /usr/bin/sed "s/[^0-9]//g")'
    rm -vrf "$@"
    ;;
esac
}


if [ -n "$NO_CONFIRM" ]; then
  :; # noop
else
  printf "Uninstall tripwire ? [Yn] "

  unset PROMPT
  read PROMPT

  if [ "$PROMPT" = 'y' ] || [ "$PROMPT" = 'Y' ]; then
    :; # noop
  else
    echo "user cancelled" >&2
    exit 1
  fi
fi

if [ -z "$NO_REMOVE" ]; then
  echo "removing tripwire binaries, scripts, docs and man pages" >&2

  # binaries
  secure_rm "TRIPWIRE_ROOT/sbin/siggen"
  secure_rm "TRIPWIRE_ROOT/sbin/tripwire"
  secure_rm "TRIPWIRE_ROOT/sbin/twadmin"
  secure_rm "TRIPWIRE_ROOT/sbin/twprint"

  # scripts
  secure_rm "TRIPWIRE_ROOT/sbin/tripwire_"*

  # docs
  secure_rm_rf "TRIPWIRE_ROOT/doc/tripwire"

  # man pages
  secure_rm "TRIPWIRE_ROOT/share/man/man4/twconfig.4"
  secure_rm "TRIPWIRE_ROOT/share/man/man4/twpolicy.4"
  secure_rm "TRIPWIRE_ROOT/share/man/man5/twfiles.5"
  secure_rm "TRIPWIRE_ROOT/share/man/man8/siggen.8"
  secure_rm "TRIPWIRE_ROOT/share/man/man8/tripwire.8"
  secure_rm "TRIPWIRE_ROOT/share/man/man8/twadmin.8"
  secure_rm "TRIPWIRE_ROOT/share/man/man8/twintro.8"
  secure_rm "TRIPWIRE_ROOT/share/man/man8/twprint.8"
fi


if [ -n "$REMOVE_REPORTS" ]; then
  echo "removing tripwire reports" >&2
  secure_rm "TRIPWIRE_ROOT/lib/tripwire/report"/*.twr
fi

if [ -n "$REMOVE_LOGS" ]; then
  echo "removing tripwire logs" >&2
  secure_rm "TRIPWIRE_LOG_DIR/tripwire_periodic_"*.log
fi

if [ -n "$REMOVE_DB" ]; then
  echo "removing tripwire db" >&2
  secure_rm "TRIPWIRE_ROOT/lib/tripwire"/*.twd*
fi

if [ -n "$REMOVE_KEYS" ]; then
  echo "removing tripwire keys" >&2
  secure_rm "TRIPWIRE_ROOT/etc"/*.key
fi

echo "finished removing tripwire" >&2