-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpgradeR
65 lines (57 loc) · 2.19 KB
/
UpgradeR
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Script to install and upgrade R.Project, R.Studio, and Rtools via Chocolatey
# Ensure Chocolatey is installed
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Host "Chocolatey is not installed. Installing Chocolatey..."
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'));
} else {
Write-Host "Chocolatey is already installed."
}
function Get-ChocoPackageVersion {
param (
[string]$packageName
)
$package = choco list --local-only $packageName | Select-String -Pattern $packageName
if ($package) {
$version = $package -replace '.*\|', ''
return $version
} else {
return $null
}
}
function Get-LatestChocoPackageVersion {
param (
[string]$packageName
)
$packageInfo = choco info $packageName
$latestVersion = $packageInfo | Select-String -Pattern "$packageName\s+(\d+(\.\d+)+)" | ForEach-Object { $_.Matches[0].Groups[1].Value }
if ($latestVersion) {
return $latestVersion
} else {
return $null
}
}
function Upgrade-Package {
param (
[string]$packageName
)
Write-Host "Upgrading $packageName..."
choco upgrade $packageName -y
}
$requiredPackages = @("r.project", "rstudio", "rtools")
foreach ($package in $requiredPackages) {
$installedVersion = Get-ChocoPackageVersion -packageName $package
$latestVersion = Get-LatestChocoPackageVersion -packageName $package
if (-not $installedVersion) {
Write-Host "$package is not installed. Installing..."
Upgrade-Package -packageName $package
} elseif ([version]$installedVersion -lt [version]$latestVersion) {
Write-Host "$package is installed but not up-to-date. Installed version: $installedVersion, Latest version: $latestVersion"
Upgrade-Package -packageName $package
} else {
Write-Host "$package is up-to-date. Installed version: $installedVersion, Latest version: $latestVersion"
}
}
Write-Host "Installation and upgrade process completed."
exit 0