aboutsummaryrefslogtreecommitdiffstats
path: root/ves-copy.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ves-copy.sh')
-rw-r--r--ves-copy.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/ves-copy.sh b/ves-copy.sh
new file mode 100644
index 0000000..11dde25
--- /dev/null
+++ b/ves-copy.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Copy and rename sh-ves environments. Environments are single files, so
+# both operations are simple file manipulations; only the name header
+# needs rewriting.
+#
+ves_copy() {
+ if [ "$#" -lt 2 ]; then
+ printf "ERROR: Insufficient arguments. usage: ves copy <src> <dst>\n" >&2
+ return 2
+ fi
+
+ src="$1"
+ dst="$2"
+
+ if ! _shves_check_env_name "$src" || ! _shves_check_env_name "$dst"; then
+ return 1
+ fi
+
+ if ! _shves_check_env_exists "$src"; then
+ return 1
+ fi
+
+ if _shves_check_env_exists "$dst" 1; then
+ printf "ERROR: Environment [%s] already exists.\n" "$dst" >&2
+ return 1
+ fi
+
+ printf "name: %s\n" "$dst" > "$SHVES_ENV_DIR/$dst"
+ grep "^export_var:" "$SHVES_ENV_DIR/$src" >> "$SHVES_ENV_DIR/$dst"
+
+ printf "Environment [%s] copied to [%s]\n" "$src" "$dst"
+
+ return 0
+}
+
+ves_rename() {
+ if [ "$#" -lt 2 ]; then
+ printf "ERROR: Insufficient arguments. usage: ves rename <old> <new>\n" >&2
+ return 2
+ fi
+
+ if [ "$1" = "$SHVES_ENV_NM" ]; then
+ printf "ERROR: Environment [%s] is currently active. Deactivate it first.\n" "$1" >&2
+ return 1
+ fi
+
+ if ! ves_copy "$1" "$2" > /dev/null; then
+ return 1
+ fi
+
+ rm -f "$SHVES_ENV_DIR/$1"
+ printf "Environment [%s] renamed to [%s]\n" "$1" "$2"
+
+ return 0
+}