#!/bin/bash # SYSTEM: CONFIG Edit # Edit System Configuration (.json) file # If profiles exist if (( ${#CONFIG_PROFILES_ARRAY[@]} )); then # Read Input read -p "Profile Name to Edit?: " CONFIG_PROFILE_TO_EDIT # Input validate (check if empty) if [[ -z "$CONFIG_PROFILE_TO_EDIT" ]] then error_message "[e] Config (edit): Input blank. No file specified for editing." echo -e "" # Input validate (check for alphanum & "-_ "), convert spaces to underscores elif [[ "$CONFIG_PROFILE_TO_EDIT" =~ [^a-zA-Z0-9_-] ]] then error_message "[e] Config (edit): Files are alphanum characters only. No spaces." else # Precautionary Convert Spaces to Understores UNDERSCORED_PROFILE_NAME_INPUT=$(convert_spaces_to_underscores "$CONFIG_PROFILE_TO_EDIT") # Check if in array of available files. If so, process if [[ " ${CONFIG_PROFILES_ARRAY[*]} " =~ ${UNDERSCORED_PROFILE_NAME_INPUT} ]] then sudo nano "$CONFIG_DIRECTORY/config-$UNDERSCORED_PROFILE_NAME_INPUT.json" TIMESTAMP=$(date +%Y-%m-%d" ("%H"h "%M"m "%S"s)") sed -i "s/\/\/ Last modified.*/\/\/ Last modified: $TIMESTAMP/" "$CONFIG_DIRECTORY/config-$UNDERSCORED_PROFILE_NAME_INPUT.json" confirmation_message "[e] Config (edit): Editing of \"$CONFIG_PROFILE_TO_EDIT\" completed." echo -e "" else error_message "[e] Config (edit): No config \"$CONFIG_PROFILE_TO_EDIT\" to edit." echo -e "" fi fi # If no profiles exist else error_message "[e] Config (edit): No config profiles to edit. Create with \"new\"." echo -e "" fi