#!/bin/sh # postinst script for hostmaster # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-remove' # * `abort-deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package # Source debconf library. . /usr/share/debconf/confmodule if [ "$DPKG_DEBUG" = "developer" ]; then set -x fi AEGIRHOME="$(su aegir -s /bin/sh -c 'echo $HOME')" case "$1" in configure) # fetch the version number from provision. the line we're looking for looks like this # version=6.x-1.9 # this obviously doesn't work for git releases VERSION=`sed -n '/^version/{s/^.*= *//;p}' /usr/share/drush/commands/provision/provision.info` FLAGS="--yes" if [ "$DPKG_DEBUG" = "developer" ]; then FLAGS="$FLAGS --debug" fi db_get "aegir/makefile" if [ ! -z "$RET" ]; then FLAGS="$FLAGS --makefile='$RET'" fi db_get "aegir/profile" if [ ! -z "$RET" ]; then PROFILE=$RET FLAGS="$FLAGS --profile='$PROFILE'" else PROFILE='hostmaster' fi db_get "aegir/webserver" if [ ! -z "$RET" ]; then if [ "$RET" = 'apache2' ]; then RET='apache' # convert argument to something aegir can understand fi FLAGS="$FLAGS --http_service_type='$RET'" WEBSERVER="$RET" fi db_get "aegir/working-copy" if [ ! -z "$RET" ]; then FLAGS="$FLAGS --working-copy" fi # make sure the configuration file exists before symlinking it in place (below) touch $AEGIRHOME/config/$WEBSERVER.conf # fix permissions on installed directories chown aegir:aegir "$AEGIRHOME" "$AEGIRHOME/config" "$AEGIRHOME/config/$WEBSERVER.conf" # flush the drush cache to find new commands su -s /bin/sh aegir -c 'drush cache-clear drush' site_uri=`su -s /bin/sh aegir -c 'drush @hostmaster status --fields="uri" --field-labels=0 2>/dev/null | tr "\n" " " | sed -e "s/^[[:space:]]*//g" -e "s/[[:space:]]*\$//g"'` drupal_root=`su -s /bin/sh aegir -c 'drush @hostmaster status --fields="root" --field-labels=0 2>/dev/null | tr "\n" " " | sed -e "s/^[[:space:]]*//g" -e "s/[[:space:]]*\$//g"'` if [ -d "$drupal_root" ]; then # upgrade db_stop echo "Aegir frontend (@hostmaster) site detected in $drupal_root" # determin target directory for the new hostmaster profile. if [ "$VERSION" = "7.x-3.x" ]; then NEW_PLATFORM="$AEGIRHOME/hostmaster-$VERSION-$(date +'%F-%H%M')" else NEW_PLATFORM="$AEGIRHOME/hostmaster-$VERSION" fi # make those paths canonical with readlink to make sure we can compare correctly NEW_PLATFORM=`readlink -f "$NEW_PLATFORM"` drupal_root=`readlink -f $drupal_root` # we upgrade only if the target platform doesn't exist *OR* # if it's not the current platform if [ -d "$NEW_PLATFORM" ] && [ "$drupal_root" = "$NEW_PLATFORM" ]; then echo "it seems to be the same version as the one we're trying to install, not upgrading" else echo "upgrading the frontend from $drupal_root to $NEW_PLATFORM" if su -s /bin/sh aegir -c 'drush @hostmaster pm-list --status=enabled --pipe' | grep -q hosting_queued; then service hosting-queued stop fi cd "$drupal_root" su -s /bin/sh aegir -c "drush hostmaster-migrate $FLAGS '$site_uri' '$NEW_PLATFORM'" echo "upgrade finished, old platform left in $drupal_root" # restart daemon if enabled if su -s /bin/sh aegir -c 'drush @hostmaster pm-list --status=enabled --pipe' | grep -q hosting_queued; then service hosting-queued start fi fi else # fresh install db_get "aegir/site" if [ ! -z "$RET" ]; then site_uri="$RET" fi db_get "aegir/db_host" AEGIR_DB_HOST="$RET" # Read /etc/os-release to properly handle differences between distributions OS_ID=$(grep ^ID /etc/os-release | cut -d= -f2) # Determin if we create a db accoount or ask for it. # Starting from MariaDB 10.1... https://www.drupal.org/node/2770819 # TODO: Work with future versions if mysql --database=mysql --execute="show tables;" > /dev/null 2>&1 then # MariaDB = 10.1 CREATEUSER=1 else # Mysql & MariaDB < 10.1 CREATEUSER=0 fi if [ $CREATEUSER = 0 ]; then db_get "aegir/db_user" AEGIR_DB_USER="$RET" db_get "aegir/db_password" AEGIR_DB_PASS="$RET" if [ -z "$AEGIR_DB_PASS" ]; then echo EMPTY database password, can not be good. fi fi db_get "aegir/email" EMAIL="$RET" db_go if [ $CREATEUSER = 0 ]; then # forget the DB password in debconf storage db_reset aegir/db_password || true db_fset aegir/db_password "seen" "true" || true fi db_stop if [ $CREATEUSER = 1 ]; then AEGIR_DB_USER="aegir_root" # Random password, will be stored in /var/aegir/.drush/server_localhost.alias.drushrc.php AEGIR_DB_PASS=$(openssl rand -base64 12) /usr/bin/mysql -e "GRANT ALL ON *.* TO '$AEGIR_DB_USER'@'localhost' IDENTIFIED BY '$AEGIR_DB_PASS' WITH GRANT OPTION" fi if [ -d $AEGIRHOME/.drush/provision ]; then echo "existing provision in $AEGIRHOME/.drush/provision detected, move away and try again" exit 1 fi echo "installing the Aegir frontend (Drupal with the $PROFILE profile), please wait..." if [ "$DPKG_DEBUG" = "developer" ]; then DEBUG="--debug" fi # pass data through JSON for extra security su -s /bin/sh aegir -c "cd $AEGIRHOME && drush hostmaster-install $FLAGS --backend $site_uri 2>&1 | drush backend-parse $DEBUG" <&1 | grep -q 'Drupal bootstrap.*Successful'; then echo 'Aegir frontend bootstrap correctly, operation was a success!' echo 'Use this URL to login on your new site:' su -s /bin/sh aegir -c 'drush @hostmaster uli' else echo 'Aegir frontend failed to bootstrap, something went wrong!' echo 'Look at the log above for clues or run with DPKG_DEBUG=developer' exit 1 fi ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0