Last active
August 13, 2023 19:21
-
-
Save HBIDamian/ee2d5c0d29e3df8e3d60542f6469dd5d to your computer and use it in GitHub Desktop.
Run Down Installer for PocketMine-MP (PowerShell).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$host.ui.RawUI.WindowTitle = "Run Down PocketMine-MP Installer" | |
$WebClient = New-Object System.Net.WebClient | |
# Setting this to true will delete all files in the current directory. | |
# Setting this to false will replace specific files in the current directory with the latest versions. | |
$global:FreshInstallMode = $false | |
# Change this to the version of PHP and PocketMine-MP you want to install. | |
$global:PHPVer = "8.2-latest" | |
$global:PMMPVer = "PM5" | |
if ($global:PMMPVer -eq "PM6") { | |
$global:PMMPURL = "https://update.pmmp.io/api?channel=alpha" | |
} | |
elseif ($global:PMMPVer -eq "PM5") { | |
$global:PMMPURL = "https://update.pmmp.io/api?channel=5" | |
} | |
elseif ($global:PMMPVer -eq "PM4") { | |
$global:PMMPURL = "https://update.pmmp.io/api?channel=4" | |
} else { | |
$global:PMMPURL = "https://update.pmmp.io/api?channel=stable" | |
} | |
function Pre-Script { | |
Splash-Text | |
Write-Host "Run Down PocketMine-MP Installer:" -foreground "Magenta" -NoNewline; Write-Host " Made by HBIDamian" -foreground "DarkCyan" | |
Write-Host "This is a very hacky way of installing PocketMine-MP." -foreground "DarkMagenta" | |
Write-Host "It's not really recommended to use it for production." -foreground "DarkRed" | |
Write-Host "" | |
if ($global:FreshInstallMode -eq $true) { | |
Write-Host "FreshInstallMode:" -foreground "White" -NoNewline; Write-Host " True" -foreground "Yellow" | |
} else { | |
Write-Host "FreshInstallMode:" -foreground "White" -NoNewline; Write-Host " False" -foreground "DarkYellow" | |
} | |
Read-Host -Prompt "Press Enter to continue" | |
clear-host | |
Start-Script | |
} | |
function Splash-Text { | |
Write-Host " _____________________ ________ " -foreground "Red" | |
Write-Host " | ___ \ _ \ ___ \ \/ |_ _| " -foreground "DarkYellow" | |
Write-Host " | |_/ / | | | |_/ / . . | | | " -foreground "Yellow" | |
Write-Host " | /| | | | __/| |\/| | | | " -foreground "Green" | |
Write-Host " | |\ \| |/ /| | | | | |_| |_ " -foreground "DarkCyan" | |
Write-Host " \_| \_|___/ \_| \_| |_/\___/ " -foreground "Magenta" | |
Write-Host "" | |
} | |
function Get-Time-Stamp { | |
Write-Host "[$((Get-Date -Format 'HH:mm:ss:fff'))] " -foreground "White" -NoNewline | |
} | |
function Download-File { | |
param( | |
[string]$url, | |
[string]$destination | |
) | |
Get-Time-Stamp; Write-Host "[INFO]: Downloading $url..." -foreground "Cyan" | |
$WebClient.DownloadFile($url, $destination) | |
if (!(Test-Path $destination)) { | |
Get-Time-Stamp; Write-Warning "[ERROR]: Absent File: $destination. Aborting." -foreground "Red" | |
Read-Host -Prompt "Press Enter to exit" | |
exit | |
} else { | |
Get-Time-Stamp; Write-Host "[SUCCESS]: Downloaded $destination" -foreground "Green" | |
} | |
} | |
function Start-Script { | |
Splash-Text | |
Get-Time-Stamp; Write-Host "[INFO]: Detecting and killing active PocketMine-MP Servers" -foreground "Cyan" | |
$PMMPProcess = Get-Process -Name "php" -ErrorAction SilentlyContinue | |
if ($PMMPProcess) { | |
$PMMPProcess | Stop-Process -Force -ErrorAction SilentlyContinue | |
$PMMPProcess.WaitForExit() | |
Get-Time-Stamp; Write-Host "[SUCCESS]: Killed any running PocketMine-MP servers." -foreground "Green" | |
} else { | |
Get-Time-Stamp; Write-Host "[INFO]: No PocketMine-MP servers running." -foreground "Cyan" | |
} | |
if ($global:FreshInstallMode -eq $true) { | |
try { | |
Get-Time-Stamp; Write-Host "[INFO]: Removing all files in current directory..." -foreground "Cyan" | |
$ScriptName = $MyInvocation.ScriptName.Split("\")[-1] | |
Get-ChildItem -Path .\ -Exclude $ScriptName | Remove-Item -Recurse -Force -ErrorAction Stop | |
Get-Time-Stamp; Write-Host "[SUCCESS]: All Files removed successfully." -foreground "Green" | |
} catch { | |
Get-Time-Stamp; Write-Host "[ERROR]: An error occurred: $($_.Exception.Message)" -foreground "Red" | |
} | |
} else { | |
try { | |
Get-Time-Stamp; Write-Host "[INFO]: Removing specific files in current directory..." -foreground "Cyan" | |
Remove-Item -Path .\bin -Recurse -Force -ErrorAction Stop | |
Remove-Item -Path .\vc_redist.x64.exe -Force -ErrorAction Stop | |
Remove-Item -Path .\PocketMine-MP.phar -Force -ErrorAction Stop | |
Remove-Item -Path .\start.cmd -Force -ErrorAction Stop | |
Remove-Item -Path .\start.ps1 -Force -ErrorAction Stop | |
Get-Time-Stamp; Write-Host "[SUCCESS]: Files removed successfully." -foreground "Green" | |
} catch { | |
Get-Time-Stamp; Write-Host "[ERROR]: An error occurred: $($_.Exception.Message)" -foreground "Red" | |
} | |
} | |
Get-Time-Stamp; Write-Host "[INFO]: Downloading Binary files..." -foreground "Cyan" | |
Download-File -url "https://github.com/pmmp/PHP-Binaries/releases/download/php-$($global:PHPVer)/PHP-Windows-x64-$($global:PMMPVer).zip" -destination "./PHP-$($global:PHPVer)-Windows-x64-$($global:PMMPVer).zip" | |
Get-Time-Stamp; Write-Host "[INFO]: Expanding the archive..." -foreground "Cyan" | |
Expand-Archive "./PHP-$($global:PHPVer)-Windows-x64-$($global:PMMPVer).zip" -DestinationPath ./ | |
Get-Time-Stamp; Write-Host "[INFO]: Removing the archive..." -foreground "Cyan" | |
remove-Item "./PHP-$($global:PHPVer)-Windows-x64-$($global:PMMPVer).zip" | |
Get-Time-Stamp; Write-Host "[INFO]: Checking if php.exe exists from archive..." -foreground "Cyan" | |
if (!(Test-Path "./bin/php/php.exe")) { | |
Write-Warning "[ERROR]: Absent File. Aborting." -foreground "Red" | |
Read-Host -Prompt "Press Enter to exit" | |
exit | |
} | |
Get-Time-Stamp; Write-Host "[INFO]: Downloading latest PocketMine-MP.phar..." -foreground "Cyan" | |
$getPhar = Invoke-RestMethod $global:PMMPURL | |
Download-File -url $getPhar.download_url -destination "./PocketMine-MP.phar" | |
Download-File -url "https://raw.githubusercontent.com/pmmp/PocketMine-MP/stable/start.cmd" -destination "./start.cmd" | |
Download-File -url "https://raw.githubusercontent.com/pmmp/PocketMine-MP/stable/start.ps1" -destination "./start.ps1" | |
Get-Time-Stamp; Write-Host "[SUCCESS]: Install Complete. You may now use 'start.cmd' or 'start.ps1'" -foreground "Green" | |
Write-Host "" | |
powershell.exe .\start.ps1 | |
Read-Host -Prompt "Press Enter to exit" | |
} | |
Pre-Script |
Updated.
- Made it more readable
- Made it easily editable (with global variables)
Note: When PM5 is released, it may not install the stable version and may require an update to the script.
Updated
- Rest in piece, Jenkins. Everyone's favourite butler.
Updated
- Added this.
# Setting this to true will delete all files in the current directory.
# Setting this to false will replace specific files in the current directory with the latest versions.
$global:FreshInstallMode = $false
Makes it easier for testing shit.
- Less green. Green is for success. Cyan is for info.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I changed the name, and made it more cancerous. :D
I also realise it doesn't display the "custom errors" properly. Good. :D