From ab7faba9fd5abb4fc26253c0a8846c0dcbb7e40d Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Sat, 4 Jul 2026 11:56:25 +0900 Subject: modified bin/rbackup --- ar/.local/bin/rbackup | 93 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 22 deletions(-) (limited to 'ar/.local/bin') diff --git a/ar/.local/bin/rbackup b/ar/.local/bin/rbackup index 8e3f75e..ed8fb82 100755 --- a/ar/.local/bin/rbackup +++ b/ar/.local/bin/rbackup @@ -1,7 +1,12 @@ #!/bin/sh # local backup -backup_path="/mnt/second/backup" +# Dotfiles are shared across machines, so no fixed device or path names: +# the target is whichever mounted /mnt/*/backup directory exists; failing +# that, a closed LUKS partition is opened and mounted under /mnt, named +# after its filesystem label (mount_luks sets $luks_mount accordingly). +luks_mount="" +backup_path="" dot_path="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}" git_path="$HOME/Private/repos" pass_path="${PASSWORD_STORE_DIR:-${XDG_DATA_HOME:-${HOME}/.local/share}/.password-store}/exported_keys" @@ -35,14 +40,42 @@ error() { exit 1 } +# First existing backup/ directory on a mounted drive under /mnt wins. +find_backup_path() { + for _dir in /mnt/*/backup; do + [ -d "$_dir" ] || continue + mountpoint -q "${_dir%/backup}" 2>/dev/null || continue + printf '%s' "$_dir" + return 0 + done + return 1 +} + +# Closed LUKS partition = crypto_LUKS fstype without an opened crypt child. +# Device names differ across machines and boots, so detect by type instead +# of hardcoding paths. Prints the largest candidate, if any. +find_closed_luks() { + lsblk -prbno PATH,FSTYPE,SIZE 2>/dev/null | + awk '$2 == "crypto_LUKS" { print $3, $1 }' | + sort -rn | + while read -r _size _dev; do + lsblk -rno TYPE "$_dev" 2>/dev/null | grep -qx "crypt" && continue + printf '%s\n' "$_dev" + break + done +} + +# Open the LUKS partition and mount it under /mnt. The mount point follows +# the inner filesystem's label (same convention as the other /mnt/