2016-02-19 04:35:43 -05:00
#!/usr/bin/env bash
2019-01-07 01:04:17 -05:00
set -eo pipefail
[ [ $TRACE ] ] && set -x
2016-02-19 04:35:43 -05:00
2014-06-25 18:11:49 -04:00
# A script to bootstrap dokku.
2024-08-25 23:30:41 -04:00
# It expects to be run on Ubuntu 20.04/22.04/24.04 via 'sudo`
2015-04-08 19:21:02 -04:00
# If installing a tag higher than 0.3.13, it may install dokku via a package (so long as the package is higher than 0.3.13)
2021-06-24 22:42:02 +01:00
# It checks out the dokku source code from GitHub into ~/dokku and then runs 'make install' from dokku source.
2014-06-25 18:11:49 -04:00
2016-02-19 04:35:43 -05:00
# We wrap this whole script in functions, so that we won't execute
2015-08-04 15:09:37 +10:00
# until the entire script is downloaded.
2015-11-09 22:52:58 -06:00
# That's good because it prevents our output overlapping with wget's.
2015-08-04 15:09:37 +10:00
# It also means that we can't run a partially downloaded script.
2024-08-25 23:30:41 -04:00
SUPPORTED_VERSIONS = "Debian [10, 11, 12], Ubuntu [20.04, 22.04, 24.04]"
2020-02-28 05:39:29 -05:00
2020-02-28 05:36:17 -05:00
log-fail( ) {
declare desc = "log fail formatter"
echo " $@ " 1>& 2
exit 1
}
2016-02-19 04:35:43 -05:00
ensure-environment( ) {
2016-04-16 17:46:07 -04:00
local FREE_MEMORY
2021-01-17 14:41:49 -05:00
if [ [ -z " $DOKKU_TAG " ] ] ; then
2021-01-16 23:56:36 +00:00
echo " Preparing to install $DOKKU_REPO ... "
else
echo " Preparing to install $DOKKU_TAG from $DOKKU_REPO ... "
fi
2015-08-04 15:09:37 +10:00
2023-07-01 03:48:45 -04:00
hostname -f & >/dev/null || {
2020-02-28 05:36:17 -05:00
log-fail "This installation script requires that you have a hostname set for the instance. Please set a hostname for 127.0.0.1 in your /etc/hosts"
2016-02-19 04:35:43 -05:00
}
2016-04-16 17:46:07 -04:00
FREE_MEMORY = $( grep MemTotal /proc/meminfo | awk '{print $2}' )
if [ [ " $FREE_MEMORY " -lt 1003600 ] ] ; then
echo "For dokku to build containers, it is strongly suggested that you have 1024 megabytes or more of free memory"
2021-02-28 01:18:33 -05:00
echo "If necessary, please consult this document to setup swap: https://dokku.com/docs/getting-started/advanced-installation/#vms-with-less-than-1-gb-of-memory"
2016-04-16 17:46:07 -04:00
fi
2016-02-19 04:35:43 -05:00
}
2013-06-09 16:08:35 -07:00
2016-02-19 04:35:43 -05:00
install-requirements( ) {
echo "--> Ensuring we have the proper dependencies"
2016-09-23 16:56:22 +03:00
case " $DOKKU_DISTRO " in
2019-01-22 13:30:59 -05:00
debian)
2021-07-11 20:58:26 -04:00
if ! dpkg -l | grep -q gpg-agent; then
apt-get update -qq >/dev/null
apt-get -qq -y --no-install-recommends install gpg-agent
fi
2019-01-22 13:30:59 -05:00
if ! dpkg -l | grep -q software-properties-common; then
apt-get update -qq >/dev/null
2021-01-17 16:09:58 -05:00
apt-get -qq -y --no-install-recommends install software-properties-common
2019-01-22 13:30:59 -05:00
fi
; ;
ubuntu)
2021-07-11 20:58:26 -04:00
if ! dpkg -l | grep -q gpg-agent; then
apt-get update -qq >/dev/null
apt-get -qq -y --no-install-recommends install gpg-agent
fi
2019-01-06 20:49:08 -05:00
if ! dpkg -l | grep -q software-properties-common; then
2019-01-07 01:04:17 -05:00
apt-get update -qq >/dev/null
2021-01-17 16:09:58 -05:00
apt-get -qq -y --no-install-recommends install software-properties-common
2019-01-06 20:49:08 -05:00
fi
2022-05-21 02:47:06 -04:00
add-apt-repository -y universe >/dev/null
2019-01-07 01:04:17 -05:00
apt-get update -qq >/dev/null
2016-09-23 16:56:22 +03:00
; ;
esac
2016-02-19 04:35:43 -05:00
}
2013-09-20 16:05:43 +02:00
2016-02-19 04:35:43 -05:00
install-dokku( ) {
2021-03-22 17:32:38 -04:00
if ! command -v dokku & >/dev/null; then
echo "--> Note: Installing dokku for the first time will result in removal of"
echo " files in the nginx 'sites-enabled' directory. Please manually"
echo " restore any files that may be removed after the installation and"
echo " web setup is complete."
echo ""
echo " Installation will continue in 10 seconds."
sleep 10
fi
2016-02-19 04:35:43 -05:00
if [ [ -n $DOKKU_BRANCH ] ] ; then
install-dokku-from-source " origin/ $DOKKU_BRANCH "
elif [ [ -n $DOKKU_TAG ] ] ; then
2019-01-07 01:04:17 -05:00
local DOKKU_SEMVER = " ${ DOKKU_TAG //v/ } "
2016-02-19 04:35:43 -05:00
major = $( echo " $DOKKU_SEMVER " | awk '{split($0,a,"."); print a[1]}' )
minor = $( echo " $DOKKU_SEMVER " | awk '{split($0,a,"."); print a[2]}' )
patch = $( echo " $DOKKU_SEMVER " | awk '{split($0,a,"."); print a[3]}' )
2018-01-13 18:15:56 -05:00
use_plugin = false
# 0.4.0 implemented a `plugin` plugin
if [ [ " $major " -eq "0" ] ] && [ [ " $minor " -ge "4" ] ] && [ [ " $patch " -ge "0" ] ] ; then
use_plugin = true
elif [ [ " $major " -ge "1" ] ] ; then
use_plugin = true
fi
2016-02-19 04:35:43 -05:00
# 0.3.13 was the first version with a debian package
if [ [ " $major " -eq "0" ] ] && [ [ " $minor " -eq "3" ] ] && [ [ " $patch " -ge "13" ] ] ; then
install-dokku-from-package " $DOKKU_SEMVER "
echo "--> Running post-install dependency installation"
dokku plugins-install-dependencies
2018-01-13 18:15:56 -05:00
elif [ [ " $use_plugin " = = "true" ] ] ; then
2016-02-19 04:35:43 -05:00
install-dokku-from-package " $DOKKU_SEMVER "
echo "--> Running post-install dependency installation"
sudo -E dokku plugin:install-dependencies --core
else
install-dokku-from-source " $DOKKU_TAG "
fi
else
install-dokku-from-package
echo "--> Running post-install dependency installation"
sudo -E dokku plugin:install-dependencies --core
fi
2015-10-17 16:39:43 -04:00
}
2016-02-19 04:35:43 -05:00
install-dokku-from-source( ) {
local DOKKU_CHECKOUT = " $1 "
2016-09-23 16:56:22 +03:00
if ! command -v apt-get & >/dev/null; then
2021-02-28 01:18:33 -05:00
log-fail "This installation script requires apt-get. For manual installation instructions, consult https://dokku.com/docs/getting-started/advanced-installation/"
2016-09-23 16:56:22 +03:00
fi
2021-01-17 16:09:58 -05:00
apt-get -qq -y --no-install-recommends install sudo git make software-properties-common
2015-04-08 19:21:02 -04:00
cd /root
2015-09-14 21:20:35 -07:00
if [ [ ! -d /root/dokku ] ] ; then
2016-02-19 04:35:43 -05:00
git clone " $DOKKU_REPO " /root/dokku
2015-04-08 19:21:02 -04:00
fi
2013-11-20 23:39:09 +00:00
2015-04-08 19:21:02 -04:00
cd /root/dokku
git fetch origin
2016-02-19 04:35:43 -05:00
[ [ -n $DOKKU_CHECKOUT ] ] && git checkout " $DOKKU_CHECKOUT "
2015-04-08 19:21:02 -04:00
make install
}
2016-02-19 04:35:43 -05:00
install-dokku-from-package( ) {
2016-09-23 16:56:22 +03:00
case " $DOKKU_DISTRO " in
2019-01-07 01:04:17 -05:00
debian | ubuntu)
2016-09-23 16:56:22 +03:00
install-dokku-from-deb-package " $@ "
; ;
*)
2021-02-28 01:18:33 -05:00
log-fail "Unsupported Linux distribution. For manual installation instructions, consult https://dokku.com/docs/getting-started/advanced-installation/"
2016-09-23 16:56:22 +03:00
; ;
esac
}
2018-04-07 12:59:18 -04:00
in-array( ) {
declare desc = " return true if value ( $1 ) is in list (all other arguments) "
local e
for e in " ${ @ : 2 } " ; do
[ [ " $e " = = " $1 " ] ] && return 0
done
return 1
}
2016-09-23 16:56:22 +03:00
install-dokku-from-deb-package( ) {
2016-02-19 04:35:43 -05:00
local DOKKU_CHECKOUT = " $1 "
2016-05-17 03:02:17 -04:00
local NO_INSTALL_RECOMMENDS = ${ DOKKU_NO_INSTALL_RECOMMENDS : = "" }
2018-01-13 18:19:21 -05:00
local OS_ID
2016-02-19 04:35:43 -05:00
2024-08-25 23:30:41 -04:00
if ! in-array " $DOKKU_DISTRO_VERSION " "20.04" "22.04" "24.04" "10" "11" "12" ; then
2020-02-28 05:39:29 -05:00
log-fail " Unsupported Linux distribution. Only the following versions are supported: $SUPPORTED_VERSIONS "
fi
2016-02-19 04:35:43 -05:00
if [ [ -n $DOKKU_DOCKERFILE ] ] ; then
NO_INSTALL_RECOMMENDS = " --no-install-recommends "
fi
2019-01-07 06:40:03 -05:00
if ! command -v docker & >/dev/null; then
echo "--> Installing docker"
if uname -r | grep -q linode; then
echo "--> NOTE: Using Linode? Docker may complain about missing AUFS support."
echo " You can safely ignore this warning."
2021-03-22 17:32:38 -04:00
echo ""
2019-01-07 06:40:03 -05:00
echo " Installation will continue in 10 seconds."
sleep 10
fi
export CHANNEL = stable
wget -nv -O - https://get.docker.com/ | sh
2017-04-04 14:27:09 -05:00
fi
2013-06-08 03:26:12 -07:00
2024-08-25 23:30:41 -04:00
OS_ID = " $( lsb_release -cs 2>/dev/null || echo "noble" ) "
2021-10-28 02:41:10 -04:00
if ! in-array " $DOKKU_DISTRO " "debian" "ubuntu" "raspbian" ; then
2018-04-07 12:59:18 -04:00
DOKKU_DISTRO = "ubuntu"
2024-08-25 23:30:41 -04:00
OS_ID = "noble"
2018-04-07 12:59:18 -04:00
fi
if [ [ " $DOKKU_DISTRO " = = "ubuntu" ] ] ; then
2024-08-25 23:30:41 -04:00
OS_IDS = ( "focal" "jammy" "noble" )
2018-04-07 12:59:18 -04:00
if ! in-array " $OS_ID " " ${ OS_IDS [@] } " ; then
2024-08-25 23:30:41 -04:00
OS_ID = "noble"
2018-04-07 12:59:18 -04:00
fi
elif [ [ " $DOKKU_DISTRO " = = "debian" ] ] ; then
2023-07-24 16:42:23 +02:00
OS_IDS = ( "stretch" "buster" "bullseye" "bookworm" )
2018-04-07 12:59:18 -04:00
if ! in-array " $OS_ID " " ${ OS_IDS [@] } " ; then
2021-08-19 15:15:32 +05:30
OS_ID = "bullseye"
2018-04-07 12:59:18 -04:00
fi
2021-10-28 02:41:10 -04:00
elif [ [ " $DOKKU_DISTRO " = = "raspbian" ] ] ; then
2022-02-28 17:12:58 -05:00
OS_IDS = ( "buster" "bullseye" )
2021-10-28 02:41:10 -04:00
if ! in-array " $OS_ID " " ${ OS_IDS [@] } " ; then
2022-02-28 17:12:58 -05:00
OS_ID = "bullseye"
2021-10-28 02:41:10 -04:00
fi
2018-04-07 12:59:18 -04:00
fi
2018-01-13 18:19:21 -05:00
2015-09-14 22:03:47 -07:00
echo "--> Installing dokku"
2022-07-24 11:12:16 -05:00
wget -qO- https://packagecloud.io/dokku/dokku/gpgkey | sudo tee /etc/apt/trusted.gpg.d/dokku.asc
2018-04-07 12:59:18 -04:00
echo " deb https://packagecloud.io/dokku/dokku/ $DOKKU_DISTRO / $OS_ID main " | tee /etc/apt/sources.list.d/dokku.list
2019-01-07 01:04:17 -05:00
apt-get update -qq >/dev/null
2015-04-01 13:44:49 +02:00
2019-01-07 01:04:17 -05:00
[ [ -n $DOKKU_VHOST_ENABLE ] ] && echo " dokku dokku/vhost_enable boolean $DOKKU_VHOST_ENABLE " | sudo debconf-set-selections
[ [ -n $DOKKU_HOSTNAME ] ] && echo " dokku dokku/hostname string $DOKKU_HOSTNAME " | sudo debconf-set-selections
2016-02-19 04:35:43 -05:00
[ [ -n $DOKKU_SKIP_KEY_FILE ] ] && echo " dokku dokku/skip_key_file boolean $DOKKU_SKIP_KEY_FILE " | sudo debconf-set-selections
2019-01-07 01:04:17 -05:00
[ [ -n $DOKKU_KEY_FILE ] ] && echo " dokku dokku/key_file string $DOKKU_KEY_FILE " | sudo debconf-set-selections
[ [ -n $DOKKU_NGINX_ENABLE ] ] && echo " dokku dokku/nginx_enable string $DOKKU_NGINX_ENABLE " | sudo debconf-set-selections
2016-02-19 04:35:43 -05:00
2015-04-08 19:21:02 -04:00
if [ [ -n $DOKKU_CHECKOUT ] ] ; then
2016-02-19 04:35:43 -05:00
apt-get -qq -y $NO_INSTALL_RECOMMENDS install " dokku= $DOKKU_CHECKOUT "
2015-04-08 19:21:02 -04:00
else
2016-02-19 04:35:43 -05:00
apt-get -qq -y $NO_INSTALL_RECOMMENDS install dokku
2015-04-08 19:21:02 -04:00
fi
}
2016-02-19 04:35:43 -05:00
main( ) {
2016-09-23 16:56:22 +03:00
export DOKKU_DISTRO DOKKU_DISTRO_VERSION
DOKKU_DISTRO = $( . /etc/os-release && echo " $ID " )
DOKKU_DISTRO_VERSION = $( . /etc/os-release && echo " $VERSION_ID " )
2016-02-19 04:35:43 -05:00
export DEBIAN_FRONTEND = noninteractive
export DOKKU_REPO = ${ DOKKU_REPO :- "https://github.com/dokku/dokku.git" }
2015-08-04 15:09:37 +10:00
2016-02-19 04:35:43 -05:00
ensure-environment
install-requirements
install-dokku
2021-08-07 18:34:19 -04:00
if [ [ -f /etc/update-motd.d/99-dokku ] ] ; then
/etc/update-motd.d/99-dokku || true
fi
2015-08-04 15:09:37 +10:00
}
2016-02-19 04:35:43 -05:00
main " $@ "