Compare commits

...

3 Commits

3 changed files with 71 additions and 26 deletions

View File

@ -87,13 +87,7 @@ fi
# }}} # }}}
# Node {{{ # Node {{{
# Move nvm folder away from home directory . /usr/share/nvm/init-nvm.sh
export NVM_DIR="${XDG_CONFIG_HOME}/nvm"
# Pretty much what is in `/usr/share/nvm/init-nvm.sh` but we add the `--no-use`
# flag to `nvm.sh` to make it lazy
. /usr/share/nvm/nvm.sh --no-use
. /usr/share/nvm/bash_completion
. /usr/share/nvm/install-nvm-exec
# }}} # }}}
# Go {{{ # Go {{{

View File

@ -2,24 +2,74 @@
# Save (encrypted) password database to cloud storage # Save (encrypted) password database to cloud storage
# #
# Can be run manually or daily by enabling the corresponding systemd user # Usage:
# service and timer, i.e. # save-passwddb - Save databases to cloud
# # save-passwddb init - Restore databases from cloud (with single backup archive)
# `systemctl --user enable save-passwddb.service`
# `systemctl --user enable save-passwddb.timer`
RCLONE_REMOTE="proton-drive" RCLONE_REMOTE="proton"
SOURCE_DIR="$HOME/doc"
TARGET_DIR="$RCLONE_REMOTE:doc"
BACKUP_DIR="$HOME/doc/bak"
# Reference: <https://unix.stackexchange.com/questions/100871/in-a-bash-if-condition-how-to-check-whether-any-files-matching-a-simple-wildcard> function save_databases() {
if [ 0 -lt "$(ls $HOME/doc/*.kdbx 2>/dev/null | wc -w)" ]; then if [ 0 -lt "$(ls $SOURCE_DIR/*.kdbx 2>/dev/null | wc -w)" ]; then
echo "Saving KeePassXC databases and database keys" echo "[save] Saving KeePassXC databases and database keys"
rclone copyto \ rclone copy "$SOURCE_DIR" "$TARGET_DIR" \
"$HOME/doc/" "$RCLONE_REMOTE:doc"/ \ --include "/*.{kdbx,kdbx.key}" \
--progress \ --progress
--include "/*.{kdbx,kdbx.key}" echo "[save] Done"
else else
echo "No password database found, use the following commands to restore" echo "[save] No password database found, restore with:"
echo "" echo ""
echo "rclone copy $RCLONE_REMOTE:doc \"$HOME/doc\" --include \"*.{kdbx,kdbx.key}\"" echo " $0 init"
exit 1 exit 1
fi fi
}
function backup_existing() {
mkdir -p "$BACKUP_DIR"
local timestamp=$(date +%Y%m%d-%H%M%S)
local backup_file="$BACKUP_DIR/passwddb_backup_${timestamp}.tar.gz"
echo "[backup] Creating backup archive: ${backup_file}"
tar -czf "$backup_file" -C "$SOURCE_DIR" $(find "$SOURCE_DIR" -maxdepth 1 -type f \( -name "*.kdbx" -o -name "*.kdbx.key" \) -printf "%f ")
echo "[backup] Backup complete"
}
function restore_databases() {
echo "[init] Checking for existing files..."
local existing_files=$(find "$SOURCE_DIR" -maxdepth 1 -type f \( -name "*.kdbx" -o -name "*.kdbx.key" \) -print)
if [ -n "$existing_files" ]; then
echo "[init] Found existing database files:"
echo "$existing_files" | while read -r file; do
echo " - $file"
done
read -p "[init] Create backup archive of existing files? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
backup_existing
fi
fi
echo "[init] Restoring KeePassXC databases and database keys"
mkdir -p "$SOURCE_DIR"
rclone copy "$TARGET_DIR" "$SOURCE_DIR" \
--include "*.{kdbx,kdbx.key}" \
--progress
echo "[init] Done"
}
case "$1" in
""|save)
save_databases
;;
init)
restore_databases
;;
*)
echo "Usage: $0 [init|save]"
exit 1
;;
esac

View File

@ -59,6 +59,7 @@ typescript-language-server
unzip unzip
vim-language-server vim-language-server
wget wget
xclip
yaml-language-server yaml-language-server
) )