canvas-lms/script/canvas_update

174 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
# TODO: improve usage / help
function usage {
echo "usage: canvas_update [[[-q]] | [-h]]"
}
function echo_console_and_log {
echo $1
echo $1 >>$LOG
}
function is_git_dir {
git rev-parse --is-inside-git-dir >/dev/null 2>&1 && [ -d .git ]
return $?
}
function is_canvas_root {
CANVAS_IN_README=$(head -1 README.md 2>/dev/null | grep 'Canvas LMS')
[[ "$CANVAS_IN_README" != "" ]] && is_git_dir
return $?
}
function ensure_in_canvas_root_directory {
if ! is_canvas_root; then
echo "Please run from a Canvas root directory"
exit 0
fi
}
function intro_message {
echo "Bringing Canvas up to date ..."
echo " Log file is $LOG"
echo >>$LOG
echo "-----------------------------" >>$LOG
echo "Canvas Update ($(date)):" >>$LOG
echo "-----------------------------" >>$LOG
}
function update_plugins {
# Loop through each plugin dir, and if it's a git repo, update it
# This needs to be done first so that db:migrate can pull in any plugin-
# precipitated changes to the database.
for PLUGIN in vendor/plugins/*; do
(
cd $PLUGIN
if is_git_dir; then
echo_console_and_log " Updating plugin $PLUGIN ..."
( git checkout master >>$LOG 2>&1 && \
git pull --rebase >>$LOG 2>&1 ) || \
( echo " failed to pull plugin (see $LOG)"; kill -INT $$ )
fi
)
done
}
function rebase_canvas {
echo_console_and_log " Pulling Canvas code ..."
( git checkout master >>$LOG 2>&1 && git pull --rebase >>$LOG 2>&1 ) || \
( echo " failed to pull Canvas (see $LOG)"; kill -INT $$ )
}
function bundle_install_with_check {
echo_console_and_log " Checking your gems (bundle check) ..."
if bundle check >>$LOG 2>&1 ; then
echo_console_and_log " Gems are up to date, no need to bundle install ..."
else
bundle_install
fi
}
function bundle_install {
echo_console_and_log " Installing gems (bundle install) ..."
rm Gemfile.lock* >/dev/null 2>&1
bundle install >>$LOG 2>&1 || \
( echo " failed to bundle install (see $LOG)"; kill -INT $$ )
}
function rake_db_migrate_dev_and_test {
echo_console_and_log " Migrating DB ..."
RAILS_ENV=development bundle exec rake db:migrate >>$LOG 2>&1 || \
( echo " failed to migrate db (development) (see $LOG)"; kill -INT $$ )
RAILS_ENV=test bundle exec rake db:migrate >>$LOG 2>&1 || \
( echo " failed to migrate db (test) (see $LOG)"; kill -INT $$ )
}
function npm_install {
echo_console_and_log " Installing npm packages ..."
npm install >>$LOG 2>&1 || \
( echo " failed to install npm packages (see $LOG)"; kill -INT $$ )
}
function generate_js {
echo_console_and_log " Generating JS ..."
bundle exec rake js:generate >>$LOG 2>&1 || \
( echo " failed to generate JS (see $LOG)"; kill -INT $$ )
}
function generate_css {
echo_console_and_log " Generating CSS ..."
bundle exec rake css:generate >>$LOG 2>&1 || \
( echo " failed to generate CSS (see $LOG)"; kill -INT $$ )
}
function generate_css_styleguide {
echo_console_and_log " Generating CSS Styleguide ..."
bundle exec rake css:styleguide >>$LOG 2>&1 || \
( echo " failed to generate Styleguide (see $LOG)"; kill -INT $$ )
}
function generate_docs {
echo_console_and_log " Generating Docs ..."
bundle exec rake doc:api >>$LOG 2>&1 || \
( echo " failed to generate Docs (see $LOG)"; kill -INT $$ )
}
# TODO: moar tips plz
function tips {
echo "Tips:"
echo " - 'bundle exec guard': auto-compiles JS files while developing"
echo " - 'script/delayed_job run': run delayed jobs in the foreground"
}
function update_canvas {
ensure_in_canvas_root_directory
intro_message
update_plugins
rebase_canvas
bundle_install_with_check
rake_db_migrate_dev_and_test
npm_install
# skip if QUICK_MODE
if ! $1; then
generate_js
generate_css
generate_css_styleguide
generate_docs
fi
tips
}
LOG=`pwd`/log/canvas_update.log
# default options
PERFORM_UPDATE=true
QUICK_MODE=false
# parse options
# http://www.tldp.org/LDP/abs/html/internal.html#EX33
while getopts ":qh" Option
do
case $Option in
q )
echo "Quick mode enabled (assumes you have guard running and don't want to generate docs)"
QUICK_MODE=true;;
h )
PERFORM_UPDATE=false
usage;;
* )
PERFORM_UPDATE=false
echo "Sorry, that's not a valid option!"
usage;;
esac
done
if $PERFORM_UPDATE; then
update_canvas $QUICK_MODE
fi