Skip to content

Commit

Permalink
Automated shell fixes found by shellcheck. Most of the scripts should…
Browse files Browse the repository at this point in the history
… still

work, but we have no way of testing :( Also, some obsolete cruft has been
removed.

Signed-off-by: Christian Kujau <[email protected]>

 backup-mysql.sh                     |  24 +--
 benchmarks/cgd_benchmark.sh         |  26 +--
 benchmarks/compress-test.sh         |  56 +++---
 benchmarks/cryptsetup_benchmark.sh  |  14 +-
 benchmarks/cryptsetup_ciphertest.sh |   4 +-
 benchmarks/fs-bench.sh              | 344 ++++++++++++++++++------------------
 benchmarks/password-test.sh         |  26 +--
 benchmarks/ssh-features.sh          |  52 ------
 benchmarks/ssh-performance.sh       |  28 +--
 benchmarks/test-digests.sh          |   8 +-
 benchmarks/tmpfs-ramfs-ramdisk.sh   |  18 +-
 benchmarks/vbox-nic-bench.sh        |  26 +--
 checksum_file.sh                    |  38 ++--
 convert-music.sh                    |  14 +-
 diff2html.sh                        |   6 +-
 find_dups.sh                        |  30 ++--
 ipsec_iproute.sh                    |  34 ++--
 kerninst.sh                         | 119 -------------
 keyboard-backlight.sh               |  20 +--
 port-mgmt.sh                        |   8 +-
 print-authorized-keys.sh            |  27 ---
 qemu-tap.sh                         |   2 +-
 rsnapshot/rsnapshot-ready.sh        |   4 +-
 rsnapshot/rsnapshot-rotate.sh       |  10 +-
 rsnapshot/rsnapshot-wrapper.sh      |  38 ++--
 security_checks.sh                  |  86 ---------
 sensors_adt746x.sh                  |   2 +-
 system-update.sh                    | 168 ------------------
 ternet/flop.sh                      |   8 +-
 ternet/iptables-ternet.sh           |   2 +-
 vbox-sysrq.sh                       |  14 +-
 31 files changed, 402 insertions(+), 854 deletions(-)
  • Loading branch information
ckujau committed Feb 7, 2020
1 parent c3ff9ff commit aeb13a8
Show file tree
Hide file tree
Showing 31 changed files with 402 additions and 854 deletions.
24 changes: 12 additions & 12 deletions backup-mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ HASH=sha1 # See 'openssl dgst -h' for possible values
# DEBUG=echo

if [ ! -d "$1" ]; then
echo "Usage: `basename $0` [dir] [-c]"
echo "Usage: $(basename "$0") [dir] [-c]"
exit 1
else
DIR="$1"
fi

# Use 'gdate' if available, 'date' otherwise
if [ "`which gdate`" ]; then
if [ "$(which gdate)" ]; then
DATE=gdate
else
DATE=date
Expand All @@ -38,8 +38,8 @@ $DATE
# We have checks too :-)
if [ "$2" = "-c" ]; then
for f in "$DIR"/*.bz2; do
printf "Processing $f (`stat -c 'scale=0; %s / 1024' $f | bc -l`KB)..."
grep -q `bzip2 -dc "$f" | openssl $HASH` `echo $f | sed "s/.bz2$/.$HASH/"`
printf "Processing $f ($(stat -c 'scale=0; %s / 1024' "$f" | bc -l)KB)..."
grep -q $(bzip2 -dc "$f" | openssl $HASH) $(echo "$f" | sed "s/.bz2$/.$HASH/")
if [ $? = 0 ]; then
echo "checksum OK"
else
Expand All @@ -49,8 +49,8 @@ if [ "$2" = "-c" ]; then
exit 0
fi

BEGIN=`$DATE +%s`
for db in `mysql --batch --skip-column-names -e 'show databases' | sort`; do
BEGIN=$($DATE +%s)
for db in $(mysql --batch --skip-column-names -e 'show databases' | sort); do
printf "Backing up "$db"...."
# - Use multiple-row INSERT syntax that include several VALUES lists
# - Continue even if an SQL error occurs during a table dump
Expand Down Expand Up @@ -81,9 +81,9 @@ for db in `mysql --batch --skip-column-names -e 'show databases' | sort`; do
esac

if [ -n "$DEBUG" ]; then
$DEBUG mysqldump $OPTIONS "$db" egrep -v -- '^-- Dump completed on' "$DIR"/DB_"$db".sql.new
$DEBUG mysqldump "$OPTIONS" "$db" egrep -v -- '^-- Dump completed on' "$DIR"/DB_"$db".sql.new
else
$DEBUG mysqldump $OPTIONS "$db" | egrep -v -- '^-- Dump completed on' > "$DIR"/DB_"$db".sql.new
$DEBUG mysqldump "$OPTIONS" "$db" | egrep -v -- '^-- Dump completed on' > "$DIR"/DB_"$db".sql.new
fi

# We're comparing checksum rather than the whole dump, so that we
Expand All @@ -96,8 +96,8 @@ for db in `mysql --batch --skip-column-names -e 'show databases' | sort`; do
else
$DEBUG openssl $HASH "$DIR"/DB_"$db".sql.new | sed 's/\.new$//' > "$DIR"/DB_"$db".sql.new.$HASH
fi
H_OLD=`awk '{print $NF}' "$DIR"/DB_"$db".sql.$HASH 2>/dev/null`
H_NEW=`awk '{print $NF}' "$DIR"/DB_"$db".sql.new.$HASH 2>/dev/null`
H_OLD=$(awk '{print $NF}' "$DIR"/DB_"$db".sql.$HASH 2>/dev/null)
H_NEW=$(awk '{print $NF}' "$DIR"/DB_"$db".sql.new.$HASH 2>/dev/null)

# - If they are equal, delete our new one, otherwise update the old one
if [ "$H_OLD" = "$H_NEW" ]; then
Expand All @@ -122,6 +122,6 @@ for db in `mysql --batch --skip-column-names -e 'show databases' | sort`; do
fi
$DEBUG
done
END=`$DATE +%s`
echo "$0 finished after `echo $END - $BEGIN | bc` seconds."
END=$($DATE +%s)
echo "$0 finished after $(echo "$END" - "$BEGIN" | bc) seconds."
echo
26 changes: 13 additions & 13 deletions benchmarks/cgd_benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ if [ "$1" = "report" ] && [ -f "$2" ]; then
fi

# FIXME: Do we want more options on the command line?
if [ ! -c /dev/r${1} ] || [ -z "$2" ]; then
echo "Usage: $(basename $0) [devicename] [runs]"
echo " $(basename $0) report [out.txt]"
if [ ! -c /dev/r"${1}" ] || [ -z "$2" ]; then
echo "Usage: $(basename "$0") [devicename] [runs]"
echo " $(basename "$0") report [out.txt]"
echo ""
echo "Example: $(basename $0) wd0b 5 | tee out.txt"
echo " $(basename $0) report out.txt"
echo "Example: $(basename "$0") wd0b 5 | tee out.txt"
echo " $(basename "$0") report out.txt"
exit 1
else
# Note: in BSD, we will use character devices, not block devices. However,
Expand All @@ -40,23 +40,23 @@ else
fi

# RAW
for i in $(seq 1 $NUM); do
for i in $(seq 1 "$NUM"); do
printf "MODE: raw I: $i\t"
dd if=/dev/r${DEV} of=/dev/null bs=1k $DEBUG conv=sync 2>&1 | grep bytes
dd if=/dev/r"${DEV}" of=/dev/null bs=1k "$DEBUG" conv=sync 2>&1 | grep bytes
done

# CGD
for c in $CIPHERS; do
cgdconfig -g -k urandomkey -o ${PRM}/test_${c} $c
cgdconfig ${CGD} /dev/${DEV} ${PRM}/test_${c}
cgdconfig -g -k urandomkey -o "${PRM}"/test_"${c}" "$c"
cgdconfig ${CGD} /dev/"${DEV}" "${PRM}"/test_"${c}"

# Repeat NUM times...
for i in $(seq 1 $NUM); do
for i in $(seq 1 "$NUM"); do
printf "MODE: $c I: $i\t"
dd if=/dev/r${CGD}a of=/dev/null bs=1k $DEBUG conv=sync 2>&1 | grep bytes
dd if=/dev/r${CGD}a of=/dev/null bs=1k "$DEBUG" conv=sync 2>&1 | grep bytes
done

cgdconfig -u /dev/${CGD}a
rm -f ${PRM}/test_${c}
rm -f "${PRM}"/test_"${c}"
done
rmdir ${PRM}
rmdir "${PRM}"
56 changes: 28 additions & 28 deletions benchmarks/compress-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ PROGRAMS=${PROGRAMS:-gzip pigz bzip2 pbzip2 lbzip2 xz pxz lz4 lzma lzip brotli z
MODES=${MODES:-9c 1c dc} # {1..9}c for compression
# dc for decompression
_help() {
echo "Usage: $(basename $0) [-n runs] [-f file]"
echo " $(basename $0) [-r results]"
echo "Usage: $(basename "$0") [-n runs] [-f file]"
echo " $(basename "$0") [-r results]"
echo
echo "Available environment variables that can be set:"
echo "PROGRAMS (default: $PROGRAMS)"
Expand All @@ -33,15 +33,15 @@ _help() {

_report() {
echo "### Fastest compressor:"
grep -v /dc ${REPORT} | sort -nk3
grep -v /dc "${REPORT}" | sort -nk3
echo

echo "### Smallest size:"
grep -v /dc ${REPORT} | sort -nrk6
grep -v /dc "${REPORT}" | sort -nrk6
echo

echo "### Fastest decompressor:"
grep /dc ${REPORT} | sort -nk3
grep /dc "${REPORT}" | sort -nk3
echo
exit $?
}
Expand Down Expand Up @@ -74,79 +74,79 @@ done
RUNS=${runs:-1}

# Read file into RAM once
[ -f ${FILE} ] && cat ${FILE} > /dev/null || _help
[ -f "${FILE}" ] && cat "${FILE}" > /dev/null || _help

# Iterate through all modes, programs
for m in $MODES; do
for p in $PROGRAMS; do
if ! which ${p} > /dev/null 2>&1; then
if ! which "${p}" > /dev/null 2>&1; then
echo "### Program ${p} not found - skipping."
continue
fi
SIZE1=$(ls -go ${FILE} | awk '{print $3}')
SIZE1=$(ls -go "${FILE}" | awk '{print $3}')
START=$(date +%s)

# If all programs had the same options, we would not have to do this.
case $p in
brotli|bro)
if [ $m = "dc" ]; then
_cmd(){ ${p} -${m} ${FILE}.${p} > /dev/null; }
if [ "$m" = "dc" ]; then
_cmd(){ ${p} -"${m}" "${FILE}"."${p}" > /dev/null; }
else
qual=$(echo $m | sed 's/c$//') # Sigh...
_cmd(){ ${p} -q ${qual} -c ${FILE} > ${FILE}.${p}; }
qual=$(echo "$m" | sed 's/c$//') # Sigh...
_cmd(){ ${p} -q "${qual}" -c "${FILE}" > "${FILE}"."${p}"; }
fi
;;

zstd|pzstd)
# pzstd: suppress the progress bar
if [ $m = "dc" ]; then
_cmd(){ ${p} -q${m} ${FILE}.${p} > /dev/null; }
if [ "$m" = "dc" ]; then
_cmd(){ ${p} -q"${m}" "${FILE}"."${p}" > /dev/null; }
else
_cmd(){ ${p} -q${m} ${FILE} > ${FILE}.${p}; }
_cmd(){ ${p} -q"${m}" "${FILE}" > "${FILE}"."${p}"; }
fi
;;

pxz)
# For some reason pxz defaults to -T1 instead of -T0
if [ $m = "dc" ]; then
_cmd(){ ${p} -T0 -dc ${FILE}.${p} > /dev/null; }
if [ "$m" = "dc" ]; then
_cmd(){ ${p} -T0 -dc "${FILE}"."${p}" > /dev/null; }
else
qual=$(echo $m | sed 's/c$//') # Sigh...
_cmd(){ ${p} -T0 -c -${qual} ${FILE} > ${FILE}.${p}; }
qual=$(echo "$m" | sed 's/c$//') # Sigh...
_cmd(){ ${p} -T0 -c -"${qual}" "${FILE}" > "${FILE}"."${p}"; }
fi
;;

pixz)
if [ $m = "dc" ]; then
_cmd(){ ${p} -d -i ${FILE}.${p} -o /dev/null; }
if [ "$m" = "dc" ]; then
_cmd(){ ${p} -d -i "${FILE}"."${p}" -o /dev/null; }
else
qual=$(echo $m | sed 's/c$//') # Sigh...
_cmd(){ ${p} -k -${qual} -i ${FILE} -o ${FILE}.${p}; }
qual=$(echo "$m" | sed 's/c$//') # Sigh...
_cmd(){ ${p} -k -"${qual}" -i "${FILE}" -o "${FILE}"."${p}"; }
fi
;;

*)
# All the sane programs out there...
if [ $m = "dc" ]; then
_cmd(){ ${p} -${m} ${FILE}.${p} > /dev/null; }
if [ "$m" = "dc" ]; then
_cmd(){ ${p} -"${m}" "${FILE}"."${p}" > /dev/null; }
else
_cmd(){ ${p} -${m} ${FILE} > ${FILE}.${p}; }
_cmd(){ ${p} -"${m}" "${FILE}" > "${FILE}"."${p}"; }
fi
;;
esac

# We could move the counter to the outer loop, but then we'd have
# to play more tricks with our statistics below.
n=0
while [ $n -lt $RUNS ]; do
while [ $n -lt "$RUNS" ]; do
_cmd
n=$((n+1))
done

# Statistics
END=$(date +%s)
DIFF=$(echo "scale=2; ($END - $START) / $n" | bc -l)
if [ $m = "dc" ]; then
if [ "$m" = "dc" ]; then
echo "### $p/$m: $DIFF seconds"
else
SIZE2=$(ls -go "$FILE"."$p" | awk '{print $3}') # More portable than stat(1)
Expand Down
14 changes: 7 additions & 7 deletions benchmarks/cryptsetup_benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
if [ ! -b "$1" ] || [ -z "$4" ]; then
echo "Usage: $0 [device] [cipher] [size] [runs]"
echo "Examples:"
echo "`basename $0` /dev/sdu1 aes-cbc-plain 128"
echo "`basename $0` /dev/sdu1 aes-cbc-essiv:sha256 448"
echo "$(basename "$0") /dev/sdu1 aes-cbc-plain 128"
echo "$(basename "$0") /dev/sdu1 aes-cbc-essiv:sha256 448"
exit 1
else
DEVICE="$1"
Expand All @@ -21,17 +21,17 @@ else
fi

cryptsetup remove $MD 2>/dev/null
$DEBUG cryptsetup -c $CIPHER -s $SIZE -d /dev/urandom create $MD $DEVICE || exit 1
$DEBUG cryptsetup -c "$CIPHER" -s "$SIZE" -d /dev/urandom create $MD "$DEVICE" || exit 1
## $DEBUG cryptsetup status $MD || exit 1
printf "$CIPHER / $SIZE : "
TIME_S=`date +%s`
TIME_S=$(date +%s)
i=0
while [ $i -lt $RUNS ]; do
while [ $i -lt "$RUNS" ]; do
## printf "$i "
$DEBUG sysctl -qw vm.drop_caches=3
$DEBUG dd if=/dev/mapper/$MD of=/dev/null bs=1M 2>/dev/null
i=$((i+1))
done
TIME_E=`date +%s`
expr $TIME_E - $TIME_S
TIME_E=$(date +%s)
expr "$TIME_E" - "$TIME_S"
cryptsetup remove $MD
4 changes: 2 additions & 2 deletions benchmarks/cryptsetup_ciphertest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# RIP
die() {
echo $1
echo "$1"
exit 2
}

Expand All @@ -55,7 +55,7 @@ for c in aes anubis blowfish camellia cast5 cast6 cipher_null khazad salsa20 ser
C=$c-$m-essiv:$h
fi
for s in 128 256 384 448 512; do
$DEBUG cryptsetup -c $C -s $s -d /dev/urandom create $MD $DEVICE 2>/dev/null
$DEBUG cryptsetup -c $C -s $s -d /dev/urandom create $MD "$DEVICE" 2>/dev/null
if [ $? = 0 ]; then
echo "Valid combination: cipher $C - size $s"
$DEBUG cryptsetup status $MD
Expand Down
Loading

0 comments on commit aeb13a8

Please sign in to comment.