-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBackup-Scoop.ps1
59 lines (44 loc) · 1.9 KB
/
Backup-Scoop.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"check scoop cache"
scoop cache
if ((Read-Host "Are you sure remove scoop cache? y/N") -eq "y") {
"remove scoop cache"
scoop cache rm *
}
"check apps install by scoop"
scoop list
"before backup, close all apps install by scoop"
if ((Read-Host "Are you sure all scoop apps had closed? y/N") -eq "y") {
#for run separately
$Destination = ""
#for run as a script file
$Destination = $PSScriptRoot
if (Test-Path $env:USERPROFILE\scoop\apps\7zip\current\) {
"Copy scoop's 7z.exe & 7z.dll to current path"
Copy-Item -Path "$env:USERPROFILE\scoop\apps\7zip\current\7z.dll" -Destination $Destination -Force
Copy-Item -Path "$env:USERPROFILE\scoop\apps\7zip\current\7z.exe" -Destination $Destination -Force
#Show-Tree -Path $env:USERPROFILE\scoop\apps\ -Depth 2 -ShowProperty mode
"Remove the `"current`" folder in scoop apps"
Get-Item $env:USERPROFILE\scoop\apps\*\current | ForEach-Object {
if ($_.mode -eq "d-r--l") {
# https://serverfault.com/questions/199921/force-remove-files-and-directories-in-powershell-fails-sometimes-but-not-always
cmd.exe /c rd /s /q $_.FullName
}
}
"backup scoop - add scoop folder to archive"
. (Join-Path $Destination "7z.exe") a $Destination\Scoop.7z $env:USERPROFILE\scoop\
"add the current folder back"
Get-ChildItem "$env:USERPROFILE\scoop\apps\" | Select-Object -ExpandProperty fullname | ForEach-Object {
if ((Get-ChildItem $_ | Select-Object -ExpandProperty name) -notcontains "current") {
$Target = Get-ChildItem $_ | Select-Object -First 1 | Select-Object -ExpandProperty fullname
New-Item -ItemType Junction -Path "$_\current" -Target $Target
}
}
scoop reset *
"Backup done, please enter to close the window"
Pause
} else {
"You should run `"scoop install 7z`" first"
}
} else {
"close the running scoop apps first"
}