Skip to content

Instantly share code, notes, and snippets.

@andreslucena
Last active January 18, 2018 09:14
Show Gist options
  • Select an option

  • Save andreslucena/b25e7d32b1d63451472389b634448278 to your computer and use it in GitHub Desktop.

Select an option

Save andreslucena/b25e7d32b1d63451472389b634448278 to your computer and use it in GitHub Desktop.
Magic installation script for Decidim on Ubuntu 16.04 LTS and macos sierra 10.2
#!/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
@andreslucena
Copy link
Author

andreslucena commented Dec 22, 2017

This should be running with:

wget https://gist.githubusercontent.com/andreslucena/b25e7d32b1d63451472389b634448278/raw/309501144ec3f33e5e25985d5c93244db36e41ba/install_decidim.bash 
bash install_decidim.bash 

@andreslucena
Copy link
Author

andreslucena commented Dec 22, 2017

For trying this with LXD:

lxc launch ubuntu:16.04 dev-decidim 
lxc exec dev-decidim bash 

Somethings that could be improved on:

  • Installation for production/staging (using nginx + passenger)
  • Support for macos (using brew)
  • Checking ubuntu version

@agustibr
Copy link

Great! Thanks 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment