pypush-plus-plus/windows_installer.ps1

73 lines
3 KiB
PowerShell
Raw Normal View History

2023-11-12 18:43:59 -06:00
Import-Module Microsoft.PowerShell.Management
2023-11-14 17:43:36 -06:00
# Prompt the user for the IP address of their phone.
$phoneIp = Read-Host "Enter the IP address of your phone: "
2023-11-10 20:51:33 -06:00
# Check if Python is installed.
2023-11-14 16:19:35 -06:00
Write-Output "Checking if Python is installed"
2023-11-14 16:08:26 -06:00
if (-not (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\python.exe")) {
2023-11-10 20:51:33 -06:00
# Python is not installed, so download and install it.
2023-11-14 16:19:35 -06:00
Write-Output "Installing Python"
2023-11-10 20:51:33 -06:00
$pythonUrl = "https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe"
$pythonInstaller = "$($env:TEMP)\python.exe"
Invoke-WebRequest -Uri $pythonUrl -OutFile $pythonInstaller
Start-Process -FilePath $pythonInstaller -ArgumentList "/quiet" -Wait
2023-11-12 18:43:59 -06:00
}
2023-11-14 17:43:36 -06:00
Write-Output "Adding Python to Path"
[Environment]::SetEnvironmentVariable("Path", "$env:Path;$env:USERPROFILE\AppData\Local\Programs\Python\Python310")
2023-11-14 16:19:35 -06:00
Write-Output "Checking if git is installed"
2023-11-12 18:43:59 -06:00
# Check if Git is installed.
2023-11-14 17:43:36 -06:00
if (-not (Test-Path "C:\Program Files\Git\bin\git.exe")) {
2023-11-10 20:51:33 -06:00
# Git is not installed, so download and install it.
2023-11-14 16:19:35 -06:00
Write-Output "Installing git"
2023-11-14 17:43:36 -06:00
$gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.42.0.windows.2/Git-2.42.0.2-64-bit.exe"
2023-11-10 20:51:33 -06:00
$gitInstaller = "$($env:TEMP)\git.exe"
Invoke-WebRequest -Uri $gitUrl -OutFile $gitInstaller
Start-Process -FilePath $gitInstaller -ArgumentList "/SILENT" -Wait
2023-11-12 18:43:59 -06:00
}
2023-11-14 17:43:36 -06:00
Write-Output "Adding Git to Path"
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Program Files\Git\bin\")
2023-11-12 18:43:59 -06:00
2023-11-14 17:43:36 -06:00
# Create the folder for virtual environments if it doesn't exist.
Write-Output "Creating folder for virtual environment"
if (Test-Path "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs") {
2023-11-12 18:43:59 -06:00
New-Item "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs" -ItemType Directory
}
# Create a Python 3.10 virtual environment named "pypush" in the user's home folder.
2023-11-14 17:43:36 -06:00
Write-Output "Creating virtual environment"
python -m venv "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs\pypush"
2023-11-12 18:43:59 -06:00
2023-11-14 17:43:36 -06:00
# Activate the virtual environment.
Write-Output "Activating virtual environment"
. "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs\pypush\Scripts\activate.ps1"
cd "$env:USERPROFILE"
# Clone the "sms-registration" branch of the repository located at https://github.com/beeper/pypush using git.
Write-Output "Cloning sms-registration branch"
git clone -b sms-registration https://github.com/beeper/pypush
2023-11-12 18:43:59 -06:00
2023-11-14 17:43:36 -06:00
# Change directories to the repository.
Write-Output "Changing directories"
cd "$env:USERPROFILE\pypush"
# Install dependencies from the requirements.txt file using pip.
Write-Output "Installing dependencies"
pip install -r "requirements.txt"
2023-11-12 18:43:59 -06:00
2023-11-14 17:43:36 -06:00
# Store the IP address in a variable.
$phoneIpVariable = Set-Variable -Name phoneIp -Value $phoneIp -Scope Global
2023-11-12 18:43:59 -06:00
2023-11-14 17:43:36 -06:00
# Execute the `python demo.py` script with the phone IP address passed as a parameter.
Write-Output "Registering"
python demo.py --phone $phoneIpVariable
2023-11-12 18:43:59 -06:00
2023-11-14 17:43:36 -06:00
# Execute the daemon for reregistration
Write-Output "Executing the daemon"
python demo.py --daemon
2023-11-12 18:43:59 -06:00