aegir3-provision.postinst 3.95 KB
Newer Older
1
#!/bin/sh
anarcat's avatar
anarcat committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# postinst script for provision
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

anarcat's avatar
anarcat committed
20 21 22
# Source debconf library.
. /usr/share/debconf/confmodule

23
if [ "$DPKG_DEBUG" = "developer" ]; then
24 25 26
    set -x
fi

anarcat's avatar
anarcat committed
27
VARLIB="/var/aegir"
anarcat's avatar
anarcat committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41

case "$1" in
    configure)
        # add a aegir user if one does not already exist
        if ! getent passwd aegir >/dev/null ; then
            echo "adding aegir user..."
            adduser --quiet --system --no-create-home --group \
                --home "$VARLIB" \
                --shell '/bin/bash' \
                --gecos 'Aegir user,,,' \
                aegir
        fi
        adduser --quiet aegir www-data

42 43 44 45 46 47 48 49 50
        if [ -d /etc/sudoers.d ]; then
            ucf --debconf-ok /usr/share/doc/aegir3-provision/examples/example.sudoers /etc/sudoers.d/aegir
            ucfr aegir-provision /etc/sudoers.d/aegir
            chmod 440 /etc/sudoers.d/aegir
        else
            echo "running an older version of sudo"
            echo "copy content of /usr/share/doc/aegir3-provision/examples/example.sudoers into /etc/sudoers for aegir to run properly"
        fi

51 52 53
        # fix permissions on installed directories
        chown aegir:aegir "$VARLIB"

54 55
        # Warn about missing composer, requiring it would break Jessie since it has no such package.
        command -v composer >/dev/null 2>&1 || { echo "WARNING: System is missing PHP composer, please install a Debian package or see https://getcomposer.org/" >&2; }
56 57


58 59
        db_get "aegir/drush_version"
        DRUSH_VERSION="$RET"
60 61 62

        if [ "$DRUSH_VERSION" != "ignore" ]; then

helmo's avatar
helmo committed
63
          DRUSH_MAJOR_VERSION=$(echo $DRUSH_VERSION| cut -d. -f1)
64

helmo's avatar
helmo committed
65
          if [ "$DRUSH_VERSION" = "stable" ]; then
66

helmo's avatar
helmo committed
67
              DRUSH_PHAR_URL="http://files.drush.org/drush.phar"
68

helmo's avatar
helmo committed
69
          elif [ "$DRUSH_VERSION" = "unstable" ]; then
70

helmo's avatar
helmo committed
71
              DRUSH_PHAR_URL="http://files.drush.org/drush-unstable.phar"
72

helmo's avatar
helmo committed
73
          elif [ "$DRUSH_MAJOR_VERSION" -ge "8" ]; then
74

helmo's avatar
helmo committed
75
              DRUSH_PHAR_URL="https://github.com/drush-ops/drush/releases/download/$DRUSH_VERSION/drush.phar"
76

helmo's avatar
helmo committed
77
          fi
78

helmo's avatar
helmo committed
79
          if [ -n "$DRUSH_PHAR_URL" ]; then
80

helmo's avatar
helmo committed
81 82
              curl -SsL $DRUSH_PHAR_URL -o drush
              chmod +x drush
83

helmo's avatar
helmo committed
84
              DRUSH_PATH="/usr/local/bin/drush"
85

helmo's avatar
helmo committed
86 87 88 89
              # Rename an old drush executable.
              if [ -f $DRUSH_PATH ]; then
                mv $DRUSH_PATH $DRUSH_PATH-old-$(date +'%Y-%m-%d')
              fi
90

helmo's avatar
helmo committed
91
              mv drush $DRUSH_PATH
92

helmo's avatar
helmo committed
93
          else  # Drush versions prior to 8 aren't available as .phar's.
94

helmo's avatar
helmo committed
95 96
              # Install Drush.
              su -c "composer global require drush/drush:$DRUSH_VERSION" aegir
97

helmo's avatar
helmo committed
98 99 100 101
              # Rename an old drush executable.
              if [ -f /usr/local/bin/drush ]; then
                mv /usr/local/bin/drush /usr/local/bin/drush-old-$(date +'%Y-%m-%d')
              fi
102

helmo's avatar
helmo committed
103 104
              # Symlink Drush for other users to use.
              ln -s ~aegir/.composer/vendor/bin/drush /usr/local/bin
105

106 107 108
              # Add composer's bin dir to the $PATH.
              # TODO: This should be made idempotent.
              echo "export PATH=\"\$HOME/.composer/vendor/bin:\$PATH\"" >>  ~aegir/.bashrc
helmo's avatar
helmo committed
109
          fi
110
        fi
111

anarcat's avatar
anarcat committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    ;;

    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