phpbb/coopcloud-entrypoint.sh

108 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
# Configurations etc.
COOPCLOUD_MAX_LOAD_SIZE=1024
export COOPCLOUD_ENTRYPOINT_VERSION=0.1.0
# Functions
logn () {
echo -n "[COOP]["$(date +%FT%T%Z)"]" "$@"
}
log () {
logn "$@"
echo " "
}
DOCS=$(cat <<-__DOCS__
EOF
Loading files into environment:
Max size is 1 kbyte, files larger than that will not be loaded.
Environment variables in the format COOPCLOUD_LOAD_<ENVIRONMENTNAME>=<FILENAME>; the contents of
<FILENAME> are loaded into <ENVIRONMENTNAME>
Startup Scripts:
Extra scripts included with the
Entrypoint:
The default entrypoint is communicated from the parent environment with COOPCLOUD_ENTRYPOINT; we expect
COOPCLOUD_ENTRYPOINT_ORIGINAL to be set also. If COOPCLOUD_ENTRYPOINT is being overriden for this execution,
this provides a fall-back and also can communicate to the child environment that the entrypoint has been
overriden.
__DOCS__
)
cat <<-__TURT__
.-=++++==-:
.=+***+*******+=.
=****++%+:+*******-
=#****:-+-.********+:
. .*****+.. .:*******+=.
=*-: .:****++=--=+*******=
=+*==+++-=#***++++++*******+=-
.+*++****==*****+++++++=++=++:
.-++++++-. :++******+=++**********++*+.
=**********: -=-+++******-+++++******++:
=#**++++****+ -===:=+++***-+%%#*+++++==+*++-.
.++*****-=****..====:*======**+*#%%%%%%#=******+=
=++***#--#**+::-==-+@=**#*+%%#**++*+**+-*******=
.=+++==-****=:-:==#@++%%%#+%##%%#%*=##*.:-----:
.-===+*****=:-:-%#+*%#%%*=#%%%##%=#%%-
-++++****+:-:=+=++##*+*#++**#%=+%%=
:=+++***=.=*****-=##%%%#**+-=*+-:
:-==+-+*******-*#####%%++*+=+#=
=********=-+++++=--==+***#-
.********+:.:::...-++******-
-********= :=+++***=-
.-**+**+: :===-:.
:. .=.
[HACK THE PLANET]
__TURT__
# echo that we're running the show
log "#### Coop Cloud Entrypoint $COOPCLOUD_ENTRYPOINT_VERSION ###"
# load specified files into environment variables
while read ENVIRON_VAR; do
file=${!ENVIRON_VAR}
logn "Loading $ENVIRON_VAR ($file)"
if test -e "$file"; then
# file exists!
fsize=$(wc -c < "$file")
if [ $fsize -lt $COOPCLOUD_MAX_LOAD_SIZE ]; then
target=$(echo $ENVIRON_VAR | cut -d_ -f3-)
val="$(cat $file)"
eval export $target=\"$val\"
echo " -> $target."
else
echo " File too big ($fsize bytes > $COOPCLOUD_MAX_LOAD_SIZE)."
fi
else
echo " File Not Found."
fi
done < <(printenv |grep ^COOPCLOUD_LOAD_ | cut -d= -f1)
### fixme we should support some sort of startup script / 1st time script thing here
# warn about overridden entrypoint
if [ "$COOPCLOUD_ENTRYPOINT" != "$COOPCLOUD_ENTRYPOINT_ORIGINAL" ]; then
log "#### Warning: Entrypoint apparently overriden to $COOPCLOUD_ENTRYPOINT ####"
fi
# call the specified entrypoint (if possible)
if [ ! -x "$COOPCLOUD_ENTRYPOINT" ]; then
log "$COOPCLOUD_ENTRYPOINT cannot be executed."
if [ -x "$COOPCLOUD_ENTRYPOINT_ORIGINAL" ]; then
log "Launching original entrypoint ..."
echo ""
exec $COOPCLOUD_ENTRYPOINT_ORIGINAL
else
log "$COOPCLOUD_ENTRYPOINT_ORIGINAL cannot be executed. Giving up."
exit -1
fi
fi
log "Launching entrypoint ..."
exec $COOPCLOUD_ENTRYPOINT "$@"