From 4ac75a4242e1c1d5e96cbcb7e8a01e6700b3f473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ospal=C3=BD?= Date: Wed, 17 Jun 2020 03:29:17 +0200 Subject: [PATCH] B #212: Fix chown command on FreeBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + fix error when CONTEXT_FILE is empty (not likely) + fix other warning/error messages shown in the log + make the script compliant with shellshock Signed-off-by: Petr OspalĂ˝ --- src/etc/one-context.d/loc-16-gen-env | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) 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"