summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-08-16 20:10:22 -0300
committerSilvio Rhatto <rhatto@riseup.net>2014-08-16 20:10:22 -0300
commit20125ba1c35ee8bceb0e3ea1ab9c3b6017b11aa1 (patch)
tree374f6ea97622455560beed7cef59bf091f71e7c5
parentcb21ca66b5b3eface2e51914801a54cb1ccb8233 (diff)
downloadkeyringer-20125ba1c35ee8bceb0e3ea1ab9c3b6017b11aa1.tar.gz
keyringer-20125ba1c35ee8bceb0e3ea1ab9c3b6017b11aa1.tar.bz2
New action 'cp' (2)
-rwxr-xr-xlib/keyringer/actions/cp33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/keyringer/actions/cp b/lib/keyringer/actions/cp
new file mode 100755
index 0000000..0629b61
--- /dev/null
+++ b/lib/keyringer/actions/cp
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+# Copy secrets.
+#
+
+# Load functions
+LIB="`dirname $0`/../functions"
+source "$LIB" || exit 1
+
+# Aditional parameters
+CWD="`pwd`"
+
+# Avoid leading slash
+ORIG="$(keyringer_filename `echo "$2" | sed -e "s|^/*||"`)"
+DEST="`echo "$3" | sed -e "s|^/*||"`"
+
+# Set destination
+if [ ! -d "$KEYDIR/$RELATIVE_PATH/$DEST" ]; then
+ keyringer_get_new_file $DEST
+else
+ FILE="$DEST"
+fi
+
+# Check if secret exists
+if ! echo "$ORIG" | grep -q '*' && [ ! -e "$KEYDIR/$RELATIVE_PATH/$ORIG" ]; then
+ echo "Secret not found: $ORIG"
+ exit 1
+fi
+
+# Run move command
+cd "$KEYDIR" && cp -a "./$RELATIVE_PATH/$ORIG" "./$FILE"
+keyringer_exec git "$BASEDIR" add "keys/$FILE"
+cd "$CWD"