From f5815890ecba49aba2913373ca37cb4c89781f54 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 30 Nov 2009 19:12:19 -0300 Subject: [PATCH] Adding upgrade script --- config/bashrc | 2 ++ script/git-upgrade | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 0 deletions(-) create mode 100644 config/bashrc create mode 100755 script/git-upgrade diff --git a/config/bashrc b/config/bashrc new file mode 100644 index 0000000..d0acae8 --- /dev/null +++ b/config/bashrc @@ -0,0 +1,2 @@ +export PS1="[Noosfero upgrade] (\w) $ " +eval `dircolors -b` diff --git a/script/git-upgrade b/script/git-upgrade new file mode 100755 index 0000000..71e9e24 --- /dev/null +++ b/script/git-upgrade @@ -0,0 +1,94 @@ +#!/bin/sh + +set -e + +export RAILS_ENV=production + +get_value(){ + ruby -ryaml -e "puts YAML.load_file('config/database.yml')['$RAILS_ENV']['$1']" +} + +usage(){ + echo "usage: $0 [OPTIONS]" + echo + echo "Options:" + echo + echo " -s, --shell Opens a shell just after upgrading code and" + echo " database to make manual steps if needed" + echo + echo " -h, --help Displays the help (this screen)" + echo + echo " -v, --version Displays Noosfero current version" + echo + exit $1 +} + +version(){ + version=$(ruby -Ilib -rnoosfero -e 'puts Noosfero::VERSION') + echo "Noosfero version $version" + exit 0 +} + +shell=no +while test $# -gt 0; do + case "$1" in + --shell) + shell=yes + ;; + --help) + usage 0 + ;; + --version) + version + ;; + *) + usage 1 + ;; + esac + shift +done + + +./script/production stop || echo "Stop failed, trying to continue anyway" + +sudo /etc/init.d/memcached stop + +rake backup + +database=$(get_value database) +adapter=$(get_value adapter) + +if [ "$adapter" = "postgresql" ]; then + mkdir -p backups/ + backup=backups/dump-$(date +%Y-%m-%d-%H-%M).sql + pg_dump "$database" > "$backup" +fi + +git pull + +for dir in public/designs/themes/*; do + (cd $dir && test -e .git/config && git pull) +done + +rake db:migrate + +if test "$shell" = "yes"; then + echo "################################################" + echo "# Noosfero upgrade shell #" + echo "################################################" + echo "# #" + echo "# If you need to do any manual steps during #" + echo "# this upgrade, now is the time. #" + echo "# #" + echo "# After you finish, just exit this shell and #" + echo "# the upgrade will proceed #" + echo "################################################" + export PS1="[Noosfero upgrade] $PS1" + bash --rcfile config/bashrc +fi + +rake makemo + +sudo /etc/init.d/memcached start + +./script/production start -- libgit2 0.21.2