#!/bin/bash # SYSTEM: CONFIG Copy # If profiles exist if (( ${#CONFIG_PROFILES_ARRAY[@]} )); then # Read input read -p "Profile to Copy?: " PROFILE_NAME_TO_COPY # Input validate (check if empty) if [[ -z "$PROFILE_NAME_TO_COPY" ]]; then error_message "[c] Config (copy): Input blank. No file identied for copying." echo -e "" # Input validate (check for alphanum & "-_") elif [[ "$PROFILE_NAME_TO_COPY" =~ [^a-zA-Z0-9_-] ]]; then # Validate response: Invalid characters error_message "[c] Config (copy): Filenames are alphanum only (no spaces). Try again." echo -e "" else # Check if in array of available files. If not, then create new. if [[ "${CONFIG_PROFILES_ARRAY[*]}" =~ ${PROFILE_NAME_TO_COPY} ]]; then # Read Input read -p "New name for Copy?: " PROFILE_COPY_NAME # Input validate (check if empty) if [[ -z "$PROFILE_COPY_NAME" ]]; then error_message "[c] Config (copy): No filename provide for new copy." echo -e "" # Input validate (check for alphanum & "-_") elif [[ "$PROFILE_COPY_NAME" =~ [^a-zA-Z0-9_-] ]]; then error_message "[c] Config (copy): New filenames are alphanum only (no spaces). Try again." echo -e "" else # Proceed with copy procedure sudo cp "$CONFIG_DIRECTORY/config-$PROFILE_NAME_TO_COPY.json" "$CONFIG_DIRECTORY/config-$PROFILE_COPY_NAME.json" confirmation_message "[c] Config (copy): Copy \"$PROFILE_COPY_NAME\" created from \"$PROFILE_NAME_TO_COPY\"." echo -e "" fi else error_message "[c] Config (copy): No file \"$PROFILE_NAME_TO_COPY\" exists to copy." echo -e "" fi fi # If no profiles exist else error_message "[c] Config (copy): No config profiles to Copy. Create with \"new\"." echo -e "" fi