Advertisement
Guest User

ps

a guest
May 17th, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.66 KB | None | 0 0
  1. PS D:\> $userSvmPath = $env:USERPROFILE + "\.svm"
  2.  
  3. #
  4. # helper functions
  5. #
  6. function Write-TitleMessage
  7. {
  8. param (
  9. [string] $message
  10. )
  11. Write-Host $("{0}" -f "`n $message `n") -BackgroundColor DarkGray -ForegroundColor Black
  12. }
  13. function Write-InfoMessage
  14. {
  15. param (
  16. [string] $message
  17. )
  18. Write-Host $("{0}" -f " $message ")
  19. }
  20.  
  21. function Write-ErrorMessage
  22. {
  23. param (
  24. [string] $message
  25. )
  26. Write-Host $("{0}" -f " $message ") -BackgroundColor DarkRed -ForegroundColor White
  27. }
  28.  
  29. function String-IsEmptyOrWhitespace
  30. {
  31. param (
  32. [string] $str
  33. )
  34. return [string]::IsNullOrEmpty($str) -or $str.Trim().length -eq 0
  35. }
  36.  
  37. function New-SvmInstallLocation
  38. {
  39. param (
  40. [string] $installPath
  41. )
  42.  
  43. if (Test-Path $installPath)
  44. {
  45. Write-InfoMessage "An existing svm installation was found at '$installPath'. This will be upgraded."
  46. $paths = Get-ChildItem "$installPath" -Exclude ("version", "versions")
  47. foreach ($path in $paths)
  48. {
  49. if ($path.PSIsContainer -eq $true) { [System.IO.Directory]::Delete($path.FullName, $true) }
  50. else { [System.IO.File]::Delete($path.FullName) }
  51. }
  52. }
  53. else
  54. {
  55. Write-InfoMessage "Creating svm install location at '$installPath'."
  56. New-Item $installPath -type Directory | Out-Null
  57. }
  58. }
  59.  
  60. function Download-SvmPackage
  61. {
  62. param (
  63. [string] $url,
  64. [string] $downloadPath
  65. )
  66.  
  67. Write-InfoMessage "Downloading svm install package from '$url'."
  68.  
  69. New-Item $([System.IO.Path]::GetDirectoryName($downloadPath)) -type Directory | Out-Null
  70. $wc = New-Object System.Net.WebClient
  71. $wc.DownloadFile($url, $downloadPath)
  72. }
  73.  
  74. function Install-SvmPackage
  75. {
  76. param (
  77. [string] $downloadPath,
  78. [string] $installPath
  79. )
  80.  
  81. Write-InfoMessage "Installing svm to '$installPath'."
  82.  
  83. $unzipFolder = [System.IO.Path]::ChangeExtension($downloadPath, $null).TrimEnd('.')
  84. New-Item $unzipFolder -type Directory | Out-Null
  85.  
  86. # Use the shell to uncompress the zip file
  87. $shellApp = New-Object -com shell.application
  88. $zipFile = $shellApp.namespace($downloadPath)
  89. $destination = $shellApp.namespace($unzipFolder)
  90. $destination.CopyHere($zipFile.items(), 0x14) #0x4 = don't show UI, 0x10 = overwrite files
  91.  
  92. # Only copy Windows specific contents into the install folder
  93. $zipFolderToExtract = [System.IO.Path]::Combine($unzipFolder, 'svm-0.4.2', 'src', 'bin')
  94. Remove-Item -Path $([System.IO.Path]::Combine($zipFolderToExtract, 'svm'))
  95. Copy-Item -Path $zipFolderToExtract -Recurse -Destination $installPath
  96. $zipFolderToExtract = [System.IO.Path]::Combine($unzipFolder, 'svm-0.4.2', 'src', 'shims')
  97. Remove-Item -Path $([System.IO.Path]::Combine($zipFolderToExtract, 'scriptcs'))
  98. Copy-Item -Path $zipFolderToExtract -Recurse -Destination $installPath
  99.  
  100. # TODO - remove temp download folder
  101. }
  102.  
  103. function Configure-Environment
  104. {
  105. param (
  106. [string] $installPath
  107. )
  108.  
  109. Write-InfoMessage "Configuring path environment variables for svm."
  110.  
  111. $envPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
  112.  
  113. $foldersToPrependToPath = @()
  114. $foldersToPrependToPath += [System.IO.Path]::Combine($installPath, 'bin')
  115. $foldersToPrependToPath += [System.IO.Path]::Combine($installPath, 'shims')
  116. $newPath = ($foldersToPrependToPath)
  117.  
  118. if (!$(String-IsEmptyOrWhitespace( $envPath )))
  119. {
  120. foreach($path in $envPath.Split(';'))
  121. {
  122. if (!$foldersToPrependToPath.Contains($path)) { $newPath += $path }
  123. }
  124. }
  125. $path = [String]::Join(';', $newPath)
  126.  
  127. # set user path
  128. [Environment]::SetEnvironmentVariable("Path", $path, [System.EnvironmentVariableTarget]::User)
  129. }
  130.  
  131. #
  132. # installer
  133. #
  134. Write-TitleMessage "scriptcs version manager - installer"
  135.  
  136. $installPath = $userSvmPath
  137. $url = "https://github.com/scriptcs-contrib/svm/archive/v0.4.2.zip"
  138. $downloadPath = [System.IO.Path]::Combine($env:TEMP, [Guid]::NewGuid(), 'svm-install.zip')
  139.  
  140. New-SvmInstallLocation $installPath
  141. Download-SvmPackage -url $url -downloadPath $downloadPath
  142. Install-SvmPackage -downloadPath $downloadPath -installPath $installPath
  143. Configure-Environment $installPath
  144.  
  145. Write-InfoMessage "Successfully installed!"
  146. Write-InfoMessage "`nStart a new console and run 'svm help' to get started."
  147.  
  148. scriptcs version manager - installer
  149.  
  150. Не удается найти перегрузку для "Combine" и количества аргументов: "3".
  151. строка:138 знак:42
  152. + $downloadPath = [System.IO.Path]::Combine <<<< ($env:TEMP, [Guid]::NewGuid(), 'svm-ins
  153. tall.zip')
  154. + CategoryInfo : NotSpecified: (:) [], MethodException
  155. + FullyQualifiedErrorId : MethodCountCouldNotFindBest
  156.  
  157. An existing svm installation was found at 'C:\Users\Akigami\.svm'. This will be upgraded
  158. .
  159. Исключение при вызове "Delete" с "1" аргументами: "Путь имеет недопустимую форму."
  160. строка:50 знак:38
  161. + else { [System.IO.File]::Delete <<<< ($path.FullName) }
  162. + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  163. + FullyQualifiedErrorId : DotNetMethodException
  164.  
  165. Downloading svm install package from 'https://github.com/scriptcs-contrib/svm/archive/v0
  166. .4.2.zip'.
  167. Исключение при вызове "GetDirectoryName" с "1" аргументами: "Путь имеет недопустимую фор
  168. му."
  169. строка:69 знак:48
  170. + New-Item $([System.IO.Path]::GetDirectoryName <<<< ($downloadPath)) -type Directory
  171. | Out-Null
  172. + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  173. + FullyQualifiedErrorId : DotNetMethodException
  174.  
  175. New-Item : Не удается привязать аргумента к параметру "Path", так как он имеет значение
  176. NULL.
  177. строка:69 знак:11
  178. + New-Item <<<< $([System.IO.Path]::GetDirectoryName($downloadPath)) -type Directory
  179. | Out-Null
  180. + CategoryInfo : InvalidData: (:) [New-Item], ParameterBindingValidationEx
  181. ception
  182. + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.
  183. PowerShell.Commands.NewItemCommand
  184.  
  185. Исключение при вызове "DownloadFile" с "2" аргументами: "Исключение во время запроса Web
  186. Client."
  187. строка:71 знак:19
  188. + $wc.DownloadFile <<<< ($url, $downloadPath)
  189. + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  190. + FullyQualifiedErrorId : DotNetMethodException
  191.  
  192. Installing svm to 'C:\Users\Akigami\.svm'.
  193. New-Item : Не удается привязать аргумент к параметру "Path", так как он представляет соб
  194. ой пустую строку.
  195. строка:84 знак:11
  196. + New-Item <<<< $unzipFolder -type Directory | Out-Null
  197. + CategoryInfo : InvalidData: (:) [New-Item], ParameterBindingValidationEx
  198. ception
  199. + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Mic
  200. rosoft.PowerShell.Commands.NewItemCommand
  201.  
  202. Не удается найти перегрузку для "Combine" и количества аргументов: "4".
  203. строка:93 знак:50
  204. + $zipFolderToExtract = [System.IO.Path]::Combine <<<< ($unzipFolder, 'svm-0.4.2', 'sr
  205. c', 'bin')
  206. + CategoryInfo : NotSpecified: (:) [], MethodException
  207. + FullyQualifiedErrorId : MethodCountCouldNotFindBest
  208.  
  209. Remove-Item : Не удается найти путь "D:\svm", так как он не существует.
  210. строка:94 знак:14
  211. + Remove-Item <<<< -Path $([System.IO.Path]::Combine($zipFolderToExtract, 'svm'))
  212. + CategoryInfo : ObjectNotFound: (D:\svm:String) [Remove-Item], ItemNotFou
  213. ndException
  214. + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemComm
  215. and
  216.  
  217. Copy-Item : Не удается привязать аргумента к параметру "Path", так как он имеет значение
  218. NULL.
  219. строка:95 знак:18
  220. + Copy-Item -Path <<<< $zipFolderToExtract -Recurse -Destination $installPath
  221. + CategoryInfo : InvalidData: (:) [Copy-Item], ParameterBindingValidationE
  222. xception
  223. + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.
  224. PowerShell.Commands.CopyItemCommand
  225.  
  226. Не удается найти перегрузку для "Combine" и количества аргументов: "4".
  227. строка:96 знак:50
  228. + $zipFolderToExtract = [System.IO.Path]::Combine <<<< ($unzipFolder, 'svm-0.4.2', 'sr
  229. c', 'shims')
  230. + CategoryInfo : NotSpecified: (:) [], MethodException
  231. + FullyQualifiedErrorId : MethodCountCouldNotFindBest
  232.  
  233. Remove-Item : Не удается найти путь "D:\scriptcs", так как он не существует.
  234. строка:97 знак:14
  235. + Remove-Item <<<< -Path $([System.IO.Path]::Combine($zipFolderToExtract, 'scriptcs')
  236. )
  237. + CategoryInfo : ObjectNotFound: (D:\scriptcs:String) [Remove-Item], ItemN
  238. otFoundException
  239. + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemComm
  240. and
  241.  
  242. Copy-Item : Не удается привязать аргумента к параметру "Path", так как он имеет значение
  243. NULL.
  244. строка:98 знак:18
  245. + Copy-Item -Path <<<< $zipFolderToExtract -Recurse -Destination $installPath
  246. + CategoryInfo : InvalidData: (:) [Copy-Item], ParameterBindingValidationE
  247. xception
  248. + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.
  249. PowerShell.Commands.CopyItemCommand
  250.  
  251. Configuring path environment variables for svm.
  252. Произошла ошибка при вызове метода, так как [System.Object[]] не содержит метод с именем
  253. "Contains".
  254. строка:122 знак:44
  255. + if (!$foldersToPrependToPath.Contains <<<< ($path)) { $newPath += $path }
  256. + CategoryInfo : InvalidOperation: (Contains:String) [], RuntimeException
  257. + FullyQualifiedErrorId : MethodNotFound
  258.  
  259. Произошла ошибка при вызове метода, так как [System.Object[]] не содержит метод с именем
  260. "Contains".
  261. строка:122 знак:44
  262. + if (!$foldersToPrependToPath.Contains <<<< ($path)) { $newPath += $path }
  263. + CategoryInfo : InvalidOperation: (Contains:String) [], RuntimeException
  264. + FullyQualifiedErrorId : MethodNotFound
  265.  
  266. Successfully installed!
  267.  
  268. Start a new console and run 'svm help' to get started.
  269.  
  270. _____________________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement