update.sh 2.2 KB

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