#!/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 \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 \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 }