From 76f1a35a463caf3e327785eace690dbf9f93e8b0 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Wed, 20 May 2020 12:13:39 +0200 Subject: [PATCH] Optimized analyziation --- scripts/analyze/client/big_files.sh | 6 +++ scripts/analyze/client/false_chown.sh | 6 +++ scripts/analyze/client/file_duplicates.sh | 6 +++ scripts/analyze/client/java_versions.sh | 6 +++ scripts/analyze/client/linux_kernel.sh | 5 +++ scripts/analyze/system/dd_optimal_bs_test.sh | 37 ++++++++++++++++ scripts/client/check.sh | 15 ------- scripts/encryption/storage/mount.sh | 3 +- scripts/encryption/storage/mount_on_boot.sh | 45 ++++++++++++++++++++ 9 files changed, 113 insertions(+), 16 deletions(-) create mode 100644 scripts/analyze/client/big_files.sh create mode 100644 scripts/analyze/client/false_chown.sh create mode 100644 scripts/analyze/client/file_duplicates.sh create mode 100644 scripts/analyze/client/java_versions.sh create mode 100644 scripts/analyze/client/linux_kernel.sh create mode 100644 scripts/analyze/system/dd_optimal_bs_test.sh delete mode 100644 scripts/client/check.sh create mode 100644 scripts/encryption/storage/mount_on_boot.sh diff --git a/scripts/analyze/client/big_files.sh b/scripts/analyze/client/big_files.sh new file mode 100644 index 0000000..f10d803 --- /dev/null +++ b/scripts/analyze/client/big_files.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# @author Kevin Veen-Birkenbach +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/../../base.sh" || (echo "Loading base.sh failed." && exit 1) +info "Searching for files which are in \"$HOME\" and bigger then 100MB..." +find ~ -type f -size +100M -exec ls -lh {} \; diff --git a/scripts/analyze/client/false_chown.sh b/scripts/analyze/client/false_chown.sh new file mode 100644 index 0000000..8305c1c --- /dev/null +++ b/scripts/analyze/client/false_chown.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# @author Kevin Veen-Birkenbach +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/../../base.sh" || (echo "Loading base.sh failed." && exit 1) +info "Searching for files which are in \"$HOME\" but don't belong to user \"$USER\"..." +sudo find "$HOME" ! -user "$USER" diff --git a/scripts/analyze/client/file_duplicates.sh b/scripts/analyze/client/file_duplicates.sh new file mode 100644 index 0000000..9e69d57 --- /dev/null +++ b/scripts/analyze/client/file_duplicates.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# @author Kevin Veen-Birkenbach +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/../../base.sh" || (echo "Loading base.sh failed." && exit 1) +info "Checking relevant home folders for duplicated files..." +fdupes -r "$HOME/Documents/" "$HOME/Downloads/" "$HOME/Images/" "$HOME/Desktop/" "$HOME/Music/" "$HOME/Pictures/" "$HOME/Videos" diff --git a/scripts/analyze/client/java_versions.sh b/scripts/analyze/client/java_versions.sh new file mode 100644 index 0000000..e083f2d --- /dev/null +++ b/scripts/analyze/client/java_versions.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# @author Kevin Veen-Birkenbach +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/../../base.sh" || (echo "Loading base.sh failed." && exit 1) +info "Showing the installed Java versions..." && +archlinux-java status diff --git a/scripts/analyze/client/linux_kernel.sh b/scripts/analyze/client/linux_kernel.sh new file mode 100644 index 0000000..0bc1b3a --- /dev/null +++ b/scripts/analyze/client/linux_kernel.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# @author Kevin Veen-Birkenbach +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/../../base.sh" || (echo "Loading base.sh failed." && exit 1) +info "Linux-Kernel: $(uname -r)" diff --git a/scripts/analyze/system/dd_optimal_bs_test.sh b/scripts/analyze/system/dd_optimal_bs_test.sh new file mode 100644 index 0000000..67837dc --- /dev/null +++ b/scripts/analyze/system/dd_optimal_bs_test.sh @@ -0,0 +1,37 @@ +#!/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/client/check.sh b/scripts/client/check.sh deleted file mode 100644 index ba9890c..0000000 --- a/scripts/client/check.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -# @author Kevin Veen-Birkenbach -# shellcheck source=/dev/null # Deactivate SC1090 -source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1) -echo "System check - Shows things which can be optimized:" -echo -info "Linux-Kernel: $(uname -r)" -info "Checking relevant home folders for duplicated files..." -fdupes -r "$HOME/Documents/" "$HOME/Downloads/" "$HOME/Images/" "$HOME/Desktop/" "$HOME/Music/" "$HOME/Pictures/" "$HOME/Videos" -info "Searching for files which are in \"$HOME\" but don't belong to user \"$USER\"..." -sudo find "$HOME" ! -user "$USER" -info "Searching for files which are in \"$HOME\" and bigger then 100MB..." -find ~ -type f -size +100M -exec ls -lh {} \; -info "Showing the installed Java versions..." && -archlinux-java status diff --git a/scripts/encryption/storage/mount.sh b/scripts/encryption/storage/mount.sh index a4a10f6..f2c86e6 100644 --- a/scripts/encryption/storage/mount.sh +++ b/scripts/encryption/storage/mount.sh @@ -1,5 +1,6 @@ +#!/bin/bash source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1) -echo "Mounting encrypted storage..." +echo "Mounts encrypted storages" set_device_mount_and_mapper_paths diff --git a/scripts/encryption/storage/mount_on_boot.sh b/scripts/encryption/storage/mount_on_boot.sh new file mode 100644 index 0000000..15703d7 --- /dev/null +++ b/scripts/encryption/storage/mount_on_boot.sh @@ -0,0 +1,45 @@ +#!/bin/bash +source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1) +echo "Automount encrypted storages" +echo +set_device_mount_and_mapper_paths + +secret_key_path="/etc/luks-keys/$mapper""_name_secret_key" && +info "Generate secret key under: $secret_key_path" && +dd if=/dev/urandom of=$secret_key_path bs=512 count=8 && +sudo cryptsetup -v luksAddKey $device_path $secret_key_path || +error + +info "Opening and closing device to verify that that everything works fine..." && +sudo cryptsetup -v luksOpen $device_path $mapper_name --key-file=$secret_key_path && +sudo cryptsetup -v luksClose $mapper_name || +error + +uuid_line=$(sudo cryptsetup luksDump $device_path | grep "UUID") +uuid=$(uuid_line "${test/UUID:/""}"|sed -e "s/[[:space:]]\+//g") +crypttab_path="/etc/crypttab" +if grep -q "$uuid" "$crypttab_path"; then + error "File $crypttab_path contains allready a string with the UUID:$uuid" +fi +"$mapper_name UUID=$uuid $secret_key_path luks" >> $crypttab_path + +info "The file $crypttab_path contains the following:" && +sudo cat $crypttab_path || +error + +info "Verifying crypttab configuration..." && +sudo cryptdisks_start $mapper_name || +error + +fstab_path="/etc/fstab" +if grep -q "$uuid" "f$stab_path"; then + error "File $fstab_path contains allready a string with the UUID:$uuid" +fi +"$mapper_path $mount_path btrfs defaults 0 2" >> $fstab_path || +error + +info "The file $crypttab_path contains the following:" && +sudo cat $crypttab_path || +error + +success "Installation finished. Please restart :)"