diff --git a/src/etc/one-context.d/loc-16-gen-env b/src/etc/one-context.d/loc-16-gen-env index 8e0565b..36c1013 100755 --- a/src/etc/one-context.d/loc-16-gen-env +++ b/src/etc/one-context.d/loc-16-gen-env @@ -17,33 +17,36 @@ #--------------------------------------------------------------------------- # ENV_FILE=/var/run/one-context/one_env -MOUNT_DIR=${MOUNT_DIR:-/mnt} -TOKENTXT=$(cat "${MOUNT_DIR}/token.txt") +MOUNT_DIR="${MOUNT_DIR:-/mnt}" +TOKEN_FILE="${MOUNT_DIR}/token.txt" if [ -n "$ONEGATE_TOKEN" ]; then TOKENTXT="$ONEGATE_TOKEN" +elif [ -f "$TOKEN_FILE" ]; then + TOKENTXT=$(cat "$TOKEN_FILE") fi umask 0377 -echo "export TOKENTXT=\"$TOKENTXT\"" > $ENV_FILE -echo "export VMID=\"$VMID\"" >> $ENV_FILE -echo "export ONEGATE_ENDPOINT=\"$ONEGATE_ENDPOINT\"" >> $ENV_FILE +echo "export TOKENTXT=\"$TOKENTXT\"" > "$ENV_FILE" +echo "export VMID=\"$VMID\"" >> "$ENV_FILE" +echo "export ONEGATE_ENDPOINT=\"$ONEGATE_ENDPOINT\"" >> "$ENV_FILE" function export_rc_vars { - if [ -f $1 ] ; then - ONE_VARS=$(cat $1 | egrep -e '^[a-zA-Z\-\_0-9]*=' | sed 's/=.*$//') + if [ -n "$1" ] && [ -f "$1" ] ; then + ONE_VARS=$(grep -E -e '^[a-zA-Z\-\_0-9]*=' "$1" | sed 's/=.*$//') - . $1 + # shellcheck disable=SC1090 + . "$1" for v in $ONE_VARS; do - echo "export $v=\"${!v}\"" >> $ENV_FILE + echo "export $v=\"${!v}\"" >> "$ENV_FILE" done fi } -export_rc_vars ${CONTEXT_FILE} +export_rc_vars "${CONTEXT_FILE}" -chown root:root $ENV_FILE -chmod 0400 $ENV_FILE +chown "root:$(id -gn root)" "$ENV_FILE" +chmod 0400 "$ENV_FILE"