-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsetup.sh
More file actions
195 lines (134 loc) · 5.48 KB
/
setup.sh
File metadata and controls
195 lines (134 loc) · 5.48 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
#!/bin/bash
# 2021 Dawson Della Valle <ddellavalle@45drives.com>
# 2025 Brett Kelly <bkelly@45drives.com>
# v2
# OS Supported
# Rocky 7,8,9
# Ubuntu 20,22
# Debian Bookworm
# curl -sSL https://repo.45drives.com/setup -o setup-repo.sh &&
# sudo bash setup-repo.sh &&
# rm setup-repo.sh
# curl -sSL https://repo.45drives.com/setup -o setup-repo.sh && sudo bash setup-repo.sh && rm setup-repo.sh
# curl -sSL https://repo.45drives.com/setup | sudo bash
function get_base_distro() {
local distro=$(cat /etc/os-release | grep '^ID_LIKE=' | head -1 | sed 's/ID_LIKE=//' | sed 's/"//g' | awk '{print $1}')
if [ -z "$distro" ]; then
distro=$(cat /etc/os-release | grep '^ID=' | head -1 | sed 's/ID=//' | sed 's/"//g' | awk '{print $1}')
fi
echo $distro
}
function get_distro() {
local distro=$(cat /etc/os-release | grep '^ID=' | head -1 | sed 's/ID=//' | sed 's/"//g' | awk '{print $1}')
echo $distro
}
function get_version_id() {
local version_id=$(cat /etc/os-release | grep '^VERSION_ID=' | head -1 | sed 's/VERSION_ID=//' | sed 's/"//g' | awk '{print $1}' | awk 'BEGIN {FS="."} {print $1}')
echo $version_id
}
function get_codename() {
local distro=$(cat /etc/os-release | grep '^VERSION_CODENAME' | cut -d = -f2)
echo $distro
}
euid=$(id -u)
if [ $euid -ne 0 ]; then
echo -e '\nYou must be root to run this utility.\n'
exit 1
fi
distro=$(get_base_distro)
custom_distro=$(get_distro)
distro_version=$(get_version_id)
distro_codename=$(get_codename)
if [ "$distro" == "rhel" ] || [ "$distro" == "fedora" ]; then
echo "Detected RHEL-based distribution. Continuing..."
items=$(find /etc/yum.repos.d -name '45drives.repo')
if [[ -z "$items" ]]; then
echo "There were no existing 45Drives repos found. Setting up the new repo..."
else
count=$(echo "$items" | wc -l)
echo "There were $count 45Drives repo(s) found. Archiving..."
mkdir -p /opt/45drives/archives/repos
mv /etc/yum.repos.d/45drives.repo /opt/45drives/archives/repos/45drives-$(date +%Y-%m-%d).repo
echo "The obsolete repos have been archived to '/opt/45drives/archives/repos'. Setting up the new repo..."
fi
curl -sSL https://repo.45drives.com/repofiles/rocky/45drives-enterprise.repo -o /etc/yum.repos.d/45drives-enterprise.repo
res=$?
if [ "$res" -ne "0" ]; then
echo "Failed to download the new repo file. Please review the above error and try again."
exit 1
fi
el_id="none"
if [[ "$distro_version" == "7" ]] || [[ "$distro_version" == "8" ]] || [[ "$distro_version" == "9" ]]; then
el_id=$distro_version
fi
if [[ "$el_id" == "none" ]]; then
echo "Failed to detect the repo that would best suit your system. Please contact repo@45drives.com to get this issue rectified!"
exit 1
fi
res=$?
if [ "$res" -ne "0" ]; then
echo "Failed to update the new repo file. Please review the above error and try again."
exit 1
fi
echo "The new repo file has been downloaded. Updating your package lists..."
pm_bin=dnf
command -v dnf > /dev/null 2>&1 || {
pm_bin=yum
}
echo "Using the '$pm_bin' package manager..."
$pm_bin clean all -y
res=$?
if [ "$res" -ne "0" ]; then
echo "Failed to run '$pm_bin clean all -y'. Please review the above error and try again."
exit 1
fi
echo "Success! Your repo has been updated to our new server!"
exit 0
fi
if [ "$distro" == "debian" ]; then
echo "Detected Debian-based distribution. Continuing..."
items=$(find /etc/apt/sources.list.d -name 45drives.list)
if [[ -z "$items" ]]; then
echo "There were no existing 45Drives repos found. Setting up the new repo..."
else
count=$(echo "$items" | wc -l)
echo "There were $count 45Drives repo(s) found. Archiving..."
mkdir -p /opt/45drives/archives/repos
mv /etc/apt/sources.list.d/45drives.list /opt/45drives/archives/repos/45drives-$(date +%Y-%m-%d).list
echo "The obsolete repos have been archived to '/opt/45drives/archives/repos'. Setting up the new repo..."
fi
if [[ -f "/etc/apt/sources.list.d/45drives.sources" ]]; then
rm -f /etc/apt/sources.list.d/45drives.sources
fi
echo "Updating ca-certificates to ensure certificate validity..."
apt update
apt install ca-certificates -y
wget -qO - https://repo.45drives.com/key/gpg.asc | gpg --pinentry-mode loopback --batch --yes --dearmor -o /usr/share/keyrings/45drives-archive-keyring.gpg
res=$?
if [ "$res" -ne "0" ]; then
echo "Failed to add the gpg key to the apt keyring. Please review the above error and try again."
exit 1
fi
curl -sSL https://repo.45drives.com/repofiles/$custom_distro/45drives-enterprise-$distro_codename.list -o /etc/apt/sources.list.d/45drives-enterprise-$distro_codename.list
res=$?
if [ "$res" -ne "0" ]; then
echo "Failed to download the new repo file. Please review the above error and try again."
exit 1
fi
if [[ "$distro_codename" != "focal" ]] && [[ "$distro_codename" != "jammy" ]] && [[ "$distro_codename" != "bookworm" ]]; then
echo "You are on an unsupported version of Debian/Ubuntu. Current repo support is Ubuntu 22 (jammy), Ubuntu 20(focal), and Debian 12 (Bookworm)"
exit 1
fi
echo "The new repo file has been downloaded. Updating your package lists..."
pm_bin=apt
$pm_bin update -y
res=$?
if [ "$res" -ne "0" ]; then
echo "Failed to run '$pm_bin update -y'. Please review the above error and try again."
exit 1
fi
echo "Success! Your repo has been updated to our new server!"
exit 0
fi
echo -e "\nThis command has been run on a distribution that is not supported by the 45Drives Team.\n\nIf you believe this is a mistake, please contact our team at repo@45drives.com!\n"
exit 1