-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
229 lines (193 loc) · 9.16 KB
/
setup.sh
File metadata and controls
229 lines (193 loc) · 9.16 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash
# Define colors and text styles
BOLD=$(tput bold)
RESET=$(tput sgr0)
GREEN=$(tput setaf 2)
# Define the log file location
LOG_FILE="/tmp/setup_log.txt"
# Initialize the log file
echo "Starting setup..." > "$LOG_FILE"
# Helper functions for displaying progress
function display_message() {
echo -n "${BOLD}$1${RESET}... "
}
function complete_message() {
echo -e "${GREEN}Done.${RESET}"
}
# Function for showing a spinner while a command runs
function spinner() {
local pid=$!
local delay=0.1
local spin=('-' '\' '|' '/')
while kill -0 "$pid" 2>/dev/null; do
for i in "${spin[@]}"; do
echo -ne "\b$i" > /dev/tty
sleep $delay
done
done
wait $pid
echo -ne "\b"
}
# Run a command with spinner
function run_with_spinner() {
display_message "$1"
eval "$2" >> "$LOG_FILE" 2>&1 & spinner
complete_message
}
# Define a custom apt function to enforce DEBIAN_FRONTEND
function apt2() {
sudo DEBIAN_FRONTEND=noninteractive apt "$@"
}
# Define software versions
# https://quarto.org/docs/get-started/
QUARTO_VERSION=${QUARTO_VERSION:-"1.8.27"}
# https://posit.co/download/rstudio-server/
RSTUDIO_SERVER_VERSION=${RSTUDIO_SERVER_VERSION:-"2026.01.0-392"}
# 1. Update and upgrade packages
run_with_spinner "Updating and upgrading OS packages" \
"apt2 update && apt2 upgrade -y"
# 2. Install essential packages for handling repositories and dependencies
run_with_spinner "Installing essential packages for repositories and dependencies" \
"apt2 install -y software-properties-common gdebi-core unzip"
# 3. Install common system libraries for R, Python, and data science packages
run_with_spinner "Installing common system libraries" \
"apt2 install -y \
wget curl git libssl-dev libxml2-dev libgit2-dev \
build-essential libclang-dev libgmp3-dev libglpk40 \
libharfbuzz-dev libfribidi-dev libicu-dev libxml2 \
libpng-dev libjpeg-dev libtiff5-dev libfontconfig1-dev \
libfreetype-dev libcairo2-dev libxt-dev libmagick++-dev \
libsqlite3-dev libmariadb-dev libpq-dev unixodbc-dev \
gdal-bin libgeos-dev libproj-dev \
zlib1g-dev libbz2-dev liblzma-dev libpcre2-dev perl \
libcurl4-openssl-dev pandoc"
# 4. Add the CRAN repository for R
run_with_spinner "Adding Ubuntu repository for R" \
"sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys \
E298A3A825C0D65DFD57CBB651716619E084DAB9 && \
sudo add-apt-repository -y 'deb https://cloud.r-project.org/bin/linux/ubuntu \
$(lsb_release -cs)-cran40/'"
# 5. Install the latest version of R
run_with_spinner "Installing R" "apt2 install -y r-base r-base-dev"
# 6. Configure CRAN mirror for R to use Posit Public Package Manager
run_with_spinner "Configuring CRAN mirror for R to use Posit Public Package Manager" \
"sudo mkdir -p /etc/R && echo 'options(repos = c(CRAN = \
\"https://packagemanager.posit.co/cran/__linux__/noble/latest\"))' | \
sudo tee /etc/R/Rprofile.site"
# 7. Install latest Python version
run_with_spinner "Installing Python" "apt2 install -y python3 python3-pip python3-venv"
# 8. Configure pip to use Posit Public Package Manager
run_with_spinner "Configuring pip to use Posit Public Package Manager" \
"sudo pip config set --global global.index-url \
https://packagemanager.posit.co/pypi/latest/simple && \
sudo pip config set --global global.trusted-host packagemanager.posit.co"
# 9. Install Quarto
run_with_spinner "Installing Quarto" "
wget https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-amd64.tar.gz && \
tar -xvzf quarto-${QUARTO_VERSION}-linux-amd64.tar.gz && \
sudo mv quarto-${QUARTO_VERSION} /opt/quarto-${QUARTO_VERSION} && \
sudo ln -s /opt/quarto-${QUARTO_VERSION}/bin/quarto /usr/local/bin/quarto && \
rm quarto-${QUARTO_VERSION}-linux-amd64.tar.gz
"
# 10a. Install Miniconda
run_with_spinner "Installing Miniconda" \
"wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
chmod +x Miniconda3-latest-Linux-x86_64.sh && ./Miniconda3-latest-Linux-x86_64.sh -b \
-p $HOME/miniconda && rm Miniconda3-latest-Linux-x86_64.sh"
# 10b. Configure Conda settings
run_with_spinner "Configuring Conda" "
$HOME/miniconda/bin/conda init &&
$HOME/miniconda/bin/conda config --add channels defaults &&
$HOME/miniconda/bin/conda config --add channels conda-forge &&
$HOME/miniconda/bin/conda config --set auto_activate_base false"
# 11. Install TinyTeX for LaTeX support
run_with_spinner "Installing TinyTeX" " /opt/quarto-${QUARTO_VERSION}/bin/quarto install tinytex --update-path"
# 12a. Install RStudio Server
run_with_spinner "Installing RStudio Server" \
"wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-${RSTUDIO_SERVER_VERSION}-amd64.deb && \
sudo gdebi -n rstudio-server-${RSTUDIO_SERVER_VERSION}-amd64.deb && \
rm rstudio-server-${RSTUDIO_SERVER_VERSION}-amd64.deb"
# 12b. Tweak default RStudio Server settings
run_with_spinner "Updating RStudio Server preferences" \
'PREFERENCES='"'"'{
"insert_native_pipe_operator": true,
"save_workspace": "never",
"load_workspace": "never",
"rainbow_parentheses": true,
"rainbow_fenced_divs": true
}'"'"'; TARGET_FILE="/etc/rstudio/rstudio-prefs.json"; echo "$PREFERENCES" | sudo tee "$TARGET_FILE" > /dev/null'
# 13a. Install VS Code (code-server)
run_with_spinner "Installing VS Code" \
"curl -fsSL https://code-server.dev/install.sh | sh && sudo systemctl enable --now code-server@$USER"
# 13b. Install VS Code extensions
run_with_spinner "Installing VS Code extensions" "
code-server --install-extension ms-python.python && \
code-server --install-extension ms-toolsai.jupyter && \
code-server --install-extension quarto.quarto && \
code-server --install-extension charliermarsh.ruff
"
# 13c. Configure Quarto settings in VS Code
run_with_spinner "Configuring Quarto settings in VS Code" "
mkdir -p $HOME/.local/share/code-server/User && \
echo '{
\"quarto.path\": \"/usr/local/bin/quarto\"
}' > $HOME/.local/share/code-server/User/settings.json
"
# 14. Install GitHub CLI
run_with_spinner "Installing GitHub CLI" \
"(type -p wget >/dev/null || (apt2 update && apt2 install wget -y)) && \
sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- \
https://cli.github.com/packages/githubcli-archive-keyring.gpg | \
sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null && \
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg && \
echo 'deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] \
https://cli.github.com/packages stable main' | \
sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
apt2 update && apt2 install gh -y"
# 15. Install DuckDB CLI
run_with_spinner "Installing DuckDB CLI" \
"curl -fsSL https://install.duckdb.org | sh"
# 16. Install Rust
run_with_spinner "Installing Rust" \
"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
echo 'export PATH=\"$HOME/.cargo/bin:\$PATH\"' >> ~/.bashrc && source ~/.bashrc"
# 17. Install uv
run_with_spinner "Installing uv, ruff, and SQLFluff" \
"curl -LsSf https://astral.sh/uv/install.sh | sh && \
source $HOME/.local/bin/env && \
uv tool install ruff && \
uv tool install sqlfluff && \
uv tool update-shell"
# 18. Set default git branch to main
run_with_spinner "Setting default Git branch to main" \
"git config --global init.defaultBranch main"
# 19. Install rig for managing R versions
run_with_spinner "Installing rig for managing R versions" "
# Add rig GPG key and repository
sudo curl -L https://rig.r-pkg.org/deb/rig.gpg -o /etc/apt/trusted.gpg.d/rig.gpg &&
echo 'deb http://rig.r-pkg.org/deb rig main' | sudo tee /etc/apt/sources.list.d/rig.list &&
apt2 update &&
apt2 install -y r-rig"
# 20. Install Docker
run_with_spinner "Installing Docker" "
# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings &&
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc &&
sudo chmod a+r /etc/apt/keyrings/docker.asc &&
# Add the repository
echo \"deb [arch=\$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
\$(. /etc/os-release && echo \"\$VERSION_CODENAME\") stable\" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null &&
# Install Docker
apt2 update &&
apt2 install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin &&
# Add user to docker group
sudo usermod -aG docker \$USER"
# Post-install message
echo -e "\n${BOLD}Installation complete!${RESET} Log saved to ${GREEN}${LOG_FILE}${RESET}."
echo "${BOLD}Installed tools${RESET}: R, Python, Quarto, RStudio Server, VS Code, DuckDB, Docker, Miniconda, Rust, uv"
echo -e "${BOLD}To finalize setup:${RESET} open a new terminal or log out and back in to update paths."
echo -e "${BOLD}Forward ports for RStudio Server (8787) and VS Code (8080) with${RESET}:
'${GREEN}gcloud compute ssh --zone \"\$ZONE\" \"\$INSTANCE_NAME\" --project \"\$PROJECT_ID\" -- -L 8787:localhost:8787 -L 8080:localhost:8080${RESET}'"
run_with_spinner "Finalizing setup and rebooting \
the system. Please reconnect in a few minutes." "sudo reboot && logout"