forked from Juniper/py-junos-eznc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·48 lines (38 loc) · 996 Bytes
/
entrypoint.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
#!/bin/bash
set +e
## Functions
function apk_add {
echo "Installing additional OS packages"
while IFS= read -r pkg
do
echo "Installing ${pkg}"
apk add --no-cache -q "${pkg}"
done < "$1"
}
function pip_install {
echo "Installing Python packages"
pip install -r $1
}
function run_scripts {
if [ "$1" = "python3" ] || [ "$1" = "python" ]; then python3
else
echo "Executing defined script"
$1 ${@:2}
fi
}
## Manually defined variables will take precedence
if [ "$APK" ]; then APK=$APK
elif [ -f "/extras/apk.txt" ]; then APK="/extras/apk.txt"
else APK=''
fi
if [ "$REQ" ]; then REQ=$REQ
elif [ -f "/extras/requirements.txt" ];then REQ="/extras/requirements.txt"
else REQ=''
fi
if [ "$#" ]; then SCRIPT=$@
else SCRIPT=''
fi
## Install extras, run scripts, or start a shell session
[[ -z "$APK" ]] || apk_add "$APK"
[[ -z "$REQ" ]] || pip_install "$REQ"
[[ -z "$SCRIPT" ]] && /bin/bash || run_scripts "$SCRIPT"