Add gd* utils
This commit is contained in:
@@ -24,3 +24,39 @@ _take() {
|
|||||||
cd $1
|
cd $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# gd: Check dependencies and auth
|
||||||
|
_gdcheck() {
|
||||||
|
# deps
|
||||||
|
local missing=()
|
||||||
|
for cmd in rclone zstd gpg; do
|
||||||
|
command -v "$cmd" >/dev/null 2>&1 || missing+=("$cmd")
|
||||||
|
done
|
||||||
|
(( ${#missing[@]} == 0 )) || {
|
||||||
|
print -u2 "Missing dependencies: ${missing[*]}"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# auth
|
||||||
|
rclone lsd gdrive: >/dev/null 2>&1 || {
|
||||||
|
print -u2 "Google Drive auth failed; try: rclone config reconnect gdrive:"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# gdpush pushes a file to Google Drive
|
||||||
|
gdpush() {
|
||||||
|
_gdcheck || return
|
||||||
|
zstd -6 -T0 -c -- "$1" | gpg -c -z 0 -o - | rclone rcat "gdrive:backups/${1:t}.zst.gpg"
|
||||||
|
}
|
||||||
|
|
||||||
|
# gdls lists files in Google Drive
|
||||||
|
gdls() {
|
||||||
|
_gdcheck || return
|
||||||
|
rclone lsf --files-only gdrive:backups/ | sed 's/\.zst\.gpg$//'
|
||||||
|
}
|
||||||
|
|
||||||
|
# gdpull pulls a file from Google Drive
|
||||||
|
gdpull() {
|
||||||
|
_gdcheck || return
|
||||||
|
rclone cat "gdrive:backups/${1:t}.zst.gpg" | gpg -d | zstd -d -c
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user