B #212: Fix chown command on FreeBSD

+ 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ý <pospaly@opennebula.io>
pull/214/head
Petr Ospalý 5 years ago committed by Vlastimil Holer
parent 470d7f8e2b
commit 4ac75a4242

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

Loading…
Cancel
Save