From 9e66e2271fa4a54607e90f834369b407b737b480 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 25 Dec 2020 13:49:03 +0100 Subject: [PATCH] Optimized code --- .../analyze/client/not_encrypted_ssh_keys.sh | 4 +- scripts/analyze/system/dd_optimal_bs_test.sh | 37 ------------------- .../encryption/storage/raid1/mount_on_boot.sh | 1 + 3 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 scripts/analyze/system/dd_optimal_bs_test.sh diff --git a/scripts/analyze/client/not_encrypted_ssh_keys.sh b/scripts/analyze/client/not_encrypted_ssh_keys.sh index d3404f5..d39191d 100644 --- a/scripts/analyze/client/not_encrypted_ssh_keys.sh +++ b/scripts/analyze/client/not_encrypted_ssh_keys.sh @@ -2,9 +2,9 @@ # @see https://stackoverflow.com/questions/32408820/how-to-list-files-and-match-first-line-in-bash-script # @see https://unix.stackexchange.com/questions/298590/using-find-non-recursively # @see https://security.stackexchange.com/questions/129724/how-to-check-if-an-ssh-private-key-has-passphrase-or-not -find $HOME/.ssh -maxdepth 1 -type f -print0 | while IFS= read -r -d $'\0' file; do +find "$HOME/.ssh" -maxdepth 1 -type f -print0 | while IFS= read -r -d $'\0' file; do if [[ $(head -n1 "$file") == "-----BEGIN OPENSSH PRIVATE KEY-----" ]]; then echo "Test file: $file" - ssh-keygen -y -P "" -f $file + ssh-keygen -y -P "" -f "$file" fi done diff --git a/scripts/analyze/system/dd_optimal_bs_test.sh b/scripts/analyze/system/dd_optimal_bs_test.sh deleted file mode 100644 index 67837dc..0000000 --- a/scripts/analyze/system/dd_optimal_bs_test.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -# Wrong scripped but good as a base to optimize later. See http://blog.tdg5.com/tuning-dd-block-size/ -# Since we're dealing with dd, abort if any errors occur -set -e - -TEST_FILE=${1:-dd_obs_testfile} -[ -e "$TEST_FILE" ]; TEST_FILE_EXISTS=$? -TEST_FILE_SIZE=134217728 - -# Header -PRINTF_FORMAT="%8s : %s\n" -printf "$PRINTF_FORMAT" 'block size' 'transfer rate' - -# Block sizes of 512b 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K 1M 2M 4M 8M 16M 32M 64M -for BLOCK_SIZE in 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 -do - # Calculate number of segments required to copy - COUNT=$(($TEST_FILE_SIZE / $BLOCK_SIZE)) - - if [ $COUNT -le 0 ]; then - echo "Block size of $BLOCK_SIZE estimated to require $COUNT blocks, aborting further tests." - break - fi - - # Create a test file with the specified block size - DD_RESULT=$(dd if=/dev/zero of=$TEST_FILE bs=$BLOCK_SIZE count=$COUNT 2>&1 1>/dev/null) - -echo $DD_RESULT - # Extract the transfer rate from dd's STDERR output - TRANSFER_RATE=$(echo $DD_RESULT | \grep --only-matching -E '[0-9.]+ ([MGk]?B|bytes)/s(ec)?') - - # Clean up the test file if we created one - [ $TEST_FILE_EXISTS -ne 0 ] && rm $TEST_FILE - - # Output the result - printf "$PRINTF_FORMAT" "$BLOCK_SIZE" "$TRANSFER_RATE" -done diff --git a/scripts/encryption/storage/raid1/mount_on_boot.sh b/scripts/encryption/storage/raid1/mount_on_boot.sh index 500d578..c335834 100644 --- a/scripts/encryption/storage/raid1/mount_on_boot.sh +++ b/scripts/encryption/storage/raid1/mount_on_boot.sh @@ -1,6 +1,7 @@ #!/bin/bash # shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location. # shellcheck disable=SC2154 # Referenced but not assigned +# shellcheck disable=SC2015 #Deactivate bool hint source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1) info "Automount raid1 encrypted storages..." && set_raid1_devices_mount_partition_and_mapper_paths &&