Your commit message
This commit is contained in:
325
功能脚本/cloudreve_install.sh
Normal file
325
功能脚本/cloudreve_install.sh
Normal file
@@ -0,0 +1,325 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
NewVerion=""
|
||||
|
||||
CMD_INSTALL=""
|
||||
CMD_UPDATE=""
|
||||
CMD_REMOVE=""
|
||||
SOFTWARE_UPDATED=0
|
||||
LinuxReleaseVersion=""
|
||||
release=""
|
||||
|
||||
RED="31m" ## 姨妈红
|
||||
GREEN="32m" ## 水鸭青
|
||||
YELLOW="33m" ## 鸭屎黄
|
||||
PURPLE="35m" ## 基佬紫
|
||||
BLUE="36m" ## 天依蓝
|
||||
BlinkRed="31;5m" ##闪烁的红色
|
||||
BackRed="41m" ## 背景红色
|
||||
|
||||
######## 颜色函数方法很精妙 ############
|
||||
colorEcho() {
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>&2
|
||||
}
|
||||
|
||||
check_root() {
|
||||
if [[ $EUID != 0 ]]; then
|
||||
colorEcho ${RED} "当前非root账号(或没有root权限),无法继续操作,请更换root账号!"
|
||||
colorEcho ${YELLOW} "使用sudo -命令获取临时root权限(执行后可能会提示输入root密码)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 判断命令是否存在
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
####### 获取系统版本及64位或32位信息
|
||||
check_sys() {
|
||||
sys_bit=$(uname -m)
|
||||
case $sys_bit in
|
||||
i[36]86)
|
||||
os_bit="32"
|
||||
release="386"
|
||||
;;
|
||||
x86_64)
|
||||
os_bit="64"
|
||||
release="amd64"
|
||||
;;
|
||||
*armv6*)
|
||||
os_bit="arm"
|
||||
release="arm6"
|
||||
;;
|
||||
*armv7*)
|
||||
os_bit="arm"
|
||||
release="arm7"
|
||||
;;
|
||||
*aarch64* | *armv8*)
|
||||
os_bit="arm64"
|
||||
release="arm64"
|
||||
;;
|
||||
*)
|
||||
colorEcho ${RED} "
|
||||
哈哈……这个 辣鸡脚本 不支持你的系统。 (-_-) \n
|
||||
备注: 仅支持 Ubuntu 16+ / Debian 8+ / CentOS 7+ 系统
|
||||
" && exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
## 判定Linux的发行版本
|
||||
if [ -f /etc/redhat-release ]; then
|
||||
LinuxReleaseVersion="centos"
|
||||
elif cat /etc/issue | grep -Eqi "debian"; then
|
||||
LinuxReleaseVersion="debian"
|
||||
elif cat /etc/issue | grep -Eqi "ubuntu"; then
|
||||
LinuxReleaseVersion="ubuntu"
|
||||
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
|
||||
LinuxReleaseVersion="centos"
|
||||
elif cat /proc/version | grep -Eqi "debian"; then
|
||||
LinuxReleaseVersion="debian"
|
||||
elif cat /proc/version | grep -Eqi "ubuntu"; then
|
||||
LinuxReleaseVersion="ubuntu"
|
||||
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
|
||||
LinuxReleaseVersion="centos"
|
||||
else
|
||||
LinuxReleaseVersion=""
|
||||
fi
|
||||
|
||||
# 判断系统的包管理工具 apt, yum, or zypper
|
||||
getPackageManageTool() {
|
||||
if [[ -n $(command -v apt-get) ]]; then
|
||||
CMD_INSTALL="apt-get -y -qq install"
|
||||
CMD_UPDATE="apt-get -qq update"
|
||||
CMD_REMOVE="apt-get -y remove"
|
||||
elif [[ -n $(command -v yum) ]]; then
|
||||
CMD_INSTALL="yum -y -q install"
|
||||
CMD_UPDATE="yum -q makecache"
|
||||
CMD_REMOVE="yum -y remove"
|
||||
elif [[ -n $(command -v zypper) ]]; then
|
||||
CMD_INSTALL="zypper -y install"
|
||||
CMD_UPDATE="zypper ref"
|
||||
CMD_REMOVE="zypper -y remove"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# 检查系统包管理方式,更新包
|
||||
getPackageManageTool
|
||||
if [ $? -eq 1 ]; then
|
||||
colorEcho ${RED} "系统的包管理不是 APT or YUM, 请手动安装所需要的软件."
|
||||
return 1
|
||||
fi
|
||||
|
||||
### 更新程序引索
|
||||
if [ $SOFTWARE_UPDATED -eq 0 ]; then
|
||||
colorEcho ${BLUE} "正在更新软件包管理...可能花费较长时间…………"
|
||||
$CMD_UPDATE
|
||||
SOFTWARE_UPDATED=1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
## 安装所需要的程序,及依赖程序
|
||||
installDemandSoftwares() {
|
||||
for software in $@; do
|
||||
## 安装该软件
|
||||
if [[ -n $(command -v ${software}) ]]; then
|
||||
colorEcho ${GREEN} "${software}已经安装了...跳过..."
|
||||
echo ""
|
||||
else
|
||||
colorEcho ${BLUE} "正在安装 ${software}..."
|
||||
$CMD_INSTALL ${software}
|
||||
## 判断该软件是否安装成功
|
||||
if [ $? -ne 0 ]; then
|
||||
colorEcho ${RED} "安装 ${software} 失败。"
|
||||
colorEcho ${RED} "如果是重要软件,本脚本会自动终止!!"
|
||||
colorEcho ${PURPLE} "一般软件,本脚本会忽略错误并继续运行,请之后手动安装该程序。"
|
||||
return 1
|
||||
else
|
||||
colorEcho ${GREEN} "已经成功安装 ${software}"
|
||||
colorEcho ${GREEN} "-----------------------------------------------------------"
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
getNewVersion(){
|
||||
VersionURL="https://api.github.com/repos/cloudreve/Cloudreve/releases/latest"
|
||||
|
||||
NewVerion=$(curl -s "${VersionURL}" --connect-timeout 60 | grep -w 'tag_name' | cut -d '"' -f4)
|
||||
|
||||
if [ $? -ne 0 ] || [ ${NewVerion} == "" ]
|
||||
then
|
||||
colorEcho ${RED} "从GitHub获取 Cloudreve 的最新版本失败!! "
|
||||
colorEcho ${RED} "大概率是由于无法访问github.com, 请检查网络!!"
|
||||
return 3
|
||||
fi
|
||||
}
|
||||
|
||||
installCloudreve(){
|
||||
CloudreveFileName="cloudreve_${NewVerion}_linux_${release}.tar.gz"
|
||||
wget --no-check-certificate -v -N -T 10 https://github.com/cloudreve/Cloudreve/releases/download/${NewVerion}/${CloudreveFileName}
|
||||
|
||||
if [ -s ${CloudreveFileName} ] || [ "$?" -eq "0" ]
|
||||
then
|
||||
tar -zxvf ${CloudreveFileName}
|
||||
chmod +x ./cloudreve
|
||||
|
||||
if [ -d /home/cloudreve ]
|
||||
then
|
||||
mv ./cloudreve /home/cloudreve/
|
||||
else
|
||||
mkdir -p /home/cloudreve
|
||||
mv ./cloudreve /home/cloudreve/
|
||||
fi
|
||||
|
||||
if [ -s /home/cloudreve/cloudreve ]; then
|
||||
colorEcho ${GREEN} "cloudreve-${NewVerion} 已经安装完成!!!"
|
||||
colorEcho ${GREEN} "安装的目录为 /home/cloudreve/"
|
||||
echo ""
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
colorEcho ${BlinkRed} "cloudreve安装包下载失败!!!"
|
||||
colorEcho ${BlinkRed} "cloudreve安装包下载失败!!!"
|
||||
echo ""
|
||||
colorEcho ${RED} "请检查网络,并重新运行此脚本!!"
|
||||
return 3
|
||||
fi
|
||||
}
|
||||
|
||||
installNginx(){
|
||||
colorEcho ${BLUE} "开始通过 apt 或者 yum 的方式安装 nginx !!"
|
||||
installDemandSoftwares nginx
|
||||
|
||||
systemctl enable nginx
|
||||
systemctl start nginx
|
||||
|
||||
systemctl status nginx | grep -q "Active: active (running)"
|
||||
if [ "$?" -eq "0" ]; then
|
||||
colorEcho ${GREEN} "nginx 安装完成,并成功运行!!"
|
||||
else
|
||||
colorEcho ${BlinkRed} "Nginx 安装失败!!!"
|
||||
colorEcho ${Red} "请查看nginx安装失败的原因!!"
|
||||
systemctl status nginx
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
configNginx(){
|
||||
nginx_pre_fix="/etc/nginx/conf.d"
|
||||
|
||||
ServerName=$1
|
||||
|
||||
if [ ${ServerName} = "" ];then
|
||||
colorEcho ${BLUE} "您没有传递域名参数!! Cloudreve将使用ip+port的形式向外暴露!"
|
||||
else
|
||||
colorEcho ${BLUE} "开始配置Nginx反向代理的相关参数!"
|
||||
cat >>${nginx_pre_fix}/{ServerName} <<EOF
|
||||
server {
|
||||
listen 443 ssl;
|
||||
ssl_certificate /etc/ssl/cloudreve.example.com.crt;
|
||||
ssl_certificate_key /etc/ssl/cloudreve.example.com.key;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_session_cache shared:MozSSL:10m;
|
||||
ssl_session_tickets off;
|
||||
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
|
||||
ssl_prefer_server_ciphers off;
|
||||
|
||||
server_name cloudreve.example.com;
|
||||
|
||||
location / {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://127.0.0.1:5212;
|
||||
|
||||
# 如果您要使用本地存储策略,请将下一行注释符删除,并更改大小为理论最大文件尺寸
|
||||
client_max_body_size 20000m;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
sed -i "s/cloudreve.example.com/${ServerName}/g" ${nginx_pre_fix}/{ServerName}
|
||||
fi
|
||||
|
||||
colorEcho ${BLUE} "开始重启Nginx!!"
|
||||
nginx -t && nginx -s reload
|
||||
|
||||
if [ "$?" -eq "0" ]; then
|
||||
echo ""
|
||||
colorEcho ${GREEN} "Nginx 重启完成!!"
|
||||
fi
|
||||
}
|
||||
|
||||
cloudreveSystemD(){
|
||||
echo ""
|
||||
colorEcho ${BLUE} "开始配置cloudreve的守护进程服务!!"
|
||||
if [ -d /usr/lib/systemd/system/ ]
|
||||
then
|
||||
systemDPath="/usr/lib/systemd/system"
|
||||
else
|
||||
systemDPath="/lib/systemd/system"
|
||||
fi
|
||||
|
||||
cat >>${systemDPath}/cloudreve.service <<EOF
|
||||
[Unit]
|
||||
Description=Cloudreve
|
||||
Documentation=https://docs.cloudreve.org
|
||||
After=network.target
|
||||
Wants=network.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/home/cloudreve
|
||||
ExecStart=/home/cloudreve/cloudreve
|
||||
Restart=on-abnormal
|
||||
RestartSec=5s
|
||||
KillMode=mixed
|
||||
|
||||
StandardOutput=null
|
||||
StandardError=syslog
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl start cloudreve.service
|
||||
|
||||
systemctl status cloudreve.service | grep -q "Active: active (running)"
|
||||
|
||||
if [ "$?" -eq "0" ]; then
|
||||
echo ""
|
||||
colorEcho ${GREEN} "cloudreve已经成功运行!!"
|
||||
colorEcho ${GREEN} "请访问 curl localhost:5212 查看!!!"
|
||||
systemctl enable cloudreve.service
|
||||
else
|
||||
colorEcho ${BlinkRed} "cloudreve守护进程配置失败!!,请查看原因!"
|
||||
systemctl status cloudreve.servic -l
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
main(){
|
||||
check_sys
|
||||
check_root
|
||||
|
||||
getNewVersion || return $?
|
||||
|
||||
installCloudreve || return $?
|
||||
|
||||
installNginx
|
||||
|
||||
configNginx "pan.s1.107421.xyz"
|
||||
|
||||
cloudreveSystemD
|
||||
|
||||
}
|
||||
|
||||
main
|
||||
171
功能脚本/v2ray_4.32.1_install.sh
Normal file
171
功能脚本/v2ray_4.32.1_install.sh
Normal file
@@ -0,0 +1,171 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
v2ray_config_file="/usr/local/etc/v2ray/config.json"
|
||||
v2ray_tls_file="/usr/local/etc/v2ray/cert"
|
||||
|
||||
# 默认的uuid
|
||||
V2rayUUID=""
|
||||
DomainName=""
|
||||
|
||||
RED="31m" ## 姨妈红
|
||||
GREEN="32m" ## 水鸭青
|
||||
YELLOW="33m" ## 鸭屎黄
|
||||
PURPLE="35m" ## 基佬紫
|
||||
BLUE="36m" ## 天依蓝
|
||||
|
||||
######## 颜色函数方法很精妙 ############
|
||||
colorEcho() {
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>&2
|
||||
}
|
||||
|
||||
check_root() {
|
||||
if [[ $EUID != 0 ]]; then
|
||||
colorEcho ${RED} "当前非root账号(或没有root权限),无法继续操作,请更换root账号!"
|
||||
colorEcho ${YELLOW} "使用sudo -命令获取临时root权限(执行后可能会提示输入root密码)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
# 判断命令是否存在
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
downloadSoftwares(){
|
||||
colorEcho ${PURPLE} "---------------------------------------------------------------------------------"
|
||||
colorEcho ${BLUE} "开始下载安装V2ray所需要的所有软件…………"
|
||||
|
||||
command_exists curl wget
|
||||
if [[ $? -nq 0]]
|
||||
then
|
||||
colorEcho ${RED} "未检测到强依赖----------------------------------------------"
|
||||
colorEcho ${RED} "请确保您已经安装wget,curl, unzip等工具!!"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
colorEcho ${BLUE} "创建v2ray的安装目录 ./v2ray_install"
|
||||
pwd
|
||||
mkdir v2ray_install
|
||||
cd ./v2ray_install
|
||||
pwd
|
||||
echo ""
|
||||
|
||||
colorEcho ${BLUE} "正在下载v2ray的安装脚本…………"
|
||||
wget https://objectstorage.ap-seoul-1.oraclecloud.com/n/cnk8d6fazu16/b/seoul/o/v2ray-install.sh
|
||||
chmod +x v2ray-install.sh
|
||||
colorEcho ${GREEN} " 下载完成 "
|
||||
echo ""
|
||||
|
||||
colorEcho ${BLUE} "正在下载v2ray-linux-adm64-v4.32.1的安装包文件…………"
|
||||
wget https://objectstorage.ap-seoul-1.oraclecloud.com/n/cnk8d6fazu16/b/seoul/o/v2ray-linux-64_v4.32.1.zip
|
||||
colorEcho ${GREEN} " 下载完成 "
|
||||
echo ""
|
||||
|
||||
colorEcho ${BLUE} "正在下载envsubst-Linux-x86_64文件…………"
|
||||
wget https://objectstorage.ap-seoul-1.oraclecloud.com/n/cnk8d6fazu16/b/seoul/o/envsubst-Linux-x86_64 -O -o envsubst
|
||||
chmod + envsubst
|
||||
mv envsubst /usr/local/bin
|
||||
colorEcho ${GREEN} " 下载完成 "
|
||||
echo ""
|
||||
}
|
||||
|
||||
installV2ray(){
|
||||
colorEcho ${PURPLE} "---------------------------------------------------------------------------------"
|
||||
colorEcho ${BLUE} "开始下载安装V2ray所需要的所有软件…………"
|
||||
echo ""
|
||||
|
||||
colorEcho ${BLUE}"开始离线安装v2ray……"
|
||||
echo "
|
||||
" | ./v2ray-install.sh --local v2ray-linux-64_v4.32.1.zip
|
||||
|
||||
echo ""
|
||||
cd ..
|
||||
colorEcho ${GREEN} "v2ray v4.32.1已经安装成功!"
|
||||
echo ""
|
||||
colorEcho ${BLUE} "正在开启v2ray的服务程序……"
|
||||
systemctl start v2ray
|
||||
colorEcho ${GREEN} " 启动完成 "
|
||||
echo ""
|
||||
colorEcho ${BLUE} "正在设置v2ray的开机自启动……"
|
||||
systemctl enable v2ray
|
||||
colorEcho ${GREEN} " 设置开启自启动完成 "
|
||||
echo ""
|
||||
}
|
||||
|
||||
modifyV2rayConfig(){
|
||||
colorEcho ${PURPLE} "---------------------------------------------------------------------------------"
|
||||
colorEcho ${BLUE} "开始配置V2ray,默认采用Vless_Over_TCP+XTLS…………"
|
||||
colorEcho ${BLUE} "本脚本暂不负责证书生成,请手动将域名的证书文件上传至 /usr/local/etc/v2ray/cert目录下"
|
||||
colorEcho ${PURPLE} "---------------------------------------------------------------------------------"
|
||||
colorEcho ${BLUE} "证书文件命名规则: <DomainName>.pem <DomainName>.key"
|
||||
echo ""
|
||||
|
||||
echo ""
|
||||
mkdir -p ${v2ray_tls_file}
|
||||
|
||||
colorEcho ${RED} "-------请输入解析到此服务器的域名(前面不带"http://"或"https://")-------"
|
||||
colorEcho ${RED} "----------------------------------------------------------"
|
||||
read -r -p "输入域名地址:" DomainName
|
||||
echo ""
|
||||
colorEcho ${BLUE} "----------------------------------------------------------"
|
||||
colorEcho ${GREEN} "您输入的域名为:${DomainName}"
|
||||
|
||||
colorEcho ${GREEN} "----------------------------------------------------------"
|
||||
echo ""
|
||||
|
||||
while true
|
||||
do
|
||||
colorEcho ${RED} "请确保您已经将证书文件上传至 ${v2ray_tls_file} 目录下!!"
|
||||
read -r -p "请输入yes进行确认,脚本才可继续运行!!" input
|
||||
case $input in
|
||||
yes)
|
||||
colorEcho ${GREEN} "您已确认上传了证书文件! 开始检测……"
|
||||
echo ""
|
||||
if [[ -f ${v2ray_tls_file}/${DomainName}.pem && -f ${v2ray_tls_file}/${DomainName}.key]]
|
||||
then
|
||||
colorEcho ${GREEN} "检测到TLS域名的证书文件!"
|
||||
colorEcho ${GREEN} "----------------------------------------------------------"
|
||||
echo ""
|
||||
break
|
||||
else
|
||||
colorEcho ${RED} "你欺骗了善良的自己!! 没有检测到TLS域名的证书文件!"
|
||||
colorEcho ${RED} "请手动将域名的证书文件上传至 ${v2ray_tls_file} 目录下"
|
||||
colorEcho ${BLUE} "证书文件命名规则:${DomainName}.pem ${DomainName}.key"
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
echo ""
|
||||
colorEcho ${RED} "输入有误!!! 请输入 >> yes << 进行确认"
|
||||
colorEcho ${RED} "-----------------------------------------------------"
|
||||
echo ""
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
colorEcho ${BLUE} "开始配置v2ray的config文件…………"
|
||||
V2rayUUID=$(cat /proc/sys/kernel/random/uuid)
|
||||
echo ""
|
||||
colorEcho ${BLUE} "生成的UUID为: ${V2rayUUID}"
|
||||
colorEcho ${GREEN} "-----------------------------------------------------"
|
||||
|
||||
colorEcho ${BLUE} "正在下载v2ray的config文件…………"
|
||||
wget https://objectstorage.ap-seoul-1.oraclecloud.com/n/cnk8d6fazu16/b/seoul/o/v2ray_vless-xtls-tcp.json
|
||||
colorEcho ${GREEN} " 下载完成 "
|
||||
echo ""
|
||||
colorEcho ${BLUE} "正在生成v2ray的config文件…………"
|
||||
envsubst < v2ray_vless-xtls-tcp.json > ${v2ray_config_file}
|
||||
colorEcho ${GREEN} " 生成完成 "
|
||||
echo ""
|
||||
}
|
||||
|
||||
printV2rayInfo(){
|
||||
|
||||
}
|
||||
|
||||
main(){
|
||||
check_root
|
||||
downloadSoftwares
|
||||
installV2ray
|
||||
modifyV2rayConfig
|
||||
printV2rayInfo
|
||||
}
|
||||
49
功能脚本/v2ray_vless-xtls-tcp.json
Normal file
49
功能脚本/v2ray_vless-xtls-tcp.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"log":{
|
||||
"access": "/var/log/v2ray/access.log",
|
||||
"error": "/var/log/v2ray/error.log",
|
||||
"loglevel": "warning"
|
||||
},
|
||||
"inbounds": [
|
||||
{
|
||||
"port": 443,
|
||||
"protocol": "vless",
|
||||
"settings": {
|
||||
"clients": [
|
||||
{
|
||||
"id": "$V2rayUUID",
|
||||
"flow": "xtls-rprx-direct",
|
||||
"level": 0,
|
||||
"email": "woshinibaba@cc.cc"
|
||||
}
|
||||
],
|
||||
"decryption": "none",
|
||||
"fallbacks": [
|
||||
{
|
||||
"dest": "www.baidu.com:443"
|
||||
}
|
||||
]
|
||||
},
|
||||
"streamSettings": {
|
||||
"network": "tcp",
|
||||
"security": "xtls",
|
||||
"xtlsSettings": {
|
||||
"alpn": [
|
||||
"http/1.1"
|
||||
],
|
||||
"certificates": [
|
||||
{
|
||||
"certificateFile": "/usr/local/etc/v2ray/cert/$DomainName.pem",
|
||||
"keyFile": "/usr/local/etc/v2ray/cert/$DomainName.key"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"outbounds": [
|
||||
{
|
||||
"protocol": "freedom"
|
||||
}
|
||||
]
|
||||
}
|
||||
40
功能脚本/基础脚本/fontColor.sh
Normal file
40
功能脚本/基础脚本/fontColor.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
#######第一种方法(推荐使用 颜色函数)########
|
||||
|
||||
#########color code#############
|
||||
RED="31m" ## 姨妈红
|
||||
GREEN="32m" ## 水鸭青
|
||||
YELLOW="33m" ## 鸭屎黄
|
||||
BLUE="35m" ## 基佬紫
|
||||
BLUE="36m" ## 天依蓝
|
||||
|
||||
###############color echo func#################
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
###########第二种方法###############
|
||||
Red_font_prefix="\033[31m"
|
||||
Green_font_prefix="\033[32m"
|
||||
Yellow_font_prefix="\033[33m"
|
||||
Blue_font_prefix="\033[34m"
|
||||
|
||||
Green_background_prefix="\033[42;37m"
|
||||
Red_background_prefix="\033[41;37m"
|
||||
Font_color_suffix="\033[0m"
|
||||
main(){
|
||||
colorEcho ${RED} "这是红色的字体!"
|
||||
colorEcho ${GREEN} "这是绿色的字体!"
|
||||
colorEcho ${YELLOW} "这是黄色的字体!"
|
||||
colorEcho ${BLUE} "这是蓝色的字体!"
|
||||
echo "#######################下面是第二种方法!###############################"
|
||||
echo
|
||||
echo -e "${Red_font_prefix}这是红色的字体!${Font_color_suffix}"
|
||||
echo -e "${Green_font_prefix}这是绿色的字体!${Font_color_suffix}"
|
||||
echo -e "${Yellow_font_prefix}这是黄色的字体!${Font_color_suffix}"
|
||||
echo -e "${Blue_font_prefix}这是蓝色的字体!${Font_color_suffix}"
|
||||
}
|
||||
|
||||
main
|
||||
494
功能脚本/基础脚本/go.sh
Normal file
494
功能脚本/基础脚本/go.sh
Normal file
@@ -0,0 +1,494 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This file is accessible as https://install.direct/go.sh
|
||||
# Original source is located at github.com/v2ray/v2ray-core/release/install-release.sh
|
||||
|
||||
# If not specify, default meaning of return value:
|
||||
# 0: Success
|
||||
# 1: System error
|
||||
# 2: Application error
|
||||
# 3: Network error
|
||||
|
||||
# CLI arguments
|
||||
PROXY=''
|
||||
HELP=''
|
||||
FORCE=''
|
||||
CHECK=''
|
||||
REMOVE=''
|
||||
VERSION=''
|
||||
VSRC_ROOT='/tmp/v2ray'
|
||||
EXTRACT_ONLY=''
|
||||
LOCAL=''
|
||||
LOCAL_INSTALL=''
|
||||
DIST_SRC='jsdelivr'
|
||||
ERROR_IF_UPTODATE=''
|
||||
|
||||
CUR_VER=""
|
||||
NEW_VER=""
|
||||
VDIS=''
|
||||
ZIPFILE="/tmp/v2ray/v2ray.zip"
|
||||
V2RAY_RUNNING=0
|
||||
|
||||
CMD_INSTALL=""
|
||||
CMD_UPDATE=""
|
||||
SOFTWARE_UPDATED=0
|
||||
|
||||
SYSTEMCTL_CMD=$(command -v systemctl 2>/dev/null)
|
||||
SERVICE_CMD=$(command -v service 2>/dev/null)
|
||||
|
||||
#######color code########
|
||||
RED="31m" # Error message
|
||||
GREEN="32m" # Success message
|
||||
YELLOW="33m" # Warning message
|
||||
BLUE="36m" # Info message
|
||||
|
||||
|
||||
#########################
|
||||
while [[ $# > 0 ]]; do
|
||||
case "$1" in
|
||||
-p|--proxy)
|
||||
PROXY="-x ${2}"
|
||||
shift # past argument
|
||||
;;
|
||||
-h|--help)
|
||||
HELP="1"
|
||||
;;
|
||||
-f|--force)
|
||||
FORCE="1"
|
||||
;;
|
||||
-c|--check)
|
||||
CHECK="1"
|
||||
;;
|
||||
--remove)
|
||||
REMOVE="1"
|
||||
;;
|
||||
--version)
|
||||
VERSION="$2"
|
||||
shift
|
||||
;;
|
||||
--extract)
|
||||
VSRC_ROOT="$2"
|
||||
shift
|
||||
;;
|
||||
--extractonly)
|
||||
EXTRACT_ONLY="1"
|
||||
;;
|
||||
-l|--local)
|
||||
LOCAL="$2"
|
||||
LOCAL_INSTALL="1"
|
||||
shift
|
||||
;;
|
||||
--source)
|
||||
DIST_SRC="$2"
|
||||
shift
|
||||
;;
|
||||
--errifuptodate)
|
||||
ERROR_IF_UPTODATE="1"
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
|
||||
######## 颜色函数方法 #########
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
archAffix(){
|
||||
case "${1:-"$(uname -m)"}" in
|
||||
i686|i386)
|
||||
echo '32'
|
||||
;;
|
||||
x86_64|amd64)
|
||||
echo '64'
|
||||
;;
|
||||
*armv7*|armv6l)
|
||||
echo 'arm'
|
||||
;;
|
||||
*armv8*|aarch64)
|
||||
echo 'arm64'
|
||||
;;
|
||||
*mips64le*)
|
||||
echo 'mips64le'
|
||||
;;
|
||||
*mips64*)
|
||||
echo 'mips64'
|
||||
;;
|
||||
*mipsle*)
|
||||
echo 'mipsle'
|
||||
;;
|
||||
*mips*)
|
||||
echo 'mips'
|
||||
;;
|
||||
*s390x*)
|
||||
echo 's390x'
|
||||
;;
|
||||
ppc64le)
|
||||
echo 'ppc64le'
|
||||
;;
|
||||
ppc64)
|
||||
echo 'ppc64'
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
downloadV2Ray(){
|
||||
rm -rf /tmp/v2ray
|
||||
mkdir -p /tmp/v2ray
|
||||
if [[ "${DIST_SRC}" == "jsdelivr" ]]; then
|
||||
DOWNLOAD_LINK="https://cdn.jsdelivr.net/gh/v2ray/dist/v2ray-linux-${VDIS}.zip"
|
||||
else
|
||||
DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/download/${NEW_VER}/v2ray-linux-${VDIS}.zip"
|
||||
fi
|
||||
colorEcho ${BLUE} "Downloading V2Ray: ${DOWNLOAD_LINK}"
|
||||
curl ${PROXY} -L -H "Cache-Control: no-cache" -o ${ZIPFILE} ${DOWNLOAD_LINK}
|
||||
if [ $? != 0 ];then
|
||||
colorEcho ${RED} "Failed to download! Please check your network or try again."
|
||||
return 3
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
installSoftware(){
|
||||
|
||||
for software in $@
|
||||
do
|
||||
COMPONENT=$1
|
||||
if [[ -n `command -v $COMPONENT` ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
getPMT
|
||||
if [[ $? -eq 1 ]]; then
|
||||
colorEcho ${RED} "The system package manager tool isn't APT or YUM, please install ${COMPONENT} manually."
|
||||
return 1
|
||||
fi
|
||||
if [[ $SOFTWARE_UPDATED -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "Updating software repo"
|
||||
$CMD_UPDATE
|
||||
SOFTWARE_UPDATED=1
|
||||
fi
|
||||
|
||||
colorEcho ${BLUE} "Installing ${COMPONENT}"
|
||||
$CMD_INSTALL $COMPONENT
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to install ${COMPONENT}. Please install it manually."
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
done
|
||||
}
|
||||
|
||||
# return 1: not apt, yum, or zypper
|
||||
getPMT(){
|
||||
if [[ -n `command -v apt-get` ]];then
|
||||
CMD_INSTALL="apt-get -y -qq install"
|
||||
CMD_UPDATE="apt-get -qq update"
|
||||
elif [[ -n `command -v yum` ]]; then
|
||||
CMD_INSTALL="yum -y -q install"
|
||||
CMD_UPDATE="yum -q makecache"
|
||||
elif [[ -n `command -v zypper` ]]; then
|
||||
CMD_INSTALL="zypper -y install"
|
||||
CMD_UPDATE="zypper ref"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
extract(){
|
||||
colorEcho ${BLUE}"Extracting V2Ray package to /tmp/v2ray."
|
||||
mkdir -p /tmp/v2ray
|
||||
unzip $1 -d ${VSRC_ROOT}
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to extract V2Ray."
|
||||
return 2
|
||||
fi
|
||||
if [[ -d "/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}" ]]; then
|
||||
VSRC_ROOT="/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
normalizeVersion() {
|
||||
if [ -n "$1" ]; then
|
||||
case "$1" in
|
||||
v*)
|
||||
echo "$1"
|
||||
;;
|
||||
*)
|
||||
echo "v$1"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# 1: new V2Ray. 0: no. 2: not installed. 3: check failed. 4: don't check.
|
||||
getVersion(){
|
||||
if [[ -n "$VERSION" ]]; then
|
||||
NEW_VER="$(normalizeVersion "$VERSION")"
|
||||
return 4
|
||||
else
|
||||
VER="$(/usr/bin/v2ray/v2ray -version 2>/dev/null)"
|
||||
RETVAL=$?
|
||||
CUR_VER="$(normalizeVersion "$(echo "$VER" | head -n 1 | cut -d " " -f2)")"
|
||||
TAG_URL="https://api.github.com/repos/v2ray/v2ray-core/releases/latest"
|
||||
NEW_VER="$(normalizeVersion "$(curl ${PROXY} -s "${TAG_URL}" --connect-timeout 10 | grep 'tag_name' | cut -d\" -f26)")"
|
||||
|
||||
if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then
|
||||
colorEcho ${RED} "Failed to fetch release information. Please check your network or try again."
|
||||
return 3
|
||||
elif [[ $RETVAL -ne 0 ]];then
|
||||
return 2
|
||||
elif [[ $NEW_VER != $CUR_VER ]];then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
stopV2ray(){
|
||||
colorEcho ${BLUE} "Shutting down V2Ray service."
|
||||
if [[ -n "${SYSTEMCTL_CMD}" ]] || [[ -f "/lib/systemd/system/v2ray.service" ]] || [[ -f "/etc/systemd/system/v2ray.service" ]]; then
|
||||
${SYSTEMCTL_CMD} stop v2ray
|
||||
elif [[ -n "${SERVICE_CMD}" ]] || [[ -f "/etc/init.d/v2ray" ]]; then
|
||||
${SERVICE_CMD} v2ray stop
|
||||
fi
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${YELLOW} "Failed to shutdown V2Ray service."
|
||||
return 2
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
startV2ray(){
|
||||
if [ -n "${SYSTEMCTL_CMD}" ] && [[ -f "/lib/systemd/system/v2ray.service" || -f "/etc/systemd/system/v2ray.service" ]]; then
|
||||
${SYSTEMCTL_CMD} start v2ray
|
||||
elif [ -n "${SERVICE_CMD}" ] && [ -f "/etc/init.d/v2ray" ]; then
|
||||
${SERVICE_CMD} v2ray start
|
||||
fi
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${YELLOW} "Failed to start V2Ray service."
|
||||
return 2
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
copyFile() {
|
||||
NAME=$1
|
||||
ERROR=`cp "${VSRC_ROOT}/${NAME}" "/usr/bin/v2ray/${NAME}" 2>&1`
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${YELLOW} "${ERROR}"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
makeExecutable() {
|
||||
chmod +x "/usr/bin/v2ray/$1"
|
||||
}
|
||||
|
||||
installV2Ray(){
|
||||
# Install V2Ray binary to /usr/bin/v2ray
|
||||
mkdir -p /usr/bin/v2ray
|
||||
copyFile v2ray
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to copy V2Ray binary and resources."
|
||||
return 1
|
||||
fi
|
||||
makeExecutable v2ray
|
||||
copyFile v2ctl && makeExecutable v2ctl
|
||||
copyFile geoip.dat
|
||||
copyFile geosite.dat
|
||||
|
||||
# Install V2Ray server config to /etc/v2ray
|
||||
if [[ ! -f "/etc/v2ray/config.json" ]]; then
|
||||
mkdir -p /etc/v2ray
|
||||
mkdir -p /var/log/v2ray
|
||||
cp "${VSRC_ROOT}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${YELLOW} "Failed to create V2Ray configuration file. Please create it manually."
|
||||
return 1
|
||||
fi
|
||||
let PORT=$RANDOM+10000
|
||||
UUID=$(cat /proc/sys/kernel/random/uuid)
|
||||
|
||||
sed -i "s/10086/${PORT}/g" "/etc/v2ray/config.json"
|
||||
sed -i "s/23ad6b10-8d1a-40f7-8ad0-e3e35cd38297/${UUID}/g" "/etc/v2ray/config.json"
|
||||
|
||||
colorEcho ${BLUE} "PORT:${PORT}"
|
||||
colorEcho ${BLUE} "UUID:${UUID}"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
installInitScript(){
|
||||
if [[ -n "${SYSTEMCTL_CMD}" ]] && [[ ! -f "/etc/systemd/system/v2ray.service" && ! -f "/lib/systemd/system/v2ray.service" ]]; then
|
||||
cp "${VSRC_ROOT}/systemd/v2ray.service" "/etc/systemd/system/"
|
||||
systemctl daemon-reload
|
||||
systemctl enable v2ray.service
|
||||
elif [[ -n "${SERVICE_CMD}" ]] && [[ ! -f "/etc/init.d/v2ray" ]]; then
|
||||
installSoftware "daemon" || return $?
|
||||
cp "${VSRC_ROOT}/systemv/v2ray" "/etc/init.d/v2ray"
|
||||
chmod +x "/etc/init.d/v2ray"
|
||||
update-rc.d v2ray defaults
|
||||
fi
|
||||
}
|
||||
|
||||
Help(){
|
||||
cat - 1>& 2 << EOF
|
||||
./install-release.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
|
||||
-h, --help Show help
|
||||
-p, --proxy To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc
|
||||
-f, --force Force install
|
||||
--version Install a particular version, use --version v3.15
|
||||
-l, --local Install from a local file
|
||||
--remove Remove installed V2Ray
|
||||
-c, --check Check for update
|
||||
EOF
|
||||
}
|
||||
|
||||
remove(){
|
||||
if [[ -n "${SYSTEMCTL_CMD}" ]] && [[ -f "/etc/systemd/system/v2ray.service" ]];then
|
||||
if pgrep "v2ray" > /dev/null ; then
|
||||
stopV2ray
|
||||
fi
|
||||
systemctl disable v2ray.service
|
||||
rm -rf "/usr/bin/v2ray" "/etc/systemd/system/v2ray.service"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to remove V2Ray."
|
||||
return 0
|
||||
else
|
||||
colorEcho ${GREEN} "Removed V2Ray successfully."
|
||||
colorEcho ${BLUE} "If necessary, please remove configuration file and log file manually."
|
||||
return 0
|
||||
fi
|
||||
elif [[ -n "${SYSTEMCTL_CMD}" ]] && [[ -f "/lib/systemd/system/v2ray.service" ]];then
|
||||
if pgrep "v2ray" > /dev/null ; then
|
||||
stopV2ray
|
||||
fi
|
||||
systemctl disable v2ray.service
|
||||
rm -rf "/usr/bin/v2ray" "/lib/systemd/system/v2ray.service"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to remove V2Ray."
|
||||
return 0
|
||||
else
|
||||
colorEcho ${GREEN} "Removed V2Ray successfully."
|
||||
colorEcho ${BLUE} "If necessary, please remove configuration file and log file manually."
|
||||
return 0
|
||||
fi
|
||||
elif [[ -n "${SERVICE_CMD}" ]] && [[ -f "/etc/init.d/v2ray" ]]; then
|
||||
if pgrep "v2ray" > /dev/null ; then
|
||||
stopV2ray
|
||||
fi
|
||||
rm -rf "/usr/bin/v2ray" "/etc/init.d/v2ray"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to remove V2Ray."
|
||||
return 0
|
||||
else
|
||||
colorEcho ${GREEN} "Removed V2Ray successfully."
|
||||
colorEcho ${BLUE} "If necessary, please remove configuration file and log file manually."
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
colorEcho ${YELLOW} "V2Ray not found."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
checkUpdate(){
|
||||
echo "Checking for update."
|
||||
VERSION=""
|
||||
getVersion
|
||||
RETVAL="$?"
|
||||
if [[ $RETVAL -eq 1 ]]; then
|
||||
colorEcho ${BLUE} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)"
|
||||
elif [[ $RETVAL -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "No new version. Current version is ${NEW_VER}."
|
||||
elif [[ $RETVAL -eq 2 ]]; then
|
||||
colorEcho ${YELLOW} "No V2Ray installed."
|
||||
colorEcho ${BLUE} "The newest version for V2Ray is ${NEW_VER}."
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
main(){
|
||||
#helping information
|
||||
[[ "$HELP" == "1" ]] && Help && return
|
||||
[[ "$CHECK" == "1" ]] && checkUpdate && return
|
||||
[[ "$REMOVE" == "1" ]] && remove && return
|
||||
|
||||
local ARCH=$(uname -m)
|
||||
VDIS="$(archAffix)"
|
||||
|
||||
# extract local file
|
||||
if [[ $LOCAL_INSTALL -eq 1 ]]; then
|
||||
colorEcho ${YELLOW} "Installing V2Ray via local file. Please make sure the file is a valid V2Ray package, as we are not able to determine that."
|
||||
NEW_VER=local
|
||||
installSoftware unzip || return $?
|
||||
rm -rf /tmp/v2ray
|
||||
extract $LOCAL || return $?
|
||||
#FILEVDIS=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f4`
|
||||
#SYSTEM=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f3`
|
||||
#if [[ ${SYSTEM} != "linux" ]]; then
|
||||
# colorEcho ${RED} "The local V2Ray can not be installed in linux."
|
||||
# return 1
|
||||
#elif [[ ${FILEVDIS} != ${VDIS} ]]; then
|
||||
# colorEcho ${RED} "The local V2Ray can not be installed in ${ARCH} system."
|
||||
# return 1
|
||||
#else
|
||||
# NEW_VER=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f2`
|
||||
#fi
|
||||
else
|
||||
# download via network and extract
|
||||
installSoftware "curl" || return $?
|
||||
getVersion
|
||||
RETVAL="$?"
|
||||
if [[ $RETVAL == 0 ]] && [[ "$FORCE" != "1" ]]; then
|
||||
colorEcho ${BLUE} "Latest version ${CUR_VER} is already installed."
|
||||
if [ -n "${ERROR_IF_UPTODATE}" ]; then
|
||||
return 10
|
||||
fi
|
||||
return
|
||||
elif [[ $RETVAL == 3 ]]; then
|
||||
return 3
|
||||
else
|
||||
colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}"
|
||||
downloadV2Ray || return $?
|
||||
installSoftware unzip || return $?
|
||||
extract ${ZIPFILE} || return $?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${EXTRACT_ONLY}" ]; then
|
||||
colorEcho ${GREEN} "V2Ray extracted to ${VSRC_ROOT}, and exiting..."
|
||||
return 0
|
||||
fi
|
||||
|
||||
if pgrep "v2ray" > /dev/null ; then
|
||||
V2RAY_RUNNING=1
|
||||
stopV2ray
|
||||
fi
|
||||
installV2Ray || return $?
|
||||
installInitScript || return $?
|
||||
if [[ ${V2RAY_RUNNING} -eq 1 ]];then
|
||||
colorEcho ${BLUE} "Restarting V2Ray service."
|
||||
startV2ray
|
||||
fi
|
||||
colorEcho ${GREEN} "V2Ray ${NEW_VER} is installed."
|
||||
rm -rf /tmp/v2ray
|
||||
return 0
|
||||
}
|
||||
|
||||
main
|
||||
3
功能脚本/基础脚本/关闭防火墙.sh
Normal file
3
功能脚本/基础脚本/关闭防火墙.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
4
功能脚本/基础脚本/去掉注释.sh
Normal file
4
功能脚本/基础脚本/去掉注释.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
sed -i -r '/^[ ]*#/d;/^$/d' /etc/haproxy/haproxy.cfg #修改配置文件去掉注释,或者你可以直接复制我的代码
|
||||
|
||||
|
||||
sed -i -r '/^[ ]*#/d;/^$/d'#Port 22
|
||||
44
功能脚本/基础脚本/参数传递-提示确认.sh
Normal file
44
功能脚本/基础脚本/参数传递-提示确认.sh
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
## 确认提示(一次)
|
||||
# 这个示例代码将为确认提示一次,如果你给输入错误,程序会以状态1退出。
|
||||
# 这个例子将只接受Y或N或YES或NO(不区分大小写)。
|
||||
read -r -p "Are You Sure? [Y/n] " input
|
||||
|
||||
case $input in
|
||||
[yY][eE][sS]|[yY])
|
||||
echo "Yes"
|
||||
;;
|
||||
|
||||
[nN][oO]|[nN])
|
||||
echo "No"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Invalid input..."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
## 确认提示(循环确认)
|
||||
# 提示进行确认(输入正常退出,输入错误则需重新输入,知道输入正确才可以)
|
||||
while true
|
||||
do
|
||||
read -r -p "Are You Sure? [Y/n] " input
|
||||
|
||||
case $input in
|
||||
[yY][eE][sS]|[yY])
|
||||
echo "Yes"
|
||||
break
|
||||
;;
|
||||
|
||||
[nN][oO]|[nN])
|
||||
echo "No"
|
||||
break
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
27
功能脚本/基础脚本/参数传递.sh
Normal file
27
功能脚本/基础脚本/参数传递.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 输出参数索引
|
||||
echo "OPTIND starts at $OPTIND"
|
||||
# 接收参数
|
||||
while getopts ":pq:" optname
|
||||
do
|
||||
case "$optname" in
|
||||
"p")
|
||||
echo "Option $optname is specified"
|
||||
;;
|
||||
"q")
|
||||
echo "Option $optname has value $OPTARG"
|
||||
;;
|
||||
"?")
|
||||
echo "Unknown option $OPTARG"
|
||||
;;
|
||||
":")
|
||||
echo "No argument value for option $OPTARG"
|
||||
;;
|
||||
*)
|
||||
# Should not occur
|
||||
echo "Unknown error while processing options"
|
||||
;;
|
||||
esac
|
||||
echo "OPtIND now is $OPTIND"
|
||||
done
|
||||
67
功能脚本/基础脚本/安装单个软件.sh
Normal file
67
功能脚本/基础脚本/安装单个软件.sh
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
CMD_INSTALL=""
|
||||
CMD_UPDATE=""
|
||||
SOFTWARE_UPDATED=0
|
||||
|
||||
#########color code#############
|
||||
RED="31m" # Error message
|
||||
GREEN="32m" # Success message
|
||||
YELLOW="33m" # Warning message
|
||||
BLUE="36m" # Info message
|
||||
|
||||
###############color echo func#################
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
# 判断系统的包管理工具 apt, yum, or zypper
|
||||
getPackageManageTool(){
|
||||
if [[ -n `command -v apt-get` ]];then
|
||||
CMD_INSTALL="apt-get -y -qq install"
|
||||
CMD_UPDATE="apt-get -qq update"
|
||||
elif [[ -n `command -v yum` ]]; then
|
||||
CMD_INSTALL="yum -y -q install"
|
||||
CMD_UPDATE="yum -q makecache"
|
||||
elif [[ -n `command -v zypper` ]]; then
|
||||
CMD_INSTALL="zypper -y install"
|
||||
CMD_UPDATE="zypper ref"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
## 安装所需要的程序,及依赖程序
|
||||
installDemands(){
|
||||
COMPONENT=$1
|
||||
if [[ -n `command -v $COMPONENT` ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
getPackageManageTool
|
||||
if [[ $? -eq 1 ]]; then
|
||||
colorEcho ${RED} "The system package manager tool isn't APT or YUM, please install ${COMPONENT} manually."
|
||||
return 1
|
||||
fi
|
||||
|
||||
### 更新程序引索
|
||||
if [[ $SOFTWARE_UPDATED -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "正在更新软件包管理..."
|
||||
$CMD_UPDATE
|
||||
SOFTWARE_UPDATED=1
|
||||
fi
|
||||
|
||||
colorEcho ${BLUE} "正在安装 ${COMPONENT}.."
|
||||
$CMD_INSTALL $COMPONENT
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "安装 ${COMPONENT} 失败. 请手动安装该程序."
|
||||
return 1
|
||||
else
|
||||
colorEcho ${GREEN} "已经成功安装 ${COMPONENT}."
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
## 下面只是例子,使用时在主函数中应用之
|
||||
installDemands "iftop" || return $?
|
||||
76
功能脚本/基础脚本/安装多个软件.sh
Normal file
76
功能脚本/基础脚本/安装多个软件.sh
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
CMD_INSTALL=""
|
||||
CMD_UPDATE=""
|
||||
CMD_REMOVE=""
|
||||
SOFTWARE_UPDATED=0
|
||||
|
||||
#########color code#############
|
||||
RED="31m" # Error message
|
||||
GREEN="32m" # Success message
|
||||
YELLOW="33m" # Warning message
|
||||
BLUE="36m" # Info message
|
||||
|
||||
###############color echo func#################
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
# 判断系统的包管理工具 apt, yum, or zypper
|
||||
getPackageManageTool(){
|
||||
if [[ -n `command -v apt-get` ]];then
|
||||
CMD_INSTALL="apt-get -y -qq install"
|
||||
CMD_UPDATE="apt-get -qq update"
|
||||
CMD_REMOVE="apt-get -y remove"
|
||||
elif [[ -n `command -v yum` ]]; then
|
||||
CMD_INSTALL="yum -y -q install"
|
||||
CMD_UPDATE="yum -q makecache"
|
||||
CMD_REMOVE="yum -y remove"
|
||||
elif [[ -n `command -v zypper` ]]; then
|
||||
CMD_INSTALL="zypper -y install"
|
||||
CMD_UPDATE="zypper ref"
|
||||
CMD_REMOVE="zypper -y remove"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
## 安装所需要的程序,及依赖程序
|
||||
installDemandSoftwares(){
|
||||
# 检查系统包管理方式,更新包
|
||||
getPackageManageTool
|
||||
if [[ $? -eq 1 ]]; then
|
||||
colorEcho ${RED} "系统的包管理不是 APT or YUM, 请手动安装所需要的软件."
|
||||
return 1
|
||||
fi
|
||||
|
||||
### 更新程序引索
|
||||
if [[ $SOFTWARE_UPDATED -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "正在更新软件包管理..."
|
||||
$CMD_UPDATE
|
||||
SOFTWARE_UPDATED=1
|
||||
fi
|
||||
|
||||
for software in $@
|
||||
do
|
||||
## 安装该软件
|
||||
if [[ -n `command -v ${software}` ]]; then
|
||||
colorEcho ${GREEN} "${software}已经安装了...跳过..."
|
||||
else
|
||||
colorEcho ${BLUE} "正在安装 ${software}.."
|
||||
$CMD_INSTALL ${software}
|
||||
|
||||
## 判断该软件是否安装成功
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "安装 ${software} 失败. 请手动安装该程序."
|
||||
return 1
|
||||
else
|
||||
colorEcho ${GREEN} "已经成功安装 ${software}."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
installDemandSoftwares iftop vim curl wget mtr
|
||||
66
功能脚本/基础脚本/检查系统版本.sh
Normal file
66
功能脚本/基础脚本/检查系统版本.sh
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
### 为了文件美观,直接继承了fontColor.sh文件 #####
|
||||
|
||||
#######第一种方法########
|
||||
RED="31m" # Error message
|
||||
GREEN="32m" # Success message
|
||||
YELLOW="33m" # Warning message
|
||||
BLUE="36m" # Info message
|
||||
|
||||
check_root(){
|
||||
if [[ $EUID != 0 ]];then
|
||||
colorEcho ${RED} "当前非root账号(或没有root权限),无法继续操作,请更换root账号!"
|
||||
colorEcho ${YELLOW} "使用sudo -命令获取临时root权限(执行后可能会提示输入root密码)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
####### 获取系统版本及64位或32位信息
|
||||
check_sys(){
|
||||
sys_bit=$(uname -m)
|
||||
case $sys_bit in
|
||||
i[36]86)
|
||||
os_bit="32"
|
||||
release="386"
|
||||
;;
|
||||
x86_64)
|
||||
os_bit="64"
|
||||
release="amd64"
|
||||
;;
|
||||
*armv6*)
|
||||
os_bit="arm"
|
||||
release="arm6"
|
||||
;;
|
||||
*armv7*)
|
||||
os_bit="arm"
|
||||
release="arm7"
|
||||
;;
|
||||
*aarch64* | *armv8*)
|
||||
os_bit="arm64"
|
||||
release="arm64"
|
||||
;;
|
||||
*)
|
||||
colorEcho ${RED} "
|
||||
哈哈……这个 辣鸡脚本 不支持你的系统。 (-_-) \n
|
||||
备注: 仅支持 Ubuntu 16+ / Debian 8+ / CentOS 7+ 系统
|
||||
" && exit 1
|
||||
;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
######## 颜色函数方法很精妙 ############
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
main(){
|
||||
check_root
|
||||
check_sys
|
||||
|
||||
colorEcho $GREEN "\t你现在正在以root的身份查看系统信息!"
|
||||
colorEcho $YELLOW "\t操作系统是${os_bit}位的,发行版本是${release}"
|
||||
}
|
||||
|
||||
main
|
||||
33
功能脚本/基础脚本/获取本机的公网IP.sh
Normal file
33
功能脚本/基础脚本/获取本机的公网IP.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 判断命令是否存在
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# 获取服务器的公网IP地址
|
||||
get_server_ip() {
|
||||
local server_ip=""
|
||||
local Network_Manage_Tool=""
|
||||
|
||||
if command_exists ip; then
|
||||
Network_Manage_Tool="$(ip addr)"
|
||||
elif command_exists ifconfig; then
|
||||
Network_Manage_Tool="$(ifconfig)"
|
||||
fi
|
||||
|
||||
server_ip=$(echo "$Network_Manage_Tool" | \
|
||||
grep -oE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | \
|
||||
grep -vE "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | \
|
||||
head -n 1)
|
||||
|
||||
# 自动获取失败时,通过网站提供的 API 获取外网地址
|
||||
if [ -z "$server_ip" ]; then
|
||||
server_ip="$(wget -qO- --no-check-certificate https://ipv4.icanhazip.com)"
|
||||
server_ip=$(curl -s https://myip.ipip.net | awk '{print$2}' | cut -d":" -f2)
|
||||
fi
|
||||
|
||||
echo "$server_ip"
|
||||
}
|
||||
|
||||
get_server_ip
|
||||
33
功能脚本/基础脚本/获取本机的内网IP.sh
Normal file
33
功能脚本/基础脚本/获取本机的内网IP.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 判断命令是否存在
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# 获取服务器的公网IP地址
|
||||
get_Internal_IP() {
|
||||
|
||||
local Internal_IP=""
|
||||
local Network_Manage_Tool=""
|
||||
|
||||
if command_exists ip; then
|
||||
Network_Manage_Tool=$(ip addr)
|
||||
|
||||
Ethernet_Interface_Name=$(echo "$Network_Manage_Tool" | grep -Eo "eth([0-9]{1,3})|eno([0-9]{1,3})|ens([0-9]{1,3})" | head -n 1)
|
||||
echo "正在使用ip addr命令获取内网的IP地址:"
|
||||
Internal_IP=$(ip addr show ${Ethernet_Interface_Name} | grep 'inet ' | head -1 | awk '{print $2}' | cut -f1 -d'/')
|
||||
|
||||
elif command_exists ifconfig; then
|
||||
Network_Manage_Tool=$(ifconfig)
|
||||
Ethernet_Interface_Name=$(echo "$Network_Manage_Tool" | grep -Eo "eth([0-9]{1,3})|eno([0-9]{1,3})|ens([0-9]{1,3})" | head -n 1)
|
||||
echo "正在使用ifconfig命令获取内网的IP地址:"
|
||||
Internal_IP=$(ifconfig ${Ethernet_Interface_Name} | grep 'inet ' | head -1 | awk '{print $2}' | cut -f1 -d'/')
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "$Internal_IP"
|
||||
echo ""
|
||||
}
|
||||
|
||||
get_Internal_IP
|
||||
66
功能脚本/基础脚本/读取脚本传递参数.sh
Normal file
66
功能脚本/基础脚本/读取脚本传递参数.sh
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 当运行时, 可以传入额外的参数
|
||||
## ./runParams.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
|
||||
|
||||
Help(){
|
||||
cat - 1>& 2 << EOF
|
||||
./install-release.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
|
||||
-h, --help Show help
|
||||
-p, --proxy To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc
|
||||
-f, --force Force install
|
||||
--version Install a particular version, use --version v3.15
|
||||
-l, --local Install from a local file
|
||||
--remove Remove installed V2Ray
|
||||
-c, --check Check for update
|
||||
EOF
|
||||
}
|
||||
|
||||
#########################
|
||||
while [[ $# > 0 ]]; do
|
||||
case "$1" in
|
||||
-p|--proxy)
|
||||
PROXY="-x ${2}"
|
||||
shift # past argument
|
||||
;;
|
||||
-h|--help)
|
||||
HELP="1"
|
||||
;;
|
||||
-f|--force)
|
||||
FORCE="1"
|
||||
;;
|
||||
-c|--check)
|
||||
CHECK="1"
|
||||
;;
|
||||
--remove)
|
||||
REMOVE="1"
|
||||
;;
|
||||
--version)
|
||||
VERSION="$2"
|
||||
shift
|
||||
;;
|
||||
--extract)
|
||||
VSRC_ROOT="$2"
|
||||
shift
|
||||
;;
|
||||
--extractonly)
|
||||
EXTRACT_ONLY="1"
|
||||
;;
|
||||
-l|--local)
|
||||
LOCAL="$2"
|
||||
LOCAL_INSTALL="1"
|
||||
shift
|
||||
;;
|
||||
--source)
|
||||
DIST_SRC="$2"
|
||||
shift
|
||||
;;
|
||||
--errifuptodate)
|
||||
ERROR_IF_UPTODATE="1"
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
Reference in New Issue
Block a user