soapdish/scripts/system/system-config_use

47 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# SYSTEM: CONFIG Use
# If profiles exist
if (( ${#CONFIG_PROFILES_ARRAY[@]} ));
# Main Use Routine
then
# Read input
read -p "Profile to use?: " PROFILE_NAME_TO_USE
# Check if empty
if [[ -z $PROFILE_NAME_TO_USE ]]; then
error_message "[u] Config (use): No filename entered."
echo -e ""
# Validate: If input not alphanum/underscore
elif [[ "$PROFILE_NAME_TO_USE" =~ [^a-zA-Z0-9_-] ]]; then
error_message "[u] Config (use): Filename must be alphanum or underscored."
echo -e ""
# Check if in array
elif [[ "${CONFIG_PROFILES_ARRAY[*]}" =~ ${PROFILE_NAME_TO_USE} ]]; then
# Empty active config declaration file, and copy new name to it
sudo truncate -s 0 $CONFIG_FILE_IDENTIFIER_PATH
echo "$PROFILE_NAME_TO_USE" >> $CONFIG_FILE_IDENTIFIER_PATH
confirmation_message "[u] Config (use): Now using profile \"$PROFILE_NAME_TO_USE\"."
echo -e ""
else
error_message "[u] Config (use): No config named \"$PROFILE_NAME_TO_USE\" to use."
echo -e ""
fi
# No profiles exist
else
error_message "[u] Config (use): No config profiles to use. Create with \"new\"."
echo -e ""
fi