├── LICENSE.txt ├── README.md └── bin ├── install-node.sh └── install-node.vbs /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2012 2 | DFKI - German Research Center for Artificial Intelligence 3 | www.dfki.de 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | portable-node 2 | ============= 3 | 4 | Install node.js locally on Windows and Linux without administrator rights. 5 | 6 | Note: when specifying version at the command line, a full version number (MAJOR.MINOR.PATCH) must be specified ! 7 | 8 | Windows Instructions 9 | -------------------- 10 | 11 | Download and run https://raw.github.com/dmrub/portable-node/master/bin/install-node.vbs. 12 | The script will download recent version of node.js and create startup files for node.js and git bash. 13 | 14 | For more options run from command line (cmd.exe or git bash): 15 | 16 | > cscript install-node.vbs /? 17 | 18 | Node Portable Environment Setup Script 19 | Usage : install-node.vbs [ /? ] [/version:node-version /arch:x86|x86_64|32|64 /force] 20 | 21 | Options: /version:node-version select node version to download (default : 6.9.5) 22 | /arch:x86|x64|x86_64|32|64 select node architecture to download (default : x86) 23 | /force force download and installation 24 | /? print this 25 | 26 | Linux Instructions 27 | -------------------- 28 | 29 | Download and run https://raw.github.com/dmrub/portable-node/master/bin/install-node.sh. 30 | 31 | For example: 32 | 33 | wget https://raw.github.com/dmrub/portable-node/master/bin/install-node.sh 34 | chmod +x ./install-node.sh 35 | ./install-node.sh 36 | 37 | For more options run from command line: 38 | 39 | > ./install-node.sh --help 40 | Node Portable Environment Setup Script 41 | Usage: ./install-node.sh [options] 42 | options : 43 | -h | --help print this 44 | -v | --version=node-version select node version to download (default : 6.9.5) 45 | -a | --arch=x86|x86_64|32|64 select node architecture to download (default : x64) 46 | -f | --force force download and installation 47 | 48 | Enjoy ! 49 | -------------------------------------------------------------------------------- /bin/install-node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Portable Node.js install script 4 | # Author: Dmitri Rubinstein 5 | # Version: 1.1 6 | # 2017-02-21 7 | # 8 | #Copyright (c) 2013, 2017 9 | # DFKI - German Research Center for Artificial Intelligence 10 | # www.dfki.de 11 | # 12 | #Permission is hereby granted, free of charge, to any person obtaining a copy of 13 | #this software and associated documentation files (the "Software"), to deal in 14 | #the Software without restriction, including without limitation the rights to 15 | #use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 16 | #of the Software, and to permit persons to whom the Software is furnished to do 17 | # so, subject to the following conditions: 18 | # 19 | #The above copyright notice and this permission notice shall be included in all 20 | #copies or substantial portions of the Software. 21 | # 22 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | #SOFTWARE. 29 | 30 | export LC_ALL=C 31 | unset CDPATH 32 | 33 | abspath() { 34 | if [ -d "$1" ]; then 35 | echo "$(cd "$1"; pwd)" 36 | else 37 | case "$1" in 38 | "" | ".") echo "$PWD";; 39 | /*) echo "$1";; 40 | *) echo "$PWD/$1";; 41 | esac 42 | fi 43 | } 44 | 45 | if [ -z "$(type -t dirname)" ]; then 46 | # Compute the dirname of FILE. 47 | dirname () { 48 | case ${1} in 49 | */*) echo "${1%/*}${2}" ;; 50 | * ) echo "${3}" ;; 51 | esac 52 | } 53 | fi 54 | 55 | die() { 56 | echo >&2 "Error: $@" 57 | exit 1 58 | } 59 | 60 | if [ "$DEBUG" = "true" -o "$DEBUG" = "yes" ] || \ 61 | [ "$DEBUG" -eq 1 ] 2>/dev/null; then 62 | debug() { echo "Debug: $@"; } 63 | else 64 | debug() { :; } 65 | fi 66 | 67 | if type -p curl > /dev/null; then 68 | download() { 69 | echo "Download: $1 to: $2" 70 | curl -fLo "$2" "$1" && [ -e "$2" ] 71 | } 72 | elif type -p wget > /dev/null; then 73 | download() { 74 | echo "Download: $1 to: $2" 75 | wget -O "$2" "$1" && [ -e "$2" ] 76 | } 77 | else 78 | die "No download tool found, please install wget or curl" 79 | fi 80 | 81 | # ask prompt default 82 | REPLY= 83 | ask() { 84 | local prompt=$1 85 | local default=$2 86 | 87 | echo "$1" 88 | [ -n "$default" ] && echo -n "[$default] " 89 | read -e 90 | 91 | [ -z "$REPLY" ] && REPLY=$default 92 | } 93 | 94 | # setup_ask prompt default 95 | setup_ask() { 96 | if [ "$AUTO_INSTALL" = "yes" ]; then 97 | echo "$1 : $2" 98 | REPLY=$2 99 | else 100 | ask "$@" 101 | fi 102 | } 103 | 104 | # Setup basic variables 105 | thisDir=$(abspath "$(dirname "$0")") 106 | case "$thisDir" in 107 | */bin) baseDir=${thisDir%/*};; 108 | *) baseDir=$thisDir;; 109 | esac 110 | 111 | # Check OS 112 | runCScript= 113 | case "$OSTYPE" in 114 | linux-gnu) ;; 115 | msys|cygwin) 116 | # Windows run install-node.vbs if available 117 | [ -e "$thisDir/install-node.vbs" ] || die "Download and run install-node.vbs" 118 | runCScript=yes 119 | ;; 120 | *) die "$OSTYPE OS is not supported." 121 | esac 122 | 123 | # Process command line arguments 124 | nodeVersion=6.9.5 125 | if [[ "$HOSTTYPE" == "x86_64" ]]; then 126 | nodeArch=x64 127 | else 128 | nodeArch=x86 129 | fi 130 | forceInstall= 131 | 132 | while [ $# -gt 0 ]; do 133 | case "$1" in 134 | --) break;; # end of options 135 | -h|--help) 136 | cat< /dev/null || die "Could not find tar tool, please install first" 209 | 210 | nodeExePath=$nodeInstallPath/bin 211 | nodeExePathRel=$nodeInstallPathRel/bin 212 | nodeExeFile=$nodeExePath/node 213 | nodeExeFileRel=$nodeExePathRel/node 214 | 215 | if [[ ( ! -e "$nodeExeFile" ) || ( "$forceInstall" == "yes" ) ]]; then 216 | [[ -d "$nodeInstallPath" ]] && { 217 | echo "Deleting directory: $nodeInstallPath" 218 | rm -rf "$nodeInstallPath" 219 | } 220 | 221 | echo "Running: cd $nodeBaseDir && tar xzf \"$nodeTarballPath\"" 222 | 223 | (cd "$nodeBaseDir" || exit 1; tar xzf "$nodeTarballPath") 224 | result=$? 225 | echo "Result: $result" 226 | if [[ "$result" != 0 ]]; then 227 | die "Could not install node.js" 228 | fi 229 | else 230 | echo "File $nodeExeFile already exists, use --force to reinstall." 231 | fi 232 | 233 | # Create node launch script 234 | 235 | funcText=$(declare -f abspath) 236 | 237 | scriptFile="$baseDir/$nodePrefix" 238 | cat > "$scriptFile" < "$scriptFile" < "\$THIS_DIR/share/git-bash-profile.sh" 269 | echo "[ -e \\"\\\$NODE_PATH/../lib/node_modules/npm/lib/utils/completion.sh\\" ] && source \\"\\\$NODE_PATH/../lib/node_modules/npm/lib/utils/completion.sh\\"" >> "\$THIS_DIR/share/git-bash-profile.sh" 270 | echo "echo Started Node Environment" >> "\$THIS_DIR/share/git-bash-profile.sh" 271 | fi 272 | exec bash --rcfile "\$THIS_DIR/share/git-bash-profile.sh" 273 | EOF 274 | chmod +x "$scriptFile" 275 | echo "Created bash launch script: $scriptFile" 276 | -------------------------------------------------------------------------------- /bin/install-node.vbs: -------------------------------------------------------------------------------- 1 | ' Portable Node.js install script 2 | ' Author: Dmitri Rubinstein 3 | ' Version: 1.0 4 | ' 13.03.2013 5 | ' 6 | 'Copyright (c) 2013 7 | ' DFKI - German Research Center for Artificial Intelligence 8 | ' www.dfki.de 9 | ' 10 | 'Permission is hereby granted, free of charge, to any person obtaining a copy of 11 | 'this software and associated documentation files (the "Software"), to deal in 12 | 'the Software without restriction, including without limitation the rights to 13 | 'use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 14 | 'of the Software, and to permit persons to whom the Software is furnished to do 15 | ' so, subject to the following conditions: 16 | ' 17 | 'The above copyright notice and this permission notice shall be included in all 18 | 'copies or substantial portions of the Software. 19 | ' 20 | 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | 'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | 'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | 'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | 'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | 'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | 'SOFTWARE. 27 | 28 | ' Declare all global variables 29 | Dim FSO, WshShell, WshEnv, thisDir, VERBOSE 30 | 31 | ' Create objects that will be shared by all following code 32 | Set FSO = CreateObject("Scripting.FileSystemObject") 33 | Set WshShell = Wscript.CreateObject("Wscript.Shell") 34 | Set WshEnv = WshShell.Environment("PROCESS") 35 | Set stdout = FSO.GetStandardStream(1) 36 | Set stderr = FSO.GetStandardStream(2) 37 | 38 | thisDir = FSO.GetParentFolderName(Wscript.ScriptFullName) 39 | If UCase(Right(thisDir, 4)) = "\BIN" Then 40 | baseDir = Left(thisDir, Len(thisDir)-4) 41 | Else 42 | baseDir = thisDir 43 | End If 44 | 45 | ' Check thisDir for existence 46 | Assert FSO.FolderExists(thisDir), "Bootstrap: There is no directory " & thisDir & ", something is wrong" 47 | 48 | ' Set VERBOSE to True if we Wscript.Echo will print to console 49 | VERBOSE = InConsole() 50 | 51 | ' Process command-line arguments 52 | Set args = Wscript.Arguments 53 | 54 | Dim nodeVersion, nodeArch, nodeURL, nodeMSIFile 55 | 56 | nodeVersion = "6.9.5" 57 | nodeArch = "x86" 58 | forceInstall = False 59 | 60 | If args.Count > 0 Then 61 | If args(0) = "-h" Or args(0) = "-?" Or _ 62 | args(0) = "--help" Or args(0) = "/?" Then 63 | Wscript.Echo "Node Portable Environment Setup Script" & vbCrLf & _ 64 | "Usage : " & Wscript.ScriptName & " [ /? ] [/version:node-version /arch:x86|x86_64|32|64 /force]" & vbCrLf & vbCrLf & _ 65 | "Options: /version:node-version select node version to download (default : " & nodeVersion & ")" & vbCrLf & _ 66 | " /arch:x86|x64|x86_64|32|64 select node architecture to download (default : " & nodeArch & ")" & vbCrLf & _ 67 | " /force force download and installation" & vbCrLf & _ 68 | " /? print this" & vbCrLf 69 | Wscript.Quit 70 | End If 71 | If args.Named.Exists("version") Then 72 | nodeVersion = args.Named.Item("version") 73 | End If 74 | If args.Named.Exists("arch") Then 75 | nodeArch = args.Named.Item("arch") 76 | End If 77 | If nodeArch = "x86_64" Then nodeArch = "x64" 78 | If nodeArch = "32" Then nodeArch = "x86" 79 | If nodeArch = "64" Then nodeArch = "x64" 80 | ' Check 81 | If nodeArch <> "x86" And nodeArch <> "x64" Then 82 | Error "Unsupported architecture: " & nodeArch, 1 83 | End If 84 | 85 | For i = 0 to args.Count-1 86 | arg = args.Item(i) 87 | If arg = "/force" Or arg = "-force" Then forceInstall = True 88 | Next 89 | 90 | End If 91 | 92 | ' Setup paths 93 | nodePrefix = "node-v" & nodeVersion & "-" & nodeArch 94 | nodeMSIFile = nodePrefix & ".msi" 95 | If nodeArch = "x86" Then 96 | nodeURL = "http://nodejs.org/dist/" & "v" & nodeVersion & "/" & nodeMSIFile 97 | Else 98 | nodeURL = "http://nodejs.org/dist/" & "v" & nodeVersion & "/x64/" & nodeMSIFile 99 | End If 100 | 101 | nodeBaseDirRel = "share\nodejs" 'relative to baseDir 102 | nodeBaseDir = FSO.BuildPath(baseDir, nodeBaseDirRel) 103 | nodeMSIPath = FSO.GetAbsolutePathName(FSO.BuildPath(nodeBaseDir, nodeMSIFile)) 104 | nodeInstallPathRel = nodeBaseDirRel & "\" & nodePrefix ' relative to baseDir 105 | nodeInstallPath = FSO.GetAbsolutePathName(FSO.BuildPath(baseDir, nodeInstallPathRel)) 106 | 107 | Wscript.Echo "Download and install locally node.js version: " & nodeVersion & " for architecture: " & nodeArch 108 | 109 | ' Download node.js 110 | CreateFolderTree(nodeBaseDir) 111 | If Not FSO.FileExists(nodeMSIPath) Or forceInstall Then 112 | If Not Download(nodeURL, nodeMSIPath) Then Error "Could not download URL: " & nodeURL, 2 113 | Else 114 | Echo "File " & nodeMSIPath & " already exists, use /force to reload." 115 | End If 116 | 117 | ' Extract node.js 118 | nodeExePath = FSO.BuildPath(nodeInstallPath, "nodejs") 119 | nodeExePathRel = FSO.BuildPath(nodeInstallPathRel, "nodejs") 120 | nodeExeFile = FSO.BuildPath(nodeExePath, "node.exe") 121 | nodeExeFileRel = FSO.BuildPath(nodeExePathRel, "node.exe") 122 | If Not FSO.FileExists(nodeExeFile) Or forceInstall Then 123 | Dim extractCmd 124 | 125 | extractCmd = "msiexec.exe /a " & nodeMSIPath & " /qn TARGETDIR=" & nodeInstallPath 126 | 127 | If FSO.FolderExists(nodeInstallPath) Then 128 | Echo "Deleting folder: " & nodeInstallPath 129 | FSO.DeleteFolder(nodeInstallPath) 130 | End If 131 | 132 | Echo "Running: " & extractCmd 133 | result = WshShell.Run(extractCmd, 1, True) 134 | Echo "Result : " & result 135 | If result <> 0 Then Error "Could not install node.js", 3 136 | 137 | ' Delete MSI file produced by installer 138 | Dim msiFile2 139 | msiFile2 = FSO.BuildPath(nodeInstallPath, nodeMSIFile) 140 | If FSO.FileExists(msiFile2) Then 141 | Echo "Deleting file: " & msiFile2 142 | FSO.DeleteFile(msiFile2) 143 | End If 144 | Else 145 | Echo "File " & nodeExeFile & " already exists, use /force to reinstall." 146 | End If 147 | 148 | ' Create node launch script 149 | Dim Script 150 | scriptFile = FSO.BuildPath(baseDir, nodePrefix & ".bat") 151 | Set script = FSO.CreateTextFile(scriptFile, True) 152 | script.WriteLine("@echo off") 153 | script.WriteLine("PATH %~dp0" & nodeExePathRel & ";%PATH%") 154 | script.WriteLine("set NODE_PATH=%~dp0" & nodeExePathRel) 155 | script.WriteLine("%~dp0" & nodeExeFileRel & " %*") 156 | script.Close 157 | Echo "Created node launch script: " & scriptFile 158 | 159 | ' Create git bash launch script 160 | gitShell = GetMsysGitShell() 161 | If gitShell <> "" Then 162 | scriptFile = FSO.BuildPath(baseDir, "git-bash-" & nodePrefix & ".bat") 163 | Set script = FSO.CreateTextFile(scriptFile, True) 164 | script.WriteLine("@echo off") 165 | script.WriteLine("PATH %~dp0" & nodeExePathRel & ";%PATH%") 166 | script.WriteLine("set NODE_PATH=%~dp0" & nodeExePathRel) 167 | script.WriteLine("rem if exist %~dp0\share\git-bash-profile.sh goto run") 168 | script.WriteLine("rem Create git-bash-profile.sh") 169 | script.WriteLine("if not exist %~dp0\share mkdir %~dp0\share") 170 | script.WriteLine("echo source /etc/profile > %~dp0\share\git-bash-profile.sh") 171 | script.WriteLine("echo NODE_PATH=$^(echo ""$NODE_PATH"" ^| sed 's^|^^\(.\):\\^|/\1/^|g; s^|\\^|/^|g';^) >> %~dp0\share\git-bash-profile.sh") 172 | script.WriteLine("echo [ -e ""$NODE_PATH/node_modules/npm/lib/utils/completion.sh"" ] ^&^& source ""$NODE_PATH/node_modules/npm/lib/utils/completion.sh"" >> %~dp0\share\git-bash-profile.sh") 173 | script.WriteLine("echo echo Started Node Evironment >> %~dp0\share\git-bash-profile.sh") 174 | script.WriteLine(":run") 175 | script.WriteLine("""" & gitShell & """ --rcfile %~dp0\share\git-bash-profile.sh") 176 | script.Close 177 | 178 | Echo "Created git bash launch script: " & scriptFile 179 | End If 180 | 181 | Wscript.Echo "Installation finished" 182 | 183 | 'Cygwin not yet supported 184 | 'cygwinShell = GetCygwinShell() 185 | 186 | Wscript.Quit 187 | 188 | ' Help procedures and functions 189 | 190 | ' Download url and save to path 191 | ' http://www.codeproject.com/Tips/506439/Downloading-files-with-VBScript 192 | Function Download(url, path) 193 | Dim objHTTP, objFSO 194 | ' Get file name from URL. 195 | ' http://download.windowsupdate.com/microsoftupdate/v6/wsusscan/wsusscn2.cab -> wsusscn2.cab 196 | 197 | Echo "Download URL: " & url & " to: " & path 198 | 199 | ' Create an HTTP object 200 | Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" ) 201 | 202 | ' Download the specified URL 203 | objHTTP.Open "GET", url, False 204 | ' Use HTTPREQUEST_SETCREDENTIALS_FOR_PROXY if user and password is for proxy, not for download the file. 205 | ' objHTTP.SetCredentials "User", "Password", HTTPREQUEST_SETCREDENTIALS_FOR_SERVER 206 | objHTTP.Send 207 | 208 | Set objFSO = CreateObject("Scripting.FileSystemObject") 209 | If objFSO.FileExists(path) Then 210 | objFSO.DeleteFile(path) 211 | End If 212 | 213 | If objHTTP.Status = 200 Then 214 | Dim objStream 215 | Set objStream = CreateObject("ADODB.Stream") 216 | With objStream 217 | .Type = 1 'adTypeBinary 218 | .Open 219 | .Write objHTTP.ResponseBody 220 | .SaveToFile path 221 | .Close 222 | End With 223 | set objStream = Nothing 224 | Else 225 | stderr.WriteLine "Could not download: " & url & " : " & objHTTP.Status & " " & objHTTP.StatusText 226 | End If 227 | 228 | If objFSO.FileExists(path) Then 229 | Echo "Download to `" & path & "` completed successfully." 230 | Download = True 231 | Else 232 | Download = False 233 | End If 234 | End Function 235 | 236 | Sub CreateFolderTree(folderPath) 237 | Dim objFSO, parent 238 | Set objFSO = CreateObject("Scripting.FileSystemObject") 239 | parent = objFSO.GetParentFolderName(folderPath) 240 | If Len(parent) > 0 And Not objFSO.FolderExists(parent) Then 241 | CreateFolderTree(parent) 242 | End If 243 | If Not objFSO.FolderExists(folderPath) Then 244 | objFSO.CreateFolder(folderPath) 245 | End If 246 | End Sub 247 | 248 | ' Detect MsysGit 249 | Function GetMsysGitShell() 250 | Dim GIT_DIR, GIT_SHELL 251 | GIT_SHELL = "" 252 | GIT_DIR = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1\InstallLocation", "") 253 | If GIT_DIR <> "" Then 254 | GIT_SHELL = FSO.BuildPath(GIT_DIR, "bin\sh.exe") 255 | Else 256 | ' Check on 64-bit Windows 257 | GIT_DIR = RegRead("HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1\InstallLocation", "") 258 | If GIT_DIR <> "" Then 259 | GIT_SHELL = FSO.BuildPath(GIT_DIR, "bin\sh.exe") 260 | End If 261 | End If 262 | GetMsysGitShell = GIT_SHELL 263 | End Function 264 | 265 | ' Detect Cygwin 266 | Function GetCygwinShell() 267 | Dim CYGWIN_DIR, CYGWIN_SHELL 268 | CYGWIN_SHELL = "" 269 | CYGWIN_DIR = RegRead("HKLM\Software\Cygnus Solutions\Cygwin\mounts v2\/\native", "") 270 | If CYGWIN_DIR = "" Then 271 | CYGWIN_DIR = RegRead("HKLM\Software\Wow6432Node\Cygwin\setup\rootdir", "") 272 | End If 273 | If CYGWIN_DIR <> "" Then 274 | CYGWIN_SHELL = FSO.BuildPath(CYGWIN_DIR, "bin\bash.exe") 275 | End If 276 | GetCygwinShell = CYGWIN_SHELL 277 | End Function 278 | 279 | ' Checks whether the script is started in text console (through CSCRIPT.EXE) 280 | ' or not 281 | Function InConsole() 282 | InConsole = (UCase(Left(FSO.GetFileName(Wscript.FullName),7)) = "CSCRIPT") 283 | End Function 284 | 285 | ' Read registry key, return defaultValue if the key with specified name 286 | ' does not exists 287 | Function RegRead(key, defaultValue) 288 | RegRead = defaultValue 289 | On Error Resume Next 290 | RegRead = WshShell.RegRead(key) 291 | End Function 292 | 293 | Function WinToMsysPath(path) 294 | WinToMsysPath = Replace(Replace(path, "\", "/"), " ", "\ ") 295 | End Function 296 | 297 | ' Echoes message if the script is in VERBOSE mode 298 | ' VERBOSE mode will be set at script start through call to InConsole 299 | Sub Echo(msg) 300 | If VERBOSE Then Wscript.Echo msg 301 | End Sub 302 | 303 | ' Show error message in message box or console and exit 304 | Sub Error(msg, exitCode) 305 | If InConsole() Then 306 | stderr.WriteLine "Setup Error: " & msg 307 | Else 308 | MsgBox msg, vbExclamation, "Setup Error" 309 | End If 310 | Wscript.Quit exitCode 311 | End Sub 312 | 313 | Sub Assert(cond, msg) 314 | If Not cond Then 315 | Error msg, 1 316 | End If 317 | End Sub 318 | 319 | ' If VBasic error was happened exit script 320 | Sub CheckVBError(msg,exitCode) 321 | If Err.Number <> 0 Then 322 | MsgBox msg & vbCrLf & Err.Description,vbExclamation, "Error" 323 | Wscript.Quit exitCode 324 | End If 325 | End Sub 326 | --------------------------------------------------------------------------------