From b0ff6ce47733311412f37f15929d3d86b4331626 Mon Sep 17 00:00:00 2001 From: Aaron Jackson Date: Wed, 31 Jul 2024 09:12:21 +0100 Subject: [PATCH 1/3] Make autohibernate autoshutdown on Windows, hibernate not working on 2022 --- modules/autohibernate.ps1 | 50 ++++++++++++++------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/modules/autohibernate.ps1 b/modules/autohibernate.ps1 index 0d233af..8328a22 100644 --- a/modules/autohibernate.ps1 +++ b/modules/autohibernate.ps1 @@ -1,17 +1,12 @@ -$ramGB = (Get-CimInstance Win32_PhysicalMemory).Capacity / 1024 / 1024 / 1024 - if ($null -eq $Env:AUTOHIBERNATE_TIME) { $Env:AUTOHIBERNATE_TIME = 120 } -# Windows cannot hibernate (at least in AWS) if it has more than 16GB -# of RAM. Instead we'll forcefully shutdown the instance because EC2 -# is expensive! -if ($ramGB -gt 16) { - $idleScript = "C:\workdir\idleshutdown.ps1" - New-Item $idleScript - Set-Content $idleScript @" + +$idleScript = "C:\workdir\idleshutdown.ps1" +New-Item $idleScript +Set-Content $idleScript @" `$quser = quser | ForEach-Object -Process { `$_ -replace '\s{2,21}',',' } | ConvertFrom-Csv `$session = `$quser | Where-Object {{ `$_.SessionName -like "rdp-tcp*" -or `$_.State -eq "Disc" }} @@ -30,26 +25,17 @@ if (`$idleTime.TotalMinutes -ge $Env:AUTOHIBERNATE_TIME) { } "@ - $action = New-ScheduledTaskAction -Execute powershell.exe ` - -Argument "-File $idleScript" - $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) ` - -RepetitionInterval (New-TimeSpan -Minutes 1) ` - -RepetitionDuration (New-TimeSpan -Days 3650) - $principal = New-ScheduledTaskPrincipal ` - -UserID "NT AUTHORITY\SYSTEM" ` - -LogonType ServiceAccount - - Register-ScheduledTask "ShutdownIdle" ` - -Action $action ` - -Principal $principal ` - -Trigger $trigger ` - -Force -} else { - powercfg /change hibernate-timeout-ac $Env:AUTOHIBERNATE_TIME - - $shell = New-Object -ComObject WScript.Shell - $shortcut = $shell.CreateShortcut([Environment]::GetFolderPath("Desktop") + "\Hibernate.lnk") - $shortcut.TargetPath = "C:\Windows\System32\shutdown.exe" - $shortcut.Arguments = "/h" - $shortcut.Save() -} +$action = New-ScheduledTaskAction -Execute powershell.exe ` + -Argument "-File $idleScript" +$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) ` + -RepetitionInterval (New-TimeSpan -Minutes 1) ` + -RepetitionDuration (New-TimeSpan -Days 3650) +$principal = New-ScheduledTaskPrincipal ` + -UserID "NT AUTHORITY\SYSTEM" ` + -LogonType ServiceAccount + +Register-ScheduledTask "ShutdownIdle" ` + -Action $action ` + -Principal $principal ` + -Trigger $trigger ` + -Force From b2eed435df27ce8629cd2a37b0d66bb059f4c852 Mon Sep 17 00:00:00 2001 From: Aaron Jackson Date: Wed, 31 Jul 2024 09:28:13 +0100 Subject: [PATCH 2/3] Fix libreoffice and rstudio versions --- modules/libreoffice.ps1 | 4 ++-- modules/rstudio.ps1 | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/libreoffice.ps1 b/modules/libreoffice.ps1 index acb7951..87acfe8 100644 --- a/modules/libreoffice.ps1 +++ b/modules/libreoffice.ps1 @@ -3,8 +3,8 @@ $ProgressPreference = 'SilentlyContinue' # Disable (slow) progress bar Set-Location C:\Tools -$LIBRE_VERSION = "24.2.3" -$LIBRE_HASH = "12b988318452120d31a4c618bc6ac314ad3bf99157584d0c2bf6029801a4cf31" +$LIBRE_VERSION = "24.2.5" +$LIBRE_HASH = "cad625d119db4720df5270fa2d860e0ed56d6e374b878e19a3cab4af68f1f54f" $LIBRE_URL = "https://mirrors.ukfast.co.uk/sites/documentfoundation.org/tdf/libreoffice/stable/${LIBRE_VERSION}/win/x86_64/LibreOffice_${LIBRE_VERSION}_Win_x86-64.msi" diff --git a/modules/rstudio.ps1 b/modules/rstudio.ps1 index bda50df..37f78e9 100644 --- a/modules/rstudio.ps1 +++ b/modules/rstudio.ps1 @@ -4,10 +4,10 @@ $ProgressPreference = "SilentlyContinue" # PS progress bar is slow $ErrorActionPreference = "Stop" # R environment -Invoke-WebRequest -Uri "https://cloud.r-project.org/bin/windows/base/R-4.4.0-win.exe" -OutFile C:\Tools\R-installer.exe +Invoke-WebRequest -Uri "https://cloud.r-project.org/bin/windows/base/R-4.4.1-win.exe" -OutFile C:\Tools\R-installer.exe Start-Process C:\Tools\R-installer.exe -ArgumentList "/VERYSILENT","/NORESTART" -NoNewWindow -Wait -PassThru -Invoke-WebRequest -Uri "https://download1.rstudio.org/electron/windows/RStudio-2024.04.1-748.exe" -OutFile C:\Tools\RStudio-installer.exe +Invoke-WebRequest -Uri "https://download1.rstudio.org/electron/windows/RStudio-2024.04.2-764.exe" -OutFile C:\Tools\RStudio-installer.exe Start-Process C:\Tools\RStudio-installer.exe -ArgumentList "/S" -NoNewWindow -Wait -PassThru Invoke-WebRequest -Uri "https://cran.r-project.org/bin/windows/Rtools/rtools44/files/rtools44-6104-6039.exe" -OutFile C:\Tools\RTools.exe @@ -17,7 +17,7 @@ Start-Process C:\Tools\RTools.exe -ArgumentList "/VERYSILENT" -NoNewWindow -Wait $pkgs = "tidyverse","odbc","dbi","qqman","metafor","tidyr","ggplot2",` "hmisc","data.table","dplyr","lubridate","survival","survminer" foreach ($pkg in $pkgs) { - & "C:\Program Files\R\R-4.4.0\bin\Rscript.exe" ` + & "C:\Program Files\R\R-4.4.1\bin\Rscript.exe" ` -e "install.packages('$pkg', repos='http://cran.uk.r-project.org')" } @@ -34,5 +34,5 @@ local({r <- getOption("repos") # Set timezone Sys.setenv(TZ='Europe/London') "@ -Set-Content "C:\Program Files\R\R-4.4.0\etc\Rprofile.site" $RConfig +Set-Content "C:\Program Files\R\R-4.4.1\etc\Rprofile.site" $RConfig Set-Content "C:\Users\Administrator\Documents\.Renviron" "RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING=1" From 2d1310737ee2bf34cb585babf9e4274c6f4beb6a Mon Sep 17 00:00:00 2001 From: Aaron Jackson Date: Wed, 31 Jul 2024 09:28:30 +0100 Subject: [PATCH 3/3] C:\workdir doesn't exist during packer build --- modules/autohibernate.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/autohibernate.ps1 b/modules/autohibernate.ps1 index 8328a22..5e22ffc 100644 --- a/modules/autohibernate.ps1 +++ b/modules/autohibernate.ps1 @@ -4,7 +4,7 @@ if ($null -eq $Env:AUTOHIBERNATE_TIME) { } -$idleScript = "C:\workdir\idleshutdown.ps1" +$idleScript = "C:\Tools\idleshutdown.ps1" New-Item $idleScript Set-Content $idleScript @" `$quser = quser | ForEach-Object -Process { `$_ -replace '\s{2,21}',',' } | ConvertFrom-Csv