postexec.sh 3.57 KB
Newer Older
HQ's avatar
HQ committed
1 2
#!/bin/bash

HQ's avatar
HQ committed
3 4 5
apt-add-repository -y ppa:brightbox/ruby-ng
apt-get update
apt-get -q -y --force-yes install ruby2.6 ruby2.6-dev
HQ's avatar
HQ committed
6 7 8 9 10 11 12 13 14 15 16

cp /var/discourse/config/discourse_defaults.conf /var/discourse/config/discourse.conf
perl -pi -e 's/db_host =.*/db_host = localhost/g' /var/discourse/config/discourse.conf
perl -pi -e 's/db_port =.*/db_port = 5432/g' /var/discourse/config/discourse.conf
perl -pi -e 's/db_password =.*/db_password = \"password\"/g' /var/discourse/config/discourse.conf
perl -pi -e 's/hostname =.*/hostname = discourse.stabile.io/g' /var/discourse/config/discourse.conf
perl -pi -e 's/smtp_address =.*/smtp_address = localhost/g' /var/discourse/config/discourse.conf
perl -pi -e 's/smtp_domain =.*/smtp_domain = stabile.io/g' /var/discourse/config/discourse.conf
perl -pi -e 's/smtp_authentication =.*/smtp_authentication = none/g' /var/discourse/config/discourse.conf
perl -pi -e 's/smtp_enable_start_tls =.*/smtp_enable_start_tls = false/g' /var/discourse/config/discourse.conf
perl -pi -e 's/APP_ROOT =.*/APP_ROOT = "\/var\/discourse\"/g' /var/discourse/config/puma.rb
HQ's avatar
HQ committed
17
perl -pi -e 's/bind .*/bind "tcp:\/\/0.0.0.0:9292"/g' /var/discourse/config/puma.rb
HQ's avatar
HQ committed
18 19 20
perl -pi -e 's/development test profile/development production test profile/g' /var/discourse/config/application.rb
perl -pi -e 's/(.*config.serve_static_files.+)/\#$1/g' /var/discourse/config/environments/production.rb

HQ's avatar
HQ committed
21
apt-get install -y npm
HQ's avatar
HQ committed
22
npm install -g svgo@0.7.2
HQ's avatar
HQ committed
23 24
#npm install pngquant
gem install image_optim
HQ's avatar
HQ committed
25
gem install image_optim_pack
HQ's avatar
HQ committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

perl -pi -e 's/inet_protocols =.*/inet_protocols = ipv4/;' /etc/postfix/main.cf

echo 'production:
  prepared_statements: false
  adapter: postgresql
  database: discourse
  min_messages: warning
  pool: 5
  timeout: 5000
  host_names: localhost' >> /var/discourse/config/database.yml

echo "---
:concurrency: 5
:pidfile: tmp/pids/sidekiq.pid
staging:
  :concurrency: 10
production:
  :concurrency: 20
  :queues:
    - [critical,4]
    - [default, 2]
    - [low]
development:
  :queues:
    - [critical,4]
    - [default, 2]
    - [low]" > /var/discourse/config/sidekiq.yml

HQ's avatar
HQ committed
55
cp
HQ's avatar
HQ committed
56 57 58
mkdir -p /var/discourse/tmp/sockets
mkdir -p /var/discourse/tmp/pids

HQ's avatar
HQ committed
59 60
cd /var/discourse
#gem install bundler
HQ's avatar
HQ committed
61
# https://bundler.io/blog/2019/05/14/solutions-for-cant-find-gem-bundler-with-executable-bundle.html
HQ's avatar
HQ committed
62
gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"
HQ's avatar
HQ committed
63
gem install uglifier
HQ's avatar
HQ committed
64
bundle install
HQ's avatar
HQ committed
65 66
echo "export RAILS_ENV=production" >> /etc/bash.bashrc

HQ's avatar
HQ committed
67 68 69 70
#lower password requirements
# https://github.com/discourse/discourse/commit/b2cfad5f47e6335ba514297517fa20e84dd004a8
wget https://github.com/mikefarah/yq/releases/download/v4.9.6/yq_linux_amd64
mv yq_linux_amd64 /usr/bin/yq
HQ's avatar
HQ committed
71
chmod 755 /usr/bin/yq
HQ's avatar
HQ committed
72 73 74 75 76
/usr/bin/yq e '.users.min_password_length.min = 6' -i /var/discourse/config/site_settings.yml
/usr/bin/yq e '.users.min_password_length.default = 6' -i /var/discourse/config/site_settings.yml
/usr/bin/yq e '.users.min_admin_password_length.min = 6' -i /var/discourse/config/site_settings.yml
/usr/bin/yq e '.users.min_admin_password_length.default = 6' -i /var/discourse/config/site_settings.yml

HQ's avatar
HQ committed
77 78 79 80 81 82 83
# Remove tabs from Webmin UI
rm -r /usr/share/webmin/stabile/tabs/commands
rm -r /usr/share/webmin/stabile/tabs/servers

cp -a /tmp/files/stabile/tabs/discourse /usr/share/webmin/stabile/tabs/
cp /tmp/files/stabile-discourse.pl /usr/local/bin/

HQ's avatar
HQ committed
84 85 86 87 88 89
echo "<Directory /var/discourse/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>" >> /etc/apache2/apache2.conf

HQ's avatar
HQ committed
90
# Change logo
HQ's avatar
HQ committed
91
perl -pi -e 's/images\/ubuntu-logo.png/tabs\/discourse\/discourse_icon.png/' /usr/share/webmin/stabile/index.cgi