################################################################################ # Intro # ################################################################################ param ( [string]$target = "C:\cygwin", [switch]$noshortcuts = $false, [switch]$soundsrv = $false ) "Cathedral Cygwin Install Script" ################################################################################ # Various settings # ################################################################################ $scriptPath = $MyInvocation.MyCommand.Definition $mirror = "cygwin.cathedral-networks.org" $psArgs = @( '-NoProfile', '-NoLogo', '-NonInteractive', '-ExecutionPolicy Bypass', "-File `"$($scriptPath)`"" ) ################################################################################ # Cygwin installation options # ################################################################################ $packages = $( "cron" "vim" "openssh" "autossh" "nc" "wget" "curl" "rsync" ) if ($soundsrv) { $packages += "pulseaudio" } $installerArgs = $( "--only-site" "--site `"http://${mirror}`"" "--root `"$target`"" "--local-package-dir `"${target}\packages`"" "--no-desktop" "--upgrade-also" "--delete-orphans" "--packages $($packages -join ',')" "--quiet-mode" "--verbose" ) if ($noshortcuts) { $installerArgs += "--no-shortcuts" } ################################################################################ # How to get the fully qualified domain name of this machine # ################################################################################ function GetFQDN { $objIPProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties() $fqdn = “{0}.{1}” -f $objIPProperties.HostName, $objIPProperties.DomainName if ($fqdn.EndsWith(".")) { $fqdn = $fqdn.Substring(0, $fqdn.Length-1) } return $fqdn.ToLowerInvariant() } ################################################################################ # How to check if we're running as an administrator # ################################################################################ function IsAdmin { return ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") } ################################################################################ # It begins... # ################################################################################ "==> Detecting current environment" "PID: $PID" ################################################################################ # Get the current user # ################################################################################ $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name "Running as: $currentUser" ################################################################################ # Get the computer name # ################################################################################ $compName = GetFQDN "FQDN: $compName" ################################################################################ # Get the computer architecture # ################################################################################ $arch = (Get-WmiObject -Class Win32_OperatingSystem -ea 0).OSArchitecture "Architecture: $arch" switch -Wildcard ($arch) { '32-*' { $setup = "setup-x86.exe" $installerArgs += "--arch x86" } '64-*' { $setup = "setup-x86_64.exe" $installerArgs += "--arch x86_64" } default { Write-Error "Unknown architecture: $arch"; exit 10 } } ################################################################################ # Make sure we have administrator privileges # ################################################################################ "==> Verifying privileges" if (!(IsAdmin)) { $adminArgs = $psArgs + "$target" if ($noshortcuts) { $adminArgs += "-noshortcuts" } Start-Process "PowerShell.exe" -ArgumentList $adminArgs -Verb RunAs exit 0 } ################################################################################ # Set up a temporary directory to work with # ################################################################################ "==> Setting up temp directory" $guid = [System.Guid]::NewGuid().ToString() $tmp = ($env:TEMP + "\" + $guid) New-Item -Type Directory -Force -Path $tmp | Out-Null ################################################################################ # Windows 7 (and probably others) need to be told to use TLS 1.2 # ################################################################################ if (!(Get-WmiObject Win32_OperatingSystem).Version.StartsWith("10.")) { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } ################################################################################ # Download and install # ################################################################################ pushd $tmp "==> Downloading installer" Invoke-WebRequest "https://${mirror}/cathedral/${setup}" -OutFile "setup.exe" "==> Installing" Start-Process -Wait -NoNewWindow ".\setup.exe" -ArgumentList $installerArgs "==> Rebasing" Start-Process -Wait -NoNewWindow "${target}\bin\dash.exe" -WorkingDirectory "${target}\bin" -ArgumentList "-c '/usr/bin/peflagsall -v'" Start-Process -Wait -NoNewWindow "${target}\bin\dash.exe" -WorkingDirectory "${target}\bin" -ArgumentList "-c '/usr/bin/rebaseall -v'" popd ################################################################################ # Cleanup # ################################################################################ "==> Cleanup" Remove-Item -Recurse -Force $tmp ################################################################################ # Hopefully everything went well... # ################################################################################ "==> Exit" # vim: tabstop=4:softtabstop=4:shiftwidth=4:noexpandtab