File discourse-update of Package discourse
#!/bin/sh
# if [ "x$(id -un)" != "xdiscourse" ] ; then
# echo "Please run this script as discourse user" 1>&2
# exit 1
# fi
set -e
export RAILS_ENV="${RAILS_ENV:=production}"
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"
echo "Hoping into the basedir within env $RAILS_ENV"
BUNDLER="BUNDLER_REPLACE"
cd /srv/www/vhosts/discourse/
if [ ! -e tmp/rebuild.txt ] ; then
echo "Nothing to do for discourse-update. Exiting"
exit 0
fi
echo "Cleaning up bootsnap-load-path-cache"
if [ -e tmp/cache/bootsnap-load-path-cache ] ; then
rm tmp/cache/bootsnap-load-path-cache
fi
echo "Cleaning up rendered assets to avoid problems while doing assets"
rm /srv/www/vhosts/discourse/public/assets/.sprockets-manifest-* ||:
rm -r /srv/www/vhosts/discourse/public/assets/* ||:
#export vendor_cache_dir=vendor/cache/yarn/
#yarn install --pure-lockfile --cache-folder "${vendor_cache_dir}"
# pushd app/assets/javascripts/
# for patch in patches/* ; do
# patch --forward -p1 < "${patch}" ||:
# done
# popd
# yarn install --offline --cache-folder vendor/cache/yarn/
echo "Running rake"
$BUNDLER exec /usr/bin/rake.@RUBY_SUFFIX@ db:migrate
$BUNDLER exec /usr/bin/rake.@RUBY_SUFFIX@ assets:clean
echo "Rendering new assets"
$BUNDLER exec /usr/bin/rake.@RUBY_SUFFIX@ --trace assets:precompile
if [ ! -e vendor/data/GeoLite2-City.mmdb ] ; then
$BUNDLER exec /usr/bin/rake.@RUBY_SUFFIX@ maxminddb:get
chown root:discourse vendor/data/*.mmdb
chmod u=rw,g=r,o= vendor/data/*.mmdb
fi
# this will be restored during puma start
rm public/fonts
echo "Fixing permissions"
chown -R discourse:discourse tmp/ app/assets/javascripts/plugins/ public/plugins/
chmod -R go+rX public/{assets,images,javascripts,plugins,uploads}
find public/backups -type d -print0 | xargs -r0 chmod u=rwx,go=x
echo "Trigger tmp/restart.txt"
touch tmp/restart.txt
echo "Finalize rebuild"
rm -f tmp/rebuild.txt