mom, we have ansible at home

This commit is contained in:
2025-11-25 12:55:44 -05:00
parent a878cb2b25
commit ec08f870bb
5 changed files with 243 additions and 174 deletions

View File

@@ -1,116 +0,0 @@
7zip
amd-ucode
bambustudio-bin
base
base-devel
bat
bind
bluez
bluez-utils
bolt
brightnessctl
btop
cantarell-fonts
clang
cups
cups-pdf
direnv
discord
dunst
e2fsprogs
emacs-wayland
eza
fastfetch
fd
firefox
flatpak
foomatic-db
foomatic-db-engine
foomatic-db-nonfree-ppds
foomatic-db-ppds
freerdp
gdb
ghostty
gimp
git
go
gutenprint
imagemagick
inetutils
kanshi
keychain
lazygit
lib32-mesa
lib32-pipewire
lib32-vulkan-radeon
libreoffice-fresh
linux
linux-firmware
linux-lts
lldb
luarocks
man-db
man-pages
mosh
nano
networkmanager
nnn
noto-fonts
noto-fonts-cjk
noto-fonts-emoji
noto-fonts-extra
nss-mdns
omnissa-horizon-client
openssh
pacman-contrib
paru
paru-debug
pavucontrol
pcsc-tools
pipewire
pipewire-alsa
pipewire-jack
pipewire-pulse
ranger
reflector
ripgrep
rustup
sbcl
stow
sway
sway-contrib
swaybg
swayidle
swaylock
system-config-printer
texinfo
texlive-bibtexextra
texlive-fontsrecommended
texlive-latex
texlive-latexextra
texlive-plaingeneric
texlive-xetex
the_silver_searcher
tlp
tmux
ttf-dejavu
ttf-fira-code
ttf-hack-nerd
ttf-liberation
unzip
vlc
vlc-plugin-ffmpeg
vulkan-radeon
waybar
weechat
wget
wimlib
wireplumber
woff2-font-awesome
wofi
xdg-desktop-portal-wlr
xdg-user-dirs
xorg-xwayland
yubico-authenticator-bin
zoom
zsh

View File

@@ -0,0 +1,153 @@
{
"timestamp": "20251125-125519",
"packages": {
"pacman": [
"7zip",
"amd-ucode",
"base",
"base-devel",
"bat",
"bind",
"bluez",
"bluez-utils",
"bolt",
"brightnessctl",
"btop",
"cantarell-fonts",
"clang",
"cups",
"cups-pdf",
"direnv",
"discord",
"dunst",
"e2fsprogs",
"emacs-wayland",
"eza",
"fastfetch",
"fd",
"firefox",
"flatpak",
"foomatic-db",
"foomatic-db-engine",
"foomatic-db-nonfree-ppds",
"foomatic-db-ppds",
"freerdp",
"gdb",
"ghostty",
"gimp",
"git",
"go",
"gutenprint",
"imagemagick",
"inetutils",
"kanshi",
"keychain",
"lazygit",
"lib32-mesa",
"lib32-pipewire",
"lib32-vulkan-radeon",
"libreoffice-fresh",
"linux",
"linux-firmware",
"linux-lts",
"lldb",
"luarocks",
"man-db",
"man-pages",
"mosh",
"nano",
"networkmanager",
"nnn",
"noto-fonts",
"noto-fonts-cjk",
"noto-fonts-emoji",
"noto-fonts-extra",
"nss-mdns",
"openssh",
"pacman-contrib",
"pavucontrol",
"pcsc-tools",
"pipewire",
"pipewire-alsa",
"pipewire-jack",
"pipewire-pulse",
"ranger",
"reflector",
"ripgrep",
"rustup",
"sbcl",
"stow",
"sway",
"sway-contrib",
"swaybg",
"swayidle",
"swaylock",
"system-config-printer",
"texinfo",
"texlive-bibtexextra",
"texlive-fontsrecommended",
"texlive-latex",
"texlive-latexextra",
"texlive-plaingeneric",
"texlive-xetex",
"the_silver_searcher",
"tlp",
"tmux",
"ttf-dejavu",
"ttf-fira-code",
"ttf-hack-nerd",
"ttf-liberation",
"unzip",
"vlc",
"vlc-plugin-ffmpeg",
"vulkan-radeon",
"waybar",
"weechat",
"wget",
"wimlib",
"wireplumber",
"woff2-font-awesome",
"wofi",
"xdg-desktop-portal-wlr",
"xdg-user-dirs",
"xorg-xwayland",
"zsh"
],
"aur": [
"bambustudio-bin",
"omnissa-horizon-client",
"paru",
"paru-debug",
"yubico-authenticator-bin",
"zoom"
]
},
"systemd": {
"system": [
"bluetooth.service",
"getty@.service",
"NetworkManager-dispatcher.service",
"NetworkManager-wait-online.service",
"NetworkManager.service",
"reflector.service",
"systemd-boot-update.service",
"tlp.service",
"avahi-daemon.socket",
"cups.socket",
"pcscd.socket",
"systemd-userdbd.socket",
"remote-fs.target"
],
"user": [
"kanshi.service",
"wireplumber.service",
"xdg-user-dirs.service",
"p11-kit-server.socket",
"pipewire-pulse.socket",
"pipewire.socket"
]
},
"flatpak": [
"com.adamcake.Bolt"
]
}

View File

