diff --git a/customscripts/improved_file_management.sh b/customscripts/improved_file_management.sh index 17dde52..f1525c6 100644 --- a/customscripts/improved_file_management.sh +++ b/customscripts/improved_file_management.sh @@ -1,8 +1,15 @@ #!/bin/bash +# usage: by its self or with nuke +# bash improved_file_management.sh +# bash improved_file_management.sh nuke +## "nuke" is not case sensitive +start_date="$(date)" +args="$@" # backup_dir="/mnt/c/Users/human/Downloads/tint" backup_dir="/mnt/d/Anbernic_Research_Tinkering_Save" -cd "$backup_dir" +error_log="${backup_dir}/error.log" # errror log path +cd "$backup_dir" # slide on in # sum text colorz RED='\033[0;31m' # anmgry red @@ -10,6 +17,38 @@ YELLOW='\033[0;33m' # BOLD yellow :"3 GREEN='\033[1;32m' # bold green :3 RESET='\033[0m' # reset color +check_error_log () { + if [ -f "$error_log" ]; then + echo -e "${GREEN}Found $error_log clearing at $(date) With $SECONDS Elapsed At Line Number $LINENO${RESET}" + echo > "$error_log" # initialize as empty + else + echo -e "${GREEN}No $error_log fiound, creating at $(date) With $SECONDS Elapsed At Line Number $LINENO${RESET}" + touch "$error_log" # create and initialize + fi +} + +environment_checks () { + # tests if backup dir is a directory and available + if [ ! -d "$backup_dir" ]; then + echo -e "\n\n\n${RED}Supplied backup dir: $backup_dir not present, not available, out of permissions, or is not a directory" + + exit 1 + else + echo -e "${GREEN}OK! Backup Dir GOOD${RESET}" + fi + + # tests current location + if [[ "$PWD" != "$backup_dir" ]]; then + echo -e "\n\n\n${RED}pwd: $PWD does not match specified dir: $backup Dir, FAIL. Exiting.${RESET}\n\n\n" # notify + + exit 1 # exit with error + else + echo -e "${GREEN}OK! Backup Dir IS Current Location!${RESET}" + fi + + echo -e "\n${GREEN}Environment Checks GOOD!${RESET}\n" +} + greet () { echo -e "\n\n\n${GREEN}WELCOME TO DURABLE, PROVABLE FILE HANDLING${RESET}\n\n\n" } @@ -28,7 +67,7 @@ verify_sha256_files() { local file local failed=0 - find "${1:-.}" -type f -name '*.sha256' -print0 | + find "${1:-.}" -type f -name '*.sha256' -not -path "*.git*" -print0 | while IFS= read -r -d '' file; do echo "Checking: $file" @@ -54,7 +93,7 @@ generate_sha256_checksums () { sha256sum "$file" | tee "$file.sha256" fi done - ' bash {} + + ' bash {} + # idk what this hippie bullshit voodoo witchcraft this syntax is, kill nme now } do_git () { @@ -77,10 +116,25 @@ run_backup () { pwsh.exe -File "D:\Anbernic-Hackin-Archive_restic_backup.ps1" # do da restic backup ps1 } -greet -delete_sha256_files -generate_sha256_checksums -verify_sha256_files -do_git -run_backup -when_done \ No newline at end of file +# shutdown by force of powershell huehhuehue +box_force_shutdown () { + webhook "TIME TO SHUT THE FUCK DOWN WOOOO\n\t$SECONDS Seconds Elapsed\n\tStart Date: $start_date\n\tEnd Date: $(date)" true # true so it pingas mneeee + + # hateful cursed powershell call to shut off box ffs + pwsh.exe -C "Stop-Computer -Force" # i reeally dgaf this is so terribly fuckin cursed +} + +greet # welcome msg +environment_checks # test environment for working +if [[ "$args" =~ nuke ]]; then + delete_sha256_files # delete all *.sha256 files +fi +check_error_log # verify error log faggot + +while $true; do # do an infinite loop to keep em all running and operating at all times :3 + verify_sha256_files # check files against their sha256 checksum + generate_sha256_checksums # create the checksums from the files to generate each file its own *.sha256 buddy \o/ + do_git # archive for version controll + run_backup # do multiple redndant backups using restic +done +when_done # goodbye msg