Skip to content

Commit 51e45f3

Browse files
committed
Initial commit
1 parent 3e8f98a commit 51e45f3

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

file.bash

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
print_usage() {
4+
echo "Usage: $PROGRAM file attach|retrieve pass-name [path]"
5+
echo " Attach or retrieve file to/from password store."
6+
exit 0
7+
}
8+
9+
cmd_attach() {
10+
local path="$1.b64"
11+
local file="$2"
12+
local passfile="$PREFIX/$path.gpg"
13+
14+
check_sneaky_paths "$1"
15+
set_git "$passfile"
16+
17+
if [[ -z $path || -z $file ]]; then
18+
print_usage
19+
elif [[ ! -f $file ]]; then
20+
die "Error: $file does not exist."
21+
fi
22+
23+
if [[ -f $passfile ]]; then
24+
read -r -p "A file with this name already exists in the store. Do you want to overwrite it? [y/N] " response
25+
if [[ $response != [yY] ]]; then
26+
exit 0;
27+
fi
28+
fi
29+
30+
mkdir -p "$(dirname "$passfile")"
31+
32+
set_gpg_recipients "$(dirname "$path")"
33+
34+
base64 $file | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}"
35+
36+
git_add_file $passfile "Attach given file for $path to store."
37+
}
38+
39+
cmd_retrieve() {
40+
local path="$1"
41+
local passfile="$PREFIX/$path.gpg"
42+
43+
if [[ -z $path ]]; then
44+
print_usage
45+
else
46+
check_sneaky_paths "$path"
47+
$GPG -d "${GPG_OPTS[@]}" "$passfile" | base64 -d || exit $?
48+
fi
49+
}
50+
51+
case $1 in
52+
attach|add)
53+
shift && cmd_attach "$@"
54+
;;
55+
retrieve|show|cat)
56+
shift && cmd_retrieve "$@"
57+
;;
58+
*)
59+
print_usage
60+
;;
61+
esac
62+

0 commit comments

Comments
 (0)