forked from Juniper/py-junos-eznc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·45 lines (35 loc) · 919 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
#!/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 {
echo "Executing defined script"
python3 $1 ${@:2}
}
## 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"