From aeb13a88d70b4d385652641e56754732b365fa67 Mon Sep 17 00:00:00 2001 From: Christian Kujau Date: Fri, 7 Feb 2020 10:13:46 -0800 Subject: [PATCH] Automated shell fixes found by shellcheck. Most of the scripts should still work, but we have no way of testing :( Also, some obsolete cruft has been removed. Signed-off-by: Christian Kujau 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(-) --- 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(-) delete mode 100755 benchmarks/ssh-features.sh delete mode 100755 kerninst.sh delete mode 100755 print-authorized-keys.sh delete mode 100755 security_checks.sh delete mode 100755 system-update.sh mode change 100644 => 100755 vbox-sysrq.sh diff --git a/backup-mysql.sh b/backup-mysql.sh index b12f4a6..95c6482 100755 --- a/backup-mysql.sh +++ b/backup-mysql.sh @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/benchmarks/cgd_benchmark.sh b/benchmarks/cgd_benchmark.sh index f49bff7..e905468 100755 --- a/benchmarks/cgd_benchmark.sh +++ b/benchmarks/cgd_benchmark.sh @@ -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, @@ -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}" diff --git a/benchmarks/compress-test.sh b/benchmarks/compress-test.sh index 2aa571e..572fff1 100755 --- a/benchmarks/compress-test.sh +++ b/benchmarks/compress-test.sh @@ -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)" @@ -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 $? } @@ -74,63 +74,63 @@ 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 @@ -138,7 +138,7 @@ for m in $MODES; do # 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 @@ -146,7 +146,7 @@ for m in $MODES; do # 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) diff --git a/benchmarks/cryptsetup_benchmark.sh b/benchmarks/cryptsetup_benchmark.sh index 503447b..9a0fdf3 100755 --- a/benchmarks/cryptsetup_benchmark.sh +++ b/benchmarks/cryptsetup_benchmark.sh @@ -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" @@ -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 diff --git a/benchmarks/cryptsetup_ciphertest.sh b/benchmarks/cryptsetup_ciphertest.sh index 64fd3f4..c2aeed4 100755 --- a/benchmarks/cryptsetup_ciphertest.sh +++ b/benchmarks/cryptsetup_ciphertest.sh @@ -30,7 +30,7 @@ # RIP die() { - echo $1 + echo "$1" exit 2 } @@ -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 diff --git a/benchmarks/fs-bench.sh b/benchmarks/fs-bench.sh index 0b9dd2c..49110bc 100755 --- a/benchmarks/fs-bench.sh +++ b/benchmarks/fs-bench.sh @@ -33,7 +33,7 @@ CONF="/usr/local/etc/fs-bench.conf" log() { -echo "`date +'%F %H:%M:%S'`: $1" +echo "$(date +'%F %H:%M:%S'): $1" [ -n "$2" ] && exit "$2" } @@ -43,37 +43,37 @@ echo "`date +'%F %H:%M:%S'`: $1" # $ echo "1:1024:2" | chkfree # -> 2048 chkfree() { -eval `awk -F: '{p=sprintf ("%.0f", ($1 * $2 * $3)); print "ESTIM="p }'` -eval `df -k $MPT | awk '!/Filesystem/ {print "AVAIL="$4}'` -if [ $ESTIM -ge $AVAIL ]; then +eval $(awk -F: '{p=sprintf ("%.0f", ($1 * $2 * $3)); print "ESTIM="p }') +eval $(df -k "$MPT" | awk '!/Filesystem/ {print "AVAIL="$4}') +if [ "$ESTIM" -ge "$AVAIL" ]; then log "WARNING: $ESTIM KB estimated but only $AVAIL KB available - $b could fail!" else - log "DEBUG: $ESTIM KB estimated, $AVAIL KB available" >> $LOG/raw/bonnie-$fs.log + log "DEBUG: $ESTIM KB estimated, $AVAIL KB available" >> "$LOG"/raw/bonnie-"$fs".log fi } # sanity checks if [ ! -b "$1" ] || [ ! -d "$2" ] || [ ! -f $CONF ]; then - log "Usage: `basename $0` [dev] [mpt]" + log "Usage: $(basename "$0") [dev] [mpt]" log "Make sure $CONF exists!" 1 else DEV="$1" - MPT="`echo $2 | sed 's/\/$//'`" + MPT="$(echo "$2" | sed 's/\/$//')" . "$CONF" fi # overwrite results dir? if [ -d "$LOG" ]; then printf "Directory $LOG already exists, overwrite? (y/n) " && read c - if [ $c = "y" ]; then + if [ "$c" = "y" ]; then $DEBUG rm -rf "$LOG" else log "Aborted." 1 fi fi $DEBUG mkdir -p "$LOG"/raw "$LOG"/env -$DEBUG cp "$0" "$LOG"/env/`basename $0`.txt -$DEBUG cp "$CONF" "$LOG"/env/`basename $CONF`.txt +$DEBUG cp "$0" "$LOG"/env/$(basename "$0").txt +$DEBUG cp "$CONF" "$LOG"/env/$(basename $CONF).txt $DEBUG gzip -dc /proc/config.gz > "$LOG"/env/config.txt 2>/dev/null $DEBUG cp /boot/config-$(uname -r) "$LOG"/env/config-$(uname -r).txt 2>/dev/null $DEBUG dmesg > "$LOG"/env/dmesg.txt @@ -84,104 +84,104 @@ $DEBUG hdparm -tT "$DEV" > "$LOG"/env/hdparm.txt # MKFS ######################################################## mkfs_btrfs() { - log "mkfs.btrfs $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.btrfs $DEV 1>/dev/null - log "mount -t btrfs -o noatime $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t btrfs -o noatime $DEV $MPT + log "mkfs.btrfs $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.btrfs "$DEV" 1>/dev/null + log "mount -t btrfs -o noatime $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t btrfs -o noatime "$DEV" "$MPT" ERR=$? } mkfs_ext2() { - log "mkfs.ext2 -Fq $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.ext2 -Fq $DEV - log "mount -t ext2 -o noatime,user_xattr $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t ext2 -o noatime,user_xattr $DEV $MPT + log "mkfs.ext2 -Fq $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.ext2 -Fq "$DEV" + log "mount -t ext2 -o noatime,user_xattr $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t ext2 -o noatime,user_xattr "$DEV" "$MPT" ERR=$? } mkfs_ext3() { - log "mkfs.ext3 -Fq $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.ext3 -Fq $DEV - log "mount -t ext3 -o noatime,user_xattr $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t ext3 -o noatime,user_xattr $DEV $MPT + log "mkfs.ext3 -Fq $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.ext3 -Fq "$DEV" + log "mount -t ext3 -o noatime,user_xattr $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t ext3 -o noatime,user_xattr "$DEV" "$MPT" ERR=$? } mkfs_ext4() { - log "mkfs.ext4 -Fq $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.ext4 -Fq $DEV - log "mount -t ext4 -o noatime,user_xattr $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t ext4 -o noatime,user_xattr $DEV $MPT + log "mkfs.ext4 -Fq $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.ext4 -Fq "$DEV" + log "mount -t ext4 -o noatime,user_xattr $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t ext4 -o noatime,user_xattr "$DEV" "$MPT" ERR=$? } mkfs_jfs() { - log "mkfs.jfs -q $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.jfs -q $DEV 1>/dev/null - log "mount -t jfs -o noatime $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t jfs -o noatime $DEV $MPT + log "mkfs.jfs -q $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.jfs -q "$DEV" 1>/dev/null + log "mount -t jfs -o noatime $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t jfs -o noatime "$DEV" "$MPT" ERR=$? } mkfs_nilfs2() { - log "mkfs.nilfs2 -q $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.nilfs2 -q $DEV - log "mount -t nilfs2 -o noatime $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t nilfs2 -o noatime $DEV $MPT 2>/dev/null + log "mkfs.nilfs2 -q $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.nilfs2 -q "$DEV" + log "mount -t nilfs2 -o noatime $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t nilfs2 -o noatime "$DEV" "$MPT" 2>/dev/null ERR=$? } mkfs_reiserfs() { - log "mkfs.reiserfs -qf $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.reiserfs -qf $DEV > /dev/null 2>&1 - log "mount -t reiserfs -o noatime,user_xattr $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t reiserfs -o noatime,user_xattr $DEV $MPT + log "mkfs.reiserfs -qf $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.reiserfs -qf "$DEV" > /dev/null 2>&1 + log "mount -t reiserfs -o noatime,user_xattr $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t reiserfs -o noatime,user_xattr "$DEV" "$MPT" ERR=$? } mkfs_reiser4() { - log "mkfs.reiser4 -yf $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.reiser4 -yf $DEV - log "mount -t reiser4 -o noatime $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t reiser4 -o noatime $DEV $MPT + log "mkfs.reiser4 -yf $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.reiser4 -yf "$DEV" + log "mount -t reiser4 -o noatime $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t reiser4 -o noatime "$DEV" "$MPT" ERR=$? } mkfs_ufs() { - log "mkfs.ufs -J -O2 -U $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.ufs -J -O2 -U $DEV > /dev/null - log "mount -t ufs -o ufstype=ufs2,noatime $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t ufs -o ufstype=ufs2,noatime $DEV $MPT + log "mkfs.ufs -J -O2 -U $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.ufs -J -O2 -U "$DEV" > /dev/null + log "mount -t ufs -o ufstype=ufs2,noatime $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t ufs -o ufstype=ufs2,noatime "$DEV" "$MPT" ERR=$? } mkfs_xfs() { - log "mkfs.xfs -qf $DEV" >> $LOG/raw/commands.txt -$DEBUG mkfs.xfs -qf $DEV - log "mount -t xfs -o noatime $DEV $MPT" >> $LOG/raw/commands.txt -$DEBUG mount -t xfs -o noatime $DEV $MPT + log "mkfs.xfs -qf $DEV" >> "$LOG"/raw/commands.txt +$DEBUG mkfs.xfs -qf "$DEV" + log "mount -t xfs -o noatime $DEV $MPT" >> "$LOG"/raw/commands.txt +$DEBUG mount -t xfs -o noatime "$DEV" "$MPT" ERR=$? } mkfs_zfs() { # special case different operating systems -case `uname -s` in +case $(uname -s) in Linux) - if [ -z "`pgrep zfs-fuse`" ]; then + if [ -z "$(pgrep zfs-fuse)" ]; then log "zfs-fuse not running!" false fi ;; SunOS) - if [ ! -x "`which zpool`" ]; then + if [ ! -x "$(which zpool)" ]; then log "zfs not found!" false fi ;; esac - log "zpool create -f -O atime=off -m $MPT ztest $DEV" >> $LOG/raw/commands.txt -$DEBUG zpool create -f -O atime=off -m $MPT ztest $DEV + log "zpool create -f -O atime=off -m $MPT ztest $DEV" >> "$LOG"/raw/commands.txt +$DEBUG zpool create -f -O atime=off -m "$MPT" ztest "$DEV" ERR=$? } @@ -189,26 +189,26 @@ umountfs() { case $fs in zfs) # ...and special case Linux/ZFS again - if [ "`uname -s`" = Linux ] && [ -z "`pgrep zfs-fuse`" ]; then + if [ "$(uname -s)" = Linux ] && [ -z "$(pgrep zfs-fuse)" ]; then log "zfs-fuse not running!" 1 fi $DEBUG sync $DEBUG sleep 5 - log "zpool destroy -f ztest" >> $LOG/raw/commands.txt - $DEBUG zpool destroy -f ztest >> $LOG/raw/zfs.log 2>&1 + log "zpool destroy -f ztest" >> "$LOG"/raw/commands.txt + $DEBUG zpool destroy -f ztest >> "$LOG"/raw/zfs.log 2>&1 # sometimes, this just fails (why?) if [ ! $? = 0 ]; then - log "Destroying ZFS pool failed, will try again in 5 seconds!" >> $LOG/raw/zfs.log + log "Destroying ZFS pool failed, will try again in 5 seconds!" >> "$LOG"/raw/zfs.log $DEBUG sync $DEBUG sleep 5 - log "zpool destroy -f ztest" >> $LOG/raw/commands.txt + log "zpool destroy -f ztest" >> "$LOG"/raw/commands.txt $DEBUG zpool destroy -f ztest || log "Unmounting $fs failed!" 1 fi ;; *) - log "umount $MPT" >> $LOG/raw/commands.txt - $DEBUG umount $MPT || log "Unmounting $fs failed!" 1 + log "umount $MPT" >> "$LOG"/raw/commands.txt + $DEBUG umount "$MPT" || log "Unmounting $fs failed!" 1 ;; esac } @@ -220,10 +220,10 @@ esac run_bonnie() { eval conf_bonnie log "Running $b on $fs..." -echo $NUMFILES | awk -F: '{printf $1 ":" $2 ":1.1"}' | chkfree - log "bonnie++ -d $MPT -s $SIZE -n $NUMFILES -m $fs -r $RAM -x $NUMTESTS -u root" >> $LOG/raw/commands.txt -$DEBUG bonnie++ -d $MPT -s $SIZE -n $NUMFILES -m $fs -r $RAM -x $NUMTESTS -u root 1>$LOG/raw/bonnie-$fs.csv 2>$LOG/raw/bonnie-$fs.err -$DEBUG egrep -hv '^format' $LOG/raw/bonnie-*.csv | bon_csv2html > $LOG/bonnie.html +echo "$NUMFILES" | awk -F: '{printf $1 ":" $2 ":1.1"}' | chkfree + log "bonnie++ -d $MPT -s $SIZE -n $NUMFILES -m $fs -r $RAM -x $NUMTESTS -u root" >> "$LOG"/raw/commands.txt +$DEBUG bonnie++ -d "$MPT" -s "$SIZE" -n "$NUMFILES" -m "$fs" -r "$RAM" -x "$NUMTESTS" -u root 1>"$LOG"/raw/bonnie-"$fs".csv 2>"$LOG"/raw/bonnie-"$fs".err +$DEBUG egrep -hv '^format' "$LOG"/raw/bonnie-*.csv | bon_csv2html > "$LOG"/bonnie.html } ######################################################## @@ -234,49 +234,49 @@ run_stress() { # $Id: stress.sh,v 1.2 1999/02/10 10:58:04 rich Exp $ # eval conf_stress -log "Running $b on $fs (size: `du -sk "$CONTENT" | awk '{print $1 / 1024 " MB"}'`)..." -$DEBUG mkdir $MPT/stress || log "cannot create $MPT/stress" 1 -$DEBUG cd $MPT/stress || log "cannot cd into $MPT/stress" 1 +log "Running $b on $fs (size: $(du -sk "$CONTENT" | awk '{print $1 / 1024 " MB"}'))..." +$DEBUG mkdir "$MPT"/stress || log "cannot create $MPT/stress" 1 +$DEBUG cd "$MPT"/stress || log "cannot cd into $MPT/stress" 1 # computing MD5 sums over content directory -find $CONTENT -type f -exec md5sum '{}' + | sort > $MPT/content.sums +find "$CONTENT" -type f -exec md5sum '{}' + | sort > "$MPT"/content.sums # !!FIXME!! # starting stress test processes p=1 -while [ $p -le $CONCURRENT ]; do +while [ $p -le "$CONCURRENT" ]; do ( # wait for all processes to start up. if [ "$STAGGER" = "yes" ]; then - $DEBUG sleep `expr 2 \* $p` + $DEBUG sleep $(expr 2 \* $p) else $DEBUG sleep 1 fi r=1 - while [ $r -le $RUNS ]; do + while [ $r -le "$RUNS" ]; do log "Running stresstest in $MPT/stress/$p (r: $r)..." # Remove old directories. - $DEBUG rm -rf $MPT/stress/$p + $DEBUG rm -rf "$MPT"/stress/$p # copy content - $DEBUG mkdir $MPT/stress/$p || log "cannot create $MPT/stress/$p" - $DEBUG cp -dRx $CONTENT/* $MPT/stress/$p || log "cannot copy $CONTENT to $MPT/stress/$p" + $DEBUG mkdir "$MPT"/stress/$p || log "cannot create $MPT/stress/$p" + $DEBUG cp -dRx "$CONTENT"/* "$MPT"/stress/$p || log "cannot copy $CONTENT to $MPT/stress/$p" # compare the content and the copy. - $DEBUG cd $MPT/stress/$p - $DEBUG find . -type f -exec md5sum '{}' + | sort > $MPT/stress.$p - $DEBUG diff -q $MPT/content.sums $MPT/stress.$p + $DEBUG cd "$MPT"/stress/$p + $DEBUG find . -type f -exec md5sum '{}' + | sort > "$MPT"/stress.$p + $DEBUG diff -q "$MPT"/content.sums "$MPT"/stress.$p if [ $? != 0 ]; then log "corruption found in $MPT/stress/$p (r: $r)" continue fi - $DEBUG cd $MPT/stress - $DEBUG rm -f $MPT/stress.$p - r=`expr $r + 1` + $DEBUG cd "$MPT"/stress + $DEBUG rm -f "$MPT"/stress.$p + r=$(expr $r + 1) done ) & -p=`expr $p + 1` +p=$(expr $p + 1) done } @@ -284,40 +284,40 @@ done run_dbench() { eval conf_dbench log "Running $b on $fs..." - log "dbench -x -t $TIME -D $MPT $NPROC" >> $LOG/raw/commands.txt -$DEBUG dbench -x -t $TIME -D $MPT $NPROC > $LOG/raw/dbench-$fs.log -echo "$fs: `egrep '^Throughput' $LOG/raw/dbench-$fs.log`" >> $LOG/dbench.txt + log "dbench -x -t $TIME -D $MPT $NPROC" >> "$LOG"/raw/commands.txt +$DEBUG dbench -x -t "$TIME" -D "$MPT" "$NPROC" > "$LOG"/raw/dbench-"$fs".log +echo "$fs: $(egrep '^Throughput' "$LOG"/raw/dbench-"$fs".log)" >> "$LOG"/dbench.txt } run_iozone() { eval conf_iozone log "Running $b on $fs..." -$DEBUG cd $MPT || log "cannot cd into $MPT" 1 - log "iozone -a -c -S $CACHESIZE -s $FILESIZE" >> $LOG/raw/commands.txt -$DEBUG iozone -a -c -S $CACHESIZE -s $FILESIZE > $LOG/raw/iozone-$fs.log +$DEBUG cd "$MPT" || log "cannot cd into $MPT" 1 + log "iozone -a -c -S $CACHESIZE -s $FILESIZE" >> "$LOG"/raw/commands.txt +$DEBUG iozone -a -c -S "$CACHESIZE" -s "$FILESIZE" > "$LOG"/raw/iozone-"$fs".log } run_tiobench() { eval conf_tiobench log "Running $b on $fs..." - log "tiobench --identifier fs_"$fs" --size $SIZE --numruns $NUMRUNS --dir $MPT --block 4096 --block 8192 --threads 1" >> $LOG/raw/commands.txt -$DEBUG tiobench --identifier fs_"$fs" --size $SIZE --numruns $NUMRUNS --dir $MPT --block 4096 --block 8192 --threads 1 1>$LOG/raw/tiobench-$fs.log 2>$LOG/raw/tiobench-$fs.err + log "tiobench --identifier fs_"$fs" --size $SIZE --numruns $NUMRUNS --dir $MPT --block 4096 --block 8192 --threads 1" >> "$LOG"/raw/commands.txt +$DEBUG tiobench --identifier fs_"$fs" --size "$SIZE" --numruns "$NUMRUNS" --dir "$MPT" --block 4096 --block 8192 --threads 1 1>"$LOG"/raw/tiobench-"$fs".log 2>"$LOG"/raw/tiobench-"$fs".err # results are hard to summarize -echo " File Blk Num Avg Maximum Lat% Lat% CPU" > $LOG/tiobench.txt -echo " Size Size Thr Rate (CPU%) Latency Latency >2s >10s Eff" >> $LOG/tiobench.txt +echo " File Blk Num Avg Maximum Lat% Lat% CPU" > "$LOG"/tiobench.txt +echo " Size Size Thr Rate (CPU%) Latency Latency >2s >10s Eff" >> "$LOG"/tiobench.txt for t in "Sequential Reads" "Sequential Writes" "Random Reads" "Random Writes"; do - echo $t + echo "$t" # adjust -An for more/less than 2 different blocksizes! - grep -h -A5 "$t" $LOG/raw/tiobench-*.log | egrep '^fs_' + grep -h -A5 "$t" "$LOG"/raw/tiobench-*.log | egrep '^fs_' echo -done >> $LOG/tiobench.txt +done >> "$LOG"/tiobench.txt } run_generic() { eval conf_generic -SIZE=`du -sk "$CONTENT" | awk '{print $1 / 1024}'` -FSP=`echo $fs | awk '{printf "%9s", $1"\n"}'` # string padding, reiserfs being the longest one +SIZE=$(du -sk "$CONTENT" | awk '{print $1 / 1024}') +FSP=$(echo "$fs" | awk '{printf "%9s", $1"\n"}') # string padding, reiserfs being the longest one ERR="" log "Running $b on $fs..." # - copy content to fs @@ -327,141 +327,141 @@ log "Running $b on $fs..." # tar to GEN_BEGIN=$(date +%s) - log "mkdir "$MPT"/tar" >> $LOG/raw/commands.txt + log "mkdir "$MPT"/tar >> "$LOG"/raw/commands.txt $DEBUG mkdir "$MPT"/tar - log "cd "$CONTENT"" >> $LOG/raw/commands.txt + log "cd "$CONTENT" >> "$LOG"/raw/commands.txt $DEBUG cd "$CONTENT" - log "tar -cf - . | tar -C "$MPT"/tar -xf -" >> $LOG/raw/commands.txt -$DEBUG tar -cf - . 2>>$LOG/raw/generic-$fs.err | tar -C "$MPT"/tar -xf - 2>>$LOG/raw/generic-$fs.err - log "diff -r "$CONTENT" "$MPT"/tar" >> $LOG/raw/commands.txt -DIFF="`diff -r "$CONTENT" "$MPT"/tar 2>&1 | grep -v 'No such file or directory'`" + log "tar -cf - . | tar -C "$MPT"/tar -xf -" >> "$LOG"/raw/commands.txt +$DEBUG tar -cf - . 2>>"$LOG"/raw/generic-"$fs".err | tar -C "$MPT"/tar -xf - 2>>"$LOG"/raw/generic-"$fs".err + log "diff -r "$CONTENT" "$MPT"/tar" >> "$LOG"/raw/commands.txt +DIFF="$(diff -r "$CONTENT" "$MPT"/tar 2>&1 | grep -v 'No such file or directory')" [ -z "$DIFF" ] || ERR="- FAILED" $DEBUG sync $DEBUG cd /tmp GEN_END=$(date +%s) -GEN_DUR=`echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l` - SPEED=`echo "scale=2; $SIZE / $GEN_DUR" | bc -l 2>/dev/null` -log "$FSP.0: $GEN_DUR seconds ($SPEED MB/s) to copy $CONTENT to $MPT and running diff $ERR" > $LOG/raw/generic-$fs.log +GEN_DUR=$(echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l) + SPEED=$(echo "scale=2; $SIZE / $GEN_DUR" | bc -l 2>/dev/null) +log "$FSP.0: $GEN_DUR seconds ($SPEED MB/s) to copy $CONTENT to $MPT and running diff $ERR" > "$LOG"/raw/generic-"$fs".log ERR="" # tar from GEN_BEGIN=$(date +%s) - log "cd "$MPT"/tar" >> $LOG/raw/commands.txt + log "cd "$MPT"/tar" >> "$LOG"/raw/commands.txt $DEBUG cd "$MPT"/tar - log "tar -cf - . | dd of=/dev/null" >> $LOG/raw/commands.txt -$DEBUG tar -cf - . 2>>$LOG/raw/generic-$fs.err | dd of=/dev/null 2>>$LOG/raw/generic-$fs.err + log "tar -cf - . | dd of=/dev/null" >> "$LOG"/raw/commands.txt +$DEBUG tar -cf - . 2>>"$LOG"/raw/generic-"$fs".err | dd of=/dev/null 2>>"$LOG"/raw/generic-"$fs".err [ $? = 0 ] || ERR="- FAILED" $DEBUG sync $DEBUG cd /tmp GEN_END=$(date +%s) -GEN_DUR=`echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l` - SPEED=`echo "scale=2; $SIZE / $GEN_DUR" | bc -l 2>/dev/null` -log "$FSP.1: $GEN_DUR seconds ($SPEED MB/s) to tar up content on $MPT $ERR" >> $LOG/raw/generic-$fs.log +GEN_DUR=$(echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l) + SPEED=$(echo "scale=2; $SIZE / $GEN_DUR" | bc -l 2>/dev/null) +log "$FSP.1: $GEN_DUR seconds ($SPEED MB/s) to tar up content on $MPT $ERR" >> "$LOG"/raw/generic-"$fs".log ERR="" # copy GEN_BEGIN=$(date +%s) - log "mkdir "$MPT"/copy" >> $LOG/raw/commands.txt + log "mkdir "$MPT"/copy" >> "$LOG"/raw/commands.txt $DEBUG mkdir "$MPT"/copy - log "cp -xfpR "$CONTENT" "$MPT"/copy" >> $LOG/raw/commands.txt -$DEBUG cp -xfpR "$CONTENT" "$MPT"/copy 2>>$LOG/raw/generic-$fs.err + log "cp -xfpR "$CONTENT" "$MPT"/copy" >> "$LOG"/raw/commands.txt +$DEBUG cp -xfpR "$CONTENT" "$MPT"/copy 2>>"$LOG"/raw/generic-"$fs".err [ $? = 0 ] || ERR="- FAILED" $DEBUG sync GEN_END=$(date +%s) -GEN_DUR=`echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l` - SPEED=`echo "scale=2; $SIZE / $GEN_DUR" | bc -l 2>/dev/null` -log "$FSP.2: $GEN_DUR seconds ($SPEED MB/s) to copy $CONTENT on $MPT $ERR" >> $LOG/raw/generic-$fs.log +GEN_DUR=$(echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l) + SPEED=$(echo "scale=2; $SIZE / $GEN_DUR" | bc -l 2>/dev/null) +log "$FSP.2: $GEN_DUR seconds ($SPEED MB/s) to copy $CONTENT on $MPT $ERR" >> "$LOG"/raw/generic-"$fs".log ERR="" # cleanup before starting the next test -SIZE_M=`du -sk "$MPT" | awk '{print $1 / 1024}'` +SIZE_M=$(du -sk "$MPT" | awk '{print $1 / 1024}') GEN_BEGIN=$(date +%s) -$DEBUG echo "DEBUG-1: `df -i "$MPT" | grep -v Filesystem`" >> $LOG/raw/generic-$fs.err +$DEBUG echo "DEBUG-1: $(df -i "$MPT" | grep -v Filesystem)" >> "$LOG"/raw/generic-"$fs".err - log "rm -rf "$MPT"/tar "$MPT"/copy" >> $LOG/raw/commands.txt -$DEBUG rm -rf "$MPT"/tar "$MPT"/copy 2>>$LOG/raw/generic-$fs.err + log "rm -rf "$MPT"/tar "$MPT"/copy" >> "$LOG"/raw/commands.txt +$DEBUG rm -rf "$MPT"/tar "$MPT"/copy 2>>"$LOG"/raw/generic-"$fs".err [ $? = 0 ] || ERR="- FAILED" -$DEBUG echo "DEBUG-2: `df -i "$MPT" | grep -v Filesystem`" >> $LOG/raw/generic-$fs.err +$DEBUG echo "DEBUG-2: $(df -i "$MPT" | grep -v Filesystem)" >> "$LOG"/raw/generic-"$fs".err GEN_END=$(date +%s) -GEN_DUR=`echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l` - SPEED=`echo "scale=2; $SIZE_M / $GEN_DUR" | bc -l 2>/dev/null` -log "$FSP.3: $GEN_DUR seconds ($SPEED MB/s) to remove content from $MPT $ERR" >> $LOG/raw/generic-$fs.log +GEN_DUR=$(echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l) + SPEED=$(echo "scale=2; $SIZE_M / $GEN_DUR" | bc -l 2>/dev/null) +log "$FSP.3: $GEN_DUR seconds ($SPEED MB/s) to remove content from $MPT $ERR" >> "$LOG"/raw/generic-"$fs".log ERR="" # create many files GEN_BEGIN=$(date +%s) $DEBUG mkdir "$MPT"/manyfiles -log "for d in seq 1 $NUMDIRS; do mkdir -p $MPT/manyfiles/dir.d && cd $MPT/manyfiles/dir.d && seq 1 $NUMFILES | xargs touch; done" >> $LOG/raw/commands.txt -for d in `seq 1 $NUMDIRS`; do - $DEBUG mkdir -p $MPT/manyfiles/dir."$d" 2>>$LOG/raw/generic-$fs.err - $DEBUG cd $MPT/manyfiles/dir."$d" 2>>$LOG/raw/generic-$fs.err - seq 1 $NUMFILES | xargs touch 2>>$LOG/raw/generic-$fs.err +log "for d in seq 1 $NUMDIRS; do mkdir -p $MPT/manyfiles/dir.d && cd $MPT/manyfiles/dir.d && seq 1 $NUMFILES | xargs touch; done" >> "$LOG"/raw/commands.txt +for d in $(seq 1 "$NUMDIRS"); do + $DEBUG mkdir -p "$MPT"/manyfiles/dir."$d" 2>>"$LOG"/raw/generic-"$fs".err + $DEBUG cd "$MPT"/manyfiles/dir."$d" 2>>"$LOG"/raw/generic-"$fs".err + seq 1 "$NUMFILES" | xargs touch 2>>"$LOG"/raw/generic-"$fs".err done sync GEN_END=$(date +%s) -GEN_DUR=`echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l` - NUMDIRS_C=`find $MPT/manyfiles -type d | wc -l` -NUMFILES_C=`find $MPT/manyfiles -type f | wc -l` -[ `expr $NUMDIRS_C - 1` = $NUMDIRS ] && [ $NUMFILES_C = `expr $NUMDIRS \* $NUMFILES` ] || ERR="- FAILED" -log "$FSP.4: $GEN_DUR seconds to create $NUMFILES files in each of the $NUMDIRS directories $ERR" >> $LOG/raw/generic-$fs.log +GEN_DUR=$(echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l) + NUMDIRS_C=$(find "$MPT"/manyfiles -type d | wc -l) +NUMFILES_C=$(find "$MPT"/manyfiles -type f | wc -l) +[ $(expr "$NUMDIRS_C" - 1) = "$NUMDIRS" ] && [ "$NUMFILES_C" = $(expr "$NUMDIRS" \* "$NUMFILES") ] || ERR="- FAILED" +log "$FSP.4: $GEN_DUR seconds to create $NUMFILES files in each of the $NUMDIRS directories $ERR" >> "$LOG"/raw/generic-"$fs".log ERR="" # cleanup before starting the next test GEN_BEGIN=$(date +%s) -$DEBUG echo "DEBUG-3: `df -i "$MPT" | grep -v Filesystem`" >> $LOG/raw/generic-$fs.err - log "rm -rf "$MPT"/manyfiles" >> $LOG/raw/commands.txt -$DEBUG rm -rf "$MPT"/manyfiles 2>>$LOG/raw/generic-$fs.err +$DEBUG echo "DEBUG-3: $(df -i "$MPT" | grep -v Filesystem)" >> "$LOG"/raw/generic-"$fs".err + log "rm -rf "$MPT"/manyfiles" >> "$LOG"/raw/commands.txt +$DEBUG rm -rf "$MPT"/manyfiles 2>>"$LOG"/raw/generic-"$fs".err [ $? = 0 ] || ERR="- FAILED" -$DEBUG echo "DEBUG-4: `df -i "$MPT" | grep -v Filesystem`" >> $LOG/raw/generic-$fs.err +$DEBUG echo "DEBUG-4: $(df -i "$MPT" | grep -v Filesystem)" >> "$LOG"/raw/generic-"$fs".err GEN_END=$(date +%s) -GEN_DUR=`echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l` - INODES=`echo "$NUMFILES * $NUMDIRS" | bc` - SPEED=`echo "scale=2; $INODES / $GEN_DUR" | bc -l 2>/dev/null` -log "$FSP.5: $GEN_DUR seconds ($SPEED i/s) to remove $INODES inodes $ERR" >> $LOG/raw/generic-$fs.log +GEN_DUR=$(echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l) + INODES=$(echo "$NUMFILES * $NUMDIRS" | bc) + SPEED=$(echo "scale=2; $INODES / $GEN_DUR" | bc -l 2>/dev/null) +log "$FSP.5: $GEN_DUR seconds ($SPEED i/s) to remove $INODES inodes $ERR" >> "$LOG"/raw/generic-"$fs".log ERR="" # create many dirs (we just replace NUMDIRS with NUMFILES and vice versa) GEN_BEGIN=$(date +%s) $DEBUG mkdir -p "$MPT"/manydirs -log "for d in seq 1 $NUMFILES; do mkdir -p $MPT/manydirs/dir.d && cd $MPT/manydirs/dir.d && seq 1 $NUMDIRS | xargs touch; done" >> $LOG/raw/commands.txt -for d in `seq 1 $NUMFILES`; do - $DEBUG mkdir -p $MPT/manydirs/dir."$d" 2>>$LOG/raw/generic-$fs.err - $DEBUG cd $MPT/manydirs/dir."$d" 2>>$LOG/raw/generic-$fs.err - seq 1 $NUMDIRS | xargs touch 2>>$LOG/raw/generic-$fs.err +log "for d in seq 1 $NUMFILES; do mkdir -p $MPT/manydirs/dir.d && cd $MPT/manydirs/dir.d && seq 1 $NUMDIRS | xargs touch; done" >> "$LOG"/raw/commands.txt +for d in $(seq 1 "$NUMFILES"); do + $DEBUG mkdir -p "$MPT"/manydirs/dir."$d" 2>>"$LOG"/raw/generic-"$fs".err + $DEBUG cd "$MPT"/manydirs/dir."$d" 2>>"$LOG"/raw/generic-"$fs".err + seq 1 "$NUMDIRS" | xargs touch 2>>"$LOG"/raw/generic-"$fs".err done sync GEN_END=$(date +%s) -GEN_DUR=`echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l` - NUMDIRS_C=`find $MPT/manydirs -type d | wc -l` -NUMFILES_C=`find $MPT/manydirs -type f | wc -l` -[ `expr $NUMDIRS_C - 1` = $NUMFILES ] && [ $NUMFILES_C = `expr $NUMDIRS \* $NUMFILES` ] || ERR="- FAILED" -log "$FSP.6: $GEN_DUR seconds to create $NUMDIRS files in each of the $NUMFILES directories $ERR" >> $LOG/raw/generic-$fs.log +GEN_DUR=$(echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l) + NUMDIRS_C=$(find "$MPT"/manydirs -type d | wc -l) +NUMFILES_C=$(find "$MPT"/manydirs -type f | wc -l) +[ $(expr "$NUMDIRS_C" - 1) = "$NUMFILES" ] && [ "$NUMFILES_C" = $(expr "$NUMDIRS" \* "$NUMFILES") ] || ERR="- FAILED" +log "$FSP.6: $GEN_DUR seconds to create $NUMDIRS files in each of the $NUMFILES directories $ERR" >> "$LOG"/raw/generic-"$fs".log ERR="" # cleanup GEN_BEGIN=$(date +%s) -$DEBUG echo "DEBUG-5: `df -i "$MPT" | grep -v Filesystem`" >> $LOG/raw/generic-$fs.err - log "rm -rf "$MPT"/manydirs" >> $LOG/raw/commands.txt -$DEBUG rm -rf "$MPT"/manydirs 2>>$LOG/raw/generic-$fs.err +$DEBUG echo "DEBUG-5: $(df -i "$MPT" | grep -v Filesystem)" >> "$LOG"/raw/generic-"$fs".err + log "rm -rf "$MPT"/manydirs" >> "$LOG"/raw/commands.txt +$DEBUG rm -rf "$MPT"/manydirs 2>>"$LOG"/raw/generic-"$fs".err [ $? = 0 ] || ERR="- FAILED" -$DEBUG echo "DEBUG-6: `df -i "$MPT" | grep -v Filesystem`" >> $LOG/raw/generic-$fs.err +$DEBUG echo "DEBUG-6: $(df -i "$MPT" | grep -v Filesystem)" >> "$LOG"/raw/generic-"$fs".err GEN_END=$(date +%s) -GEN_DUR=`echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l` - INODES=`echo "$NUMFILES * $NUMDIRS" | bc` - SPEED=`echo "scale=2; $INODES / $GEN_DUR" | bc -l 2>/dev/null` -log "$FSP.7: $GEN_DUR seconds ($SPEED i/s) to remove $INODES inodes $ERR" >> $LOG/raw/generic-$fs.log +GEN_DUR=$(echo "scale=2; $GEN_END - $GEN_BEGIN" | bc -l) + INODES=$(echo "$NUMFILES * $NUMDIRS" | bc) + SPEED=$(echo "scale=2; $INODES / $GEN_DUR" | bc -l 2>/dev/null) +log "$FSP.7: $GEN_DUR seconds ($SPEED i/s) to remove $INODES inodes $ERR" >> "$LOG"/raw/generic-"$fs".log ERR="" # results across all tests, appended after each test -egrep -h seconds $LOG/raw/generic-$fs.log | sed 's/.*[0-9][0-9]://;s/\.[0-9]//' >> $LOG/raw/generic_all.txt +egrep -h seconds "$LOG"/raw/generic-"$fs".log | sed 's/.*[0-9][0-9]://;s/\.[0-9]//' >> "$LOG"/raw/generic_all.txt # sorted results, generated new after each run -for t in `seq 0 7`; do - fgrep -h ".$t:" $LOG/raw/generic-*.log | sort -n -k4 +for t in $(seq 0 7); do + fgrep -h ".$t:" "$LOG"/raw/generic-*.log | sort -n -k4 echo -done | sed 's/.*:[0-9][0-9]://;s/\.[0-9]//' > $LOG/generic.txt +done | sed 's/.*:[0-9][0-9]://;s/\.[0-9]//' > "$LOG"/generic.txt } ######################################################## @@ -492,7 +492,7 @@ for fs in $FILESYSTEMS; do BM_BEG=$(date +%s) # Linux: flush caches before we start - log "echo 3 > /proc/sys/vm/drop_caches" >> $LOG/raw/commands.txt + log "echo 3 > /proc/sys/vm/drop_caches" >> "$LOG"/raw/commands.txt echo 3 > /proc/sys/vm/drop_caches 2>/dev/null run_"$b" $DEBUG cd / @@ -501,18 +501,18 @@ for fs in $FILESYSTEMS; do $DEBUG sync umountfs BM_END=$(date +%s) - BM_DUR=`echo "scale=2; ( $BM_END - $BM_BEG ) / 60" | bc -l` + BM_DUR=$(echo "scale=2; ( $BM_END - $BM_BEG ) / 60" | bc -l) log "Running $b on $fs took $BM_DUR minutes." done FS_END=$(date +%s) - FS_DUR=`echo "scale=2; ( $FS_END - $FS_BEG ) / 60" | bc -l` + FS_DUR=$(echo "scale=2; ( $FS_END - $FS_BEG ) / 60" | bc -l) echo log "Running all benchmarks on $fs took $FS_DUR minutes." echo -done 2>&1 | tee $LOG/fs-bench.log +done 2>&1 | tee "$LOG"/fs-bench.log $DEBUG dmesg > "$LOG"/env/dmesg_post.txt END=$(date +%s) -DUR=`echo "scale=2; ( $END - $BEGIN ) / 60" | bc -l` +DUR=$(echo "scale=2; ( $END - $BEGIN ) / 60" | bc -l) log "Finished after $DUR minutes." diff --git a/benchmarks/password-test.sh b/benchmarks/password-test.sh index b736898..3d0d99e 100755 --- a/benchmarks/password-test.sh +++ b/benchmarks/password-test.sh @@ -9,26 +9,26 @@ # Password length and number of passwords required if [ -z "$1" ]; then - echo "Usage: $(basename $0) [length] [num]" + echo "Usage: $(basename "$0") [length] [num]" exit 1 else LEN="$1" NUM="$2" # See the comment for r_pwqgen below - if [ $LEN -gt 22 ]; then + if [ "$LEN" -gt 22 ]; then echo "WARNING: \"length\" is greater than 22, results for pwqgen may not be correct!" fi # See the comment for r_openssl below - if [ $LEN -gt 64 ]; then + if [ "$LEN" -gt 64 ]; then echo "WARNING: \"length\" is greater than 64, results for openssl may not be correct!" fi fi stats() { # arguments: FAILED, NUM, TYPE, TIME_E, TIME_S -echo "$FAILED passwords ($(echo "scale=2; $FAILED / $NUM * 100" | bc -l)%) failed for $c, runtime: $(expr $TIME_E - $TIME_S) seconds." +echo "$FAILED passwords ($(echo "scale=2; $FAILED / $NUM * 100" | bc -l)%) failed for $c, runtime: $(expr "$TIME_E" - "$TIME_S") seconds." } # Password checkers @@ -42,7 +42,7 @@ parallel --pipe pwqcheck -1 --multi 2>/dev/null | fgrep -c -v 'OK:' # Password generators r_pwgen() { -pwgen -s -1 $LEN $NUM +pwgen -s -1 "$LEN" "$NUM" } # @@ -61,7 +61,7 @@ pwgen -s -1 $LEN $NUM # r_pwqgen() { # The following is good enough for passwords of length 22 characters and below: -for a in $(seq 1 $NUM); do +for a in $(seq 1 "$NUM"); do pwqgen random=85 done | cut -c-"$LEN" | egrep -o "^.{$LEN}$" @@ -72,14 +72,14 @@ done | cut -c-"$LEN" | egrep -o "^.{$LEN}$" } r_apg() { -apg -a 1 -m $LEN -x $LEN -n $NUM +apg -a 1 -m "$LEN" -x "$LEN" -n "$NUM" } r_gpw() { # gpw: Password Generator # https://www.multicians.org/thvv/tvvtools.html#gpw # USAGE: gpw [npasswds] [pwlength<100] -gpw $NUM $LEN +gpw "$NUM" "$LEN" } r_makepasswd() { @@ -93,12 +93,12 @@ r_makepasswd() { # > https://koji.fedoraproject.org/koji/packageinfo?packageID=17537 # # makepasswd --chars=$LEN --count=$NUM # Debian -makepasswd -l $LEN -n $NUM # Fedora +makepasswd -l "$LEN" -n "$NUM" # Fedora } r_urandom() { -for a in $(seq 1 $NUM); do - tr -dc A-Za-z0-9_ < /dev/urandom | head -c $LEN | xargs +for a in $(seq 1 "$NUM"); do + tr -dc A-Za-z0-9_ < /dev/urandom | head -c "$LEN" | xargs done } @@ -111,7 +111,7 @@ r_openssl() { # two equal signs ("=="). Using -hex would limit our charset too much though. Also, # since we're reading line-by-line, we have an upper limit of 64 characters. # -for a in $(seq 1 $NUM); do +for a in $(seq 1 "$NUM"); do openssl rand -base64 64 | head -1 done | sed 's/.=$//' | cut -c-"$LEN" } @@ -123,7 +123,7 @@ for c in cracklib pwqcheck; do TIME_S=$(date +%s) FAILED=$(r_$g | r_$c) TIME_E=$(date +%s) - stats $FAILED $NUM $c $TIME_E $TIME_S + stats "$FAILED" "$NUM" $c "$TIME_E" "$TIME_S" done echo done diff --git a/benchmarks/ssh-features.sh b/benchmarks/ssh-features.sh deleted file mode 100755 index 3164a60..0000000 --- a/benchmarks/ssh-features.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh -# -# (c)2014 Christian Kujau -# -# Attempts to open an SSH connection with different Ciphers, MACs and -# Key Exchange Algorithms. The output can be fed to ssh-performance.sh later on. -# -# Note: Starting with OpenSSH 6.3, we can use "ssh -Q" to enumerate all known -# ciphers, MAC and key exchange algorithms, so this script is kinda obsolete now. -# -# Run with: -# ./ssh-features.sh dummy@host0 2>&1 | tee ssh-eval.log -# - -# Find out which ciphers are supported in _our_ version. And we do this by looking up its manpage...is -# there really no other way? (Apart from running strings(1) on the SSH binary) -CIPHERS=$(man ssh_config | grep -A5 aes128-ctr, | fgrep , | xargs echo | sed 's/,/ /g') - MACS=$(man ssh_config | grep -A15 MACs | egrep ' [hu]mac' | xargs echo | sed 's/,/ /g') - KEX=$(man ssh_config | grep -A10 KexAlgorithms | egrep '(ecdh|diffie|curve)' | xargs echo | sed 's/,/ /g') - -ssh -V 2>&1 | cat - -echo "Ciphers (`echo $CIPHERS | wc -w`):" -echo $CIPHERS -echo - -echo "MACs (`echo $MACS | wc -w`):" -echo $MACS -echo - -echo "KexAlgorithms (`echo $KEX | wc -w`):" -echo $KEX -echo - -if [ -z "$1" ]; then - echo "Usage: $0 [user@][host]" - exit 1 -else - host="$1" -fi - -ssh -v "$host" true 2>&1 | egrep 'Local version|Remote proto' -echo -for c in $CIPHERS; do - for m in $MACS; do - for k in $KEX; do - printf "cipher: $c mac: $m kex: $k " - ssh -o Ciphers="$c" -o MACs="$m" -o KexAlgorithms="$k" "$host" true 2>/dev/null - echo "exit: $?" - done - done -done diff --git a/benchmarks/ssh-performance.sh b/benchmarks/ssh-performance.sh index 7f60de6..3a3645e 100755 --- a/benchmarks/ssh-performance.sh +++ b/benchmarks/ssh-performance.sh @@ -11,9 +11,9 @@ # > https://anongit.mindrot.org/openssh.git/tree/regress/cipher-speed.sh # _help() { - echo "Usage: $(basename $0) run [user@][host] [size-in-MB] [runs] | tee report.out" - echo " $(basename $0) report [report.out] [top]" - echo " $(basename $0) worst [report.out] [top]" + echo "Usage: $(basename "$0") run [user@][host] [size-in-MB] [runs] | tee report.out" + echo " $(basename "$0") report [report.out] [top]" + echo " $(basename "$0") worst [report.out] [top]" echo echo "Note: Cipher, MAC and Kex algorithms can also be controlled by" echo " the CIPHER, MAC and KEX environment variables." @@ -42,7 +42,7 @@ CIPHER="${CIPHER:-$(ssh -Q cipher)}" KEX="${KEX:-$(ssh -Q kex)}" # Possible combinations -COMB=$(expr $(echo $CIPHER | awk '{print NF}') \* $(echo $MAC | awk '{print NF}') \* $(echo $KEX | awk '{print NF}')) +COMB=$(expr $(echo "$CIPHER" | awk '{print NF}') \* $(echo "$MAC" | awk '{print NF}') \* $(echo "$KEX" | awk '{print NF}')) # Initialize combination counter n=1 @@ -59,7 +59,7 @@ for c in $CIPHER; do # [ $RUNS -lt 10 ] && printf " " # Formatting quirk... a=$(date +%s) - while [ $r -le $RUNS ]; do + while [ $r -le "$RUNS" ]; do printf "$r\b" >&2 # We don't need this on stdout dd if=/dev/zero bs=1024k count="$SIZE" 2>/dev/null | \ @@ -77,7 +77,7 @@ for c in $CIPHER; do # Calculate the average time for one run; reset the error counter. b=$(date +%s) - d=$(echo \( $b - $a \) / $RUNS | bc) + d=$(echo \( "$b" - "$a" \) / "$RUNS" | bc) [ -z "$ERR" ] && echo "$d seconds avg." || unset ERR n=$((n+1)) done @@ -90,39 +90,39 @@ done # _report() { echo "### Top-$TOP overall" -grep seconds "$FILE" | sort $REVERSE -nk9 | head -$TOP +grep seconds "$FILE" | sort "$REVERSE" -nk9 | head -"$TOP" echo echo "### Fastest cipher" -awk '/seconds/ {print $3, $9, "seconds"}' "$FILE" | sort $REVERSE -nk2 | head -$TOP | uniq -c +awk '/seconds/ {print $3, $9, "seconds"}' "$FILE" | sort "$REVERSE" -nk2 | head -"$TOP" | uniq -c echo echo "### Fastest MAC" -awk '/seconds/ {print $5, $9, "seconds"}' "$FILE" | sort $REVERSE -nk2 | head -$TOP | uniq -c +awk '/seconds/ {print $5, $9, "seconds"}' "$FILE" | sort "$REVERSE" -nk2 | head -"$TOP" | uniq -c echo echo "### Fastest Kex" -awk '/seconds/ {print $7, $9, "seconds"}' "$FILE" | sort $REVERSE -nk2 | head -$TOP | uniq -c +awk '/seconds/ {print $7, $9, "seconds"}' "$FILE" | sort "$REVERSE" -nk2 | head -"$TOP" | uniq -c echo echo "### Top-$TOP for each cipher" for c in $(awk '/seconds/ {print $3}' "$FILE" | sort -u); do echo "### Cipher: $c" - fgrep seconds "$FILE" | grep "$c" | sort $REVERSE -nk9 | head -$TOP + fgrep seconds "$FILE" | grep "$c" | sort "$REVERSE" -nk9 | head -"$TOP" echo done echo "### Top-$TOP for each MAC" for m in $(awk '/seconds/ {print $5}' "$FILE" | sort -u); do echo "### MAC: $m" - fgrep seconds "$FILE" | grep "$m" | sort $REVERSE -nk9 | head -$TOP + fgrep seconds "$FILE" | grep "$m" | sort "$REVERSE" -nk9 | head -"$TOP" echo done echo "### Top-$TOP for each Kex" for k in $(awk '/seconds/ {print $7}' "$FILE" | sort -u); do echo "### Kex: $k" - fgrep seconds "$FILE" | grep "$k" | sort $REVERSE -nk9 | head -$TOP + fgrep seconds "$FILE" | grep "$k" | sort "$REVERSE" -nk9 | head -"$TOP" echo done } @@ -144,7 +144,7 @@ case $1 in if [ ! -f "$2" ]; then _help else - [ $1 = "worst" ] && REVERSE="-r" # Hall of Shame + [ "$1" = "worst" ] && REVERSE="-r" # Hall of Shame FILE="$2" TOP=${3:-5} _report diff --git a/benchmarks/test-digests.sh b/benchmarks/test-digests.sh index f21d634..fbdb263 100755 --- a/benchmarks/test-digests.sh +++ b/benchmarks/test-digests.sh @@ -16,7 +16,7 @@ if [ -f "$1" ]; then FILE="$1" RUNS=${2:-1} else - echo "Usage: $(basename $0) [file] [n]" + echo "Usage: $(basename "$0") [file] [n]" exit 1 fi @@ -26,15 +26,15 @@ fi get_time() { TEST="$1" # Only one run for rhash_benchmark - [ $TEST = "rhash_benchmark" ] && n=1 || n=$RUNS + [ "$TEST" = "rhash_benchmark" ] && n=1 || n=$RUNS shift TIME_A=$(date +%s) - for i in `seq 1 $n`; do + for i in $(seq 1 "$n"); do $DEBUG $@ done TIME_B=$(date +%s) - echo "TEST: $TEST / DIGEST: $d / $(echo $TIME_B - $TIME_A | bc -l) seconds over $n runs" + echo "TEST: $TEST / DIGEST: $d / $(echo "$TIME_B" - "$TIME_A" | bc -l) seconds over $n runs" } diff --git a/benchmarks/tmpfs-ramfs-ramdisk.sh b/benchmarks/tmpfs-ramfs-ramdisk.sh index ca76763..259e3e4 100755 --- a/benchmarks/tmpfs-ramfs-ramdisk.sh +++ b/benchmarks/tmpfs-ramfs-ramdisk.sh @@ -24,12 +24,12 @@ mkdir -p -m0700 $DIR_TMPFS $DIR_RAMFS $DIR_RAMDISK $RESULTS || exit benchmark() { B_DIR="$1" B_TYPE="$2" - B_SIZE=$(expr $SIZE / 5) # -s file size - B_RAM=$(expr $SIZE / 10) # -r RAM size - B_NUMFILES=$(expr $SIZE / $B_SIZE) # -n file count + B_SIZE=$(expr "$SIZE" / 5) # -s file size + B_RAM=$(expr "$SIZE" / 10) # -r RAM size + B_NUMFILES=$(expr "$SIZE" / "$B_SIZE") # -n file count B_NUMTESTS=1 # -x test count - bonnie++ -d $B_DIR -s $B_SIZE -n $B_NUMFILES -m $B_TYPE -r $B_RAM -x $B_NUMTESTS -u root \ - 1>$RESULTS/bonnie-$B_TYPE.csv 2>$RESULTS/bonnie-$B_TYPE.err + bonnie++ -d "$B_DIR" -s "$B_SIZE" -n "$B_NUMFILES" -m "$B_TYPE" -r "$B_RAM" -x $B_NUMTESTS -u root \ + 1>$RESULTS/bonnie-"$B_TYPE".csv 2>$RESULTS/bonnie-"$B_TYPE".err } # Switch @@ -37,14 +37,14 @@ case $1 in tmpfs) mount -t tmpfs -o size="$SIZE"M tmpfs $DIR_TMPFS - benchmark $DIR_TMPFS $1 + benchmark $DIR_TMPFS "$1" umount $DIR_TMPFS ;; ramfs) mount -t ramfs -o size="$SIZE"M ramfs $DIR_RAMFS - benchmark $DIR_RAMFS $1 + benchmark $DIR_RAMFS "$1" umount $DIR_RAMFS ;; @@ -67,8 +67,8 @@ case $1 in M_OPTIONS="-qf" ;; esac - mkfs.$fs $M_OPTIONS /dev/ram0 > /dev/null 2>&1 || continue - mount -t $fs /dev/ram0 $DIR_RAMDISK || continue + mkfs."$fs" $M_OPTIONS /dev/ram0 > /dev/null 2>&1 || continue + mount -t "$fs" /dev/ram0 $DIR_RAMDISK || continue benchmark $DIR_RAMDISK "$1"_"$fs" sleep 1 umount $DIR_RAMDISK || break diff --git a/benchmarks/vbox-nic-bench.sh b/benchmarks/vbox-nic-bench.sh index a49a286..5e988a0 100755 --- a/benchmarks/vbox-nic-bench.sh +++ b/benchmarks/vbox-nic-bench.sh @@ -16,8 +16,8 @@ NICTYPES="Am79C970A Am79C973 82540EM 82543GC 82545EM virtio" if [ $# -ne 3 ]; then - echo "Usage: $(basename $0) [vm1] [vm2] [num]" - echo " $(basename $0) [report] [file.log] [num]" + echo "Usage: $(basename "$0") [vm1] [vm2] [num]" + echo " $(basename "$0") [report] [file.log] [num]" echo "" echo " NOTES:" echo " * An iperf3 server MUST be started on vm1 after boot." @@ -43,7 +43,7 @@ if [ "$1" = "report" ]; then fi # Dry-run? -[ $NUM = 0 ] && DEBUG=echo +[ "$NUM" = 0 ] && DEBUG=echo die() { echo "$@" @@ -63,40 +63,40 @@ ison() { for nic2 in $NICTYPES; do echo "### NIC2: $nic2 -- shutting down $VM2" - ison $VM2 && ( $DEBUG VBoxManage controlvm $VM2 acpipowerbutton || die "VBoxManage controlvm $VM2 acpipowerbutton FAILED" ) + ison "$VM2" && ( $DEBUG VBoxManage controlvm "$VM2" acpipowerbutton || die "VBoxManage controlvm $VM2 acpipowerbutton FAILED" ) $DEBUG sleep 20 echo "### NIC2: $nic2 -- setting NIC to $nic2 on $VM2" - $DEBUG VBoxManage modifyvm $VM2 --nictype1 "$nic2" || die "VBoxManage modifyvm $VM2 --nictype1 "$nic2" FAILED" - $DEBUG VBoxManage showvminfo $VM2 --machinereadable | grep -A1 -w nic1 + $DEBUG VBoxManage modifyvm "$VM2" --nictype1 "$nic2" || die "VBoxManage modifyvm $VM2 --nictype1 "$nic2" FAILED" + $DEBUG VBoxManage showvminfo "$VM2" --machinereadable | grep -A1 -w nic1 echo "### NIC2: $nic2 -- starting $VM2" - $DEBUG VBoxManage startvm $VM2 --type headless || die "VBoxManage startvm $VM2 --type headless FAILED" + $DEBUG VBoxManage startvm "$VM2" --type headless || die "VBoxManage startvm $VM2 --type headless FAILED" # $DEBUG VBoxHeadless --startvm $VM2 & # [ $? = 0 ] || die "VBoxHeadless --startvm $VM2 FAILED" $DEBUG sleep 30 for nic1 in $NICTYPES; do echo "### NIC1: $nic1 -- shutting down $VM1" - ison $VM1 && ( $DEBUG VBoxManage controlvm $VM1 acpipowerbutton || die "VBoxManage controlvm $VM1 acpipowerbutton FAILED" ) + ison "$VM1" && ( $DEBUG VBoxManage controlvm "$VM1" acpipowerbutton || die "VBoxManage controlvm $VM1 acpipowerbutton FAILED" ) $DEBUG sleep 20 echo "### NIC1: $nic1 -- setting NIC to $nic1 on $VM1" - ison $VM1 || ( $DEBUG VBoxManage modifyvm $VM1 --nictype1 "$nic1" || die "VBoxManage modifyvm $VM1 --nictype1 "$nic1" FAILED" ) - $DEBUG VBoxManage showvminfo $VM1 --machinereadable | grep -A1 -w nic1 + ison "$VM1" || ( $DEBUG VBoxManage modifyvm "$VM1" --nictype1 "$nic1" || die "VBoxManage modifyvm $VM1 --nictype1 "$nic1" FAILED" ) + $DEBUG VBoxManage showvminfo "$VM1" --machinereadable | grep -A1 -w nic1 echo "### NIC1: $nic1 -- starting $VM1" - $DEBUG VBoxManage startvm $VM1 --type headless || die "VBoxManage startvm $VM1 --type headless FAILED" + $DEBUG VBoxManage startvm "$VM1" --type headless || die "VBoxManage startvm $VM1 --type headless FAILED" # $DEBUG VBoxHeadless --startvm $VM1 & # [ $? = 0 ] || die "VBoxHeadless --startvm $VM1 FAILED" $DEBUG sleep 30 echo "### Running iperf3 tests. NIC1: $nic1 NIC2: $nic2" a=1 - while [ $a -le $NUM ] || [ $NUM = 0 ]; do + while [ $a -le "$NUM" ] || [ "$NUM" = 0 ]; do echo "### RUN $a of $NUM" # NAT # $DEBUG ssh -p2001 192.168.56.1 "iperf3 -f M -c 10.0.2.5" || die "ssh -p2001 192.168.56.1 ... FAILED" - $DEBUG ssh $VM2 "iperf3 -f M -T \"$nic1 - $nic2\" -c $VM1" || die "ssh $VM2 -- FAILED" + $DEBUG ssh "$VM2" "iperf3 -f M -T \"$nic1 - $nic2\" -c $VM1" || die "ssh $VM2 -- FAILED" [ -z "$DEBUG" ] && a=$((a++1)) || break done | egrep 'RUN|ssh|sender|receiver' # The "ssh" is only matched in $DEBUG mode echo diff --git a/checksum_file.sh b/checksum_file.sh index 8a02918..93d6d50 100755 --- a/checksum_file.sh +++ b/checksum_file.sh @@ -32,13 +32,13 @@ PATH=/bin:/usr/bin:/sbin:/usr/local/bin:/opt/local/bin:/opt/csw/bin:/usr/sfw/bin print_usage() { - echo "Usage: $(basename $0) [get] [file]" - echo " $(basename $0) [set] [file]" - echo " $(basename $0) [get-set] [file]" - echo " $(basename $0) [check-set] [file]" - echo " $(basename $0) [check] [file]" - echo " $(basename $0) [remove] [file]" - echo " $(basename $0) [test]" + echo "Usage: $(basename "$0") [get] [file]" + echo " $(basename "$0") [set] [file]" + echo " $(basename "$0") [get-set] [file]" + echo " $(basename "$0") [check-set] [file]" + echo " $(basename "$0") [check] [file]" + echo " $(basename "$0") [remove] [file]" + echo " $(basename "$0") [test]" echo "" echo " get-set - sets a new checksum if none is found, print checksum otherwise." echo " check-set - sets a new checksum if none is found, verify checksum otherwise." @@ -56,7 +56,7 @@ fi # Print, exit if necessary do_log() { echo "$1" - [ -n "$2" ] && exit $2 + [ -n "$2" ] && exit "$2" } # CALC @@ -172,19 +172,19 @@ CHECKSUM_C=$(_calc "$1") case ${OS} in Darwin) - xattr -w user.checksum.${DIGEST} ${CHECKSUM_C} "$1" + xattr -w user.checksum.${DIGEST} "${CHECKSUM_C}" "$1" ;; FreeBSD) - pxattr -n user.checksum.${DIGEST} -v ${CHECKSUM_C} "$1" + pxattr -n user.checksum.${DIGEST} -v "${CHECKSUM_C}" "$1" ;; NetBSD) - setextattr user checksum.${DIGEST} ${CHECKSUM_C} "$1" + setextattr user checksum.${DIGEST} "${CHECKSUM_C}" "$1" ;; Linux) - setfattr --name user.checksum.${DIGEST} --value ${CHECKSUM_C} -- "$1" + setfattr --name user.checksum.${DIGEST} --value "${CHECKSUM_C}" -- "$1" ;; SunOS) @@ -256,7 +256,7 @@ case ${ACTION} in do_log "ERROR: failed to calculate/get the ${DIGEST} checksum for file ${FILE}!" 1 # Compare checksums - if [ ${CHECKSUM_S} = ${CHECKSUM_C} ]; then + if [ "${CHECKSUM_S}" = "${CHECKSUM_C}" ]; then echo "FILE: ${FILE} - OK" true else @@ -304,22 +304,22 @@ case ${ACTION} in if [ ! -f "$TEMP" ]; then do_log "Failed to create temporary file ${TEMP}!" 1 else - date > ${TEMP} + date > "${TEMP}" fi # More, and more elaborate tests needed. for action in get get-set check-set check remove remove check-set remove check; do echo "### ACTION: ${action}" - $0 ${action} ${TEMP} + $0 ${action} "${TEMP}" echo $? && echo done echo "### ACTION: set - alter - check" - $0 set ${TEMP} + $0 set "${TEMP}" echo "Modifying ${TEMP}..." - echo . >> ${TEMP} - $0 check ${TEMP} - echo $? + echo . >> "${TEMP}" + $0 check "${TEMP}" + echo "RC: $?" ;; ####### HELP diff --git a/convert-music.sh b/convert-music.sh index 8bc2c73..9094d39 100755 --- a/convert-music.sh +++ b/convert-music.sh @@ -13,7 +13,7 @@ # > https://forums.gentoo.org/viewtopic-t-463068.html # if [ ! $# -eq 2 ] || [ ! -f "$2" ]; then - echo "Usage: `basename $0` [conversion] [file]" + echo "Usage: $(basename "$0") [conversion] [file]" echo "Conversions: flac2mp3, m4a2mp3, ogg2mp3" exit 1 else @@ -70,13 +70,13 @@ case $CONVERSION in DATE=$(faad --info "$FILE" 2>&1 | grep ^date | sed 's/^.*: //') GENRE=$(faad --info "$FILE" 2>&1 | grep ^genre | sed 's/^.*: //') - faad --stdio "$FILE" | lame $LAMEARGS --tn "${TRACK:-0}" --tt "$TITLE" \ + faad --stdio "$FILE" | lame "$LAMEARGS" --tn "${TRACK:-0}" --tt "$TITLE" \ --ta "$ARTIST" --tl "$ALBUM" --ty "$DATE" --tg "${GENRE:-12}" - "$OUTPUT" ;; ogg2mp3) OUTPUT=${FILE%.ogg}.mp3 - eval `ogginfo -qv "$FILE" | awk '/ARTIST/ || /TITLE/' | sed 's/^ //'` + eval $(ogginfo -qv "$FILE" | awk '/ARTIST/ || /TITLE/' | sed 's/^ //') # echo "ARTIST: $ARTIST TITLE: $TITLE" if [ -z "$ARTIST" ] || [ -z "$TITLE" ]; then echo "WARNING: Not enough metadata, trying to gather track information from filename! ($FILE)" @@ -84,16 +84,16 @@ case $CONVERSION in TITLE=$(ls "$FILE" | sed 's/^[0-9]* - //;s/\.ogg//') # Try to find the ARLBUM via the directory name - cd "`dirname "$FILE"`" - ALBUM="`basename $(pwd)`" + cd "$(dirname "$FILE")" || exit + ALBUM="$(basename $(pwd))" echo "TRACK: $TRACK TITLE: $TITLE ALBUM: $ALBUM" fi - oggdec --quiet "$FILE" --output - | lame $LAMEARGS --tn "${TRACK:-0}" --tt "$TITLE" \ + oggdec --quiet "$FILE" --output - | lame "$LAMEARGS" --tn "${TRACK:-0}" --tt "$TITLE" \ --tl "$ALBUM" - "$OUTPUT" ;; *) - echo "`basename $0`: conversion $CONVERSION unknow." + echo "$(basename "$0"): conversion $CONVERSION unknow." exit 1 ;; esac diff --git a/diff2html.sh b/diff2html.sh index 1c2ed58..445f9bb 100755 --- a/diff2html.sh +++ b/diff2html.sh @@ -110,15 +110,15 @@ while [ $? -eq 0 ]; do # Output the line. if [ "$cls" ]; then - printf ''${s}'' + printf ''"${s}"'' else - printf ${s} + printf "${s}" fi read -r s done IFS=$OIFS -if [ $diffseen -eq 0 ] && [ $onlyseen -eq 0 ]; then +if [ $diffseen -eq 0 ] && [ "$onlyseen" -eq 0 ]; then printf '' else echo "" diff --git a/find_dups.sh b/find_dups.sh index a44cbb7..3131929 100755 --- a/find_dups.sh +++ b/find_dups.sh @@ -36,7 +36,7 @@ # xargs -0 md5sum | uniq -w32 -D # _help() { - echo "Usage: `basename $0` [smart|brute] [directories]" + echo "Usage: $(basename "$0") [smart|brute] [directories]" exit 1 } @@ -48,19 +48,19 @@ else DIRS=$@ fi -TEMP=`mktemp` +TEMP=$(mktemp) trap "rm -f $TEMP $TEMP.fallout $TEMP.fallout.md5 $TEMP.fallout.dup; exit" EXIT INT TERM HUP case $MODE in smart) - BEGIN=`date +%s` + BEGIN=$(date +%s) printf "### Gather size & name of all files... " - find $DIRS -type f -exec stat -c %s:%n '{}' + > $TEMP + find "$DIRS" -type f -exec stat -c %s:%n '{}' + > "$TEMP" cat "$TEMP" | wc -l # No UUOC here, but we don't want the leading spaces from wc(1) printf "### Gather files of the same size... " - cut -d: -f1 $TEMP | sort | uniq -d | while read s; do - grep ^"$s" $TEMP + cut -d: -f1 "$TEMP" | sort | uniq -d | while read s; do + grep ^"$s" "$TEMP" done | sort -u > "$TEMP".fallout # The "sort -u" at the end is crucial :) cat "$TEMP".fallout | wc -l @@ -77,29 +77,29 @@ case $MODE in grep ^"$d" "$TEMP".fallout.md5 echo done | tee "$TEMP".fallout.dup - END=`date +%s` + END=$(date +%s) # Statistics echo echo " All files: $(cat "$TEMP" | wc -l)" echo "Files with same size: $(cat "$TEMP".fallout | wc -l)" - echo " Duplicate files: $(expr `egrep -c '^[[:alnum:]]' "$TEMP".fallout.dup` / 2)" - echo " Time to complete: $(expr $END - $BEGIN) seconds" + echo " Duplicate files: $(expr $(egrep -c '^[[:alnum:]]' "$TEMP".fallout.dup) / 2)" + echo " Time to complete: $(expr "$END" - "$BEGIN") seconds" echo ;; brute) - BEGIN=`date +%s` - find $DIRS -type f -exec md5sum '{}' + > "$TEMP" - sort -k1 $TEMP | uniq -w32 -D > "$TEMP".dup # Print _all_ duplicate lines + BEGIN=$(date +%s) + find "$DIRS" -type f -exec md5sum '{}' + > "$TEMP" + sort -k1 "$TEMP" | uniq -w32 -D > "$TEMP".dup # Print _all_ duplicate lines echo echo "Duplicate files:" && cat "$TEMP".dup - END=`date +%s` + END=$(date +%s) echo echo " All files: $(cat "$TEMP" | wc -l)" - echo " Duplicate files: $(expr `egrep -c '^[[:alnum:]]' "$TEMP".dup` / 2)" - echo " Time to complete: $(expr $END - $BEGIN) seconds" + echo " Duplicate files: $(expr $(egrep -c '^[[:alnum:]]' "$TEMP".dup) / 2)" + echo " Time to complete: $(expr "$END" - "$BEGIN") seconds" ;; *) diff --git a/ipsec_iproute.sh b/ipsec_iproute.sh index cce2723..f5a5ce1 100755 --- a/ipsec_iproute.sh +++ b/ipsec_iproute.sh @@ -11,7 +11,7 @@ # > https://backreference.org/2014/11/12/on-the-fly-ipsec-vpn-with-iproute2/ # if [ $# -ne 7 ] || [ ! -f "$HOME/.xfrm-keys" ]; then - echo "Usage: $(basename $0) [SRC LOCAL DEV] [DST REMOTE DEV] [start|stop|status]" + echo "Usage: $(basename "$0") [SRC LOCAL DEV] [DST REMOTE DEV] [start|stop|status]" echo " Note: We also need a key file in \$HOME/.xfrm-keys, with NN bit keys and" echo " a 32 bit id, generated like this:" echo "" @@ -32,7 +32,7 @@ else fi # Read keys -eval $(grep -v ^\# $HOME/.xfrm-keys) +eval $(grep -v ^\# "$HOME"/.xfrm-keys) if [ -z "$CIPHER" ] || [ -z "$KEY1" ] || [ -z "$KEY2" ] || [ -z "$ID" ]; then echo "Could not read cipher/keys from $HOME/.xfrm-keys!" exit 1 @@ -45,17 +45,17 @@ fi case $ACTION in start) # XFRM - $DEBUG ip xfrm state add src $SRC dst $DST proto esp spi $ID reqid $ID mode tunnel auth sha256 $KEY1 enc "$CIPHER" $KEY2 - $DEBUG ip xfrm state add src $DST dst $SRC proto esp spi $ID reqid $ID mode tunnel auth sha256 $KEY1 enc "$CIPHER" $KEY2 - $DEBUG ip xfrm policy add src $LOCAL dst $REMOTE dir out tmpl src $SRC dst $DST proto esp reqid $ID mode tunnel - $DEBUG ip xfrm policy add src $REMOTE dst $LOCAL dir in tmpl src $DST dst $SRC proto esp reqid $ID mode tunnel + $DEBUG ip xfrm state add src "$SRC" dst "$DST" proto esp spi "$ID" reqid "$ID" mode tunnel auth sha256 "$KEY1" enc "$CIPHER" "$KEY2" + $DEBUG ip xfrm state add src "$DST" dst "$SRC" proto esp spi "$ID" reqid "$ID" mode tunnel auth sha256 "$KEY1" enc "$CIPHER" "$KEY2" + $DEBUG ip xfrm policy add src "$LOCAL" dst "$REMOTE" dir out tmpl src "$SRC" dst "$DST" proto esp reqid "$ID" mode tunnel + $DEBUG ip xfrm policy add src "$REMOTE" dst "$LOCAL" dir in tmpl src "$DST" dst "$SRC" proto esp reqid "$ID" mode tunnel # Routing - $DEBUG ip addr add $LOCAL/32 dev lo - $DEBUG ip route add $REMOTE/32 dev $DEVL src $LOCAL + $DEBUG ip addr add "$LOCAL"/32 dev lo + $DEBUG ip route add "$REMOTE"/32 dev "$DEVL" src "$LOCAL" # And again on the remote side - ssh $DST /bin/sh -x << EOF + ssh "$DST" /bin/sh -x << EOF # XFRM $DEBUG ip xfrm state add src $SRC dst $DST proto esp spi $ID reqid $ID mode tunnel auth sha256 $KEY1 enc "$CIPHER" $KEY2 $DEBUG ip xfrm state add src $DST dst $SRC proto esp spi $ID reqid $ID mode tunnel auth sha256 $KEY1 enc "$CIPHER" $KEY2 @@ -69,7 +69,7 @@ EOF stop) # Remote - ssh $DST /bin/sh -x << EOF + ssh "$DST" /bin/sh -x << EOF # Routing $DEBUG ip route del $LOCAL/32 dev $DEVR src $REMOTE $DEBUG ip addr del $REMOTE/32 dev lo @@ -80,20 +80,20 @@ EOF $DEBUG ip xfrm state del src $SRC dst $DST proto esp spi $ID EOF # Routing - $DEBUG ip route del $REMOTE/32 dev $DEVL src $LOCAL - $DEBUG ip addr del $LOCAL/32 dev lo + $DEBUG ip route del "$REMOTE"/32 dev "$DEVL" src "$LOCAL" + $DEBUG ip addr del "$LOCAL"/32 dev lo # XFRM - $DEBUG ip xfrm policy del src $REMOTE dst $LOCAL dir in - $DEBUG ip xfrm policy del src $LOCAL dst $REMOTE dir out - $DEBUG ip xfrm state del src $DST dst $SRC proto esp spi $ID - $DEBUG ip xfrm state del src $SRC dst $DST proto esp spi $ID + $DEBUG ip xfrm policy del src "$REMOTE" dst "$LOCAL" dir in + $DEBUG ip xfrm policy del src "$LOCAL" dst "$REMOTE" dir out + $DEBUG ip xfrm state del src "$DST" dst "$SRC" proto esp spi "$ID" + $DEBUG ip xfrm state del src "$SRC" dst "$DST" proto esp spi "$ID" ;; status) $DEBUG ip xfrm state && ip xfrm policy echo - ssh $DST /bin/sh -x << EOF + ssh "$DST" /bin/sh -x << EOF $DEBUG ip xfrm state && ip xfrm policy EOF ;; diff --git a/kerninst.sh b/kerninst.sh deleted file mode 100755 index 6839a93..0000000 --- a/kerninst.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/bin/sh -# -# (c)2010 Christian Kujau -# -# Install a new kernel, System.map and .config, -# but not via the usual "make install" routine -# -umask 0022 - -# unset me! -# DEBUG=echo - -if [ ! `id -u` = 0 ]; then - echo "Please execute as root or use sudo!" - exit 1 -fi - -usage() { -echo "Usage: `basename $0` [directory] [builddir]" -echo " `basename $0` [user@]host:[directory] [builddir]" -exit 1 -} - -# set correct arch, imagename -case `uname -m` in - ppc|ppc64) - ARCH=powerpc - IMAGE=zImage - ;; - - x86_64|x86|i686) - ARCH=x86 - IMAGE=bzImage - ;; -esac - -# We need a destination to install to (could be a directory or host:/directory) -if [ -z "$1" ]; then - usage -fi - -# destination is a local directory -if [ -d "$1" ]; then - MODE=local - DEST_DIR="$1" - [ -w "$DEST_DIR" ] || usage - -# destination is remote -else - MODE=remote - DEST_HOST=`echo $1 | awk -F: '{print $1}'` - DEST_DIR=`echo $1 | awk -F: '{print $2}'` - # Make sure we can resolve our host - getent hosts `echo $DEST_HOST | sed 's/^.*@//'` > /dev/null || usage -fi - -# We might specify a build directory -if [ -d "$2" ] && [ -x "$2"/vmlinux ]; then - BUILDDIR="$2" - OPTIONS="O=$BUILDDIR" - -# ...or we omit it, but a vmlinux must be in place then -elif [ -x ./vmlinux ]; then - BUILDDIR=. - -else - echo "vmlinux not found in $BUILDDIR (no [builddir] specified?)" - usage -fi - -case $MODE in - remote) - TDIR=`$DEBUG mktemp -d` - $DEBUG cp "$BUILDDIR"/vmlinux "$TDIR"/vmlinux - $DEBUG cp "$BUILDDIR"/System.map "$TDIR"/System.map - $DEBUG cp "$BUILDDIR"/.config "$TDIR"/config - - printf "Do you want to save the current kernel? (Y/n) " && read c - echo - if [ "$c" = n ]; then - echo "Not saving the current kernel!" - else - echo "Saving the current kernel on $DEST_HOST:$DEST_DIR..." - $DEBUG ssh "$DEST_HOST" \ - "mv "$DEST_DIR"/vmlinux "$DEST_DIR"/vmlinux.old && \ - mv "$DEST_DIR"/System.map "$DEST_DIR"/System.map.old && \ - mv "$DEST_DIR"/config "$DEST_DIR"/config.old" - fi - - echo - echo "Copying kernel to $DEST_HOST:$DEST_DIR..." - $DEBUG scp "$TDIR"/* "$DEST_HOST":"$DEST_DIR" - $DEBUG rm -rf "$TDIR" - $DEBUG cd "$BUILDDIR" - echo - echo "Installing modules locally..." - $DEBUG make $OPTIONS modules_install - ;; - - local) - printf "Do you want to save the current kernel? (Y/n) " && read c - echo - if [ "$c" = n ]; then - echo "Not saving the current kernel!" - else - echo "Saving the current kernel in $DEST_DIR..." - $DEBUG mv "$DEST_DIR"/$IMAGE "$DEST_DIR"/$IMAGE.old - $DEBUG mv "$DEST_DIR"/vmlinux "$DEST_DIR"/vmlinux.old - $DEBUG mv "$DEST_DIR"/System.map "$DEST_DIR"/System.map.old - $DEBUG mv "$DEST_DIR"/config "$DEST_DIR"/config.old - fi - $DEBUG cp "$BUILDDIR"/arch/"$ARCH"/boot/$IMAGE "$DEST_DIR"/$IMAGE && \ - $DEBUG cp "$BUILDDIR"/vmlinux "$DEST_DIR"/vmlinux && \ - $DEBUG cp "$BUILDDIR"/System.map "$DEST_DIR"/System.map && \ - $DEBUG cp "$BUILDDIR"/.config "$DEST_DIR"/config && \ - $DEBUG cd "$BUILDDIR" && \ - $DEBUG make $OPTIONS modules_install - ;; -esac diff --git a/keyboard-backlight.sh b/keyboard-backlight.sh index 570c37d..9c2f8bc 100755 --- a/keyboard-backlight.sh +++ b/keyboard-backlight.sh @@ -43,22 +43,22 @@ exit 1 case $1 in up) # BRIGHTNESS will be capped at 255 anyway - if [ $BRIGHTNESS -lt 255 ]; then - expr $BRIGHTNESS + $INCREMENT > $BACKLIGHT + if [ "$BRIGHTNESS" -lt 255 ]; then + expr "$BRIGHTNESS" + $INCREMENT > $BACKLIGHT else - die $BRIGHTNESS + die "$BRIGHTNESS" fi ;; down) - if [ $BRIGHTNESS -gt 0 ]; then - VALUE=`expr $BRIGHTNESS - $INCREMENT` + if [ "$BRIGHTNESS" -gt 0 ]; then + VALUE=$(expr "$BRIGHTNESS" - $INCREMENT) # BRIGHTNESS cannot be negative - [ $VALUE -lt 0 ] && VALUE=0 + [ "$VALUE" -lt 0 ] && VALUE=0 echo $VALUE > $BACKLIGHT else - die $BRIGHTNESS + die "$BRIGHTNESS" fi ;; @@ -72,8 +72,8 @@ case $1 in [\-0-9]*) VALUE=$1 - if [ $VALUE -ge 0 ] && [ $VALUE -le 255 ]; then - echo $VALUE > $BACKLIGHT + if [ "$VALUE" -ge 0 ] && [ "$VALUE" -le 255 ]; then + echo "$VALUE" > $BACKLIGHT else echo "Invalid argument ($VALUE). Please provide a value from 0 to 255!" exit 1 @@ -81,7 +81,7 @@ case $1 in ;; *) - echo "Use: `basename $0` [up|down|total|off|value]" + echo "Use: $(basename "$0") [up|down|total|off|value]" exit 1 ;; esac diff --git a/port-mgmt.sh b/port-mgmt.sh index ebc7149..56372c5 100755 --- a/port-mgmt.sh +++ b/port-mgmt.sh @@ -21,10 +21,10 @@ case $1 in port echo outdated port upgrade -u outdated if [ -f "$LAST" ]; then - A=`stat -f %m "$LAST"` - B=`date +%s` + A=$(stat -f %m "$LAST") + B=$(date +%s) # Cleanup every 1209600 seconds (14 days) - if [ `echo $B - $A | bc` -gt 1209600 ]; then + if [ $(echo "$B" - "$A" | bc) -gt 1209600 ]; then echo "port clean all..." echo nice -n20 port clean -f --all all > /dev/null fi @@ -34,7 +34,7 @@ case $1 in ;; *) - echo "Usage: `basename $0` [i|a|u]" + echo "Usage: $(basename "$0") [i|a|u]" echo "i - list inactive" echo "a - list active" echo "u - upgrade" diff --git a/print-authorized-keys.sh b/print-authorized-keys.sh deleted file mode 100755 index 02ef381..0000000 --- a/print-authorized-keys.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# -# (c)2013 Christian Kujau -# -# There's currently no way to list the fingerprints of all the keys in -# authorized_keys separately. This may be useful to see if a certain -# public key is listed in authorized_keys. -# -# Unfortunately ssh-keygen cannot read from stdin, so we have to use -# a temporary file here. -# - -# We need a temporary file, even on MacOS -TEMP=`mktemp 2>/dev/null || mktemp -t authorized_keys 2>/dev/null` -if [ ! -O "$TEMP" ]; then - echo "Cannot create TEMP file, bailing out!" - exit 2 -fi - -i=1 -egrep -v '^#|^$' ~/.ssh/authorized_keys | while read l; do - printf "key: $i " - echo "$l" > "$TEMP" - ssh-keygen -f "$TEMP" -l - i=$((i+1)) -done -rm -f "$TEMP" diff --git a/qemu-tap.sh b/qemu-tap.sh index 23af0c8..c833afe 100755 --- a/qemu-tap.sh +++ b/qemu-tap.sh @@ -12,7 +12,7 @@ INTERFACE=en1 DEBUG=sudo # See how we were called -case $(basename $0) in +case $(basename "$0") in qemu-ifup) # Needed for the symlink umask 0022 diff --git a/rsnapshot/rsnapshot-ready.sh b/rsnapshot/rsnapshot-ready.sh index ddbc4de..aad6676 100755 --- a/rsnapshot/rsnapshot-ready.sh +++ b/rsnapshot/rsnapshot-ready.sh @@ -12,13 +12,13 @@ FILE=/var/run/rsnapshot.ready # DEBUG=echo if [ $# = 0 ]; then - echo "Usage: `basename $0` [dir1] [dir2] [...]" + echo "Usage: $(basename "$0") [dir1] [dir2] [...]" exit 1 fi for d in $@; do # normalize - DIR=`echo $d | sed 's/\/$//'` + DIR=$(echo "$d" | sed 's/\/$//') test -n "$DEBUG" && echo "DIR: $DIR" # check if we're mounted diff --git a/rsnapshot/rsnapshot-rotate.sh b/rsnapshot/rsnapshot-rotate.sh index 86355a5..669cc9f 100755 --- a/rsnapshot/rsnapshot-rotate.sh +++ b/rsnapshot/rsnapshot-rotate.sh @@ -6,12 +6,12 @@ CONF="/etc/rsnapshot" if [ ! $# = 1 ]; then - HOSTS=`ls "$CONF"/rsnapshot-*.conf | sed 's/.*\/rsnapshot-//;s/\.conf//' | xargs echo | sed 's/ /|/g'` - echo "Usage: `basename $0` [$HOSTS]" + HOSTS=$(ls "$CONF"/rsnapshot-*.conf | sed 's/.*\/rsnapshot-//;s/\.conf//' | xargs echo | sed 's/ /|/g') + echo "Usage: $(basename "$0") [$HOSTS]" exit 1 else CONF="$CONF"/rsnapshot-"$1".conf - DIR=`awk '/^snapshot_root/ {print $2}' $CONF` + DIR=$(awk '/^snapshot_root/ {print $2}' "$CONF") # Don't let rsnapshot-wrapper remount our backup store WRAPPER_CONF="/usr/local/etc/rsnapshot-wrapper.conf" @@ -23,9 +23,9 @@ else fi for i in daily weekly monthly; do - C=`ls -d "$DIR"/"$i".* 2>/dev/null | wc -l` + C=$(ls -d "$DIR"/"$i".* 2>/dev/null | wc -l) j=0 - while [ $j -le $C ]; do + while [ $j -le "$C" ]; do echo "("$j"/"$C") rsnapshot -c "$CONF" "$i"..." rsnapshot -c "$CONF" "$i" j=$((j+1)) diff --git a/rsnapshot/rsnapshot-wrapper.sh b/rsnapshot/rsnapshot-wrapper.sh index 3f22afa..a00d21c 100755 --- a/rsnapshot/rsnapshot-wrapper.sh +++ b/rsnapshot/rsnapshot-wrapper.sh @@ -63,8 +63,8 @@ for c in $CONFDIR/*.conf; do # backup if the client wants us to. # unset ROOT RLOG NAME HOST PORT OS TAG RDY MSG - eval `awk '/^snapshot_root/ {print "ROOT="$2}; /^logfile/ {print "RLOG="$2}' $c` - eval `awk -F\# '/^##HOST=/ {print $3}' "$c"` + eval $(awk '/^snapshot_root/ {print "ROOT="$2}; /^logfile/ {print "RLOG="$2}' "$c") + eval $(awk -F\# '/^##HOST=/ {print $3}' "$c") # Set NAME to HOST if it wasn't set explicitly in the configuration file [ -z "$NAME" ] && NAME="$HOST" @@ -94,7 +94,7 @@ for c in $CONFDIR/*.conf; do fi # See if the remote system is up & running - nc -w1 -z $HOST $PORT > /dev/null + nc -w1 -z "$HOST" "$PORT" > /dev/null if [ ! $? = 0 ]; then log "**** Host $NAME not responding on port $PORT, skipping!" continue @@ -108,22 +108,22 @@ for c in $CONFDIR/*.conf; do case "$OS" in Darwin) # We need TAG=Darwin for this to work! - TAG2=$(ssh -4 -p$PORT $HOST "uname -s" 2>/dev/null) + TAG2=$(ssh -4 -p"$PORT" "$HOST" "uname -s" 2>/dev/null) ;; Windows) # We need TAG=Windows for this to work! - TAG2="$(ssh -4 -p$PORT $HOST "cygcheck.exe -s" 2>/dev/null | awk '/^Windows/ {print $1}')" + TAG2="$(ssh -4 -p"$PORT" "$HOST" "cygcheck.exe -s" 2>/dev/null | awk '/^Windows/ {print $1}')" ;; BusyBox) # We need TAG=BusyBox for this to work! - TAG2="$(ssh -4 -p$PORT $HOST "ls --help" 2>&1 | awk '/BusyBox/ {print $1}')" + TAG2="$(ssh -4 -p"$PORT" "$HOST" "ls --help" 2>&1 | awk '/BusyBox/ {print $1}')" ;; *) # Most Unix/Linux systems have "hostid" - TAG2="$(ssh -4 -p$PORT $HOST "hostid" 2>/dev/null)" + TAG2="$(ssh -4 -p"$PORT" "$HOST" "hostid" 2>/dev/null)" ;; esac @@ -137,8 +137,8 @@ for c in $CONFDIR/*.conf; do if [ -n "$RDY" ]; then # See if the remote site wants us to backup - TEMP=`$DEBUG mktemp` - $DEBUG rsync -4 --port="$PORT" $HOST:"$RDY" "$TEMP" 2>/dev/null + TEMP=$($DEBUG mktemp) + $DEBUG rsync -4 --port="$PORT" "$HOST":"$RDY" "$TEMP" 2>/dev/null if [ ! $? = 0 ]; then log "**** File \""$NAME":"$RDY"\" ($OS) not found, skipping!" $DEBUG rm -f "$TEMP" @@ -163,9 +163,9 @@ for c in $CONFDIR/*.conf; do # All tests passed, let's do this now log "**** $NAME/$OS ($INTERVAL) started..." | tee -a "$RLOG" if [ -z "$DEBUG" ]; then - rsnapshot -c "$c" $INTERVAL >> "$RLOG" 2>&1 + rsnapshot -c "$c" "$INTERVAL" >> "$RLOG" 2>&1 else - echo rsnapshot -c "$c" $INTERVAL + echo rsnapshot -c "$c" "$INTERVAL" fi # See if we were successful @@ -206,7 +206,7 @@ PID=$(cat "$PIDFILE" 2>/dev/null) if [ -n "$PID" ]; then ps -p"$PID" > /dev/null if [ $? = 0 ]; then - log "**** There's another instance of $(basename $0) running (PID: $PID)" 1 + log "**** There's another instance of $(basename "$0") running (PID: $PID)" 1 else echo $$ > "$PIDFILE" fi @@ -216,7 +216,7 @@ fi } # Be nice to others -[ -n "$NICE" ] && renice $NICE $$ > /dev/null +[ -n "$NICE" ] && renice "$NICE" $$ > /dev/null [ -n "$IDLE" ] && ionice -c 3 -p $$ > /dev/null # Main @@ -224,14 +224,14 @@ case $1 in hourly|daily|weekly|monthly) run_only_once CYCLE="$1" - preexec 2>&1 | tee -a $LOG - backup "$CYCLE" 2>&1 | tee -a $LOG - postexec 2>&1 | tee -a $LOG + preexec 2>&1 | tee -a "$LOG" + backup "$CYCLE" 2>&1 | tee -a "$LOG" + postexec 2>&1 | tee -a "$LOG" ;; stats) # Not Y3K safe :-) - for h in `awk '/^2[0-9][0-9][0-9].*\((hourly|daily|weekly|monthly)\) finished/ {print $5}' "$LOG" | sort -u`; do + for h in $(awk '/^2[0-9][0-9][0-9].*\((hourly|daily|weekly|monthly)\) finished/ {print $5}' "$LOG" | sort -u); do MINUTES=$(egrep "${h}.*finished" "$LOG" | awk '{sum+=$9} END {printf "%0.1f\n", sum/NR}') echo "Host $h took an average of $MINUTES minutes to complete." done | sort -nk7 @@ -245,8 +245,8 @@ case $1 in ;; *) - echo "Usage: $(basename $0) [hourly|daily|weekly|monthly]" - echo " $(basename $0) [stats]" + echo "Usage: $(basename "$0") [hourly|daily|weekly|monthly]" + echo " $(basename "$0") [stats]" exit 1 ;; esac diff --git a/security_checks.sh b/security_checks.sh deleted file mode 100755 index 090186d..0000000 --- a/security_checks.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/sh -# -# (c)2010 Christian Kujau -# -# Execute a few security checks, keep state across runs. -# rkhunter: http://rkhunter.sourceforge.net/ -# lynis: https://cisofy.com/lynis/ -# chkrootkit: http://www.chkrootkit.org/ -# -STATE=/var/run/sec.state -MAXAGE=7 - -# unset me! -# DEBUG=echo - -# BTS# 231267 -if [ -f "$STATE" ] && [ ! -L "$STATE" ]; then - : -else - $DEBUG rm -f "$STATE" - $DEBUG touch "$STATE" -fi - -check() { -C="$1" -AGE=`echo \( $(date +%s) - $(stat -c %Y "$STATE"."$C") \) / 604800 | bc` -diff -u "$STATE"."$C" "$STATE"."$C".$$ > "$STATE"."$C".diff - -# If something changed, display the differences -if [ -s "$STATE"."$C".diff ]; then - cat "$STATE"."$C".diff - mv "$STATE"."$C".$$ "$STATE"."$C" - -# If nothing changed, display statefile anyway (every MAXAGE days) -elif [ "$AGE" -ge $MAXAGE ]; then - cat "$STATE"."$C" - rm "$STATE"."$C".$$ - -# If nothing changed, clean up -else - rm "$STATE"."$C".$$ -fi -} - - -case $1 in chkrootkit) - $DEBUG touch "$STATE".chkrootkit - cd /opt/chkrootkit/sbin - $DEBUG ./chkrootkit > "$STATE".chkrootkit.$$ - check chkrootkit - ;; - - rkhunter) - $DEBUG touch "$STATE".rkhunter - $DEBUG /opt/rkhunter/bin/rkhunter --pkgmgr DPKG --nocolors --logfile /var/log/rkhunter.log \ - --skip-keypress --report-warnings-only --check > "$STATE".rkhunter.$$ - check rkhunter - ;; - - lynis) - $DEBUG touch "$STATE".lynis - cd /opt/lynis - yes | $DEBUG ./lynis --checkall --no-colors > "$STATE".lynis.$$ - check lynis - ;; - - show) - for c in chkrootkit rkhunter lynis; do - echo "======= $c =======" - cat "$STATE"."$c" - done - ;; - - RESET) - for c in chkrootkit rkhunter lynis; do - echo > "$STATE"."$c" - done - ;; - - *) - echo "Usage: `basename $0` [chkrootkit|rkhunter|lynis]" - echo " [show]" - echo " [RESET]" - exit 1 - ;; -esac diff --git a/sensors_adt746x.sh b/sensors_adt746x.sh index fdfb32d..eec4b8e 100755 --- a/sensors_adt746x.sh +++ b/sensors_adt746x.sh @@ -21,7 +21,7 @@ case $1 in ;; -h) - echo "Usage: `basename $0` [-s] ....print short summary" + echo "Usage: $(basename "$0") [-s] ....print short summary" echo " [-b] ....print battery status" echo " [-h] ....print this help text" echo "With no arguments supplied, we will print out a long summary." diff --git a/system-update.sh b/system-update.sh deleted file mode 100755 index 8d7f361..0000000 --- a/system-update.sh +++ /dev/null @@ -1,168 +0,0 @@ -#!/bin/sh -# -# (c)2012 Christian Kujau -# -# Automatic upgrades for various distributions. -# -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/local/bin:/opt/csw/bin - URL=https://raw.githubusercontent.com/ckujau/scripts/master/system-update.sh - LOG=/var/log/system-update.log - -umask 0022 - -case $1 in - start) - : - ;; - - selfupdate) - printf "This will update $0 - continue? (y/N) " - read c - if [ "$c" = y ]; then - FILE=`mktemp` - wget -q "$URL" -O "$FILE" - grep '^# END' "$FILE" > /dev/null - - if [ $? = 0 ]; then - mv "$FILE" "$0" || exit $? - exit 0 - else - echo "Something went wrong, update failed!" - rm "$FILE" || exit $? - exit 2 - fi - else - exit $? - fi - ;; - - *) - echo "Usage: `basename $0` [start|selfupdate]" - exit 1 - ;; -esac - -rebootmsg() { -# A reboot may be required. But don't flood our motd. -grep "Reboot may be required" /etc/motd > /dev/null -if [ $? = 0 ]; then - : -else - echo "$0: Reboot may be required! (`date`)" | tee -a /etc/motd -fi -exit 0 -} - -die() { -echo "$0 failed: $1" -[ -z "$2" ] && exit "$2" -} - -# Redirect everything LOG -exec >> "$LOG" 2>&1 - -# -# Find out which OS we are on. -# -# Linux -# Note: For Linux systems "lsb_release" could be used, but may -# not be installed so we try to determine the distribution the -# old fashioned way. -if [ $(uname -s) = "Linux" ]; then - # Debian/Ubuntu - if [ -f /etc/debian_version ]; then - APT_LISTCHANGES_FRONTEND=none - DEBIAN_FRONTEND=noninteractive - $DEBUG apt-get --quiet=2 update || die "apt-get update" 1 - $DEBUG apt-get --quiet --yes --verbose-versions \ - --option Dpkg::Options::="--force-confdef --force-confold" dist-upgrade \ - || die "apt-get dist-upgrade" 1 - $DEBUG apt-get --quiet clean || die "apt-get clean" 1 - $DEBUG deborphan --guess-all || die "deborphan --guess-all" 1 - - # Reboot required? - grep -q 'linux-image' "$LOG" && rebootmsg - fi - - # Gentoo - if [ -f /etc/gentoo-release ]; then - NOCOLOR=true - emerge --sync > /dev/null || die "emerge --sync" 1 - emerge portage || die "emerge portage" 1 - emerge --update --deep --newuse --with-bdeps=y world || die "emerge update" 1 - emerge --depclean || die "emerge --depclean" 1 - revdep-rebuild || die "revdep-rebuild" 1 - eselect news read new || die "eselect news read new" 1 - -# # Reboot required? -# grep -q 'Verifying : kernel-' "$LOG" && rebootmsg - fi - - # Redhat/Fedora/CentOS - if [ -f /etc/redhat-release ]; then - # Note: --assumeyes is unknown to older Yum versions - $DEBUG yum -y update || die "yum update" 1 - $DEBUG yum clean packages || die "yum clean packages" 1 - - # Reboot required? - grep -A10000 Installing "$LOG" | grep -q kernel- && rebootmsg - fi - - # SUSE, openSUSE - if [ -f /etc/SuSE-release ]; then - $DEBUG zypper --quiet --non-interactive update || die "zypper update" 1 - $DEBUG zypper clean || die "zypper clean" 1 - -# # Reboot required? -# grep -q 'Verifying : kernel-' "$LOG" && rebootmsg - fi -fi - -# Darwin/MacOS X -if [ $(uname -s) = "Darwin" ]; then - # MacOS - $DEBUG softwareupdate --install --all --verbose - $DEBUG diskutil umount "Recovery HD" - - # MacPorts - if [ -n "$(port version)" ]; then - $DEBUG port selfupdate || die "port selfupdate" 1 - $DEBUG port echo outdated || die "port echo outdated" 1 - $DEBUG port upgrade -u outdated || die "port upgrade -u outdated" 1 - - # Whan was the last time we did "port clean"? - LAST="$HOME"/.ports.clean - if [ -f "$LAST" ]; then - A=`stat -f %m "$LAST"` - B=`date +%s` - # Cleanup every 1209600 seconds (14 days) - if [ `echo $B - $A | bc` -gt 1209600 ]; then - echo "port clean -f --all all" - $DEBUG nice -n 5 port clean -f --all all > /dev/null \ - || die "port clean" 1 - touch "$LAST" - fi - else - touch "$LAST" - fi - fi - - # Reboot required? - grep -q 'Reboot' "$LOG" && rebootmsg -fi - -# SunOS/Solaris -if [ $(uname -s) = "SunOS" ]; then - # IPS? - : - - # OpenCSW - if [ -f /opt/csw/etc/pkgutil.conf ]; then - $DEBUG pkgutil --catalog --upgrade --yes || die "pkgutil --upgrade" 1 - fi - - # Reboot required? - # grep 'foo' "$LOG" > /dev/null && rebootmsg -fi - -# END diff --git a/ternet/flop.sh b/ternet/flop.sh index ab384d3..b2430ea 100755 --- a/ternet/flop.sh +++ b/ternet/flop.sh @@ -6,14 +6,14 @@ # DIR=/var/www/ternet while read URL; do - SURL=$(echo ${URL} | cut -d" " -f1) - echo ${SURL} | egrep -qi "\.(jp(e)?g|gif|png|tiff|bmp|ico)$" && + SURL=$(echo "${URL}" | cut -d" " -f1) + echo "${SURL}" | egrep -qi "\.(jp(e)?g|gif|png|tiff|bmp|ico)$" && ( umask 002 PIC=$$-${RANDOM} - wget -q -O ${DIR}/${PIC}.tmp ${SURL} + wget -q -O ${DIR}/${PIC}.tmp "${SURL}" convert -quiet ${DIR}/${PIC}.tmp -flop ${DIR}/${PIC}.png rm -f ${DIR}/${PIC}.tmp echo http://127.0.0.1/ternet/${PIC}.png - ) || echo $URL + ) || echo "$URL" done diff --git a/ternet/iptables-ternet.sh b/ternet/iptables-ternet.sh index 2298f23..c0cc775 100755 --- a/ternet/iptables-ternet.sh +++ b/ternet/iptables-ternet.sh @@ -24,7 +24,7 @@ case $1 in ;; *) - echo "Usage: `basename $0` [start|stop]" + echo "Usage: $(basename "$0") [start|stop]" exit 1 ;; esac diff --git a/vbox-sysrq.sh b/vbox-sysrq.sh old mode 100644 new mode 100755 index 5dc7892..f175594 --- a/vbox-sysrq.sh +++ b/vbox-sysrq.sh @@ -26,7 +26,7 @@ # https://web.archive.org/web/20130102094426/http://blog.frameos.org/2011/06/08/changing-linux-terminals-in-virtualbox-using-vboxmanage # if [ ! $# -eq 2 ]; then - echo "Usage: `basename $0` [vm] [sysrq]" + echo "Usage: $(basename "$0") [vm] [sysrq]" echo " [vm] help" exit 1 else @@ -35,7 +35,7 @@ else fi # https://www.kernel.org/doc/Documentation/admin-guide/sysrq.rst -PRESS=`echo " +PRESS=$(echo " b|30 # reBoot c|2E # Crash e|12 # terminate-all-tasks @@ -56,16 +56,16 @@ t|14 # show-task-states u|16 # Unmount w|11 # show-blocked-tasks z|2C # dump-ftrace-buffer -" | grep "^"$SYSRQ"" | cut -c3,4` +" | grep -E "^${SYSRQ}" | cut -c3,4) if [ -n "$PRESS" ]; then - RELEASE=`printf "%X\n" $((0x$PRESS + 0x80))` # or: 'obase=16; ibase=16; $PRESS + 80 | bc' + RELEASE=$(printf "%X\n" $((0x$PRESS + 0x80))) # or: 'obase=16; ibase=16; $PRESS + 80 | bc' set -x - VBoxManage controlvm "$VM" keyboardputscancode 1d 38 54 $PRESS $RELEASE d4 b8 9d + VBoxManage controlvm "$VM" keyboardputscancode 1d 38 54 "$PRESS" "$RELEASE" d4 b8 9d else echo - echo "Unknown sysrq key! ("$SYSRQ")" - egrep '^.\|' $0 + echo "Unknown sysrq key! ("${SYSRQ}")" + egrep '^.\|' "$0" echo exit 1 fi