@@ -2,56 +2,113 @@
set -e
PKGLIST="pkglist.txt"
SYSTEMD_SYSTEM="systemd_enabled.txt"
SYSTEMD_USER="systemd_user_enabled.txt"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BACKUP_FILE="system-backup-${TIMESTAMP}.json"
show_help() {
echo "Usage: $0 [OPTION]"
echo ""
echo "Options:"
echo " -b, --backup Create backup files of packages and systemd units"
echo " -r, --restore Restore packages and systemd units from backup files"
echo " -b, --backup [filename] Create backup (default: system-backup-TIMESTAMP.json)"
echo " -r, --restore <filename> Restore from backup file"
echo " -h, --help Show this help message"
}
backup() {
echo "Creating package list..."
paru -Qqe > "$PKGLIST"
echo "Created $PKGLIST"
local filename="${1:-$BACKUP_FILE}"
echo "Creating system unit list..."
systemctl list-unit-files --state=enabled --no-pager | awk '{print $1}' > "$SYSTEMD_SYSTEM"
echo "Created $SYSTEMD_SYSTEM"
echo "Creating backup..."
echo "Creating user unit list..."
systemctl --user list-unit-files --state=enabled --no-pager | awk '{print $1}' > "$SYSTEMD_USER"
echo "Created $SYSTEMD_USER"
# Get package lists (filtering out any integers/counts)
local pacman_pkgs=$(paru -Qqen | grep -v '^[0-9]*$')
local aur_pkgs=$(paru -Qqem | grep -v '^[0-9]*$')
echo "Backup complete."
# Get systemd units (filter headers, footers, and integers)
local system_units=$(systemctl list-unit-files --state=enabled --no-pager --no-legend | \
awk '{print $1}' | grep -E '\.(service|timer|socket|target|path|mount)$')
local user_units=$(systemctl --user list-unit-files --state=enabled --no-pager --no-legend | \
awk '{print $1}' | grep -E '\.(service|timer|socket|target|path|mount)$')
# Get flatpak list
local flatpak_pkgs=""
if command -v flatpak &> /dev/null; then
flatpak_pkgs=$(flatpak list --app --columns=application | tail -n +1 | grep -v '^[0-9]*$')
fi
# Build JSON
jq -n \
--arg timestamp "$TIMESTAMP" \
--arg pacman "$pacman_pkgs" \
--arg aur "$aur_pkgs" \
--arg system "$system_units" \
--arg user "$user_units" \
--arg flatpak "$flatpak_pkgs" \
'{
timestamp: $timestamp,
packages: {
pacman: ($pacman | split("\n") | map(select(length > 0))),
aur: ($aur | split("\n") | map(select(length > 0)))
},
systemd: {
system: ($system | split("\n") | map(select(length > 0))),
user: ($user | split("\n") | map(select(length > 0)))
},
flatpak: ($flatpak | split("\n") | map(select(length > 0)))
}' > "$filename"
echo "Backup created: $filename"
}
restore() {
if [[ ! -f "$PKGLIST" ]]; then
echo "Error: $PKGLIST not found"
local filename="$1"
if [[ -z "$filename" ]]; then
echo "Error: No backup file specified"
show_help
exit 1
fi
echo "Installing packages..."
paru -S --needed - < "$PKGLIST"
if [[ -f "$SYSTEMD_SYSTEM" ]]; then
echo "Enabling system units..."
while read unit; do
sudo systemctl enable "$unit" 2>/dev/null || echo "Skipping $unit"
done < "$SYSTEMD_SYSTEM"
if [[ ! -f "$filename" ]]; then
echo "Error: Backup file $filename not found"
exit 1
fi
if [[ -f "$SYSTEMD_USER" ]]; then
# Ensure jq is installed
if ! command -v jq &> /dev/null; then
echo "Installing jq..."
sudo pacman -S --noconfirm jq
fi
echo "Restoring from $filename..."
# Install pacman packages
echo "Installing official repository packages..."
jq -r '.packages.pacman[]' "$filename" | paru -S --needed --noconfirm -
# Install AUR packages
echo "Installing AUR packages..."
jq -r '.packages.aur[]' "$filename" | paru -S --needed --noconfirm -
# Enable system units
echo "Enabling system units..."
jq -r '.systemd.system[]' "$filename" | while read -r unit; do
[[ -n "$unit" ]] && sudo systemctl enable "$unit" 2>/dev/null || echo "Skipping $unit"
done
# Enable user units
echo "Enabling user units..."
while read unit; do
systemctl --user enable "$unit" 2>/dev/null || echo "Skipping $unit"
done < "$SYSTEMD_USER"
jq -r '.systemd.user[]' "$filename" | while read -r unit; do
[[ -n "$unit" ]] && systemctl --user enable "$unit" 2>/dev/null || echo "Skipping $unit"
done
# Install flatpak packages
if command -v flatpak &> /dev/null; then
echo "Installing flatpak packages..."
jq -r '.flatpak[]' "$filename" | while read -r pkg; do
[[ -n "$pkg" ]] && flatpak install -y "$pkg" 2>/dev/null || echo "Skipping $pkg"
done
else
echo "Flatpak not installed, skipping flatpak packages"
fi
echo "Restore complete."
@@ -59,10 +116,10 @@ restore() {
case "$1" in
-b|--backup)
backup
backup "$2"
;;
-r|--restore)
restore
restore "$2"
;;
-h|--help)
show_help

View File

@@ -1,16 +0,0 @@
UNIT
bluetooth.service
getty@.service
NetworkManager-dispatcher.service
NetworkManager-wait-online.service
NetworkManager.service
reflector.service
systemd-boot-update.service
tlp.service
avahi-daemon.socket
cups.socket
pcscd.socket
systemd-userdbd.socket
remote-fs.target
13

View File

@@ -1,9 +0,0 @@
UNIT
kanshi.service
wireplumber.service
xdg-user-dirs.service
p11-kit-server.socket
pipewire-pulse.socket
pipewire.socket
6