Files
Das-OS/srcpkgs/das-snapshots/files/das-snapper-setup
T
dasandClaude Opus 5.5 eba4516998 Stage 6: server image with a console installer (0.4.0)
- server/ profile and build-iso.sh [desktop|server]; make iso-server,
  make qemu-server, run-qemu.sh --serial; login on tty and ttyS0
- das-server: SSH, chrony, NetworkManager/dhcpcd, Docker with Compose,
  nftables (closed except SSH, own table), fail2ban reading socklog,
  sshd without root passwords, Docker log rotation, tools
- das-server-install: dialog installer in Ukrainian and English, or
  unattended with --config; GPT + Btrfs subvolumes, GRUB for UEFI and BIOS,
  serial console, SSH key with optional keys-only logins
- das-install-common: mount-source and postinstall shared with Calamares
- dsv: runit service manager (list, enable, disable, start, stop,
  restart, status, logs) with bash completion, also on the desktop
- das-update split into a subpackage without GTK; the window and tray
  icon move to /usr/libexec/das/das-update-gui
- das-snapper-setup enables dbus, which snapper needs
- TODO: ISO size review with measured numbers and options

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 21:28:26 +03:00

52 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# Set up snapper for a Das OS root file system on Btrfs.
#
# Expects the layout created by the installer: the root in subvolume @ and
# snapshots in subvolume @snapshots mounted at /.snapshots, which is what
# snapper-rollback needs. Safe to run again.
set -eu
msg() { echo "das-snapper-setup: $*"; }
if [ "$(id -u)" -ne 0 ]; then
msg "must be run as root" >&2
exit 1
fi
if [ "$(findmnt -no FSTYPE /)" != btrfs ]; then
msg "the root file system is not Btrfs, nothing to do"
exit 0
fi
if [ "$(findmnt -no FSTYPE /.snapshots 2>/dev/null)" != btrfs ]; then
msg "/.snapshots is not a mounted Btrfs subvolume" >&2
exit 1
fi
if [ ! -e /etc/snapper/configs/root ]; then
install -m 640 /usr/share/das/snapper/root /etc/snapper/configs/root
msg "created /etc/snapper/configs/root"
fi
if ! grep -q '^SNAPPER_CONFIGS=".*\broot\b' /etc/conf.d/snapper; then
sed -i 's/^SNAPPER_CONFIGS=.*/SNAPPER_CONFIGS="root"/' /etc/conf.d/snapper
fi
chmod 750 /.snapshots
chgrp wheel /.snapshots
# snapper-rollback mounts the top-level subvolume from this device.
dev=$(findmnt -no SOURCE / | sed 's/\[.*\]$//')
uuid=$(blkid -s UUID -o value "$dev")
sed -i "s|^#\?\s*dev = .*|dev = /dev/disk/by-uuid/$uuid|" /etc/snapper-rollback.conf
# Name the GRUB submenu that grub-btrfs adds
cfg=/etc/default/grub-btrfs/config
if [ -f "$cfg" ] && ! grep -q '^GRUB_BTRFS_SUBMENUNAME=' "$cfg"; then
echo 'GRUB_BTRFS_SUBMENUNAME="Das OS snapshots"' >>"$cfg"
fi
# Hourly snapshots come from cron, and grub-btrfs adds them to the boot menu.
# snapper talks to snapperd over the system bus (the server has no desktop
# that would enable dbus).
for sv in dbus cronie grub-btrfs; do
ln -sfn "/etc/sv/$sv" "/etc/runit/runsvdir/default/$sv"
done
msg "snapshots are enabled"