feat: add all options

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
Xinwei Xiong(cubxxw-openim)
2023-08-21 21:17:30 +08:00
parent b02d65bf9a
commit 84c7cc1801
34 changed files with 259 additions and 1287 deletions
+88 -1
View File
@@ -25,4 +25,91 @@ source ${OPENIM_ROOT}/scripts/install/openim-rpc.sh
source ${OPENIM_ROOT}/scripts/install/openim-crontask.sh
source ${OPENIM_ROOT}/scripts/install/openim-api.sh
source ${OPENIM_ROOT}/scripts/install/test.sh
source ${OPENIM_ROOT}/scripts/install/man.sh
source ${OPENIM_ROOT}/scripts/install/man.sh
# Detailed help function
function show_help() {
echo "OpenIM Installer"
echo "Usage: $0 <command> [options]"
echo ""
echo "Commands:"
echo " -i, --install Install all OpenIM components."
echo " -u, --uninstall Remove all OpenIM components."
echo " -s, --status Check the current status of OpenIM components."
echo " -h, --help Show this help menu."
echo ""
echo "Example: "
echo " $0 -i Will install all OpenIM components."
echo " $0 --install Same as above."
}
function openim::install::install_openim()
{
openim::log::info "check openim dependency"
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
openim::msggateway::install || return 1
openim::msgtransfer::install || return 1
openim::push::install || return 1
openim::rpc::install || return 1
openim::crontask::install || return 1
openim::api::install || return 1
openim::log::success "openim install success"
}
function openim::uninstall::uninstall_openim()
{
openim::log::info "uninstall openim"
openim::msggateway::uninstall || return 1
openim::msgtransfer::uninstall || return 1
openim::push::uninstall || return 1
openim::rpc::uninstall || return 1
openim::crontask::uninstall || return 1
openim::api::uninstall || return 1
openim::log::success "openim uninstall success"
}
function openim::install::status()
{
openim::log::info "check openim status"
openim::msggateway::status || return 1
openim::msgtransfer::status || return 1
openim::push::status || return 1
openim::rpc::status || return 1
openim::crontask::status || return 1
openim::api::status || return 1
openim::log::success "openim status success"
}
# Argument parsing to call functions based on user input
while (( "$#" )); do
case "$1" in
-i|--install)
openim::install::install_openim
shift
;;
-u|--uninstall)
openim::uninstall::uninstall_openim
shift
;;
-s|--status)
openim::install::status
shift
;;
-h|--help|*)
show_help
exit 0
;;
esac
done
# If no arguments are provided, show help
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi
-83
View File
@@ -1,83 +0,0 @@
#!/usr/bin/env bash
# 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.
# The root of the build/dist directory
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
# 安装后打印必要的信息
function openim::mariadb::info() {
cat << EOF
MariaDB Login: mysql -h127.0.0.1 -u${MARIADB_ADMIN_USERNAME} -p'${MARIADB_ADMIN_PASSWORD}'
EOF
}
# 安装
function openim::mariadb::install()
{
# 1. 配置 MariaDB 10.5 apt 源
openim::common::sudo "apt-get install software-properties-common dirmngr apt-transport-https"
echo ${LINUX_PASSWORD} | sudo -S apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
# add /etc/apt/sources.list
echo ${LINUX_PASSWORD} | sudo -S add-apt-repository 'deb [arch=amd64,arm64,ppc64el,s390x] https://mirrors.aliyun.com/mariadb/repo/10.5/ubuntu focal main'
# 2. 安装 MariaDB 和 MariaDB 客户端
openim::common::sudo "apt update"
openim::common::sudo "apt -y install mariadb-server"
# 3. 启动 MariaDB,并设置开机启动
openim::common::sudo "systemctl enable mariadb"
openim::common::sudo "systemctl start mariadb"
# 4. 设置 root 初始密码
openim::common::sudo "mysqladmin -u${MARIADB_ADMIN_USERNAME} password ${MARIADB_ADMIN_PASSWORD}"
openim::mariadb::status || return 1
openim::mariadb::info
openim::log::info "install MariaDB successfully"
}
# 卸载
function openim::mariadb::uninstall()
{
set +o errexit
openim::common::sudo "systemctl stop mariadb"
openim::common::sudo "systemctl disable mariadb"
openim::common::sudo "apt-get -y remove mariadb-server"
openim::common::sudo "rm -rf /var/lib/mysql"
set -o errexit
openim::log::info "uninstall MariaDB successfully"
}
# 状态检查
function openim::mariadb::status()
{
# 查看 mariadb 运行状态,如果输出中包含 active (running) 字样说明 mariadb 成功启动。
systemctl status mariadb |grep -q 'active' || {
openim::log::error "mariadb failed to start, maybe not installed properly"
return 1
}
mysql -u${MARIADB_ADMIN_USERNAME} -p${MARIADB_ADMIN_PASSWORD} -e quit &>/dev/null || {
openim::log::error "can not login with root, mariadb maybe not initialized properly"
return 1
}
openim::log::info "MariaDB status active"
}
if [[ "$*" =~ openim::mariadb:: ]];then
eval $*
fi
+20 -1
View File
@@ -85,4 +85,23 @@ for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do
done
OPENIM_API_PORT_STRINGARIES=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[@]}) )
openim::util::check_ports ${OPENIM_API_PORT_STRINGARIES[@]}
openim::util::check_ports ${OPENIM_API_PORT_STRINGARIES[@]}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
function openim::api::install() {
}
function openim::api::uninstall() {
}
function openim::api::status() {
}
if [[ "$*" =~ ${SERVER_NAME}:: ]];then
eval $*
fi
+19
View File
@@ -126,3 +126,22 @@ done
openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]}
# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
function openim::rpc::install() {
}
function openim::rpc::uninstall() {
}
function openim::rpc::status() {
}
if [[ "$*" =~ ${SERVER_NAME}:: ]];then
eval $*
fi
-89
View File
@@ -1,89 +0,0 @@
#!/usr/bin/env bash
# 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.
# The root of the build/dist directory
IAM_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
[[ -z ${COMMON_SOURCED} ]] && source ${IAM_ROOT}/scripts/install/common.sh
# Print the necessary information after installation
function openim::redis::info() {
cat << EOF
Redis Login: redis-cli --no-auth-warning -h ${REDIS_HOST} -p ${REDIS_PORT} -a '${REDIS_PASSWORD}'
EOF
}
# 安装
function openim::redis::install()
{
# 1. 安装 Redis
openim::common::sudo "apt-get -y install redis-server"
# 2. 配置 Redis
# 2.1 修改 `/etc/redis/redis.conf` 文件,将 daemonize 由 no 改成 yes,表示允许 Redis 在后台启动
echo ${LINUX_PASSWORD} | sudo -S sed -i '/^daemonize/{s/no/yes/}' /etc/redis/redis.conf
# 2.2 在 `bind 127.0.0.1` 前面添加 `#` 将其注释掉,默认情况下只允许本地连接,注释掉后外网可以连接 Redis
echo ${LINUX_PASSWORD} | sudo -S sed -i '/^# bind 127.0.0.1/{s/# //}' /etc/redis/redis.conf
# 2.3 修改 requirepass 配置,设置 Redis 密码
echo ${LINUX_PASSWORD} | sudo -S sed -i 's/^# requirepass.*$/requirepass '"${REDIS_PASSWORD}"'/' /etc/redis/redis.conf
# 2.4 因为我们上面配置了密码登录,需要将 protected-mode 设置为 no,关闭保护模式
echo ${LINUX_PASSWORD} | sudo -S sed -i '/^protected-mode/{s/yes/no/}' /etc/redis/redis.conf
# 3. 为了能够远程连上 Redis,需要执行以下命令关闭防火墙,并禁止防火墙开机启动(如果不需要远程连接,可忽略此步骤)
openim::common::sudo "sudo ufw disable"
openim::common::sudo "sudo ufw status"
# 4. 启动 Redis
openim::common::sudo "redis-server /etc/redis/redis.conf"
openim::redis::status || return 1
openim::redis::info
openim::log::info "install Redis successfully"
}
# 卸载
function openim::redis::uninstall()
{
set +o errexit
openim::common::sudo "/etc/init.d/redis-server stop"
openim::common::sudo "apt-get -y remove redis-server"
openim::common::sudo "rm -rf /var/lib/redis"
set -o errexit
openim::log::info "uninstall Redis successfully"
}
# 状态检查
function openim::redis::status()
{
if [[ -z "`pgrep redis-server`" ]];then
openim::log::error_exit "Redis not running, maybe not installed properly"
return 1
fi
redis-cli --no-auth-warning -h ${REDIS_HOST} -p ${REDIS_PORT} -a "${REDIS_PASSWORD}" --hotkeys || {
openim::log::error "can not login with ${REDIS_USERNAME}, redis maybe not initialized properly"
return 1
}
openim::log::info "redis-server status active"
}
#eval $*
if [[ "$*" =~ openim::redis:: ]];then
eval $*
fi