0001 <#
0002 Licensed to the Apache Software Foundation (ASF) under one
0003 or more contributor license agreements. See the NOTICE file
0004 distributed with this work for additional information
0005 regarding copyright ownership. The ASF licenses this file
0006 to you under the Apache License, Version 2.0 (the
0007 "License"); you may not use this file except in compliance
0008 with the License. You may obtain a copy of the License at
0009 http://www.apache.org/licenses/LICENSE-2.0
0010 Unless required by applicable law or agreed to in writing,
0011 software distributed under the License is distributed on an
0012 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0013 KIND, either express or implied. See the License for the
0014 specific language governing permissions and limitations
0015 under the License.
0016 #>
0017
0018 $CRAN = "https://cloud.r-project.org"
0019
0020 Function InstallR {
0021 if ( -not(Test-Path Env:\R_ARCH) ) {
0022 $arch = "i386"
0023 }
0024 Else {
0025 $arch = $env:R_ARCH
0026 }
0027
0028 $urlPath = ""
0029 $latestVer = $(ConvertFrom-JSON $(Invoke-WebRequest https://rversions.r-pkg.org/r-release-win).Content).version
0030 If ($rVer -ne $latestVer) {
0031 $urlPath = ("old/" + $rVer + "/")
0032 }
0033
0034 $rurl = $CRAN + "/bin/windows/base/" + $urlPath + "R-" + $rVer + "-win.exe"
0035
0036 # Downloading R
0037 Start-FileDownload $rurl "R-win.exe"
0038
0039 # Running R installer
0040 Start-Process -FilePath .\R-win.exe -ArgumentList "/VERYSILENT /DIR=C:\R" -NoNewWindow -Wait
0041
0042 $RDrive = "C:"
0043 echo "R is now available on drive $RDrive"
0044
0045 $env:PATH = $RDrive + '\R\bin\' + $arch + ';' + 'C:\MinGW\msys\1.0\bin;' + $env:PATH
0046
0047 # Testing R installation
0048 Rscript -e "sessionInfo()"
0049 }
0050
0051 Function InstallRtools {
0052 $rtoolsver = $rToolsVer.Split('.')[0..1] -Join ''
0053 $rtoolsurl = $CRAN + "/bin/windows/Rtools/Rtools$rtoolsver.exe"
0054
0055 # Downloading Rtools
0056 Start-FileDownload $rtoolsurl "Rtools-current.exe"
0057
0058 # Running Rtools installer
0059 Start-Process -FilePath .\Rtools-current.exe -ArgumentList /VERYSILENT -NoNewWindow -Wait
0060
0061 $RtoolsDrive = "C:"
0062 echo "Rtools is now available on drive $RtoolsDrive"
0063
0064 if ( -not(Test-Path Env:\GCC_PATH) ) {
0065 $gccPath = "gcc-4.6.3"
0066 }
0067 Else {
0068 $gccPath = $env:GCC_PATH
0069 }
0070 $env:PATH = $RtoolsDrive + '\Rtools\bin;' + $RtoolsDrive + '\Rtools\MinGW\bin;' + $RtoolsDrive + '\Rtools\' + $gccPath + '\bin;' + $env:PATH
0071 $env:BINPREF=$RtoolsDrive + '/Rtools/mingw_$(WIN)/bin/'
0072 }
0073
0074 # create tools directory outside of Spark directory
0075 $up = (Get-Item -Path ".." -Verbose).FullName
0076 $tools = "$up\tools"
0077 if (!(Test-Path $tools)) {
0078 New-Item -ItemType Directory -Force -Path $tools | Out-Null
0079 }
0080
0081 # ========================== Maven
0082 Push-Location $tools
0083
0084 $mavenVer = "3.6.3"
0085 Start-FileDownload "https://archive.apache.org/dist/maven/maven-3/$mavenVer/binaries/apache-maven-$mavenVer-bin.zip" "maven.zip"
0086
0087 # extract
0088 Invoke-Expression "7z.exe x maven.zip"
0089
0090 # add maven to environment variables
0091 $env:PATH = "$tools\apache-maven-$mavenVer\bin;" + $env:PATH
0092 $env:M2_HOME = "$tools\apache-maven-$mavenVer"
0093 $env:MAVEN_OPTS = "-Xmx2g -XX:ReservedCodeCacheSize=1g"
0094
0095 Pop-Location
0096
0097 # ========================== Hadoop bin package
0098 # This must match the version at https://github.com/steveloughran/winutils/tree/master/hadoop-2.7.1
0099 $hadoopVer = "2.7.1"
0100 $hadoopPath = "$tools\hadoop"
0101 if (!(Test-Path $hadoopPath)) {
0102 New-Item -ItemType Directory -Force -Path $hadoopPath | Out-Null
0103 }
0104 Push-Location $hadoopPath
0105
0106 Start-FileDownload "https://github.com/steveloughran/winutils/archive/master.zip" "winutils-master.zip"
0107
0108 # extract
0109 Invoke-Expression "7z.exe x winutils-master.zip"
0110
0111 # add hadoop bin to environment variables
0112 $env:HADOOP_HOME = "$hadoopPath/winutils-master/hadoop-$hadoopVer"
0113 $env:Path += ";$env:HADOOP_HOME\bin"
0114
0115 Pop-Location
0116
0117 # ========================== R
0118 $rVer = "3.6.2"
0119 $rToolsVer = "3.5.1"
0120
0121 InstallR
0122 InstallRtools
0123
0124 $env:R_LIBS_USER = 'c:\RLibrary'
0125 if ( -not(Test-Path $env:R_LIBS_USER) ) {
0126 mkdir $env:R_LIBS_USER
0127 }
0128