forked from Giotino/LessDestructiveFarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_stop.sh
executable file
·68 lines (59 loc) · 2.69 KB
/
start_stop.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
#!/bin/bash
# ------------------------------------------------
# ------------------ VARIABLES -------------------
RED="#E95378"
GREEN="#29D398"
BLUE="#26BBD9"
WHITE=${main_color}
ORANGE="#F09483"
# ------------------------------------------------
# -------------------- SCRIPT --------------------
[[ $(groups | grep docker | wc -l) -eq 1 ]] && DOCKER="docker" || DOCKER="sudo docker"
# PASS=$(gum input --password --placeholder "your user password" --header "Sudo password to run docker" --header.foreground "$WHITE")# if [[ $(groups | grep docker | wc -l) -eq 1 ]]
CHOICE=$(gum choose --cursor.foreground "$ORANGE" --item.faint "Up (Directly)" "Up (Build)" "Down" "Exit" --header "What do you want to do with the Farmer?" --header.foreground "$WHITE")
if [[ $CHOICE == "Exit" ]]
then
echo "Bye :snake:" | gum format -t emoji | gum style --align center --padding "1 6"
exit 1
fi
# LOGS=$(gum choose --cursor.foreground "$ORANGE" --item.faint "Yes" " No" --header "Show logs?" --header.foreground "$WHITE")
# [[ $LOGS == "Yes" ]] && LOGS="--show-output" || LOGS=""
if [[ $CHOICE == "Up (Build)" ]]
then
gum spin -s line --title "Building container ..." -- $DOCKER compose up -d --build
if [[ $($DOCKER container ls | grep server-app | wc -l) -eq 1 ]]
then
echo "Container correctly $(gum style --foreground "$GREEN" --bold "UP")"
else
echo "$(gum style --foreground "$RED" --bold "Something went wrong") ... Aborting"
exit 1
fi
elif [[ $CHOICE == "Up (Directly)" ]]
then
if [[ $($DOCKER container ls | grep server-app | wc -l) -eq 1 ]]
then
REBUILD=$(gum choose --cursor.foreground "$ORANGE" --item.faint "Yes" "No" --header "The Farmer container is already $(gum style --foreground "$GREEN" --bold "UP"), do you want to rebuild it?" --header.foreground "$WHITE")
if [[ $REBUILD == "Yes" ]]
then
gum spin -s line --title "Taking container down ..." -- $DOCKER compose down
gum spin -s line --title "Rebuilding container ..." -- $DOCKER compose up -d --build
fi
else
gum spin -s line --title "Building container ..." -- $DOCKER compose up -d
fi
if [[ $($DOCKER container ls | grep server-app | wc -l) -eq 1 ]]
then
echo "Container correctly $(gum style --foreground "$GREEN" --bold "UP")"
else
echo "$(gum style --foreground "$RED" --bold "Something went wrong") ... Aborting"
exit 1
fi
elif [[ $CHOICE == "Down" ]]
then
if [[ $($DOCKER container ls | grep server-app | wc -l) -eq 1 ]]
then
gum spin -s line --title "Stopping and removing container ..." -- $DOCKER compose down
fi
echo "Container correctly $(gum style --foreground "$RED" --bold "DOWN")"
fi
echo "Bye :snake:" | gum format -t emoji | gum style --align center --padding "1 6"