Skip to content

Instantly share code, notes, and snippets.

@uyriq
Last active August 8, 2022 16:57
Show Gist options
  • Save uyriq/a13fc5259ed0563ebab3d0201b9badfc to your computer and use it in GitHub Desktop.
Save uyriq/a13fc5259ed0563ebab3d0201b9badfc to your computer and use it in GitHub Desktop.
bckp-restore "Slack" , "Microsoft VScode", "gnupg", "Notepad\+\+", "Notion" "figma"
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.CoreBuildTools",
"Microsoft.VisualStudio.Workload.MSBuildTools",
"Microsoft.VisualStudio.Component.Windows10SDK",
"Microsoft.VisualStudio.Component.VC.CoreBuildTools",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"Microsoft.VisualStudio.Component.Windows10SDK.19041",
"Microsoft.VisualStudio.Component.VC.CMake.Project",
"Microsoft.VisualStudio.Component.TestTools.BuildTools",
"Microsoft.VisualStudio.Component.VC.ASAN",
"Microsoft.VisualStudio.Component.TextTemplating",
"Microsoft.VisualStudio.Component.VC.CoreIde",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.Workload.VCTools"
]
}
Set-ExecutionPolicy RemoteSigned
#архив > 1 дня
$ruleForBackupDays = -1;
#AppData/Local
$filterLocalAppData = @("gnupg")
#AppData/Roaming
$filterAppData = @("gnupg", "Notepad\+\+")
Write-Host "before backup shutdown all procs as gnupg-agent, slack, etc, manually down" -ForegroundColor Yellow
write-host -noNewLine "Choice [0] for backup, [1] for restore, [2] to view hardcoded settings, [3] privacy tune by registry, [4] tune file rights for .ssh:"
$answer = read-host
if ($answer -eq $null) {
write-host -foregroundColor Red "Error: have to specify 0,1,2,3,4 "
exit
}
switch ( $answer ) {
0 {
$lastModifiedDate1 = (Get-Item "$env:OneDrive\LocalAPPDATA.zip" -ErrorAction SilentlyContinue ).LastWriteTime
$lastModifiedDate2 = (Get-Item "$env:OneDrive\APPDATA.zip" -ErrorAction SilentlyContinue).LastWriteTime
$checkIs = ( ( $lastModifiedDate1 -le (Get-Date).AddDays($ruleForBackupDays)) -or ($lastModifiedDate2 -le (Get-Date).AddDays($ruleForBackupDays) ));
Write-Host "backup stage" -ForegroundColor Cyan
Write-Host "check for days rule at least $ruleForBackupDays is behind: $checkIs"
if ($lastModifiedDate1 -le (Get-Date).AddDays($ruleForBackupDays)) {
Write-Host "rule check is OK, backup LOCALAPPDATA for $($filterLocalAppData -join ', ') " -ForegroundColor Cyan
$list_local = Get-ChildItem $env:LOCALAPPDATA | Select-String -Pattern $filterLocalAppData ;
$list_local | ForEach-Object { Compress-Archive -Path $env:LOCALAPPDATA\$_ -DestinationPath $env:OneDrive\LOCALAPPDATA.zip -Update -CompressionLevel Fastest ; "done: $_" }
}
if ($lastModifiedDate2 -le (Get-Date).AddDays($ruleForBackupDays)) {
Write-Host "backup APPDATA for $($filterAppData -join ', ') " -ForegroundColor Cyan
$list_roam = Get-ChildItem $env:APPDATA | Select-String -Pattern $filterAppData ;
$list_roam | ForEach-Object { Compress-Archive -Path $env:APPDATA\$_ -DestinationPath $env:OneDrive\APPDATA.zip -Update -CompressionLevel Fastest ; "done: $_" }
}
$lastModifiedDate1 = (Get-Item "$env:OneDrive\LocalAPPDATA.zip" -ErrorAction SilentlyContinue ).LastWriteTime
$lastModifiedDate2 = (Get-Item "$env:OneDrive\APPDATA.zip" -ErrorAction SilentlyContinue).LastWriteTime
Write-Host "DONE backup for LOCALAPPDATA: $lastModifiedDate1, APPDATA: $lastModifiedDate2" -ForegroundColor Cyan
exit
}
# ...
1 {
Write-Host "restore stage" -ForegroundColor Cyan
# Expand-Archive -Path $env:OneDrive\LOCALAPPDATA.zip -DestinationPath $env:LOCALAPPDATA
# Expand-Archive -Path $env:OneDrive\APPDATA.zip -DestinationPath $env:APPDATA
winget -v
if ($? -eq $false) { Write-Host "for app install winget is needed, visit https://github.com/microsoft/winget-cli" -ForegroundColor Yellow; exit }
# winget install 7zip.7zip
# winget install Microsoft.VisualStudioCode
# winget install git.git
# winget install GitHub.cli
# winget install GnuPG.GnuPG
# winget install Notepad++.Notepad++
# winget install JanDeDobbeleer.OhMyPosh -s winget
# oh-my-posh font install
# Write-Host "please open new terminal to install font " -ForegroundColor Yellow; Write-Host "press any to open new term and select font, install then press ctrl-c ... " -ForegroundColor Cyan ; cmd /c pause | out-null
# Start-Process -Wait -UseNewEnvironment -FilePath 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -ArgumentList '-Command "oh-my-posh font install ; exit "'
Invoke-WebRequest https://aka.ms/vs/17/release/vs_BuildTools.exe -outfile ".\vs_BuildTools.exe"
Write-Host " for Microsoft.VisualStudio.2022.BuildTools please select c++ dev tool to be installed " -ForegroundColor Yellow; Start-Sleep -Seconds 5
winget install Microsoft.VisualStudio.2022.BuildTools
Start-Process -Wait ".\vs_buildtools.exe" -ArgumentList "--config $env:OneDrive\.vsconfig"
winget install Microsoft.DotNet.DesktopRuntime.6
winget install Notion.Notion
winget install TablePlus.TablePlus
# winget install OBSProject.OBSStudio
# winget install Docker.DockerDesktop
Invoke-WebRequest https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe -OutFile "rustup-init.exe"
Start-Process -Wait ".\rustup-init.exe"
# cargo install fnm
Write-Host "for cargo restart needed, try open new terminal wait for 'cargo install fnm ; fnm install v16.16.0 ' then press ctrl-c, note, for compilee rust that you need Microsoft.VisualStudio.2022.BuildTools with c++ 1.6gig installed " -ForegroundColor Yellow; Write-Host " press any now ... " -ForegroundColor Cyan ; cmd /c pause | out-null
Start-Process -Wait -FilePath 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -ArgumentList '-Command " cargo install fnm ; fnm install v16.16.0; exit "'
Write-Host "restore stage is done " -ForegroundColor Cyan
exit
}
2 {
Get-Content -Path $PSCommandPath | Select-String -Pattern "\s{8}winget install", "\s{8}cargo install", "\s{8}fnm install", "\s{8}Invoke-WebRequest", '\SruleForBackupDays\s+=', '\SfilterLocalAppData =', '\SfilterAppData ='
Write-Host "these are hardcoded settings for $PSCommandPath may change it by edit file directly" -ForegroundColor Yellow; Write-Host "press any to exit ... " -ForegroundColor Cyan ; cmd /c pause | out-null
exit;
}
3 {
##########################################
# Personal Preferences on UI and Privacy #
##########################################
write-host "enable restore at 720 min interval"
If (-Not (Test-Path "HKLM:Software\Microsoft\Windows NT\CurrentVersion\SystemRestore" )) {
New-Item -Path "HKLM:Software\Microsoft\Windows NT\CurrentVersion" -Name SystemRestore | Out-Null}
Set-ItemProperty -Path "HKLM:Software\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -Type DWord -Value 720
Checkpoint-Computer -Description "ChangeSettings" -RestorePointType MODIFY_SETTINGS
Write-Output "Privacy: Let apps use my advertising ID: Disable "
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Name Enabled -Type DWord -Value 0
# To Restore:
#Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Name Enabled -Type DWord -Value 1
Write-Output "WiFi Sense: Shared HotSpot Auto-Connect: Disable"
Set-ItemProperty -Path HKLM:\Software\Microsoft\PolicyManager\default\WiFi\AllowAutoConnectToWiFiSenseHotspots -Name value -Type DWord -Value 0
Write-Output "Activity Tracking: Disable"
@('EnableActivityFeed', 'PublishUserActivities', 'UploadUserActivities') | % { Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\System -Name $_ -Type DWord -Value 0 }
Write-Output "Start Menu: Disable Bing Search Results"
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name BingSearchEnabled -Type DWord -Value 0
# To Restore (Enabled):
# Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name BingSearchEnabled -Type DWord -Value 1
Write-Output "Disable Telemetry (requires a reboot to take effect)"
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type DWord -Value 0
Get-Service DiagTrack, Dmwappushservice | Stop-Service | Set-Service -StartupType Disabled
Write-Output "Disable the Lock Screen (the one before password prompt - to prevent dropping the first character)"
If (-Not (Test-Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization)) {
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows -Name Personalization | Out-Null
}
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization -Name NoLockScreen -Type DWord -Value 1
# To Restore:
#Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization -Name NoLockScreen -Type DWord -Value 1
Write-Output "Dark Theme for Windows "
If (-Not (Test-Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize)) {
New-Item -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes -Name Personalize | Out-Null
}
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Type DWord -Value 0
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Type DWord -Value 0
# To Restore (Light Theme):
#Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Type DWord -Value 1
#Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Type DWord -Value 1
}
4 {
$list=Get-Item -Path $env:USERPROFILE\.ssh\* -Exclude known*;
if ($? -eq $false) {Write-Host "no .ssh folder? feel free to copy one, for now exiting"; exit}
$list | % {
Icacls $_.FullName /c /t /Inheritance:d;
Icacls $_.FullName /c /t /Grant ${env:UserName}:F;
$acl = Get-Acl $_ ;
$acl.Access | %{$acl.RemoveAccessRule($_)} | Out-Null;
$acl.SetAccessRuleProtection($true,$true);
Set-Acl $_.FullName $acl;
TakeOwn /F $_.FullName;
}
}
default { write-host -foregroundColor Red "Error: have to specify 0,1,2,3,4" ; exit }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment