Debian Codegraph @

entrypoint.sh

raw
1 #!/bin/bash
2
3 set +e
4
5 ## Functions
6 function apk_add {
7 echo "Installing additional OS packages"
8 while IFS= read -r pkg
9 do
10 echo "Installing ${pkg}"
11 apk add --no-cache -q "${pkg}"
12 done < "$1"
13 }
14
15 function pip_install {
16 echo "Installing Python packages"
17 pip install -r $1
18 }
19
20 function run_scripts {
21 if [ "$1" = "python3" ] || [ "$1" = "python" ]; then python3
22 else
23 echo "Executing defined script"
24 $1 ${@:2}
25 fi
26 }
27
28 ## Manually defined variables will take precedence
29
30 if [ "$APK" ]; then APK=$APK
31 elif [ -f "/extras/apk.txt" ]; then APK="/extras/apk.txt"
32 else APK=''
33 fi
34
35 if [ "$REQ" ]; then REQ=$REQ
36 elif [ -f "/extras/requirements.txt" ];then REQ="/extras/requirements.txt"
37 else REQ=''
38 fi
39
40 if [ "$#" ]; then SCRIPT=$@
41 else SCRIPT=''
42 fi
43
44 ## Install extras, run scripts, or start a shell session
45 [[ -z "$APK" ]] || apk_add "$APK"
46 [[ -z "$REQ" ]] || pip_install "$REQ"
47 [[ -z "$SCRIPT" ]] && /bin/bash || run_scripts "$SCRIPT"
48