feat: install script

This commit is contained in:
VaalaCat
2024-12-21 05:58:50 +00:00
parent 373276633f
commit a8a530c0fe
2 changed files with 66 additions and 18 deletions

View File

@@ -15,9 +15,9 @@ if ([System.Environment]::Is64BitOperatingSystem) {
Write-Host "Your system is 32-bit, please use 64-bit operating system" -BackgroundColor DarkGreen -ForegroundColor White
exit
}
$clientreleases = "https://api.github.com/repos/$clientrepo/releases"
#重复运行自动更新
if (Test-Path "C:\frpp") {
if (Test-Path "C:\frpp\frpp.exe") {
Write-Host "frp panel client already exists, delete and reinstall" -BackgroundColor DarkGreen -ForegroundColor White
C:/frpp/frpp.exe stop
C:/frpp/frpp.exe uninstall
@@ -26,19 +26,16 @@ if (Test-Path "C:\frpp") {
}
#TLS/SSL
Write-Host "Determining latest frp panel client release" -BackgroundColor DarkGreen -ForegroundColor White
Write-Host "Check network connection to google" -BackgroundColor DarkGreen -ForegroundColor White
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$agenttag = (Invoke-WebRequest -Uri $clientreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
#Region判断
$ipapi= Invoke-RestMethod -Uri "https://api.myip.com/" -UserAgent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1"
$region=$ipapi.cc
echo $ipapi
if($region -eq "CN" -or [string]::IsNullOrEmpty($ipapi)){
$download = "https://ghp.ci/https://github.com/$clientrepo/releases/download/$agenttag/$file"
$networkAvailable = Test-Connection -ComputerName google.com -Count 1 -ErrorAction SilentlyContinue
if([string]::IsNullOrEmpty($networkAvailable)){
$download = "https://gh-proxy.com/https://github.com/$clientrepo/releases/latest/download/$file"
Write-Host "Location:CN,use mirror address" -BackgroundColor DarkRed -ForegroundColor Green
}else{
$download = "https://github.com/$clientrepo/releases/download/$agenttag/$file"
Write-Host "Location:$region,connect directly!" -BackgroundColor DarkRed -ForegroundColor Green
$download = "https://github.com/$clientrepo/releases/latest/download/$file"
Write-Host "Location: google ok,connect directly!" -BackgroundColor DarkRed -ForegroundColor Green
}
echo $download
Invoke-WebRequest $download -OutFile "C:\frpp.exe"

View File

@@ -3,13 +3,19 @@
OS=$(uname -s)
ARCH=$(uname -m)
if [ "$(curl -s https://ipinfo.io/country)" = "CN" ]; then
prefix="https://mirror.ghproxy.com/"
echo "监测到您的IP在中国使用镜像下载"
else
if ping -c 1 -W 1 google.com > /dev/null 2>&1; then
prefix=""
echo "检测到您的网络可以连接到 Google不使用镜像下载"
else
prefix="https://mirror.ghproxy.com/"
echo "检测到您的网络无法连接到 Google使用镜像下载"
fi
current_dir=$(pwd)
temp_dir=$(mktemp -d)
echo "下载临时文件夹创建在: $temp_dir"
cd "$temp_dir"
case "$OS" in
Linux)
case "$ARCH" in
@@ -43,13 +49,52 @@ case "$OS" in
;;
esac
chmod +x frp-panel
sudo chmod +x frp-panel
cd "$current_dir"
new_executable_path="$temp_dir/frp-panel"
get_start_params() {
read -p "请输入启动参数:" params
echo "$params"
}
find_frpp_executable() {
service_file=$(systemctl show -p FragmentPath frpp.service 2>/dev/null | cut -d'=' -f2)
if [[ -z "$service_file" || ! -f "$service_file" ]]; then
echo ""
return 1
fi
exec_start=$(grep -oP '^ExecStart=\K.*' "$service_file")
if [[ -z "$exec_start" ]]; then
echo ""
return 1
fi
executable_path=$(echo "$exec_start" | awk '{print $1}')
echo "$executable_path"
}
if systemctl list-units --type=service | grep -q frpp; then
echo "frpp 服务存在"
executable_path=$(find_frpp_executable)
if [ -z "$executable_path" ]; then
echo "无法找到 frpp 服务的执行文件路径请检查systemd文件"
exit 1
fi
echo "更新程序到原路径:$executable_path"
sudo rm -rf "$executable_path"
sudo cp "$new_executable_path" "$executable_path"
sudo systemctl restart frpp
echo "frpp 服务已更新。"
$executable_path version
exit 0
else
echo "frpp 服务不存在,进行安装"
fi
sudo cp "$new_executable_path" .
if [ -n "$1" ]; then
start_params="$@"
else
@@ -58,9 +103,15 @@ fi
sudo ./frp-panel install $start_params
echo "frp-panel 服务安装完成, 安装路径:$(pwd)/frp-panel"
sudo systemctl daemon-reload
sudo systemctl start frpp
sudo ./frp-panel start
sudo ./frp-panel version
echo "frp-panel 服务已启动"
sudo systemctl restart frpp