2015-12-31 08:22:06 -05:00
|
|
|
#!/bin/bash
|
2019-01-07 01:04:17 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $TRACE ]] && set -x
|
2015-01-11 18:38:51 -05:00
|
|
|
|
2016-06-09 12:48:54 -04:00
|
|
|
if [[ -e /usr/share/debconf/confmodule ]]; then
|
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
|
. /usr/share/debconf/confmodule
|
|
|
|
|
fi
|
2015-05-03 22:21:32 +02:00
|
|
|
|
2018-04-01 17:48:06 -04:00
|
|
|
if [[ -r /etc/default/dokku ]]; then
|
2018-02-24 16:43:32 -05:00
|
|
|
# shellcheck disable=SC1091
|
2018-04-01 17:48:06 -04:00
|
|
|
source /etc/default/dokku
|
2018-02-24 16:43:32 -05:00
|
|
|
fi
|
|
|
|
|
|
2015-05-03 22:21:32 +02:00
|
|
|
readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}"
|
2015-12-23 20:02:56 -05:00
|
|
|
readonly DOKKU_LIB_ROOT="${DOKKU_LIB_PATH:-/var/lib/dokku}"
|
2015-05-03 22:21:32 +02:00
|
|
|
|
2016-06-09 12:40:01 -04:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-11 18:38:51 -05:00
|
|
|
case "$1" in
|
2019-01-07 01:04:17 -05:00
|
|
|
abort-upgrade | abort-remove | abort-deconfigure) ;;
|
2015-01-11 18:38:51 -05:00
|
|
|
|
2019-01-07 01:04:17 -05:00
|
|
|
\
|
|
|
|
|
configure)
|
2015-01-11 18:38:51 -05:00
|
|
|
mandb
|
|
|
|
|
[ ! -x /usr/bin/docker.io ] || ln -sf /usr/bin/docker.io /usr/local/bin/docker
|
2019-05-13 02:59:41 -04:00
|
|
|
if [[ -f /sbin/modprobe ]]; then
|
|
|
|
|
modprobe aufs || echo "WARNING: Restart server to finish installing dokku!"
|
|
|
|
|
fi
|
2016-06-09 12:40:01 -04:00
|
|
|
call-sshcommand create dokku /usr/bin/dokku
|
|
|
|
|
|
2015-01-11 18:38:51 -05:00
|
|
|
egrep -i "^docker" /etc/group || groupadd docker
|
|
|
|
|
usermod -aG docker dokku
|
2019-06-11 11:32:41 -07:00
|
|
|
mkdir -p ${DOKKU_ROOT}/.dokkurc
|
2015-09-19 19:05:51 -04:00
|
|
|
|
2016-04-08 11:22:43 -04:00
|
|
|
echo "Setting up storage directories"
|
|
|
|
|
mkdir -p ${DOKKU_LIB_ROOT}/data ${DOKKU_LIB_ROOT}/data/storage
|
2017-04-02 15:07:18 -04:00
|
|
|
chown dokku:dokku ${DOKKU_LIB_ROOT}/data ${DOKKU_LIB_ROOT}/data/storage
|
2016-04-08 11:22:43 -04:00
|
|
|
|
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`
|
2015-12-23 20:02:56 -05:00
|
|
|
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"
|
2015-12-23 20:02:56 -05:00
|
|
|
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
|
2015-12-23 20:02:56 -05:00
|
|
|
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
|
2019-01-07 01:04:17 -05:00
|
|
|
mv ${DOKKU_LIB_ROOT}/plugins/$plugin ${DOKKU_LIB_ROOT}/plugins/available
|
2015-09-19 19:05:51 -04:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2018-09-30 15:33:42 -04:00
|
|
|
db_get "dokku/nginx_enable"
|
2016-01-01 21:35:11 -05:00
|
|
|
echo "Enabling all core plugins"
|
2015-12-23 20:02:56 -05:00
|
|
|
find ${DOKKU_LIB_ROOT}/core-plugins/available -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do
|
2018-09-30 15:33:42 -04:00
|
|
|
if [ "$plugin" = "nginx-vhosts" ] && [ "$RET" = "false" ]; then
|
|
|
|
|
echo "Skipping enable of nginx-vhosts plugin"
|
|
|
|
|
continue
|
|
|
|
|
elif [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
ln -s ${DOKKU_LIB_ROOT}/core-plugins/available/$plugin ${DOKKU_LIB_ROOT}/plugins/available/$plugin
|
2015-12-23 20:02:56 -05:00
|
|
|
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
|
2016-03-26 19:23:31 -04:00
|
|
|
find -L ${DOKKU_LIB_ROOT} -type l -delete
|
2015-12-23 20:02:56 -05:00
|
|
|
chown dokku:dokku -R ${DOKKU_LIB_ROOT}/plugins ${DOKKU_LIB_ROOT}/core-plugins
|
2015-09-19 19:05:51 -04:00
|
|
|
|
2016-06-09 12:40:01 -04:00
|
|
|
echo "Ensure proper sshcommand path"
|
2019-01-07 01:04:17 -05:00
|
|
|
echo '/usr/bin/dokku' >"${DOKKU_ROOT}/.sshcommand"
|
2016-06-09 12:40:01 -04:00
|
|
|
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
|
|
|
|
2015-12-23 03:59:10 -05:00
|
|
|
rm -f ${DOKKU_ROOT}/VERSION
|
2015-12-23 20:02:56 -05:00
|
|
|
cp ${DOKKU_LIB_ROOT}/STABLE_VERSION ${DOKKU_ROOT}/VERSION
|
2015-01-12 01:54:14 -05:00
|
|
|
|
2016-01-01 21:37:42 -05:00
|
|
|
if [[ -f /etc/nginx/conf.d/dokku-installer.conf ]]; then
|
|
|
|
|
echo "Setting up dokku-installer"
|
2016-01-01 22:02:40 -05:00
|
|
|
/usr/share/dokku/contrib/dokku-installer.py onboot
|
2016-01-01 21:37:42 -05:00
|
|
|
|
2016-01-02 02:29:57 -05:00
|
|
|
if command -v systemctl &>/dev/null; then
|
2016-01-02 03:53:27 -05:00
|
|
|
echo "Enabling dokku-installer"
|
|
|
|
|
systemctl enable dokku-installer
|
2016-01-02 02:29:57 -05:00
|
|
|
fi
|
|
|
|
|
|
2019-01-07 01:04:17 -05:00
|
|
|
installer_status="$(service dokku-installer status 2>/dev/null || true)"
|
|
|
|
|
if echo $installer_status | grep -Eq "(inactive|waiting)" >/dev/null; then
|
2016-01-02 03:53:27 -05:00
|
|
|
echo "Starting dokku-installer"
|
|
|
|
|
service dokku-installer start || echo "Unable to start dokku-installer"
|
2016-01-02 02:29:57 -05:00
|
|
|
fi
|
2015-01-12 01:54:14 -05:00
|
|
|
fi
|
2015-05-03 22:21:32 +02:00
|
|
|
|
|
|
|
|
db_get "dokku/web_config"
|
|
|
|
|
if [ "$RET" = "true" ]; then
|
2015-12-31 08:54:02 -05:00
|
|
|
db_stop
|
2015-05-03 22:21:32 +02:00
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2017-10-02 11:48:29 -04:00
|
|
|
if [ -f "${DOKKU_ROOT}/VHOST" ]; then
|
|
|
|
|
echo "VHOST file detected, skipping modification"
|
|
|
|
|
else
|
2017-10-02 17:37:17 +02:00
|
|
|
db_get "dokku/vhost_enable"
|
|
|
|
|
if [ "$RET" = "true" ]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
db_get "dokku/hostname"
|
|
|
|
|
echo "Setting VHOST contents to $RET"
|
|
|
|
|
echo "$RET" >"${DOKKU_ROOT}/VHOST"
|
2017-10-02 17:37:17 +02:00
|
|
|
fi
|
2015-05-03 22:21:32 +02:00
|
|
|
fi
|
2017-10-02 11:40:31 -04:00
|
|
|
|
2015-05-03 22:21:32 +02:00
|
|
|
db_get "dokku/hostname"
|
2019-01-07 01:04:17 -05:00
|
|
|
echo "$RET" >"${DOKKU_ROOT}/HOSTNAME"
|
2015-05-03 22:21:32 +02:00
|
|
|
|
|
|
|
|
if [ -z "${DEBCONF_RECONFIGURE}" ]; then
|
|
|
|
|
db_get "dokku/key_file"
|
2015-12-07 11:52:14 -05:00
|
|
|
if [ -f "$RET" ]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
call-sshcommand acl-add dokku default <"$RET" || true
|
2015-12-07 11:52:14 -05:00
|
|
|
fi
|
2015-05-03 22:21:32 +02:00
|
|
|
fi
|
2015-01-11 18:38:51 -05:00
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
echo "postinst called with unknown argument \`$1'" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2015-12-31 08:54:02 -05:00
|
|
|
db_stop
|
2015-01-11 18:38:51 -05:00
|
|
|
exit 0
|