From d5552e796e163bc3bdd427146fc26f61e26b6100 Mon Sep 17 00:00:00 2001 From: Matthew Yang Date: Thu, 15 Feb 2024 10:00:48 -0500 Subject: [PATCH 1/3] Create moverestorations.sh script that moves older transcription disc restorations into a directory and creates a readme.txt file --- .../moverestorations.sh | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 transcription disc scripts/moverestorations.sh diff --git a/transcription disc scripts/moverestorations.sh b/transcription disc scripts/moverestorations.sh new file mode 100755 index 0000000..7d39253 --- /dev/null +++ b/transcription disc scripts/moverestorations.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# microservice to move older transcription disc restorations into the restoration_old directory after a newer restoration is made using the mm/makederiv microservice + +# color codes for messages +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +_usage(){ + echo -e ${GREEN}"\nThis script moves older transcription disc restorations into the restoration_old directory after a newer restoration is made using the mm/makederiv microservice.\n"${NC} +} + +_usage + +# asks for a directory and checks it + +echo "Enter the directory path to begin:" +read -r -p "> " user_directory + +if [[ ! -d "$user_directory" || -z "$(ls -A "$user_directory")" ]]; then + echo -e ${RED}"Directory not found or empty: $user_directory"${NC} + exit 1 +fi + +echo -e ${GREEN}"Selected directory: $user_directory"${NC} + +# is there a restoration directory? if no, exit +restoration_directory="$user_directory/objects/restoration" + +if [ ! -d "$restoration_directory" ]; then + echo -e ${RED}"There is no 'restoration' directory in the objects directory. Aborting..."${NC} + exit 1 +fi + +# does it have wav files? if no, exit +wav_files=$(find "$restoration_directory" -maxdepth 1 -type f -name "*.wav") + +if [ -z "$wav_files" ]; then + echo -e ${RED}"No WAV files found in the restoration directory. Aborting..."${NC} + exit 1 +fi + +# create restoration_old directory +restoration_old_dir="$user_directory/objects/restoration/restoration_old" + +# append to readme.txt log file +readme_file="$user_directory/metadata/oldrestoration_readme.txt" +user=$(whoami) +echo "Old transcription disc restoration file move log" > "$readme_file" +echo "Initiated by: $user" >> "$readme_file" +echo "==============================" >> "$readme_file" + +# identify old & new wav file +for wav_file in $wav_files; do + filename=$(basename "$wav_file") + current_datetime=$(date +"%m-%d-%Y %H:%M:%S") + + # identifies the old restorations by checking filenames that are NOT _transcriptiondisc[0-9]*\.wav, _transcriptiondisc_ + if [[ ! "$filename" =~ _transcriptiondisc[0-9]*\.wav ]] && [[ "$filename" != *"_transcriptiondisc_"* ]]; then + mkdir -p "$restoration_old_dir" + mv "$wav_file" "$restoration_old_dir/" + + echo -e ${GREEN}"Moved $filename to $restoration_old_dir"${NC} + echo "Transfer details:" >> "$readme_file" + echo " File: $filename" >> "$readme_file" + echo " Transfer Date & Time: $current_datetime" >> "$readme_file" + echo " From: $user_directory" >> "$readme_file" + echo " To: $restoration_old_dir" >> "$readme_file" + echo "------------------------------" >> "$readme_file" + fi +done + +echo -e ${GREEN}"Old restorations successfully moved to the restoration_old directory. See oldrestoration_readme.txt in the metadata directory for the transfer log."${NC} \ No newline at end of file From 4e54c0b1cfed821a1593957f1a9beb42aaf491af Mon Sep 17 00:00:00 2001 From: Matthew Yang Date: Thu, 15 Feb 2024 16:02:14 -0500 Subject: [PATCH 2/3] Update moverestorations.sh -moved variables in double quotes -added checks restoration_old directory and oldrestoration_readme.txt -added -n flag when wav files are moved -removed interaction and now loops over input directories --- .../moverestorations.sh | 104 ++++++++++-------- 1 file changed, 59 insertions(+), 45 deletions(-) diff --git a/transcription disc scripts/moverestorations.sh b/transcription disc scripts/moverestorations.sh index 7d39253..29bb277 100755 --- a/transcription disc scripts/moverestorations.sh +++ b/transcription disc scripts/moverestorations.sh @@ -7,7 +7,7 @@ RED='\033[0;31m' NC='\033[0m' _usage(){ - echo -e ${GREEN}"\nThis script moves older transcription disc restorations into the restoration_old directory after a newer restoration is made using the mm/makederiv microservice.\n"${NC} + echo -e "${GREEN}\nThis script moves older transcription disc restorations into the restoration_old directory after a newer restoration is made using the mm/makederiv microservice.\n${NC}" } _usage @@ -15,59 +15,73 @@ _usage # asks for a directory and checks it echo "Enter the directory path to begin:" -read -r -p "> " user_directory - if [[ ! -d "$user_directory" || -z "$(ls -A "$user_directory")" ]]; then echo -e ${RED}"Directory not found or empty: $user_directory"${NC} exit 1 fi -echo -e ${GREEN}"Selected directory: $user_directory"${NC} +# loop through input directories +for user_directory in $@; do + directory_name=$(basename "$user_directory") -# is there a restoration directory? if no, exit -restoration_directory="$user_directory/objects/restoration" +# checks whether input is a directory and whether it is empty + if [[ ! -d "$user_directory" || -z "$(ls -A "$user_directory")" ]]; then + echo -e "${RED}[$directory_name] Directory not found or empty. Aborting...${NC}" + continue + fi -if [ ! -d "$restoration_directory" ]; then - echo -e ${RED}"There is no 'restoration' directory in the objects directory. Aborting..."${NC} - exit 1 -fi + # is there a restoration directory? if no, exit + restoration_directory="$user_directory/objects/restoration" + + if [ ! -d "$restoration_directory" ]; then + echo -e "${RED}[$directory_name] There is no 'restoration' directory in the objects directory. Aborting...${NC}" + continue + fi -# does it have wav files? if no, exit -wav_files=$(find "$restoration_directory" -maxdepth 1 -type f -name "*.wav") + # does it have wav files? if no, exit + wav_files=$(find "$restoration_directory" -maxdepth 1 -type f -name "*.wav") -if [ -z "$wav_files" ]; then - echo -e ${RED}"No WAV files found in the restoration directory. Aborting..."${NC} - exit 1 -fi + if [ -z "$wav_files" ]; then + echo -e "${RED}[$directory_name] No WAV files found in the restoration directory. Aborting...${NC}" + continue + fi + + # does it already have an existing restoration_old directory or oldrestoration_readme.txt? + restorationold_directory="$user_directory/objects/restoration/restoration_old" + readme_text="$user_directory/metadata/oldrestoration_readme.txt" -# create restoration_old directory -restoration_old_dir="$user_directory/objects/restoration/restoration_old" - -# append to readme.txt log file -readme_file="$user_directory/metadata/oldrestoration_readme.txt" -user=$(whoami) -echo "Old transcription disc restoration file move log" > "$readme_file" -echo "Initiated by: $user" >> "$readme_file" -echo "==============================" >> "$readme_file" - -# identify old & new wav file -for wav_file in $wav_files; do - filename=$(basename "$wav_file") - current_datetime=$(date +"%m-%d-%Y %H:%M:%S") - - # identifies the old restorations by checking filenames that are NOT _transcriptiondisc[0-9]*\.wav, _transcriptiondisc_ - if [[ ! "$filename" =~ _transcriptiondisc[0-9]*\.wav ]] && [[ "$filename" != *"_transcriptiondisc_"* ]]; then - mkdir -p "$restoration_old_dir" - mv "$wav_file" "$restoration_old_dir/" - - echo -e ${GREEN}"Moved $filename to $restoration_old_dir"${NC} - echo "Transfer details:" >> "$readme_file" - echo " File: $filename" >> "$readme_file" - echo " Transfer Date & Time: $current_datetime" >> "$readme_file" - echo " From: $user_directory" >> "$readme_file" - echo " To: $restoration_old_dir" >> "$readme_file" - echo "------------------------------" >> "$readme_file" + if [ -d "$restorationold_directory" ] || [ -f "$readme_text" ] ; then + echo -e "${RED}[$directory_name] There is an existing restoration_old directory or old_restoration_readme.txt file. Aborting...${NC}" + continue fi -done -echo -e ${GREEN}"Old restorations successfully moved to the restoration_old directory. See oldrestoration_readme.txt in the metadata directory for the transfer log."${NC} \ No newline at end of file + # create restoration_old directory + restoration_old_dir="$user_directory/objects/restoration/restoration_old" + + # append to readme.txt log file + readme_file="$user_directory/metadata/oldrestoration_readme.txt" + user=$(whoami) + echo "Old transcription disc restoration file move log" > "$readme_file" + echo "Initiated by: $user" >> "$readme_file" + echo "==============================" >> "$readme_file" + + # identify old & new wav file + for wav_file in $wav_files; do + filename=$(basename "$wav_file") + current_datetime=$(date +"%m-%d-%Y %H:%M:%S") + + # identifies the old restorations by checking filenames that are NOT _transcriptiondisc[0-9]*\.wav, _transcriptiondisc_ + if [[ ! "$filename" =~ _transcriptiondisc[0-9]*\.wav ]] && [[ "$filename" != *"_transcriptiondisc_"* ]]; then + mkdir -p "$restoration_old_dir" + mv -n "$wav_file" "$restoration_old_dir/" + echo -e "${GREEN}Moved $filename to $restoration_old_dir${NC}" + echo "Transfer details:" >> "$readme_file" + echo " File: $filename" >> "$readme_file" + echo " Transfer Date & Time: $current_datetime" >> "$readme_file" + echo " From: $user_directory" >> "$readme_file" + echo " To: $restoration_old_dir" >> "$readme_file" + echo "------------------------------" >> "$readme_file" + fi + done +echo -e "${GREEN}[$directory_name] Old restorations successfully moved to the restoration_old directory. See oldrestoration_readme.txt in the metadata directory for the transfer log.${NC}" +done \ No newline at end of file From 88d45f73cc0141520bbb877274ad7ecb484af523 Mon Sep 17 00:00:00 2001 From: Matthew Yang Date: Thu, 15 Feb 2024 16:04:29 -0500 Subject: [PATCH 3/3] Update moverestorations.sh provide script usage instruction if no input provided --- transcription disc scripts/moverestorations.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/transcription disc scripts/moverestorations.sh b/transcription disc scripts/moverestorations.sh index 29bb277..dd82499 100755 --- a/transcription disc scripts/moverestorations.sh +++ b/transcription disc scripts/moverestorations.sh @@ -10,13 +10,11 @@ _usage(){ echo -e "${GREEN}\nThis script moves older transcription disc restorations into the restoration_old directory after a newer restoration is made using the mm/makederiv microservice.\n${NC}" } -_usage - -# asks for a directory and checks it - -echo "Enter the directory path to begin:" -if [[ ! -d "$user_directory" || -z "$(ls -A "$user_directory")" ]]; then - echo -e ${RED}"Directory not found or empty: $user_directory"${NC} +# provide script usage instruction if no input provided +if [[ $# -eq 0 ]]; then + script_name=$(basename "$0") + _usage + echo -e "Usage: $script_name ... \n" exit 1 fi