Compare commits

..

No commits in common. "b5b48016ef9ceb2f0d1591ee0fbe987523741df4" and "09288ce752afccfec4289038d2c8ad057985f207" have entirely different histories.

3 changed files with 26 additions and 71 deletions

View File

@ -87,7 +87,13 @@ fi
# }}} # }}}
# Node {{{ # Node {{{
. /usr/share/nvm/init-nvm.sh # Move nvm folder away from home directory
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,74 +2,24 @@
# Save (encrypted) password database to cloud storage # Save (encrypted) password database to cloud storage
# #
# Usage: # Can be run manually or daily by enabling the corresponding systemd user
# save-passwddb - Save databases to cloud # service and timer, i.e.
# 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" RCLONE_REMOTE="proton-drive"
SOURCE_DIR="$HOME/doc"
TARGET_DIR="$RCLONE_REMOTE:doc"
BACKUP_DIR="$HOME/doc/bak"
function save_databases() { # Reference: <https://unix.stackexchange.com/questions/100871/in-a-bash-if-condition-how-to-check-whether-any-files-matching-a-simple-wildcard>
if [ 0 -lt "$(ls $SOURCE_DIR/*.kdbx 2>/dev/null | wc -w)" ]; then if [ 0 -lt "$(ls $HOME/doc/*.kdbx 2>/dev/null | wc -w)" ]; then
echo "[save] Saving KeePassXC databases and database keys" echo "Saving KeePassXC databases and database keys"
rclone copy "$SOURCE_DIR" "$TARGET_DIR" \ rclone copyto \
--include "/*.{kdbx,kdbx.key}" \ "$HOME/doc/" "$RCLONE_REMOTE:doc"/ \
--progress --progress \
echo "[save] Done" --include "/*.{kdbx,kdbx.key}"
else else
echo "[save] No password database found, restore with:" echo "No password database found, use the following commands to restore"
echo "" echo ""
echo " $0 init" echo "rclone copy $RCLONE_REMOTE:doc \"$HOME/doc\" --include \"*.{kdbx,kdbx.key}\""
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,7 +59,6 @@ typescript-language-server
unzip unzip
vim-language-server vim-language-server
wget wget
xclip
yaml-language-server yaml-language-server
) )