Skip to content

Commit 3219844

Browse files
authored
Create config-wizard.sh
1 parent 0e259d9 commit 3219844

1 file changed

Lines changed: 248 additions & 0 deletions

File tree

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
#!/bin/bash
2+
3+
echo
4+
echo "APPLICATION STUDY TOOL CONFIGURATION WIZARD"
5+
echo "Note: This script is meant to be run only at initial installation time. If you need to make changes afterwards or you make an error while inputting the required values, you will need to re-run the script and enter everything all over again. Alternatively, to just make one-off edits, you can manually edit the config files after the script exits."
6+
7+
# THE FOLLOWING STEPS ARE PREREQS FOR THIS SCRIPT:
8+
# (Install Docker)
9+
# git clone https://github.com/f5devcentral/application-study-tool.git
10+
# cd application-study-tool
11+
# chmod +x config-wizard.sh
12+
# Then the user can run this setup wizard by running "./config-wizard.sh".
13+
14+
# Check if .env file, .env.device-secrets, and config directory do not exist. If they don't, but the example files exist, copy the example files to the actual files.
15+
if [ ! -f "./.env" ]; then
16+
if [ -f "./.env-example" ]; then
17+
cp .env-example .env
18+
else # Neither file exists
19+
echo "Error: neither .env nor .env-example file exists in current directory. Exiting script."
20+
exit 1
21+
fi
22+
fi
23+
if [ ! -f "./.env.device-secrets" ]; then
24+
if [ -f "./.env.device-secrets-example" ]; then
25+
cp .env.device-secrets-example .env.device-secrets
26+
else # Neither file exists
27+
echo "Error: neither .env.device-secrets-example nor .env.device-secrets file exists in current directory. Exiting script."
28+
exit 1
29+
fi
30+
fi
31+
if [ ! -d "./config" ]; then
32+
echo "Error: ./config directory does not exist in current directory. Exiting script."
33+
exit 1
34+
fi
35+
36+
# Set up some defaults for script:
37+
DEFAULT_USER=admin
38+
DEFAULT_PASS=admin
39+
40+
# SET UP GRAFANA CREDENTIALS
41+
echo "Setting up Grafana dashboard credentials."
42+
echo "Enter desired Grafana username (or press ENTER to leave as default): "
43+
read GF_ADMIN_USER
44+
if [ -n "$GF_ADMIN_USER" ]; then # not empty
45+
stty -echo
46+
echo "Enter desired Grafana password (or press ENTER to leave as the default): "
47+
read GF_ADMIN_PASS
48+
stty echo
49+
echo
50+
GF_ADMIN_PASS="${GF_ADMIN_PASS:-$DEFAULT_PASS}"
51+
52+
# Update .env file
53+
sed -i -e s/^GF_SECURITY_ADMIN_USER/#GF_SECURITY_ADMIN_USER/g ./.env
54+
sed -i -e s/^GF_SECURITY_ADMIN_PASSWORD/#GF_SECURITY_ADMIN_PASSWORD/g ./.env
55+
echo >> .env
56+
echo "GF_SECURITY_ADMIN_USER=$GF_ADMIN_USER" >> .env
57+
echo "GF_SECURITY_ADMIN_PASSWORD=$GF_ADMIN_PASS" >> .env
58+
fi
59+
60+
# TODO: Do the same for SENSOR_ID and SENSOR_SECRET_TOKEN in .env
61+
62+
# CONFIGURE GLOBAL BIG-IP ACCESS
63+
# First, set global default credentials in config/ast_defaults.yaml
64+
echo "Setting up default global BIG-IP credentials."
65+
66+
echo "Enter default global username for BIG-IP (or press ENTER to leave as default: admin): "
67+
read BIGIP_ADMIN_USER
68+
stty -echo
69+
echo "Enter default BIG-IP password (or press ENTER to leave as default): "
70+
read BIGIP_ADMIN_PASS
71+
stty echo
72+
echo
73+
74+
if [ -n "$BIGIP_ADMIN_USER" ]; then # not empty
75+
# Update config/ast_defaults.yaml
76+
sed -i -e s/"username\:"/"username\: $BIGIP_ADMIN_USER #"/1 ./config/ast_defaults.yaml
77+
fi
78+
79+
if [ -n "$BIGIP_ADMIN_PASS" ]; then # not empty
80+
# Update config/ast_defaults.yaml
81+
sed -i -e s/"password\:"/"password\: $BIGIP_ADMIN_PASS #"/1 ./config/ast_defaults.yaml
82+
fi
83+
84+
# Ask user whether to validate certificates (skip when using self-signed certs)
85+
echo "Skip certificate verification (use self-signed certs) or verify CA certificates (requires CA file name)? "
86+
echo "Enter Y to use self-signed certificates, or N to verify the certificates (or press Enter to leave as default): "
87+
read DONT_VERIFY_CERTS
88+
89+
if [ -n "$DONT_VERIFY_CERTS" ]; then # not empty
90+
if [[ "$DONT_VERIFY_CERTS" == Y* ]] || [[ "$DONT_VERIFY_CERTS" == y* ]]; then
91+
# Don't verify certificates
92+
sed -i -e s/"insecure_skip_verify\:"/"insecure_skip_verify\: true #"/1 ./config/ast_defaults.yaml
93+
sed -i -e s/"ca_file\:"/"ca_file\: \"\" #"/1 ./config/ast_defaults.yaml
94+
else
95+
# Yes, verify certificates
96+
echo "Enter the full pathname of the CA file: "
97+
read CA_FILE_PATH
98+
sed -i -e s/"insecure_skip_verify\:"/"insecure_skip_verify\: false #"/1 ./config/ast_defaults.yaml
99+
if [ -n "$CA_FILE_PATH" ]; then # not empty
100+
sed -i -e s~"ca_file\:"~"ca_file\: \"$CA_FILE_PATH\" #"~1 ./config/ast_defaults.yaml
101+
fi
102+
fi
103+
fi
104+
105+
# DO WE NEED THIS BLOCK?
106+
# CONFIGURE INDIVIDUAL BIG-IP ACCESS
107+
# Re-check that this file still exists in the current directory
108+
if [ ! -f "./.env.device-secrets" ]; then
109+
exit 1
110+
fi
111+
112+
echo "Enter the first BIG-IP management IP address (or press Enter to leave unchanged): "
113+
read BIG_IP_ADDR
114+
115+
# Validate IPv4 IP address format
116+
while [[ -n "$BIG_IP_ADDR" ]] && ! [[ "${BIG_IP_ADDR}" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; do
117+
echo "Invalid IP address. Enter the first BIG-IP management IPv4 address in a.b.c.d format (or press Enter to stop adding devices): "
118+
read BIG_IP_ADDR
119+
done;
120+
121+
if [ -n "$BIG_IP_ADDR" ]; then # not empty
122+
# if file already exists, rename it and create a new file
123+
if [ -f "./config/bigip_receivers.yaml" ]; then
124+
mv ./config/bigip_receivers.yaml ./config/bigip_receivers.yaml.old
125+
fi
126+
touch ./config/bigip_receivers.yaml
127+
echo "# Your bigip targets" >> ./config/bigip_receivers.yaml
128+
fi
129+
BIG_IP_NUM=1
130+
131+
while [ -n "$BIG_IP_ADDR" ]; do # while not empty
132+
echo "CONFIGURING BIG-IP $BIG_IP_NUM ($BIG_IP_ADDR)..."
133+
echo "Enter this BIG-IP's admin username (press Enter to use global default username and password): "
134+
read BIGIP_LOCAL_USER
135+
if [ -n "$BIGIP_LOCAL_USER" ]; then # not empty
136+
stty -echo
137+
echo "Enter this BIG-IP's admin password (press Enter to use global default admin password): "
138+
read BIGIP_LOCAL_PASS
139+
stty echo
140+
echo
141+
fi
142+
echo "bigip/$BIG_IP_NUM:" >> ./config/bigip_receivers.yaml
143+
if [[ "$BIG_IP_ADDR" == http* ]]; then
144+
echo " endpoint: $BIG_IP_ADDR" >> ./config/bigip_receivers.yaml
145+
else
146+
echo " endpoint: https://$BIG_IP_ADDR" >> ./config/bigip_receivers.yaml
147+
fi
148+
if [ -n "$BIGIP_LOCAL_USER" ]; then
149+
echo " username: $BIGIP_LOCAL_USER" >> ./config/bigip_receivers.yaml
150+
if [ -n "$BIGIP_LOCAL_PASS" ]; then
151+
echo " password: $BIGIP_LOCAL_PASS" >> ./config/bigip_receivers.yaml
152+
fi
153+
fi
154+
echo "Enter the next BIG-IP management IP address (or press Enter to stop adding devices): "
155+
read BIG_IP_ADDR
156+
157+
# Validate IPv4 IP address format
158+
while [[ -n "$BIG_IP_ADDR" ]] && ! [[ "${BIG_IP_ADDR}" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; do
159+
echo "Invalid IP address. Enter the first BIG-IP management IPv4 address in a.b.c.d format (or press Enter to stop adding devices): "
160+
read BIG_IP_ADDR
161+
done;
162+
163+
164+
BIG_IP_NUM=$(($BIG_IP_NUM+1))
165+
done
166+
167+
# File configuration is complete. Now prompt the user to run the Configuration Generator container.
168+
169+
# CHECK FOR CONTAINER RUNTIME TOOLS AND PROMPT USER TO RUN THEM.
170+
CONTAINER_RUNTIME="#"
171+
echo "Checking for installation of Docker..."
172+
DOCKER=`command -v docker`
173+
if [ -n "$DOCKER" ]; then # not empty
174+
echo "Docker is installed."
175+
CONTAINER_RUNTIME="docker"
176+
else
177+
PODMAN=`command -v podman`
178+
if [ -n "$PODMAN" ]; then # not empty
179+
echo "Podman is installed."
180+
CONTAINER_RUNTIME="podman"
181+
else
182+
echo "Neither Docker nor Podman are installed. Please install one of these tools before continuing."
183+
exit 1
184+
fi
185+
fi
186+
187+
# If we got to this point, either Docker or Podman is installed on the sytem.
188+
echo "Would you like to run the configuration generator now (y/n)?"
189+
read RUN_CONFIG_GEN
190+
if [ -n "$RUN_CONFIG_GEN" ]; then # not empty
191+
if [[ "$RUN_CONFIG_GEN" == Y* ]] || [[ "$RUN_CONFIG_GEN" == y* ]]; then
192+
# Test to see if sudo is required before docker/podman command
193+
$CONTAINER_RUNTIME version
194+
if [[ "$?" == 1 ]]; then # Previous command failed
195+
SUDO_REQUIRED=sudo
196+
# CONTAINER_RUNTIME="$SUDO_REQUIRED $CONTAINER_RUNTIME"
197+
else SUDO_REQUIRED=""
198+
fi
199+
$SUDO_REQUIRED $CONTAINER_RUNTIME run --rm -it -w /app -v ${PWD}:/app --entrypoint /app/src/bin/init_entrypoint.sh python:3.12.6-slim-bookworm --generate-config
200+
else
201+
echo "Configuration files have been created. The next step is to run the configuration gnerator with the following command:"
202+
echo " \$ $SUDO_REQUIRED $CONTAINER_RUNTIME run --rm -it -w /app -v ${PWD}:/app --entrypoint /app/src/bin/init_entrypoint.sh python:3.12.6-slim-bookworm --generate-config"
203+
exit 1
204+
fi
205+
fi
206+
echo
207+
echo "Configuration complete."
208+
echo
209+
210+
COMPOSE_TOOL="#"
211+
echo "Checking for installation of Docker Compose..."
212+
DOCKER_COMPOSE=`command -v docker-compose`
213+
214+
if [ -n "$DOCKER_COMPOSE" ]; then # not empty
215+
echo "Docker Compose is installed."
216+
COMPOSE_TOOL="docker-compose"
217+
else # Docker Compose is not installed. Let's check Podman Compose.
218+
PODMAN_COMPOSE=`command -v podman-compose`
219+
if [ -n "$PODMAN_COMPOSE" ]; then # not empty
220+
echo "Podman is installed."
221+
COMPOSE_TOOL="podman-compose"
222+
else # neither is installed
223+
echo "Neither Docker Compose nor Podman Compose are installed. Please install one of these tools in order to start the service."
224+
exit 1
225+
fi
226+
fi
227+
228+
# If we got to this point, either Docker Compose or Podman Compose is installed on the sytem.
229+
echo "Would you like to start the sevice now (y/n)?"
230+
read RUN_SERVICE
231+
if [ -n "$RUN_SERVICE" ]; then # not empty
232+
if [[ "$RUN_SERVICE" == Y* ]] || [[ "$RUN_SERVICE" == y* ]]; then
233+
# Quick check to ensure docker-compose file is present
234+
if [ -f "./docker-compose.yaml" ]; then
235+
# docker-compose up
236+
$SUDO_REQUIRED $COMPOSE_TOOL up
237+
else
238+
echo "Error: docker-compose.yaml file does not exist in current directory. Cannot start docker compose service."
239+
exit 1
240+
fi
241+
else
242+
echo "Configuration is complete. The next step is to run the compose tool to start the service, using the following command:"
243+
echo " \$ $SUDO_REQUIRED $COMPOSE_TOOL up"
244+
fi
245+
else
246+
echo "Configuration is complete. The next step is to run the compose tool to start the service, using the following command:"
247+
echo " \$ $SUDO_REQUIRED $COMPOSE_TOOL up"
248+
fi

0 commit comments

Comments
 (0)