From 7986d61b6fab5c6769b23776d4cbb0741cd602fc Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Tue, 14 Dec 2021 18:26:57 +0530 Subject: [PATCH] feat: allow users to select components to install when using linux script (#3528) Provide a choice to select the components to install. The script should be able to just install chatwoot alone. Postgres, redis, SSL certs via letsencrypt and nginx as a webserver should be installed after confirmation. Fixes: #3513 --- deployment/setup_20.04.sh | 61 ++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/deployment/setup_20.04.sh b/deployment/setup_20.04.sh index e9b055eb4..6f0e195da 100644 --- a/deployment/setup_20.04.sh +++ b/deployment/setup_20.04.sh @@ -2,7 +2,7 @@ # Description: Chatwoot installation script # OS: Ubuntu 20.04 LTS / Ubuntu 20.10 -# Script Version: 0.6 +# Script Version: 0.7 # Run this script as root read -p 'Would you like to configure a domain and SSL for Chatwoot?(yes or no): ' configure_webserver @@ -19,6 +19,13 @@ exit 1 fi fi +read -p 'Would you like to install postgres and redis?(Answer no if you plan to use external services): ' install_pg_redis + +if [ $install_pg_redis == "no" ] +then +echo "***** Skipping pg and redis installation. ****" +fi + apt update && apt upgrade -y apt install -y curl curl -sL https://deb.nodesource.com/setup_12.x | bash - @@ -27,12 +34,22 @@ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.lis apt update apt install -y \ - git software-properties-common imagemagick libpq-dev \ + git software-properties-common imagemagick libpq-dev \ libxml2-dev libxslt1-dev file g++ gcc autoconf build-essential \ - libssl-dev libyaml-dev libreadline-dev gnupg2 nginx redis-server \ - redis-tools postgresql postgresql-contrib certbot \ - python3-certbot-nginx nodejs yarn patch ruby-dev zlib1g-dev liblzma-dev \ - libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev nginx-full + libssl-dev libyaml-dev libreadline-dev gnupg2 \ + postgresql-client redis-tools \ + nodejs yarn patch ruby-dev zlib1g-dev liblzma-dev \ + libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev + +if [ $install_pg_redis != "no" ] +then +apt install -y postgresql postgresql-contrib redis-server +fi + +if [ $configure_webserver == "yes" ] +then +apt install -y nginx nginx-full certbot python3-certbot-nginx +fi adduser --disabled-login --gecos "" chatwoot @@ -41,6 +58,8 @@ gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A170311 curl -sSL https://get.rvm.io | bash -s stable adduser chatwoot rvm +if [ $install_pg_redis != "no" ] +then pg_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 15 ; echo '') sudo -i -u postgres psql << EOF \set pass `echo $pg_pass` @@ -57,6 +76,7 @@ EOF systemctl enable redis-server.service systemctl enable postgresql +fi secret=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 63 ; echo '') RAILS_ENV=production @@ -86,11 +106,18 @@ sed -i -e "/POSTGRES_PASSWORD/ s/=.*/=$pg_pass/" .env sed -i -e '/RAILS_ENV/ s/=.*/=$RAILS_ENV/' .env echo -en "\nINSTALLATION_ENV=linux_script" >> ".env" -RAILS_ENV=production bundle exec rake db:create -RAILS_ENV=production bundle exec rake db:reset rake assets:precompile RAILS_ENV=production EOF +if [ $install_pg_redis != "no" ] +then +sudo -i -u chatwoot << EOF +cd chatwoot +RAILS_ENV=production bundle exec rake db:create +RAILS_ENV=production bundle exec rake db:reset +EOF +fi + cp /home/chatwoot/chatwoot/deployment/chatwoot-web.1.service /etc/systemd/system/chatwoot-web.1.service cp /home/chatwoot/chatwoot/deployment/chatwoot-worker.1.service /etc/systemd/system/chatwoot-worker.1.service cp /home/chatwoot/chatwoot/deployment/chatwoot.target /etc/systemd/system/chatwoot.target @@ -98,13 +125,16 @@ cp /home/chatwoot/chatwoot/deployment/chatwoot.target /etc/systemd/system/chatwo systemctl enable chatwoot.target systemctl start chatwoot.target +public_ip=$(curl http://checkip.amazonaws.com -s) + if [ $configure_webserver != "yes" ] then +echo -en "\n\n***************************************************************************\n" echo "Woot! Woot!! Chatwoot server installation is complete" -echo "The server will be accessible at http://:3000" +echo "The server will be accessible at http://$public_ip:3000" echo "To configure a domain and SSL certificate, follow the guide at https://www.chatwoot.com/docs/deployment/deploy-chatwoot-in-linux-vm" +echo "***************************************************************************" else - curl https://ssl-config.mozilla.org/ffdhe4096.txt >> /etc/ssl/dhparam wget https://raw.githubusercontent.com/chatwoot/chatwoot/develop/deployment/nginx_chatwoot.conf cp nginx_chatwoot.conf /etc/nginx/sites-available/nginx_chatwoot.conf @@ -117,6 +147,17 @@ cd chatwoot sed -i "s/http:\/\/0.0.0.0:3000/https:\/\/$domain_name/g" .env EOF systemctl restart chatwoot.target +echo -en "\n\n***************************************************************************\n" echo "Woot! Woot!! Chatwoot server installation is complete" echo "The server will be accessible at https://$domain_name" +echo "***************************************************************************" +fi + + +if [ $install_pg_redis == "no" ] +then +echo -en "\n\n***************************************************************************\n" +echo "DB migrations are not run as pg and redis is not installed." +echo "After modifying .env with your external db creds, run db migrations !!!" +echo "***************************************************************************" fi