diff --git a/script/git-upgrade b/script/git-upgrade index ad19f58..5a00890 100755 --- a/script/git-upgrade +++ b/script/git-upgrade @@ -4,6 +4,10 @@ set -e export RAILS_ENV=production +say(){ + echo -e "\033[33;01m$0: $1\033[m" +} + get_value(){ ruby -ryaml -e "puts YAML.load_file('config/database.yml')['$RAILS_ENV']['$1']" } @@ -29,6 +33,62 @@ version(){ exit 0 } +backup(){ + say "Making files backup" + rake backup + + database=$(get_value database) + adapter=$(get_value adapter) + + if [ "$adapter" = "postgresql" ]; then + mkdir -p backups/ + dumpfile=backups/dump-$(date +%Y-%m-%d-%H-%M).sql + say "Making database backup" + pg_dump "$database" > "$dumpfile" + fi +} + +stop_service(){ + say "Stopping service" + ./script/production stop || say "Stop failed, trying to continue anyway" + sudo /etc/init.d/memcached restart +} + +start_service(){ + say "Starting service" + ./script/production start +} + +upgrade_code(){ + say "Upgrading code" + git pull + for dir in public/designs/themes/*; do + (cd $dir && test -e .git/config && git pull) + done + rake makemo +} + +upgrade_database(){ + say "Upgrading database" + + 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 +} + shell=no while test $# -gt 0; do case "$1" in @@ -48,45 +108,8 @@ while test $# -gt 0; do shift done - -./script/production stop || echo "Stop failed, trying to continue anyway" - -sudo /etc/init.d/memcached restart - -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 - -./script/production start +backup +stop_service +upgrade_code +upgrade_database +start_service -- libgit2 0.21.2