-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·106 lines (91 loc) · 3.12 KB
/
install.sh
File metadata and controls
executable file
·106 lines (91 loc) · 3.12 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
103
104
105
106
#!/bin/bash
# Path to the .env file
ENV_FILE="./.env"
# Check if .env file exists
if [ ! -f "$ENV_FILE" ]; then
echo "Error: .env file not found."
exit 1
fi
# Check and set SAMPLE_APP from first argument
SAMPLE_APP_ARG="$1"
if [ -z "$SAMPLE_APP_ARG" ]; then
echo "Error: First argument (SAMPLE_APP) is required."
echo "Usage: $0 <smart-parking|loitering-detection|smart-intersection> [HOST_IP]"
exit 1
fi
case "$SAMPLE_APP_ARG" in
"smart-parking"|"loitering-detection"|"smart-intersection")
# Update SAMPLE_APP in .env file
if grep -q "^SAMPLE_APP=" "$ENV_FILE"; then
sed -i "s/^SAMPLE_APP=.*/SAMPLE_APP=$SAMPLE_APP_ARG/" "$ENV_FILE"
else
echo "SAMPLE_APP=$SAMPLE_APP_ARG" >> "$ENV_FILE"
fi
;;
*)
echo "Error: Invalid SAMPLE_APP value '$SAMPLE_APP_ARG'. Must be one of: smart-parking, loitering-detection, smart-intersection."
exit 1
;;
esac
# Update the HOST_IP in .env file
# Check if HOST_IP is provided as second argument, otherwise use hostname -I
HOST_IP_ARG="$2"
if [ -z "$HOST_IP_ARG" ]; then
HOST_IP=$(hostname -I | cut -f1 -d' ')
else
# Validate IP format (basic validation for IPv4)
if [[ ! $HOST_IP_ARG =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Warning: Invalid IP format. Using hostname -I instead."
HOST_IP=$(hostname -I | cut -f1 -d' ')
else
HOST_IP=$HOST_IP_ARG
fi
fi
echo "Configuring application to use $HOST_IP"
if grep -q "^HOST_IP=" "$ENV_FILE"; then
# Replace existing HOST_IP line
sed -i "s/^HOST_IP=.*/HOST_IP=$HOST_IP/" "$ENV_FILE"
else
# Add HOST_IP if it doesn't exist
echo "HOST_IP=$HOST_IP" >> "$ENV_FILE"
fi
# Extract SAMPLE_APP variable from .env file to ensure consistency
SAMPLE_APP=$(grep -E "^SAMPLE_APP=" "$ENV_FILE" | cut -d '=' -f2 | tr -d '"' | tr -d "'")
# Validate that SAMPLE_APP was set correctly
if [ -z "$SAMPLE_APP" ]; then
echo "Error: SAMPLE_APP not found in .env file."
exit 1
fi
# Determine appropriate docker-compose file based on SAMPLE_APP
if [ "$SAMPLE_APP" = "smart-intersection" ]; then
RI_COMPOSE_FILE_ARG="compose-scenescape.yml"
else
RI_COMPOSE_FILE_ARG="compose-without-scenescape.yml"
fi
# Check if the compose file exists
if [ ! -f "$RI_COMPOSE_FILE_ARG" ]; then
echo "Error: Compose file $RI_COMPOSE_FILE_ARG not found."
exit 1
fi
# Bring down the application before updating docker compose file
if docker compose -f "$RI_COMPOSE_FILE_ARG" ps >/dev/null 2>&1; then
echo "Bringing down any running containers..."
docker compose -f "$RI_COMPOSE_FILE_ARG" down
fi
# Copy appropriate docker-compose file
cp "$RI_COMPOSE_FILE_ARG" docker-compose.yml
# Check if the directory exists
if [ ! -d "$SAMPLE_APP" ]; then
echo "Error: Directory $SAMPLE_APP does not exist."
exit 1
fi
# Navigate to the directory and run the install script
echo "Navigating to $SAMPLE_APP directory and running install script..."
cd "$SAMPLE_APP" || exit 1
if [ -f "./install.sh" ]; then
chmod +x ./install.sh
./install.sh $HOST_IP
else
echo "Error: install.sh not found in $SAMPLE_APP directory."
exit 1
fi