Large refactoring projects: OpenIM automation, scripting, and openimctl refactoring (#825)

* fix: fix bin tools path

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: fix golang release file path

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: fix golang release file path

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: fix scripts and optimize

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: fix scripts path module

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: sync script code

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add lib and start scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* ci: add copyright scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* ci: add go-docs file and  copyright scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts cross ower

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* style: Formatting code make lint path

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* style: Formatting code make lint path

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* style: Formatting code make lint path

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* style: Formatting code make lint path

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: chat scripts path bug

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: channge smail images

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add makefile feature

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add config and images log

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* style: Migrate directory to remove docker to images

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* style: formatting style Code

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: set opneim's bash logs

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: option scripts and docs

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add git cherry

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add git cherry

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save all bash and docs labels

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: scripts feature extend

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add config path config

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add config path config

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add feat scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add save scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add save scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add sctips help

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add start sctips help

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save scripts file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save all file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add openim server template file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add alot of system design

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save all file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save all file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add env config options

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add more robot details

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add more module explain

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts environment details design

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add openim msgtransfer scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add openim msgtransfer scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add more design scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add file save

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add file save

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add rpc build and start

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add rpc build and start

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add rpc build and start

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save all images file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts set

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add test options

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: fix config path file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: update config file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: update config file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: update config file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: update config file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add readme docs

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save build scripts

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add all actions file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add chat scripts name

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add all compose

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: commit tag

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save server code

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add docker compose fix

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add docker compose fix

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add docker compose fix

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: save server code

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: optimize dockerfile option

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: optimize dockerfile option

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: optimize dockerfile option

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add all options

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add all options

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add more scrips

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add more options

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add more options

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add config path

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: Add some optimizations

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* fix: Add some optimizations

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: delele go work sum

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: delele go work sum

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* Delete go.work.sum

* feat: delele go work sum

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* Update .env

* feat: delele go work sum

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: delele go work sum

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: delele go work sum

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: delele go work sum

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add docker compose fix

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add docker compose fix

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: delele go work sum

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

---------

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
Xinwei Xiong
2023-08-23 09:09:51 +08:00
committed by GitHub
parent ff9b258229
commit 58f591e5f6
255 changed files with 12457 additions and 4111 deletions
+178
View File
@@ -0,0 +1,178 @@
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# A set of helpers for starting/running chat for tests
CHAT_VERSION=${CHAT_VERSION:-1.1.0}
CHAT_HOST=${CHAT_HOST:-127.0.0.1}
CHAT_PORT=${CHAT_PORT:-2379}
# This is intentionally not called CHAT_LOG_LEVEL:
# chat checks that and compains when it is set in addition
# to the command line argument, even when both have the same value.
CHAT_LOGLEVEL=${CHAT_LOGLEVEL:-warn}
export OPENIM_INTEGRATION_CHAT_URL="http://${CHAT_HOST}:${CHAT_PORT}"
openim::chat::validate() {
# validate if in path
command -v chat >/dev/null || {
openim::log::usage "chat must be in your PATH"
openim::log::info "You can use 'hack/install-chat.sh' to install a copy in third_party/."
exit 1
}
# validate chat port is free
local port_check_command
if command -v ss &> /dev/null && ss -Version | grep 'iproute2' &> /dev/null; then
port_check_command="ss"
elif command -v netstat &>/dev/null; then
port_check_command="netstat"
else
openim::log::usage "unable to identify if chat is bound to port ${CHAT_PORT}. unable to find ss or netstat utilities."
exit 1
fi
if ${port_check_command} -nat | grep "LISTEN" | grep "[\.:]${CHAT_PORT:?}" >/dev/null 2>&1; then
openim::log::usage "unable to start chat as port ${CHAT_PORT} is in use. please stop the process listening on this port and retry."
openim::log::usage "$(${port_check_command} -nat | grep "LISTEN" | grep "[\.:]${CHAT_PORT:?}")"
exit 1
fi
# need set the env of "CHAT_UNSUPPORTED_ARCH" on unstable arch.
arch=$(uname -m)
if [[ $arch =~ arm* ]]; then
export CHAT_UNSUPPORTED_ARCH=arm
fi
# validate installed version is at least equal to minimum
version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3)
if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then
export PATH=${OPENIM_ROOT}/third_party/chat:${PATH}
hash chat
echo "${PATH}"
version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3)
if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then
openim::log::usage "chat version ${CHAT_VERSION} or greater required."
openim::log::info "You can use 'hack/install-chat.sh' to install a copy in third_party/."
exit 1
fi
fi
}
openim::chat::version() {
printf '%s\n' "${@}" | awk -F . '{ printf("%d%03d%03d\n", $1, $2, $3) }'
}
openim::chat::start() {
# validate before running
openim::chat::validate
# Start chat
CHAT_DIR=${CHAT_DIR:-$(mktemp -d 2>/dev/null || mktemp -d -t test-chat.XXXXXX)}
if [[ -d "${ARTIFACTS:-}" ]]; then
CHAT_LOGFILE="${ARTIFACTS}/chat.$(uname -n).$(id -un).log.DEBUG.$(date +%Y%m%d-%H%M%S).$$"
else
CHAT_LOGFILE=${CHAT_LOGFILE:-"/dev/null"}
fi
openim::log::info "chat --advertise-client-urls ${OPENIM_INTEGRATION_CHAT_URL} --data-dir ${CHAT_DIR} --listen-client-urls http://${CHAT_HOST}:${CHAT_PORT} --log-level=${CHAT_LOGLEVEL} 2> \"${CHAT_LOGFILE}\" >/dev/null"
chat --advertise-client-urls "${OPENIM_INTEGRATION_CHAT_URL}" --data-dir "${CHAT_DIR}" --listen-client-urls "${OPENIM_INTEGRATION_CHAT_URL}" --log-level="${CHAT_LOGLEVEL}" 2> "${CHAT_LOGFILE}" >/dev/null &
CHAT_PID=$!
echo "Waiting for chat to come up."
openim::util::wait_for_url "${OPENIM_INTEGRATION_CHAT_URL}/health" "chat: " 0.25 80
curl -fs -X POST "${OPENIM_INTEGRATION_CHAT_URL}/v3/kv/put" -d '{"key": "X3Rlc3Q=", "value": ""}'
}
openim::chat::start_scraping() {
if [[ -d "${ARTIFACTS:-}" ]]; then
CHAT_SCRAPE_DIR="${ARTIFACTS}/chat-scrapes"
else
CHAT_SCRAPE_DIR=$(mktemp -d -t test.XXXXXX)/chat-scrapes
fi
openim::log::info "Periodically scraping chat to ${CHAT_SCRAPE_DIR} ."
mkdir -p "${CHAT_SCRAPE_DIR}"
(
while sleep 30; do
openim::chat::scrape
done
) &
CHAT_SCRAPE_PID=$!
}
openim::chat::scrape() {
curl -s -S "${OPENIM_INTEGRATION_CHAT_URL}/metrics" > "${CHAT_SCRAPE_DIR}/next" && mv "${CHAT_SCRAPE_DIR}/next" "${CHAT_SCRAPE_DIR}/$(date +%s).scrape"
}
openim::chat::stop() {
if [[ -n "${CHAT_SCRAPE_PID:-}" ]] && [[ -n "${CHAT_SCRAPE_DIR:-}" ]] ; then
kill "${CHAT_SCRAPE_PID}" &>/dev/null || :
wait "${CHAT_SCRAPE_PID}" &>/dev/null || :
openim::chat::scrape || :
(
# shellcheck disable=SC2015
cd "${CHAT_SCRAPE_DIR}"/.. && \
tar czf chat-scrapes.tgz chat-scrapes && \
rm -rf chat-scrapes || :
)
fi
if [[ -n "${CHAT_PID-}" ]]; then
kill "${CHAT_PID}" &>/dev/null || :
wait "${CHAT_PID}" &>/dev/null || :
fi
}
openim::chat::clean_chat_dir() {
if [[ -n "${CHAT_DIR-}" ]]; then
rm -rf "${CHAT_DIR}"
fi
}
openim::chat::cleanup() {
openim::chat::stop
openim::chat::clean_chat_dir
}
openim::chat::install() {
(
local os
local arch
os=$(openim::util::host_os)
arch=$(openim::util::host_arch)
cd "${OPENIM_ROOT}/third_party" || return 1
if [[ $(readlink chat) == chat-v${CHAT_VERSION}-${os}-* ]]; then
openim::log::info "chat v${CHAT_VERSION} already installed. To use:"
openim::log::info "export PATH=\"$(pwd)/chat:\${PATH}\""
return #already installed
fi
if [[ ${os} == "darwin" ]]; then
download_file="chat-v${CHAT_VERSION}-${os}-${arch}.zip"
url="https://github.com/chat-io/chat/releases/download/v${CHAT_VERSION}/${download_file}"
openim::util::download_file "${url}" "${download_file}"
unzip -o "${download_file}"
ln -fns "chat-v${CHAT_VERSION}-${os}-${arch}" chat
rm "${download_file}"
elif [[ ${os} == "linux" ]]; then
url="https://github.com/coreos/chat/releases/download/v${CHAT_VERSION}/chat-v${CHAT_VERSION}-${os}-${arch}.tar.gz"
download_file="chat-v${CHAT_VERSION}-${os}-${arch}.tar.gz"
openim::util::download_file "${url}" "${download_file}"
tar xzf "${download_file}"
ln -fns "chat-v${CHAT_VERSION}-${os}-${arch}" chat
rm "${download_file}"
else
openim::log::info "${os} is NOT supported."
fi
openim::log::info "chat v${CHAT_VERSION} installed. To use:"
openim::log::info "export PATH=\"$(pwd)/chat:\${PATH}\""
)
}
+92 -28
View File
@@ -14,24 +14,47 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# this script is used to install the dependencies of the project
#
# Usage: `scripts/color.sh`.
################################################################################
# shellcheck disable=SC2034
if [[ ! -v COLOR_OPEN ]]; then
COLOR_OPEN=1
fi
# Function for colored echo
openim::color::echo() {
COLOR=$1
[ $COLOR_OPEN -eq 1 ] && echo -e "${COLOR} $(date '+%Y-%m-%d %H:%M:%S') $@ ${COLOR_SUFFIX}"
shift
}
# 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
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';
# --- 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
@@ -44,31 +67,18 @@ WHITE_PREFIX="\033[37m" # White prefix
BOLD_PREFIX="\033[1m" # Bold prefix
UNDERLINE_PREFIX="\033[4m" # Underline prefix
ITALIC_PREFIX="\033[3m" # Italic prefix
BRIGHT_GREEN_PREFIX='\033[1;32m' # Bright green prefix
CYAN_PREFIX="\033[0;36m" # Cyan prefix
# --- helper functions for logs ---
info()
{
echo -e "[${GREEN_PREFIX}INFO${COLOR_SUFFIX}] " "$@"
}
warn()
{
echo -e "[${YELLOW_PREFIX}WARN${COLOR_SUFFIX}] " "$@" >&2
}
fatal()
{
echo -e "[${RED_PREFIX}ERROR${COLOR_SUFFIX}] " "$@" >&2
exit 1
}
debug()
{
echo -e "[${BLUE_PREFIX}DEBUG${COLOR_SUFFIX}]===> " "$@"
}
success()
{
echo -e "${BRIGHT_GREEN_PREFIX}===> [SUCCESS] <===${COLOR_SUFFIX}\n=> " "$@"
}
# --- make demo (run demo) ---
reset=$(tput sgr0)
bold=$(tput bold)
black=$(tput setaf 0)
red=$(tput setaf 1)
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)
# Print colors you can use
openim::color::print_color()
@@ -85,3 +95,57 @@ openim::color::print_color()
dim; blink; nobold; under"
echo
}
# test functions
openim::color::test() {
echo "Starting the color tests..."
echo "Testing normal echo without color"
openim::color::echo $COLOR_NORMAL "This is a normal text"
echo "Testing bold echo"
openim::color::echo $COLOR_BOLD "This is bold text"
echo "Testing dim echo"
openim::color::echo $COLOR_DIM "This is dim text"
echo "Testing underlined echo"
openim::color::echo $COLOR_UNDER "This is underlined text"
echo "Testing italic echo"
openim::color::echo $COLOR_ITALIC "This is italic text"
echo "Testing red color"
openim::color::echo $COLOR_RED "This is red text"
echo "Testing green color"
openim::color::echo $COLOR_GREEN "This is green text"
echo "Testing yellow color"
openim::color::echo $COLOR_YELLOW "This is yellow text"
echo "Testing blue color"
openim::color::echo $COLOR_BLUE "This is blue text"
echo "Testing magenta color"
openim::color::echo $COLOR_MAGENTA "This is magenta text"
echo "Testing cyan color"
openim::color::echo $COLOR_CYAN "This is cyan text"
echo "Testing black background"
openim::color::echo $COLOR_BBLACK "This is text with black background"
echo "Testing red background"
openim::color::echo $COLOR_BRED "This is text with red background"
echo "Testing green background"
openim::color::echo $COLOR_BGREEN "This is text with green background"
echo "Testing blue background"
openim::color::echo $COLOR_BBLUE "This is text with blue background"
echo "All tests completed!"
}
# openim::color::test
+123 -8
View File
@@ -13,24 +13,58 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# shellcheck disable=SC2034 # Variables sourced in other scripts.
# The golang package that we are building.
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
readonly OPENIM_GO_PACKAGE=github.com/openimsdk/open-im-server
# The server platform we are building on.
readonly OPENIM_SUPPORTED_SERVER_PLATFORMS=(
linux/amd64
linux/arm64
linux/s390x
linux_mips64
linux_mips64le
darwin_amd64
windows_amd64
linux_amd64
linux_arm64
linux_ppc64le
)
# If we update this we should also update the set of platforms whose standard
# library is precompiled for in build/build-image/cross/Dockerfile
readonly OPENIM_SUPPORTED_CLIENT_PLATFORMS=(
linux/amd64
linux/arm64
linux/s390x
linux/ppc64le
windows/amd64
)
# openim chat
readonly OPENIM_CHAT_SUPPORTED_PLATFORMS=(
linux/amd64
linux/arm64
linux/s390x
linux/ppc64le
windows/amd64
)
# Which platforms we should compile test targets for.
# Not all client platforms need these tests
readonly KUBE_SUPPORTED_TEST_PLATFORMS=(
linux/amd64
linux/arm64
linux/s390x
linux/ppc64le
darwin/amd64
darwin/arm64
windows/amd64
windows/arm64
)
# The set of server targets that we are only building for Linux
# If you update this list, please also update build/BUILD.
# TODO: Label
openim::golang::server_targets() {
local targets=(
openim-api
@@ -54,14 +88,84 @@ IFS=" " read -ra OPENIM_SERVER_TARGETS <<< "$(openim::golang::server_targets)"
readonly OPENIM_SERVER_TARGETS
readonly OPENIM_SERVER_BINARIES=("${OPENIM_SERVER_TARGETS[@]##*/}")
# TODO: Label
START_SCRIPTS_PATH="${OPENIM_ROOT}/scripts/install/"
openim::golang::start_script_list() {
local targets=(
openim-api.sh
openim-rpc.sh
openim-push.sh
openim-msgtransfer.sh
openim-msggateway.sh
openim-crontask.sh
openim-tools.sh
)
local result=()
for target in "${targets[@]}"; do
result+=("${START_SCRIPTS_PATH}${target}")
done
echo "${result[@]}"
}
# Populate the OPENIM_SERVER_SCRIPT_START_LIST with the full path names of the scripts.
IFS=" " read -ra OPENIM_SERVER_SCRIPT_START_LIST <<< "$(openim::golang::start_script_list)"
readonly OPENIM_SERVER_SCRIPT_START_LIST
# Extract just the script names from the full paths.
readonly OPENIM_SERVER_SCRIPTARIES=("${OPENIM_SERVER_SCRIPT_START_LIST[@]##*/}")
openim::golang::check_openim_binaries() {
local missing_binaries=()
for binary in "${OPENIM_SERVER_BINARIES[@]}"; do
if [[ ! -x "${OPENIM_OUTPUT_HOSTBIN}/${binary}" ]]; then
missing_binaries+=("${binary}")
fi
done
if [[ ${#missing_binaries[@]} -ne 0 ]]; then
echo "The following binaries were not found in ${OPENIM_OUTPUT_HOSTBIN}:"
for missing in "${missing_binaries[@]}"; do
echo " - ${missing}"
done
return 1
else
echo "All binaries have been installed in ${OPENIM_OUTPUT_HOSTBIN}"
return 0
fi
}
openim::golang::tools_targets() {
local targets=(
yamlfmt
changelog
infra
ncpu
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_TOOLS_TARGETS <<< "$(openim::golang::tools_targets)"
readonly OPENIM_TOOLS_TARGETS
readonly OPENIM_TOOLS_BINARIES=("${OPENIM_TOOLS_TARGETS[@]##*/}")
# The set of server targets we build docker images for
openim::golang::server_image_targets() {
# NOTE: this contains cmd targets for openim::build::get_docker_wrapped_binaries
local targets=(
cmd/openim-apiserver
cmd/openim-authz-server
cmd/openim-pump
cmd/openim-watcher
cmd/openim-api
cmd/openim-cmdutils
cmd/openim-crontask
cmd/openim-msggateway
cmd/openim-msgtransfer
cmd/openim-push
cmd/openim-rpc-auth
cmd/openim-rpc-conversation
cmd/openim-rpc-friend
cmd/openim-rpc-group
cmd/openim-rpc-msg
cmd/openim-rpc-third
cmd/openim-rpc-user
)
echo "${targets[@]}"
}
@@ -70,6 +174,8 @@ IFS=" " read -ra OPENIM_SERVER_IMAGE_TARGETS <<< "$(openim::golang::server_image
readonly OPENIM_SERVER_IMAGE_TARGETS
readonly OPENIM_SERVER_IMAGE_BINARIES=("${OPENIM_SERVER_IMAGE_TARGETS[@]##*/}")
# shellcheck disable=SC2034 # Variables sourced in other scripts.
# ------------
# NOTE: All functions that return lists should use newlines.
# bash functions can't return arrays, and spaces are tricky, so newline
@@ -87,12 +193,21 @@ openim::golang::dups() {
printf "%s\n" "$@" | sort | uniq -d
}
# echo "aa: $OPENIM_SERVER_IMAGE_TARGETS"
# echo "aa: $OPENIM_SERVER_IMAGE_BINARIES"
openim::golang::dups $OPENIM_SERVER_IMAGE_TARGETS
openim::golang::dups $OPENIM_SERVER_IMAGE_BINARIES
# Returns a sorted newline-separated list with duplicated items removed.
openim::golang::dedup() {
# We use printf to insert newlines, which are required by sort.
printf "%s\n" "$@" | sort -u
}
# openim::golang::dedup $OPENIM_SERVER_IMAGE_TARGETS
# openim::golang::dedup $OPENIM_SERVER_IMAGE_BINARIES
# Depends on values of user-facing OPENIM_BUILD_PLATFORMS, OPENIM_FASTBUILD,
# and OPENIM_BUILDER_OS.
# Configures OPENIM_SERVER_PLATFORMS and OPENIM_CLIENT_PLATFORMS, then sets them
@@ -175,7 +290,7 @@ EOF
local go_version
IFS=" " read -ra go_version <<< "$(go version)"
local minimum_go_version
minimum_go_version=go1.13.4
minimum_go_version=go1.18
if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then
openim::log::usage_from_stdin <<EOF
Detected go version: ${go_version[*]}.
+176 -7
View File
@@ -13,25 +13,194 @@
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set +o nounset
set -o pipefail
# Short-circuit if init.sh has already been sourced
[[ $(type -t openim::init::loaded) == function ]] && return 0
# Unset CDPATH so that path interpolation can work correctly
unset CDPATH
# Default use go modules
# Until all GOPATH references are removed from all build scripts as well,
# explicitly disable module mode to avoid picking up user-set GO111MODULE preferences.
# As individual scripts (like hack/update-vendor.sh) make use of go modules,
# they can explicitly set GO111MODULE=on
export GO111MODULE=on
# The root of the build/dist directory
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
source "${OPENIM_ROOT}/scripts/lib/util.sh"
source "${OPENIM_ROOT}/scripts/lib/logging.sh"
source "${OPENIM_ROOT}/scripts/lib/color.sh"
OPENIM_OUTPUT_SUBPATH="${OPENIM_OUTPUT_SUBPATH:-_output}"
OPENIM_OUTPUT="${OPENIM_ROOT}/${OPENIM_OUTPUT_SUBPATH}"
OPENIM_OUTPUT_BINPATH="${OPENIM_OUTPUT}/bin/platforms"
OPENIM_OUTPUT_BINTOOLPATH="${OPENIM_OUTPUT}/bin/tools"
OPENIM_OUTPUT_TOOLS="${OPENIM_OUTPUT}/tools"
OPENIM_OUTPUT_TMP="${OPENIM_OUTPUT}/tmp"
OPENIM_OUTPUT_LOGS="${OPENIM_OUTPUT}/logs"
# This controls rsync compression. Set to a value > 0 to enable rsync
# compression for build container
OPENIM_RSYNC_COMPRESS="${KUBE_RSYNC_COMPRESS:-0}"
# Set no_proxy for localhost if behind a proxy, otherwise,
# the connections to localhost in scripts will time out
export no_proxy="127.0.0.1,localhost${no_proxy:+,${no_proxy}}"
# This is a symlink to binaries for "this platform", e.g. build tools.
export THIS_PLATFORM_BIN="${OPENIM_ROOT}/_output/bin/platforms"
export THIS_PLATFORM_BIN_TOOLS="${OPENIM_ROOT}/_output/bin/tools"
. $(dirname ${BASH_SOURCE})/color.sh
. $(dirname ${BASH_SOURCE})/util.sh
. $(dirname ${BASH_SOURCE})/logging.sh
openim::log::install_errexit
openim::util::ensure-bash-version
source "${OPENIM_ROOT}/scripts/lib/version.sh"
source "${OPENIM_ROOT}/scripts/lib/golang.sh"
. $(dirname ${BASH_SOURCE})/version.sh
. $(dirname ${BASH_SOURCE})/golang.sh
. $(dirname ${BASH_SOURCE})/release.sh
. $(dirname ${BASH_SOURCE})/chat.sh
OPENIM_OUTPUT_HOSTBIN="${OPENIM_OUTPUT_BINPATH}/$(openim::util::host_platform)"
export OPENIM_OUTPUT_HOSTBIN
OPENIM_OUTPUT_HOSTBIN_TOOLS="${OPENIM_OUTPUT_BINTOOLPATH}/$(openim::util::host_platform)"
export OPENIM_OUTPUT_HOSTBIN_TOOLS
export OPENIM_NONSERVER_GROUP_VERSIONS
# This emulates "readlink -f" which is not available on MacOS X.
# Test:
# T=/tmp/$$.$RANDOM
# mkdir $T
# touch $T/file
# mkdir $T/dir
# ln -s $T/file $T/linkfile
# ln -s $T/dir $T/linkdir
# function testone() {
# X=$(readlink -f $1 2>&1)
# Y=$(kube::readlinkdashf $1 2>&1)
# if [ "$X" != "$Y" ]; then
# echo readlinkdashf $1: expected "$X", got "$Y"
# fi
# }
# testone /
# testone /tmp
# testone $T
# testone $T/file
# testone $T/dir
# testone $T/linkfile
# testone $T/linkdir
# testone $T/nonexistant
# testone $T/linkdir/file
# testone $T/linkdir/dir
# testone $T/linkdir/linkfile
# testone $T/linkdir/linkdir
function openim::readlinkdashf {
# run in a subshell for simpler 'cd'
(
if [[ -d "${1}" ]]; then # This also catch symlinks to dirs.
cd "${1}"
pwd -P
else
cd "$(dirname "${1}")"
local f
f=$(basename "${1}")
if [[ -L "${f}" ]]; then
readlink "${f}"
else
echo "$(pwd -P)/${f}"
fi
fi
)
}
# This emulates "readlink -f" which is not available on MacOS X.
# Test:
# T=/tmp/$$.$RANDOM
# mkdir $T
# touch $T/file
# mkdir $T/dir
# ln -s $T/file $T/linkfile
# ln -s $T/dir $T/linkdir
# function testone() {
# X=$(readlink -f $1 2>&1)
# Y=$(kube::readlinkdashf $1 2>&1)
# if [ "$X" != "$Y" ]; then
# echo readlinkdashf $1: expected "$X", got "$Y"
# fi
# }
# testone /
# testone /tmp
# testone $T
# testone $T/file
# testone $T/dir
# testone $T/linkfile
# testone $T/linkdir
# testone $T/nonexistant
# testone $T/linkdir/file
# testone $T/linkdir/dir
# testone $T/linkdir/linkfile
# testone $T/linkdir/linkdir
function openim::readlinkdashf {
# run in a subshell for simpler 'cd'
(
if [[ -d "${1}" ]]; then # This also catch symlinks to dirs.
cd "${1}"
pwd -P
else
cd "$(dirname "${1}")"
local f
f=$(basename "${1}")
if [[ -L "${f}" ]]; then
readlink "${f}"
else
echo "$(pwd -P)/${f}"
fi
fi
)
}
# This emulates "realpath" which is not available on MacOS X
# Test:
# T=/tmp/$$.$RANDOM
# mkdir $T
# touch $T/file
# mkdir $T/dir
# ln -s $T/file $T/linkfile
# ln -s $T/dir $T/linkdir
# function testone() {
# X=$(realpath $1 2>&1)
# Y=$(kube::realpath $1 2>&1)
# if [ "$X" != "$Y" ]; then
# echo realpath $1: expected "$X", got "$Y"
# fi
# }
# testone /
# testone /tmp
# testone $T
# testone $T/file
# testone $T/dir
# testone $T/linkfile
# testone $T/linkdir
# testone $T/nonexistant
# testone $T/linkdir/file
# testone $T/linkdir/dir
# testone $T/linkdir/linkfile
# testone $T/linkdir/linkdir
openim::realpath() {
if [[ ! -e "${1}" ]]; then
echo "${1}: No such file or directory" >&2
return 1
fi
openim::readlinkdashf "${1}"
}
# Marker function to indicate init.sh has been fully sourced
openim::init::loaded() {
return 0
}
+67 -15
View File
@@ -13,10 +13,39 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Controls verbosity of the script output and logging.
OPENIM_VERBOSE="${OPENIM_VERBOSE:-5}"
# Enable logging by default. Set to false to disable.
ENABLE_LOGGING=true
# If OPENIM_OUTPUT is not set, set it to the default value
if [[ ! -v OPENIM_OUTPUT ]]; then
OPENIM_OUTPUT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../_output" && pwd -P)"
fi
# Set the log file path
LOG_FILE="${OPENIM_OUTPUT}/logs/openim_$(date '+%Y%m%d').log"
if [[ ! -d "${OPENIM_OUTPUT}/logs" ]]; then
mkdir -p "${OPENIM_OUTPUT}/logs"
touch "$LOG_FILE"
fi
# Define the logging function
function echo_log() {
if $ENABLE_LOGGING; then
echo -e "$@" | tee -a "${LOG_FILE}"
else
echo -e "$@"
fi
}
# MAX_LOG_SIZE=10485760 # 10MB
# Clear logs from 5 days ago
# find $OPENIM_OUTPUT_LOGS -type f -name "*.log" -mtime +5 -exec rm -f {} \;
# Handler for when we exit automatically on an error.
# Borrowed from https://gist.github.com/ahendrix/7030300
openim::log::errexit() {
@@ -58,7 +87,7 @@ openim::log::stack() {
local stack_skip=${1:-0}
stack_skip=$((stack_skip + 1))
if [[ ${#FUNCNAME[@]} -gt ${stack_skip} ]]; then
echo "Call stack:" >&2
echo_log "Call stack:" >&2
local i
for ((i=1 ; i <= ${#FUNCNAME[@]} - stack_skip ; i++))
do
@@ -66,7 +95,7 @@ openim::log::stack() {
local source_file=${BASH_SOURCE[${frame_no}]}
local source_lineno=${BASH_LINENO[$((frame_no - 1))]}
local funcname=${FUNCNAME[${frame_no}]}
echo " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
echo_log " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
done
fi
}
@@ -85,14 +114,14 @@ openim::log::error_exit() {
if [[ ${OPENIM_VERBOSE} -ge 4 ]]; then
local source_file=${BASH_SOURCE[${stack_skip}]}
local source_line=${BASH_LINENO[$((stack_skip - 1))]}
echo "!!! Error in ${source_file}:${source_line}" >&2
echo_log -e "${COLOR_RED}!!! Error in ${source_file}:${source_line} ${COLOR_SUFFIX}" >&2
[[ -z ${1-} ]] || {
echo " ${1}" >&2
echo_log " ${1}" >&2
}
openim::log::stack ${stack_skip}
echo "Exiting with status ${code}" >&2
echo_log "Exiting with status ${code}" >&2
fi
exit "${code}"
@@ -101,21 +130,21 @@ openim::log::error_exit() {
# Log an error but keep going. Don't dump the stack or exit.
openim::log::error() {
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "!!! ${timestamp} ${1-}" >&2
echo_log "!!! ${timestamp} ${1-}" >&2
shift
for message; do
echo " ${message}" >&2
echo_log " ${message}" >&2
done
}
# Print an usage message to stderr. The arguments are printed directly.
openim::log::usage() {
echo >&2
echo_log >&2
local message
for message; do
echo "${message}" >&2
echo_log "${message}" >&2
done
echo >&2
echo_log >&2
}
openim::log::usage_from_stdin() {
@@ -135,17 +164,18 @@ openim::log::info() {
fi
for message; do
echo "${message}"
echo_log "${message}"
done
}
# Just like openim::log::info, but no \n, so you can make a progress bar
openim::log::progress() {
for message; do
echo -e -n "${message}"
echo_log -e -n "${message}"
done
}
# Print out some info that isn't a top level status line
openim::log::info_from_stdin() {
local messages=()
while read -r line; do
@@ -163,9 +193,31 @@ openim::log::status() {
fi
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "+++ ${timestamp} ${1}"
echo_log "+++ ${timestamp} ${1}"
shift
for message; do
echo " ${message}"
echo_log " ${message}"
done
}
openim::log::success()
{
local V="${V:-0}"
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
return
fi
timestamp=$(date +"%m%d %H:%M:%S")
echo_log -e "${COLOR_GREEN}[success ${timestamp}] ${COLOR_SUFFIX}==> " "$@"
}
function openim::log::test_log() {
echo_log "test log"
openim::log::error "openim::log::error"
openim::log::info "openim::log::info"
openim::log::progress "openim::log::progress"
openim::log::status "openim::log::status"
openim::log::success "openim::log::success"
openim::log::error_exit "openim::log::error_exit"
}
# openim::log::test_log
+5 -9
View File
@@ -38,6 +38,7 @@ readonly RELEASE_IMAGES="${LOCAL_OUTPUT_ROOT}/release-images"
# OpenIM github account info
readonly OPENIM_GITHUB_ORG=OpenIMSDK
readonly OPENIM_GITHUB_REPO=Open-IM-Server
readonly CHAT_GITHUB_REPO=chat
readonly ARTIFACT=openim.tar.gz
readonly CHECKSUM=${ARTIFACT}.sha1sum
@@ -104,7 +105,7 @@ function openim::release::package_tarballs() {
mkdir -p "${RELEASE_TARS}"
openim::release::package_src_tarball &
openim::release::package_client_tarballs &
openim::release::package_iam_manifests_tarball &
openim::release::package_openim_manifests_tarball &
openim::release::package_server_tarballs &
openim::util::wait-for-jobs || { openim::log::error "previous tarball phase failed"; return 1; }
@@ -143,8 +144,8 @@ function openim::release::package_src_tarball() {
-path "${OPENIM_ROOT}"/.config\* -o \
-path "${OPENIM_ROOT}"/.chglog\* -o \
-path "${OPENIM_ROOT}"/.gitlint -o \
-path "${OPENIM_ROOT}"/.golangci.yml -o \
-path "${OPENIM_ROOT}"/.goreleaser.yml -o \
-path "${OPENIM_ROOT}"/scripts/golangci.yml -o \
-path "${OPENIM_ROOT}"/build/goreleaser.yaml -o \
-path "${OPENIM_ROOT}"/.note.md -o \
-path "${OPENIM_ROOT}"/.todo.md \
\) -prune \
@@ -395,7 +396,7 @@ EOF
}
# This will pack openim-system manifests files for distros such as COS.
function openim::release::package_iam_manifests_tarball() {
function openim::release::package_openim_manifests_tarball() {
openim::log::status "Building tarball: manifests"
local src_dir="${OPENIM_ROOT}/deployments"
@@ -456,11 +457,6 @@ EOF
cp -R "${OPENIM_ROOT}/scripts/release" "${release_stage}/"
cat <<EOF > "${release_stage}/release/get-openim-binaries.sh"
#!/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.
# This file download openim client and server binaries from tencent cos bucket.
os=linux arch=amd64 version=${OPENIM_GIT_VERSION} && wget https://${BUCKET}.cos.${REGION}.myqcloud.com/${COS_RELEASE_DIR}/\$version/{openim-client-\$os-\$arch.tar.gz,openim-server-\$os-\$arch.tar.gz}
+593 -42
View File
@@ -13,6 +13,74 @@
# 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
################################################################################
# TODO Debug: Just for testing, please comment out
# OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
# source "${OPENIM_ROOT}/scripts/lib/logging.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
@@ -64,7 +132,7 @@ openim::util::wait_for_url() {
return 1
}
# Example: openim::util::wait_for_success 120 5 "imctl get nodes|grep localhost"
# Example: openim::util::wait_for_success 120 5 "openimctl get nodes|grep localhost"
# arguments: wait time, sleep time, shell command
# returns 0 if the shell command get output, 1 otherwise.
openim::util::wait_for_success(){
@@ -122,7 +190,7 @@ openim::util::cleanup-temp-dir() {
# OPENIM_TEMP
openim::util::ensure-temp-dir() {
if [[ -z ${OPENIM_TEMP-} ]]; then
OPENIM_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t iamrnetes.XXXXXX)
OPENIM_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t openimrnetes.XXXXXX)
openim::util::trap_add openim::util::cleanup-temp-dir EXIT
fi
}
@@ -182,6 +250,272 @@ openim::util::host_arch() {
echo "${host_arch}"
}
# The `openim::util::check_ports` function analyzes the state of processes based on given ports.
# It accepts multiple ports as arguments and prints:
# 1. The state of the process (whether it's running or not).
# 2. The start time of the process if it's running.
# User:
# openim::util::check_ports 8080 8081 8082
# The function returns a status of 1 if any of the processes is not running.
openim::util::check_ports() {
# An array to collect ports of processes that are not running.
local not_started=()
# An array to collect information about processes that are running.
local started=()
openim::log::info "Checking ports: $*"
# Iterate over each given port.
for port in "$@"; do
# Use the `lsof` command to find process information related to the given port.
local info=$(lsof -i :$port -n -P | grep LISTEN || true)
# If there's no process information, it means the process associated with the port is not running.
if [[ -z $info ]]; then
not_started+=($port)
else
# If there's process information, extract relevant details:
# Process ID, Command Name, and Start Time.
local pid=$(echo $info | awk '{print $2}')
local command=$(echo $info | awk '{print $1}')
local start_time=$(ps -o lstart= -p $pid)
started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time")
fi
done
echo
# Print information about ports whose processes are not running.
if [[ ${#not_started[@]} -ne 0 ]]; then
openim::log::info "### Not started ports:"
for port in "${not_started[@]}"; do
openim::log::error "Port $port is not started."
done
fi
# Print information about ports whose processes are running.
if [[ ${#started[@]} -ne 0 ]]; then
echo
openim::log::info "### Started ports:"
for info in "${started[@]}"; do
openim::log::info "$info"
done
fi
# If any of the processes is not running, return a status of 1.
if [[ ${#not_started[@]} -ne 0 ]]; then
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
return 1
else
openim::log::success "started[@] processes are running."
return 0
fi
}
# openim::util::check_ports 10002 1004
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
# It accepts multiple process names as arguments and prints:
# 1. The state of the process (whether it's running or not).
# 2. The start time of the process if it's running.
# User:
# openim::util::check_process_names nginx mysql redis
# The function returns a status of 1 if any of the processes is not running.
openim::util::check_process_names() {
# Arrays to collect details of processes
local not_started=()
local started=()
openim::log::info "Checking processes: $*"
# Iterate over each given process name
for process_name in "$@"; do
# Use `pgrep` to find process IDs related to the given process name
local pids=($(pgrep -f $process_name))
# Check if any process IDs were found
if [[ ${#pids[@]} -eq 0 ]]; then
not_started+=($process_name)
else
# If there are PIDs, loop through each one
for pid in "${pids[@]}"; do
local command=$(ps -p $pid -o cmd=)
local start_time=$(ps -p $pid -o lstart=)
local port=$(ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2)
# Check if port information was found for the PID
if [[ -z $port ]]; then
port="N/A"
fi
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
done
fi
done
# Print information
if [[ ${#not_started[@]} -ne 0 ]]; then
openim::log::info "Not started processes:"
for process_name in "${not_started[@]}"; do
openim::log::error "Process $process_name is not started."
done
fi
if [[ ${#started[@]} -ne 0 ]]; then
echo
openim::log::info "Started processes:"
for info in "${started[@]}"; do
openim::log::info "$info"
done
fi
# Return status
if [[ ${#not_started[@]} -ne 0 ]]; then
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
return 1
else
openim::log::success "All processes are running."
return 0
fi
}
# openim::util::check_process_names docker-pr
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.
# It accepts multiple ports as arguments and performs the following:
# 1. Attempts to stop any services running on the specified ports.
# 2. Prints details of services successfully stopped and those that failed to stop.
# Usage:
# openim::util::stop_services_on_ports 8080 8081 8082
# The function returns a status of 1 if any service couldn't be stopped.
openim::util::stop_services_on_ports() {
# An array to collect ports of processes that couldn't be stopped.
local not_stopped=()
# An array to collect information about processes that were stopped.
local stopped=()
openim::log::info "Stopping services on ports: $*"
# Iterate over each given port.
for port in "$@"; do
# Use the `lsof` command to find process information related to the given port.
info=$(lsof -i :$port -n -P | grep LISTEN || true)
# If there's process information, it means the process associated with the port is running.
if [[ -n $info ]]; then
# Extract the Process ID.
while read -r line; do
local pid=$(echo $line | awk '{print $2}')
# Try to stop the service by killing its process.
if kill -TERM $pid; then
stopped+=($port)
else
not_stopped+=($port)
fi
done <<< "$info"
fi
done
# Print information about ports whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
openim::log::info "Ports that couldn't be stopped:"
for port in "${not_stopped[@]}"; do
openim::log::status "Failed to stop service on port $port."
done
fi
# Print information about ports whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
openim::log::info "Stopped services on ports:"
for port in "${stopped[@]}"; do
openim::log::info "Successfully stopped service on port $port."
done
fi
# If any of the processes couldn't be stopped, return a status of 1.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
return 1
else
openim::log::success "All specified services were stopped."
return 0
fi
}
# nc -l -p 12345
# nc -l -p 123456
# ps -ef | grep "nc -l"
# openim::util::stop_services_on_ports 1234 12345
# The `openim::util::stop_services_with_name` function stops services with specified names.
# It accepts multiple service names as arguments and performs the following:
# 1. Attempts to stop any services with the specified names.
# 2. Prints details of services successfully stopped and those that failed to stop.
# Usage:
# openim::util::stop_services_with_name nginx apache
# The function returns a status of 1 if any service couldn't be stopped.
openim::util::stop_services_with_name() {
# An array to collect names of processes that couldn't be stopped.
local not_stopped=()
# An array to collect information about processes that were stopped.
local stopped=()
openim::log::info "Stopping services with names: $*"
# Iterate over each given service name.
for server_name in "$@"; do
# Use the `pgrep` command to find process IDs related to the given service name.
local pids=$(pgrep -f "$server_name")
# If no process was found with the name, add it to the not_stopped list
if [[ -z $pids ]]; then
not_stopped+=("$server_name")
continue
fi
local stopped_this_time=false
for pid in $pids; do
# Exclude the PID of the current script
if [[ "$pid" == "$$" ]]; then
continue
fi
# If there's a Process ID, it means the service with the name is running.
if [[ -n $pid ]]; then
# Try to stop the service by killing its process.
if kill -TERM $pid 2>/dev/null; then
stopped_this_time=true
fi
fi
done
if $stopped_this_time; then
stopped+=("$server_name")
else
not_stopped+=("$server_name")
fi
done
# Print information about services whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
openim::log::info "Services that couldn't be stopped:"
for name in "${not_stopped[@]}"; do
openim::log::status "Failed to stop the $name service."
done
fi
# Print information about services whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
openim::log::info "Stopped services:"
for name in "${stopped[@]}"; do
openim::log::info "Successfully stopped the $name service."
done
fi
openim::log::success "All specified services were stopped."
}
# sleep 333333&
# sleep 444444&
# ps -ef | grep "sleep"
# openim::util::stop_services_with_name "sleep 333333" "sleep 444444"
# This figures out the host platform without relying on golang. We need this as
# we don't want a golang install to be a prerequisite to building yet we need
# this info to figure out where the final binaries are placed.
@@ -213,14 +547,14 @@ openim::util::find-binary() {
openim::util::find-binary-for-platform "$1" "$(openim::util::host_platform)"
}
# Run all known doc generators (today gendocs and genman for imctl)
# Run all known doc generators (today gendocs and genman for openimctl)
# $1 is the directory to put those generated documents
openim::util::gen-docs() {
local dest="$1"
# Find binary
gendocs=$(openim::util::find-binary "gendocs")
geniamdocs=$(openim::util::find-binary "geniamdocs")
genopenimdocs=$(openim::util::find-binary "genopenimdocs")
genman=$(openim::util::find-binary "genman")
genyaml=$(openim::util::find-binary "genyaml")
genfeddocs=$(openim::util::find-binary "genfeddocs")
@@ -229,24 +563,24 @@ openim::util::gen-docs() {
# least from k/k tree), remove it completely.
openim::util::sourced_variable "${genfeddocs}"
mkdir -p "${dest}/docs/guide/en-US/cmd/imctl/"
"${gendocs}" "${dest}/docs/guide/en-US/cmd/imctl/"
mkdir -p "${dest}/docs/guide/en-US/cmd/openimctl/"
"${gendocs}" "${dest}/docs/guide/en-US/cmd/openimctl/"
mkdir -p "${dest}/docs/guide/en-US/cmd/"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-api"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-cmdutils"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-crontask"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-msggateway"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-msgtransfer"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-push"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-auth"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-conversation"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-friend"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-group"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-msg"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-third"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-user"
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/imctl" "imctl"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-api"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-cmdutils"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-crontask"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-msggateway"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-msgtransfer"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-push"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-auth"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-conversation"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-friend"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-group"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-msg"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-third"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-user"
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/openimctl" "openimctl"
mkdir -p "${dest}/docs/man/man1/"
"${genman}" "${dest}/docs/man/man1/" "openim-api"
@@ -263,8 +597,8 @@ openim::util::gen-docs() {
"${genman}" "${dest}/docs/man/man1/" "openim-rpc-third"
"${genman}" "${dest}/docs/man/man1/" "openim-rpc-user"
mkdir -p "${dest}/docs/guide/en-US/yaml/imctl/"
"${genyaml}" "${dest}/docs/guide/en-US/yaml/imct/"
mkdir -p "${dest}/docs/guide/en-US/yaml/openimctl/"
"${genyaml}" "${dest}/docs/guide/en-US/yaml/openimctl/"
# create the list of generated files
pushd "${dest}" > /dev/null || return 1
@@ -290,7 +624,7 @@ openim::util::remove-gen-docs() {
# repo, e.g. "upstream" or "origin".
openim::util::git_upstream_remote_name() {
git remote -v | grep fetch |\
grep -E 'github.com[/:]marmotedu/openim|marmotedu.io/openim' |\
grep -E 'github.com[/:]OpenIMSDK/Open-IM-Server|openim.cc/server' |\
head -n 1 | awk '{print $1}'
}
@@ -455,8 +789,8 @@ function openim::util::create_serving_certkey {
EOF
}
# creates a self-contained iamconfig: args are sudo, dest-dir, ca file, host, port, client id, token(optional)
function openim::util::write_client_iamconfig {
# creates a self-contained openimconfig: args are sudo, dest-dir, ca file, host, port, client id, token(optional)
function openim::util::write_client_openimconfig {
local sudo=$1
local dest_dir=$2
local ca_file=$3
@@ -464,7 +798,7 @@ function openim::util::write_client_iamconfig {
local api_port=$5
local client_id=$6
local token=${7:-}
cat <<EOF | ${sudo} tee "${dest_dir}"/"${client_id}".iamconfig > /dev/null
cat <<EOF | ${sudo} tee "${dest_dir}"/"${client_id}".openimconfig > /dev/null
apiVersion: v1
kind: Config
clusters:
@@ -486,12 +820,12 @@ contexts:
current-context: local-up-cluster
EOF
# flatten the iamconfig files to make them self contained
# flatten the openimconfig files to make them self contained
username=$(whoami)
${sudo} /usr/bin/env bash -e <<EOF
$(openim::util::find-binary imct) --iamconfig="${dest_dir}/${client_id}.iamconfig" config view --minify --flatten > "/tmp/${client_id}.iamconfig"
mv -f "/tmp/${client_id}.iamconfig" "${dest_dir}/${client_id}.iamconfig"
chown ${username} "${dest_dir}/${client_id}.iamconfig"
$(openim::util::find-binary openimctl) --openimconfig="${dest_dir}/${client_id}.openimconfig" config view --minify --flatten > "/tmp/${client_id}.openimconfig"
mv -f "/tmp/${client_id}.openimconfig" "${dest_dir}/${client_id}.openimconfig"
chown ${username} "${dest_dir}/${client_id}.openimconfig"
EOF
}
@@ -545,6 +879,29 @@ function openim::util::join {
echo "$*"
}
# Function: openim::util::list-to-string <list...>
# Description: Converts a list to a string, removing spaces, brackets, and commas.
# Example input: [1002 3 , 2 32 3 , 3 434 ,]
# Example output: 10023 2323 3434
# Example usage:
# result=$(openim::util::list-to-string "[10023, 2323, 3434]")
# echo $result
function openim::util::list-to-string() {
# Capture all arguments into a single string
ports_list="$*"
# Use sed for transformations:
# 1. Remove spaces
# 2. Replace commas with spaces
# 3. Remove opening and closing brackets
ports_array=$(echo "$ports_list" | sed 's/ //g; s/,/ /g; s/^\[\(.*\)\]$/\1/')
# For external use, we might want to echo the result so that it can be captured by callers
echo "$ports_array"
}
# MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string "10023, 2323, 34 34")
# echo ${MSG_GATEWAY_PROM_PORTS}
# Downloads cfssl/cfssljson/cfssl-certinfo into $1 directory if they do not already exist in PATH
#
# Assumed vars:
@@ -616,6 +973,47 @@ function openim::util::ensure-cfssl {
popd > /dev/null || return 1
}
function openim::util::ensure-docker-buildx {
# podman returns 0 on `docker buildx version`, docker on `docker buildx`. One of them must succeed.
if docker buildx version >/dev/null 2>&1 || docker buildx >/dev/null 2>&1; then
return 0
else
echo "ERROR: docker buildx not available. Docker 19.03 or higher is required with experimental features enabled"
exit 1
fi
}
# openim::util::ensure-bash-version
# Check if we are using a supported bash version
#
function openim::util::ensure-bash-version {
# shellcheck disable=SC2004
if ((${BASH_VERSINFO[0]}<4)) || ( ((${BASH_VERSINFO[0]}==4)) && ((${BASH_VERSINFO[1]}<2)) ); then
echo "ERROR: This script requires a minimum bash version of 4.2, but got version of ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}"
if [ "$(uname)" = 'Darwin' ]; then
echo "On macOS with homebrew 'brew install bash' is sufficient."
fi
exit 1
fi
}
# openim::util::ensure-install-nginx
# Check if nginx is installed
#
function openim::util::ensure-install-nginx {
if ! command -v nginx &>/dev/null; then
echo "ERROR: nginx not found. Please install nginx."
exit 1
fi
for port in 80
do
if echo |telnet 127.0.0.1 $port 2>&1|grep refused &>/dev/null;then
exit 1
fi
done
}
# openim::util::ensure-gnu-sed
# Determines which sed binary is gnu-sed on linux/darwin
#
@@ -624,7 +1022,7 @@ function openim::util::ensure-cfssl {
#
function openim::util::ensure-gnu-sed {
# NOTE: the echo below is a workaround to ensure sed is executed before the grep.
# see: https://github.com/iamrnetes/iamrnetes/issues/87251
# see: https://github.com/openimrnetes/openimrnetes/issues/87251
sed_help="$(LANG=C sed --help 2>&1 || true)"
if echo "${sed_help}" | grep -q "GNU\|BusyBox"; then
SED="sed"
@@ -637,6 +1035,26 @@ function openim::util::ensure-gnu-sed {
openim::util::sourced_variable "${SED}"
}
# openim::util::ensure-gnu-date
# Determines which date binary is gnu-date on linux/darwin
#
# Sets:
# DATE: The name of the gnu-date binary
#
function openim::util::ensure-gnu-date {
# NOTE: the echo below is a workaround to ensure date is executed before the grep.
date_help="$(LANG=C date --help 2>&1 || true)"
if echo "${date_help}" | grep -q "GNU\|BusyBox"; then
DATE="date"
elif command -v gdate &>/dev/null; then
DATE="gdate"
else
openim::log::error "Failed to find GNU date as date or gdate. If you are on Mac: brew install coreutils." >&2
return 1
fi
openim::util::sourced_variable "${DATE}"
}
# openim::util::check-file-in-alphabetical-order <file>
# Check that the file is in alphabetical order
#
@@ -710,22 +1128,155 @@ fi
# ex: ts=2 sw=2 et filetype=sh
function openim::util::desc() {
openim::util:run::maybe_first_prompt
rate=25
if [ -n "$DEMO_RUN_FAST" ]; then
rate=1000
fi
echo "$blue# $@$reset" | pv -qL $rate
openim::util:run::prompt
}
# input: [10023, 2323, 3434]
# output: 10023 2323 3434
function openim::util:run::prompt() {
echo -n "$yellow\$ $reset"
}
# Function function: Converts a list to a string, removing Spaces and parentheses
function list_to_string() {
ports_list=$* # 获取传入的参数列表
sub_s1=$(echo $ports_list | sed 's/ //g') # 去除空格
sub_s2=${sub_s1//,/ } # 将逗号替换为空格
sub_s3=${sub_s2#*[} # 去除左括号及其之前的内容
sub_s4=${sub_s3%]*} # 去除右括号及其之后的内容
ports_array=$sub_s4 # 将处理后的字符串赋值给变量 ports_array
started=""
function openim::util:run::maybe_first_prompt() {
if [ -z "$started" ]; then
openim::util:run::prompt
started=true
fi
}
# After a `run` this variable will hold the stdout of the command that was run.
# If the command was interactive, this will likely be garbage.
DEMO_RUN_STDOUT=""
function openim::util::run() {
openim::util:run::maybe_first_prompt
rate=25
if [ -n "$DEMO_RUN_FAST" ]; then
rate=1000
fi
echo "$green$1$reset" | pv -qL $rate
if [ -n "$DEMO_RUN_FAST" ]; then
sleep 0.5
fi
OFILE="$(mktemp -t $(basename $0).XXXXXX)"
if [ "$(uname)" == "Darwin" ]; then
script -q "$OFILE" $1
else
script -eq -c "$1" -f "$OFILE"
fi
r=$?
read -d '' -t "${timeout}" -n 10000 # clear stdin
openim::util:run::prompt
if [ -z "$DEMO_AUTO_RUN" ]; then
read -s
fi
DEMO_RUN_STDOUT="$(tail -n +2 $OFILE | sed 's/\r//g')"
return $r
}
function openim::util::run::relative() {
for arg; do
echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|"
done
}
# This function retrieves the IP address of the current server.
# It primarily uses the `curl` command to fetch the public IP address from ifconfig.me.
# If curl or the service is not available, it falls back
# to the internal IP address provided by the hostname command.
# TODO: If a delay is found, the delay needs to be addressed
function openim::util::get_server_ip() {
# Check if the 'curl' command is available
if command -v curl &> /dev/null; then
# Try to retrieve the public IP address using curl and ifconfig.me
IP=$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/"//g' | tr -d '\n')
# Check if IP retrieval was successful
if [[ -z "$IP" ]]; then
# If not, get the internal IP address
IP=$(ip addr show | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
fi
else
# If curl is not available, get the internal IP address
IP=$(ip addr show | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
fi
# Return the fetched IP address
echo "$IP"
}
function openim::util::onCtrlC() {
kill -9 "${do_sth_pid}" "${progress_pid}" "${countdown_pid}"
echo
echo 'Ctrl+C is captured'
exit 1
}
# Function Function: Remove Spaces in the string
function remove_space() {
function openim::util::remove_space() {
value=$* # 获取传入的参数
result=$(echo $value | sed 's/ //g') # 去除空格
}
function openim::util::gencpu() {
# Check the system type
system_type=$(uname)
if [[ "$system_type" == "Darwin" ]]; then
# macOS (using sysctl)
cpu_count=$(sysctl -n hw.ncpu)
elif [[ "$system_type" == "Linux" ]]; then
# Linux (using lscpu)
cpu_count=$(lscpu --parse | grep -E '^([^#].*,){3}[^#]' | sort -u | wc -l)
else
echo "Unsupported operating system: $system_type"
exit 1
fi
echo $cpu_count
}
function openim::util::gen_os_arch() {
# Get the current operating system and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
# Select the repository home directory based on the operating system and architecture
if [[ "$OS" == "darwin" ]]; then
if [[ "$ARCH" == "x86_64" ]]; then
REPO_DIR="darwin/amd64"
else
REPO_DIR="darwin/386"
fi
elif [[ "$OS" == "linux" ]]; then
if [[ "$ARCH" == "x86_64" ]]; then
REPO_DIR="linux/amd64"
elif [[ "$ARCH" == "arm64" ]]; then
REPO_DIR="linux/arm64"
elif [[ "$ARCH" == "mips64" ]]; then
REPO_DIR="linux/mips64"
elif [[ "$ARCH" == "mips64le" ]]; then
REPO_DIR="linux/mips64le"
elif [[ "$ARCH" == "ppc64le" ]]; then
REPO_DIR="linux/ppc64le"
elif [[ "$ARCH" == "s390x" ]]; then
REPO_DIR="linux/s390x"
else
REPO_DIR="linux/386"
fi
elif [[ "$OS" == "windows" ]]; then
if [[ "$ARCH" == "x86_64" ]]; then
REPO_DIR="windows/amd64"
else
REPO_DIR="windows/386"
fi
else
echo -e "${RED_PREFIX}Unsupported OS: $OS${COLOR_SUFFIX}"
exit 1
fi
}
-1
View File
@@ -12,7 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
# Version management helpers. These functions help to set, save and load the