HM-SPMS/installer/installer_linux.sh

411 lines
11 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#判断是否管理员权限
if [ $(id -u) -ne 0 ]; then
echo "ERROR:当前用户没有管理员权限,非管理员请用 sudo ./installer_linux.sh 命令执行"
exit
fi
#variable
#当前的安装包运行目录
initfile=$(dirname "$(dirname "$(readlink -f "$0")")")
#安装目录
INSTALL_DIR="/opt/HMEnergy"
#debug or release
SETUP_DEBUG_RELEASE=debug
#安装平台 centos 、openeuler
OS_DEFINE=""
#nginx 定制系统配置目录 以及服务名称
NGINX_CONFIGDIR=""
NGINX_SERVICE_NAME=""
#polkit 权限规则处理
polkit_rule_path=""
custom_rule_file=""
#系统设置开机执行文件路径
custom_cmd_file=""
#加载宏定义,用来判断平台
if [ -f "/etc/profile.d/iscs6000.sh" ]; then
source /etc/profile.d/iscs6000.sh
fi
if [ -f "/etc/profile.d/iscs6000env.sh" ]; then
source /etc/profile.d/iscs6000env.sh
fi
if [ -f "/etc/profile.d/rqeh6000.sh" ]; then
source /etc/profile.d/rqeh6000.sh
fi
if [ -f "/etc/profile.d/rqeh6000env.sh" ]; then
source /etc/profile.d/rqeh6000env.sh
fi
#variable
#script_path="$(cd "$(dirname "$0")" && pwd)"
script_path="${INSTALL_DIR}/installer"
echo "INFO:当前脚本执行目录: $script_path"
if [ -n "$RQEH6000_OS" ]; then
OS_DEFINE=$RQEH6000_OS
echo "INFO:安装操作系统平台:" $RQEH6000_OS
fi
if [ -n "$ISCS6000_OS" ]; then
OS_DEFINE=$ISCS6000_OS
echo "INFO:安装操作系统平台:" $ISCS6000_OS
fi
if [ ! -n "$OS_DEFINE" ]; then
echo "ERROR:没有找到操作系统平台定义"
exit 1
fi
echo "INFO:安装目录为: ${INSTALL_DIR} "
#判断原来目录下有文件,则删除
if [ -d "$INSTALL_DIR" ]; then
echo "WARNING:安装目录 $INSTALL_DIR 不为空!"
# 询问用户是否删除这些文件
read -p "INFO:是否删除这些文件或者取消安装?注意:安装前需要保证原系统停止运行!(y/c): " answer
case $answer in
[Yy]* )
rm -rf $INSTALL_DIR
;;
[Cc]* )
echo "INFO:安装操作已取消。"
exit 1
;;
* )
echo "INFO:无效的输入,安装操作已取消。"
exit 1
;;
esac
fi
mkdir $INSTALL_DIR
cp -r $initfile/* $INSTALL_DIR
#开启配置数据库服务
if [ "kylin10d" = "$OS_DEFINE" ]; then
echo "INFO:kylin need to select db-service"
valid_input=false
while [ "$valid_input" = false ]; do
echo "请选择数据库服务名:"
echo "1) kingbase"
echo "2) mariadb"
read -p "请输入数字选择(默认: 1: " choice
case "$choice" in
1 | "") # 输入 1 或直接回车
DB_SERVICE_NAME="kingbase"
valid_input=true
;;
2)
DB_SERVICE_NAME="mariadb"
valid_input=true
;;
*)
echo "无效选择,请重新输入!"
;;
esac
done
echo "INFO: 选择的数据库服务为 ${DB_SERVICE_NAME}"
if [ "kingbase" = "$DB_SERVICE_NAME" ]; then
if sudo systemctl is-active --quiet "$DB_SERVICE_NAME"; then
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
else
chmod +x /opt/Kingbase/ES/V8/Scripts/root.sh
/opt/Kingbase/ES/V8/Scripts/root.sh
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
fi
fi
if [ "mariadb" = "$DB_SERVICE_NAME" ]; then
if sudo systemctl is-active --quiet "$DB_SERVICE_NAME"; then
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
else
systemctl enable mariadb.service
systemctl start mariadb.service
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
fi
fi
elif [ "oe2203" = "$OS_DEFINE" ] || [ "oe2203_aarch64" = "$OS_DEFINE" ]; then
echo "INFO:openEuler need to select db-service"
valid_input=false
while [ "$valid_input" = false ]; do
echo "请选择数据库服务名:"
echo "1) opengauss"
echo "2) mysqld"
read -p "请输入数字选择(默认: 1: " choice
case "$choice" in
1 | "") # 输入 1 或直接回车
DB_SERVICE_NAME="opengauss"
valid_input=true
;;
2)
DB_SERVICE_NAME="mysql"
valid_input=true
;;
*)
echo "无效选择,请重新输入!"
;;
esac
done
echo "INFO: 选择的数据库服务为 ${DB_SERVICE_NAME}"
if [ "mysql" = "$DB_SERVICE_NAME" ]; then
if sudo systemctl is-active --quiet "$DB_SERVICE_NAME"; then
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
else
systemctl enable mysqld.service
systemctl start mysqld.service
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
fi
fi
if [ "opengauss" = "$DB_SERVICE_NAME" ]; then
if sudo systemctl is-active --quiet "$DB_SERVICE_NAME"; then
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
else
chown -R ${SUDO_USER}:${SUDO_USER} /usr/local/opengauss
chown -R ${SUDO_USER}:${SUDO_USER} /var/lib/opengauss
echo "INFO:opengauss dir owner has changed "
sed -i "s/^User=.*/User=$SUDO_USER/" /usr/lib/systemd/system/opengauss.service
systemctl daemon-reload
systemctl restart opengauss.service
systemctl enable opengauss.service
check_service_path=${script_path}/checkOpengauss.sh
chmod +x ${check_service_path}
${check_service_path}
if [ $? -eq 0 ]; then
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
else
echo "INFO:${DB_SERVICE_NAME} 服务开启失败。"
fi
fi
fi
else
echo "INFO:数据库使用mariadb服务"
DB_SERVICE_NAME="mariadb"
if sudo systemctl is-active --quiet "$DB_SERVICE_NAME"; then
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
else
systemctl enable mariadb.service
systemctl start mariadb.service
echo "INFO:${DB_SERVICE_NAME} 服务已开启。"
fi
fi
#开启历史数据库服务
HISDB_SERVICE_NAME="influxdb"
if sudo systemctl is-active --quiet "$HISDB_SERVICE_NAME"; then
echo "INFO:${HISDB_SERVICE_NAME} 服务已开启。"
else
systemctl enable influxdb
systemctl start influxdb
echo "INFO:${HISDB_SERVICE_NAME} 服务已开启。"
fi
#nginx配置文件以及polkit规则文件
if [ "oe2203" = "$OS_DEFINE" ] || [ "kylin10d" = "$OS_DEFINE" ]; then
#nginx 配置文件
NGINX_CONFIGDIR="/etc/nginx/nginx.conf"
NGINX_SERVICE_NAME="nginx"
echo "INFO:nginx配置文件"$NGINX_CONFIGDIR "服务名称" $NGINX_SERVICE_NAME
#polkit-auth
polkit_rule_path="/etc/polkit-1/rules.d"
custom_rule_file="51-custom-authentication.rules" #注意数字排序别被规则覆盖
if [ "kylin10d" = "$OS_DEFINE" ]; then
polkit_rule_path="/etc/polkit-1/localauthority/50-local.d"
custom_rule_file="allow-program-kylin.pkla"
fi
echo "INFO:polkit配置文件"$polkit_rule_path "自定义文件名称" $custom_rule_file
custom_rule_file_path=${script_path}/${custom_rule_file}
cp ${custom_rule_file_path} ${polkit_rule_path}/
chmod 644 ${polkit_rule_path}/${custom_rule_file}
systemctl restart polkit.service
echo "INFO:规则文件已拷贝并且polkit服务已重启"
#auth
chown ${SUDO_USER}:${SUDO_USER} ${INSTALL_DIR}
echo "INFO: change auth to user- ${SUDO_USER} dir-${INSTALL_DIR}"
else
NGINX_CONFIGDIR="/etc/opt/rh/rh-nginx116/nginx/nginx.conf"
NGINX_SERVICE_NAME="rh-nginx116-nginx"
echo "INFO:nginx配置文件"$NGINX_CONFIGDIR "服务名称" $NGINX_SERVICE_NAME
fi
#开启Nginx服务
nginx_path="${INSTALL_DIR}/nginx/nginx.conf"
if [ -e "$nginx_path" ]; then
echo "copy nginx config"
cp "$nginx_path" "$NGINX_CONFIGDIR"
rm "$nginx_path"
else
echo "cannot find nginx config in ${INSTALL_DIR}"
fi
ln -s "$NGINX_CONFIGDIR" "$nginx_path"
chmod -R 775 "$nginx_path"
if [ -L "$nginx_path" ]; then
echo "nginx symbolic link create success!"
else
echo "nginx symbolic link create failure!"
fi
if sudo systemctl is-active --quiet "$NGINX_SERVICE_NAME"; then
echo "INFO:${NGINX_SERVICE_NAME} 服务已开启。"
else
systemctl enable ${NGINX_SERVICE_NAME}
systemctl start ${NGINX_SERVICE_NAME}
echo "INFO:${NGINX_SERVICE_NAME} 服务已开启。"
fi
if [ -d "$(dirname "$script_path")/product/${OS_DEFINE}_debug/" ]; then
SETUP_DEBUG_RELEASE=debug
else
SETUP_DEBUG_RELEASE=release
fi
echo "INFO:安装版本:" $SETUP_DEBUG_RELEASE
export BIN_DIR_VER=${OS_DEFINE}_${SETUP_DEBUG_RELEASE}
#进行配置数据库初始化操作
$(dirname "$script_path")/product/$BIN_DIR_VER/db_installer
echo "INFO:开始进行附文件权限"
sh_path="$(dirname "$script_path")/product/$BIN_DIR_VER/"
sh_files=$(find "$sh_path" -maxdepth 1 -type f -name "*.sh")
#sh_files=$(find "$script_path" -maxdepth 1 -type f -name "*.sh")
if [ -n "$sh_files" ]; then
echo "INFO:找到以下 .sh 文件:"
echo "$sh_files"
echo "INFO:为这些文件添加执行权限..."
for file in $sh_files; do
chmod +x "$file"
done
fi
app_name="HMEnergy"
exec_command="$(dirname "$script_path")/product/$BIN_DIR_VER/workBench"
# 创建.desktop文件
sudo -k
DESKTOP_DIR=/root/桌面
if [ -n "$SUDO_USER" ]; then
DESKTOP_DIR=/home/$SUDO_USER/桌面
fi
if [ ! -d "${DESKTOP_DIR}" ]; then
echo "ERROR:目录不存在:${DESKTOP_DIR}"
exit
fi
echo "INFO:start-创建快捷方式成功"
cat > ${DESKTOP_DIR}/$app_name.desktop <<EOL
[Desktop Entry]
Name=$app_name
Exec=$exec_command
Type=Application
Terminal=false
Icon=$(dirname "$script_path")/installer/rqeh6000.ico
StartupNotify=true
EOL
echo "INFO:end-创建EMS.desktop快捷方式成功"
#赋权限
#net Permission
echo 'net.ipv4.ping_group_range = 0 2147483647' > /etc/sysctl.d/z5-ping.conf
sysctl -p /etc/sysctl.d/z5-ping.conf
# 赋予.desktop文件执行权限
chmod u+x ${DESKTOP_DIR}/$app_name.desktop
if [ -n "$SUDO_USER" ]; then
chown $SUDO_USER ${DESKTOP_DIR}/$app_name.desktop
chown -R $SUDO_USER ${INSTALL_DIR}/*
fi
cp ${DESKTOP_DIR}/$app_name.desktop /usr/share/applications/
#net_keepalived config
config_keepalived_cmd="$(dirname "$script_path")/platform/$BIN_DIR_VER/net_keepalived"
KEEPALIVE_SERVICE_NAME="net_keepalived"
if sudo systemctl is-active --quiet "$KEEPALIVE_SERVICE_NAME"; then
systemctl stop net_keepalived
systemctl disable net_keepalived
fi
$config_keepalived_cmd -r
if [ $? -ne 0 ]; then
echo "WARNING: Command '$config_keepalived_cmd -r' failed."
fi
systemctl start net_keepalived
systemctl enable net_keepalived
if sudo systemctl is-active --quiet "$KEEPALIVE_SERVICE_NAME"; then
echo "INFO:${KEEPALIVE_SERVICE_NAME} 服务已开启。"
else
echo "INFO:${KEEPALIVE_SERVICE_NAME} 服务开启失败。"
fi
INFLUXD_PROGRAM_PATH=$(which influxd)
ln -sf "${INFLUXD_PROGRAM_PATH}" "${INSTALL_DIR}/product/$BIN_DIR_VER/"
if [ "oe2203" = "$OS_DEFINE" ]; then
# 设置core_pattern
echo '/corefiles/core-%e-%p-%s-%t' >/proc/sys/kernel/core_pattern
# 检查操作是否成功
if [ $? -eq 0 ]; then
echo "core_pattern has been set successfully."
else
echo "Failed to set core_pattern."
fi
fi
if [ "kylin10d" = "$OS_DEFINE" ]; then
profile_path="/etc/profile.d"
custom_cmd_file="customCmd.sh"
cp ${custom_cmd_file} ${profile_path}/
chmod +x ${profile_path}/${custom_cmd_file}
echo "**********************"
echo "由于更改了系统设置,需要重启电脑或者注销用户然后重新登录才能生效!!!!!"
echo "**********************"
fi
# 导入io
if [ "oe2203" = "$OS_DEFINE" ]; then
echo 85 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio85/direction
fi
echo "INFO安装成功$app_name"