66 lines
2.0 KiB
Bash
66 lines
2.0 KiB
Bash
|
#!/bin/bash
|
|||
|
set -e
|
|||
|
|
|||
|
release=$(curl -L https://api.github.com/repos/discourse/discourse/tags -s | jq -r '.[0].name')
|
|||
|
|
|||
|
echo "Warning, this scipt is not fully tested yet! Proceed with caution!"
|
|||
|
echo
|
|||
|
read -p "Trying to update to Discourse ${release} – proceed?" -n 1 -r
|
|||
|
echo
|
|||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]
|
|||
|
then
|
|||
|
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script
|
|||
|
fi
|
|||
|
echo
|
|||
|
|
|||
|
basedir=$HOME/discourse
|
|||
|
patch=$HOME/latest.patch
|
|||
|
# not clear why this is a samplefile
|
|||
|
# they seem to do this by hand on the docker repo
|
|||
|
#rubyver=$(< $basedir/.ruby-version.sample)
|
|||
|
rubyver=$(curl -s https://raw.githubusercontent.com/discourse/discourse_docker/main/image/base/slim.Dockerfile | grep -oP '(?<=RUBY_VERSION=)[0-9]+\.[0-9]+\.[0-9]+')
|
|||
|
nodever=$(curl -s https://raw.githubusercontent.com/discourse/discourse_docker/main/image/base/slim.Dockerfile | grep -oP '(?<=nodesource.com/setup_)[0-9]+[0-9]')
|
|||
|
|
|||
|
cd $basedir
|
|||
|
|
|||
|
git fetch -q
|
|||
|
|
|||
|
# attempting not having to use a patchfile
|
|||
|
git stash
|
|||
|
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
|
|||
|
git stash apply
|
|||
|
|
|||
|
# failsafe if stash apply causes too much trouble
|
|||
|
#echo "looking for patchfile at [ $patch ], executing if found..."
|
|||
|
#[ -e $patch ] && . $patch
|
|||
|
#echo "command ended with status $?"
|
|||
|
|
|||
|
#echo ~/.rbenv/versions/$rubyver
|
|||
|
|
|||
|
if [[ ! -e ~/.rbenv/versions/$rubyver ]]
|
|||
|
then
|
|||
|
git -C $HOME/.rbenv/plugins/ruby-build pull
|
|||
|
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install
|
|||
|
fi
|
|||
|
|
|||
|
echo "proceeding with bundle and yarn"
|
|||
|
# upstream does a gem update --system
|
|||
|
# we assume their Gemfile.lock is on track tho
|
|||
|
# and try to avoid problems due to too new gems
|
|||
|
bundle install
|
|||
|
yarn install --frozen-lockfile
|
|||
|
|
|||
|
RAILS_ENV=production bundle exec rails assets:precompile
|
|||
|
|
|||
|
read -p "Proceed with migrations? " -n 1 -r
|
|||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]
|
|||
|
then
|
|||
|
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
|
|||
|
fi
|
|||
|
RAILS_ENV=production bundle exec rails db:migrate
|
|||
|
|
|||
|
systemctl restart --user discourse
|
|||
|
|
|||
|
sleep 2
|
|||
|
|
|||
|
systemctl status --user discourse
|