Debian Codegraph @

windows/msys-install.ps1

raw
1 <#
2 Install MSYS2 32-bit environment for BleachBit on Windows.
3 It installs in a portable style.
4 This script may be run in an empty directory like `c:\projects`.
5
6 Copyright (C) 2008-2025 Andrew Ziem
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #>
19
20 $ErrorActionPreference = "Stop"
21
22 #$msys_exe_fn = "msys2-x86_64-20241208.exe"
23 #$msys_exe_url = "https://github.com/msys2/msys2-installer/releases/download/2024-12-08/$msys_exe_fn"
24 #$msys_root = ".\msys2"
25 # The .sfx.exe file is a self-extracting archive built using 7-zip.
26 # The i686 version was last updated 2021.
27 $msys_exe_fn = "msys2-base-x86_64-20250830.sfx.exe"
28 $msys_exe_full_path = Join-Path -Path (Get-Location) -ChildPath $msys_exe_fn
29 $msys_exe_url = "https://github.com/msys2/msys2-installer/releases/download/2025-08-30/$msys_exe_fn"
30 $msys_root = ".\msys64"
31 if (-not (Test-Path $msys_exe_full_path)) {
32 Write-Host "Downloading MSYS2 from $msys_exe_url..."
33 Invoke-WebRequest -Uri $msys_exe_url -OutFile $msys_exe_full_path -ErrorAction Stop
34 } else {
35 Write-Host "MSYS2 is already downloaded."
36 }
37 $fileSizeMB = (Get-Item $msys_exe_full_path).Length
38 Write-Host "File size: $($fileSizeMB.ToString('N0')) bytes"
39 $fileHash = Get-FileHash -Path $msys_exe_full_path -Algorithm SHA256
40 Write-Host "File hash: $($fileHash.Hash)"
41
42 #$msys_root_install = Join-Path ("$msys_root", "..").Path | Resolve-Path
43 $msys_root_install = (Resolve-Path (Split-Path $msys_root -Parent)).Path
44 Write-Host "MSYS2 will be installed to $msys_root_install"
45
46 if (Test-Path "$msys_root\usr\bin\ls.exe") {
47 Write-Host "MSYS2 is already installed."
48 } else {
49 Write-Host "Installing MSYS2..."
50 Write-Host "Installer: $msys_exe_full_path"
51
52 try {
53 $p = Start-Process -FilePath "$msys_exe_full_path" -ArgumentList "-y -o$msys_root_install" -Wait -NoNewWindow -PassThru
54 if ($p.ExitCode -ne 0) {
55 Write-Error "Failed to install MSYS2, exit code: $($p.ExitCode)"
56 exit $p.ExitCode
57 }
58 } catch {
59 Write-Error "Exception during MSYS2 installation: $_"
60 exit 1
61 }
62 }
63
64 # Check whether $msys_root\home has any subdirectroes
65 #if ((Get-ChildItem -Path "$msys_root\home" -Directory).Count -gt 0) {
66 if (Test-Path "$msys_root\etc\hosts") {
67 Write-Host "MSYS2 was already initialized."
68 } else {
69 Start-Process -FilePath "$msys_root\msys2_shell.cmd" -ArgumentList "-defterm", "-here", "-no-start", "-msys", "-c", "exit" -Wait -NoNewWindow
70 }
71
72 $pacman_path = "$msys_root\usr\bin\pacman.exe"
73 if (-not (Test-Path $pacman_path)) {
74 Write-Error "Pacman not found in $pacman_path"
75 exit 1
76 }
77
78 # Update pacman without user interaction
79 function Update-Pacman {
80 Write-Host "Updating pacman and packages..."
81 $p = Start-Process "$pacman_path" -ArgumentList "-Syu", "--noconfirm" -Wait -NoNewWindow -PassThru
82 if ($p.ExitCode -ne 0) {
83 Write-Error "Failed to update pacman"
84 exit $p.ExitCode
85 }
86 }
87
88 Update-Pacman
89 # Run a second time to update remaining packages
90 Update-Pacman
91
92 $GETTEXT_PKG = "mingw-w64-x86_64-gettext-runtime"
93 $p = Start-Process "$pacman_path" -ArgumentList "-S", "$GETTEXT_PKG", "--noconfirm" -Wait -NoNewWindow -PassThru
94 if ($p.ExitCode -ne 0) {
95 Write-Error "Failed to install package $GETTEXT_PKG"
96 exit $p.ExitCode
97 }
98
99 Write-Host "Checking for msgunfmt.exe..."
100 Get-ChildItem -Path $msys_root -Filter msgunfmt.exe -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
101
102 $libintl_path = "$msys_root\mingw64\bin\libintl-8.dll"
103 if (-not (Test-Path $libintl_path)) {
104 Write-Error "libintl-8.dll not found in $libintl_path"
105 exit 1
106 }