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

Fixed some errors regarding gpg

parent a3d1a97e
......@@ -110,7 +110,7 @@ signFile() {
encryptFile() {
message="Encrypting file ${COL_LGREEN}$1${COL_RESET}..."
printf "$message\n"
$GPGCMD --yes --always-trust -o $1.gpg -e -r $RECIPIENT $1
$GPGCMD --yes --batch --always-trust -o $1.gpg -e -r $RECIPIENT $1
message="File is encrypted as ${COL_LYELLOW}$1.gpg${COL_RESET}!"
printf "$message\n"
}
......@@ -137,12 +137,12 @@ if [ $# -gt 0 ]; then
if [ "$1" == "--version" ] || [ "$1" == "-v" ] || [ "$1" == "version" ]; then
showVersion
exit 1
exit 0
fi
if [ "$1" == "--help" ] || [ "$1" == "-H" ] || [ "$1" == "help" ]; then
showHelp
exit 1
exit 0
fi
if [ "$1" == "init" ]; then
......@@ -150,23 +150,23 @@ if [ $# -gt 0 ]; then
if [ ! -x "$(command -v tar)" ]; then
echo "Error: tar command is not available."
exit 0
exit 22
fi
if [ ! -x "$(command -v sftp)" ]; then
echo "Error: sftp command is not available."
exit 0
exit 22
fi
if [ ! -f .env ]; then
echo "No .env file found within current working directory $(pwd)"
echo "Create a .env file before re-initializing"
exit 0
exit 2
fi
if [ ! -f spsp ]; then
echo "No spsp file found within current working directory $(pwd)"
exit 0
exit 2
fi
echo "SPSP: Making spsp transfer-tool command available"
......@@ -186,6 +186,7 @@ if [ $# -gt 0 ]; then
CURRENTDATE=`date +"%Y-%m-%d"`
echo "############# $CURRENTDATE #############"
echo "SPSP: Starting the transfer-tool..."
OUTBOX=outbox
......@@ -215,12 +216,24 @@ if [ $# -gt 0 ]; then
touch $LOGFILE
fi
if [ ! -x "$(command -v gpg)" ]; then
echo "Error: gpg command is not available, this error may happen when you use a CRON task. Modifying the PATH..."
export PATH=$PATH:/usr/local/bin
if [ ! -x "$(command -v gpg)" ]; then
echo "Error: gpg command is not available (no gpg instance is installed)."
exit 22
fi
fi
if ! nc -w 1 -z ${HOST} 22 &> /dev/null;then
echo "[`date +"%T"`] local.ERROR: ${HOST}:22 is unreachable, please check your connection" >> $LOGFILE
echo "SPSP: Error detected please check $LOGFILE"
exit 0
echo "########################################"
exit 55
fi
for DIRECTORY in *; do
if [ -d "$DIRECTORY" ] && [ $DIRECTORY != $OUTBOX ] && [ $DIRECTORY != $SENT ] && [ $DIRECTORY != $LOGS ]; then
if ls $DIRECTORY/*.fastq* 1> /dev/null 2>&1 && [ -f $DIRECTORY/*.xlsx ]; then
......@@ -233,53 +246,57 @@ if [ $# -gt 0 ]; then
else
echo "[`date +"%T"`] local.ERROR: Missing files (*.fastq/.fastq.gz and/or *.xlsx) inside ${DIRECTORY}" >> $LOGFILE
echo "SPSP: Error detected please check $LOGFILE"
exit 0
echo "########################################"
exit 13
fi
fi
done
for FILE in ./outbox/*; do
if [ -f "$FILE" ]; then
echo "SPSP: Signing $FILE using SHA-256 algorithm..."
signFile $FILE &> /dev/null
echo "SPSP: $File is now signed!"
echo "SPSP: Encrypting $FILE using SPSP public key..."
encryptFile $FILE &> /dev/null
encryptFile $FILE
echo "SPSP: $FILE is now encrypted"
echo "SPSP: Removing unencrypted version of $FILE"
rm -rf $FILE
echo "SPSP: Deleted!"
if [ -f "$FILE.sha256" ] && [ -f "$FILE.gpg" ]; then
echo "SPSP: Signing $FILE using SHA-256 algorithm..."
signFile $FILE.gpg
echo "SPSP: $FILE is now signed!"
if [ -f "$FILE.gpg.sha256" ] && [ -f "$FILE.gpg" ]; then
echo "SPSP: Starting the transfer"
transferFile $FILE.sha256 &> /dev/null
transferFile $FILE.gpg &> /dev/null
transferFile $FILE.gpg.sha256
transferFile $FILE.gpg
echo "SPSP: $FILE has been transferred sucessfully!"
mv $FILE.sha256 ./sent/.
mv $FILE.gpg.sha256 ./sent/.
mv $FILE.gpg ./sent/.
echo "SPSP: Removing unencrypted version of $FILE"
rm -rf "$FILE"
echo "SPSP: Deleted!"
else
echo "[`date +"%T"`] local.ERROR: Missing the encrypted version or the signature for $FILE" >> $LOGFILE
echo "SPSP: Error detected please check $LOGFILE"
exit 0
echo "########################################"
exit 2
fi
echo ""
fi
done
echo ""
echo "SPSP: Process completed!"
echo "########################################"
# Compress a folder given as an input
elif [ "$1" == "compress" ]; then
shift 1
compressFolder $@
# Transfer a file given as an input
elif [ "$1" == "transfer" ]; then
shift 1
transferFile $@
# Sign a afile given as an input
elif [ "$1" == "sign" ]; then
shift 1
signFile $@
# Encrypt a folder/file given as an input
elif [ "$1" == "encrypt" ]; then
shift 1
encryptFile $@
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment