1+ # Variables to help determine new naming convention in download string - currently only testing different geosupport versions in linux
2+ # New naming convention example: linux_geo18d_184.zip
3+ $legacyVersions = @ (' 18a' , ' 18b' , ' 18c' )
4+ $subVersions = ' a' , ' b' , ' c' , ' d' , ' e' , ' f'
5+ $BASE_URL = ' https://www1.nyc.gov/assets/planning/download/zip/data-maps/open-data/'
6+
7+ # DL function modified from https://github.com/ogrisel/python-appveyor-demo/blob/master/appveyor/install.ps1
8+ function Download ($filename , $url )
9+ {
10+ $webclient = New-Object System.Net.WebClient
11+ $basedir = $pwd.Path + " //"
12+ $filepath = $basedir + $filename
13+ if (Test-Path $filename )
14+ {
15+ Write-Host " Reusing" $filepath
16+ return $filepath
17+ }
18+
19+ # Download and retry up to 3 times in case of network transient errors.
20+ Write-Host " Downloading" $filename " from" $url
21+ $retry_attempts = 2
22+ for ($i = 0 ; $i -lt $retry_attempts ; $i ++ ) {
23+ try
24+ {
25+ Write-Host " Download attempt" $ ( $i + 1 )
26+ $webclient.DownloadFile ($url , $filepath )
27+ break
28+ }
29+ Catch [Exception ]
30+ {
31+ Write-Host " Download Error"
32+ Start-Sleep 1
33+ }
34+ }
35+ if (Test-Path $filepath )
36+ {
37+ Write-Host " File saved at" $filepath
38+ }
39+ else
40+ {
41+ Write-Host " File not downloaded"
42+ # Retry once to get the error message if any at the last try
43+ $webclient.DownloadFile ($url , $filepath )
44+ }
45+ return $filepath
46+ }
47+
48+ if ($isWindows )
49+ {
50+ # set download and temp directory names
51+ if ($env: PYTHON_ARCH -eq ' 64' )
52+ {
53+
54+ $LOCALDIR = ' geosupport-install-x64'
55+ $TARGETDIR = ' C:\Program Files\Geosupport Desktop Edition'
56+ $FILENAME = " gde64_$ ( $env: GEO_VERSION ) .zip"
57+ $URL = " $ ( $BASE_URL ) $ ( $FILENAME ) "
58+ }
59+ elseif ($env: PYTHON_ARCH -eq ' 32' )
60+ {
61+ $LOCALDIR = ' geosupport-install-x86'
62+ $TARGETDIR = ' C:\Program Files (x86)\Geosupport Desktop Edition'
63+ $FILENAME = " gde_$ ( $env: GEO_VERSION ) .zip"
64+ $URL = " $ ( $BASE_URL ) $ ( $FILENAME ) "
65+ }
66+
67+ # download
68+ Write-Host " Downloading $env: PYTHON_ARCH bit Geosupport version $env: GEO_VERSION for Windows..."
69+ $DOWNLOAD_FILE = Download $FILENAME $URL
70+
71+ # extract
72+ Write-Host " Extracting..."
73+ unzip $FILENAME - d $LOCALDIR
74+
75+ # delete .zip
76+ rm $FILENAME
77+
78+ # silently install Geosupport Desktop
79+ Write-Host " Installing..."
80+ Start-Process - Wait - FilePath " $ ( $LOCALDIR ) /setup.exe" - Verb runAs - ArgumentList ' /s' , ' /v"/qn"'
81+
82+ # set Geosupport Environmental variables
83+ $env: PATH = " $ ( $TARGETDIR ) \bin;$ ( $env: PATH ) "
84+ $env: GEOFILES = " $ ( $TARGETDIR ) \fls\"
85+
86+ Write-Host " Install complete."
87+ }
88+
89+ elseif ($isLinux )
90+ {
91+ if ($legacyVersions -contains $env: GEO_VERSION )
92+ {
93+ $FILENAME = " gdelx_$ ( $env: GEO_VERSION ) .zip"
94+ }
95+
96+ # determine string if new geosupport download naming convention
97+ else
98+ {
99+ foreach ($version in $subVersions )
100+ {
101+ if ($version -eq $env: GEO_VERSION.Substring (2 ))
102+ {
103+ $idx = [array ]::indexOf($subVersions , $version ) + 1
104+ $FILENAME = " linux_geo$ ( $env: GEO_VERSION ) _$ ( $env: GEO_VERSION.Substring (0 , 2 ) ) $ ( $idx ) .zip"
105+ }
106+ }
107+ }
108+
109+ # set download string and local directory names
110+ $LOCALDIR = ' geosupport-install-lx'
111+ $URL = " $ ( $BASE_URL ) $ ( $FILENAME ) "
112+
113+ # download
114+ Write-Host " Downloading Geosuport version $env: GEO_VERSION for Linux..."
115+ Download $FILENAME $URL
116+
117+ # extract
118+ Write-Host " Extracting..."
119+ unzip $FILENAME - d $LOCALDIR
120+
121+ # get the first child directory name of the unzipped geosupport install dir
122+ $GEO_DIR_CHILD_NAME = Get-ChildItem $LOCALDIR - Recurse | Where-Object { $_.FullName -like " *$ ( $env: GEO_VERSION ) *" } | Select-Object - First 1 | select - expand Name
123+ $INSTALL_PATH = " $ ( $pwd ) /$ ( $LOCALDIR ) /$ ( $GEO_DIR_CHILD_NAME ) "
124+
125+ # delete .zip
126+ rm $FILENAME
127+
128+ # set Geosupport Environmental variables
129+ $env: GEOFILES = " $ ( $INSTALL_PATH ) /fls/"
130+ $env: LD_LIBRARY_PATH = " $ ( $INSTALL_PATH ) /lib/:$ ( $env: LD_LIBRARY_PATH ) "
131+
132+ Write-Host " Install complete."
133+ }
0 commit comments