Created
July 11, 2016 16:17
-
-
Save dmmfll/109f9134c2f0a3575953361483be559a to your computer and use it in GitHub Desktop.
an example of an unattended dokku install script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# <UDF name="ssh_key" default="" label="Public SSH Key for user" /> | |
# <UDF name="username" default="" label="default username" /> | |
# <UDF name="hostname" default="" label="default username" /> | |
function logit { | |
# Simple logging function that prepends an easy-to-find marker '=> ' and a timestamp to a message | |
TIMESTAMP=$(date -u +'%m/%d %H:%M:%S') | |
MSG="=> ${TIMESTAMP} $1" | |
echo ${MSG} | |
} | |
exec &> /root/setup-linodku.log | |
function add_user { | |
logit "starting creation of user '${USERNAME}'" | |
HOME=/home/"${USERNAME}" | |
logit "adding user ${USERNAME}..." | |
# the value after -p is encrypted password | |
useradd $USERNAME -m -s /bin/bash -p PNDaLfjXH1fOc | |
logit "making user superuser..." | |
usermod -a -G sudo $USERNAME | |
logit "creating .ssh directory..." | |
mkdir $HOME/.ssh | |
chown $USERNAME $HOME/.ssh | |
logit "adding public key to authorized_keys..." | |
echo "${SSH_KEY}" >> $HOME/.ssh/authorized_keys | |
echo "${SSH_KEY}" >> $HOME/.ssh/id_rsa.pub | |
} | |
function set_passwordless_ssh { | |
logit "making login with password impossible..." | |
# warning: there is also a /etc/ssh/ssh_config file, ignore it | |
passwordfile=/etc/ssh/sshd_config | |
# logit "Turn off password authentication and root login for SSH" | |
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' "$passwordfile" | |
service ssh restart | |
} | |
function set_hostname { | |
logit "setting hostname to ${HOSTNAME}..." | |
if [ -n "${HOSTNAME}" ]; then | |
echo $HOSTNAME > /etc/hostname | |
echo $IPADDR $FQDN $HOSTNAME >> /etc/hosts | |
else | |
system_primary_ip > /etc/hostname | |
echo "$(system_primary_ip) localhost" >> /etc/hosts | |
fi | |
IPADDR=$(/sbin/ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://') | |
hostname -F /etc/hostname | |
} | |
function install_prerequisites { | |
sudo apt-get install -qq -y curl > /dev/null 2>&1 | |
logit "installing docker gpg key..." | |
curl -sSL https://get.docker.com/gpg 2> /dev/null | apt-key add - > /dev/null 2>&1 | |
logit "installing dokku gpg key..." | |
curl -sSL https://packagecloud.io/gpg.key 2> /dev/null | apt-key add - > /dev/null 2>&1 | |
logit "running apt-get update..." | |
sudo apt-get update > /dev/null | |
logit "installing pre-requisites..." | |
sudo apt-get install -qq -y apt-transport-https > /dev/null 2>&1 | |
logit "setting up apt repositories..." | |
echo "deb https://get.docker.io/ubuntu docker main" > /etc/apt/sources.list.d/docker.list | |
echo "deb https://packagecloud.io/dokku/dokku/ubuntu/ trusty main" > /etc/apt/sources.list.d/dokku.list | |
logit "running apt-get update..." | |
sudo apt-get update > /dev/null | |
} | |
function install_postgres { | |
logit "installing Postgres..." | |
sudo apt-get install -qq -y postgresql postgresql-contrib > /dev/null 2>&1 | |
logit "starting Postgres..." | |
sudo service postgresql start | |
} | |
function install_dokku { | |
logit "setting up debconf..." | |
HOME=/home/"${USERNAME}" | |
echo "dokku dokku/vhost_enable boolean true" | sudo debconf-set-selections | |
echo "dokku dokku/web_config boolean false" | sudo debconf-set-selections | |
echo "dokku dokku/hostname string ${HOSTNAME}" | sudo debconf-set-selections | |
echo "dokku dokku/key_file string $HOME/.ssh/id_rsa.pub" | sudo debconf-set-selections | |
logit "installing Docker..." | |
# install docker | |
wget -nv -O - https://get.docker.com/ | sh | |
# install dokku | |
logit "installing Dokku..." | |
sudo apt-get update -qq > /dev/null | |
sudo apt-get install -qq -y dokku | |
sudo dokku plugin:install-dependencies --core | |
# start creation of backing services | |
# on your dokku host | |
# install the postgres plugin | |
# plugin installation requires root, hence the user change | |
logit "installing Postgres plugin for Dokku..." | |
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git | |
logit "Dokku installed." | |
} | |
add_user | |
set_passwordless_ssh | |
set_hostname | |
install_prerequisites | |
install_postgres | |
install_dokku |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment