#!/bin/sh # local 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" suck_path="${XDG_SOURCES_HOME:-${HOME}/.local/src}/suckless" user_home=$(eval echo ~"$USER") # targets bash_path="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/ar/.config/bash" shell_path="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/ar/.config/shell" vim_path="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/ar/.config/vim" thesiah_path="${THESIAH_WWW:-${HOME}/Private/repos/THESIAH}/public" lf_path="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/ar/.config/lf" usage() { echo "Synchronize files and save them in backup path." echo "" echo "Usage: ${0##*/} [OPTIONS]" echo "" echo "Options:" echo " -h, --help Show this help message" echo " -r, --root Sync root files only" echo "" echo "Example:" echo " ${0##*/} # Sync all files to backup path" echo " ${0##*/} --root # Sync root files only" exit 0 } error() { printf "%s\n" "$1" >&2 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/