From 6fa02e042ac21f4c1125abeff82fd76dbdcb5a1e Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 3 Sep 2024 12:05:32 -0400 Subject: [PATCH] update --- mods/scripts/apps_defaults.sh | 55 ++++++++++++++++------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/mods/scripts/apps_defaults.sh b/mods/scripts/apps_defaults.sh index 97b5d90b0a..88a8fae011 100644 --- a/mods/scripts/apps_defaults.sh +++ b/mods/scripts/apps_defaults.sh @@ -2,49 +2,44 @@ parse_and_store_defaults() { local app_name="$1" local app_type="$2" # 'personal' for personal apps, 'official' for official apps - # Determine paths based on config type + # Determine paths based on app type if [[ "$app_type" == "personal" ]]; then - local app_file_path="/pg/p_apps/${app_name}.app" local config_path="/pg/personal_configs/${app_name}.cfg" + local app_path="/pg/p_apps/${app_name}.app" else - local app_file_path="/pg/apps/${app_name}.app" local config_path="/pg/config/${app_name}.cfg" + local app_path="/pg/apps/${app_name}.app" fi # Check if the config file exists, create it if not [[ ! -f "$config_path" ]] && touch "$config_path" # Check if the app file exists - if [[ ! -f "$app_file_path" ]]; then - echo "Error: App file $app_file_path does not exist." + if [[ ! -f "$app_path" ]]; then + echo "Error: App file $app_path does not exist." return 1 fi - # Read through the app file for lines starting with "##### " - while IFS= read -r line; do - if [[ "$line" =~ ^#####[[:space:]]+(.*?):[[:space:]]*(.*) ]]; then - local key="${BASH_REMATCH[1]}" - local value="${BASH_REMATCH[2]}" - - # Convert key to lowercase and replace spaces with underscores - key=$(echo "$key" | tr '[:upper:]' '[:lower:]' | tr ' ' '_') - - # Trim leading and trailing whitespace from value - value=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - - # If value is "null", set it to an empty string - if [[ "$value" == "null" ]]; then - value="" - fi - - # Check if the key already exists in the config file, update if it does, add if it doesn't - if grep -q "^$key=" "$config_path"; then - sed -i "s|^$key=.*|$key=$value|" "$config_path" - else - echo "$key=$value" >> "$config_path" + # Source the app's default_variables function + source "$app_path" + + # Call the default_variables function for the specific app + default_variables + + # Parse the default_variables function and write to config if not exist + declare -f default_variables | while read line; do + if [[ $line =~ ^[[:space:]]*([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$ ]]; then + var="${BASH_REMATCH[1]}" + value="${BASH_REMATCH[2]}" + + # Remove any existing quotes and semicolons from the value + value=$(echo "$value" | sed -e 's/^"//' -e 's/"$//' -e "s/^'//" -e "s/'$//" -e 's/;$//') + + # Check if the variable exists in the config file + if ! grep -q "^${var}=" "$config_path"; then + # Add quotes around the value (without semicolon) and write to config + echo "${var}=\"${value}\"" >> "$config_path" fi fi - done < "$app_file_path" - - echo "Configuration updated in $config_path" + done } \ No newline at end of file