瀏覽代碼

Added update_db function, and some error handling

deadtom 2 周之前
父節點
當前提交
bf3e1653ef
共有 1 個文件被更改,包括 39 次插入18 次删除
  1. 39 18
      update.sh

+ 39 - 18
update.sh

@@ -1,32 +1,53 @@
 #!/bin/bash
 
-CONFIG_FILE="instance/config.py"
+set -e  # Exit immediately if any command exits with a non-zero status
 
-NEW_VARIABLES="\
+update_config() {
+    CONFIG_FILE="instance/config.py"
+
+    NEW_VARIABLES="\
 INDIEAUTH_CLIENT_ID = ''  # Create a new access token at Owncast Admin panel -> Integrations -> Access Tokens, this variable is the name you associate with that token
 INDIEAUTH_CLIENT_SECRET = ''  # The access token you created for INDIEAUTH_CLIENT_ID
+FOLLOW_POINTS = '50'  # How many points to award viewers for following
 "
 
-# Create a temporary file
-TEMP_FILE=$(mktemp)
+    TEMP_FILE=$(mktemp)  # Create a temporary file
+
+    if [[ ! -f "$CONFIG_FILE" ]]; then  # Check if CONFIG_FILE exists
+        echo "Error: Configuration file '$CONFIG_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
+        echo "$line" >> "$TEMP_FILE" || { echo "Error writing to temp file"; exit 1; }
+    done < "$CONFIG_FILE"
 
-# Read through the original config file and output to the temp file
-while IFS= read -r line
-do
-    echo "$line" >> "$TEMP_FILE"
+    echo "$NEW_VARIABLES" >> "$TEMP_FILE" || { echo "Error writing new variables to temp file"; exit 1; }  # Append new variables to the temp file
 
-    # Check for the section marker and insert new lines after it
-    if [[ "$line" == "# Owncast stuff. Needed to interact with your Owncast instance" ]]; then
-        echo "$NEW_VARIABLES" >> "$TEMP_FILE"
+    mv "$TEMP_FILE" "$CONFIG_FILE" || { echo "Error replacing the original config file"; exit 1; }   # Move the temp file to the config file
+
+    echo "Config file updated successfully."
+}
+
+activate_venv() {
+    source env/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
+}
+
+update_db() {  # Create the database. This also populates it with some goals and votes from the default rewards.py
+    export FLASK_APP=ownchatbot
+    if python -m flask update-db; then
+        echo "Database updated successfully."
+    else
+        echo "Failed to update the database. Please check for errors."
+        exit 1  # Exit the script with a non-zero status
     fi
-done < "$CONFIG_FILE"
+}
 
-# Replace the original config file with the updated temp file
-mv "$TEMP_FILE" "$CONFIG_FILE"
+update_config
+activate_venv
+update_db
+deactivate
 
-echo -e "Config file updated.\n"
 echo -e "***IMPORTANT***\n"
-echo -e "Create a new access token in your Owncast Admin panel -> Integrations -> Access Tokens."
-echo -e "Enter the new name and token into the new variables in $CONFIG_FILE.\n"
+echo -e "Look for new \"Authentication\" and \"New Follower\" options in the Settings menu of your OwnchatBot managemment panel.\n"
 echo "The way you access your OwnchatBot management panel has changed. Authentication is now handled using your Owncast server as an IndieAuth server. You log in using the same credentials you use to log in to your Owncast Admin page."
-