2022-07-10 10:05:19 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
##@Version : 202207101005-git
|
|
|
|
# @Author : Jason Hempstead
|
|
|
|
# @Contact : jason@casjaysdev.com
|
|
|
|
# @License : WTFPL
|
|
|
|
# @ReadME : entrypoint-deno.sh --help
|
|
|
|
# @Copyright : Copyright: (c) 2022 Jason Hempstead, Casjays Developments
|
|
|
|
# @Created : Sunday, Jul 10, 2022 10:05 EDT
|
|
|
|
# @File : entrypoint-deno.sh
|
2022-07-10 12:19:06 -04:00
|
|
|
# @Description :
|
|
|
|
# @TODO :
|
|
|
|
# @Other :
|
|
|
|
# @Resource :
|
2022-07-10 10:05:19 -04:00
|
|
|
# @sudo/root : no
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2022-10-11 16:07:58 -04:00
|
|
|
# Set bash options
|
|
|
|
[ -n "$DEBUG" ] && set -x
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2022-07-10 10:05:19 -04:00
|
|
|
APPNAME="$(basename "$0" 2>/dev/null)"
|
|
|
|
VERSION="202207101005-git"
|
|
|
|
HOME="${USER_HOME:-$HOME}"
|
|
|
|
USER="${SUDO_USER:-$USER}"
|
|
|
|
RUN_USER="${SUDO_USER:-$USER}"
|
|
|
|
SRC_DIR="${BASH_SOURCE%/*}"
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
|
|
|
|
__exec_bash() { [ $# -ne 0 ] && exec "${*:-bash -l}" || exec /bin/bash -l; }
|
|
|
|
__find() { ls -A "$*" 2>/dev/null; }
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
DATA_DIR="$(__find /data/ 2>/dev/null | grep '^' || false)"
|
|
|
|
CONFIG_DIR="$(__find /config/ 2>/dev/null | grep '^' || false)"
|
|
|
|
export TZ="${TZ:-America/New_York}"
|
|
|
|
export HOSTNAME="${HOSTNAME:-casjaysdev-bin}"
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
if [[ -n "${TZ}" ]]; then
|
|
|
|
echo "${TZ}" >/etc/timezone
|
|
|
|
fi
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
if [[ -f "/usr/share/zoneinfo/${TZ}" ]]; then
|
|
|
|
ln -sf "/usr/share/zoneinfo/${TZ}" "/etc/localtime"
|
|
|
|
fi
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
if [[ -n "${HOSTNAME}" ]]; then
|
|
|
|
echo "${HOSTNAME}" >/etc/hostname
|
|
|
|
echo "127.0.0.1 $HOSTNAME localhost" >/etc/hosts
|
|
|
|
fi
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2022-10-12 16:23:14 -04:00
|
|
|
[[ -f "/config/.env" ]] && source /config/.env
|
|
|
|
|
2022-10-12 18:31:11 -04:00
|
|
|
if [ -z "$1" ] && [ -z "$(ls -A "/data/htdocs/www" 2>/dev/null)" ]; then
|
2022-10-12 16:23:14 -04:00
|
|
|
FRESH_INSTALL="true"
|
2022-10-12 18:31:11 -04:00
|
|
|
deno run -A -r https://fresh.deno "/data/htdocs/www"
|
2022-10-12 16:23:14 -04:00
|
|
|
fi
|
2022-07-10 10:05:19 -04:00
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case "$1" in
|
|
|
|
--help)
|
|
|
|
echo "Usage: $APPNAME [healthcheck, bash, command]"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
healthcheck)
|
2022-07-10 19:42:09 -04:00
|
|
|
type -P deno &>/dev/null && echo 'OK' || exit 1
|
2022-07-10 10:05:19 -04:00
|
|
|
;;
|
2022-07-10 19:38:22 -04:00
|
|
|
sh | bash | shell | /bin/sh | /bin/bash)
|
2022-07-10 10:05:19 -04:00
|
|
|
shift 1
|
|
|
|
__exec_bash "$@"
|
|
|
|
;;
|
2022-10-12 16:23:14 -04:00
|
|
|
|
|
|
|
deno)
|
|
|
|
shift 1
|
2022-10-12 18:31:11 -04:00
|
|
|
deno run --allow-net "${@:-/data/htdocs/www/sample.ts}"
|
2022-10-12 16:23:14 -04:00
|
|
|
;;
|
2022-07-10 10:05:19 -04:00
|
|
|
*)
|
2022-10-12 16:23:14 -04:00
|
|
|
if [ "$FRESH_INSTALL" = "true" ]; then
|
|
|
|
deno --allow-all task start
|
|
|
|
else
|
2022-10-12 18:31:11 -04:00
|
|
|
deno run --watch --allow-all "${@:-/data/htdocs/www/sample.ts}"
|
2022-10-12 16:23:14 -04:00
|
|
|
fi
|
2022-07-10 10:05:19 -04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
#end
|