2016-02-09 06:43:40 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
set -u
|
2016-02-10 02:04:35 +01:00
|
|
|
|
|
|
|
# small library for output
|
|
|
|
. "$(dirname $0)/out.sh"
|
|
|
|
|
2016-02-09 06:43:40 +01:00
|
|
|
# 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
|
|
|
|
testmachine=wwwd8-test-$(date +%y%m%d%H%M%S)
|
|
|
|
|
|
|
|
conf="$(dirname $0)/../config.sh"
|
|
|
|
[[ -f "$conf" ]] && . "$conf"
|
|
|
|
|
2016-02-10 02:04:35 +01:00
|
|
|
|
2016-02-09 06:43:40 +01:00
|
|
|
machineexists() {
|
|
|
|
machinectl list-images|awk '{ print $1 }'|egrep -q "^${1}\$"
|
|
|
|
}
|
|
|
|
|
2016-02-10 02:04:35 +01:00
|
|
|
inm() {
|
|
|
|
# execute command IN Machine
|
|
|
|
machine=$1
|
|
|
|
shift 1
|
|
|
|
systemd-nspawn --setenv='DEBIAN_FRONTEND=noninteractive' -D "/var/lib/machines/${machine}" "$@"
|
|
|
|
}
|
|
|
|
|
2016-02-09 06:43:40 +01:00
|
|
|
# intermediate creation END {{{1
|
|
|
|
if ! machineexists "$intermediate"; then
|
|
|
|
if ! machineexists "$sourcemachine"; then
|
2016-02-10 02:04:35 +01:00
|
|
|
progress "Creating source machine"
|
2016-02-09 06:43:40 +01:00
|
|
|
debootstrap "/var/lib/machines/${sourcemachine}"
|
2016-02-10 02:04:35 +01:00
|
|
|
ok "Source machine created ($sourcemachine)"
|
2016-02-09 06:43:40 +01:00
|
|
|
fi
|
|
|
|
machinectl clone "${sourcemachine}" "${intermediate}"
|
|
|
|
fi
|
2016-02-10 02:04:35 +01:00
|
|
|
progress "Setting up intermediate machine $intermediate"
|
|
|
|
cat <<EOF > /var/lib/machines/${intermediate}/etc/gitconfig
|
|
|
|
[transfer]
|
|
|
|
fsckobjects = true
|
|
|
|
[fetch]
|
|
|
|
fsckobjects = true
|
|
|
|
[receive]
|
|
|
|
fsckObjects = true
|
|
|
|
EOF
|
|
|
|
cat <<EOF > /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 <<EOF > /var/lib/machines/${intermediate}/etc/apt/sources.list.d/stretch.list
|
|
|
|
deb http://ftp.debian.org/debian stretch main
|
|
|
|
EOF
|
|
|
|
inm $intermediate apt-get update
|
|
|
|
fi
|
2016-02-09 06:43:40 +01:00
|
|
|
# those are idempotent, so...
|
2016-02-10 02:04:35 +01:00
|
|
|
inm $intermediate /usr/bin/apt-get -y install apache2 libapache2-mod-php5 php5-gd mariadb-server git
|
|
|
|
inm $intermediate /usr/bin/apt-get -y install -t stretch composer
|
|
|
|
inm $intermediate /usr/sbin/a2enmod rewrite
|
|
|
|
inm $intermediate /usr/sbin/a2enmod php5
|
|
|
|
inm $intermediate /bin/mkdir -p /mig
|
|
|
|
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
|
|
|
|
ln -sf /root/.composer/vendor/bin/drush /usr/bin/drush
|
|
|
|
ok "Drush installed"
|
|
|
|
fi
|
|
|
|
ok "Intermediate machine $intermediate set up"
|
2016-02-09 06:43:40 +01:00
|
|
|
# intermediate creation END }}}1
|
|
|
|
|
|
|
|
machinectl clone "${intermediate}" "${testmachine}"
|
2016-02-10 02:04:35 +01:00
|
|
|
progress "deploying on ${testmachine}"
|
2016-02-09 06:43:40 +01:00
|
|
|
systemd-nspawn -D "/var/lib/machines/${testmachine}" --bind-ro="$(readlink -f $(dirname $0)/../):/mig" /mig/deploy/deploy.sh
|
2016-02-10 02:04:35 +01:00
|
|
|
ok "all done"
|
2016-02-09 06:43:40 +01:00
|
|
|
|
|
|
|
# vim: set fdm=marker:
|