-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-rstudio-daily.sh
executable file
·196 lines (162 loc) · 5.95 KB
/
install-rstudio-daily.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
#
# Installs the latest RStudio daily desktop build for OSX/macOS and Ubuntu(amd64)
#
# https://support.rstudio.com/hc/en-us/articles/203842428-Getting-the-newest-RStudio-builds
set -e
# A version like 2022.01.0-daily+294 will have a filename/URL like
# RStudio-2022.01.0-daily-294.dmg. There was a brief period of time when the
# URL contained the plus (which required escaping).
# From URL-form to version-form.
# 2022.07.0-548 => 2022.07.0+548
# 2022.10.0-daily-9 => 2022.10.0-daily+9
dailyplus() {
sed -e 's/-\([0-9]*\)$/+\1/'
}
# From version-form to URL-form.
# 2022.07.0+548 => 2022.07.0-548
# 2022.10.0-daily+9 => 2022.10.0-daily-9
dailyunplus() {
sed -e 's/+\([0-9]*\)$/-\1/'
}
installed_macos_version() {
PLIST="/Applications/RStudio.app/Contents/Info.plist"
if [ -f "${PLIST}" ] ; then
# Maybe CFBundleShortVersionString or CFBundleVersion?
INSTALLED_VERSION=$(defaults read "${PLIST}" CFBundleLongVersionString)
echo "${INSTALLED_VERSION}"
return
fi
echo "none"
}
install_macos_daily() {
FORCE="$1"
REQUESTED_VERSION="$2"
JSON=$(curl -s https://dailies.rstudio.com/rstudio/latest/index.json)
LATEST_URL=$(echo "${JSON}" | jq -r .products.electron.platforms.macos.link)
LATEST_VERSION=$(echo "${JSON}" | jq -r .products.electron.platforms.macos.version)
LATEST_URL_VERSION=$(echo "${LATEST_VERSION}" | dailyunplus)
echo "Latest version: ${LATEST_VERSION}"
REQUESTED_URL="${LATEST_URL}"
if [ -z "${REQUESTED_VERSION}" ] ; then
REQUESTED_VERSION="${LATEST_VERSION}"
elif [ "${REQUESTED_VERSION}" != "${LATEST_VERSION}" ] ; then
echo "Requested version: ${REQUESTED_VERSION}"
REQUESTED_URL_VERSION=$(echo "${REQUESTED_VERSION}" | dailyunplus)
# shellcheck disable=SC2001
REQUESTED_URL=$(echo "${LATEST_URL}" | sed -e "s|${LATEST_URL_VERSION}|${REQUESTED_URL_VERSION}|")
fi
INSTALLED_VERSION=$(installed_macos_version)
echo "Installed version: ${INSTALLED_VERSION}"
if [ "${REQUESTED_VERSION}" == "${INSTALLED_VERSION}" ] ; then
if [ "${FORCE}" == "yes" ] ; then
echo "RStudio ${REQUESTED_VERSION} is already installed. Forcing re-installation."
else
echo "RStudio ${REQUESTED_VERSION} is already installed. Use '-f' to force re-installation."
exit 0
fi
fi
install_macos_url "${REQUESTED_URL}"
}
install_macos_url() {
REQUESTED_URL="$1"
echo "Downloading: ${REQUESTED_URL}"
cd /tmp
TARGET=$(basename "${REQUESTED_URL}")
# Volume name mirrors the DMG filename without extension.
# Simpler than parsing hdiutil output.
VOLUME_NAME=$(basename "${TARGET}" .dmg)
VOLUME_MOUNT="/Volumes/${VOLUME_NAME}"
curl -L --fail -o "${TARGET}" "${REQUESTED_URL}"
echo "Attaching to image: ${TARGET}"
hdiutil attach -readonly -quiet "${TARGET}"
echo "Removing existing installation (if any)."
rm -rf /Applications/RStudio.app
echo "Installing into: /Applications/RStudio.app"
cp -R "${VOLUME_MOUNT}/RStudio.app" /Applications
echo "Detaching from image: ${VOLUME_MOUNT}"
hdiutil detach -quiet "${VOLUME_MOUNT}"
echo "Removing download: ${TARGET}"
rm "${TARGET}"
echo
echo "Installed RStudio from volume ${VOLUME_NAME} as /Applications/RStudio.app"
}
install_ubuntu() {
DISTRIBUTION="$1"
REQUESTED_VERSION="$2"
JSON=$(curl -s https://dailies.rstudio.com/rstudio/latest/index.json)
DIST_JSON=$(echo "${JSON}" | jq .products.electron.platforms['"'"${DISTRIBUTION}"'"'])
LATEST_URL=$(echo "${DIST_JSON}" | jq -r '.link')
LATEST_VERSION=$(echo "${DIST_JSON}" | jq -r '.version')
LATEST_URL_VERSION=$(echo "${LATEST_VERSION}" | dailyunplus)
echo "Latest version: ${LATEST_VERSION}"
REQUESTED_URL="${LATEST_URL}"
if [ -z "${REQUESTED_VERSION}" ] ; then
REQUESTED_VERSION="${LATEST_VERSION}"
elif [ "${REQUESTED_VERSION}" != "${LATEST_VERSION}" ] ; then
echo "Requested version: ${REQUESTED_VERSION}"
REQUESTED_URL_VERSION=$(echo "${REQUESTED_VERSION}" | dailyunplus)
# shellcheck disable=SC2001
REQUESTED_URL=$(echo "${LATEST_URL}" | sed -e "s|${LATEST_URL_VERSION}|${REQUESTED_URL_VERSION}|")
fi
PACKAGE=$(basename "${REQUESTED_URL}")
TARGET="/tmp/${PACKAGE}"
echo "Downloading daily build from: ${REQUESTED_URL}"
if [ -x /usr/bin/curl ] ; then
curl -L --fail -o "${TARGET}" "${REQUESTED_URL}"
elif [ -x /usr/bin/wget ] ; then
wget -O "${TARGET}" "${REQUESTED_URL}"
else
echo "Unable to obtain the RStudio package: cannot find 'curl' or 'wget'"
exit 1
fi
echo "Installing ${TARGET}"
LAUNCH=""
if [[ $(whoami) != "root" ]]; then
LAUNCH="sudo"
fi
${LAUNCH} apt install -y "${TARGET}"
rm "${TARGET}"
}
help() {
echo "$0 [-h] [-s] [-f]"
echo ""
echo "Install the most recent RStudio build. Supports macOS and Ubuntu 18.04."
echo ""
echo "Arguments:"
echo " -f, --force Force installation when the same version is already"
echo " installed (macOS only)."
echo " -h, --help Display this help text and exit."
}
FORCE="no"
for arg in "$@"; do
case $arg in
-f|--force)
FORCE="yes"
shift
;;
-h|--help)
help
exit
;;
esac
done
VERSION=
if [[ $# -eq 1 ]]; then
VERSION="$1"
elif [[ $# -ne 0 ]]; then
echo "Only one (optional) version argument is supported."
exit 1
fi
if [[ $(uname -s) = "Darwin" ]]; then
install_macos_daily "${FORCE}" "${VERSION}"
elif grep -q "Ubuntu 18" /etc/issue ; then
install_ubuntu "bionic-amd64" "${VERSION}"
elif grep -q "Ubuntu 20" /etc/issue ; then
install_ubuntu "bionic-amd64" "${VERSION}"
elif grep -q "Ubuntu 22" /etc/issue ; then
install_ubuntu "jammy-amd64" "${VERSION}"
else
echo "This script only works on OSX/macOS and Ubuntu Linux."
exit 1
fi