Commit f9fa314e authored by Dillenn Terumalai's avatar Dillenn Terumalai
Browse files

Merge branch 'dev' into 'master'

Version 1.9.0

See merge request !11
parents bec294d9 5fad2416
Pipeline #2085 passed with stage
in 26 seconds
......@@ -2,7 +2,7 @@
# SPSP transfer-tool is developed and maintained by SIB. For more information, please contact spsp-support@sib.swiss
VERSION="1.8.0" # bumped to support spsp --help, spsp --version
VERSION="1.9.0" # bumped to support spsp --help, spsp --version
# Define colors that are used in the help screen
......@@ -21,641 +21,848 @@ RECIPIENT="spsp-support@sib.swiss"
# Check for the machine compatibility
UNAMEOUT="$(uname -s)"
case "${UNAMEOUT}" in
Linux*) MACHINE=linux;;
Darwin*) MACHINE=mac;;
*) MACHINE="UNKNOWN"
Linux*) MACHINE=linux ;;
Darwin*) MACHINE=mac ;;
*) MACHINE="UNKNOWN" ;;
esac
if [ "$MACHINE" == "UNKNOWN" ]; then
echo "Unsupported system type"
echo "System must be a Macintosh or Linux"
echo ""
echo "System detection determined via uname command"
echo "If the following is empty, could not find uname command: $(uname -v)"
echo "Your reported uname is: $(uname -s)"
echo "Unsupported system type"
echo "System must be a Macintosh or Linux"
echo ""
echo "System detection determined via uname command"
echo "If the following is empty, could not find uname command: $(uname -v)"
echo "Your reported uname is: $(uname -s)"
fi
# Set environment variables for dev
if [ "$MACHINE" == "linux" ]; then
SHACMD="sha256sum"
SHACMD="sha256sum"
elif [ "$MACHINE" == "mac" ]; then
SHACMD="shasum -a 256"
SHACMD="shasum -a 256"
fi
showVersion() {
intro="🔐${COL_GREEN} SPSP transfer-tool${COL_RESET}\n"
intro="$intro ${COL_CYAN}Version ${VERSION}\n${COL_RESET}"
intro="🔐${COL_GREEN} SPSP transfer-tool${COL_RESET}\n"
intro="$intro ${COL_CYAN}Version ${VERSION}\n${COL_RESET}"
printf "$intro"
printf "$intro"
}
showHelp() {
showVersion
showVersion
usage="${COL_LYELLOW}Usage:\n${COL_RESET}"
usage="$usage ./spsp <cmd> <options>"
usage="${COL_LYELLOW}Usage:\n${COL_RESET}"
usage="$usage ./spsp <cmd> <options>"
commands="${COL_LYELLOW}Commands:\n${COL_RESET}"
commands="$commands auto Automatically run the commands to Compress, Hash, Encrypt & Transfer, add --no-archive option to delete the files after the transfer\n"
commands="$commands help Shows help screen\n"
commands="$commands test Dry run with fake generated files with report\n"
commands="$commands cleanup Clean the following directories: logs, sent, viruses, bacteria and .outbox\n"
commands="${COL_LYELLOW}Commands:\n${COL_RESET}"
commands="$commands auto Automatically run the commands to Compress, Hash, Encrypt & Transfer, add --no-archive option to delete the files after the transfer\n"
commands="$commands help Shows help screen\n"
commands="$commands test Fake run with fake generated files\n"
commands="$commands cleanup Clean the following directories: logs, sent, viruses, bacteria and .outbox\n"
options="${COL_LYELLOW}Options:\n${COL_RESET}"
options="$options --help, -h Shows Help (this screen)\n"
options="$options --version, -V, version Show Version\n"
options="$options --without-env, -W Use environment variables from the system and the .env file\n"
options="${COL_LYELLOW}Options:\n${COL_RESET}"
options="$options --help, -h Shows Help (this screen)\n"
options="$options --version, -V, version Show Version\n"
options="$options --without-env, -W Use environment variables from the system and the .env file\n"
examples="${COL_LYELLOW}Examples:\n${COL_RESET}"
examples="$examples ${COL_CYAN}$ ./spsp auto${COL_RESET}\n"
examples="$examples ${COL_CYAN}$ ./spsp test${COL_RESET}\n"
examples="$examples ${COL_CYAN}$ ./spsp cleanup${COL_RESET}\n"
examples="${COL_LYELLOW}Examples:\n${COL_RESET}"
examples="$examples ${COL_CYAN}$ ./spsp auto${COL_RESET}\n"
examples="$examples ${COL_CYAN}$ ./spsp test${COL_RESET}\n"
examples="$examples ${COL_CYAN}$ ./spsp cleanup${COL_RESET}\n"
printf "\n"
printf "$usage\n\n"
printf "$commands\n"
printf "$options\n"
printf "$examples\n"
printf "\n"
printf "$usage\n\n"
printf "$commands\n"
printf "$options\n"
printf "$examples\n"
}
compressFolder() {
tar -czf $1.tar.gz $1
tar -czf $1.tar.gz $1
}
hashFile() {
$SHACMD "$1" > "$1".sha256
$SHACMD "$1" >"$1".sha256
}
encryptFile() {
gpg -q --batch --yes --always-trust -o "$1".gpg -e -r $RECIPIENT "$1"
gpg -q --batch --yes --always-trust -o "$1".gpg -e -r $RECIPIENT "$1"
}
cleanup() {
OUTBOX=".outbox"
LOGS="logs"
SENT="sent"
VIRUSES="viruses"
BACTERIA="bacteria"
BUILDS="builds"
rm -rf ./$OUTBOX/*
rm -rf ./$LOGS/*
rm -rf ./$SENT/*
rm -rf ./$VIRUSES/*
rm -rf ./$BACTERIA/*
rm -rf ./$BUILDS/*
OUTBOX=".outbox"
LOGS="logs"
SENT="sent"
VIRUSES="viruses"
BACTERIA="bacteria"
BUILDS="builds"
rm -rf ./$OUTBOX/*
rm -rf ./$LOGS/*
rm -rf ./$SENT/*
rm -rf ./$VIRUSES/*
rm -rf ./$BACTERIA/*
rm -rf ./$BUILDS/*
}
initMode() {
echo "- Initializing the Transfer Tool..."
if [ ! -x "$(command -v tar)" ]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} command unavailable: the tar command is not available on this system and is mandatory for the pipeline."
exit 22
echo "- Initializing the Transfer Tool..."
if [ ! -x "$(command -v tar)" ]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} command unavailable: the tar command is not available on this system and is mandatory for the pipeline."
exit 22
fi
if [ ! -x "$(command -v sftp)" ]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} command unavailable: the sftp command is not available on this system and is mandatory for the pipeline.\n"
printf "${BACK_CYAN} INFO ${COL_RESET} Check out OpenSSH at ${COL_CYAN}https://www.openssh.com/${COL_RESET}"
exit 22
fi
if [ ! -x "$(command -v nc)" ]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} command unavailable: the nc command is not available on this system and is mandatory for the pipeline.\n"
printf "${BACK_CYAN} INFO ${COL_RESET} Check out Netcat at ${COL_CYAN}http://netcat.sourceforge.net/${COL_RESET}"
exit 22
fi
if [ ! -x "$(command -v gpg)" ]; then
export PATH=$PATH:/usr/local/bin
if [ ! -x "$(command -v gpg)" ]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} command unavailable: the gpg command is not available on this system and is mandatory for the pipeline.\n"
printf "${BACK_CYAN} INFO ${COL_RESET} Check out GnuPG at ${COL_CYAN}https://gnupg.org/${COL_RESET}"
exit 22
fi
fi
if [ ! -x "$(command -v sftp)" ]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} command unavailable: the sftp command is not available on this system and is mandatory for the pipeline.\n"
printf "${BACK_CYAN} INFO ${COL_RESET} Check out OpenSSH at ${COL_CYAN}https://www.openssh.com/${COL_RESET}"
exit 22
fi
chmod +x spsp
if [ ! -x "$(command -v nc)" ]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} command unavailable: the nc command is not available on this system and is mandatory for the pipeline.\n"
printf "${BACK_CYAN} INFO ${COL_RESET} Check out Netcat at ${COL_CYAN}http://netcat.sourceforge.net/${COL_RESET}"
exit 22
fi
gpg -q --import --fingerprint .pub
if [ ! -x "$(command -v gpg)" ]; then
export PATH=$PATH:/usr/local/bin
if [ ! -x "$(command -v gpg)" ]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} command unavailable: the gpg command is not available on this system and is mandatory for the pipeline.\n"
printf "${BACK_CYAN} INFO ${COL_RESET} Check out GnuPG at ${COL_CYAN}https://gnupg.org/${COL_RESET}"
exit 22
fi
fi
chmod +x spsp
gpg -q --import --fingerprint .pub
printf "${BACK_GREEN} DONE ${COL_RESET} All commands available\n"
printf "${BACK_GREEN} DONE ${COL_RESET} SPSP Public key imported\n"
printf "${BACK_CYAN} INFO ${COL_RESET} Please make sure that the fingerprint: "
printf "${COL_CYAN}"
gpg -q --with-colons --import-options show-only --import --fingerprint .pub | awk -F: '$1 == "fpr" {print $10;}' | head -n 1
printf "${COL_RESET}"
printf "matches the fingerprint on this page: https://gitlab.sib.swiss/SPSP/transfer-tool/-/wikis/Installation#verify-the-public-key\n"
printf "${BACK_GREEN} DONE ${COL_RESET} All commands available\n"
printf "${BACK_GREEN} DONE ${COL_RESET} SPSP Public key imported\n"
printf "${BACK_CYAN} INFO ${COL_RESET} Please make sure that the fingerprint: "
printf "${COL_CYAN}"
gpg -q --with-colons --import-options show-only --import --fingerprint .pub | awk -F: '$1 == "fpr" {print $10;}' | head -n 1
printf "${COL_RESET}"
printf "matches the fingerprint on this page: https://gitlab.sib.swiss/SPSP/transfer-tool/-/wikis/Installation#verify-the-public-key\n"
}
autoMode() {
START=$(date +%s)
CURRENTDATE=$(date +"%Y-%m-%d")
VIRUSES=viruses
BACTERIA=bacteria
OUTBOX=".outbox"
SENT=sent
LOGS="logs"
LOGFILE="$LOGS/spsp-$CURRENTDATE.log"
ERRORLOGFILE="$LOGS/error.log"
ERRORS=0
SUCCESS=0
printf " - Initializing the automatic mode of the Transfer Tool... "
if [ ! -d "$OUTBOX" ]; then
mkdir $OUTBOX
echo "[$(date +"%T")] local.SUCCESS: $OUTBOX directory was successfully created" >> "$LOGFILE"
fi
START=$(date +%s)
CURRENTDATE=$(date +"%Y-%m-%d")
VIRUSES=viruses
BACTERIA=bacteria
OUTBOX=".outbox"
SENT=sent
LOGS="logs"
LOGFILE="$LOGS/spsp-$CURRENTDATE.log"
ERRORLOGFILE="$LOGS/error.log"
ERRORS=0
SUCCESS=0
printf " - Initializing the automatic mode of the Transfer Tool... "
if [ ! -d "$OUTBOX" ]; then
mkdir $OUTBOX
echo "[$(date +"%T")] local.SUCCESS: $OUTBOX directory was successfully created" >>"$LOGFILE"
fi
if [ ! -d "$OUTBOX/$VIRUSES" ]; then
mkdir -p $OUTBOX/$VIRUSES
echo "[$(date +"%T")] local.SUCCESS: $OUTBOX/$VIRUSES subfolder was successfully created" >>"$LOGFILE"
fi
if [ ! -d "$OUTBOX/$BACTERIA" ]; then
mkdir -p $OUTBOX/$BACTERIA
echo "[$(date +"%T")] local.SUCCESS: $OUTBOX/$BACTERIA subfolder was successfully created" >>"$LOGFILE"
fi
if [ ! -d "$SENT" ]; then
mkdir $SENT
fi
if [ ! -d "$LOGS" ]; then
mkdir $LOGS
fi
if [ ! -f "$LOGFILE" ]; then
touch "$LOGFILE"
fi
if [ ! -f "$ERRORLOGFILE" ]; then
touch "$ERRORLOGFILE"
fi
printf "${BACK_GREEN} DONE ${COL_RESET}\n"
printf " - Testing the connection to the remote server... "
STEP_ERRORS=0
if ! nc -w 1 -z "${HOST}" 22 &>/dev/null; then
((STEP_ERRORS = STEP_ERRORS + 1))
echo "[$(date +"%T")] local.ERROR: ${HOST}:22 is unreachable, please check your connection" >>"$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: ${HOST}:22 is unreachable, please check your connection" >>"$ERRORLOGFILE"
fi
if [[ "$*" == *--local* ]] || [[ "$*" == *-L* ]]; then
STEP_ERRORS=0
fi
if [ ! -d "$OUTBOX/$VIRUSES" ]; then
mkdir -p $OUTBOX/$VIRUSES
echo "[$(date +"%T")] local.SUCCESS: $OUTBOX/$VIRUSES subfolder was successfully created" >> "$LOGFILE"
fi
if [[ $STEP_ERRORS > 0 ]]; then
printf "${BACK_RED} ERROR ${COL_RESET}\n"
exit 55
else
printf "${BACK_GREEN} DONE ${COL_RESET}\n"
fi
if [ ! -d "$OUTBOX/$BACTERIA" ]; then
mkdir -p $OUTBOX/$BACTERIA
echo "[$(date +"%T")] local.SUCCESS: $OUTBOX/$BACTERIA subfolder was successfully created" >> "$LOGFILE"
fi
if [ ! -d "$SENT" ]; then
mkdir $SENT
fi
if [ ! -d "$LOGS" ]; then
mkdir $LOGS
fi
printf " - Compressing the viruses and bacteria subfolders... "
if [ ! -f "$LOGFILE" ]; then
touch "$LOGFILE"
fi
STEP_ERRORS=0
if [ ! -f "$ERRORLOGFILE" ]; then
touch "$ERRORLOGFILE"
fi
cd $VIRUSES
printf "${BACK_GREEN} DONE ${COL_RESET}\n"
for DIRECTORY in ./*; do
printf " - Testing the connection to the remote server... "
if [ -d "$DIRECTORY" ] && [ "$DIRECTORY" != $OUTBOX ] && [ "$DIRECTORY" != $SENT ] && [ "$DIRECTORY" != $LOGS ]; then
STEP_ERRORS=0
for FILE in "$DIRECTORY"/*; do
if [[ -f $FILE && $FILE != *.@(fasta|fa|fasta.gz|fa.gz|fasta.xz|fa.xz|fastq|fastq.gz|cram|bam|cram.gz|bam.gz|csv|tsv|csv.gz|tsv.gz|vcf|xls|xlsx) ]]; then
((ERRORS = ERRORS + 1))
((STEP_ERRORS = STEP_ERRORS + 1))
echo "[$(date +"%T")] local.ERROR: Unsupported format ($FILE)" >>"../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Unsupported format ($FILE)" >>"../$ERRORLOGFILE"
fi
done
if ls "$DIRECTORY"/*.fa* 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.*am 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.*sv* 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.vcf 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.xls* 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.*.gz 1>/dev/null 2>&1; then
if [[ "$*" == *--fake* ]] || [[ "$*" == *-F* ]]; then
compressFolder "$DIRECTORY" 2>>"../$ERRORLOGFILE"
if [ -f "$DIRECTORY.tar.gz" ]; then
echo "[$(date +"%T")] local.SUCCESS: $DIRECTORY has been successfully compress into $DIRECTORY.tar.gz" >>"../$LOGFILE"
else
((ERRORS = ERRORS + 1))
((STEP_ERRORS = STEP_ERRORS + 1))
echo "[$(date +"%T")] local.ERROR: Compression of $DIRECTORY failed" >>"../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Compression of $DIRECTORY failed" >>"../$ERRORLOGFILE"
fi
else
ARCHIVENAME=$(date +"%Y%m%d%H%M")
mv $DIRECTORY $ARCHIVENAME
compressFolder "$ARCHIVENAME" 2>>"../$ERRORLOGFILE"
if [ -f "$ARCHIVENAME.tar.gz" ]; then
echo "[$(date +"%T")] local.SUCCESS: $ARCHIVENAME has been successfully compress into $DIRECTORY.tar.gz" >>"../$LOGFILE"
else
((ERRORS = ERRORS + 1))
((STEP_ERRORS = STEP_ERRORS + 1))
echo "[$(date +"%T")] local.ERROR: Compression of $ARCHIVENAME failed" >>"../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Compression of $ARCHIVENAME failed" >>"../$ERRORLOGFILE"
fi
fi
if ! nc -w 1 -z "${HOST}" 22 &> /dev/null;then
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: ${HOST}:22 is unreachable, please check your connection" >> "$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: ${HOST}:22 is unreachable, please check your connection" >> "$ERRORLOGFILE"
fi
if [[ "$*" == *--fake* ]] || [[ "$*" == *-F* ]]; then
mv "$DIRECTORY.tar.gz" "../$OUTBOX/$VIRUSES/"
rm -rf "$DIRECTORY"
echo "[$(date +"%T")] local.SUCCESS: $DIRECTORY has been successfully removed" >>"../$LOGFILE"
else
mv "$ARCHIVENAME.tar.gz" "../$OUTBOX/$VIRUSES/"
rm -rf "$ARCHIVENAME"
echo "[$(date +"%T")] local.SUCCESS: $ARCHIVENAME has been successfully removed" >>"../$LOGFILE"
fi
if [[ "$*" == *--local* ]] || [[ "$*" == *-L* ]]; then
STEP_ERRORS=0
fi
else
((ERRORS = ERRORS + 1))
((STEP_ERRORS = STEP_ERRORS + 1))
echo "[$(date +"%T")] local.ERROR: Missing required files inside $DIRECTORY of $VIRUSES DIRECTORY" >>"../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Missing required files inside $DIRECTORY of $VIRUSES DIRECTORY" >>"../$ERRORLOGFILE"
fi
if [[ $STEP_ERRORS > 0 ]]; then
printf "${BACK_RED} ERROR ${COL_RESET}\n"
exit 55
else
printf "${BACK_GREEN} DONE ${COL_RESET}\n"
fi
done
printf " - Compressing the viruses and bacteria subfolders... "
cd ..
STEP_ERRORS=0
cd $BACTERIA
cd $VIRUSES
for DIRECTORY in ./*; do
if [ -d "$DIRECTORY" ] && [ "$DIRECTORY" != $OUTBOX ] && [ "$DIRECTORY" != $SENT ] && [ "$DIRECTORY" != $LOGS ]; then
for FILE in "$DIRECTORY"/*;do
if [[ -f $FILE && $FILE != *.@(fasta|fa|fasta.gz|fa.gz|fasta.xz|fa.xz|fastq|fastq.gz|cram|bam|csv|tsv|csv.gz|tsv.gz|vcf|xls|xlsx) ]]; then
((ERRORS=ERRORS+1))
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: Unsupported format ($FILE)" >> "../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Unsupported format ($FILE)" >> "../$ERRORLOGFILE"
fi
done
if ls "$DIRECTORY"/*.fa* 1> /dev/null 2>&1 || ls "$DIRECTORY"/*.*am 1> /dev/null 2>&1 || ls "$DIRECTORY"/*.*sv* 1> /dev/null 2>&1 || ls "$DIRECTORY"/*.vcf 1> /dev/null 2>&1 && ls "$DIRECTORY"/*.xls* 1> /dev/null 2>&1; then
if [[ "$*" == *--fake* ]] || [[ "$*" == *-F* ]]; then
compressFolder "$DIRECTORY"
if [ -f "$DIRECTORY.tar.gz" ]; then
echo "[$(date +"%T")] local.SUCCESS: $DIRECTORY has been successfully compress into $DIRECTORY.tar.gz" >> "../$LOGFILE"
else
((ERRORS=ERRORS+1))
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: Compression of $DIRECTORY failed" >> "../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Compression of $DIRECTORY failed" >> "../$ERRORLOGFILE"
fi
else
ARCHIVENAME=$(date +"%Y%m%d%H%M")
mv $DIRECTORY $ARCHIVENAME
compressFolder "$ARCHIVENAME"
if [ -f "$ARCHIVENAME.tar.gz" ]; then
echo "[$(date +"%T")] local.SUCCESS: $ARCHIVENAME has been successfully compress into $DIRECTORY.tar.gz" >> "../$LOGFILE"
else
((ERRORS=ERRORS+1))
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: Compression of $ARCHIVENAME failed" >> "../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Compression of $ARCHIVENAME failed" >> "../$ERRORLOGFILE"
fi
fi
if [[ "$*" == *--fake* ]] || [[ "$*" == *-F* ]]; then
mv "$DIRECTORY.tar.gz" "../$OUTBOX/$VIRUSES/"
rm -rf "$DIRECTORY"
echo "[$(date +"%T")] local.SUCCESS: $DIRECTORY has been successfully removed" >> "../$LOGFILE"
else
mv "$ARCHIVENAME.tar.gz" "../$OUTBOX/$VIRUSES/"
rm -rf "$ARCHIVENAME"
echo "[$(date +"%T")] local.SUCCESS: $ARCHIVENAME has been successfully removed" >> "../$LOGFILE"
fi
else
((ERRORS=ERRORS+1))
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: Missing required files inside $DIRECTORY of $VIRUSES DIRECTORY" >> "../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Missing required files inside $DIRECTORY of $VIRUSES DIRECTORY" >> "../$ERRORLOGFILE"
fi
for DIRECTORY in ./*; do
if [ -d "$DIRECTORY" ] && [ "$DIRECTORY" != $OUTBOX ] && [ "$DIRECTORY" != $SENT ] && [ "$DIRECTORY" != $LOGS ]; then
for FILE in "$DIRECTORY"/*; do
if [[ -f $FILE && $FILE != *.@(fasta|fa|fasta.gz|fa.gz|fasta.xz|fa.xz|fastq|fastq.gz|cram|bam|cram.gz|bam.gz|csv|tsv|csv.gz|tsv.gz|vcf|xls|xlsx) ]]; then
((ERRORS = ERRORS + 1))
((STEP_ERRORS = STEP_ERRORS + 1))
echo "[$(date +"%T")] local.ERROR: Unsupported format ($FILE)" >>"../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Unsupported format ($FILE)" >>"../$ERRORLOGFILE"
fi
done
cd ..;
cd $BACTERIA;
for DIRECTORY in ./*; do
if [ -d "$DIRECTORY" ] && [ "$DIRECTORY" != $OUTBOX ] && [ "$DIRECTORY" != $SENT ] && [ "$DIRECTORY" != $LOGS ]; then
for FILE in "$DIRECTORY"/*;do
if [[ -f $FILE && $FILE != *.@(fasta|fa|fasta.gz|fa.gz|fasta.xz|fa.xz|fastq|fastq.gz|cram|bam|csv|tsv|csv.gz|tsv.gz|vcf|xls|xlsx) ]]; then
((ERRORS=ERRORS+1))
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: Unsupported format ($FILE)" >> "../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Unsupported format ($FILE)" >> "../$ERRORLOGFILE"
fi
done
if ls "$DIRECTORY"/*.fa* 1> /dev/null 2>&1 || ls "$DIRECTORY"/*.*am 1> /dev/null 2>&1 || ls "$DIRECTORY"/*.*sv* 1> /dev/null 2>&1 || ls "$DIRECTORY"/*.vcf 1> /dev/null 2>&1 && ls "$DIRECTORY"/*.xls* 1> /dev/null 2>&1; then
if [[ "$*" == *--fake* ]] || [[ "$*" == *-F* ]]; then
compressFolder "$DIRECTORY"
if [ -f "$DIRECTORY.tar.gz" ]; then
echo "[$(date +"%T")] local.SUCCESS: $DIRECTORY has been successfully compress into $DIRECTORY.tar.gz" >> "../$LOGFILE"
else
((ERRORS=ERRORS+1))
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: Compression of $DIRECTORY failed" >> "../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Compression of $DIRECTORY failed" >> "../$ERRORLOGFILE"
fi
else
ARCHIVENAME=$(date +"%Y%m%d%H%M")
mv $DIRECTORY $ARCHIVENAME
compressFolder "$ARCHIVENAME"
if [ -f "$ARCHIVENAME.tar.gz" ]; then
echo "[$(date +"%T")] local.SUCCESS: $ARCHIVENAME has been successfully compress into $DIRECTORY.tar.gz" >> "../$LOGFILE"
else
((ERRORS=ERRORS+1))
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: Compression of $ARCHIVENAME failed" >> "../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Compression of $ARCHIVENAME failed" >> "../$ERRORLOGFILE"
fi
fi
if [[ "$*" == *--fake* ]] || [[ "$*" == *-F* ]]; then
mv "$DIRECTORY.tar.gz" "../$OUTBOX/$BACTERIA/"
rm -rf "$DIRECTORY"
echo "[$(date +"%T")] local.SUCCESS: $DIRECTORY has been successfully removed" >> "../$LOGFILE"
else
mv "$ARCHIVENAME.tar.gz" "../$OUTBOX/$BACTERIA/"
rm -rf "$ARCHIVENAME"
echo "[$(date +"%T")] local.SUCCESS: $ARCHIVENAME has been successfully removed" >> "../$LOGFILE"
fi
else
((ERRORS=ERRORS+1))
((STEP_ERRORS=STEP_ERRORS+1))
echo "[$(date +"%T")] local.ERROR: Missing required files inside $DIRECTORY of $BACTERIA DIRECTORY" >> "../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Missing required files inside $DIRECTORY of $BACTERIA DIRECTORY" >> "../$ERRORLOGFILE"
fi
done
if ls "$DIRECTORY"/*.fa* 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.*am 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.*sv* 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.vcf 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.xls* 1>/dev/null 2>&1 || ls "$DIRECTORY"/*.*.gz 1>/dev/null 2>&1; then
if [[ "$*" == *--fake* ]] || [[ "$*" == *-F* ]]; then
compressFolder "$DIRECTORY"
if [ -f "$DIRECTORY.tar.gz" ]; then
echo "[$(date +"%T")] local.SUCCESS: $DIRECTORY has been successfully compress into $DIRECTORY.tar.gz" >>"../$LOGFILE"
else
((ERRORS = ERRORS + 1))
((STEP_ERRORS = STEP_ERRORS + 1))
echo "[$(date +"%T")] local.ERROR: Compression of $DIRECTORY failed" >>"../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Compression of $DIRECTORY failed" >>"../$ERRORLOGFILE"
fi
else
ARCHIVENAME=$(date +"%Y%m%d%H%M")
mv $DIRECTORY $ARCHIVENAME
compressFolder "$ARCHIVENAME"
if [ -f "$ARCHIVENAME.tar.gz" ]; then
echo "[$(date +"%T")] local.SUCCESS: $ARCHIVENAME has been successfully compress into $DIRECTORY.tar.gz" >>"../$LOGFILE"
else
((ERRORS = ERRORS + 1))
((STEP_ERRORS = STEP_ERRORS + 1))
echo "[$(date +"%T")] local.ERROR: Compression of $ARCHIVENAME failed" >>"../$LOGFILE"
echo "[$(date +"%F %T")] local.ERROR: Compression of $ARCHIVENAME failed" >>"../$ERRORLOGFILE"
fi
fi
done
cd ..;
if [[ "$*" == *--fake* ]] || [[ "$*" == *-F* ]]; then
mv "$DIRECTORY.tar.gz" "../$OUTBOX/$BACTERIA/"
rm -rf "$DIRECTORY"
echo "[$(date +"%T")] local.SUCCESS: $DIRECTORY has been successfully removed" >>"../$LOGFILE"
else
mv "$ARCHIVENAME.tar.gz" "../$OUTBOX/$BACTERIA/"
rm -rf "$ARCHIVENAME"
echo "[$(date +"%T")] local.SUCCESS: $ARCHIVENAME has been successfully removed" >>"../$LOGFILE"
fi
if [[ $STEP_ERRORS > 0 ]]; then
printf "${BACK_RED} ERROR ${COL_RESET}\n"
else