Skip to content

Instantly share code, notes, and snippets.

@wstrinz
Created June 1, 2016 04:04
Show Gist options
  • Save wstrinz/9744156f86be59371a660f257da0e76b to your computer and use it in GitHub Desktop.
Save wstrinz/9744156f86be59371a660f257da0e76b to your computer and use it in GitHub Desktop.
quick script for huginn updating. needs original repo to have been cloned by root :(
run_cmd = ->(cmdstring) { puts cmdstring; puts `#{cmdstring}`}
puts '# You can also use [Capistrano](./capistrano.md) to keep your installation up to date.'
puts '### 0. Ensure depencies are up to date'
cmd_to_run = <<-EOCMD
cd /home/huginn/huginn
sudo bundle exec rake production:check
EOCMD
run_cmd[cmd_to_run]
puts '### 1. Stop server'
cmd_to_run = <<-EOCMD
sudo bundle exec rake production:stop
EOCMD
run_cmd[cmd_to_run]
puts '### 2. Store the current version'
cmd_to_run = <<-EOCMD
export OLD_VERSION=`git rev-parse HEAD`
EOCMD
run_cmd[cmd_to_run]
puts '### 3. Update the code'
puts '# Back up changed files'
cmd_to_run = <<-EOCMD
cp Procfile Procfile.bak
EOCMD
run_cmd[cmd_to_run]
puts '# Get the new code'
cmd_to_run = <<-EOCMD
git fetch --all
git checkout -- Procfile
git checkout master
git pull
EOCMD
run_cmd[cmd_to_run]
puts '# Restore backed up files'
cmd_to_run = <<-EOCMD
cp Procfile.bak Procfile
EOCMD
run_cmd[cmd_to_run]
puts '### 4. Install gems, migrate and precompile assets'
cmd_to_run = <<-EOCMD
cd /home/huginn/huginn
sudo -u huginn -H bundle install --deployment --without development test
echo '# Run database migrations'
sudo -u huginn -H bundle exec rake db:migrate RAILS_ENV=production
echo '# Clean up assets and cache'
sudo -u huginn -H bundle exec rake assets:clean assets:precompile tmp:cache:clear RAILS_ENV=production
EOCMD
run_cmd[cmd_to_run]
puts '### 5. Update the Procfile'
puts '#Check for changes made to the default `Procfile`'
cmd_to_run = <<-EOCMD
sudo -u huginn -H git diff $OLD_VERSION..master Procfile
EOCMD
run_cmd[cmd_to_run]
puts '#Update your `Procfile` if the default options of the version you are using changed'
# cmd_to_run = <<-EOCMD
# sudo -u huginn -H editor Procfile
# EOCMD
puts '### 6. Update the .env file'
puts '#Check for changes made to the example `.env`'
cmd_to_run = <<-EOCMD
sudo -u huginn -H git diff $OLD_VERSION..master .env.example
EOCMD
run_cmd[cmd_to_run]
puts '#Update your `.env` with new options or changed defaults'
# cmd_to_run = <<-EOCMD
# sudo -u huginn -H editor .env
# EOCMD
puts '### 7. Export init script and start Huginn'
cmd_to_run = <<-EOCMD
sudo bundle exec rake production:export
EOCMD
run_cmd[cmd_to_run]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment