-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashPutFile
More file actions
executable file
·102 lines (88 loc) · 3.76 KB
/
Copy pathbashPutFile
File metadata and controls
executable file
·102 lines (88 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
. ./bashTransactionId
#Set tranId variable to contents of transactionId.sh
tranId=$(cat bashTransactionId)
#Set checkTranId to cut string from field 2 of tranId variable
checkTranId=$(cut -d '=' -f2 <<< $tranId)
#Set outboundFolderCheck array to files listed within files directory and set outboundFolderExist boolean to false
outboundFolderCheck=
outboundFolderCheck=($(ls files/))
outboundFolderExist=false
#Set outboundFiles array to files listed in outbound directory and set fileExists boolean to false
outboundFiles=
outboundFiles=($(ls files/outbound))
fileExists=false
#Bold colors
BWHITE='\033[1;37m'
BGREEN='\033[1;32m'
BRED='\033[1;31m'
BYELLOW='\033[1;33m'
BBLUE='\033[1;34m'
UBLUE='\033[4;34m'
NC='\033[0m' # No color
#If checkTranId is empty then display no open transaction message and instruct to first open a transaction
#and exit script
if [ "$checkTranId" == '""' ]
then
echo -e "\n${BRED}There are currently no open transactions!"
echo -e "\n\n${BYELLOW}You will need to first run the below command to open a transaction before putting a file or enter ${BWHITE}2${BYELLOW} when you run ${BGREEN}./bashMenu${BYELLOW}:"
echo -e "\n\n${BWHITE}Command: ${BGREEN}./bashCurlOpenTransaction${NC}\n"
exit 1
fi
#For each folder in the outboundFolderCheck array check for the folder named outbound and if exists set
#outboundFolderExist boolean to true
for ((i=0; i<${#outboundFolderCheck[@]}; i++)); do
if [[ ${outboundFolderCheck[$i]} == "outbound" ]]
then
outboundFolderExist=true
fi
done
#If outboundFolderExist is not true display no outbound folder message and exit script
if [ $outboundFolderExist != true ]
then
echo -e "\n${BRED}An outbound folder does not exist!\n\n${BYELLOW}You must create an outbound folder in ${BWHITE}\"sea-client-nodejs/files/\" ${BYELLOW}and have messages within that folder read to send before using this command.\n${NC}"
exit 1
#Else if there are no files in the outbound display no files in outbound message and exit script
elif [ ${#outboundFiles[@]} -lt 1 ]
then
echo -e "\n${BRED}There are currently no files to send in your outbound folder!\n\n${BYELLOW}Please place valid files to send within the ${BWHITE}\"sea-client-nodejs/files/outbound\" ${BYELLOW}folder before running this command again.\n"
exit 1
fi
#Option for fileName
while getopts ":f:" option; do
case $option in
f) # give file name from outbound to put
fileName=$OPTARG;;
\?) #Invalid option
echo "ERROR: Invalid option"
exit;;
esac
done
#While fileName is empty ask user for input
while ! [ $fileName ]; do
read -p "$(echo -e "\n"${BYELLOW}"Please enter a file name: "${NC})" fileName
echo -e "\n"
done
#For each file in outboundFiles array if file matches fileName set fileExists to true
for ((i=0; i<${#outboundFiles[@]}; i++)); do
if [[ "${outboundFiles[$i]}" == "$fileName" ]]
then
fileExists=true
fi
done
#If fileExists is true then put file
if [ $fileExists == true ]
then
node putClientFile -f $fileName -t $transactionId
#Else display error message, instruct to run command again with valid file name from outbound folder
#, show files that currently exist in outbound folder and show example command with option
else
echo -e "\n${BRED}ERROR: That is not a valid file from the outbound folder! Please run the command again with a valid file name."
echo -e "\n${BYELLOW}### Below are files that exist within your outbound folder ###\n${BBLUE}"
for ((i=0; i<${#outboundFiles[@]}; i++)); do
echo -e "${outboundFiles[i]}"
done
echo -e "\n${BWHITE}Example: ${BGREEN}./bashPutFile -f ${outboundFiles[0]}\n"
echo -e "\n\n${NC}${BYELLOW}OR...${NC}"
echo -e "\n\n${NC}${BWHITE}Run this command and enter ${BBLUE}3${BWHITE} from the Menu options: ${BGREEN}./bashMenu\n${NC}"
fi