|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# For fresh installs of Rocky (8) |
| 4 | +# Installs desktop environment + sets up distros |
| 5 | + |
| 6 | +get_base_distro() { |
| 7 | + local base_distro |
| 8 | + base_distro=$(grep '^ID_LIKE=' /etc/os-release | cut -d= -f2 | tr -d '"' | awk '{print $1}') |
| 9 | + |
| 10 | + if [ -z "$base_distro" ]; then |
| 11 | + # fallback to ID if ID_LIKE is not found |
| 12 | + base_distro=$(grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"' | awk '{print $1}') |
| 13 | + fi |
| 14 | + |
| 15 | + echo "$base_distro" |
| 16 | +} |
| 17 | + |
| 18 | +get_distro() { |
| 19 | + grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"' |
| 20 | +} |
| 21 | + |
| 22 | +get_version_id() { |
| 23 | + grep '^VERSION_ID=' /etc/os-release | cut -d= -f2 | tr -d '"' | cut -d '.' -f1 |
| 24 | +} |
| 25 | + |
| 26 | +require_root() { |
| 27 | + if [ "$(id -u)" -ne 0 ]; then |
| 28 | + echo "This script must be run as root." |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | +} |
| 32 | + |
| 33 | +backup_existing_repo() { |
| 34 | + if [[ -f /etc/yum.repos.d/45drives.repo ]]; then |
| 35 | + mkdir -p /opt/45drives/archives/repos |
| 36 | + mv /etc/yum.repos.d/45drives.repo /opt/45drives/archives/repos/45drives-$(date +%F).repo |
| 37 | + echo "Existing 45Drives repo backed up." |
| 38 | + fi |
| 39 | + if [[ -f /etc/apt/sources.list.d/45drives.list ]]; then |
| 40 | + mkdir -p /opt/45drives/archives/repos |
| 41 | + mv /etc/apt/sources.list.d/45drives.list /opt/45drives/archives/repos/45drives-$(date +%F).list |
| 42 | + echo "Existing 45Drives APT repo backed up." |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +install_desktop_env() { |
| 47 | + if [[ $distro == "rhel" || $distro == "fedora" ]]; then |
| 48 | + echo "Installing XFCE Desktop Environment for Rocky/RHEL..." |
| 49 | + dnf update -y |
| 50 | + dnf install -y epel-release kernel-headers |
| 51 | + dnf groupinstall -y "Xfce" "base-x" |
| 52 | + echo "exec /usr/bin/xfce4-session" >> ~/.xinitrc |
| 53 | + systemctl set-default graphical |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +add_cockpit_overrides() { |
| 58 | + echo "Adding Cockpit override configurations..." |
| 59 | + cat > /usr/share/cockpit/45drives-system/override.json <<EOF |
| 60 | +{ |
| 61 | + "menu": { |
| 62 | + "45drives-system": { |
| 63 | + "order": 112 |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +EOF |
| 68 | +} |
| 69 | + |
| 70 | +allow_root_in_cockpit() { |
| 71 | + echo "Ensuring root is allowed in Cockpit..." |
| 72 | + local disallowed_file="/etc/cockpit/disallowed-users" |
| 73 | + |
| 74 | + if [[ -f "$disallowed_file" ]]; then |
| 75 | + grep -q "^root$" "$disallowed_file" && { |
| 76 | + sed -i '/^root$/d' "$disallowed_file" |
| 77 | + echo "Removed root from $disallowed_file" |
| 78 | + } || echo "Root not present in disallowed-users" |
| 79 | + else |
| 80 | + echo "$disallowed_file does not exist. Skipping." |
| 81 | + fi |
| 82 | +} |
| 83 | + |
| 84 | +run_preconfig_inline() { |
| 85 | + echo "Running integrated preconfiguration for $distro_id $distro_version..." |
| 86 | + backup_existing_repo |
| 87 | + |
| 88 | + if [[ "$distro" == "rhel" || "$distro" == "fedora" ]]; then |
| 89 | + setenforce 0 |
| 90 | + sed -i 's/SELINUX=.*/SELINUX=permissive/' /etc/selinux/config |
| 91 | + curl -sSL https://repo.45drives.com/setup | bash |
| 92 | + dnf install -y cockpit cockpit-pcp cockpit-benchmark cockpit-navigator cockpit-file-sharing cockpit-45drives-hardware cockpit-identities cockpit-sosreport cockpit-storaged cockpit-scheduler |
| 93 | + firewall-cmd --add-service=cockpit --permanent && firewall-cmd --reload |
| 94 | + systemctl enable --now cockpit.socket |
| 95 | + dnf update -y |
| 96 | + fi |
| 97 | + |
| 98 | + allow_root_in_cockpit |
| 99 | + |
| 100 | + echo "Preconfiguration complete. Houston UI available at: https://$(hostname -I | awk '{print $1}'):9090" |
| 101 | +} |
| 102 | + |
| 103 | +# Start Execution |
| 104 | +require_root |
| 105 | +distro=$(get_base_distro) |
| 106 | +distro_id=$(get_distro) |
| 107 | +distro_version=$(get_version_id) |
| 108 | + |
| 109 | +echo "Detected distro: $distro_id (base: $distro), version: $distro_version" |
| 110 | + |
| 111 | +if [[ "$distro" != "rhel" && "$distro" != "fedora" && "$distro" != "rocky" ]]; then |
| 112 | + echo "This is an unsupported distro. Please run on a Rocky, RHEL, or Fedora system." |
| 113 | + exit 1 |
| 114 | +fi |
| 115 | + |
| 116 | +install_desktop_env |
| 117 | +run_preconfig_inline |
| 118 | + |
| 119 | +echo "Finished initial setup.... Reboot required." |
| 120 | +echo "Run ZFS-setup.sh after reboot to install zfs and cockpit zfs modules" |
| 121 | + |
| 122 | +read -n 1 -s -r -p "Press any key to reboot..." |
| 123 | +echo |
| 124 | + |
| 125 | +sudo reboot |
| 126 | + |
0 commit comments