Skip to content

Commit 472f8fa

Browse files
authored
fix: Fix some bugs in shell scripts (#29)
1. Fix the incorrect format of file:// URLs supported in configuration 2. Always create a default McpBridge resource for editing 3. Exclude the test folder when decompressing during installation
1 parent 1b8df73 commit 472f8fa

12 files changed

Lines changed: 171 additions & 25 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ docker compose
4747

4848
配置服务的 URL。
4949
- 若使用独立部署的 Nacos 服务,URL 格式为:nacos://192.168.0.1:8848
50-
- 若在本地磁盘上保存配置,URL 格式为:file://opt/higress/conf
50+
- 若在本地磁盘上保存配置,URL 格式为:file:///opt/higress/conf
5151

5252
* --use-builtin-nacos
5353

@@ -71,7 +71,7 @@ docker compose
7171

7272
* -p, --console-password=CONSOLE-PASSWORD
7373

74-
后续用户访问 Higress Console 的密码(用户名固定为 `admin`)。默认值为 `admin`
74+
后续用户访问 Higress Console 的密码(用户名固定为 `admin`)。若未设置,Higress 将自动生成一个随机的密码
7575

7676
* --nacos-port=NACOS-PORT
7777

@@ -81,7 +81,7 @@ docker compose
8181

8282
Higress Gateway 在服务器本地监听的 HTTP 端口。默认值为 80。
8383

84-
* --gateway-https-port=GATEAWY-HTTPS-PORT
84+
* --gateway-https-port=GATEWAY-HTTPS-PORT
8585

8686
Higress Gateway 在服务器本地监听的 HTTPS 端口。默认值为 443。
8787

bin/configure.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ configure() {
192192
}
193193

194194
resetEnv() {
195+
COMPOSE_PROFILES=""
195196
CONFIG_STORAGE=""
196197
FILE_ROOT_DIR=""
197198
NACOS_SERVER_URL=""
@@ -276,12 +277,23 @@ configureFileStorageByArgs() {
276277

277278
FILE_ROOT_DIR="${CONFIG_URL#file://}"
278279
if [ "$OS" == "windows" ]; then
279-
if [[ "$FILE_ROOT_DIR" == *":"* ]]; then
280-
FILE_ROOT_DIR="${FILE_ROOT_DIR//\\//}"
281-
else
282-
FILE_ROOT_DIR="/${FILE_ROOT_DIR//\\//}"
280+
# Fix path separators
281+
FILE_ROOT_DIR="${FILE_ROOT_DIR//\\//}"
282+
if [[ "$FILE_ROOT_DIR" == "."* ]] || [[ "$FILE_ROOT_DIR" == "~/"* ]]; then
283+
# A relatpath ive or user home based path. Do nothing.
284+
:
285+
elif [[ "$FILE_ROOT_DIR" != "/"* ]]; then
286+
echo 'Invalid file URL. Relative path must begin with a ".". Absolute path must begin with a "/" or "~/".'
287+
exit -1
288+
elif [[ "$FILE_ROOT_DIR" == *":"* ]]; then
289+
FILE_ROOT_DIR="${FILE_ROOT_DIR#/}"
283290
fi
284291
fi
292+
if [[ "$FILE_ROOT_DIR" == '~/'* ]]; then
293+
# A user home based path.
294+
FILE_ROOT_DIR="${HOME}${FILE_ROOT_DIR#\~}"
295+
fi
296+
echo "Root: $FILE_ROOT_DIR"
285297
mkdir -p "$FILE_ROOT_DIR" && cd "$_"
286298
if [ $? -ne 0 ]; then
287299
echo "Unable to create/access the config folder. Please fix it or choose another one."
@@ -415,7 +427,9 @@ configureFileStorage() {
415427
readNonEmpty "Please input the root path of config folder: "
416428
FILE_ROOT_DIR="$input"
417429
if [ "$OS" == "windows" ]; then
418-
if [[ "$FILE_ROOT_DIR" == "/"* ]]; then
430+
if [[ "$FILE_ROOT_DIR" == "."* ]]; then
431+
:
432+
elif [[ "$FILE_ROOT_DIR" == "/"* ]]; then
419433
:
420434
elif [[ "$FILE_ROOT_DIR" == *":"* ]]; then
421435
FILE_ROOT_DIR="${FILE_ROOT_DIR//\\//}"
@@ -474,7 +488,7 @@ outputUsage() {
474488
-a, --auto-start start Higress after configuration
475489
-c, --config-url=URL URL of the config storage
476490
Use Nacos with format: nacos://192.168.0.1:8848
477-
Use local files with format: file://opt/higress/conf
491+
Use local files with format: file:///opt/higress/conf
478492
--use-builtin-nacos use the built-in Nacos service instead of
479493
an external one to store configurations
480494
--nacos-ns=NACOS-NAMESPACE

compose/scripts/init.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ publishFileConfig() {
8989

9090
if [ "$skipWhenExisted" == true ] && [ -f "$configFile" ]; then
9191
echo " Config file [$configFile] already exists"
92-
exit 0
92+
return 0
9393
fi
9494

9595
mkdir -p "$configDir"
@@ -381,6 +381,17 @@ initializeGateway() {
381381
initializeMcpBridge() {
382382
echo "Initializing McpBridge resource..."
383383

384+
read -r -d '' content << EOF
385+
apiVersion: networking.higress.io/v1
386+
kind: McpBridge
387+
metadata:
388+
creationTimestamp: "$(now)"
389+
name: default
390+
namespace: higress-system
391+
spec:
392+
registries:
393+
EOF
394+
384395
if [ "$CONFIG_STORAGE" == "nacos" ]; then
385396
if [[ "$NACOS_SERVER_URL" =~ ^http://([a-zA-Z0-9.]+?)(:([0-9]+))/nacos$ ]]; then
386397
NACOS_SERVER_DOMAIN="${BASH_REMATCH[1]}"
@@ -410,14 +421,7 @@ EOF
410421
fi
411422

412423
read -r -d '' content << EOF
413-
apiVersion: networking.higress.io/v1
414-
kind: McpBridge
415-
metadata:
416-
creationTimestamp: "$(now)"
417-
name: default
418-
namespace: higress-system
419-
spec:
420-
registries:
424+
${content}
421425
- domain: ${NACOS_SERVER_DOMAIN}
422426
nacosGroups:
423427
- DEFAULT_GROUP
@@ -427,8 +431,9 @@ spec:
427431
type: nacos2
428432
authSecretName: "${nacosAuthSecretName}"
429433
EOF
430-
publishConfig "higress-system" "mcpbridges" "default" "$content"
431434
fi
435+
436+
publishConfig "higress-system" "mcpbridges" "default" "$content"
432437
}
433438

434439
initializeConsole() {

src/get-higress.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ outputUsage() {
7171
echo '
7272
-c, --config-url=URL URL of the config storage
7373
Use Nacos with format: nacos://192.168.0.1:8848
74-
Use local files with format: file://opt/higress/conf
74+
Use local files with format: file:///opt/higress/conf
7575
--use-builtin-nacos use the built-in Nacos service instead of
7676
an external one
7777
--nacos-ns=NACOS-NAMESPACE
@@ -190,7 +190,7 @@ download() {
190190

191191
# install installs the product.
192192
install() {
193-
tar -zx --exclude="docs" --exclude="src" -f "$HIGRESS_TMP_FILE" -C "$DESTINATION" --strip-components=1
193+
tar -zx --exclude="docs" --exclude="src" --exclude="test" -f "$HIGRESS_TMP_FILE" -C "$DESTINATION" --strip-components=1
194194
bash "$DESTINATION/bin/configure.sh" --auto-start ${CONFIG_ARGS[@]}
195195
}
196196

test/configure/cases/args-file-full_non-windows.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
CONFIGURE_ARGS="-c file://tmp/higress/data --console-password=helloworld --gateway-http-port=30002 --gateway-https-port=30003 --gateway-metrics-port=30004 --console-port=30005"
15+
CONFIGURE_ARGS="-c file:///tmp/higress/data --console-password=helloworld --gateway-http-port=30002 --gateway-https-port=30003 --gateway-metrics-port=30004 --console-port=30005"
1616

1717
CONFIGURE_INPUT=""
1818

test/configure/cases/args-file-full_windows.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
CONFIGURE_ARGS="-c file://c/temp/higress/data --console-password=helloworld --gateway-http-port=30002 --gateway-https-port=30003 --gateway-metrics-port=30004 --console-port=30005"
15+
CONFIGURE_ARGS="-c file:///c/temp/higress/data --console-password=helloworld --gateway-http-port=30002 --gateway-https-port=30003 --gateway-metrics-port=30004 --console-port=30005"
1616

1717
CONFIGURE_INPUT=""
1818

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2023 Alibaba Group Holding Ltd.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http:www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
CONFIGURE_ARGS="-c file://./higress/data"
16+
17+
CONFIGURE_INPUT=""
18+
19+
declare -A EXPECTED_ENVS=(
20+
["COMPOSE_PROFILES"]=''
21+
["CONFIG_STORAGE"]='file'
22+
["FILE_ROOT_DIR"]="$(pwd)/higress/data"
23+
["GATEWAY_HTTP_PORT"]='80'
24+
["GATEWAY_HTTPS_PORT"]='443'
25+
["GATEWAY_METRICS_PORT"]='15020'
26+
["CONSOLE_PORT"]='8080'
27+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2023 Alibaba Group Holding Ltd.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http:www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
CONFIGURE_ARGS="-c file://./higress/data"
16+
17+
CONFIGURE_INPUT=""
18+
19+
declare -A EXPECTED_ENVS=(
20+
["COMPOSE_PROFILES"]=''
21+
["CONFIG_STORAGE"]='file'
22+
["FILE_ROOT_DIR"]="$(cygpath -w "$PWD")\\higress\\data"
23+
["GATEWAY_HTTP_PORT"]='80'
24+
["GATEWAY_HTTPS_PORT"]='443'
25+
["GATEWAY_METRICS_PORT"]='15020'
26+
["CONSOLE_PORT"]='8080'
27+
)

test/configure/cases/args-file-path-with-colon_windows.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
CONFIGURE_ARGS="-c file://c/temp/higress/data"
15+
CONFIGURE_ARGS="-c file:///c:/temp/higress/data"
1616

1717
CONFIGURE_INPUT=""
1818

test/configure/cases/input-file-full_non-windows.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ CONFIGURE_ARGS=""
1717
CONFIGURE_INPUT="file
1818
/tmp/higress/data
1919
admin
20-
30001
2120
30002
2221
30003
2322
30004

0 commit comments

Comments
 (0)