update.sh 2.2 KB

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