Files
dokku/debian/postinst

127 lines
4.1 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set -eo pipefail; [[ $TRACE ]] && set -x
. /usr/share/debconf/confmodule
readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}"
readonly DOKKU_LIB_ROOT="${DOKKU_LIB_PATH:-/var/lib/dokku}"
call-sshcommand() {
if [[ -x /usr/local/bin/sshcommand ]]; then
/usr/local/bin/sshcommand "$@"
elif [[ -x /usr/bin/sshcommand ]]; then
/usr/bin/sshcommand "$@"
else
echo "Unable to find sshcommand binary" 1>&2
exit 1
fi
}
case "$1" in
abort-upgrade|abort-remove|abort-deconfigure)
;;
configure)
mandb
[ ! -x /usr/bin/docker.io ] || ln -sf /usr/bin/docker.io /usr/local/bin/docker
modprobe aufs || echo "WARNING: Restart server to finish installing dokku!"
call-sshcommand create dokku /usr/bin/dokku
egrep -i "^docker" /etc/group || groupadd docker
usermod -aG docker dokku
2015-09-19 19:05:51 -04:00
echo "Setting up storage directories"
mkdir -p ${DOKKU_LIB_ROOT}/data ${DOKKU_LIB_ROOT}/data/storage
chown dokku:dokku -R ${DOKKU_LIB_ROOT}/data
2016-01-01 21:35:11 -05:00
echo "Setting up plugin directories"
2015-09-19 19:05:51 -04:00
# should be replaced by `plugn init`
mkdir -p ${DOKKU_LIB_ROOT}/core-plugins/available ${DOKKU_LIB_ROOT}/plugins/available
mkdir -p ${DOKKU_LIB_ROOT}/core-plugins/enabled ${DOKKU_LIB_ROOT}/plugins/enabled
touch ${DOKKU_LIB_ROOT}/core-plugins/config.toml ${DOKKU_LIB_ROOT}/plugins/config.toml
2015-09-19 19:05:51 -04:00
2016-01-01 21:35:11 -05:00
echo "Migrating old plugins"
find ${DOKKU_LIB_ROOT}/plugins/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do
2015-09-19 19:05:51 -04:00
if [ "$plugin" = "available" ] || [ "$plugin" = "enabled" ]; then
continue
elif [ -f ${DOKKU_LIB_ROOT}/plugins/$plugin/.core ]; then
rm -rf ${DOKKU_LIB_ROOT}/plugins/$plugin
elif [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then
mv ${DOKKU_LIB_ROOT}/plugins/$plugin ${DOKKU_LIB_ROOT}/plugins/available;
2015-09-19 19:05:51 -04:00
fi
done
2016-01-01 21:35:11 -05:00
echo "Enabling all core plugins"
find ${DOKKU_LIB_ROOT}/core-plugins/available -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do
if [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then
ln -s ${DOKKU_LIB_ROOT}/core-plugins/available/$plugin ${DOKKU_LIB_ROOT}/plugins/available/$plugin;
PLUGIN_PATH=${DOKKU_LIB_ROOT}/core-plugins plugn enable $plugin
PLUGIN_PATH=${DOKKU_LIB_ROOT}/plugins plugn enable $plugin
2015-09-19 19:05:51 -04:00
fi
done
find -L ${DOKKU_LIB_ROOT} -type l -delete
chown dokku:dokku -R ${DOKKU_LIB_ROOT}/plugins ${DOKKU_LIB_ROOT}/core-plugins
2015-09-19 19:05:51 -04:00
echo "Ensure proper sshcommand path"
echo '/usr/bin/dokku' > "${DOKKU_ROOT}/.sshcommand"
if [[ -f .ssh/authorized_keys ]]; then
sed -i.bak 's#/usr/local/bin/dokku#/usr/bin/dokku#' "${DOKKU_ROOT}/.ssh/authorized_keys"
rm "${DOKKU_ROOT}/.ssh/authorized_keys"
fi
2016-01-01 21:35:11 -05:00
echo "Install all core plugins"
2015-09-08 12:14:57 -07:00
dokku plugin:install --core
2015-09-19 19:05:51 -04:00
rm -f ${DOKKU_ROOT}/VERSION
cp ${DOKKU_LIB_ROOT}/STABLE_VERSION ${DOKKU_ROOT}/VERSION
if [[ -f /etc/nginx/conf.d/dokku-installer.conf ]]; then
echo "Setting up dokku-installer"
/usr/share/dokku/contrib/dokku-installer.py onboot
if command -v systemctl &>/dev/null; then
echo "Enabling dokku-installer"
systemctl enable dokku-installer
fi
2016-01-02 04:31:48 -05:00
installer_status="$(service dokku-installer status 2> /dev/null || true)"
if echo $installer_status | grep -Eq "(inactive|waiting)" > /dev/null; then
echo "Starting dokku-installer"
service dokku-installer start || echo "Unable to start dokku-installer"
fi
fi
db_get "dokku/web_config"
if [ "$RET" = "true" ]; then
db_stop
exit 0
fi
db_get "dokku/vhost_enable"
if [ "$RET" = "true" ]; then
2015-09-08 12:14:57 -07:00
db_get "dokku/hostname"
echo "$RET" > "${DOKKU_ROOT}/VHOST"
else
rm -f "${DOKKU_ROOT}/VHOST"
fi
db_get "dokku/hostname"
echo "$RET" > "${DOKKU_ROOT}/HOSTNAME"
if [ -z "${DEBCONF_RECONFIGURE}" ]; then
db_get "dokku/key_file"
if [ -f "$RET" ]; then
call-sshcommand acl-add dokku default < "$RET" || true
fi
fi
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
db_stop
exit 0