forked from libyal/libewf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyncbzip2.ps1
63 lines (48 loc) · 1.53 KB
/
syncbzip2.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
60
61
62
# Script that synchronizes bzip2.
#
# Version: 20171105
$ExitSuccess = 0
$ExitFailure = 1
Function DownloadFile($Url, $Destination)
{
$Client = New-Object Net.WebClient
${Client}.DownloadFile(${Url}, ${Destination})
}
Function ExtractTarGz($Filename)
{
$SevenZip = "C:\Program Files\7-Zip\7z.exe"
If (-Not (Test-Path ${SevenZip}))
{
Write-Host "Missing 7z.exe." -foreground Red
Exit ${ExitFailure}
}
# Run 7z twice first to extract the .gz then the .tar
# PowerShell will raise NativeCommandError if 7z writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
# The leading & and single quotes are necessary to compensate for the spaces in the path.
$Output = Invoke-Expression -Command "& '${SevenZip}' -y x ${Filename} 2>&1"
$Filename = ${Filename}.TrimEnd(".gz")
$Output = Invoke-Expression -Command "& '${SevenZip}' -y x ${Filename} 2>&1"
Remove-Item -Path ${Filename} -Force
}
$Version = "1.0.6"
$Filename = "${pwd}\bzip2-${Version}.tar.gz"
$Url = "http://www.bzip.org/${Version}/bzip2-${Version}.tar.gz"
$ExtractedPath = "bzip2-${Version}"
$DestinationPath = "..\bzip2"
If (Test-Path ${Filename})
{
Remove-Item -Path ${Filename} -Force
}
DownloadFile -Url ${Url} -Destination ${Filename}
If (Test-Path ${ExtractedPath})
{
Remove-Item -Path ${ExtractedPath} -Force -Recurse
}
ExtractTarGz -Filename ${Filename}
Remove-Item -Path ${Filename} -Force
If (Test-Path ${DestinationPath})
{
Remove-Item -Path ${DestinationPath} -Force -Recurse
}
Move-Item ${ExtractedPath} ${DestinationPath}