forked from postmodern/chruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·183 lines (161 loc) · 6.03 KB
/
setup
File metadata and controls
executable file
·183 lines (161 loc) · 6.03 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
#!/bin/bash
. ./test/helper.sh
function log() {
if [[ -t 1 ]]; then
printf "%b>>>%b %b%s%b\n" "\x1b[1m\x1b[32m" "\x1b[0m" \
"\x1b[1m\x1b[37m" "$1" "\x1b[0m"
else
printf ">>> %s\n" "$1"
fi
}
function error() {
if [[ -t 1 ]]; then
printf "%b!!!%b %b%s%b\n" "\x1b[1m\x1b[31m" "\x1b[0m" \
"\x1b[1m\x1b[37m" "$1" "\x1b[0m" >&2
else
printf "!!! %s\n" "$1" >&2
fi
}
function fail() {
error "$1"
exit -1
}
function download() {
if command -v wget >/dev/null; then
wget -c -O "$2" "$1"
elif command -v curl >/dev/null; then
curl -L -C - -o "$2" "$1"
else
error "Could not find wget or curl"
return 1
fi
}
function detect_system() {
# adapted from RVM: https://github.com/wayneeseguin/rvm/blob/master/scripts/functions/utility_system#L3
system_type="unknown"
system_name="unknown"
system_version="unknown"
system_arch="$(uname -m)"
case "$(uname)" in
(Linux|GNU*)
system_type="linux"
if [[ -f /etc/lsb-release ]] &&
[[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=Ubuntu"* ]]
then
system_name="ubuntu"
system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)"
system_arch="$(dpkg --print-architecture)"
elif [[ -f /etc/lsb-release ]] &&
[[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=LinuxMint"* ]]
then
system_name="mint"
system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)"
system_arch="$( dpkg --print-architecture )"
elif [[ -f /etc/lsb-release ]] &&
[[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=ManjaroLinux"* ]]
then
system_name="manjaro"
system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)"
elif [[ -f /etc/os-release ]] &&
[[ "$(< /etc/os-release)" == *"ID=opensuse"* ]]
then
system_name="opensuse"
system_version="$(awk -F'=' '$1=="VERSION_ID"{gsub(/"/,"");print $2}' /etc/os-release)" #'
elif [[ -f /etc/SuSE-release ]]; then
system_name="suse"
system_version="$(
awk -F'=' '{gsub(/ /,"")} $1~/VERSION/ {version=$2} $1~/PATCHLEVEL/ {patch=$2} END {print version"."patch}' < /etc/SuSE-release
)"
elif [[ -f /etc/debian_version ]]; then
system_name="debian"
system_version="$(< /etc/debian_version | awk -F. '{print $1"."$2}')"
system_arch="$( dpkg --print-architecture )"
elif [[ -f /etc/os-release ]] &&
[[ "$(< /etc/os-release)" == *"ID=debian"* ]]
then
system_name="debian"
system_version="$(awk -F'=' '$1=="VERSION_ID"{gsub(/"/,"");print $2}' /etc/os-release | awk -F. '{print $1"."$2}')" #'
system_arch="$( dpkg --print-architecture )"
elif [[ -f /etc/fedora-release ]]; then
system_name="fedora"
system_version="$(grep -Eo '[[:digit:]]+' /etc/fedora-release)"
elif [[ -f /etc/centos-release ]]; then
system_name="centos"
system_version="$(grep -Eo '[[:digit:]\.]+' /etc/centos-release | awk -F. '{print $1"."$2}')"
elif [[ -f /etc/redhat-release ]]; then
if [[ "$(< /etc/redhat-release)" == *"CentOS"* ]]; then
system_name="centos"
else
system_name="redhat"
fi
system_version="$(grep -Eo '[[:digit:]\.]+' /etc/redhat-release | awk -F. '{print $1"."$2}')"
elif [[ -f /etc/system-release ]] &&
[[ "$(< /etc/system-release)" == *"Amazon Linux AMI"* ]]
then
system_name="amazon"
system_version="$(grep -Eo '[[:digit:]\.]+' /etc/system-release | awk -F. '{print $1"."$2}')"
elif [[ -f /etc/gentoo-release ]]; then
system_name="gentoo"
system_version="base-$(< /etc/gentoo-release | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')"
elif [[ -f /etc/arch-release ]]; then
system_name="arch"
system_version="libc-$(ldd --version | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')"
else
system_version="libc-$(ldd --version | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')"
fi
;;
(SunOS)
system_type="sunos"
system_name="solaris"
system_version="$(uname -v)"
if [[ "${system_version}" == joyent* ]]; then
system_name="smartos"
system_version="${system_version#* }"
elif [[ "${system_version}" == oi* ]]; then
system_name="openindiana"
system_version="${system_version#* }"
fi
;;
(OpenBSD)
system_type="bsd"
system_name="openbsd"
system_version="$(uname -r)"
;;
(Darwin)
system_type="darwin"
system_name="osx"
system_version="$(sw_vers -productVersion)"
system_version="${system_version%.*}" # only major.minor - teeny is ignored
;;
(FreeBSD)
system_type="bsd"
system_name="freebsd"
system_version="$(uname -r)"
system_version="${system_version%%-*}"
;;
(*)
return 1
;;
esac
system_type="${system_type//[ \/]/_}"
system_name="${system_name//[ \/]/_}"
system_version="${system_version//[ \/]/_}"
system_arch="${system_arch//[ \/]/_}"
system_arch="${system_arch/amd64/x86_64}"
system_arch="${system_arch/i[123456789]86/i386}"
}
detect_system || fail "Cannot auto-detect system type"
[[ "$system_name" == "unknown" ]] && fail "Could not detect system name"
[[ "$system_version" == "unknown" ]] && fail "Could not detect system version"
[[ "$system_arch" == "unknown" ]] && fail "Could not detect system arch"
test_ruby_archive="$test_ruby_engine-$test_ruby_version-p$test_ruby_patchlevel.tar.bz2"
test_ruby_url="http://rvm.io/binaries/$system_name/$system_version/$system_arch/$test_ruby_archive"
test_ruby_root="$test_ruby_engine-$test_ruby_version-p$test_ruby_patchlevel"
mkdir -p "$PREFIX/opt/rubies"
cd "$PREFIX/opt/rubies"
log "Downloading $test_ruby_url ..."
download "$test_ruby_url" "$test_ruby_archive" || fail "Download failed"
log "Unpacking $test_ruby_archive ..."
tar -xjf "$test_ruby_archive" || fail "Unpacking failed"
log "Cleaning up ..."
rm -f "$test_ruby_archive"