#!/bin/bash set -e set -u # small library for output . "$(dirname $0)/out.sh" # questo coso assume che si usa machinectl # questa macchina e' una debian pulita sourcemachine=jessie-amd64-base # questa macchina ha alcune cose di base installate/configurate # come Apache, PHP, eccetera intermediate=wwwd8-base if [[ $# -eq 0 ]]; then testmachine=wwwd8-test-$(date +%y%m%d%H%M%S) elif [[ $# -eq 1 ]]; then testmachine=$1 shift 1 else echo "Usage error" >&2 exit 2 fi drupal_path=/var/www/d8/ conf="$(dirname $0)/../config.sh" [[ -f "$conf" ]] && . "$conf" machineexists() { machinectl list-images|awk '{ print $1 }'|egrep -q "^${1}\$" } inm() { # execute command IN Machine machine=$1 shift 1 systemd-nspawn --setenv='DEBIAN_FRONTEND=noninteractive' -D "/var/lib/machines/${machine}" "$@" } sourcecreate() { progress "Creating source machine" debootstrap "/var/lib/machines/${sourcemachine}" ok "Source machine created ($sourcemachine)" } intermcreate() { if ! machineexists "$intermediate"; then if ! machineexists "$sourcemachine"; then sourcecreate fi machinectl clone "${sourcemachine}" "${intermediate}" fi progress "Setting up intermediate machine $intermediate" cat < /var/lib/machines/${intermediate}/etc/gitconfig [transfer] fsckobjects = true [fetch] fsckobjects = true [receive] fsckObjects = true EOF cat < /var/lib/machines/${intermediate}/etc/apt/apt.conf.d/default.conf APT::Default-Release "jessie"; EOF if [[ ! -f /var/lib/machines/${intermediate}/etc/apt/sources.list.d/stretch.list ]]; then cat < /var/lib/machines/${intermediate}/etc/apt/sources.list.d/stretch.list deb http://ftp.debian.org/debian stretch main EOF inm $intermediate /usr/bin/apt-get -q update fi # those are idempotent, so... inm $intermediate /usr/bin/apt-get -q -y install apache2 libapache2-mod-php5 php5-gd php5-mysql mariadb-server git pwgen inm $intermediate /usr/bin/apt-get -q -y install -t stretch composer inm $intermediate /usr/sbin/a2enmod rewrite inm $intermediate /usr/sbin/a2enmod php5 inm $intermediate /bin/mkdir -p /mig inm $intermediate /bin/sed -i "s+DocumentRoot.*$+DocumentRoot ${drupal_path}+" /etc/apache2/sites-enabled/000-default.conf progress "Installation of Drush" inm $intermediate /usr/bin/composer global require drush/drush:8.0.3 if ! inm $intermediate /usr/bin/test -x /root/.composer/vendor/bin/drush; then error Cannot install drush exit 1 else inm ${intermediate} /bin/ln -sf /root/.composer/vendor/bin/drush /usr/bin/drush ok "Drush installed" fi ok "Intermediate machine $intermediate set up" } testcreate() { if ! machineexists "${testmachine}"; then intermcreate machinectl clone "${intermediate}" "${testmachine}" fi } testcreate progress "deploying on ${testmachine}" systemd-nspawn -D "/var/lib/machines/${testmachine}"\ --bind-ro="$(readlink -f $(dirname $0)/../):/mig" \ /mig/deploy/deploy.sh ok "all done, enjoy!"