update.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. set -e # Exit immediately if any command exits with a non-zero status
  3. update_config() {
  4. CONFIG_FILE="instance/config.py"
  5. NEW_VARIABLES="\
  6. ACCESS_ID = '' # The name of your access token
  7. FOLLOW_POINTS = '50' # How many points to award viewers for following
  8. "
  9. TEMP_FILE=$(mktemp) # Create a temporary file
  10. if [[ ! -f "$CONFIG_FILE" ]]; then # Check if CONFIG_FILE exists
  11. echo "Error: Configuration file '$CONFIG_FILE' does not exist."
  12. exit 1
  13. fi
  14. while IFS= read -r line; do # Read through the original config file and output to the temp file
  15. echo "$line" >> "$TEMP_FILE" || { echo "Error writing to temp file"; exit 1; }
  16. done < "$CONFIG_FILE"
  17. echo "$NEW_VARIABLES" >> "$TEMP_FILE" || { echo "Error writing new variables to temp file"; exit 1; } # Append new variables to the temp file
  18. mv "$TEMP_FILE" "$CONFIG_FILE" || { echo "Error replacing the original config file"; exit 1; } # Move the temp file to the config file
  19. echo "Config file updated successfully."
  20. }
  21. activate_venv() {
  22. source env/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
  23. }
  24. update_db() { # Create the database. This also populates it with some goals and votes from the default rewards.py
  25. export FLASK_APP=ownchatbot
  26. if python -m flask update-db; then
  27. echo "Database updated successfully."
  28. else
  29. echo "Failed to update the database. Please check for errors."
  30. exit 1 # Exit the script with a non-zero status
  31. fi
  32. }
  33. update_config
  34. activate_venv
  35. update_db
  36. deactivate
  37. echo -e "***IMPORTANT***\n"
  38. echo -e "Look for new \"Access Token Name\" option in the Settings menu of your OwnchatBot managemment panel.\n"
  39. 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."