forked from esimonetti/SugarDockerized
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstack.sh
executable file
·98 lines (87 loc) · 3.39 KB
/
stack.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
#!/bin/bash
# Enrico Simonetti
# enricosimonetti.com
# enter the repo's root directory
REPO="$( dirname ${BASH_SOURCE[0]} )/../"
cd $REPO
# include stack configuration
. ./utilities/stacks.conf
if [ -z $1 ] || [ -z $2 ]
then
echo Provide two parameters. The sugar stack version keyword for \(eg: 14, 13\) and the action \(up, down\). The stacks keywords available can be found below:
for index in "${stacks[@]}" ; do
KEY="${index%%::*}"
echo $KEY
done
else
# based on the solution of literal key/values for old bash versions described here
#https://stackoverflow.com/questions/6047648/bash-4-associative-arrays-error-declare-a-invalid-option
for index in "${stacks[@]}" ; do
KEY="${index%%::*}"
VALUE="${index##*::}"
if [ "$KEY" == $1 ]; then
STACKFILE=$VALUE
break
fi
done
# if it is our repo, and the source exists, and the destination does not
if [ -f '.gitignore' ] && [ -d 'data' ] && [ ! -z $STACKFILE ] && [ -f $STACKFILE ]
then
# check if the stack is running
RUNNING=`docker ps | grep sugar-web1 | wc -l`
if [ $RUNNING -gt 0 ] && [ $2 == 'up' ]
then
echo A stack is running, please take the stack down first
else
echo $STACKFILE $2
if [ $2 == 'down' ]
then
if [ $RUNNING -eq 0 ]
then
echo The stack is already down, skipping
else
docker compose -f $STACKFILE down
docker compose -f $STACKFILE rm
fi
else
if [ $2 == 'up' ]
then
docker compose -f $STACKFILE up -d --build
else
echo The action $2 is not applicable
fi
fi
echo Checking for a newer SugarDockerized version, please wait...
NEEDSUPGRADE=`./utilities/sugardockerized/checkversion.sh`
echo Done.
if $NEEDSUPGRADE
then
echo
echo --------------------------------------------------------------------------------------------------------------------------------
echo Your SugarDockerized needs to be upgraded, please execute ./utilities/sugardockerized/selfupgrade.sh to proceed with the upgrade
echo --------------------------------------------------------------------------------------------------------------------------------
echo
fi
echo
echo
echo If you find this software useful, please consider supporting the work that went into it, with a monthly amount
echo Please visit the original repo: https://github.com/esimonetti/SugarDockerized for details
echo Thank you!
echo
echo
fi
else
if [ ! -d 'data' ]
then
echo \"data\" cannot be empty, the command needs to be executed from within the clone of the repository
fi
if [ -z $STACKFILE ] || [ ! -f $STACKFILE ]
then
echo The stack keyword $1 does not exist on your configuration file. The stacks keywords available can be found below:
for index in "${stacks[@]}" ; do
KEY="${index%%::*}"
echo $KEY
done
fi
fi
fi