update.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. pip install pkce || { echo "Failed to install pkce module"; exit 1; }
  24. }
  25. update_db() { # Create the database. This also populates it with some goals and votes from the default rewards.py
  26. export FLASK_APP=ownchatbot
  27. if python -m flask update-db; then
  28. echo "Database updated successfully."
  29. else
  30. echo "Failed to update the database. Please check for errors."
  31. exit 1 # Exit the script with a non-zero status
  32. fi
  33. }
  34. update_config
  35. activate_venv
  36. update_db
  37. deactivate
  38. echo -e "***IMPORTANT***\n"
  39. echo -e "Look for new \"Access Token Name\" option in the Settings menu of your OwnchatBot managemment panel.\n"
  40. 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."