-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·133 lines (110 loc) · 3.62 KB
/
install.sh
File metadata and controls
executable file
·133 lines (110 loc) · 3.62 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
#!/bin/sh
set -e
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
VERSION_MANAGER="${VERSIONMANAGER:-"mise"}"
USE_PRECOMPILED_RUBIES="${USEPRECOMPILEDRUBIES:-"false"}"
# Function to install dependencies needed for building Ruby
install_dependencies() {
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
git \
curl \
ca-certificates \
libssl-dev \
libreadline-dev \
zlib1g-dev \
autoconf \
bison \
build-essential \
libyaml-dev \
libncurses5-dev \
libffi-dev \
libgdbm-dev \
libxml2-dev \
rustc
}
# Function to add lines to shell initialization files
add_to_shell_init() {
_user="$1"
_bash_line="$2"
_zsh_line="${3:-$_bash_line}" # Use bash_line as default if zsh_line not provided
if [ "$_user" = "root" ]; then
_home_dir="/root"
else
_home_dir="/home/$_user"
fi
echo "$_bash_line" >> "$_home_dir/.bashrc"
if [ -f "$_home_dir/.zshrc" ]; then
echo "$_zsh_line" >> "$_home_dir/.zshrc"
fi
}
# Function to setup rbenv
setup_rbenv() {
_user="$1"
_user_home="/home/$_user"
# Clone rbenv and ruby-build
git clone https://github.com/rbenv/rbenv.git /usr/local/share/rbenv
git clone https://github.com/rbenv/ruby-build.git /usr/local/share/ruby-build
# Setup plugins for root
mkdir -p /root/.rbenv/plugins
ln -s /usr/local/share/ruby-build /root/.rbenv/plugins/ruby-build
# Setup for non-root user if needed
if [ "$_user" != "root" ]; then
mkdir -p "$_user_home/.rbenv/plugins"
ln -s /usr/local/share/ruby-build "$_user_home/.rbenv/plugins/ruby-build"
chown -R "$_user" "$_user_home/.rbenv/"
chmod -R g+r+w "$_user_home/.rbenv"
fi
# shellcheck disable=SC2016
add_to_shell_init "$_user" 'export PATH="/usr/local/share/rbenv/bin:$PATH"'
# shellcheck disable=SC2016
add_to_shell_init "$_user" 'eval "$(rbenv init -)"'
}
# Function to install Ruby with rbenv
install_ruby_rbenv() {
_user="$1"
_version="$2"
su "$_user" -c "/usr/local/share/rbenv/bin/rbenv install $_version"
su "$_user" -c "/usr/local/share/rbenv/bin/rbenv global $_version"
}
# Function to setup mise
setup_mise() {
_user="$1"
_use_precompiled_rubies="$2"
if [ "$_user" = "root" ]; then
_home_dir="/root"
else
_home_dir="/home/$_user"
fi
su "$_user" -c "curl https://mise.run | sh"
if [ "$_use_precompiled_rubies" = "true" ]; then
su "$_user" -c "$_home_dir/.local/bin/mise settings ruby.compile=false"
else
su "$_user" -c "$_home_dir/.local/bin/mise settings ruby.compile=true"
fi
# shellcheck disable=SC2016
add_to_shell_init "$_user" 'eval "$(~/.local/bin/mise activate bash)"' 'eval "$(~/.local/bin/mise activate zsh)"'
}
# Function to install Ruby with mise
install_ruby_mise() {
_user="$1"
_version="$2"
if [ "$_user" = "root" ]; then
_home_dir="/root"
else
_home_dir="/home/$_user"
fi
su "$_user" -c "$_home_dir/.local/bin/mise install ruby@$_version"
su "$_user" -c "$_home_dir/.local/bin/mise use -g ruby@$_version"
su "$_user" -c "$_home_dir/.local/bin/mise settings add idiomatic_version_file_enable_tools ruby"
}
install_dependencies
# Setup version manager and install Ruby based on user choice
if [ "$VERSION_MANAGER" = "rbenv" ]; then
setup_rbenv "$USERNAME"
install_ruby_rbenv "$USERNAME" "$VERSION"
else
setup_mise "$USERNAME" "$USE_PRECOMPILED_RUBIES"
install_ruby_mise "$USERNAME" "$VERSION"
fi
rm -rf /var/lib/apt/lists/*