Files
Sovran_SystemsOS/iso/installer.sh
2026-03-29 08:06:21 -05:00

176 lines
6.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
LOG=/tmp/sovran-install.log
exec > >(tee -a "$LOG") 2>&1
export PATH=/run/current-system/sw/bin:$PATH
# Changed to 2TB cutoff
BYTES_2TB=$((2 * 1024 * 1024 * 1024 * 1024))
LOGO="/etc/sovran/logo.png"
human_size() {
numfmt --to=iec --suffix=B "$1"
}
# ── 1. WELCOME & ROLE SELECTION ──────────────────────────────────────────
ROLE=$(zenity --list --radiolist \
--window-icon="$LOGO" \
--width=1000 --height=400 \
--title="Welcome to Sovran SystemsOS" \
--text="<span font='36' weight='heavy'>Sovran Systems</span>\n<span font='16' style='italic' foreground='#aaaaaa'>Be Digitally Sovereign</span>\n\nPlease select your preferred installation type:" \
--print-column=3 \
--column="Select" --column="Logo" --column="Role" --column="Description" \
TRUE "🖥️" "Server+Desktop" "Gives you the full Sovereign Experience. A beautiful, easy-to-use, powerful daily driver desktop computer plus your very own cloud, website, secure messaging, video calling, password manager, and full Bitcoin node with Bitcoin Lightning and non-KYC buying and selling." \
FALSE "💻" "Desktop Only" "The same beautiful, easy-to-use desktop experience, but just the desktop without the background server applications." \
FALSE "₿" "Node (Bitcoin-only)" "Full Bitcoin node with Bitcoin Lightning and non-KYC buying and selling." || true)
if [ -z "$ROLE" ]; then
zenity --error --window-icon="$LOGO" --text="Installation cancelled."
exit 1
fi
# ── 2. FETCH DISKS ───────────────────────────────────────────────────────
# Filter out USB drives and loop/cdrom devices so it doesn't try to install to the installation media
mapfile -t DISKS < <(lsblk -b -dno NAME,SIZE,TYPE,RO,TRAN -e 7,11 | awk '$3=="disk" && $4=="0" && $5!="usb" {print $1":"$2}')
if [ "${#DISKS[@]}" -eq 0 ]; then
zenity --error --window-icon="$LOGO" --text="No valid internal drives found. (USB drives are ignored)"
exit 1
fi
IFS=$'\n' DISKS_SORTED=($(printf "%s\n" "${DISKS[@]}" | sort -t: -k2,2n))
unset IFS
BOOT_DISK="${DISKS_SORTED[0]%%:*}"
BOOT_SIZE="${DISKS_SORTED[0]##*:}"
DATA_DISK=""
DATA_SIZE=""
if [ "${#DISKS_SORTED[@]}" -ge 2 ]; then
DATA_DISK="${DISKS_SORTED[-1]%%:*}"
DATA_SIZE="${DISKS_SORTED[-1]##*:}"
fi
# Updated to check against 2TB
if [ -n "$DATA_DISK" ] && [ "$DATA_SIZE" -lt "$BYTES_2TB" ]; then
zenity --warning --window-icon="$LOGO" --text="Second disk detected (${DATA_DISK}), but it is smaller than 2TB.\n\nIt will NOT be used."
DATA_DISK=""
DATA_SIZE=""
fi
SUMMARY="Boot disk: /dev/${BOOT_DISK} ($(human_size "$BOOT_SIZE"))"
if [ -n "$DATA_DISK" ]; then
SUMMARY="${SUMMARY}\nData disk: /dev/${DATA_DISK} ($(human_size "$DATA_SIZE"))"
else
SUMMARY="${SUMMARY}\nData disk: none"
fi
CONFIRM=$(zenity --entry --window-icon="$LOGO" --text="WARNING: This will ERASE ALL DATA on:\n\n${SUMMARY}\n\nType ERASE to continue.")
if [ "$CONFIRM" != "ERASE" ]; then
zenity --error --window-icon="$LOGO" --text="Install cancelled."
exit 1
fi
BOOT_PATH="/dev/${BOOT_DISK}"
DATA_PATH=""
if [ -n "$DATA_DISK" ]; then
DATA_PATH="/dev/${DATA_DISK}"
fi
# ── 3. PARTITION & FORMAT ─────────────────────────────────────────────────
# Run Disko to partition and format drives
# Use --arg (not --argstr) so device paths are passed as Nix string values correctly
(
if [ -n "$DATA_PATH" ]; then
disko --mode disko /etc/sovran/flake/iso/disko.nix \
--arg device '"'"$BOOT_PATH"'"' \
--arg dataDevice '"'"$DATA_PATH"'"'
else
disko --mode disko /etc/sovran/flake/iso/disko.nix \
--arg device '"'"$BOOT_PATH"'"'
fi
) 2>&1 | zenity --progress --pulsing \
--window-icon="$LOGO" \
--title="Partitioning Drives" \
--text="Partitioning and formatting your drives...\n\nThis will take a moment." \
--width=500 \
--auto-close \
--no-cancel
nixos-generate-config --root /mnt
cp /mnt/etc/nixos/hardware-configuration.nix /tmp/hardware-configuration.nix
rm -rf /mnt/etc/nixos/*
cp -a /etc/sovran/flake/* /mnt/etc/nixos/
cp /tmp/hardware-configuration.nix /mnt/etc/nixos/hardware-configuration.nix
# ── 4. APPLY ROLE STATE & TEMPLATE ───────────────────────────────────────
IS_SERVER="false"
IS_DESKTOP="false"
IS_NODE="false"
case "$ROLE" in
"Server+Desktop") IS_SERVER="true" ;;
"Desktop Only") IS_DESKTOP="true" ;;
"Node (Bitcoin-only)") IS_NODE="true" ;;
esac
cat > /mnt/etc/nixos/role-state.nix <<EOF
# THIS FILE IS AUTO-GENERATED BY THE INSTALLER. DO NOT EDIT.
# To change your role later, edit custom.nix instead.
{ config, lib, ... }:
{
sovran_systemsOS.roles.server_plus_desktop = lib.mkDefault ${IS_SERVER};
sovran_systemsOS.roles.desktop = lib.mkDefault ${IS_DESKTOP};
sovran_systemsOS.roles.node = lib.mkDefault ${IS_NODE};
}
EOF
# Copy the pristine custom.template.nix for the user to edit
cp /mnt/etc/nixos/custom.template.nix /mnt/etc/nixos/custom.nix
# ── 5. VERIFY FILES BEFORE INSTALL ───────────────────────────────────────
# Sanity check: ensure role-state.nix and custom.nix exist before calling nixos-install
for f in /mnt/etc/nixos/role-state.nix /mnt/etc/nixos/custom.nix; do
if [ ! -f "$f" ]; then
zenity --error --window-icon="$LOGO" --width=500 \
--title="Installation Error" \
--text="<b>A required file is missing:</b>\n\n<tt>${f}</tt>\n\nThe installation cannot continue. Please check the log at <tt>${LOG}</tt> and try again."
exit 1
fi
done
# ── 6. FINAL INSTALL & REBOOT ────────────────────────────────────────────
nixos-install --root /mnt --flake /mnt/etc/nixos#nixos 2>&1 | \
zenity --progress --pulsing \
--window-icon="$LOGO" \
--title="Installing Sovran SystemsOS" \
--text="Installing your system...\n\nThis may take 2040 minutes depending on your internet speed.\nPlease do not turn off your computer." \
--width=500 \
--auto-close \
--no-cancel
zenity --info --width=600 --title="INSTALLATION COMPLETE! 🎉 PLEASE READ" --text="<b><span size='large'>Installation Successful!</span></b>
Before you reboot, please write down your main login details:
<b>Username:</b> free
<b>Password:</b> free
🚨 <b>CRITICAL:</b> Do not lose this password! If you forget this, you will be permanently locked out of your computer.
📁 <b>Other Passwords:</b> Once the system reboots, it will finish building your forts and generate all the passwords for your apps (Nextcloud, Bitcoin, Matrix, etc.). It will save them in a secure PDF in your <b>Documents</b> folder.
Click OK to reboot into your new system!"
reboot