ソースを参照

Added copy todo.py to instance folder

deadtom 1 週間 前
コミット
813f8080c4
1 ファイル変更16 行追加11 行削除
  1. 16 11
      update.sh

+ 16 - 11
update.sh

@@ -4,26 +4,31 @@ set -e  # Exit immediately if any command exits with a non-zero status
 
 update_config() {
     CONFIG_FILE="instance/config.py"
+    TODO_FILE="ownchatbot/defaults/todo.py"
+    TEMP_FILE=$(mktemp)  # Create a temporary file
 
-    # Prompt the user for the Owncast instance URL
-    read -p "Enter the name of the existing Owncast access token used by OwnchatBot: " TOKEN_NAME
-
-    NEW_VARIABLES="\
-ACCESS_ID = '$TOKEN_NAME'  # The name of your access token
-"
+        read -p "Enter the name of the existing Owncast access token used by OwnchatBot: " TOKEN_NAME
 
-    TEMP_FILE=$(mktemp)  # Create a temporary file
+    if grep -q "ACCESS_ID =" "$CONFIG_FILE"; then  # Check if the variable already exists in CONFIG_FILE
+        echo "ACCESS_ID variable already exists in '$CONFIG_FILE'."
+    else
+        NEW_VARIABLES="ACCESS_ID = '$TOKEN_NAME'  # The name of your access token"
+    fi
 
-    if [[ ! -f "$CONFIG_FILE" ]]; then  # Check if CONFIG_FILE exists
-        echo "Error: Configuration file '$CONFIG_FILE' does not exist."
+    if [[ -f "$TODO_FILE" ]]; then  # Copy todo.py to the instance directory
+        cp "$TODO_FILE" "instance/" || { echo "Error copying $TODO_FILE to instance/"; exit 1; }
+    else
+        echo "Error: '$TODO_FILE' does not exist."
         exit 1
     fi
 
-    while IFS= read -r line; do  # Read through the original config file and output to the temp file
+    while IFS= read -r line; do  # Read the original config file and output to the temp file
         echo "$line" >> "$TEMP_FILE" || { echo "Error writing to temp file"; exit 1; }
     done < "$CONFIG_FILE"
 
-    echo "$NEW_VARIABLES" >> "$TEMP_FILE" || { echo "Error writing new variables to temp file"; exit 1; }  # Append new variables to the temp file
+    if [[ -n "$NEW_VARIABLES" ]]; then  # Append new variables if they are not already present
+        echo "$NEW_VARIABLES" >> "$TEMP_FILE" || { echo "Error writing new variables to temp file"; exit 1; }
+    fi
 
     mv "$TEMP_FILE" "$CONFIG_FILE" || { echo "Error replacing the original config file"; exit 1; }  # Move the temp file to the config file