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

Commit 20a9c97

Browse files
ospalaxvholer
authored andcommitted
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>
1 parent 470d7f8 commit 20a9c97

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/etc/one-context.d/loc-16-gen-env

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,36 @@
1717
#--------------------------------------------------------------------------- #
1818

1919
ENV_FILE=/var/run/one-context/one_env
20-
MOUNT_DIR=${MOUNT_DIR:-/mnt}
21-
TOKENTXT=$(cat "${MOUNT_DIR}/token.txt")
20+
MOUNT_DIR="${MOUNT_DIR:-/mnt}"
21+
TOKEN_FILE="${MOUNT_DIR}/token.txt"
2222

2323
if [ -n "$ONEGATE_TOKEN" ]; then
2424
TOKENTXT="$ONEGATE_TOKEN"
25+
elif [ -f "$TOKEN_FILE" ]; then
26+
TOKENTXT=$(cat "$TOKEN_FILE")
2527
fi
2628

2729
umask 0377
28-
echo "export TOKENTXT=\"$TOKENTXT\"" > $ENV_FILE
29-
echo "export VMID=\"$VMID\"" >> $ENV_FILE
30-
echo "export ONEGATE_ENDPOINT=\"$ONEGATE_ENDPOINT\"" >> $ENV_FILE
30+
echo "export TOKENTXT=\"$TOKENTXT\"" > "$ENV_FILE"
31+
echo "export VMID=\"$VMID\"" >> "$ENV_FILE"
32+
echo "export ONEGATE_ENDPOINT=\"$ONEGATE_ENDPOINT\"" >> "$ENV_FILE"
3133

3234
function export_rc_vars
3335
{
34-
if [ -f $1 ] ; then
35-
ONE_VARS=$(cat $1 | egrep -e '^[a-zA-Z\-\_0-9]*=' | sed 's/=.*$//')
36+
if [ -n "$1" ] && [ -f "$1" ] ; then
37+
ONE_VARS=$(grep -E -e '^[a-zA-Z\-\_0-9]*=' "$1" | sed 's/=.*$//')
3638

37-
. $1
39+
# shellcheck disable=SC1090
40+
. "$1"
3841

3942
for v in $ONE_VARS; do
40-
echo "export $v=\"${!v}\"" >> $ENV_FILE
43+
echo "export $v=\"${!v}\"" >> "$ENV_FILE"
4144
done
4245
fi
4346
}
4447

45-
export_rc_vars ${CONTEXT_FILE}
48+
export_rc_vars "${CONTEXT_FILE}"
4649

47-
chown root:root $ENV_FILE
48-
chmod 0400 $ENV_FILE
50+
chown "root:$(id -gn root)" "$ENV_FILE"
51+
chmod 0400 "$ENV_FILE"
4952

0 commit comments

Comments
 (0)