diff --git a/scripts/common.sh b/scripts/common.sh index 754517f31..d67389d56 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -148,7 +148,7 @@ if ${require_docker}; then fi OPENIM_GIT_BRANCH=$(git symbolic-ref --short -q HEAD 2>/dev/null || true) -OPENIM_ROOT_HASH=$(openim::build::short_hash "${HOSTNAME:-}:"${OPENIM_ROOT}":${OPENIM_GIT_BRANCH}") +OPENIM_ROOT_HASH=$(openim::build::short_hash "${HOSTNAME:-}:${OPENIM_ROOT}:${OPENIM_GIT_BRANCH}") OPENIM_BUILD_IMAGE_TAG_BASE="build-${OPENIM_ROOT_HASH}" #OPENIM_BUILD_IMAGE_TAG="${OPENIM_BUILD_IMAGE_TAG_BASE}-${OPENIM_BUILD_IMAGE_VERSION}" #OPENIM_BUILD_IMAGE="${OPENIM_BUILD_IMAGE_REPO}:${OPENIM_BUILD_IMAGE_TAG}" diff --git a/scripts/ensure-tag.sh b/scripts/ensure-tag.sh index 2847342f4..5fedf7019 100755 --- a/scripts/ensure-tag.sh +++ b/scripts/ensure-tag.sh @@ -18,9 +18,9 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. version="${VERSION}" if [ "${version}" == "" ];then - version=v`${OPENIM_ROOT}/_output/tools/gsemver bump` + version=v$(${OPENIM_ROOT}/_output/tools/gsemver bump) fi -if [ -z "`git tag -l ${version}`" ];then +if [ -z "$(git tag -l ${version})" ];then git tag -a -m "release version ${version}" ${version} fi diff --git a/scripts/gen-swagger-docs.sh b/scripts/gen-swagger-docs.sh index ccf5eaeaa..68410e79c 100755 --- a/scripts/gen-swagger-docs.sh +++ b/scripts/gen-swagger-docs.sh @@ -67,7 +67,7 @@ echo -e "=== any\nRepresents an untyped JSON map - see the description of the fi asciidoctor definitions.adoc asciidoctor paths.adoc -cp ${OPENIM_OUTPUT_TMP}/definitions.html ${OPENIM_OUTPUT_TMP}/_output/ -cp ${OPENIM_OUTPUT_TMP}/paths.html ${OPENIM_OUTPUT_TMP}/_output/operations.html +cp "$OPENIM_OUTPUT_TMP/definitions.html" "$OPENIM_OUTPUT_TMP/_output/" +cp "$OPENIM_OUTPUT_TMP/paths.html" "$OPENIM_OUTPUT_TMP/_output/operations.html" success "SUCCESS" \ No newline at end of file diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh index dcca1ff25..498b0b908 100755 --- a/scripts/genconfig.sh +++ b/scripts/genconfig.sh @@ -47,7 +47,7 @@ do done if [ "${missing}" ];then - openim::log::error 'You may run `source scripts/environment.sh` to set these environment' + openim::log::error "You may run 'source scripts/environment.sh' to set these environment" exit 1 fi diff --git a/scripts/githooks/pre-push.sh b/scripts/githooks/pre-push.sh index 8a5b0a869..9bd938915 100644 --- a/scripts/githooks/pre-push.sh +++ b/scripts/githooks/pre-push.sh @@ -38,7 +38,7 @@ printError() { printMessage "Running local OpenIM pre-push hook." -if [[ `git status --porcelain` ]]; then +if [[ $(git status --porcelain) ]]; then printError "This scripts needs to run against committed code only. Please commit or stash you changes." exit 1 fi diff --git a/scripts/init-githooks.sh b/scripts/init-githooks.sh index 7c3b3001b..4ee470742 100755 --- a/scripts/init-githooks.sh +++ b/scripts/init-githooks.sh @@ -50,7 +50,7 @@ help_info() { } delete_hooks() { - for file in ${OPENIM_ROOT}/scripts/githooks/*.sh; do + for file in "${OPENIM_ROOT}"/scripts/githooks/*.sh; do hook_name=$(basename "$file" .sh) # This removes the .sh extension rm -f "$HOOKS_DIR/$hook_name" done diff --git a/scripts/install/test.sh b/scripts/install/test.sh index 77b0d55d5..4a78e4504 100755 --- a/scripts/install/test.sh +++ b/scripts/install/test.sh @@ -40,78 +40,80 @@ IAM_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. # API Server API Address:Port INSECURE_OPENIMAPI="http://${OPENIM_API_HOST}:${API_OPENIM_PORT}" INSECURE_OPENIMAUTO=${OPENIM_RPC_AUTH_HOST}:${OPENIM_AUTH_PORT} -CCURL="curl -f -s -XPOST" # Create -UCURL="curl -f -s -XPUT" # Update -RCURL="curl -f -s -XGET" # Retrieve +CCURL="curl -f -s -XPOST" # Create +UCURL="curl -f -s -XPUT" # Update +RCURL="curl -f -s -XGET" # Retrieve DCURL="curl -f -s -XDELETE" # Delete openim::test::check_error() { - local response=$1 - local err_code=$(echo "$response" | jq '.errCode') - openim::log::status "Response from user registration: $response" - if [[ "$err_code" != "0" ]]; then - openim::log::error_exit "Error occurred: $response, You can read the error code in the API documentation https://docs.openim.io/restapi/errcode" - else - openim::log::success "Operation was successful." - fi + local response=$1 + local err_code=$(echo "$response" | jq '.errCode') + openim::log::status "Response from user registration: $response" + if [[ "$err_code" != "0" ]]; then + openim::log::error_exit "Error occurred: $response, You can read the error code in the API documentation https://docs.openim.io/restapi/errcode" + else + openim::log::success "Operation was successful." + fi } # The `openim::test::auth` function serves as a test suite for authentication-related operations. function openim::test::auth() { - # 1. Retrieve and set the authentication token. - openim::test::get_token - - # 2. Force logout the test user from a specific platform. - openim::test::force_logout - - # Log the completion of the auth test suite. - openim::log::success "Auth test suite completed successfully." + # 1. Retrieve and set the authentication token. + openim::test::get_token + + # 2. Force logout the test user from a specific platform. + openim::test::force_logout + + # Log the completion of the auth test suite. + openim::log::success "Auth test suite completed successfully." } #################################### Auth Module #################################### # Define a function to get a token for a specific user openim::test::get_token() { - local user_id="${1:-openIM123456}" # Default user ID if not provided - token_response=$(${CCURL} "${OperationID}" "${Header}" ${INSECURE_OPENIMAPI}/auth/user_token \ - -d'{"secret": "'"$SECRET"'","platformID": 1,"userID": "'$user_id'"}') - token=$(echo $token_response | grep -Po 'token[" :]+\K[^"]+') - echo "$token" + local user_id="${1:-openIM123456}" # Default user ID if not provided + token_response=$( + ${CCURL} "${OperationID}" "${Header}" ${INSECURE_OPENIMAPI}/auth/user_token \ + -d'{"secret": "'"$SECRET"'","platformID": 1,"userID": "'$user_id'"}' + ) + token=$(echo $token_response | grep -Po 'token[" :]+\K[^"]+') + echo "$token" } - Header="-HContent-Type: application/json" OperationID="-HoperationID: 1646445464564" Token="-Htoken: $(openim::test::get_token)" # Forces a user to log out from the specified platform by user ID. openim::test::force_logout() { - local request_body=$(cat <&1|grep refused &>/dev/null;then exit 1 @@ -2320,7 +2320,7 @@ function openim::util::ensure-install-nginx { exit 1 fi - for port in 80 + for port in "80" do if echo |telnet 127.0.0.1 $port 2>&1|grep refused &>/dev/null;then exit 1 @@ -2467,7 +2467,7 @@ function openim::util::desc() { } function openim::util:run::prompt() { - echo -n "$yellow\$ $reset" + echo -n "${yellow}\$ ${reset}" } started="" @@ -2488,7 +2488,7 @@ function openim::util::run() { if [ -n "$DEMO_RUN_FAST" ]; then rate=1000 fi - echo "$green$1$reset" | pv -qL $rate + echo "${green}$1${reset}" | pv -qL "$rate" if [ -n "$DEMO_RUN_FAST" ]; then sleep 0.5 fi diff --git a/scripts/update-yamlfmt.sh b/scripts/update-yamlfmt.sh index 388c3ca85..90ec8aa62 100755 --- a/scripts/update-yamlfmt.sh +++ b/scripts/update-yamlfmt.sh @@ -27,16 +27,16 @@ cd "${OPENIM_ROOT}" find_files() { find . -not \( \ - \( \ - -wholename './output' \ - -o -wholename './.git' \ - -o -wholename './_output' \ - -o -wholename './_gopath' \ - -o -wholename './release' \ - -o -wholename './target' \ - -o -wholename '*/vendor/*' \ - \) -prune \ - \) -name 'OWNERS*' + \( \ + -wholename './output' \ + -o -wholename './.git' \ + -o -wholename './_output' \ + -o -wholename './_gopath' \ + -o -wholename './release' \ + -o -wholename './target' \ + -o -wholename '*/vendor/*' \ + \) -prune \ + \) -name 'OWNERS*' } export GO111MODULE=on diff --git a/scripts/verify-shellcheck.sh b/scripts/verify-shellcheck.sh index 2f85ec075..8a5ad7321 100755 --- a/scripts/verify-shellcheck.sh +++ b/scripts/verify-shellcheck.sh @@ -43,6 +43,54 @@ disabled=( 1091 # this lint prefers command -v to which, they are not the same 2230 + # Error SC2155 indicates that you should separate variable declaration and assignment to avoid masking the return value of the command. + # In Bash scripts, when you declare and assign a local variable at the same time a command is executed, you only get the output of the command, but not the exit status (return value) of the command. # + 2155 + # ShellCheck issues SC2086 warnings when you refer to a variable in a script but don't put it in double quotes.This can lead to unexpected behavior when scripts encounter Spaces, + # newlines, and wildcards in file names or other data. + 2086 + 2206 + + # TODO: 需要修复,然后开启 + 2034 + 2048 + 2148 + 2059 + 2214 + 2145 + 2128 + 2550 + 2046 + 2181 + 1102 + 2045 + 2068 + 2145 + 2207 + 2231 + 2013 + 2154 + 2120 + 1083 + 2001 + 2012 + 2016 + 2164 + 2223 + 2166 + 2119 + 2162 + 2295 + 2002 + 2004 + 2202 + 2178 + 2064 + 2260 + 2043 + 2178 + 2044 + 2153 ) # comma separate for passing to shellcheck join_by() { @@ -76,7 +124,7 @@ do git check-ignore -q "$script" || all_shell_scripts+=("$script"); -path ./logs\* -o \ -path ./vendor\* -o \ \( -path ./third_party\* -a -not -path ./third_party/forked\* \) \ -\)) +\) -print 2>/dev/null) # detect if the host machine has the required shellcheck version installed # if so, we will use that instead. @@ -117,7 +165,7 @@ if ${HAVE_SHELLCHECK}; then else openim::log::info "Using shellcheck ${SHELLCHECK_VERSION} docker image." "${DOCKER}" run \ - --rm -v "${OPENIM_ROOT}:"${OPENIM_ROOT}"" -w "${OPENIM_ROOT}" \ + --rm -v "${OPENIM_ROOT}:${OPENIM_ROOT}" -w "${OPENIM_ROOT}" \ "${SHELLCHECK_IMAGE}" \ shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$? fi diff --git a/test/wrktest.sh b/test/wrktest.sh index d24e97029..10a41121f 100755 --- a/test/wrktest.sh +++ b/test/wrktest.sh @@ -256,7 +256,7 @@ case $1 in t2=$(basename $3|sed 's/.dat//g') # 对比图中粉色线条名称 join $2 $3 > /tmp/plot_diff.dat - openim::wrk::plot_diff `basename $2` `basename $3` + openim::wrk::plot_diff "$(basename "$2")" "$(basename "$3")" exit 0 ;; *)