1
0

upgrade.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. set -e # Exit immediately if any command exits with a non-zero status
  3. activate_venv() {
  4. source env/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
  5. }
  6. update_modules() {
  7. pip install --upgrade pip || { echo "Failed to upgrade pip"; exit 1; } # Upgrade pip
  8. pip install -e . || { echo "Failed to install/upgrade module"; exit 1; } # Install/upgrade modules
  9. }
  10. update_config() {
  11. KOFI_TOKEN=$(grep "^KOFI_TOKEN" instance/config.py | cut -d'=' -f2 | cut -d'#' -f1 | tr -d '[:space:]') # Get the value of KOFI_TOKEN
  12. if [ "$KOFI_TOKEN" = "False" ]; then # So bash doesn't blank the variable in kofi.py if it's False
  13. KOFI_TOKEN="False"
  14. fi
  15. if [ "$KOFI_INTEGRATION" = "False" ]; then # Likewise
  16. KOFI_INTEGRATION="False"
  17. fi
  18. if [ -z "$KOFI_INTEGRATION" ]; then # Due to a bug I missed, the variable may be blank. If so, set to False
  19. KOFI_INTEGRATION="False"
  20. fi
  21. KOFI_INTEGRATION=$(grep "^KOFI_INTEGRATION" instance/config.py | cut -d'=' -f2 | cut -d'#' -f1 | tr -d '[:space:]') # Get the value of KOFI_INTEGRATION
  22. sed -i "s/}/, \'token\': ${KOFI_TOKEN}, \'integration\': ${KOFI_INTEGRATION}}/" instance/kofi.py # Append those values to kofi.py
  23. sed -i "/^KOFI_TOKEN/d" instance/config.py # Delete KOFI_TOKEN line from config.py
  24. sed -i "/^KOFI_INTEGRATION/d" instance/config.py # Delete KOFI_INTEGRATION line from config.py
  25. sed -i "s/}/,\"gb_name\": \"\"}/" instance/alerts.py # Append those values to kofi.py
  26. cp ownchatbot/defaults/givebutter.py instance/ # Copy the default givebutter config file into instance/
  27. }
  28. activate_venv
  29. update_modules
  30. deactivate
  31. update_config
  32. echo -e "\nYour OwnchatBot configuration has been upgraded. Look for GiveButter integration settings in the OCB Management Panel.\nHappy streaming!"