Last active
January 18, 2018 09:14
-
-
Save andreslucena/b25e7d32b1d63451472389b634448278 to your computer and use it in GitHub Desktop.
Revisions
-
andreslucena revised this gist
Dec 28, 2017 . 1 changed file with 190 additions and 88 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,41 +1,62 @@ #!/usr/bin/env bash # # Decidim installation script on Ubuntu 16.04 LTS and macos sierra 10.2 # # This is a BETA and as such you should be aware that this could break your environment (if you have any) # This will install rbenv, postgresql, nodejs and install decidim on this directory # It'll take 15 minutes depending on your network connection # set -e #set -x DB_USER=decidim_app DB_PASS=$( openssl rand -base64 32 ) DECIDIM_DIR=decidim_application RUBY_VERSION=2.3.1 function ascii_banner { echo "************************************************************************************************" echo " █████████▓▌▄, ╦╦⌐ ]╫Ñ .╦╦ j╫Ñ" echo " ████████▀█████▌ ╫╫∩ .╫╫ " echo " ███████▌╫╫██████p ╔NN╦╫╫∩ ,╦NN╦≈ ╔╦NN╦ j╫Ñ .╦NN╦╫╫ jNN jNu╦NN╦╔╦DN≈" echo " █████▓╫╫╫╫╫▒▓████ j╫Ñ ╫╫∩ :╫Ñ ╫╫⌐ 1╫H ]╫H j╫Ñ ╫╫H :╫╫ j╫Ñ ]╫Ñ ╫╫H :╫╫" echo " ████▒╫╫╫╫╫╫╫▒▓███ ]╫N ╫╫∩ j╫Ñ≈≈╫╫⌐ ╫╫H j╫Ñ ╫╫░ :╫╫ j╫Ñ ]╫Ñ ╫╫∩ :╫╫" echo " ███████╫╫╫▒█████▌ ]╫N ╫╫∩ j╫Ñ'''' ╫╫H j╫Ñ ╫╫░ :╫╫ j╫Ñ ]╫Ñ ╫╫∩ :╫╫" echo " ████████▒▓█████▀ ]╫N ╫╫∩ j╫Ñ j╦¬ ╠╫H j╦r j╫Ñ ╫╫░ :╫╫ j╫Ñ ]╫Ñ ╫╫∩ :╫╫" echo " ████████████▓▀ 'Ñ╫NN╬╫∩ ╚╫N╦╫M ╩╫NÑÑ j╫Ñ ╙ÑÑ╦Ñ╫╫ j╫Ñ ]╫Ñ ╫╫∩ :╫╫" echo "************************************************************************************************" } function start_banner { ascii_banner echo " Welcome to Decidim installation" echo " This is a BETA" echo " You should be aware that this could break your environment (if you have any)" echo " This will install rbenv, postgresql, nodejs and install decidim on this directory" echo " It'll take from 10 to 30 minutes depending on your network connection" echo "************************************************************************************************" echo "Starting on 60 seconds. Press CTRL+C to cancel" sleep 60 } function end_banner { ascii_banner echo " Decidim installation process finished. All is OK!" echo "************************************************************************************************" echo " You can go to http://localhost:3000 and see the website." echo " It'll take a few minutes to start up the first time. Be patient. " echo "************************************************************************************************" echo " ------------------------------------------------------------------------------------------" echo " | Email | Password | URL | Role |" echo " ------------------------------------------------------------------------------------------" echo " | user@example.org | decidim123456 | http://localhost:3000/session/new | Regular user |" echo " | admin@example.org | decidim123456 | http://localhost:3000/admin | Admin user |" echo " ------------------------------------------------------------------------------------------" echo "************************************************************************************************" read -p "Press any key to continue: " -n 1 -r } function check_root { if [ "$(id -u)" == "0" ] ; then @@ -44,96 +65,177 @@ function check_root { fi } function check_git_config { if [ $(git config -l | wc -l) == 0 ] ; then echo "Configure git and execute again" echo 'git config --global user.email "you@example.com"' echo 'git config --global user.name "Your Name"' exit 2 fi } ### macos function install_ruby_macos { if [ ! -f /usr/local/bin/rbenv ] ; then brew install rbenv ruby-build echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile source ~/.bash_profile rbenv install $RUBY_VERSION rbenv global $RUBY_VERSION echo "gem: --no-document" > ~/.gemrc gem install bundler fi } ### Ubuntu function install_ruby_ubuntu { if [ ! -d ~/.rbenv ] ; then git clone https://github.com/rbenv/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)" git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build rbenv install $RUBY_VERSION rbenv global $RUBY_VERSION echo "gem: --no-document" > ~/.gemrc gem install bundler fi } ### Shared function install_decidim { gem install decidim decidim ${DECIDIM_DIR} cd ${DECIDIM_DIR} bundle install git init git add . git commit -m "Initial installation with Decidim (https://decidim.org)" cd - } function configure_db { cd ${DECIDIM_DIR} echo "gem 'figaro'" >> Gemfile bundle install bundle exec figaro install cat <<EOF > config/application.yml DATABASE_USERNAME: ${DB_USER} DATABASE_PASSWORD: ${DB_PASS} EOF cd - } function migrate_db { cd ${DECIDIM_DIR} bin/rails db:create db:migrate db:seed cd - } function start_decidim { cd ${DECIDIM_DIR} bin/rails server } function cleanup { rm -rf ${DECIDIM_DIR} psql -c "DROP DATABASE IF EXISTS decidim_application_development;" psql -c "DROP DATABASE IF EXISTS decidim_application_test;" psql -c "DROP ROLE IF EXISTS decidim_app;" } function install_all_ubuntu { sudo apt-get update # Installs development tools sudo apt-get install -y build-essential autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev # Installs Ruby install_ruby_ubuntu # Installs and configures PostgreSQL sudo apt-get install -y postgresql libpq-dev sudo -u postgres psql -c "CREATE USER ${DB_USER} WITH CREATEROLE SUPERUSER CREATEDB;" sudo -u postgres psql -c "ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASS}';" # Installs nodejs curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - sudo apt-get install -y nodejs # Installs imagemagick library sudo apt-get install -y imagemagick } function install_all_macos { # Installs xcode xcode-select -p 2> /dev/null || xcode-select --install 2> /dev/null # Installs Brew if [ ! -f /usr/local/bin/brew ] ; then /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew update fi # Installs Ruby install_ruby_macos # Installs and configures PostgreSQL brew install postgres sleep 5 nohup postgres -D /usr/local/var/postgres & sleep 5 createdb $(whoami) || true psql -c "CREATE USER ${DB_USER} WITH CREATEROLE SUPERUSER CREATEDB;" psql -c "ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASS}';" # Installs imagemagick library brew install imagemagick } function main { start_banner #cleanup ${DECIDIM_DIR} check_root check_git_config OS="`uname`" case $OS in 'Linux') echo "Installing dependencies for Ubuntu ..." install_all_ubuntu echo "Cloning decidim ..." install_decidim echo "Configuring database ..." configure_db migrate_db end_banner start_decidim ;; 'Darwin') echo "Installing dependencies for macos ..." install_all_macos echo "Cloning decidim ..." install_decidim echo "Configuring database ..." migrate_db end_banner start_decidim ;; *) "Operating System Not Supported" exit 2 ;; esac exit 0 } main -
andreslucena created this gist
Dec 22, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,139 @@ #!/usr/bin/env bash set -e function start_banner { echo "****************************************************************************************************************************************************************" echo "@@@@@@@@@@@@@@@@&&&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*..../@@@@@@@@@@@@&%%%%&@@@@,....#@@@@@@@@@@@@@@@@@@@@@@@@@@@" echo "################//(((((#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,....@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.....,@@@@@@@@@@@@,....,@@@@.....,@@@@@@@@@@@@@@@@@@@@@@@@@@@" echo "###############(,/(((((((((#@@@@@@@@@@@@@@@@@@@@@@@@@@@,....@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.....@@@@@@@@@@@@@,....,@@@@ ....@@@@@@@@@@@@@@@@@@@@@@@@@@@@" echo "##############(*.,(((((((((((&@@@@@@@@@@@@@@@@@@@@@@@@@,....@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,....,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" echo "##############,...*(((((((((((#@@@@@@@@@@@@@@@@@@&%%%&@,....@@@@@@@@&%%%%%&@@@@@@@@@@@%%%%%&@@@@@@&%%%%@@@@@@@&%%%%@,....,@@@@&%%%%@@@@@%%%%@@@%%%%%@@@@&%%%%&@" echo "#############*.....*/(((((((((((&@@@@@@@@@@@@@@%............@@@@@@*.........%@@@@@@%*........%@@@@*....@@@@@%*...........,@@@@*....@@@@@..../........**......./" echo "###########/,........//(((((((((#@@@@@@@@@@@@@,.............@@@@@/...........*@@@@#...........*@@@*....@@@@@.............,@@@@*....@@@@@......................." echo "########/*.............,//(((((((@@@@@@@@@@@@@.....@@@@,....@@@@@....,@@@,....@@@*.....@@@,...*@@@*....@@@@/....,@@@,....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "###(/*,....................,*//((#@@@@@@@@@@@@....*@@@@,....@@@@*....,@@@,....@@@*....@@@@,....@@@*....@@@@,....,@@@,....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "(((/,,......................,*///#@@@@@@@@@@@@....*@@@@,....@@@@,....,@@@,....@@@*....@@@@@@@@@@@@*....@@@@,....,@@@,....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "#######(*...............*/(((((((@@@@@@@@@@@@@....*@@@@,....@@@@,.............@@@*....@@@@@@@@@@@@*....@@@@,....,@@@,....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "##########/...........*((((((((((@@@@@@@@@@@@@....*@@@@,....@@@@,.............@@@*....@@@@@@@@@@@@*....@@@@,....,@@@,....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "############(,.....,/(((((((((((@@@@@@@@@@@@@@....*@@@@,....@@@@,....,@@@@@@@@@@@*....@@@@@@@@@@@@*....@@@@,....,@@@,....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "#############(,...,((((((((((((@@@@@@@@@@@@@@@....*@@@@,....@@@@.....,@@@@&%%%@@@,....@@@@&%%%&@@@*....@@@@,....,@@@,....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "##############(,../(((((((((((@@@@@@@@@@@@@@@@.....@@@@,....@@@@@....,@@@#,...@@@...../@@@*...,@@@*....@@@@.....,@@@,....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "###############(.*((((((((((@@@@@@@@@@@@@@@@@@,....*%.......@@@@@.....#@@,....@@@@.....*%#....,@@@*....@@@@@.....%@%.....,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "################*/((((((((@@@@@@@@@@@@@@@@@@@@@.............@@@@@@........... @@@@@...........@@@@*....@@@@@.............,@@@@*....@@@@@.....@@@@,....@@@@@...." echo "****************************************************************************************************************************************************************" echo " Welcome to Decidim installation on Ubuntu 16.04 LTS" echo " This is a BETA and as such you should be aware that this could break your environment (if you have any)" echo " This will install rbenv, postgresql, nodejs and install decidim on this directory" echo " It'll take 15 minutes depending on your network connection" echo "****************************************************************************************************************************************************************" read -p "Are you sure? " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]] then exit 1 fi } function check_root { if [ "$(id -u)" == "0" ] ; then echo "This script must not be run as root" 1>&2 exit 1 fi } function generate_password { date +%s | sha256sum | base64 | head -c 32 ; echo } function install_rbenv { if [ ! -d ~/.rbenv ] ; then sudo apt-get update sudo apt-get install -y build-essential autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev git clone https://github.com/rbenv/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)" git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build rbenv install 2.3.1 rbenv global 2.3.1 echo "gem: --no-document" > ~/.gemrc gem install bundler fi } function install_postgresql { db_user=$1 db_pass=$2 sudo apt-get install -y postgresql libpq-dev sudo -u postgres psql -c "CREATE USER ${db_user} WITH CREATEROLE SUPERUSER CREATEDB;" sudo -u postgres psql -c "ALTER USER ${db_user} WITH PASSWORD '${db_pass}';" } function install_nodejs { curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - sudo apt-get install -y nodejs } function install_decidim { decidim_dir=$1 sudo apt-get install -y imagemagick gem install decidim decidim ${decidim_dir} cd ${decidim_dir} bundle install cd - } function configure_decidim_db { decidim_dir=$1 db_user=$2 db_pass=$3 cd ${decidim_dir} git init git add . git commit -m "Initial installation with Decidim (https://decidim.org)" echo "gem 'figaro'" >> Gemfile bundle install bundle exec figaro install cat <<EOF > config/application.yml DATABASE_USERNAME: ${db_user} DATABASE_PASSWORD: ${db_pass} EOF bin/rails db:create db:migrate db:seed cd - } function start_decidim_webserver { decidim_dir=$1 cd $decidim_dir bin/rails s } function cleanup { decidim_dir=$1 rm -rf ${decidim_dir} sudo -u postgres psql -c "DROP DATABASE decidim_application_development;" sudo -u postgres psql -c "DROP DATABASE decidim_application_test;" sudo -u postgres psql -c "DROP ROLE decidim_app;" } function main { start_banner db_user=decidim_app db_pass=$(generate_password) decidim_dir=decidim_application #cleanup ${decidim_dir} check_root install_rbenv install_postgresql ${db_user} ${db_pass} install_nodejs install_decidim ${decidim_dir} configure_decidim_db ${decidim_dir} ${db_user} ${db_pass} start_decidim_webserver ${decidim_dir} } main