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
|
|
|
|
|
. /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
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-22 20:25:22 -05:00
|
|
|
setup-docker-live-restore() {
|
|
|
|
|
# skip if running in docker-based installation
|
|
|
|
|
if [[ "$DOKKU_INIT_SYSTEM" == "sv" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# allow disabling via /etc/default/dokku
|
|
|
|
|
if [[ "$DOKKU_LIVE_RESTORE" == "false" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
live_restore="$(docker info --format '{{ .LiveRestoreEnabled }}' || true)"
|
|
|
|
|
if [ "$live_restore" = "true" ]; then
|
|
|
|
|
echo "Docker live-restore is already enabled"
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Enabling docker live-restore"
|
|
|
|
|
if [[ ! -f /etc/docker/daemon.json ]]; then
|
|
|
|
|
echo "{}" >/etc/docker/daemon.json
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
config="$(jq '. + {"live-restore": true}' /etc/docker/daemon.json)"
|
|
|
|
|
echo "$config" >/etc/docker/daemon.json
|
|
|
|
|
if command -v systemctl &>/dev/null; then
|
|
|
|
|
if ! systemctl reload docker; then
|
|
|
|
|
echo "Unable to reload docker, please reload manually" 1>&2
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "Unable to reload docker, please reload manually" 1>&2
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 15:18:00 -04:00
|
|
|
setup-user() {
|
|
|
|
|
echo "Setting up dokku user"
|
|
|
|
|
call-sshcommand create dokku /usr/bin/dokku
|
2020-02-17 05:59:52 -05:00
|
|
|
grep -i -E "^docker" /etc/group || groupadd docker
|
2019-08-08 15:18:00 -04:00
|
|
|
usermod -aG docker dokku
|
|
|
|
|
mkdir -p "$DOKKU_ROOT/.ssh" "$DOKKU_ROOT/.dokkurc"
|
|
|
|
|
touch "$DOKKU_ROOT/.ssh/authorized_keys"
|
|
|
|
|
chown -R dokku:dokku "$DOKKU_ROOT/.ssh" "${DOKKU_ROOT}/.dokkurc"
|
|
|
|
|
}
|
2015-01-11 18:38:51 -05:00
|
|
|
|
2019-08-08 15:18:00 -04:00
|
|
|
setup-storage() {
|
|
|
|
|
echo "Setting up storage directories"
|
|
|
|
|
mkdir -p "${DOKKU_LIB_ROOT}/data" "${DOKKU_LIB_ROOT}/data/storage"
|
|
|
|
|
chown dokku:dokku "${DOKKU_LIB_ROOT}/data"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setup-plugins() {
|
2021-05-23 16:56:39 -04:00
|
|
|
echo "Deleting invalid plugins"
|
|
|
|
|
if [ -f "${DOKKU_LIB_ROOT}/core-plugins/available/" ]; then
|
|
|
|
|
find "${DOKKU_LIB_ROOT}/core-plugins/available/" -type d -empty -delete
|
|
|
|
|
fi
|
|
|
|
|
if [ -f "${DOKKU_LIB_ROOT}/core-plugins/enabled/" ]; then
|
|
|
|
|
find "${DOKKU_LIB_ROOT}/core-plugins/enabled/" -type d -empty -delete
|
|
|
|
|
fi
|
|
|
|
|
if [ -f "${DOKKU_LIB_ROOT}/plugins/available/" ]; then
|
|
|
|
|
find "${DOKKU_LIB_ROOT}/plugins/available/" -type d -empty -delete
|
|
|
|
|
fi
|
|
|
|
|
if [ -f "${DOKKU_LIB_ROOT}/plugins/enabled/" ]; then
|
|
|
|
|
find "${DOKKU_LIB_ROOT}/plugins/enabled/" -type d -empty -delete
|
|
|
|
|
fi
|
|
|
|
|
|
2019-08-08 15:18:00 -04:00
|
|
|
echo "Setting up plugin directories"
|
|
|
|
|
# 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"
|
|
|
|
|
|
|
|
|
|
echo "Migrating old plugins"
|
|
|
|
|
find ${DOKKU_LIB_ROOT}/plugins/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do
|
|
|
|
|
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
|
2019-05-13 02:59:41 -04:00
|
|
|
fi
|
2019-08-08 15:18:00 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
db_get "dokku/nginx_enable"
|
|
|
|
|
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 [ "$plugin" = "nginx-vhosts" ] && [ "$RET" = "false" ]; then
|
|
|
|
|
echo "Skipping enable of nginx-vhosts plugin"
|
|
|
|
|
continue
|
|
|
|
|
elif [ ! -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"
|
2016-06-09 12:40:01 -04:00
|
|
|
fi
|
2019-08-08 15:18:00 -04:00
|
|
|
done
|
2023-12-25 14:29:11 -05:00
|
|
|
find -L "${DOKKU_LIB_ROOT}/core-plugins" -type l -delete
|
|
|
|
|
find -L "${DOKKU_LIB_ROOT}/plugins" -type l -delete
|
2019-08-08 15:18:00 -04:00
|
|
|
chown dokku:dokku -R "${DOKKU_LIB_ROOT}/plugins" "${DOKKU_LIB_ROOT}/core-plugins"
|
2016-06-09 12:40:01 -04:00
|
|
|
|
2019-08-08 15:18:00 -04:00
|
|
|
echo "Install all core plugins"
|
|
|
|
|
dokku plugin:install --core
|
|
|
|
|
}
|
2015-09-19 19:05:51 -04:00
|
|
|
|
2019-08-08 15:18:00 -04:00
|
|
|
setup-sshcommand() {
|
|
|
|
|
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
|
|
|
|
|
}
|
2015-01-12 01:54:14 -05:00
|
|
|
|
2019-08-08 15:18:00 -04:00
|
|
|
dpkg-handling() {
|
|
|
|
|
if [ -f "${DOKKU_ROOT}/VHOST" ]; then
|
|
|
|
|
echo "VHOST file detected, skipping modification"
|
|
|
|
|
else
|
|
|
|
|
db_get "dokku/vhost_enable"
|
2015-05-03 22:21:32 +02:00
|
|
|
if [ "$RET" = "true" ]; then
|
2019-08-08 15:18:00 -04:00
|
|
|
db_get "dokku/hostname"
|
|
|
|
|
echo "Setting VHOST contents to $RET"
|
|
|
|
|
echo "$RET" >"${DOKKU_ROOT}/VHOST"
|
2022-05-10 12:44:01 -04:00
|
|
|
chown dokku:dokku "${DOKKU_ROOT}/VHOST"
|
2015-05-03 22:21:32 +02:00
|
|
|
fi
|
2019-08-08 15:18:00 -04:00
|
|
|
fi
|
2015-05-03 22:21:32 +02:00
|
|
|
|
2019-08-08 15:18:00 -04:00
|
|
|
if [ -z "${DEBCONF_RECONFIGURE}" ]; then
|
|
|
|
|
db_get "dokku/key_file"
|
|
|
|
|
if [ -f "$RET" ]; then
|
|
|
|
|
call-sshcommand acl-add dokku default <"$RET" || true
|
2015-05-03 22:21:32 +02:00
|
|
|
fi
|
2019-08-08 15:18:00 -04:00
|
|
|
fi
|
|
|
|
|
}
|
2017-10-02 11:40:31 -04:00
|
|
|
|
2019-08-08 15:18:00 -04:00
|
|
|
case "$1" in
|
|
|
|
|
abort-upgrade | abort-remove | abort-deconfigure) ;;
|
2015-05-03 22:21:32 +02:00
|
|
|
|
2022-12-26 16:41:45 -05:00
|
|
|
configure)
|
2019-08-08 15:18:00 -04:00
|
|
|
mandb
|
|
|
|
|
[ ! -x /usr/bin/docker.io ] || ln -sf /usr/bin/docker.io /usr/local/bin/docker
|
|
|
|
|
|
|
|
|
|
setup-user
|
|
|
|
|
setup-storage
|
2021-08-07 19:25:01 -04:00
|
|
|
|
|
|
|
|
dpkg-handling
|
2019-08-08 15:18:00 -04:00
|
|
|
setup-plugins
|
|
|
|
|
setup-sshcommand
|
2025-11-22 20:25:22 -05:00
|
|
|
setup-docker-live-restore
|
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
|