summaryrefslogtreecommitdiff
path: root/src/password-store.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsrc/password-store.sh46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/password-store.sh b/src/password-store.sh
index 411f467..1960636 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -48,10 +48,6 @@ Usage:
Optionally put it on the clipboard and clear board after 45 seconds.
$program rm [--recursive,-r] [--force,-f] pass-name
Remove existing password or directory, optionally forcefully.
- $program push
- If the password store is a git repository, push the latest changes.
- $program pull
- If the password store is a git repository, pull the latest changes.
$program git git-command-args...
If the password store is a git repository, execute a git command
specified by git-command-args.
@@ -61,9 +57,9 @@ Usage:
Show version information.
_EOF
}
-isCommand() {
+is_command() {
case "$1" in
- init|ls|list|show|insert|edit|generate|remove|rm|delete|push|pull|git|help|--help|version|--version) return 0 ;;
+ init|ls|list|show|insert|edit|generate|remove|rm|delete|git|help|--help|version|--version) return 0 ;;
*) return 1 ;;
esac
}
@@ -115,10 +111,16 @@ GETOPT="getopt"
# END Platform definable
#
+function git_add_file() {
+ [[ -d $GIT_DIR ]] || return
+ git add "$1" || return
+ [[ -n $(git status --porcelain "$1") ]] || return
+ git commit -m "$2"
+}
program="$(basename "$0")"
command="$1"
-if isCommand "$command"; then
+if is_command "$command"; then
shift
else
command="show"
@@ -134,6 +136,7 @@ case "$command" in
mkdir -v -p "$PREFIX"
echo "$gpg_id" > "$ID"
echo "Password store initialized for $gpg_id."
+ git_add_file "$ID" "Set GPG id to $gpg_id."
exit 0
;;
help|--help)
@@ -246,10 +249,7 @@ case "$command" in
read -p "Enter password for $path: " -e password
$GPG -e -r "$ID" -o "$passfile" $GPG_OPTS <<<"$password"
fi
- if [[ -d $GIT_DIR ]]; then
- git add "$passfile"
- git commit -m "Added given password for $path to store."
- fi
+ git_add_file "$passfile" "Added given password for $path to store."
;;
edit)
if [[ $# -ne 1 ]]; then
@@ -277,11 +277,7 @@ case "$command" in
echo "GPG encryption failed. Retrying."
sleep 1
done
-
- if [[ -d $GIT_DIR ]]; then
- git add "$passfile"
- git commit -m "$action password for $path using ${EDITOR:-vi}."
- fi
+ git_add_file "$passfile" "$action password for $path using ${EDITOR:-vi}."
;;
generate)
clip=0
@@ -310,10 +306,7 @@ case "$command" in
pass="$(pwgen -s $symbols $length 1)"
passfile="$PREFIX/$path.gpg"
$GPG -e -r "$ID" -o "$passfile" $GPG_OPTS <<<"$pass"
- if [[ -d $GIT_DIR ]]; then
- git add "$passfile"
- git commit -m "Added generated password for $path to store."
- fi
+ git_add_file "$passfile" "Added generated password for $path to store."
if [ $clip -eq 0 ]; then
echo "The generated password to $path is:"
@@ -353,16 +346,11 @@ case "$command" in
git commit -m "Removed $path from store."
fi
;;
- push|pull)
- if [[ -d $GIT_DIR ]]; then
- exec git $command "$@"
- else
- echo "Error: the password store is not a git repository."
- exit 1
- fi
- ;;
git)
- if [[ $1 == "init" || -d $GIT_DIR ]]; then
+ if [[ $1 == "init" ]]; then
+ git "$@" || exit 1
+ git_add_file "$PREFIX" "Added current contents of password store."
+ elif [[ -d $GIT_DIR ]]; then
exec git "$@"
else
echo "Error: the password store is not a git repository."
o.be> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-06-11use cgit_httpscheme() for atom feedDiego Ongaro2-3/+6 2009-06-11add cgit_httpscheme() -> http:// or https://Diego Ongaro2-0/+12 2009-06-07Return http statuscode 404 on unknown branchLars Hjemli3-0/+6 Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-06-07Add head-include configuration option.Mark Lodato3-1/+6 This patch adds an option to the configuration file, "head-include", which works just like "header" or "footer", except the content is put into the HTML's <head> tag. 2009-03-15CGIT 0.8.2.1v0.8.2.1Lars Hjemli1-1/+1 Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli2-1/+6 Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli1-6/+17 Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15fix segfault when displaying empty blobsEric Wong1-5/+8 When size is zero, subtracting one from it turns it into ULONG_MAX which causes an out-of-bounds access on buf. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-19Add support for HEAD requestsLars Hjemli2-0/+7 This is a quick 'n dirty hack which makes cgit honor HEAD requests. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-19Add support for ETag in 'plain' viewLars Hjemli4-0/+5 When downloading a blob identified by its path, the client might want to know if the blob has been modified since a previous download of the same path. To this end, an ETag containing the blob SHA1 seems to be ideal. Todo: add support for HEAD requests... Suggested-by: Owen Taylor <otaylor@redhat.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli1-4/+9 Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-12Makefile: add doc-related targetsLars Hjemli1-2/+17 Signed-off-by: Lars Hjemli <hjemli@gmail.com>