forked from AlabamaWaterInstitute/CloudInfra
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathrunTeehr.sh
131 lines (120 loc) · 4.54 KB
/
runTeehr.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
#!/bin/bash
# Check if the config file exists and read from it
_check_and_read_config() {
echo "check"
local config_file="$1"
if [ -f "$config_file" ]; then
local last_path=$(cat "$config_file")
echo -e "Last used data directory path: %s\n" "$last_path${Color_Off}"
read -erp "Do you want to use the same path? (Y/n): " use_last_path
if [[ "$use_last_path" =~ ^[Yy] ]]; then
DATA_FOLDER_PATH="$last_path"
_check_if_data_folder_exits
return 0
elif [[ "$use_last_path" =~ ^[Nn] ]]; then
read -erp "Enter your input data directory path (use absolute path): " DATA_FOLDER_PATH
_check_if_data_folder_exits
# Save the new path to the config file
echo "$DATA_FOLDER_PATH" > "$CONFIG_FILE"
echo -e "The Directory you've given is:\n$DATA_FOLDER_PATH\n${Color_Off}"
else
echo -e "Invalid input. Exiting.\n${Color_Off}" >&2
return 1
fi
fi
}
_check_if_data_folder_exits(){
# Check the directory exists
if [ ! -d "$DATA_FOLDER_PATH" ]; then
echo -e "${BRed}Directory does not exist. Exiting the program.${Color_Off}"
exit 0
fi
}
# Check if the config file exists and read from it
_check_and_read_config() {
local config_file="$1"
if [ -f "$config_file" ]; then
local last_path=$(cat "$config_file")
echo -e "Last used data directory path: %s\n" "$last_path${Color_Off}"
read -erp "Do you want to use the same path? (Y/n): " use_last_path
if [[ "$use_last_path" =~ ^[Yy] ]]; then
DATA_FOLDER_PATH="$last_path"
_check_if_data_folder_exits
return 0
elif [[ "$use_last_path" =~ ^[Nn] ]]; then
read -erp "Enter your input data directory path (use absolute path): " DATA_FOLDER_PATH
_check_if_data_folder_exits
# Save the new path to the config file
echo "$DATA_FOLDER_PATH" > "$CONFIG_FILE"
echo -e "The Directory you've given is:\n$DATA_FOLDER_PATH\n${Color_Off}"
else
echo -e "Invalid input. Exiting.\n${Color_Off}" >&2
return 1
fi
fi
}
check_last_path() {
if [[ -z "$1" ]]; then
_check_and_read_config "$CONFIG_FILE"
else
DATA_FOLDER_PATH="$1"
fi
}
### Start of the Script ###
# Constanst
CONFIG_FILE="$HOME/.host_data_path.conf"
check_last_path "$@"
IMAGE_NAME=awiciroh/ngiab-teehr
while true; do
echo -e "${YELLOW}Run a TEEHR Evaluation on the output (https://rtiinternational.github.io/ngiab-teehr/)? (y/N, default: y):${RESET}"
read -r run_teehr_choice
# Default to 'y' if input is empty
if [[ -z "$run_teehr_choice" ]]; then
run_teehr_choice="y"
fi
# Check for valid input
if [[ "$run_teehr_choice" == [YyNn]* ]]; then
break
else
echo -e "${RED}Invalid choice. Please enter 'y' for yes, 'n' for no, or press Enter for default (yes).${RESET}"
fi
done
# Execute the command
if [[ "$run_teehr_choice" == [Yy]* ]]; then
# TEEHR run options
echo -e "${UYellow}Specify the TEEHR image tag to use: ${Color_Off}"
read -erp "Image tag (ex. v0.1.4, default: 'latest'): " teehr_image_tag
if [[ -z "$teehr_image_tag" ]]; then
if uname -a | grep arm64 || uname -a | grep aarch64 ; then
teehr_image_tag=latest
else
teehr_image_tag=x86
fi
fi
echo -e "${UYellow}Select an option (type a number): ${Color_Off}"
options=("Run TEEHR using existing local docker image" "Run TEEHR after updating to latest docker image" "Exit")
select option in "${options[@]}"; do
case $option in
"Run TEEHR using existing local docker image")
echo "running the TEEHR evaluation"
break
;;
"Run TEEHR after updating to latest docker image")
echo "pulling container and running the TEEHR evaluation"
docker pull $IMAGE_NAME:$teehr_image_tag
break
;;
Exit)
echo "Have a nice day!"
exit 0
;;
*) echo "Invalid option $REPLY, 1 to continue with existing local image, 2 to update and run, and 3 to exit"
;;
esac
done
docker run -v "$DATA_FOLDER_PATH:/app/data" "$IMAGE_NAME:$teehr_image_tag"
echo -e "${GREEN}TEEHR evaluation complete.${RESET}\n"
else
echo -e "${CYAN}Skipping TEEHR evaluation step.${RESET}\n"
fi
# ================================