Skip to content

Commit

Permalink
feat: windows service install script
Browse files Browse the repository at this point in the history
  • Loading branch information
VaalaCat committed Mar 18, 2024
1 parent 61a7383 commit d906a76
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 14 deletions.
65 changes: 65 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Download latest release from github
if($PSVersionTable.PSVersion.Major -lt 5){
Write-Host "Require PS >= 5,your PSVersion:"$PSVersionTable.PSVersion.Major -BackgroundColor DarkGreen -ForegroundColor White
exit
}
$clientrepo = "VaalaCat/frp-panel"
$nssmrepo = "nezhahq/nssm-backup"
# x86 or x64
if ([System.Environment]::Is64BitOperatingSystem) {
$file = "frp-panel-amd64.exe"
}
else {
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"
$nssmreleases = "https://api.github.com/repos/$nssmrepo/releases"
#重复运行自动更新
if (Test-Path "C:\frpp") {
Write-Host "frp panel client already exists, delete and reinstall" -BackgroundColor DarkGreen -ForegroundColor White
C:/frpp/nssm.exe stop frpp
C:/frpp/nssm.exe remove frpp
Remove-Item "C:\frpp" -Recurse
}

#TLS/SSL
Write-Host "Determining latest frp panel client release" -BackgroundColor DarkGreen -ForegroundColor White
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$agenttag = (Invoke-WebRequest -Uri $clientreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
$nssmtag = (Invoke-WebRequest -Uri $nssmreleases -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 -ne "CN"){
$download = "https://github.com/$clientrepo/releases/download/$agenttag/$file"
$nssmdownload="https://github.com/$nssmrepo/releases/download/$nssmtag/nssm.zip"
Write-Host "Location:$region,connect directly!" -BackgroundColor DarkRed -ForegroundColor Green
}else{
$download = "https://dn-dao-github-mirror.daocloud.io/$clientrepo/releases/download/$agenttag/$file"
$nssmdownload="https://dn-dao-github-mirror.daocloud.io/$nssmrepo/releases/download/$nssmtag/nssm.zip"
Write-Host "Location:CN,use mirror address" -BackgroundColor DarkRed -ForegroundColor Green
}
echo $download
echo $nssmdownload
Invoke-WebRequest $nssmdownload -OutFile "C:\nssm.zip"
Invoke-WebRequest $download -OutFile "C:\frpp.exe"
#使用nssm安装服务

#解压
Expand-Archive "C:\nssm.zip" -DestinationPath "C:\temp" -Force
if (!(Test-Path "C:\frpp")) { New-Item -Path "C:\frpp" -type directory }

#整理文件
Move-Item -Path "C:\frpp.exe" -Destination "C:\frpp\frpp.exe"
Move-Item -Path "C:\temp\nssm-2.24\win64\nssm.exe" -Destination "C:\frpp\nssm.exe"

#清理垃圾
Remove-Item "C:\nssm.zip"
Remove-Item "C:\temp" -Recurse
#安装部分
C:\frpp\nssm.exe install frpp C:\frpp\frpp.exe $args
C:\frpp\nssm.exe start frpp
#enjoy
Write-Host "Enjoy It!" -BackgroundColor DarkGreen -ForegroundColor Red
10 changes: 5 additions & 5 deletions www/components/client_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ export const ClientID = ({ client }: { client: ClientTableSchema }) => {
<PopoverTrigger asChild>
<div className="font-mono">{client.id}</div>
</PopoverTrigger>
<PopoverContent className="w-fit overflow-auto max-w-64">
<PopoverContent className="w-fit overflow-auto max-w-72 max-h-72">
<div>Linux安装到systemd</div>
<div className="p-2 border rounded font-mono w-fit">
{platformInfo === undefined ? '获取平台信息失败' : LinuxInstallCommand('client', client, platformInfo)}
</div>
{/* <div>Windows</div>
<div className="p-2 border rounded font-mono w-fit">
{platformInfo === undefined ? "获取平台信息失败" : WindowsInstallCommand("client", client, platformInfo)}
</div> */}
<div>Windows安装到系统服务</div>
<div className="p-2 border rounded font-mono w-fit">
{platformInfo === undefined ? "获取平台信息失败" : WindowsInstallCommand("client", client, platformInfo)}
</div>
</PopoverContent>
</Popover>
)
Expand Down
8 changes: 4 additions & 4 deletions www/components/server_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ export const ServerID = ({ server }: { server: ServerTableSchema }) => {
<div className="p-2 border rounded font-mono w-fit">
{platformInfo === undefined ? '获取平台信息失败' : LinuxInstallCommand('server', server, platformInfo)}
</div>
{/* <div>Windows</div>
<div className="p-2 border rounded font-mono w-fit">
{platformInfo === undefined ? "获取平台信息失败" : WindowsInstallCommand("server", server, platformInfo)}
</div> */}
<div>Windows安装到系统服务</div>
<div className="p-2 border rounded font-mono w-fit">
{platformInfo === undefined ? '获取平台信息失败' : WindowsInstallCommand('server', server, platformInfo)}
</div>
</PopoverContent>
</Popover>
)
Expand Down
12 changes: 7 additions & 5 deletions www/lib/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export const WindowsInstallCommand = <T extends Client | Server>(
item: T,
info: GetPlatformInfoResponse,
) => {
return `Invoke-WebRequest -Uri 'https://github.com/your_repository/frp-panel/releases/latest/download/frp-panel-amd64.exe' -OutFile 'frp-panel.exe'
Move-Item .\\frp-panel.exe C:\\Tools\\frp-panel.exe
$command = "C:\\Tools\\${ExecCommandStr(type, item, info, 'frp-panel.exe')}"
Set-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Services\\FRPPanel' -Name 'ImagePath' -Value "\`"$command\`""
New-Service -Name 'FRPPanel' -BinaryPathName 'C:\\Tools\\frp-panel.exe' -StartupType Automatic | Start-Service`
return `[Net.ServicePointManager]::SecurityProtocol = `+
`[Net.SecurityProtocolType]::Ssl3 -bor `+
`[Net.SecurityProtocolType]::Tls -bor ` +
`[Net.SecurityProtocolType]::Tls11 -bor ` +
`[Net.SecurityProtocolType]::Tls12;set-ExecutionPolicy RemoteSigned;`+
`Invoke-WebRequest https://raw.githubusercontent.com/VaalaCat/frp-panel/main/install.ps1 `+
`-OutFile C:\install.ps1;powershell.exe C:\install.ps1 ${ExecCommandStr(type, item, info, ' ')}`
}

export const LinuxInstallCommand = <T extends Client | Server>(
Expand Down

0 comments on commit d906a76

Please sign in to comment.