Setting Up Dokku via Command-Line Script

Dokku is a PAAS implementation, useful for websites, servers, or development. As it notes in its website, the installation in a Debian host running Bash is just three steps:

# only works on debian systems!
wget https://raw.githubusercontent.com/dokku/dokku/v0.5.3/bootstrap.sh
sudo DOKKU_TAG=v0.5.3 bash bootstrap.sh
# go to your server's IP and follow the web installer

The last “step” is written as a Bash comment. It states to complete the installation via a web browser. If you’re like me, this is a surprise, completely opposite of command-line driven provisioning. Using Fiddler, I conjured up a script to fix this problem. Enjoy!

(Note: I asked the question in the Dokku issue page, and the reply pointed to usingĀ debconf. You can use that. Or, you can use this script–which I think is easier.)

#
# Set up Dokku via command line

set -e

if [ "$#" -ne 1 ]; then
 echo "Try this: cat ~/.ssh/id_rsa.pub | ${0##*/} -"
 exit 1
fi

export IP=`ip route get 8.8.8.8 | awk '{print $NF; exit}'`
export KEY=$(</dev/stdin)

if [ "${KEY/ssh-rsa}" = "$KEY" ] ; then
 echo "Input is not a ssh key."
 exit 1
fi

curl "http://localhost" > /dev/null 2>&1

export FKEY=`echo -ne "$KEY" | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g'`

cat <<EOF | curl -XPOST --data @- "http://localhost/setup"
keys=$FKEY&hostname=$IP
EOF

 

Posted in Tip