Skip to content

Commit 35bf6a3

Browse files
author
Slyke
committed
Added better version messaging for python and deps
1 parent 038be7d commit 35bf6a3

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

menu.sh

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DOCKER_COMPOSE_OVERRIDE_YML=./compose-override.yml
1212
COMPOSE_VERSION="3.6"
1313
REQ_DOCKER_VERSION=18.2.0
1414
REQ_PYTHON_VERSION=3.6.9
15-
REQ_PYYAML_VERSION_=5.3.1
15+
REQ_PYYAML_VERSION=5.3.1
1616

1717
declare -A cont_array=(
1818
[portainer]="Portainer"
@@ -123,29 +123,58 @@ function minimum_version_check() {
123123
CURR_VERSION_MAJOR=$2
124124
CURR_VERSION_MINOR=$3
125125
CURR_VERSION_BUILD=$4
126+
127+
VERSION_GOOD="Unknown"
126128

127-
VERSION_GOOD="false"
129+
if [ -z "$CURR_VERSION_MAJOR" ]; then
130+
echo "$VERSION_GOOD"
131+
return 1
132+
fi
133+
134+
if [ -z "$CURR_VERSION_MINOR" ]; then
135+
echo "$VERSION_GOOD"
136+
return 1
137+
fi
138+
139+
if [ -z "$CURR_VERSION_BUILD" ]; then
140+
echo "$VERSION_GOOD"
141+
return 1
142+
fi
128143

129144
if [ "${CURR_VERSION_MAJOR}" -ge $REQ_MIN_VERSION_MAJOR ]; then
130145
VERSION_GOOD="true"
146+
echo "$VERSION_GOOD"
147+
return 0
148+
else
149+
VERSION_GOOD="false"
131150
fi
132151

133152
if [ "${CURR_VERSION_MAJOR}" -ge $REQ_MIN_VERSION_MAJOR ] && \
134153
[ "${CURR_VERSION_MINOR}" -ge $REQ_MIN_VERSION_MINOR ]; then
135154
VERSION_GOOD="true"
155+
echo "$VERSION_GOOD"
156+
return 0
157+
else
158+
VERSION_GOOD="false"
136159
fi
137160

138161
if [ "${CURR_VERSION_MAJOR}" -ge $REQ_MIN_VERSION_MAJOR ] && \
139162
[ "${CURR_VERSION_MINOR}" -ge $REQ_MIN_VERSION_MINOR ] && \
140163
[ "${CURR_VERSION_BUILD}" -ge $REQ_MIN_VERSION_BUILD ]; then
141164
VERSION_GOOD="true"
165+
echo "$VERSION_GOOD"
166+
return 0
167+
else
168+
VERSION_GOOD="false"
142169
fi
143170

144171
echo "$VERSION_GOOD"
145172
}
146173

147174
function install_python3_and_deps() {
148-
if (whiptail --title "Python 3 and Dependencies" --yesno "Python 3 (v3.6.9) or later, PyYaml 5.3.1 and pip3 is required for compose-overrides.yml file to merge into the docker-compose.yml file. Install now?" 20 78); then
175+
CURR_PYTHON_VER="${1:-Unknown}"
176+
CURR_PYYAML_VER="${2:-Unknown}"
177+
if (whiptail --title "Python 3 and Dependencies" --yesno "Python 3.6.9 or later (Current = $CURR_PYTHON_VER), PyYaml 5.3.1 or later (Current = $CURR_PYYAML_VER) and pip3 is required for compose-overrides.yml file to merge into the docker-compose.yml file. Install these now?" 20 78); then
149178
sudo apt install -y python3-pip python3-dev
150179
if [ $? -eq 0 ]; then
151180
PYTHON_VERSION_GOOD="true"
@@ -169,36 +198,42 @@ function do_python3_pip() {
169198

170199
if command_exists python3 && command_exists pip3; then
171200
PYTHON_VERSION=$(python3 --version)
172-
echo "Python Version: $PYTHON_VERSION"
201+
echo "Python Version: ${PYTHON_VERSION:-Unknown}"
173202
PYTHON_VERSION_MAJOR=$(echo "$PYTHON_VERSION"| cut -d' ' -f 2 | cut -d'.' -f 1)
174203
PYTHON_VERSION_MINOR=$(echo "$PYTHON_VERSION"| cut -d'.' -f 2)
175204
PYTHON_VERSION_BUILD=$(echo "$PYTHON_VERSION"| cut -d'.' -f 3)
176205

177-
if [ "$(minimum_version_check $REQ_PYTHON_VERSION $PYTHON_VERSION_MAJOR $PYTHON_VERSION_MINOR $PYTHON_VERSION_BUILD )" == "true" ]; then
178-
PYTHON_VERSION_GOOD="true"
179-
else
180-
echo "Python is outdated."
181-
install_python3_and_deps
182-
fi
183-
184206
PYYAML_VERSION=$(python3 ./scripts/yaml_merge.py --pyyaml-version)
185-
echo "PyYaml Version: $PYYAML_VERSION"
207+
PYYAML_VERSION="${PYYAML_VERSION:-Unknown}"
186208
PYYAML_VERSION_MAJOR=$(echo "$PYYAML_VERSION"| cut -d' ' -f 2 | cut -d'.' -f 1)
187209
PYYAML_VERSION_MINOR=$(echo "$PYYAML_VERSION"| cut -d'.' -f 2)
188210
PYYAML_VERSION_BUILD=$(echo "$PYYAML_VERSION"| cut -d'.' -f 3)
189211

190-
if [ "$(minimum_version_check $REQ_PYYAML_VERSION $PYYAML_VERSION_MAJOR $PYYAML_VERSION_MINOR $PYYAML_VERSION_BUILD )" == "true" ]; then
212+
if [ "$(minimum_version_check $REQ_PYTHON_VERSION $PYTHON_VERSION_MAJOR $PYTHON_VERSION_MINOR $PYTHON_VERSION_BUILD)" == "true" ]; then
213+
PYTHON_VERSION_GOOD="true"
214+
else
215+
echo "Python is outdated."
216+
install_python3_and_deps "$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR.$PYTHON_VERSION_BUILD" "$PYYAML_VERSION_MAJOR.$PYYAML_VERSION_MINOR.$PYYAML_VERSION_BUILD"
217+
return 1
218+
fi
219+
echo "PyYaml Version: $PYYAML_VERSION"
220+
if [ "$(minimum_version_check $REQ_PYYAML_VERSION $PYYAML_VERSION_MAJOR $PYYAML_VERSION_MINOR $PYYAML_VERSION_BUILD)" == "true" ]; then
191221
PYYAML_VERSION_GOOD="true"
192222
else
193223
echo "PyYaml is outdated."
194-
install_python3_and_deps
224+
if [ "$PYYAML_VERSION" != "Unknown" ]; then
225+
install_python3_and_deps "$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR.$PYTHON_VERSION_BUILD" "$PYYAML_VERSION_MAJOR.$PYYAML_VERSION_MINOR.$PYYAML_VERSION_BUILD"
226+
else
227+
install_python3_and_deps "$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR.$PYTHON_VERSION_BUILD"
228+
fi
229+
return 1
195230
fi
196231
else
197232
install_python3_and_deps
233+
return 1
198234
fi
199235
}
200236

201-
202237
#function copies the template yml file to the local service folder and appends to the docker-compose.yml file
203238
function yml_builder() {
204239

@@ -375,9 +410,7 @@ case $mainmenu_selection in
375410
#if no container is selected then dont overwrite the docker-compose.yml file
376411
if [ -n "$container_selection" ]; then
377412
touch $TMP_DOCKER_COMPOSE_YML
378-
# echo "services:" > $TMP_DOCKER_COMPOSE_YML
379413

380-
# Uncomment once sort_keys is available in Pyton->yaml
381414
echo "version: '$COMPOSE_VERSION'" > $TMP_DOCKER_COMPOSE_YML
382415
echo "services:" >> $TMP_DOCKER_COMPOSE_YML
383416

@@ -411,9 +444,6 @@ case $mainmenu_selection in
411444
cp $TMP_DOCKER_COMPOSE_YML $DOCKER_COMPOSE_YML
412445
fi
413446

414-
# Prepend compose version after merging/copying, so that merging doesn't move it to the bottom (alphabetically ordered).
415-
# echo -e "version: '$COMPOSE_VERSION'\n$(cat $DOCKER_COMPOSE_YML)" > $DOCKER_COMPOSE_YML # Remove once sort_keys works in Python->yaml.
416-
417447
echo "docker-compose successfully created"
418448
echo "run 'docker-compose up -d' to start the stack"
419449
else

0 commit comments

Comments
 (0)