I hate sed modification but I must.

Daan Selen committed Mar 21, 2025 at 16:56 UTC e11a858081fec5b64ab3c55c737e19ed8750d622
2 files changed +21 -21
docker/Dockerfile
+1 -1
@@ -2,7 +2,7 @@
2 FROM node:lts-alpine AS builder
3
4 # Any value inside one of the disable ARGs will be accepted.
5 -ARG DISABLE_MINIFY=""
5 +ARG DISABLE_MINIFY="yes"
6 ARG DISABLE_TRANSLATE="yes"
7
8 RUN mkdir -p /opt/meshcentral/meshcentral
docker/entrypoint.sh
+20 -20
@@ -51,81 +51,81 @@ if [[ "$DYNAMIC_CONFIG" =~ ^(true|yes)$ ]]; then
51 if [[ $REGENSESSIONKEY =~ ^(true|yes)$ ]]; then
52 echo "Regenerating Session-Key because REGENSESSIONKEY is 'true' or 'yes'"
53 SESSION_KEY=$(tr -dc 'A-Z0-9' < /dev/urandom | fold -w 60 | head -n 1)
54 - sed -i "s/sessionKey:/ sessionKey\": \"$SESSION_KEY\"/g" "$CONFIG_FILE"
54 + sed -i "s/\"sessionKey\": *\"[^\"]*\"/\"sessionKey\": \"$SESSION_KEY\"/" "$CONFIG_FILE"
55 else
56 echo "REGENSESSIONKEY is not 'true' or 'yes', therefore it's being kept as is."
57 fi
58
59 # HOSTNAME
60 - if [[ -n $HOSTNAME ]]; then
60 + if [[ -n $HOSTNAME ]] && [[ $HOSTNAME =~ ^([a-zA-Z0-9-]+\.)+[a-zA-Z0-9-]+$ ]]; then
61 echo "Setting hostname (cert)... - $HOSTNAME"
62 - sed -i '/cert/ c\ "cert": "'"$HOSTNAME"'"' "$CONFIG_FILE"
62 + sed -i "s/\"cert\": *\"[^\"]*\"/\"cert\": \"$HOSTNAME\"/" "$CONFIG_FILE"
63 else
64 - echo "Hostname environment variable is empty, commenting it out..."
65 - sed -i 's/"cert":/ "_cert":/g' "$CONFIG_FILE"
64 + echo "Invalid hostname, commenting it out..."
65 + sed -i "s/\"cert\": *\"[^\"]*\"/\"cert\": \"localhost\"/" "$CONFIG_FILE"
66 fi
67
68 # ALLOW_NEW_ACCOUNTS
69 if [[ -n $ALLOW_NEW_ACCOUNTS ]] && [[ $ALLOW_NEW_ACCOUNTS =~ ^(true|false)$ ]]; then
70 echo "Setting NewAccounts... - $ALLOW_NEW_ACCOUNTS"
71 - sed -i '/NewAccounts/ c\ "NewAccounts": "'"$ALLOW_NEW_ACCOUNTS"'"' "$CONFIG_FILE"
71 + sed -i "s/\"NewAccounts\": *[a-z]*/\"NewAccounts\": $ALLOW_NEW_ACCOUNTS/" "$CONFIG_FILE"
72 else
73 echo "Invalid ALLOW_NEW_ACCOUNTS value given, commenting out so default applies..."
74 - sed -i 's/"NewAccounts":/ "_NewAccounts":/g' "$CONFIG_FILE"
74 + sed -i 's/"NewAccounts":/"_NewAccounts":/g' "$CONFIG_FILE"
75 fi
76
77 # ALLOWPLUGINS
78 if [[ -n $ALLOWPLUGINS ]] && [[ $ALLOWPLUGINS =~ ^(true|false)$ ]]; then
79 echo "Setting plugins... - $ALLOWPLUGINS"
80 - sed -i '/plugins/ c\ "plugins": {"enabled": '"$ALLOWPLUGINS"'}"' "$CONFIG_FILE"
80 + sed -i "s/\"plugins\": *{[^}]*}/\"plugins\": {\"enabled\": $ALLOWPLUGINS}/" "$CONFIG_FILE"
81 else
82 echo "Invalid ALLOWPLUGINS value given, commenting out so default applies..."
83 - sed -i 's/"plugins":/ "_plugins":/g' "$CONFIG_FILE"
83 + sed -i 's/"plugins":/"_plugins":/g' "$CONFIG_FILE"
84 fi
85
86 # LOCALSESSIONRECORDING
87 if [[ -n $LOCALSESSIONRECORDING ]] && [[ $LOCALSESSIONRECORDING =~ ^(true|false)$ ]]; then
88 echo "Setting localSessionRecording... - $LOCALSESSIONRECORDING"
89 - sed -i '/localSessionRecording/ c\ "localSessionRecording": "'"$LOCALSESSIONRECORDING"'"' "$CONFIG_FILE"
89 + sed -i "s/\"localSessionRecording\": *[a-z]*/\"localSessionRecording\": $LOCALSESSIONRECORDING/" "$CONFIG_FILE"
90 else
91 echo "Invalid LOCALSESSIONRECORDING value given, commenting out so default applies..."
92 - sed -i 's/"localSessionRecording":/ "_localSessionRecording":/g' "$CONFIG_FILE"
92 + sed -i 's/"localSessionRecording":/"_localSessionRecording":/g' "$CONFIG_FILE"
93 fi
94
95 # MINIFY
96 if [[ -n $MINIFY ]] && [[ $MINIFY =~ ^(true|false)$ ]]; then
97 echo "Setting minify... - $MINIFY"
98 - sed -i '/minify/ c\ "minify": "'"$MINIFY"'"' "$CONFIG_FILE"
98 + sed -i "s/\"minify\": *[a-z]*/\"minify\": $MINIFY/" "$CONFIG_FILE"
99 else
100 echo "Invalid MINIFY value given, commenting out so default applies..."
101 - sed -i 's/"minify":/ "_minify":/g' "$CONFIG_FILE"
101 + sed -i 's/"minify":/"_minify":/g' "$CONFIG_FILE"
102 fi
103
104 # WEBRTC
105 if [[ -n $WEBRTC ]] && [[ $WEBRTC =~ ^(true|false)$ ]]; then
106 echo "Setting WebRTC... - $WEBRTC"
107 - sed -i '/WebRTC/ c\ "WebRTC": "'"$WEBRTC"'"' "$CONFIG_FILE"
107 + sed -i "s/\"WebRTC\": *[a-z]*/\"WebRTC\": $WEBRTC/" "$CONFIG_FILE"
108 else
109 echo "Invalid WEBRTC value given, commenting out so default applies..."
110 - sed -i 's/"WebRTC":/ "_WebRTC":/g' "$CONFIG_FILE"
110 + sed -i 's/"WebRTC":/"_WebRTC":/g' "$CONFIG_FILE"
111 fi
112
113 # IFRAME
114 if [[ -n $IFRAME ]] && [[ $IFRAME =~ ^(true|false)$ ]]; then
115 echo "Setting AllowFraming... - $IFRAME"
116 - sed -i '/AllowFraming/ c\ "AllowFraming": "'"$IFRAME"'"' "$CONFIG_FILE"
116 + sed -i "s/\"AllowFraming\": *[a-z]*/\"AllowFraming\": $IFRAME/" "$CONFIG_FILE"
117 else
118 echo "Invalid IFRAME value given, commenting out so default applies..."
119 - sed -i 's/"AllowFraming":/ "_AllowFraming":/g' "$CONFIG_FILE"
119 + sed -i 's/"AllowFraming":/"_AllowFraming":/g' "$CONFIG_FILE"
120 fi
121
122 # ALLOWED_ORIGIN
123 if [[ -n $ALLOWED_ORIGIN ]] && [[ $ALLOWED_ORIGIN =~ ^(true|false)$ ]]; then
124 echo "Setting allowedOrigin... - $ALLOWED_ORIGIN"
125 - sed -i '/allowedOrigin/ c\ "allowedOrigin": "'"$ALLOWED_ORIGIN"'"' "$CONFIG_FILE"
125 + sed -i "s/\"allowedOrigin\": *[a-z]*/\"allowedOrigin\": $ALLOWED_ORIGIN/" "$CONFIG_FILE"
126 else
127 echo "Invalid ALLOWED_ORIGIN value given, commenting out so default applies..."
128 - sed -i 's/"allowedOrigin":/ "_allowedOrigin":/g' "$CONFIG_FILE"
128 + sed -i 's/"allowedOrigin":/"_allowedOrigin":/g' "$CONFIG_FILE"
129 fi
130
131 echo -e "\n$(cat "$CONFIG_FILE")"
@@ -147,4 +147,4 @@ fi
147 node /opt/meshcentral/meshcentral/meshcentral --configfile "${CONFIG_FILE}" "${ARGS}" >> /proc/1/fd/1 &
148 meshcentral_pid=$!
149
150 -wait "$meshcentral_pid"
150 +wait "$meshcentral_pid"
\ No newline at end of file