#!/bin/bash # # Purpose : Check the machine before install.sh sets it up, and offer to fix # what can be fixed: too little disk space, / not on btrfs, a login # screen other than GNOME's GDM, PulseAudio instead of PipeWire. # Exits 1 to stop the install. refresh runs install.sh again, so it # says nothing on a machine where all is well. COREDESKTOP="$HOME/.local/share/coredesktop" source "$COREDESKTOP/utils.sh" SERVICES_OFF="$HOME/.config/coredesktop/services-off" # install.sh is usually piped into bash, so ask on the terminal TTY="${COREDESKTOP_TTY:-/dev/tty}" # ask ask() { local answer if ! { : < "$TTY"; } 2> /dev/null; then [ "$3" = y ] return fi if [ "$2" = y ]; then read -rp "$1 [Y/n] " answer < "$TTY" [[ "$answer" != [nN]* ]] else read -rp "$1 [y/N] " answer < "$TTY" [[ "$answer" == [yY]* ]] fi } # Set up before: install.sh records migrations as its last step already_installed() { [ -d "$HOME/.local/state/coredesktop/migrations" ] } check_disk() { local need=60 free already_installed && need=10 free="$(df -k --output=avail / | tail -n 1 | tr -d ' ')" [[ "$free" =~ ^[0-9]+$ ]] || return 0 free=$(( free / 1024 / 1024 )) (( free < need )) || return 0 echo "Only $free GB is free on /, and this needs about $need GB." ask "Continue anyway?" n n } # Can't be fixed without reinstalling Arch, so only asked about the first time check_btrfs() { local fstype already_installed && return 0 fstype="$(findmnt -no FSTYPE /)" [ "$fstype" = btrfs ] && return 0 echo "/ is on $fstype, not btrfs, so update can't take a snapshot first, and a bad" echo "update can't be rolled back (see Snapshots in the README). Only reinstalling Arch" echo "with btrfs, archinstall's default, changes that." ask "Continue without snapshots?" y y } # CoreDesktop turns on GDM, which fails while another login screen is on check_display_manager() { local dm dm="$(readlink /etc/systemd/system/display-manager.service 2> /dev/null)" dm="$(basename "${dm:-none}")" [ "$dm" = none ] || [ "$dm" = gdm.service ] && return 0 grep -qsx "system gdm.service" "$SERVICES_OFF" && return 0 echo "This machine's login screen is ${dm%.service}, not GNOME's (GDM)." if ask "Switch to GNOME's login screen? It takes over when you restart." y n; then # enable_services turns GDM on later in the install sudo systemctl disable "$dm" || return 1 else mkdir -p "$(dirname "$SERVICES_OFF")" echo "system gdm.service" >> "$SERVICES_OFF" echo "Keeping ${dm%.service}. Choose GNOME from its session menu when you log in." echo "To switch later: sudo systemctl disable $dm && sudo systemctl enable gdm" echo "then delete the line \"system gdm.service\" from $SERVICES_OFF" fi } # PipeWire replaces PulseAudio; GNOME's screen sharing needs it, and calls in # Jitsi and Element work best with it check_sound() { local plugins=() is_installed pulseaudio || return 0 echo "This machine plays sound through PulseAudio. PipeWire replaces it: GNOME's" echo "screen sharing needs it, and calls in Jitsi and Element work best with it." if ! ask "Switch to PipeWire?" y n; then echo "Keeping PulseAudio." return 0 fi # Its modules (bluetooth, ...) need it, so they go first; PipeWire does # what they did mapfile -t plugins < <(pacman -Qq | grep '^pulseaudio-') if (( ${#plugins[@]} > 0 )); then sudo pacman -R --noconfirm "${plugins[@]}" || return 1 fi # --ask=4 answers yes to removing pulseaudio, which pipewire-pulse replaces sudo pacman -S --needed --noconfirm --ask=4 pipewire pipewire-pulse pipewire-alsa wireplumber || return 1 echo "Switched to PipeWire. It takes over when you log out and in again." } check_disk || exit 1 check_btrfs || exit 1 check_display_manager || exit 1 check_sound || exit 1 exit 0