This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
guide.sh
executable file
·150 lines (126 loc) · 5.4 KB
/
guide.sh
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# Bold
BBlack='\033[1;30m' # Black
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
BYellow='\033[1;33m' # Yellow
BBlue='\033[1;34m' # Blue
BPurple='\033[1;35m' # Purple
BCyan='\033[1;36m' # Cyan
BWhite='\033[1;37m' # White
# Underline
UBlack='\033[4;30m' # Black
URed='\033[4;31m' # Red
UGreen='\033[4;32m' # Green
UYellow='\033[4;33m' # Yellow
UBlue='\033[4;34m' # Blue
UPurple='\033[4;35m' # Purple
UCyan='\033[4;36m' # Cyan
UWhite='\033[4;37m' # White
# Reset
Color_Off='\033[0m' # Text Reset
set -e
echo -e "\n"
echo "========================================================="
echo -e "${UWhite} Welcome to CIROH-UA:NextGen National Water Model App! ${Color_Off}"
echo "========================================================="
echo -e "\n"
echo -e "Looking for input data (a directory containing the following directories: forcings, config and outputs): \n"
echo -e "${BBlue}forcings${Color_Off} is the hydrofabric input data for your model(s)."
echo -e "${BGreen}config${Color_Off} folder has all the configuration related files for the model."
echo -e "${BPurple}outputs${Color_Off} is where the output files are copied to when the model finish the run"
echo -e "\n"
read -rp "Enter your input data directory path (use absolute path): " HOST_DATA_PATH
echo -e "The Directory you've given is:" && echo "$HOST_DATA_PATH"
Outputs_Count=$(ls $HOST_DATA_PATH/outputs | wc -l)
Forcings_Count=$(ls $HOST_DATA_PATH/forcings | wc -l)
Config_Count=$(ls $HOST_DATA_PATH/config | wc -l)
#Validate paths exist:
[ -d "$HOST_DATA_PATH/forcings" ] && echo -e "${BBlue}forcings${Color_Off} exists. $Forcings_Count forcings found." || echo -e "Error: Directory $HOST_DATA_PATH/${BBlue}forcings${Color_Off} does not exist."
[ -d "$HOST_DATA_PATH/outputs" ] && echo -e "${BPurple}outputs${Color_Off} exists. $Outputs_Count outputs found." || echo -e "Error: Directory $HOST_DATA_PATH/${BPurple}outputs${Color_Off} does not exist, but will be created if you choose to copy the outputs after the run."
[ -d "$HOST_DATA_PATH/config" ] && echo -e "${BGreen}config${Color_Off} exists. $Config_Count configs found." || echo -e "Error: Directory $HOST_DATA_PATH/${BGreen}config${Color_Off} does not exist."
echo -e "\n"
if [ $Outputs_Count -gt 0 ]; then
echo -e "${UYellow}Cleanup Process: This step will delete all files in the outputs folder: $HOST_DATA_PATH/outputs! Be Careful.${Color_Off}"
PS3="Select an option (type a number): "
options=("Delete output files and run fresh" "Continue without cleaning" "Exit")
select option in "${options[@]}"; do
case $option in
"Delete output files and run fresh")
echo "Cleaning Outputs folder for fresh run"
echo "Starting Cleanup of Files:"
echo "Cleaning Up $Outputs_Count Files"
rm -f "$HOST_DATA_PATH/outputs"/*
break
;;
"Continue without cleaning")
echo "Happy Hydro Modeling."
break
;;
"Exit")
echo "Have a nice day!"
exit 0
;;
*)
echo "Invalid option $REPLY. Please select again."
;;
esac
done
else
echo -e "Outputs directory is empty and model is ready for run."
fi
echo -e "\n"
echo "Looking in the provided directory gives us:"
HYDRO_FABRIC_CATCHMENTS=$(find $HOST_DATA_PATH -iname "*catchment*.geojson")
HYDRO_FABRIC_NEXUS=$(find $HOST_DATA_PATH -iname "*nexus*.geojson")
NGEN_REALIZATIONS=$(find $HOST_DATA_PATH -iname "*realization*.json")
#pwd
echo -e "${UGreen}Found these Catchment files:${Color_Off}" && sleep 1 && echo "$HYDRO_FABRIC_CATCHMENTS"
echo -e "${UGreen}Found these Nexus files:${Color_Off}" && sleep 1 && echo "$HYDRO_FABRIC_NEXUS"
echo -e "${UGreen}Found these Realization files:${Color_Off}" && sleep 1 && echo "$NGEN_REALIZATIONS"
#Detect Arch
AARCH=$(uname -a)
echo -e "\n"
echo -e "Detected ISA = $AARCH"
if docker --version ; then
echo "Docker found"
else
echo "Docker not found"
fi
echo -e "\n"
PS3="Select an option (type a number): "
options=("Run NextGen Model using docker" "Exit")
select option in "${options[@]}"; do
case $option in
"Run NextGen Model using docker")
echo "Pulling NextGen docker image and running the model"
break
;;
Exit)
echo "Have a nice day!"
exit 0
;;
*)
echo "Invalid option $REPLY, 1 to continue and 2 to exit"
;;
esac
done
echo -e "\n"
if uname -a | grep arm64 || uname -a | grep aarch64 ; then
docker pull awiciroh/ciroh-ngen-image:latest-arm
echo -e "Pulled awiciroh/ciroh-ngen-image:latest-arm image"
IMAGE_NAME=awiciroh/ciroh-ngen-image:latest-arm
else
docker pull awiciroh/ciroh-ngen-image:latest-x86
echo -e "Pulled awiciroh/ciroh-ngen-image:latest-x86 image"
IMAGE_NAME=awiciroh/ciroh-ngen-image:latest-x86
fi
echo -e "\n"
echo -e "Running NextGen docker container..."
echo -e "Mounting local host directory $HOST_DATA_PATH to /ngen/ngen/data within the container."
docker run --rm -it -v $HOST_DATA_PATH:/ngen/ngen/data $IMAGE_NAME /ngen/ngen/data/
Final_Outputs_Count=$(ls $HOST_DATA_PATH/outputs | wc -l)
echo -e "$Final_Outputs_Count new outputs created."
echo -e "Any copied files can be found here: $HOST_DATA_PATH/outputs"
echo -e "Thank you for running NextGen In A Box: National Water Model! Have a nice day!"
exit 0