mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 22:39:18 +08:00
fix: fix scripts path module
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
@@ -18,9 +18,8 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/lib/init.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
@@ -43,7 +42,7 @@ service_port_name=(
|
||||
)
|
||||
for i in ${service_port_name[*]}; do
|
||||
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
|
||||
openim::util:list-to-string $list
|
||||
openim::util::list-to-string $list
|
||||
for j in ${ports_array}; do
|
||||
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
|
||||
if [[ ${port} -ne ${j} ]]; then
|
||||
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
clear
|
||||
. $(dirname ${BASH_SOURCE})/lib/util.sh
|
||||
|
||||
openim::util::desc "You can learn a lot about automation using make help"
|
||||
openim::util::run "make help"
|
||||
clear
|
||||
|
||||
openim::util::desc "You can learn a lot about automation using make help-all"
|
||||
openim::util::run "make help-all"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run tidy"
|
||||
openim::util::run "make tidy"
|
||||
clear
|
||||
|
||||
openim::util::desc "Vendor go.mod"
|
||||
openim::util::run "make vendor"
|
||||
clear
|
||||
|
||||
openim::util::desc "Code style: fmt, vet, lint"
|
||||
openim::util::run "make style"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run unit tests"
|
||||
openim::util::run "make test"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run unit tests and get test coverage"
|
||||
openim::util::run "make cover"
|
||||
clear
|
||||
|
||||
openim::util::desc "Check for updates to go.mod dependencies"
|
||||
openim::util::run "make updates"
|
||||
clear
|
||||
|
||||
openim::util::desc "Clean"
|
||||
openim::util::run "make clean"
|
||||
clear
|
||||
|
||||
openim::util::desc "Generate all necessary files"
|
||||
openim::util::run "make gen"
|
||||
clear
|
||||
|
||||
openim::util::desc "Generate swagger document"
|
||||
openim::util::run "make swagger"
|
||||
clear
|
||||
|
||||
openim::util::desc "Serve swagger spec and docs"
|
||||
openim::util::run "make serve-swagger"
|
||||
clear
|
||||
|
||||
openim::util::desc "Verify the license headers for all files"
|
||||
openim::util::run "make verify-copyright"
|
||||
clear
|
||||
|
||||
openim::util::desc "Add copyright"
|
||||
openim::util::run "make add-copyright"
|
||||
clear
|
||||
|
||||
openim::util::desc "Project introduction, become a contributor"
|
||||
openim::util::run "make advertise"
|
||||
clear
|
||||
|
||||
openim::util::desc "Release the project"
|
||||
openim::util::run "make release"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run demo"
|
||||
openim::util::run "make demo"
|
||||
clear
|
||||
@@ -38,7 +38,7 @@ service_port_name=(
|
||||
|
||||
for i in ${service_port_name[*]}; do
|
||||
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
|
||||
openim::util:list-to-string $list
|
||||
openim::util::list-to-string $list
|
||||
for j in ${ports_array}; do
|
||||
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
|
||||
if [[ ${port} -ne ${j} ]]; then
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#input:[10023,2323,3434]
|
||||
#output:10023 2323 3434
|
||||
openim::util:list-to-string(){
|
||||
openim::util::list-to-string(){
|
||||
ports_list=$*
|
||||
sub_s1=`echo $ports_list | sed 's/ //g'`
|
||||
sub_s2=${sub_s1//,/ }
|
||||
|
||||
+9
-10
@@ -14,25 +14,24 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# Define color variables
|
||||
# Feature
|
||||
# --- Feature ---
|
||||
COLOR_NORMAL='\033[0m';COLOR_BOLD='\033[1m';COLOR_DIM='\033[2m';COLOR_UNDER='\033[4m';
|
||||
COLOR_ITALIC='\033[3m';COLOR_NOITALIC='\033[23m';COLOR_BLINK='\033[5m';
|
||||
COLOR_REVERSE='\033[7m';COLOR_CONCEAL='\033[8m';COLOR_NOBOLD='\033[22m';
|
||||
COLOR_NOUNDER='\033[24m';COLOR_NOBLINK='\033[25m';
|
||||
|
||||
# Front color
|
||||
# --- Front color ---
|
||||
COLOR_BLACK='\033[30m';COLOR_RED='\033[31m';COLOR_GREEN='\033[32m';COLOR_YELLOW='\033[33m';
|
||||
COLOR_BLUE='\033[34m';COLOR_MAGENTA='\033[35m';COLOR_CYAN='\033[36m';COLOR_WHITE='\033[37m';
|
||||
|
||||
# background color
|
||||
# --- background color ---
|
||||
COLOR_BBLACK='\033[40m';COLOR_BRED='\033[41m';
|
||||
COLOR_BGREEN='\033[42m';COLOR_BYELLOW='\033[43m';
|
||||
COLOR_BBLUE='\033[44m';COLOR_BMAGENTA='\033[45m';
|
||||
COLOR_BCYAN='\033[46m';COLOR_BWHITE='\033[47m';
|
||||
|
||||
# Color definitions
|
||||
# --- Color definitions ---
|
||||
COLOR_SUFFIX="\033[0m" # End all colors and special effects
|
||||
BLACK_PREFIX="\033[30m" # Black prefix
|
||||
RED_PREFIX="\033[31m" # Red prefix
|
||||
@@ -48,11 +47,11 @@ BRIGHT_GREEN_PREFIX='\033[1;32m' # Bright green prefix
|
||||
CYAN_PREFIX="\033[0;36m" # Cyan prefix
|
||||
|
||||
# --- make demo (run demo) ---
|
||||
readonly reset=$(tput sgr0)
|
||||
readonly green=$(tput bold; tput setaf 2)
|
||||
readonly yellow=$(tput bold; tput setaf 3)
|
||||
readonly blue=$(tput bold; tput setaf 6)
|
||||
readonly timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)
|
||||
reset=$(tput sgr0)
|
||||
green=$(tput bold; tput setaf 2)
|
||||
yellow=$(tput bold; tput setaf 3)
|
||||
blue=$(tput bold; tput setaf 6)
|
||||
timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)
|
||||
|
||||
# --- helper functions for logs ---
|
||||
info()
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
# Controls verbosity of the script output and logging.
|
||||
OPENIM_VERBOSE="${OPENIM_VERBOSE:-5}"
|
||||
|
||||
souorce $(dirname ${BASH_SOURCE})/color.sh
|
||||
|
||||
# Handler for when we exit automatically on an error.
|
||||
# Borrowed from https://gist.github.com/ahendrix/7030300
|
||||
openim::log::errexit() {
|
||||
|
||||
+65
-1
@@ -13,6 +13,70 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# this script is used to check whether the code is formatted by gofmt or not
|
||||
#
|
||||
# Usage: source scripts/lib/util.sh
|
||||
|
||||
|
||||
#1、将IP写在一个文件里,比如文件名为hosts_file,一行一个IP地址。
|
||||
#2、修改ssh-mutual-trust.sh里面的用户名及密码,默认为root用户及密码123。
|
||||
# hosts_file_path="path/to/your/hosts/file"
|
||||
# openim:util::setup_ssh_key_copy "$hosts_file_path" "root" "123"
|
||||
function openim:util::setup_ssh_key_copy() {
|
||||
local hosts_file="$1"
|
||||
local username="${2:-root}"
|
||||
local password="${3:-123}"
|
||||
|
||||
local sshkey_file=~/.ssh/id_rsa.pub
|
||||
|
||||
# check sshkey file
|
||||
if [[ ! -e $sshkey_file ]]; then
|
||||
expect -c "
|
||||
spawn ssh-keygen -t rsa
|
||||
expect \"Enter*\" { send \"\n\"; exp_continue; }
|
||||
"
|
||||
fi
|
||||
|
||||
# get hosts list
|
||||
local hosts=$(awk '/^[^#]/ {print $1}' "${hosts_file}")
|
||||
|
||||
ssh_key_copy() {
|
||||
local target=$1
|
||||
|
||||
# delete history
|
||||
sed -i "/$target/d" ~/.ssh/known_hosts
|
||||
|
||||
# copy key
|
||||
expect -c "
|
||||
set timeout 100
|
||||
spawn ssh-copy-id $username@$target
|
||||
expect {
|
||||
\"yes/no\" { send \"yes\n\"; exp_continue; }
|
||||
\"*assword\" { send \"$password\n\"; }
|
||||
\"already exist on the remote system\" { exit 1; }
|
||||
}
|
||||
expect eof
|
||||
"
|
||||
}
|
||||
|
||||
# auto sshkey pair
|
||||
for host in $hosts; do
|
||||
if ! ping -i 0.2 -c 3 -W 1 "$host" > /dev/null 2>&1; then
|
||||
echo "[ERROR]: Can't connect $host"
|
||||
continue
|
||||
fi
|
||||
|
||||
local host_entry=$(awk "/$host/"'{print $1, $2}' /etc/hosts)
|
||||
if [[ $host_entry ]]; then
|
||||
local hostaddr=$(echo "$host_entry" | awk '{print $1}')
|
||||
local hostname=$(echo "$host_entry" | awk '{print $2}')
|
||||
ssh_key_copy "$hostaddr"
|
||||
ssh_key_copy "$hostname"
|
||||
else
|
||||
ssh_key_copy "$host"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function openim::util::sourced_variable {
|
||||
# Call this function to tell shellcheck that a variable is supposed to
|
||||
@@ -774,7 +838,7 @@ trap "echo" EXIT
|
||||
# input: [10023, 2323, 3434]
|
||||
# output: 10023 2323 3434
|
||||
# Function function: Converts a list to a string, removing Spaces and parentheses
|
||||
function openim::util:list-to-string() {
|
||||
function openim::util::list-to-string() {
|
||||
ports_list=$* # 获取传入的参数列表
|
||||
sub_s1=$(echo $ports_list | sed 's/ //g') # 去除空格
|
||||
sub_s2=${sub_s1//,/ } # 将逗号替换为空格
|
||||
|
||||
@@ -36,11 +36,11 @@ ulimit -n 200000
|
||||
list1=$(cat $config_path | grep openImMessageGatewayPort | awk -F '[:]' '{print $NF}')
|
||||
list2=$(cat $config_path | grep openImWsPort | awk -F '[:]' '{print $NF}')
|
||||
list3=$(cat $config_path | grep messageGatewayPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||
openim::util:list-to-string $list1
|
||||
openim::util::list-to-string $list1
|
||||
rpc_ports=($ports_array)
|
||||
openim::util:list-to-string $list2
|
||||
openim::util::list-to-string $list2
|
||||
ws_ports=($ports_array)
|
||||
openim::util:list-to-string $list3
|
||||
openim::util::list-to-string $list3
|
||||
prome_ports=($ports_array)
|
||||
if [ ${#rpc_ports[@]} -ne ${#ws_ports[@]} ]; then
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ logs_dir="$OPENIM_ROOT/logs"
|
||||
cd $OPENIM_ROOT
|
||||
|
||||
list1=$(cat $config_path | grep messageTransferPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||
openim::util:list-to-string $list1
|
||||
openim::util::list-to-string $list1
|
||||
prome_ports=($ports_array)
|
||||
|
||||
#Check if the service exists
|
||||
|
||||
@@ -37,9 +37,9 @@ cd "$OPENIM_ROOT/scripts/"
|
||||
|
||||
list1=$(cat $config_path | grep openImPushPort | awk -F '[:]' '{print $NF}')
|
||||
list2=$(cat $config_path | grep pushPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||
openim::util:list-to-string $list1
|
||||
openim::util::list-to-string $list1
|
||||
rpc_ports=($ports_array)
|
||||
openim::util:list-to-string $list2
|
||||
openim::util::list-to-string $list2
|
||||
prome_ports=($ports_array)
|
||||
|
||||
#Check if the service exists
|
||||
|
||||
@@ -90,11 +90,11 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do
|
||||
cd $BIN_DIR
|
||||
# Get the rpc port in the configuration file
|
||||
portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
||||
openim::util:list-to-string ${portList}
|
||||
openim::util::list-to-string ${portList}
|
||||
service_ports=($ports_array)
|
||||
|
||||
portList2=$(cat $config_path | grep ${service_prometheus_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
||||
openim::util:list-to-string $portList2
|
||||
openim::util::list-to-string $portList2
|
||||
prome_ports=($ports_array)
|
||||
#Start related rpc services based on the number of ports
|
||||
for ((j = 0; j < ${#service_ports[*]}; j++)); do
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $OPENIM_ROOT/scripts/style_info.sh
|
||||
source $OPENIM_ROOT/scripts/lib/init.sh
|
||||
source $OPENIM_ROOT/scripts/path_info.sh
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/hack/lib/init.sh"
|
||||
|
||||
kube::golang::setup_env
|
||||
|
||||
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*'
|
||||
}
|
||||
|
||||
export GO111MODULE=on
|
||||
find_files | xargs go run tools/yamlfmt/main.go
|
||||
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script checks whether the OWNERS files need to be formatted or not by
|
||||
# `yamlfmt`. Run `scripts/update-yamlfmt.sh` to actually format sources.
|
||||
#
|
||||
# Usage: `scripts/verify-yamlfmt.sh`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
openim::util::ensure_clean_working_dir
|
||||
# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
|
||||
openim::golang::setup_env
|
||||
|
||||
_tmpdir="$(openim::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
|
||||
git worktree add -f -q "${_tmpdir}" HEAD
|
||||
openim::util::trap_add "git worktree remove -f ${_tmpdir}" EXIT
|
||||
cd "${_tmpdir}"
|
||||
|
||||
# Format YAML files
|
||||
hack/update-yamlfmt.sh
|
||||
|
||||
# Test for diffs
|
||||
diffs=$(git status --porcelain | wc -l)
|
||||
if [[ ${diffs} -gt 0 ]]; then
|
||||
echo "YAML files need to be formatted" >&2
|
||||
git diff
|
||||
echo "Please run 'hack/update-yamlfmt.sh'" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,9 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
|
||||
# Use of this source code is governed by a MIT style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
# Use this script to test if a given TCP host/port are available
|
||||
|
||||
WAITFORIT_cmdname=${0##*/}
|
||||
|
||||
Reference in New Issue
Block a user