node-red-app/make-env-file

51 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
is_p_int() { [ "$1" ] && [ -z "${1//[0-9]/}" ]; }
getip ()
{
dig +short $1 | tail -1
}
declare -A settings
# echo env $1
[[ ! $(getent group docker) ]] && echo no docker group on machine, exiting && exit
[[ ! $1 ]] && echo "no app set, usage make-env-file <app>" && exit
SDIR=$(
cd $(dirname $(readlink -f "$0")) >/dev/null 2>&1
pwd -P
)
ENV_FILE=$SDIR/apps/${1}.cfg
echo processing config file $ENV_FILE
# source any environment for particular site
# shopt -s extglob
# ENV_FILE=$(ls ${FILE}* 2> /dev/null | grep -v '.off$\|.example$\|.tmpl$\|.template$')
[[ -f $ENV_FILE ]] && source $ENV_FILE || echo WARNING no settings file $ENV_FILE, using defaults
PUID=$(id -u $USER 2>/dev/null)
[[ ! $PUID ]] && echo no user $USER, exiting && exit
[[ ! $(getent group docker | grep ${USER}) ]] && echo $USER not in docker group, exiting && exit
__ce_PUID=${PUID:-$([[ ! $(is_p_int PUID) ]] && echo $(id -u))}
__ce_PGID=${PGID:-$(getent group docker | cut -d: -f3)}
ename=${2:-$(basename "${1%.*}")}
__ce_Name=${Name:-$ename-nodered-app}
__ce_Tag=${Tag:-latest-18}
__ce_Broker=$(getip "${Broker}")
__ce_HomeAssistant=$(getip "${HomeAssistant}")
__ce_TZ=${TZ:-"America/Los_Angeles"}
Parent_Folder=${Parent_Folder:-${HOME}/.local/share}
__ce_Data=${Data:-${Parent_Folder}/node-red-apps/$ename}
mkdir -p ${__ce_Data}
# __ce_Config=${Config:-${Parent_Folder}/$ename/config}
# mkdir -p ${__ce_Config}
__ce_Port=${Port:-1880}
echo "$(
set -o posix
set | grep __ce_ | sed 's/__ce_//'
)" >$SDIR/apps/docker.$1.env
echo created $SDIR/apps/docker.$1.env
cat $SDIR/apps/docker.$1.env