Commit 04ac2faf authored by Dillenn Terumalai's avatar Dillenn Terumalai
Browse files

Fixed some wrong behaviour

parent b3370448
spsp 100644 → 100755
......@@ -100,14 +100,17 @@ compressFolder() {
}
transferFile() {
SUBFOLDER = '';
if [ -z "$2" ]
then
SUBFOLDER = $2
if [ $# -eq 2 ]; then
for f in "$1"; do
printf "progress\nput $f" | sftp -b- "${SFTP_URL}$2" || exit 1
done
else
for f in "$1"; do
printf "progress\nput $f" | sftp -b- "${SFTP_URL}" || exit 1
done
fi
for f in "$1"; do
printf "progress\nput $f" | sftp -b- "${SFTP_URL}${SUBFOLDER}" || exit 1
done
}
signFile() {
......@@ -135,17 +138,17 @@ deleteSource() {
}
cleanup() {
$OUTBOX=".outbox"
$LOGS="logs"
$SENT="sent"
$VIRUSES="viruses"
$BACTERIA="bacteria"
# rm -rf ./$OUTBOX/*
# rm -rf ./$LOGS/*
OUTBOX=".outbox"
LOGS="logs"
SENT="sent"
VIRUSES="viruses"
BACTERIA="bacteria"
rm -rf ./$OUTBOX/*
rm -rf ./$LOGS/*
rm -rf ./$SENT/*
# rm -rf ./$VIRUSES/*
# rm -rf ./$BACTERIA/*
rm -rf ./$VIRUSES/*
rm -rf ./$BACTERIA/*
}
initMode() {
......@@ -267,7 +270,7 @@ autoMode() {
echo "SPSP: Compressing $DIRECTORY folder..."
compressFolder $DIRECTORY &> /dev/null
echo "SPSP: Sucessfully compressed!"
echo "SPSP: Removing the source and moving the tar.gz to '$OUTBOX' folder."
echo "SPSP: Removing the source and moving the tar.gz to '$OUTBOX'/'$VIRUSES' folder."
mv $DIRECTORY.tar.gz ./$OUTBOX/$VIRUSES
rm -rf $DIRECTORY
echo "SPSP: Deleted!"
......@@ -286,7 +289,7 @@ autoMode() {
echo "SPSP: Compressing $DIRECTORY folder..."
compressFolder $DIRECTORY &> /dev/null
echo "SPSP: Sucessfully compressed!"
echo "SPSP: Removing the source and moving the tar.gz to '$OUTBOX' folder."
echo "SPSP: Removing the source and moving the tar.gz to '$OUTBOX'/'$BACTERIA' folder."
mv $DIRECTORY.tar.gz ./$OUTBOX/$BACTERIA
rm -rf $DIRECTORY
echo "SPSP: Deleted!"
......@@ -299,7 +302,9 @@ autoMode() {
fi
done
for FILE in ./$OUTBOX/$VIRUSES/*.*; do
cd $OUTBOX/$VIRUSES;
for FILE in *.*; do
if [ -f "$FILE" ]; then
echo "SPSP: Encrypting $FILE using SPSP public key..."
encryptFile $FILE
......@@ -307,10 +312,10 @@ autoMode() {
echo "SPSP: Signing $FILE using SHA-256 algorithm..."
signFile "$FILE"
echo "SPSP: $FILE is now signed!"
if [ -f "$FILE.gpg.sha256" ] && [ -f "$FILE.gpg" ]; then
if [ -f "$FILE.sha256" ] && [ -f "$FILE.gpg" ]; then
echo "SPSP: Starting the transfer"
transferFile $FILE.gpg /$VIRUSES
transferFile $FILE.gpg.sha256 /$VIRUSES
transferFile $FILE.sha256 /$VIRUSES
echo "SPSP: $FILE has been transferred sucessfully!"
echo "SPSP: Removing unencrypted version of $FILE..."
rm $FILE
......@@ -318,14 +323,15 @@ autoMode() {
if [ "$1" == "--no-archive" ] || [ "$1" == "no-archive" ]; then
echo "SPSP: 'No archive' mode is activated, removing archives..."
rm $FILE.gpg
rm $FILE.gpg.sha256
rm $FILE.sha256
else
echo "SPSP: Moving $FILE.gpg and $FILE.gpg.sha256 to '$SENT' directory!"
mv $FILE.gpg.sha256 ./$SENT
echo "SPSP: Moving $FILE.gpg and $FILE.sha256 to '$SENT' directory!"
mv $FILE.sha256 ./$SENT
mv $FILE.gpg ./$SENT
echo "SPSP: Archives have been moved sucessfully!"
fi
else
cd ../..
echo "[`date +"%T"`] local.ERROR: Missing the encrypted version or the signature for $FILE" >> $LOGFILE
echo "SPSP: Error detected please check $LOGFILE"
echo "########################################"
......@@ -334,7 +340,11 @@ autoMode() {
fi
done
for FILE in ./$OUTBOX/$BACTERIA/*.*; do
cd ..
cd $BACTERIA
for FILE in *.*; do
if [ -f "$FILE" ]; then
echo "SPSP: Encrypting $FILE using SPSP public key..."
encryptFile $FILE
......@@ -342,10 +352,10 @@ autoMode() {
echo "SPSP: Signing $FILE using SHA-256 algorithm..."
signFile "$FILE"
echo "SPSP: $FILE is now signed!"
if [ -f "$FILE.gpg.sha256" ] && [ -f "$FILE.gpg" ]; then
if [ -f "$FILE.sha256" ] && [ -f "$FILE.gpg" ]; then
echo "SPSP: Starting the transfer"
transferFile $FILE.gpg /$BACTERIA
transferFile $FILE.gpg.sha256 /$BACTERIA
transferFile $FILE.sha256 /$BACTERIA
echo "SPSP: $FILE has been transferred sucessfully!"
echo "SPSP: Removing unencrypted version of $FILE..."
rm $FILE
......@@ -353,14 +363,15 @@ autoMode() {
if [ "$1" == "--no-archive" ] || [ "$1" == "no-archive" ]; then
echo "SPSP: 'No archive' mode is activated, removing archives..."
rm $FILE.gpg
rm $FILE.gpg.sha256
rm $FILE.sha256
else
echo "SPSP: Moving $FILE.gpg and $FILE.gpg.sha256 to '$SENT' directory!"
mv $FILE.gpg.sha256 ./$SENT
echo "SPSP: Moving $FILE.gpg and $FILE.sha256 to '$SENT' directory!"
mv $FILE.sha256 ./$SENT
mv $FILE.gpg ./$SENT
echo "SPSP: Archives have been moved sucessfully!"
fi
else
cd ../..
echo "[`date +"%T"`] local.ERROR: Missing the encrypted version or the signature for $FILE" >> $LOGFILE
echo "SPSP: Error detected please check $LOGFILE"
echo "########################################"
......
Markdown is supported
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