#!/bin/sh

# init timezone
test -f /usr/share/zoneinfo/${TZ} && \
ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
echo "${TZ}" >  /etc/timezone && \
echo "init TZ: ${TZ}"

echo "current time: `date`"

if [ "$(id -u)x" != "0x" ]; then
    echo "err: you must run the container as root."
    echo "you can specific the PUID and PGID if you want the app run as specific user."
    exit 1
fi

PUID=${PUID:-1000}
PGID=${PGID:-100}

groupmod -o -g "$PGID" public
usermod -o -u "$PUID" public

echo "
-------------------------------------
     _                      _
 ___(_)_ __ ___   __ _  ___| | __
/ __| | '_ ` _ \ / _` |/ _ \ |/ /
\__ \ | | | | | | (_| |  __/   <
|___/_|_| |_| |_|\__,_|\___|_|\_\

Brought to you by simaek.com
We gratefully accept donations at:
https://www.simaek.com/
-------------------------------------
GID/UID
-------------------------------------"
echo "
User uid:    $(id -u public)
User gid:    $(id -g public)
-------------------------------------
"

if [ $# -gt 0 ]; then
    $1
fi

exec /bin/s6-svscan -t0 /etc/services.d/