Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
B #212: Fix chown command on FreeBSD
Browse files Browse the repository at this point in the history
+ 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ý <[email protected]>
  • Loading branch information
Petr Ospalý authored and Vlastimil Holer committed Jun 18, 2020
1 parent 470d7f8 commit 4ac75a4
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/etc/one-context.d/loc-16-gen-env
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 4ac75a4

Please sign in to comment.