function Download-File { param ( [string]$Url, [string]$File ) Write-Host "Downloading $Url to $File" [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Invoke-WebRequest -Uri $url -OutFile $File } function Remove-Directory { param ( [string]$Path ) if ([System.IO.Directory]::Exists($Path)) { Write-Host "Deleting $Path" [System.IO.Directory]::Delete($Path, $true) } } function Unzip-File { param( [string]$File, [string]$Destination = (Get-Location).Path ) $FilePath = Resolve-Path $File $DestinationPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Destination) If ($PSVersionTable.PSVersion.Major -ge 3) { [System.IO.Compression.ZipFile]::ExtractToDirectory("$FilePath", "$DestinationPath") } else { throw "Unzip-File is not supported on PowerShell versions less than 3.0" } } function Move-DirectoryContent { param ( [string]$Source, [string]$Destination ) $SourcePath = Resolve-Path $Source $DestinationPath = Resolve-Path $Destination Write-Output "Moving content of $SourcePath to $DestinationPath" Get-ChildItem -Path $SourcePath -Recurse | Move-Item -Destination $DestinationPath } $UserName = "tsugami" $RepoName = "dotfiles" $Branch = "master" $DotfileTmpDir = $env:TEMP $SourceFile = Join-Path $DotfileTmpDir "dotfiles.zip" $DestPath = Join-Path $env:userprofile ".dotfiles" Download-File "https://github.com/$UserName/$RepoName/archive/$Branch.zip" $SourceFile Remove-Directory $DestPath Unzip-File $SourceFile $DestPath $ZipOutputDir = Join-Path $DestPath "$RepoName-$Branch" Move-DirectoryContent $ZipOutputDir $DestPath Remove-Directory $ZipOutputDir