2020-05-04 20:29:38 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-10-25 17:10:13 +00:00
|
|
|
# Description: Chatwoot installation script
|
|
|
|
# OS: Ubuntu 20.04 LTS / Ubuntu 20.10
|
2021-02-17 14:33:43 +00:00
|
|
|
# Script Version: 0.5
|
|
|
|
# Run this script as root
|
2020-05-04 20:29:38 +00:00
|
|
|
|
|
|
|
apt update && apt upgrade -y
|
|
|
|
apt install -y curl
|
|
|
|
curl -sL https://deb.nodesource.com/setup_12.x | bash -
|
|
|
|
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
|
|
|
|
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
|
|
|
|
apt update
|
|
|
|
|
|
|
|
apt install -y \
|
2020-10-25 17:10:13 +00:00
|
|
|
git software-properties-common imagemagick libpq-dev \
|
2020-05-04 20:29:38 +00:00
|
|
|
libxml2-dev libxslt1-dev file g++ gcc autoconf build-essential \
|
2020-10-25 17:10:13 +00:00
|
|
|
libssl-dev libyaml-dev libreadline-dev gnupg2 nginx redis-server \
|
2020-05-04 20:29:38 +00:00
|
|
|
redis-tools postgresql postgresql-contrib certbot \
|
2020-10-25 17:10:13 +00:00
|
|
|
python3-certbot-nginx nodejs yarn patch ruby-dev zlib1g-dev liblzma-dev \
|
2021-02-17 14:33:43 +00:00
|
|
|
libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev nginx-full
|
2020-05-04 20:29:38 +00:00
|
|
|
|
|
|
|
adduser --disabled-login --gecos "" chatwoot
|
|
|
|
|
2021-06-25 15:49:08 +00:00
|
|
|
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
|
|
|
gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
2020-05-04 20:29:38 +00:00
|
|
|
curl -sSL https://get.rvm.io | bash -s stable
|
2021-07-22 14:19:12 +00:00
|
|
|
adduser chatwoot rvm
|
2020-05-04 20:29:38 +00:00
|
|
|
|
|
|
|
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`
|
|
|
|
CREATE USER chatwoot CREATEDB;
|
|
|
|
ALTER USER chatwoot PASSWORD :'pass';
|
|
|
|
ALTER ROLE chatwoot SUPERUSER;
|
2021-02-17 14:33:43 +00:00
|
|
|
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
|
|
|
|
DROP DATABASE template1;
|
|
|
|
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
|
|
|
|
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
|
|
|
|
\c template1
|
|
|
|
VACUUM FREEZE;
|
2020-05-04 20:29:38 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
systemctl enable redis-server.service
|
|
|
|
systemctl enable postgresql
|
|
|
|
|
|
|
|
secret=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 63 ; echo '')
|
|
|
|
RAILS_ENV=production
|
|
|
|
|
|
|
|
sudo -i -u chatwoot << EOF
|
|
|
|
rvm --version
|
|
|
|
rvm autolibs disable
|
2021-06-29 13:48:10 +00:00
|
|
|
rvm install "ruby-2.7.3"
|
|
|
|
rvm use 2.7.3 --default
|
2020-05-04 20:29:38 +00:00
|
|
|
|
|
|
|
git clone https://github.com/chatwoot/chatwoot.git
|
|
|
|
cd chatwoot
|
2020-12-04 19:26:33 +00:00
|
|
|
if [[ -z "$1" ]]; then
|
2021-02-17 14:33:43 +00:00
|
|
|
git checkout master;
|
2020-11-27 08:07:57 +00:00
|
|
|
else
|
2021-02-17 14:33:43 +00:00
|
|
|
git checkout $1;
|
2020-11-27 08:07:57 +00:00
|
|
|
fi
|
2020-05-04 20:29:38 +00:00
|
|
|
bundle
|
|
|
|
yarn
|
|
|
|
|
|
|
|
cp .env.example .env
|
|
|
|
sed -i -e "/SECRET_KEY_BASE/ s/=.*/=$secret/" .env
|
|
|
|
sed -i -e '/REDIS_URL/ s/=.*/=redis:\/\/localhost:6379/' .env
|
|
|
|
sed -i -e '/POSTGRES_HOST/ s/=.*/=localhost/' .env
|
|
|
|
sed -i -e '/POSTGRES_USERNAME/ s/=.*/=chatwoot/' .env
|
|
|
|
sed -i -e "/POSTGRES_PASSWORD/ s/=.*/=$pg_pass/" .env
|
|
|
|
sed -i -e '/RAILS_ENV/ s/=.*/=$RAILS_ENV/' .env
|
|
|
|
|
|
|
|
RAILS_ENV=production bundle exec rake db:create
|
|
|
|
RAILS_ENV=production bundle exec rake db:reset
|
|
|
|
rake assets:precompile RAILS_ENV=production
|
|
|
|
EOF
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
systemctl enable chatwoot.target
|
|
|
|
systemctl start chatwoot.target
|
|
|
|
|
2021-02-17 14:33:43 +00:00
|
|
|
read -p 'Would you like to configure Webserver and SSL (yes or no): ' configure_webserver
|
|
|
|
|
|
|
|
if [ $configure_webserver != "yes" ]
|
|
|
|
then
|
2020-10-25 17:10:13 +00:00
|
|
|
echo "Woot! Woot!! Chatwoot server installation is complete"
|
|
|
|
echo "The server will be accessible at http://<server-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"
|
2021-02-17 14:33:43 +00:00
|
|
|
else
|
|
|
|
read -p 'What is your domain name server (chatwoot.domain.com for example) : ' domain_name
|
|
|
|
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
|
|
|
|
certbot certonly --nginx -d $domain_name
|
|
|
|
sed -i "s/chatwoot.domain.com/$domain_name/g" /etc/nginx/sites-available/nginx_chatwoot.conf
|
|
|
|
ln -s /etc/nginx/sites-available/nginx_chatwoot.conf /etc/nginx/sites-enabled/nginx_chatwoot.conf
|
|
|
|
systemctl restart nginx
|
|
|
|
sudo -i -u chatwoot << EOF
|
|
|
|
cd chatwoot
|
|
|
|
sed -i "s/http:\/\/0.0.0.0:3000/https:\/\/$domain_name/g" .env
|
|
|
|
EOF
|
|
|
|
systemctl restart chatwoot.target
|
|
|
|
echo "Woot! Woot!! Chatwoot server installation is complete"
|
|
|
|
echo "The server will be accessible at https://$domain_name"
|
|
|
|
fi
|