1 Star 3 Fork 45

灰尘.../moba协议

forked from liyonghelpme/moba协议 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
yuanshen.sh 13.71 KB
一键复制 编辑 原始数据 按行查看 历史
灰尘... 提交于 2022-06-02 01:59 . update yuanshen.sh.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
export GrasscutterURL="https://github.com/Grasscutters/Grasscutter.git"
export ResourcesURL="https://gitlab.com/yukiz/GrasscutterResources.git"
export yuanshen_public_ip
export yuasnhen_game_port
export keystorePassword='123456'
TIME() {
[[ -z "$1" ]] && {
echo -ne " "
} || {
case $1 in
r) export Color="\e[31;1m" ;;
g) export Color="\e[32;1m" ;;
b) export Color="\e[34;1m" ;;
y) export Color="\e[33;1m" ;;
z) export Color="\e[35;1m" ;;
l) export Color="\e[36;1m" ;;
esac
[[ $# -lt 2 ]] && echo -e "\e[36m\e[0m ${1}" || {
echo -e "\e[36m\e[0m ${Color}${2}\e[0m"
}
}
}
INSTALL_Git_Tmux(){
echo
TIME g "是否安装wget git zsh tmux vim 回车键跳过"
read -r -p "输入? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
yum -y install wget git zsh tmux vim
TIME g "安装完成!"
;;
[nN][oO]|[nN])
return 1
;;
*)
echo "跳过安装"
return 1
;;
esac
}
INSTALL_JAVA(){
if command -v java &> /dev/null;then
java -version
echo
TIME g "检测到JAVA存在,是否强制安装?回车键跳过"
read -r -p "输入? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
;;
[nN][oO]|[nN])
return 1
;;
*)
echo "跳过安装"
return 1
;;
esac
fi
TIME r "开始安装java,请耐心等待执行完毕"
cd ~
if [ -f /root/OpenJDK17U-jdk_x64_linux_hotspot_17.0.3_7.tar.gz ] ; then
echo
TIME g "检测到安装包存在,是否重新下载? 回车键跳过"
read -r -p "输入? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
TIME r "安装包开始下载"
rm -f /root/OpenJDK17U-jdk_x64_linux_hotspot_17.0.3_7.tar.gz
wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/Adoptium/17/jdk/x64/linux/OpenJDK17U-jdk_x64_linux_hotspot_17.0.3_7.tar.gz
;;
[nN][oO]|[nN])
echo "跳过"
;;
*)
echo "跳过"
;;
esac
else
TIME r "安装包不存在,开始下载"
wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/Adoptium/17/jdk/x64/linux/OpenJDK17U-jdk_x64_linux_hotspot_17.0.3_7.tar.gz
fi
tar zxvf OpenJDK17U-jdk_x64_linux_hotspot_17.0.3_7.tar.gz
rm -rf /usr/local/java
mv jdk-17.0.3+7 /usr/local/java
# 检查原先是否已配置java环境变量
jdk1=$(grep -n "export JAVA_HOME=.*" /etc/profile | cut -f1 -d':')
if [ -n "$jdk1" ];then
echo "JAVA_HOME已配置,删除内容"
sed -i "${jdk1}d" /etc/profile
fi
jdk2=$(grep -n "export CLASSPATH=.*\$JAVA_HOME.*" /etc/profile | cut -f1 -d':')
if [ -n "$jdk2" ];then
echo "CLASSPATH路径已配置,删除内容"
sed -i "${jdk2}d" /etc/profile
fi
jdk3=$(grep -n "export PATH=.*\$JAVA_HOME.*" /etc/profile | cut -f1 -d':')
if [ -n "$jdk3" ];then
echo "PATH-JAVA路径已配置,删除内容"
sed -i "${jdk3}d" /etc/profile
fi
# 检查配置信息
TIME r "正在配置jdk环境"
sed -i '$a export JAVA_HOME=/usr/local/java' /etc/profile
sed -i '$a export PATH=$PATH:$JAVA_HOME/bin' /etc/profile
sed -i '$a export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' /etc/profile
TIME r "JAVA环境配置已完成.重新加载配置文件"
source /etc/profile
TIME r "配置版本信息如下:"
java -version
TIME g "安装java执行完成"
}
INSTALL_MongoDB(){
#检测mongodb是否成功安装
check_mongo=`ps -ef |grep "mongodb"`
if [ -z "${check_mongo}" ];then
TIME r "没有检测到MongoDB"
else
mongo -version
echo
TIME g "检测到MongoDB存在,是否强制安装?回车键跳过"
read -r -p "输入? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
;;
[nN][oO]|[nN])
return 1
;;
*)
echo "跳过安装"
return 1
;;
esac
fi
TIME r "开始安装MongoDB,请耐心等待执行完毕"
cd ~
if [ -f /root/mongodb-linux-x86_64-rhel70-5.0.8.tgz ]; then
echo
TIME g "检测到安装包存在,是否重新下载? 回车键跳过"
read -r -p "输入? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
TIME r "安装包开始下载"
rm -f /root/mongodb-linux-x86_64-rhel70-5.0.8.tgz
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.8.tgz
;;
[nN][oO]|[nN])
echo "跳过"
;;
*)
echo "跳过"
;;
esac
else
TIME r "安装包不存在,开始下载"
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.8.tgz
fi
tar zxvf mongodb-linux-x86_64-rhel70-5.0.8.tgz
rm -rf /usr/local/mongodb
mv mongodb-linux-x86_64-rhel70-5.0.8 /usr/local/mongodb
# 检查原先是否已配置MONGODB环境变量
mongo1=$(grep -n "export MONGODB_HOME=.*" /etc/profile | cut -f1 -d':')
if [ -n "$mongo1" ];then
echo "MONGODB_HOME已配置,删除内容"
sed -i "${mongo1}d" /etc/profile
fi
mongo2=$(grep -n "export PATH=$PATH:$MONGODB_HOME/bin" /etc/profile | cut -f1 -d':')
if [ -n "$mongo2" ];then
echo "export PATH路径已配置,删除内容"
sed -i "${mongo2}d" /etc/profile
fi
# 检查配置信息
TIME r "正在配置mongodb环境"
sed -i '$a export MONGODB_HOME=/usr/local/mongodb' /etc/profile
sed -i '$a export PATH=$PATH:$MONGODB_HOME/bin' /etc/profile
TIME r "mongodb环境配置已完成.重新加载配置文件"
source /etc/profile
TIME r "配置版本信息如下:"
mongo -version
TIME g "安装mongodb执行完成"
TIME r "创建配置文件及日志文件"
rm -rf /usr/local/mongodb/data
rm -rf /usr/local/mongodb/logs
cat /dev/null > /usr/local/mongodb/mongod.conf
mkdir -p /usr/local/mongodb/{data,logs}
touch /usr/local/mongodb/mongod.conf
echo "dbpath=/usr/local/mongodb/data">>/usr/local/mongodb/mongod.conf
echo "logpath=/usr/local/mongodb/logs/mongodb.log">>/usr/local/mongodb/mongod.conf
echo "logappend=true">>/usr/local/mongodb/mongod.conf
echo "port=27017">>/usr/local/mongodb/mongod.conf
echo "auth=false">>/usr/local/mongodb/mongod.conf
echo "fork=true" >>/usr/local/mongodb/mongod.conf
echo "bind_ip=127.0.0.1">>/usr/local/mongodb/mongod.conf
TIME r "mongodb服务自启动设置"
echo "/usr/local/mongodb/bin/mongod --dbpath=/data/db --fork --bind_ip=0.0.0.0 --port 27017 --logpath=/data/db/log --logappend --auth" >> /etc/rc.local
TIME g "配置完成,以后台方式启动数据库"
mongod -f /usr/local/mongodb/mongod.conf
TIME g "启动数据库完成"
}
INSTALL_Mojo(){
if [ -f /root/Grasscutter/plugins/mojoconsole.jar ]; then
echo
TIME g "检测到已经有mojo插件,删除成功"
rm -rf /root/Grasscutter/plugins/mojoconsole
rm -rf /root/Grasscutter/plugins/mojoconsole-plus
rm -f /root/Grasscutter/plugins/mojoconsole.jar
fi
if [ -d /root/Grasscutter/plugins ]; then
TIME r "找到plugins文件夹"
else
mkdir /root/Grasscutter/plugins
fi
cd /root/Grasscutter/plugins
TIME r "下载插件资源"
wget https://ghproxy.com/github.com/gc-mojoconsole/gc-mojoconsole-backend/releases/download/dev-1.2.0/mojoconsole.jar
TIME g "下载控制台成功"
wget https://ghproxy.com/github.com/gc-mojoconsole/gc-mojoconsole.github.io/releases/download/latest/zh-cn.zip
TIME g "下载前端成功"
unzip zh-cn.zip
rm -f zh-cn.zip
TIME r "移除压缩包文件"
TIME r "需启动游戏生成配置文件,待游戏启动后输入stop停止游戏服务端,继续执行安装脚本,按回车确定"
read input
SERVER_START
sed -i "s/false/true/" /root/Grasscutter/plugins/mojoconfig.json
TIME g "Mojo插件安装完成,游戏中使用 /mojo 调用"
}
INSTALL_SERVER(){
if [ -f /root/Grasscutter/*.jar ]; then
echo
TIME g "检测到已经有服务端JAR,是否重新下载编译?回车键跳过"
read -r -p "输入? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
;;
[nN][oO]|[nN])
return 1
;;
*)
echo "跳过安装"
return 1
;;
esac
fi
echo
TIME r "开始安装服务端"
echo
cd ~
TIME r "是否使用代理下载服务端文件"
echo
while :; do
read -p " [输入[ N/n ]不使用代理下载服务端文件,输入[ Y/y ]使用代理下载服务端文件]: " ANDK
case $ANDK in
[Yy])
GhproxyURL="https://ghproxy.com/"$GrasscutterURL
git clone -b development $GhproxyURL
break
;;
[Nn])
git clone -b development $GrasscutterURL
break
;;
*)
echo
TIME b "提示:请输入正确的选择!"
echo
;;
esac
done
TIME g "下载完成"
TIME r "开始编译"
cd Grasscutter
./gradlew jar
TIME g "服务端编译完成"
}
UPDATA_SERVER(){
cd ~
rm -rf /root/Grasscutter
INSTALL_SERVER
INSTALL_Resources
INSTALL_Config
}
UPDATA_Resources(){
cd ~
rm -rf /root/resources
INSTALL_Resources
}
INSTALL_Resources(){
if [ -d "/root/resources" ]; then
TIME g "资源文件存在 开始配置"
else
cd ~
TIME r "----下载服务端资源文件-------"
mkdir resources
cd resources
mkdir git && cd git
git clone -b 2.7 $ResourcesURL
TIME g "-----下载完成-------"
TIME r "正在配置资源文件,等待完成"
fi
if [ -d "/root/Grasscutter/resources" ]; then
rm -rf /root/Grasscutter/resources
fi
mkdir /root/Grasscutter/resources
cd /root/resources/git/GrasscutterResources/Resources
cp -r Subtitle ~/Grasscutter/resources
cp -r Readable ~/Grasscutter/resources
cp -r ExcelBinOutput ~/Grasscutter/resources
cp -r BinOutput ~/Grasscutter/resources
cp -r Scripts ~/Grasscutter/resources
cp -r TextMap ~/Grasscutter/resources
TIME g "服务端配置资源完成"
}
CER_TO_P12(){
cd ~
TIME y "---开始制作P12证书--- "
if [ -d "/root/certs" ]; then
rm -rf /root/certs
fi
mkdir certs
cd certs
TIME y "正在生成 CA 密钥和证书对... "
openssl req -x509 -nodes -days 25202 -newkey rsa:2048 -subj "/C=GB/ST=Essex/L=London/O=Grasscutters/OU=Grasscutters/CN=${yuanshen_public_ip}" -keyout CAkey.key -out CAcert.crt
TIME y "正在生成 SSL 密钥和证书对..."
openssl genpkey -out ssl.key -algorithm rsa
#创建一个conf文件以生成一个csr
cat > csr.conf <<EOF
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn
[ dn ]
C = GB
ST = Essex
L = London
O = Grasscutters
OU = Grasscutters
CN = $yuanshen_public_ip
[ req_ext ]
subjectAltName = @alt_names
[ alt_names ]
IP.1 = $yuanshen_public_ip
EOF
TIME y "使用 key 和 conf 创建 csr"
openssl req -new -key ssl.key -out ssl.csr -config csr.conf
TIME y "创建 conf 以完成证书的创建"
cat > cert.conf <<EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, keyAgreement, dataEncipherment
subjectAltName = @alt_names
[alt_names]
IP.1 = $yuanshen_public_ip
EOF
TIME y "创建 ssl 证书"
openssl x509 -req -in ssl.csr -CA CAcert.crt -CAkey CAkey.key -CAcreateserial -out ssl.crt -days 25202 -sha256 -extfile cert.conf
TIME y "从密钥和证书生成 keystore.p12..."
TIME y "证书密码: "$keystorePassword
openssl pkcs12 -export -out keystore.p12 -inkey ssl.key -in ssl.crt -certfile CAcert.crt -passout pass:$keystorePassword
#复制证书
TIME y "复制证书 "
cp -f /root/certs/keystore.p12 /root/Grasscutter/keystore.p12
sed -i "s/123456/$keystorePassword/g" /root/Grasscutter/config.json
TIME g "已将证书转换为p12格式并替换至服务端"
}
SERVER_START(){
cd ~/Grasscutter
TIME y "等待启动完成......"
java -jar *.jar
}
ONE_INSTALL(){
INSTALL_Git_Tmux
INSTALL_JAVA
INSTALL_MongoDB
INSTALL_SERVER
INSTALL_Resources
INSTALL_Config
}
INSTALL_Config(){
cd ~/Grasscutter
if [ -f /root/Grasscutter/config.json ]; then
rm -f /root/Grasscutter/config.json
TIME r "删除旧配置文件成功"
fi
ls
TIME r "---开始生成服务端配置文件----"
java -jar *.jar -handbook
TIME r "修改配置 外网地址如下:"
wget -qO - ifconfig.co
TIME r "输入上面显示的外网地址 ,回车"
read input
yuanshen_public_ip=$input
TIME r "请指定服务端口(upd端口) ,回车"
read input
yuasnhen_game_port=$input
sed -i "s/443,/$yuasnhen_game_port","/" /root/Grasscutter/config.json
sed -i "s/scripts/Scripts/g" /root/Grasscutter/config.json
sed -i "s/Scripts/scripts/" /root/Grasscutter/config.json
sed -i "s/127.0.0.1/$yuanshen_public_ip/g" /root/Grasscutter/config.json
#自动注册
sed -i "s/false/true/" /root/Grasscutter/config.json
#GM权限
#sed -i "s/[]/[*]/" /root/Grasscutter/config.json
sed -i '26c "defaultPermissions": [*],' config.json
#证书
CER_TO_P12
cd ~
TIME g "服务端全部配置成功,按回车键后会进入新的会话,重新运行脚本启动服务端"
read input
tmux new -s server
}
TIME g "--------------原神一键端安装脚本--------------------------------"
TIME r "
1.一键安装(安装最新版本)
2.启动游戏
3.进入游戏服务端运行界面
4.更新游戏服务端
5.更新服务端资源文件
6.安装JAVA
7.安装MongoDB
8.重新生成配置文件(生成P12证书)
9.安装Mojo插件
"
TIME g "--------------------------------------------------------------"
TIME r " "
while :; do
read -p " [输入数字]: " ANDK
case $ANDK in
[1])
ONE_INSTALL
break
;;
[2])
SERVER_START
break
;;
[3])
tmux new -s server
tmux attach -t server
break
;;
[4])
UPDATA_SERVER
break
;;
[5])
UPDATA_Resources
break
;;
[6])
INSTALL_JAVA
break
;;
[7])
INSTALL_MongoDB
break
;;
[8])
INSTALL_Config
break
;;
[9])
INSTALL_Mojo
break
;;
*)
break
;;
esac
done
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yeshengjun1990/mobaXieYi.git
git@gitee.com:yeshengjun1990/mobaXieYi.git
yeshengjun1990
mobaXieYi
moba协议
moba

搜索帮助