From d9a989d6b05f605309d018475f263e45914e2cb6 Mon Sep 17 00:00:00 2001 From: 3onyc <3onyc@x3tech.com> Date: Sun, 3 May 2015 22:21:32 +0200 Subject: [PATCH] Use debconf to allow for command-line or unattended installation --- AUTHORS | 1 + debian/config | 21 +++++++++++++++++++++ debian/postinst | 25 +++++++++++++++++++++++++ debian/preinst | 17 +++++++++++++++++ debian/templates | 19 +++++++++++++++++++ docs/getting-started/install/debian.md | 21 +++++++++++++++++++++ 6 files changed, 104 insertions(+) create mode 100755 debian/config create mode 100644 debian/templates diff --git a/AUTHORS b/AUTHORS index 374428a14..2c4693bd6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,7 @@ # If you're submitting a patch, please add your name here in alphabetical order as part of the patch. # This file lists all individuals having contributed content to the repository. # +3onyc <3onyc@x3tech.com> Alexander Alexander Beletsky Alexis Gavoty diff --git a/debian/config b/debian/config new file mode 100755 index 000000000..8b294e076 --- /dev/null +++ b/debian/config @@ -0,0 +1,21 @@ +#!/bin/sh -e + +. /usr/share/debconf/confmodule + +readonly ACTION="${1:-configure}" +readonly VERSION="${2:-dev}" + +db_input "high" "dokku/web_config" || true +db_go || true + +db_get "dokku/web_config" +if [ $RET = "true" ]; then + exit 0 +fi + +db_input "high" "dokku/hostname" || true +db_input "high" "dokku/vhost_enable" || true +if [ "$ACTION" != "reconfigure" ]; then + db_input "high" "dokku/key_file" || true +fi +db_go || true diff --git a/debian/postinst b/debian/postinst index 231c1a20d..d9d94b818 100755 --- a/debian/postinst +++ b/debian/postinst @@ -1,6 +1,10 @@ #!/bin/sh set -e +. /usr/share/debconf/confmodule + +readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}" + case "$1" in abort-upgrade|abort-remove|abort-deconfigure) ;; @@ -19,6 +23,27 @@ case "$1" in if [ -f /etc/init/dokku-installer.conf ] && service dokku-installer status 2> /dev/null | grep waiting; then sudo service dokku-installer start fi + + db_get "dokku/web_config" + if [ "$RET" = "true" ]; then + exit 0 + fi + + db_get "dokku/vhost_enable" + if [ "$RET" = "true" ]; then + 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" + sshcommand acl-add dokku default < "$RET" + fi ;; *) diff --git a/debian/preinst b/debian/preinst index 198b8aee6..998338eb9 100755 --- a/debian/preinst +++ b/debian/preinst @@ -1,8 +1,25 @@ #!/bin/sh set -e +. /usr/share/debconf/confmodule + case "$1" in install) + if [ -z "${DEBCONF_RECONFIGURE}" ]; then + db_get "dokku/key_file" + if [ ! -f "$RET" ]; then + echo "Error: keyfile '$RET' not found." + echo " you can enter a new keyfile path when you restart the installation." + db_reset "dokku/key_file" + exit 1 + fi + fi + + db_get "dokku/web_config" + if [ "$RET" = "false" ]; then + exit 0 + fi + INIT_CONF="/etc/init/dokku-installer.conf" NGINX_CONF="/etc/nginx/conf.d/dokku-installer.conf" diff --git a/debian/templates b/debian/templates new file mode 100644 index 000000000..e63a3e859 --- /dev/null +++ b/debian/templates @@ -0,0 +1,19 @@ +Template: dokku/web_config +Description: Use the web-based config page? +Type: boolean +Default: true + +Template: dokku/vhost_enable +Description: Use vhost based deployments? +Type: boolean +Default: false + +Template: dokku/hostname +Description: Machine's hostname or IP +Type: string +Default: dokku.me + +Template: dokku/key_file +Description: Keyfile for initial user +Type: string +Default: /root/.ssh/id_rsa.pub diff --git a/docs/getting-started/install/debian.md b/docs/getting-started/install/debian.md index 42374c7ef..40d4748a8 100644 --- a/docs/getting-started/install/debian.md +++ b/docs/getting-started/install/debian.md @@ -13,3 +13,24 @@ sudo apt-get update > /dev/null sudo apt-get install -qq -y linux-image-extra-`uname -r` apt-transport-https sudo apt-get install -qq -y dokku ``` + +## Unattended installation + +In case you want to perform an unattended installation of dokku, this is made possible through [debconf](https://en.wikipedia.org/wiki/Debconf_%28software_package%29), which allows you to configure a package before installing it. + +You can set any of the below options through the `debconf-set-selections` command, for example to enable vhost-based deployments: + +```bash +echo "dokku dokku/vhost_enable boolean true" | debconf-set-selections +``` + +After setting the desired options, proceed with the installation as described above. + +### debconf options + +| Name | Type | Default | Description | +| ------------------ | ------- | --------------------- | ------------------------------------------------------------------------ | +| dokku/web_config | boolean | true | Use web-based config for below options | +| dokku/vhost_enable | boolean | false | Use vhost-based deployments (e.g. .dokku.me) | +| dokku/hostname | string | dokku.me | Hostname, used as vhost domain and for showing app URL after deploy | +| dokku/key_file | string | /root/.ssh/id_rsa.pub | SSH key to add to the Dokku user (Will be ignored on `dpkg-reconfigure`) |