200 lines
6.0 KiB
Bash
Executable File
200 lines
6.0 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
|
|
###############################################################################
|
|
# 变量 #
|
|
###############################################################################
|
|
|
|
# 将终端的输出重置为默认设置,并且不会换行(用于重置终端的字体颜色、背景色和文本样式等设置)
|
|
echo -e "\e[0m\c"
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
# 脚本在执行过程中遇到任何非零返回码的命令时立即退出
|
|
set -e
|
|
|
|
# 下载域
|
|
readonly DOWNLOAD_DOMAIN=https://gitea.whlug.cn/
|
|
# 下载保存路径
|
|
TMP_ROOT=/tmp/xunmi
|
|
|
|
# 读取系统架构和内核信息
|
|
readonly UNAME_M="$(uname -m)"
|
|
readonly UNAME_R="$(uname -r)"
|
|
WorldType="新世界"
|
|
|
|
# 加载系统信息
|
|
source /etc/os-release
|
|
readonly Release=$(echo "${ID}")
|
|
readonly ReleaseName=$(echo "${NAME}")
|
|
|
|
# 获取项目路径
|
|
ItemDir=$1
|
|
|
|
###############################################################################
|
|
# 终端配色 #
|
|
###############################################################################
|
|
|
|
# 颜色配置
|
|
readonly COLOUR_RESET='\e[0m'
|
|
readonly aCOLOUR=(
|
|
'\e[38;5;154m' # 0: 亮绿
|
|
'\e[1m' # 1: 白
|
|
'\e[90m' # 2: 灰
|
|
'\e[91m' # 3: 红
|
|
'\e[32m' # 4: 绿
|
|
'\e[33m' # 5: 黄
|
|
)
|
|
|
|
Show() {
|
|
if (($1 == 0)); then
|
|
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} 成功 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
|
elif (($1 == 1)); then
|
|
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]} 失败 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
|
exit 1
|
|
elif (($1 == 2)); then
|
|
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]} 信息 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
|
elif (($1 == 3)); then
|
|
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[5]} 通知 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
|
fi
|
|
}
|
|
|
|
# 灰色信息(处理一些无关紧要的信息, 调用后在没有清除颜色之前会一直使用灰色输出)
|
|
GreyStart() {
|
|
echo -e "${aCOLOUR[2]}\c"
|
|
}
|
|
|
|
# 清除颜色(一般和灰色信息连用)
|
|
ColorReset() {
|
|
echo -e "$COLOUR_RESET\c"
|
|
}
|
|
|
|
###############################################################################
|
|
# 函数/方法 #
|
|
###############################################################################
|
|
|
|
# 检查文件是否存在
|
|
exist_file() {
|
|
if [ -e "$1" ]; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# 识别架构
|
|
Check_Arch() {
|
|
case $UNAME_M in
|
|
# *x86_64*)
|
|
# TARGET_ARCH="amd64"
|
|
# ;;
|
|
*loongarch64*)
|
|
TARGET_ARCH="loong64"
|
|
;;
|
|
*)
|
|
Show 1 "此模块仅支持 loong64 架构处理器暂不支持 $UNAME_M 架构"
|
|
exit 1
|
|
;;
|
|
esac
|
|
Show 2 "检测到 $TARGET_ARCH 架构"
|
|
}
|
|
|
|
# 检查发行版和世界信息
|
|
Check_Distribution() {
|
|
sType=2
|
|
notice=""
|
|
case $Release in
|
|
*arch*) ;;
|
|
*Loongnix*);;
|
|
*openwrt*)
|
|
Show 1 "暂不支持openwrt"
|
|
exit 1
|
|
;;
|
|
*)
|
|
sType=3
|
|
notice="我们尚未在此发行版上进行测试,默认使用新世界文件替换"
|
|
;;
|
|
esac
|
|
if [[ $UNAME_R =~ ^4.19.0-.+ ]]; then
|
|
WorldType="旧世界"
|
|
fi
|
|
Show ${sType} "检测到 ${ReleaseName} 发行版系统, 根据内核版本推断属于 -> ${WorldType} <- 系统 "
|
|
|
|
if [[ ${sType} == 1 ]]; then
|
|
select yn in "Yes" "No"; do
|
|
case $yn in
|
|
[yY][eE][sS] | [yY])
|
|
Show 0 "检查已忽略"
|
|
break
|
|
;;
|
|
[nN][oO] | [nN])
|
|
Show 1 "已退出安装"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done < /dev/tty # < /dev/tty 用于从终端读取输入信息
|
|
fi
|
|
}
|
|
|
|
# 下载替换依赖
|
|
DownloadAndInstall() {
|
|
PACKAGES=(
|
|
"${DOWNLOAD_DOMAIN}public/JetBrains_jna/releases/download/1.0/libjnidispatch_${WorldType}.so"
|
|
"${DOWNLOAD_DOMAIN}public/JetBrains_pty4j/releases/download/1.0/libpty_${WorldType}.so"
|
|
|
|
"${DOWNLOAD_DOMAIN}public/JetBrains_fsnotifier/releases/download/1.0/fsnotifier_${WorldType}"
|
|
)
|
|
|
|
# 检测项目路径是否存在
|
|
exist_file $ItemDir/lib/jna/amd64 || Show 1 "未找到关键路径 '$ItemDir/lib/jna/amd64' 请使用最新版JetBrains"
|
|
|
|
rm -rf ${TMP_ROOT}
|
|
mkdir -p ${TMP_ROOT} || Show 1 "无法创建临时目录"
|
|
TmpDir=$(mktemp -d -p ${TMP_ROOT} || Show 1 "无法创建临时目录")
|
|
pushd "${TmpDir}"
|
|
|
|
for PACKAGE in "${PACKAGES[@]}"; do
|
|
Show 2 "下载 ${PACKAGE}..."
|
|
GreyStart
|
|
wget -t 3 -q --show-progress -c "${PACKAGE}" || Show 1 "无法下载程序包"
|
|
ColorReset
|
|
Show 0 "下载完成"
|
|
done
|
|
now=$(date +"%Y%m%d-%H%M%S")
|
|
exist_file $ItemDir/lib/jna/amd64 || Show 1 "未找到指定路径 $ItemDir"
|
|
|
|
Show 2 "开始文件替换"
|
|
GreyStart
|
|
mv -nv $ItemDir/lib/jna/amd64/libjnidispatch.so $ItemDir/lib/jna/amd64/libjnidispatch_x86_$now.so
|
|
cp -v $TmpDir/libjnidispatch_${WorldType}.so $ItemDir/lib/jna/amd64/libjnidispatch.so
|
|
mkdir -vp $ItemDir/lib/pty4j/linux/loongarch64
|
|
cp -v $TmpDir/libpty_${WorldType}.so $ItemDir/lib/pty4j/linux/loongarch64/libpty.so
|
|
cp -v $TmpDir/fsnotifier_${WorldType} ~/.config/JetBrains/fsnotifier
|
|
chmod -v 755 ~/.config/JetBrains/fsnotifier
|
|
echo "idea.filewatcher.executable.path=$(readlink -f ~/.config/JetBrains/fsnotifier)" >> $ItemDir/bin/idea.properties
|
|
ColorReset
|
|
Show 0 "文件替换完成"
|
|
}
|
|
|
|
###############################################################################
|
|
# 入口(main) #
|
|
###############################################################################
|
|
|
|
usage() {
|
|
cat <<-EOF
|
|
使用方法: "$0 <PATH>"
|
|
PATH: JetBrains软件解压路径
|
|
EOF
|
|
}
|
|
|
|
if [ $# -eq 0 ]; then
|
|
usage
|
|
Show 1 "该脚本需要至少一个参数!"
|
|
fi
|
|
|
|
# 检查架构
|
|
Check_Arch
|
|
# 检查发行版
|
|
Check_Distribution
|
|
# 下载替换依赖
|
|
DownloadAndInstall
|