artemis-portable/build.ps1

141 lines
5.3 KiB
PowerShell

$workdir = "work/"
$artemis_repo = "Hay1tsme/artemis" # must be hosted on gitea.tendokyu.moe
$artemis_branch = "develop"
$python_version = "3.9.13"
$mariadb_version = "10.11.6"
Remove-Item -Recurse $workdir 2>&1>$null
New-Item $workdir -ItemType Directory 2>&1>$null
Set-Location $workdir
# --------------------------------------------------------
# Setting up Python
# --------------------------------------------------------
Write-Output "[INFO] Downloading Python $python_version..."
curl.exe -LO "https://www.python.org/ftp/python/$python_version/python-$python_version-embed-amd64.zip"
Write-Output "[INFO] Extracting Python $python_version..."
7z x "python-$python_version-embed-amd64.zip" -opython
Write-Output "[INFO] Configuring Python $python_version..."
7z x python/python39.zip -opython/Lib
Remove-Item python/python39.zip
Move-Item python/python39._pth python/python39.pth
New-Item -ItemType Directory python/DLLs
curl.exe -L https://bootstrap.pypa.io/get-pip.py | python/python.exe -
Remove-Item "python-$python_version-embed-amd64.zip"
python/python.exe -m pip install wheel pygit2
# --------------------------------------------------------
# Setting up MariaDB
# --------------------------------------------------------
$mariadb_root_password = (-join ((65..90) + (97..122) | Get-Random -Count 32 | ForEach-Object {[char]$_}))
$mariadb_aime_password = (-join ((65..90) + (97..122) | Get-Random -Count 32 | ForEach-Object {[char]$_}))
$mariadb_port = (40000..49151) | Get-Random
Write-Output "[INFO] Downloading MariaDB $mariadb_version..."
curl.exe -LO "https://archive.mariadb.org/mariadb-$mariadb_version/winx64-packages/mariadb-$mariadb_version-winx64.zip"
7z.exe x "mariadb-$mariadb_version-winx64.zip"
Rename-Item "mariadb-$mariadb_version-winx64" mariadb
Remove-Item "mariadb-$mariadb_version-winx64.zip"
Set-Location mariadb
Write-Output "[INFO] Setting up MariaDB on port $mariadb_port..."
bin/mysql_install_db.exe --datadir=data --password=$mariadb_root_password "--port=$mariadb_port"
../python/python.exe ../../scripts/update_myini.py data/my.ini
Write-Output "[INFO] Creating user for ARTEMiS..."
$process = Start-Process -NoNewWindow -PassThru -RedirectStandardError "NUL" .\bin\mysqld.exe --console
bin/mysql.exe --user=root --password=$mariadb_root_password -e "$((Get-Content ../../scripts/artemis.sql) -replace "%%PASSWORD%%", "$mariadb_aime_password")"
# don't stop mysqld yet, artemis will need it
# remove mariadb junk
$junk_extensions = ".pdb",".lib"
$exclusions = "mysqld","mysql","server"
Get-ChildItem bin | ForEach-Object {
if ($junk_extensions.Contains($_.Extension)) {
Remove-Item $_.FullName
return
}
if ($exclusions.Contains($_.BaseName)) { return }
Remove-Item $_.FullName
}
Remove-Item -Recurse include
Get-ChildItem -Recurse lib | ForEach-Object {
if ($junk_extensions.Contains($_.Extension)) {
Remove-Item $_.FullName
return
}
# other storage engines, we don't care, only innodb for you
if ($_.BaseName.StartsWith("ha_")) {
Remove-Item $_.FullName
}
}
Remove-Item share/*.sql
Remove-Item share/*.jar
Get-ChildItem -Directory share | ForEach-Object {
if ($_.BaseName -ne "english") {
Remove-Item -Recurse $_.FullName
}
}
../python/python.exe ../../scripts/remove_mariadb_languages.py share/errmsg-utf8.txt
Set-Location ..
# ----------------------------------------------------
# Setting up ARTEMiS
# ----------------------------------------------------
Write-Output "[INFO] Downloading ARTEMiS..."
git.exe clone -b $artemis_branch "https://gitea.tendokyu.moe/$artemis_repo"
Set-Location artemis
Write-Output "[INFO] Installing dependencies..."
../python/python.exe -m pip install --no-warn-script-location -r requirements.txt
Write-Output "[INFO] Setting up ARTEMiS core configuration..."
Copy-Item -Recurse example_config config
../python/python.exe ../../scripts/update_artemis_config.py config/core.yaml "$mariadb_aime_password" "$mariadb_port"
Write-Output "[INFO] Generating ARTEMiS tables..."
../python/python.exe dbutils.py create
Set-Location ..
Stop-Process $process.Id
Remove-Item "mariadb/data/$env:ComputerName.*"
# ----------------------------------------------------
# Slim down Python install
# ----------------------------------------------------
python/python.exe -m pip uninstall -y mypy
Remove-Item python/pythonw.exe
Remove-Item -Recurse python/Include/*
Remove-Item -Recurse python/Scripts/*
Remove-Item -Recurse python/Lib/pydoc_data
# ----------------------------------------------------
# Pack things up
# ----------------------------------------------------
Copy-Item ../assets/dbutils.bat .
Copy-Item ../assets/read.bat .
Copy-Item ../assets/start.bat .
Copy-Item ../assets/update-artemis.bat .
New-Item scripts -ItemType Directory
Copy-Item ../assets/start.ps1 scripts/
$update_script = (Get-Content ../assets/update-artemis.ps1) -replace "%%ARTEMIS_REPO%%", "$artemis_repo" -replace "%%ARTEMIS_BRANCH%%", "$artemis_branch"
$update_script | Out-File -Force -FilePath scripts/update-artemis.ps1
$readme = (Get-Content ../assets/README.txt) -replace "%%MARIADB_ROOT_PASSWORD%%", "$mariadb_root_password" -replace "%%MARIADB_AIME_PASSWORD%%", "$mariadb_aime_password" -replace "%%MARIADB_PORT%%", "$mariadb_port"
$readme | Out-File -Force -FilePath README.txt
7z a -t7z ../artemis-portable.7z *
Set-Location ..