v2raya.sh

This commit is contained in:
eddy
2025-11-07 14:07:46 +08:00
parent 78bd81e5c9
commit b5737d0594

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# ddns-go 自动安装脚本 # V2rayA 自动安装/卸载脚本
# 使用方法: chmod +x v2raya.sh && ./v2raya.sh # 使用方法: chmod +x v2raya.sh && ./v2raya.sh
# curl -sS -O https://gitea.tohub.top/Share/vps/raw/branch/main/v2raya/v2raya.sh && chmod +x v2raya.sh && ./v2raya.sh # curl -sS -O https://gitea.tohub.top/Share/vps/raw/branch/main/v2raya/v2raya.sh && chmod +x v2raya.sh && ./v2raya.sh
@@ -11,92 +11,314 @@ BLUE='\033[0;34m'
CYAN='\033[0;36m' CYAN='\033[0;36m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
# 配置变量
INSTALL_DIR="/root/data/docker_data"
BASE_URL="https://gitea.tohub.top/Share/vps/raw/branch/main/v2raya"
XRAY_VERSION="25.8.3"
V2RAYA_VERSION="2.2.7.4"
## 下载 # 默认账号信息
DEFAULT_USER="admin@gmail.com"
DEFAULT_PASS="gmail.com"
https://gitea.tohub.top/Share/vps/raw/branch/main/v2raya/xray_25.8.3_arm64.deb # 打印信息函数
https://gitea.tohub.top/Share/vps/raw/branch/main/v2raya/v2raya_2.2.7.4_amd64.deb print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
## 1. 手动安装 V2rayA print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
1. 下载 `.deb` 安装包: print_warning() {
```yaml echo -e "${YELLOW}[WARNING]${NC} $1"
/root/data/docker_data/xray_25.8.3_amd64.deb }
/root/data/docker_data/v2raya_2.2.7.4_amd64.deb
```
2. 安装依赖: print_error() {
```bash echo -e "${RED}[ERROR]${NC} $1"
sudo chmod 644 /root/data/docker_data/xray_25.8.3_amd64.deb }
sudo dpkg -i /root/data/docker_data/xray_25.8.3_amd64.deb
sudo apt --fix-broken install
```
3. 安装V2rayA # 检查是否以 root 权限运行
```bash check_root() {
sudo chmod 644 /root/data/docker_data/v2raya_2.2.7.4_amd64.deb if [[ $EUID -ne 0 ]]; then
sudo dpkg -i /root/data/docker_data/v2raya_2.2.7.4_amd64.deb print_error "此脚本需要 root 权限运行"
sudo apt --fix-broken install print_info "请使用: sudo $0"
``` exit 1
fi
}
4. 启动 V2rayA # 检测系统架构
```bash detect_arch() {
sudo systemctl start v2raya.service local arch=$(dpkg --print-architecture)
``` if [[ "$arch" == "amd64" ]] || [[ "$arch" == "arm64" ]]; then
echo "$arch"
else
print_error "不支持的系统架构: $arch"
print_info "仅支持 amd64 和 arm64"
exit 1
fi
}
5. 设置开机自启: # 创建安装目录
```bash create_install_dir() {
sudo systemctl enable v2raya.service if [[ ! -d "$INSTALL_DIR" ]]; then
``` print_info "创建安装目录: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
if [[ $? -ne 0 ]]; then
print_error "创建目录失败"
exit 1
fi
fi
}
6. 登录信息: # 下载文件
```yaml download_file() {
账号: admin@gmail.com local url=$1
密码: gmail.com local output=$2
```
--- print_info "正在下载: $url"
## 2.手动卸载 V2rayA if command -v wget &> /dev/null; then
wget -q --show-progress "$url" -O "$output"
elif command -v curl &> /dev/null; then
curl -# -L "$url" -o "$output"
else
print_error "未找到 wget 或 curl请先安装"
exit 1
fi
要卸载通过.deb包安装的V2rayA和Xray请按照以下步骤操作 if [[ $? -eq 0 ]]; then
print_success "下载完成: $output"
return 0
else
print_error "下载失败: $url"
return 1
fi
}
1. 首先停止服务 # 下载安装包
```bash download_packages() {
sudo systemctl stop v2raya.service local arch=$(detect_arch)
``` print_info "检测到系统架构: $arch"
2. 禁用开机自启 create_install_dir
```bash
sudo systemctl disable v2raya.service
```
3. 卸载V2rayA软件包 local xray_file="xray_${XRAY_VERSION}_${arch}.deb"
```bash local v2raya_file="v2raya_${V2RAYA_VERSION}_${arch}.deb"
sudo apt remove v2raya
```
4. 卸载Xray软件包 # 下载 Xray
```bash if [[ ! -f "$INSTALL_DIR/$xray_file" ]]; then
sudo apt remove xray download_file "$BASE_URL/$xray_file" "$INSTALL_DIR/$xray_file"
``` else
print_warning "文件已存在,跳过下载: $xray_file"
fi
5. 清理不再需要的依赖项(可选) # 下载 V2rayA
```bash if [[ ! -f "$INSTALL_DIR/$v2raya_file" ]]; then
sudo apt autoremove download_file "$BASE_URL/$v2raya_file" "$INSTALL_DIR/$v2raya_file"
``` else
print_warning "文件已存在,跳过下载: $v2raya_file"
fi
}
6. 如果需要,删除配置文件(谨慎操作) # 安装 V2rayA
```bash install_v2raya() {
sudo rm -rf /etc/v2raya local arch=$(detect_arch)
``` local xray_file="$INSTALL_DIR/xray_${XRAY_VERSION}_${arch}.deb"
local v2raya_file="$INSTALL_DIR/v2raya_${V2RAYA_VERSION}_${arch}.deb"
7. 彻底清除所有配置文件 # 检查文件是否存在
```bash if [[ ! -f "$xray_file" ]] || [[ ! -f "$v2raya_file" ]]; then
sudo apt purge xray v2raya print_warning "安装包不存在,开始下载..."
``` download_packages
fi
8. 验证:如果没有输出,说明卸载完全成功。
```bash print_info "开始安装 Xray..."
dpkg -l | grep -E 'v2raya|xray' chmod 644 "$xray_file"
``` dpkg -i "$xray_file"
apt --fix-broken install -y
if [[ $? -ne 0 ]]; then
print_error "Xray 安装失败"
exit 1
fi
print_success "Xray 安装成功"
print_info "开始安装 V2rayA..."
chmod 644 "$v2raya_file"
dpkg -i "$v2raya_file"
apt --fix-broken install -y
if [[ $? -ne 0 ]]; then
print_error "V2rayA 安装失败"
exit 1
fi
print_success "V2rayA 安装成功"
# 启动服务
print_info "启动 V2rayA 服务..."
systemctl start v2raya.service
if [[ $? -eq 0 ]]; then
print_success "V2rayA 服务启动成功"
else
print_error "V2rayA 服务启动失败"
fi
# 设置开机自启
print_info "设置开机自启..."
systemctl enable v2raya.service
print_success "已设置开机自启"
# 显示登录信息
echo ""
print_success "============================================"
print_success "V2rayA 安装完成!"
print_success "============================================"
print_info "访问地址: http://localhost:2017"
print_info "默认账号: ${CYAN}$DEFAULT_USER${NC}"
print_info "默认密码: ${CYAN}$DEFAULT_PASS${NC}"
print_success "============================================"
echo ""
}
# 卸载 V2rayA
uninstall_v2raya() {
print_warning "即将卸载 V2rayA 和 Xray"
read -p "是否继续?[y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "已取消卸载"
return
fi
# 停止服务
print_info "停止 V2rayA 服务..."
systemctl stop v2raya.service 2>/dev/null
# 禁用开机自启
print_info "禁用开机自启..."
systemctl disable v2raya.service 2>/dev/null
# 卸载软件包
print_info "卸载 V2rayA..."
apt remove v2raya -y 2>/dev/null
print_info "卸载 Xray..."
apt remove xray -y 2>/dev/null
# 清理依赖
print_info "清理不需要的依赖..."
apt autoremove -y
# 询问是否删除配置文件
read -p "是否删除配置文件?[y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "删除配置文件..."
rm -rf /etc/v2raya 2>/dev/null
apt purge xray v2raya -y 2>/dev/null
fi
# 验证卸载
if dpkg -l | grep -E 'v2raya|xray' &> /dev/null; then
print_warning "部分组件可能未完全卸载"
dpkg -l | grep -E 'v2raya|xray'
else
print_success "V2rayA 和 Xray 已完全卸载"
fi
}
# 检查安装状态
check_status() {
echo ""
print_info "============================================"
print_info "检查 V2rayA 状态"
print_info "============================================"
if dpkg -l | grep -q v2raya; then
print_success "V2rayA 已安装"
if systemctl is-active --quiet v2raya.service; then
print_success "V2rayA 服务运行中"
else
print_warning "V2rayA 服务未运行"
fi
if systemctl is-enabled --quiet v2raya.service; then
print_success "开机自启已启用"
else
print_warning "开机自启未启用"
fi
else
print_warning "V2rayA 未安装"
fi
if dpkg -l | grep -q xray; then
print_success "Xray 已安装"
else
print_warning "Xray 未安装"
fi
print_info "============================================"
echo ""
}
# 主菜单
show_menu() {
clear
echo -e "${CYAN}"
echo "============================================"
echo " V2rayA 自动安装/卸载脚本"
echo "============================================"
echo -e "${NC}"
echo -e "${GREEN}1.${NC} 安装 V2rayA"
echo -e "${GREEN}2.${NC} 卸载 V2rayA"
echo -e "${GREEN}3.${NC} 仅下载安装包"
echo -e "${GREEN}4.${NC} 检查状态"
echo -e "${GREEN}0.${NC} 退出"
echo ""
echo -e "${CYAN}============================================${NC}"
}
# 主程序
main() {
check_root
while true; do
show_menu
read -p "请选择操作 [0-4]: " choice
case $choice in
1)
install_v2raya
read -p "按任意键继续..." -n 1
;;
2)
uninstall_v2raya
read -p "按任意键继续..." -n 1
;;
3)
download_packages
read -p "按任意键继续..." -n 1
;;
4)
check_status
read -p "按任意键继续..." -n 1
;;
0)
print_info "退出脚本"
exit 0
;;
*)
print_error "无效的选择,请重新输入"
sleep 2
;;
esac
done
}
# 运行主程序
main