#!/bin/bash set -eo pipefail log-info() { declare desc="Log info formatter" echo " $*" 1>&2 } log-fail() { declare desc="Log fail formatter" echo "! $*" 1>&2 exit 1 } support-userns() { chown 0:0 /usr/bin/sudo chmod 4755 /usr/bin/sudo chown 0:0 /usr/lib/sudo/sudoers.so chown -R 0:0 /etc/sudoers chown -R 0:0 /etc/sudoers.d chown -R 0:0 /run/sshd } main() { local NGINX_ROOT support-userns if [[ ! -d /mnt/dokku ]]; then log-info "Creating missing /mnt/dokku" mkdir -p /mnt/dokku fi directories=("/etc/ssh" "/home/dokku" "/var/lib/dokku/config" "/var/lib/dokku/data") for dir in "${directories[@]}"; do if [[ ! -e "$dir" ]]; then log-info "Copying ${dir} skel into place" mkdir -p "/mnt/dokku${dir}" rsync -a "/skel${dir}/" "${dir}/" || log-fail "Unable to copy ${dir} skel into place" fi # chown mount directories to "dokku:dokku" if [[ "$dir" != "/etc/ssh" ]]; then find "$dir" -print0 | xargs -0 chown -h dokku:dokku fi done if [[ -f /mnt/dokku/plugin-list ]]; then while read line; do dokku plugin:install "$(echo "$line" | awk '{print $2}')" "$(echo "$line" | cut -d':' -f1)" done "/home/dokku/.dokkurc/DOCKER_BIN" fi if [[ -n "$DOKKU_HOST_ROOT" ]]; then touch /etc/default/dokku echo "export DOKKU_HOST_ROOT=$DOKKU_HOST_ROOT" >>/etc/default/dokku chown dokku:dokku /etc/default/dokku fi NGINX_ROOT="/etc/nginx" if [[ -x /usr/bin/openresty ]]; then NGINX_ROOT="/usr/local/openresty/nginx/conf" rm -rf /etc/runit/runsvdir/default/nginx else rm -rf /etc/runit/runsvdir/default/openresty fi if [[ ! -f "/mnt/dokku${NGINX_ROOT}/dhparam.pem" ]]; then mkdir -p "/mnt/dokku${NGINX_ROOT}" openssl dhparam -out "/mnt/dokku${NGINX_ROOT}/dhparam.pem" 2048 fi mkdir -p "${NGINX_ROOT}/conf.d" cp -f "/mnt/dokku${NGINX_ROOT}/dhparam.pem" "${NGINX_ROOT}/dhparam.pem" chown root:root "${NGINX_ROOT}/dhparam.pem" chown root:root "${NGINX_ROOT}/conf.d" } main "$@"