|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# 2021 Dawson Della Valle <ddellavalle@45drives.com> |
| 4 | +# 2025 Brett Kelly <bkelly@45drives.com> |
| 5 | +# v2 |
| 6 | +# OS Supported |
| 7 | +# Rocky 7,8,9 |
| 8 | +# Ubuntu 20,22 |
| 9 | +# Debian Bookworm |
| 10 | + |
| 11 | +# curl -sSL https://repo.45drives.com/setup -o setup-repo.sh && |
| 12 | +# sudo bash setup-repo.sh && |
| 13 | +# rm setup-repo.sh |
| 14 | + |
| 15 | +# curl -sSL https://repo.45drives.com/setup -o setup-repo.sh && sudo bash setup-repo.sh && rm setup-repo.sh |
| 16 | + |
| 17 | +# curl -sSL https://repo.45drives.com/setup | sudo bash |
| 18 | + |
| 19 | +function get_base_distro() { |
| 20 | + local distro=$(cat /etc/os-release | grep '^ID_LIKE=' | head -1 | sed 's/ID_LIKE=//' | sed 's/"//g' | awk '{print $1}') |
| 21 | + |
| 22 | + if [ -z "$distro" ]; then |
| 23 | + distro=$(cat /etc/os-release | grep '^ID=' | head -1 | sed 's/ID=//' | sed 's/"//g' | awk '{print $1}') |
| 24 | + fi |
| 25 | + |
| 26 | + echo $distro |
| 27 | +} |
| 28 | + |
| 29 | +function get_distro() { |
| 30 | + local distro=$(cat /etc/os-release | grep '^ID=' | head -1 | sed 's/ID=//' | sed 's/"//g' | awk '{print $1}') |
| 31 | + |
| 32 | + echo $distro |
| 33 | +} |
| 34 | + |
| 35 | +function get_version_id() { |
| 36 | + 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}') |
| 37 | + |
| 38 | + echo $version_id |
| 39 | +} |
| 40 | + |
| 41 | +function get_codename() { |
| 42 | + local distro=$(cat /etc/os-release | grep '^VERSION_CODENAME' | cut -d = -f2) |
| 43 | + |
| 44 | + echo $distro |
| 45 | +} |
| 46 | + |
| 47 | +euid=$(id -u) |
| 48 | + |
| 49 | +if [ $euid -ne 0 ]; then |
| 50 | + echo -e '\nYou must be root to run this utility.\n' |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +distro=$(get_base_distro) |
| 55 | +custom_distro=$(get_distro) |
| 56 | +distro_version=$(get_version_id) |
| 57 | +distro_codename=$(get_codename) |
| 58 | + |
| 59 | +if [ "$distro" == "rhel" ] || [ "$distro" == "fedora" ]; then |
| 60 | + echo "Detected RHEL-based distribution. Continuing..." |
| 61 | + |
| 62 | + items=$(find /etc/yum.repos.d -name '45drives.repo') |
| 63 | + |
| 64 | + if [[ -z "$items" ]]; then |
| 65 | + echo "There were no existing 45Drives repos found. Setting up the new repo..." |
| 66 | + else |
| 67 | + count=$(echo "$items" | wc -l) |
| 68 | + echo "There were $count 45Drives repo(s) found. Archiving..." |
| 69 | + |
| 70 | + mkdir -p /opt/45drives/archives/repos |
| 71 | + |
| 72 | + mv /etc/yum.repos.d/45drives.repo /opt/45drives/archives/repos/45drives-$(date +%Y-%m-%d).repo |
| 73 | + |
| 74 | + echo "The obsolete repos have been archived to '/opt/45drives/archives/repos'. Setting up the new repo..." |
| 75 | + fi |
| 76 | + |
| 77 | + curl -sSL https://repo.45drives.com/repofiles/rocky/45drives-enterprise.repo -o /etc/yum.repos.d/45drives-enterprise.repo |
| 78 | + |
| 79 | + res=$? |
| 80 | + |
| 81 | + if [ "$res" -ne "0" ]; then |
| 82 | + echo "Failed to download the new repo file. Please review the above error and try again." |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + |
| 86 | + el_id="none" |
| 87 | + |
| 88 | + if [[ "$distro_version" == "7" ]] || [[ "$distro_version" == "8" ]] || [[ "$distro_version" == "9" ]]; then |
| 89 | + el_id=$distro_version |
| 90 | + fi |
| 91 | + |
| 92 | + if [[ "$el_id" == "none" ]]; then |
| 93 | + echo "Failed to detect the repo that would best suit your system. Please contact repo@45drives.com to get this issue rectified!" |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | + |
| 97 | + res=$? |
| 98 | + |
| 99 | + if [ "$res" -ne "0" ]; then |
| 100 | + echo "Failed to update the new repo file. Please review the above error and try again." |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + |
| 104 | + echo "The new repo file has been downloaded. Updating your package lists..." |
| 105 | + |
| 106 | + pm_bin=dnf |
| 107 | + |
| 108 | + command -v dnf > /dev/null 2>&1 || { |
| 109 | + pm_bin=yum |
| 110 | + } |
| 111 | + |
| 112 | + echo "Using the '$pm_bin' package manager..." |
| 113 | + |
| 114 | + $pm_bin clean all -y |
| 115 | + |
| 116 | + res=$? |
| 117 | + |
| 118 | + if [ "$res" -ne "0" ]; then |
| 119 | + echo "Failed to run '$pm_bin clean all -y'. Please review the above error and try again." |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | + |
| 123 | + echo "Success! Your repo has been updated to our new server!" |
| 124 | + exit 0 |
| 125 | +fi |
| 126 | + |
| 127 | +if [ "$distro" == "debian" ]; then |
| 128 | + echo "Detected Debian-based distribution. Continuing..." |
| 129 | + |
| 130 | + items=$(find /etc/apt/sources.list.d -name 45drives.list) |
| 131 | + |
| 132 | + if [[ -z "$items" ]]; then |
| 133 | + echo "There were no existing 45Drives repos found. Setting up the new repo..." |
| 134 | + else |
| 135 | + count=$(echo "$items" | wc -l) |
| 136 | + echo "There were $count 45Drives repo(s) found. Archiving..." |
| 137 | + |
| 138 | + mkdir -p /opt/45drives/archives/repos |
| 139 | + |
| 140 | + mv /etc/apt/sources.list.d/45drives.list /opt/45drives/archives/repos/45drives-$(date +%Y-%m-%d).list |
| 141 | + |
| 142 | + echo "The obsolete repos have been archived to '/opt/45drives/archives/repos'. Setting up the new repo..." |
| 143 | + fi |
| 144 | + |
| 145 | + if [[ -f "/etc/apt/sources.list.d/45drives.sources" ]]; then |
| 146 | + rm -f /etc/apt/sources.list.d/45drives.sources |
| 147 | + fi |
| 148 | + |
| 149 | + echo "Updating ca-certificates to ensure certificate validity..." |
| 150 | + |
| 151 | + apt update |
| 152 | + apt install ca-certificates -y |
| 153 | + |
| 154 | + wget -qO - https://repo.45drives.com/key/gpg.asc | gpg --pinentry-mode loopback --batch --yes --dearmor -o /usr/share/keyrings/45drives-archive-keyring.gpg |
| 155 | + |
| 156 | + res=$? |
| 157 | + |
| 158 | + if [ "$res" -ne "0" ]; then |
| 159 | + echo "Failed to add the gpg key to the apt keyring. Please review the above error and try again." |
| 160 | + exit 1 |
| 161 | + fi |
| 162 | + |
| 163 | + 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 |
| 164 | + |
| 165 | + res=$? |
| 166 | + |
| 167 | + if [ "$res" -ne "0" ]; then |
| 168 | + echo "Failed to download the new repo file. Please review the above error and try again." |
| 169 | + exit 1 |
| 170 | + fi |
| 171 | + |
| 172 | + if [[ "$distro_codename" != "focal" ]] && [[ "$distro_codename" != "jammy" ]] && [[ "$distro_codename" != "bookworm" ]]; then |
| 173 | + echo "You are on an unsupported version of Debian/Ubuntu. Current repo support is Ubuntu 22 (jammy), Ubuntu 20(focal), and Debian 12 (Bookworm)" |
| 174 | + exit 1 |
| 175 | + fi |
| 176 | + |
| 177 | + echo "The new repo file has been downloaded. Updating your package lists..." |
| 178 | + |
| 179 | + pm_bin=apt |
| 180 | + |
| 181 | + $pm_bin update -y |
| 182 | + |
| 183 | + res=$? |
| 184 | + |
| 185 | + if [ "$res" -ne "0" ]; then |
| 186 | + echo "Failed to run '$pm_bin update -y'. Please review the above error and try again." |
| 187 | + exit 1 |
| 188 | + fi |
| 189 | + |
| 190 | + echo "Success! Your repo has been updated to our new server!" |
| 191 | + exit 0 |
| 192 | +fi |
| 193 | + |
| 194 | +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" |
| 195 | +exit 1 |
0 commit comments