-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoxy-processor.sh
More file actions
executable file
·104 lines (90 loc) · 3.31 KB
/
foxy-processor.sh
File metadata and controls
executable file
·104 lines (90 loc) · 3.31 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
#!/bin/bash
echo " . "
echo " .~5B. "
echo " ~P#@@@? "
echo " !@@@@@@@J. "
echo " ^~~^:. P@@@@@@&&BY."
echo " ^5@@&#G?: !&@@@@@&!.:. "
echo " ?@@@@@&! .^!5@@@@@@@@G "
echo " B@@@@@&: ^JG&@@@@@@@@@@@? "
echo " .#@@@@@@~ ^P@@@@@@@@@@@@@&7 "
echo " ?@@@@@@&.^&@@@@@@@@@@@@@@7 "
echo " 5@@@@@@G G@@@@@@@@@@@@@@@! "
echo " J@@@@@@#:#@@@@@@@@@@@G?@@G. "
echo " .P@@@@@@P#@@@@@@@@&BY. ~B@G^ "
echo " ~YB#&@@@@@@@@@@#P7 .J&&P5! "
echo " .::^^^^^^^^^^^: .^^^: "
echo "######################################"
echo "# Welcome to Foxy Processor Module #"
echo "######################################"
echo
# Define the container name and the script path
APP_CONTAINER_NAME="foxy-apps"
APP_SCRIPT_PATH="processor/app.py"
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
INITIATOR_SCRIPT="$SCRIPT_DIR/foxy-install.sh"
# Function to check if Docker is installed
check_docker_installed() {
if ! command -v docker > /dev/null 2>&1; then
echo "Docker is not installed."
echo "Please install Docker to continue."
echo "You can find installation instructions at: https://docs.docker.com/get-docker/"
exit 1
fi
}
# Function to check if the container exists
container_exists() {
docker ps -a --format '{{.Names}}' | grep -q "^$APP_CONTAINER_NAME$"
}
# Function to check if the container is running
container_is_running() {
docker ps -q -f name="$APP_CONTAINER_NAME" > /dev/null 2>&1
}
# Function to run the script inside the container
run_app_script() {
echo "Running $APP_SCRIPT_PATH inside the container $APP_CONTAINER_NAME..."
docker exec -it "$APP_CONTAINER_NAME" python "$APP_SCRIPT_PATH"
}
# Function to start the container using the initiator script
start_container() {
echo "Starting the container using '$INITIATOR_SCRIPT'..."
if [ -f "$INITIATOR_SCRIPT" ]; then
bash "$INITIATOR_SCRIPT"
# Wait a few seconds to give the container time to start
sleep 2
else
echo "Initiator script '$INITIATOR_SCRIPT' not found. Please ensure it is present in the current directory."
exit 1
fi
}
# Main script execution
check_docker_installed
if container_exists; then
echo "Container $APP_CONTAINER_NAME exists."
if container_is_running; then
echo "Container $APP_CONTAINER_NAME is running."
run_app_script
else
echo "Container $APP_CONTAINER_NAME is not running."
start_container
if container_is_running; then
echo "Container $APP_CONTAINER_NAME is now running."
run_app_script
else
echo "Container $APP_CONTAINER_NAME failed to start. Please check the '$INITIATOR_SCRIPT' for errors."
exit 1
fi
fi
else
echo "Container $APP_CONTAINER_NAME does not exist."
start_container
if container_exists; then
echo "Container $APP_CONTAINER_NAME has been created and started."
run_app_script
else
echo "Container $APP_CONTAINER_NAME could not be created. Please check the '$INITIATOR_SCRIPT' for errors."
exit 1
fi
fi
# Pause the script until a key is pressed
read -p "Press any key to exit..."