install.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. #
  3. set -e # Exit immediately if any command exits with a non-zero status
  4. check_venv() { # Check if the venv module is available
  5. if python3 -c "import venv" &> /dev/null; then
  6. return 0
  7. else
  8. echo "The 'venv' module is not available. Please ensure you are using Python 3.3 or later."
  9. return 1
  10. fi
  11. }
  12. create_venv() {
  13. python3 -m venv env
  14. }
  15. activate_venv() {
  16. source env/bin/activate
  17. }
  18. install_dependencies() {
  19. pip install --upgrade pip || { echo "Failed to upgrade pip"; exit 1; }
  20. pip install gunicorn || { echo "Failed to install Gunicorn"; exit 1; }
  21. pip install -e . || { echo "Failed to install dependencies"; exit 1; }
  22. }
  23. initialize_db() { # Create the database. This also populates it with some goals and votes from the default rewards.py
  24. export FLASK_APP=ownchatbot
  25. if python -m flask init-db; then
  26. echo "Database initialized successfully."
  27. else
  28. echo "Failed to initialize the database. Please check for errors."
  29. exit 1 # Exit the script with a non-zero status
  30. fi
  31. }
  32. generate_key() {
  33. KEY=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c 32)
  34. echo "$KEY"
  35. }
  36. update_config() { # Generate key for SECRET_KEY
  37. local key_name="$1"
  38. local key_value="$2"
  39. local bak_file="instance/config.py.bak"
  40. echo "Go to Go to your Owncast Admin panel -> Integrations -> Access Tokens, and create an access token for OwnchatBot"
  41. # Update the config file
  42. if sed -i.bak "s|$key_name = ''|$key_name = '$key_value'|" "instance/config.py"; then
  43. echo "Set $key_name successfully."
  44. else
  45. echo "Failed to set $key_name."
  46. exit 1 # Exit the script with a non-zero status
  47. fi
  48. read -p "Enter the name of the access token: " ACCESS_ID
  49. if sed -i.bak "s|ACCESS_ID = ''|ACCESS_ID = '$ACCESS_ID'|" "instance/config.py"; then
  50. echo "Set ACCESS_ID successfully."
  51. else
  52. echo "Failed to set ACCESS_ID."
  53. exit 1 # Exit the script with a non-zero status
  54. fi
  55. read -p "Enter the access token: " ACCESS_TOKEN
  56. if sed -i.bak "s|ACCESS_TOKEN = ''|ACCESS_TOKEN = '$ACCESS_TOKEN'|" "instance/config.py"; then
  57. echo "Set ACCESS_TOKEN successfully."
  58. else
  59. echo "Failed to set ACCESS_TOKEN."
  60. exit 1 # Exit the script with a non-zero status
  61. fi
  62. read -p "Enter the external URL of your Owncast instance, with \"https://\": " OWNCAST_URL
  63. if sed -i.bak "s|OWNCAST_URL = ''|OWNCAST_URL = '$OWNCAST_URL'|" "instance/config.py"; then
  64. echo "Set OWNCAST_URL successfully."
  65. rm "$bak_file" # Remove the .bak file if the update was successful
  66. else
  67. echo "Failed to set ACCESS_ID."
  68. exit 1 # Exit the script with a non-zero status
  69. fi
  70. }
  71. read -p "This app includes an option to integrate Kofi donations and membership rewards into your stream. If you use this feature, you acknowledge that you alone are responsible for backing up and securing the OwnchatBot folder, so as not to lose any data related to rewards your viewiers earned by spending money on Kofi. The developer(s) of OwnchatBot assume no responsibility for any loss of such data. Do you agree to these terms? Type \"yes\" or \"no\": " agreement # Prompt the user to accept the agreement
  72. if [[ "$agreement" != "yes" ]]; then
  73. echo -e "\n\nAgreement declined by user. OwnchatBot not installed.\n\n"
  74. exit 0
  75. fi
  76. if check_venv; then
  77. create_venv
  78. else
  79. exit 1
  80. fi
  81. activate_venv
  82. install_dependencies
  83. initialize_db
  84. deactivate
  85. cp ownchatbot/defaults/*py instance/ # Copy the default config files into the instance folder
  86. mkdir instance/alerts # Create upload folder for alert images
  87. SECRET_KEY=$(generate_key)
  88. update_config "SECRET_KEY" "$SECRET_KEY"
  89. read -p "Please enter the port number you would like OwnchatBot to listen on: " OCB_PORT
  90. echo "
  91. You're ready to start OwnchatBot! Run:
  92. env/bin/python -m gunicorn --error-logfile ownchatbot.log -b 0.0.0.0:$OCB_PORT -w 1 'ownchatbot:create_app()'
  93. To configure your bot, go to:
  94. http://localhost:$OCB_PORT/mgmt
  95. Login to using your owncast admin name and password.
  96. "