Files
security-misc/usr/lib/security-misc/apt-get-wrapper
Patrick Schleizer bddbba84a6 "$@"
2017-02-14 17:30:31 +00:00

68 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
## This file is part of Whonix.
## Copyright (C) 2012 - 2014 Patrick Schleizer <adrelanos@riseup.net>
## See the file COPYING for copying conditions.
set -e
set -o pipefail
set -o errtrace
cleanup() {
if [ -d "$temp_dir" ]; then
rm --recursive --force "$temp_dir"
fi
}
temp_dir="$(mktemp --directory)"
logfile="$temp_dir/log"
tee_fifo="$temp_dir/tee_fifo"
trap "cleanup" EXIT
mkfifo "$tee_fifo"
tee "$logfile" < "$tee_fifo" &
tee_pid="$!"
apt-get \
"$@" \
1> "$tee_fifo" \
2> "$tee_fifo" \
&
apt_get_pid="$!"
wait "$tee_pid"
wait "$apt_get_pid"
apt_get_exit_code="$?"
if [ ! "$apt_get_exit_code" = "0" ]; then
exit "$apt_get_exit_code"
fi
log="$(cat "$logfile")"
while read -r -d $'\n' line; do
line_lower_case="${line,,}"
first_two="${line_lower_case:0:2}"
if [ "$first_two" = "e:" ]; then
exit 125
fi
if [ "$first_two" = "w:" ]; then
first_twelve="${line_lower_case:0:12}"
if [ "$first_twelve" = "w: duplicate" ]; then
continue
fi
skip_summary_line="W: You may want to run apt-get update to correct these problems"
skip_summary_line_lower_case="${skip_summary_line,,}"
if [ "$line_lower_case" = "$skip_summary_line_lower_case" ]; then
continue
fi
exit 125
fi
done < <( echo "$log" )
exit "$apt_get_exit_code"