Debian Codegraph @

debian/aideinit

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 #
3 # Copyright (C) 2003-2005 Mike Markley <[email protected]>
4 # Copyright (C) 2005-2022 Marc Haber
5 # Copyright (C) 2010 Hannes von Haugwitz
6 #
7 # This script is free for any purpose whatseoever so long as the above
8 # copyright notice remains in place.
9
10 if [scip-shell system . . `[`. -f /etc/default/aidescip-shell filesystem . . `/etc/default/aide`. ]; then
11 . /etc/default/aidescip-shell source . . `/etc/default/aide`.
12 fi
13
14 # Defaults
15 MAILTO="${MAILTO:-root}"
16 CONFIG="${CONFIG:-/etc/aide/aide.conf}"
17
18 # Options
19 opt_f=0
20 opt_y=0
21 opt_c=0
22 opt_b=0
23
24 if ! [scip-shell system . . `[`. -f "/usr/bin/aidescip-shell filesystem . . `/usr/bin/aide`." ] && ! [scip-shell system . . `[`. -f "/usr/sbin/aidescip-shell filesystem . . `/usr/sbin/aide`." ]; then
25 printfscip-shell system . . printf. >&2 "no /usr/bin/aide found, check your dependencies\\n"
26 exit 1
27 fi
28
29 aideinit_usagescip-shell shell shell-project 0.0.0 aideinit_usage().() {
30 printfscip-shell system . . printf. >&2 "Usage: %s [options] -- [aide options]\\n" "$0"
31 printfscip-shell system . . printf. >&2 " -y|--yes Overwrite output file\\n"
32 printfscip-shell system . . printf. >&2 " -f|--force Force overwrite of database\\n"
33 printfscip-shell system . . printf. >&2 " -c|--config Specify alternate config file\\n"
34 printfscip-shell system . . printf. >&2 " -o|--output Specify alternate output file\\n"
35 printfscip-shell system . . printf. >&2 " -d|--database Specify alternate database file\\n"
36 printfscip-shell system . . printf. >&2 " -b|--background Run in the background\\n"
37 }
38
39 while [scip-shell system . . `[`. -n "$1" ]; do
40 case "$1" in
41 -h|--help)
42 aideinit_usagescip-shell shell shell-project 0.0.0 aideinit_usage().
43 exit 0
44 ;;
45 -f|--force)
46 opt_f=1
47 shift
48 ;;
49 -y|--yes)
50 opt_y=1
51 shift
52 ;;
53 -b|--background)
54 opt_b=1
55 shift
56 ;;
57 -o|--output)
58 shift
59 [scip-shell system . . `[`. -z "$1" ] && aideinit_usagescip-shell shell shell-project 0.0.0 aideinit_usage(). && exit 1
60 outfile=$1
61 shift
62 ;;
63 -d|--database)
64 shift
65 [scip-shell system . . `[`. -z "$1" ] && aideinit_usagescip-shell shell shell-project 0.0.0 aideinit_usage(). && exit 1
66 dbfile=$1
67 shift
68 ;;
69 -c|--config)
70 opt_c=1
71 shift
72 [scip-shell system . . `[`. -z "$1" ] && aideinit_usagescip-shell shell shell-project 0.0.0 aideinit_usage(). && exit 1
73 config=$1
74 shift
75 ;;
76 --)
77 shift
78 break 2
79 ;;
80 *)
81 printfscip-shell system . . printf. >&2 "Unknown option %s (use -- to delimit aideinit and aide options)\\n" "$1"
82 exit
83 ;;
84 esac
85 done
86
87
88 config=${config:-$CONFIG}
89
90 if [scip-shell system . . `[`. ! -f "$config" ]; then
91 printfscip-shell system . . printf. >&2 "%s: %s: file not found\\n" "$0" "${config}"
92 exit 1
93 fi
94
95 if [scip-shell system . . `[`. -z "${outfile}" ]; then
96 outfile=$(grepscip-shell system . . grep. -E "^[[:space:]]*database_out=file:" "${config}" | cutscip-shell system . . cut. -d: -f2)
97 [scip-shell system . . `[`. -z "${outfile}" ] && outfile="/var/lib/aide/aide.db.newscip-shell filesystem . . `/var/lib/aide/aide.db.new`."
98 fi
99 if [scip-shell system . . `[`. -z "${dbfile}" ]; then
100 dbfile=$(grepscip-shell system . . grep. -E "^[[:space:]]*database_in=file:" "${config}" | cutscip-shell system . . cut. -d: -f2)
101 [scip-shell system . . `[`. -z "${dbfile}" ] && dbfile="/var/lib/aide/aide.dbscip-shell filesystem . . `/var/lib/aide/aide.db`."
102 fi
103
104 if [scip-shell system . . `[`. -f "${outfile}" ]; then
105 if [scip-shell system . . `[`. $opt_y -eq 0 ]; then
106 printfscip-shell system . . printf. "Overwrite existing %s [Yn]? " "${outfile}"
107 read yn
108 case "$yn" in
109 [Nn]*)
110 exit 0
111 ;;
112 esac
113 fi
114 fi
115
116 extraflags=""
117
118 run_aideinitscip-shell shell shell-project 0.0.0 run_aideinit().() {
119 if command -v capsh >/dev/nullscip-shell filesystem . . `/dev/null`.; then
120 capsh --caps="cap_dac_read_search,cap_audit_write+eip cap_setpcap,cap_setuid,cap_setgid+ep" --keep=1 --user=_aide --addamb=cap_dac_read_search,cap_audit_write -- \
121 -c "aide --config=${config} --init $extraflags $@ >/var/log/aide/aideinit.log 2>/var/log/aide/aideinit.errors"
122 RET=$?
123 else
124 aide --config="${config}" --init ${extraflags} $@ >/var/log/aide/aideinit.logscip-shell filesystem . . `/var/log/aide/aideinit.log`. 2>/var/log/aide/aideinit.errorsscip-shell filesystem . . `/var/log/aide/aideinit.errors`.
125 RET=$?
126 fi
127 printfscip-shell system . . printf. "AIDE --init return code %d\\n" "${RET}" >> /var/log/aide/aideinit.logscip-shell filesystem . . `/var/log/aide/aideinit.log`.
128 if [scip-shell system . . `[`. "$RET" != "0" ]; then
129 printfscip-shell system . . printf. "AIDE --init return code %d\\n" "${RET}" >> /var/log/aide/aideinit.errorsscip-shell filesystem . . `/var/log/aide/aideinit.errors`.
130 fi
131 return $RET
132 }
133
134 aideinit_backgroundscip-shell shell shell-project 0.0.0 aideinit_background().() {
135 printfscip-shell system . . printf. "running aide --init in background. See /var/log/aide/aideinit.* for log and errors\\n"
136 touchscip-shell system . . touch. /var/log/aide/adeinit.still-runningscip-shell filesystem . . `/var/log/aide/adeinit.still-running`.
137 run_aideinitscip-shell shell shell-project 0.0.0 run_aideinit().
138 RET=$?
139 rmscip-shell system . . rm. -f /var/log/aide/adeinit.still-runningscip-shell filesystem . . `/var/log/aide/adeinit.still-running`.
140 if [scip-shell system . . `[`. -f "${dbfile}" ] && [scip-shell system . . `[`. "${opt_f}" -eq 0 ]; then
141 printfscip-shell system . . printf. >&2 "%s exists and -f was not specified\\n" "${dbfile}" >> /var/log/aide/aideinit.errorsscip-shell filesystem . . `/var/log/aide/aideinit.errors`.
142 fi
143 if [scip-shell system . . `[`. "$(< /var/log/aide/aideinit.errorsscip-shell filesystem . . `/var/log/aide/aideinit.errors`. wcscip-shell system . . wc. -l)" -gt 0 ]; then
144 (printfscip-shell system . . printf. "AIDE init errors:\\n"; catscip-shell system . . cat. /var/log/aide/aideinit.errorsscip-shell filesystem . . `/var/log/aide/aideinit.errors`.) | /usr/bin/mailscip-shell filesystem . . `/usr/bin/mail`. -s "AIDE initialization problem" "${MAILTO}"
145 else
146 cpscip-shell system . . cp. -f "${outfile}" "${dbfile}"
147 fi
148 return "${RET}"
149 }
150
151 if [scip-shell system . . `[`. "${opt_b}" -eq 1 ]; then
152 aideinit_backgroundscip-shell shell shell-project 0.0.0 aideinit_background(). &
153 exit 0
154 fi
155
156 # this is only reached if we run in foreground
157 printfscip-shell system . . printf. >&2 "Running aide --init...\\n"
158 run_aideinitscip-shell shell shell-project 0.0.0 run_aideinit().
159 RET=$?
160
161 if [scip-shell system . . `[`. "$RET" != "0" ]; then
162 printfscip-shell system . . printf. >&2 "AIDE --init return code %s\\n" "${RET}"
163 exit $RET
164 fi
165
166 if [scip-shell system . . `[`. -f "$dbfile" ] && [scip-shell system . . `[`. "${opt_f}" -eq 0 ]; then
167 printfscip-shell system . . printf. "Overwrite %s [yN]? " "${dbfile}"
168 read yn
169 case "$yn" in
170 [yY]*)
171 cpscip-shell system . . cp. -f "${outfile}" "${dbfile}"
172 ;;
173 esac
174 else
175 cpscip-shell system . . cp. -f "${outfile}" "${dbfile}"
176 fi
177
178 # vim: tabstop=4 shiftwidth=4 expandtab
179 # end of file
180