Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
script/quick-start: backport upstream script
script/quick-start | 186 ++++++++++++++++++++++++++++++-----------------
diff --git a/script/quick-start b/script/quick-start index 539e5ac278ce2684217201bf6e4a6f888e3ef8e8..d5c9b1f92250e4a52e6fe4fb8cf57000c4ea9847 100755 --- a/script/quick-start +++ b/script/quick-start @@ -61,89 +61,141 @@ export PATH="$dir:$PATH" fi } +_usage() { + echo "$program_name: basic setup for Noosfero" + echo + echo "Options:" + echo " --force-install|-f" + echo " Force installation" + echo " --db-setup|-d" + echo " Setup the database" + echo " --install-dependencies|-i" + echo " Install all Noosfero's dependecies" + echo +} + # change current directory to the noosfero's root cd "$(dirname $0)/../" force_install=false -if test "$1" = '--force-install'; then - force_install=true -fi -if gem which system_timer >/dev/null 2>&1 && which xvfb-run >/dev/null 2>&1 && test "$force_install" = 'false'; then - say "Assuming dependencies are already installed. Pass --force-install to force their installation" -else - if ! which lsb_release >/dev/null 2>&1; then - # special case Debian-based systems; in others people will have to install - # lsb-release by themselves - if which apt-get >/dev/null 2>&1; then - sudo apt-get update - sudo apt-get -y install lsb-release +db_setup=false +install_dependencies=false +program_name=$(basename $0) + +while [ ! -z "$1" ]; do + opt="$1" + shift + case "$opt" in + -f|--force-install) + force_install=true + ;; + -d|--db-setup) + db_setup=true + ;; + -i|--install-dependencies) + install_dependencies=true + ;; + -h|--help) + _usage + exit 0 + ;; + *) + echo "Unknown option: $opt" + _usage + exit 1 + ;; + esac +done + +if [ "$install_dependencies" = 'true' ] || [ "$db_setup" = 'false' ]; then + if gem which system_timer >/dev/null 2>&1 && which xvfb-run >/dev/null 2>&1 && test "$force_install" = 'false'; then + say "Assuming dependencies are already installed. Pass --force-install to force their installation" + else + if ! which lsb_release >/dev/null 2>&1; then + # special case Debian-based systems; in others people will have to install + # lsb-release by themselves + if which apt-get >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get -y install lsb-release + else + complain "E: lsb_release not available! (Try installing the lsb-release package)" + exit 1 + fi + fi + system=$(echo $(lsb_release -sic) | awk '{print(tolower($1) "-" tolower($2))}') + install_script="$(dirname $0)/install-dependencies/${system}.sh" + if test -f "$install_script"; then + . $install_script + say "I: All dependecies were installed." else - complain "E: lsb_release not available! (Try installing the lsb-release package)" + # FIXME the Ruby stuff could be installed with Rubygems + # FIXME but there is not generic way to install the non-Ruby stuff + complain "E: $install_script not found, cannot install dependencies." exit 1 fi fi - system=$(echo $(lsb_release -sic) | awk '{print(tolower($1) "-" tolower($2))}') - install_script="$(dirname $0)/install-dependencies/${system}.sh" - if test -f "$install_script"; then - . $install_script - else - # FIXME the Ruby stuff could be installed with Rubygems - # FIXME but there is not generic way to install the non-Ruby stuff - complain "E: $install_script not found, cannot install dependencies." - exit 1 - fi fi -# Ensure database is running -sudo service postgresql start -while ! sudo -u postgres psql < /dev/null >/dev/null 2>&1; do - sleep 5s -done +if [ "$db_setup" = 'true' ] || [ "$install_dependencies" = 'false' ]; then + # Ensure database is running + sudo service postgresql start + while ! sudo -u postgres psql < /dev/null >/dev/null 2>&1; do + sleep 5s + done -if test -e config/database.yml && test "$force_install" = 'false'; then - say 'Not updating existent database.yml.' - say 'If you wish to automatic reconfigure your database connection and' - say 'recreate the database, you can delete config/database.yml and run' - say 'this script again.' -else - # create the database with sample data - say 'Configuring Noosfero to use PostgreSQL, with your user.' - run cp config/database.yml.pgsql config/database.yml - if [ -z "$USER" ]; then - USER=$(stat -c %U $0) + if test -e config/database.yml && test "$force_install" = 'false'; then + say 'Not updating existent database.yml.' + say 'If you wish to automatic reconfigure your database connection and' + say 'recreate the database, you can delete config/database.yml and run' + say 'this script again.' + else + # create the database with sample data + say 'Configuring Noosfero to use PostgreSQL, with your user.' + run cp config/database.yml.pgsql config/database.yml + if [ -z "$USER" ]; then + USER=$(whoami) + fi + sed -ri "s/username: noosfero/username: $USER/" config/database.yml + + # Create database and users + sudo su - postgres -c "createuser $USER --no-superuser --createdb --no-createrole" || true + sudo su - postgres -c "createdb noosfero_development -O $USER" || true + sudo su - postgres -c "createdb noosfero_test -O $USER" || true + + # Create table and sample data + run rake db:schema:load + run rake db:schema:load RAILS_ENV=test + + if [ "$RAILS_ENV" != 'test' ]; then + run rake db:data:minimal + rails runner 'Environment.default.enable("skip_new_user_email_confirmation")' + fi + + say "I: Database setup finished." fi - sed -ri "s/username: noosfero/username: $USER/" config/database.yml - # Create database and users - sudo su - postgres -c "createuser $USER --no-superuser --createdb --no-createrole" || true - sudo su - postgres -c "createdb noosfero_development -O $USER" || true - sudo su - postgres -c "createdb noosfero_test -O $USER" || true - - # Create table and sample data - run rake db:schema:load - run rake db:schema:load RAILS_ENV=test - run rake db:data:minimal - rails runner 'Environment.default.enable("skip_new_user_email_confirmation")' + if [ ! -d locale ]; then + run quiet rake noosfero:translations:compile + fi fi -if [ ! -d locale ]; then - run quiet rake noosfero:translations:compile -fi +if [ "$db_setup" = 'false' ] && [ "$install_dependencies" = 'false' ]; then + # create needed directory + mkdir -p tmp/pids + mkdir -p tmp/cache + mkdir -p cache -# create needed directory -mkdir -p tmp/pids -mkdir -p tmp/cache -mkdir -p cache + # use default gitignore rules + if [ ! -f .gitignore ]; then + ln -s gitignore.example .gitignore + fi -# use default gitignore rules -if [ ! -f .gitignore ]; then - ln -s gitignore.example .gitignore + # remove obsolete symbolic link added by old versions + rm -f vendor/rails + + # you can now start the server + say "I: Congratulations, you are ready to run Noosfero." + say "I: To execute Noosfero in development mode, run \`./script/development\` and browse to http://localhost:3000" + say "I: To execute Noosfero tests, run \`rake\`." fi -# remove obsolete symbolic link added by old versions -rm -f vendor/rails - -# you can now start the server -say "I: Congratulations, you are ready to run Noosfero." -say "I: To execute Noosfero in development mode, run \`./script/development\` and browse to http://localhost:3000" -say "I: To execute Noosfero tests, run \`rake\`."