update.sh 2.6 KB

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