Skip to content

Commit 0f3d64b

Browse files
committed
ENH: Add subcommand 'pw', primitive wrapping password input
1 parent 5e7a37c commit 0f3d64b

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

README.full.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Subcommands:
157157
checkout PATH... Sparse-checkout and decrypt files into $WORK_TREE
158158
checkout COMMIT Switch files to a commit of plain or encrypted repo
159159
gc Garbage collect, remove synced encrypted packs
160+
pw Secure password input. Usage: PASSWORD="$(myba pw)"
160161
git CMD [OPTS] Inspect/execute raw git commands inside plain repo
161162
git_enc CMD [OPTS] Inspect/execute raw git commands inside encrypted repo
162163
@@ -198,15 +199,18 @@ export WORK_TREE="$HOME"
198199

199200
myba init
200201
myba add Documents Photos Etc .dotfile
201-
PASSWORD='secret' myba commit -m "my precious"
202+
PASSWORD="$(myba pw)" # Secure read from the controlling terminal
203+
export PASSWORD
204+
myba commit -m "my precious"
202205
myba remote add origin "/media/usb/backup/path"
203206
myba remote add github "git@github.com:user/my-backup.git"
204207
VERBOSE=1 myba push # Push to ALL configured remotes & free up disk space
205208

206-
# Somewhere else, much, much later, avoiding catastrophe ...
209+
# Somewhere else, post apocalypse, yet avoiding catastrophe ...
207210

208211
export WORK_TREE="$HOME"
209-
PASSWORD='secret' myba clone "..." # Clone one of the known remotes
212+
export PASSWORD=...
213+
myba clone ... # Clone one of the known remotes
210214
myba checkout ".dotfile" # Restore backed up files in a space-efficient manner
211215

212216
# When already cloned ...

myba.sh

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ usage () {
8080
echo " checkout PATH... Sparse-checkout and decrypt files into \$WORK_TREE"
8181
echo " checkout COMMIT Switch files to a commit of plain or encrypted repo"
8282
echo " gc Garbage collect, remove synced encrypted packs"
83+
echo " pw Secure password input. Usage: PASSWORD=\"$(myba pw)\""
8384
echo " git CMD [OPTS] Inspect/execute raw git commands inside plain repo"
8485
echo " git_enc CMD [OPTS] Inspect/execute raw git commands inside encrypted repo"
8586
echo
@@ -118,18 +119,23 @@ _read_vars () {
118119
read -r "$@" || [ "$(eval echo '$'"$1")" ];
119120
}
120121

122+
cmd_pw () {
123+
stty -echo
124+
{
125+
IFS= read -p "Enter encryption PASSWORD=: " -r PASSWORD
126+
echo
127+
(
128+
IFS= read -p "Repeat: " -r PASSWORD2
129+
[ "$PASSWORD" = "$PASSWORD2" ] || { warn 'ERROR: Password mismatch!'; exit 1; }
130+
)
131+
} < /dev/tty
132+
stty echo
133+
echo
134+
echo "$PASSWORD"
135+
}
121136
_ask_pw () {
122137
if [ -z "${PASSWORD+1}" ]; then
123-
stty -echo
124-
{
125-
IFS= read -p "Enter encryption PASSWORD=: " -r PASSWORD
126-
echo
127-
(
128-
IFS= read -p "Repeat: " -r PASSWORD2
129-
[ "$PASSWORD" = "$PASSWORD2" ] || { warn 'ERROR: Password mismatch!'; exit 1; }
130-
)
131-
} < /dev/tty
132-
stty echo
138+
cmd_pw > /dev/null
133139
fi
134140

135141
# Set up encryption via OpenSSL
@@ -831,6 +837,7 @@ case "$cmd" in
831837
largest) verbose cmd_largest "$@" ;;
832838
checkout) verbose cmd_checkout "$@" ;;
833839
gc) verbose cmd_gc "$@" ;;
840+
pw) verbose cmd_pw "$@" ;;
834841
git_enc) verbose git_enc "$@" ;;
835842
git)
836843
# Handle buggy ls-files in bare plain repo

0 commit comments

Comments
 (0)