summarylogtreecommitdiffstats
path: root/dokku.install
blob: 943632542c3c1aae4f29cc3e49baa69495d86284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
post_install() {
  getent group dokku >/dev/null ||
    groupadd --system dokku

  # same as: sshcommand create dokku /usr/bin/dokku
  getent passwd dokku >/dev/null ||
    useradd --system \
            --gid dokku \
            --shell /usr/bin/dokku \
            --home-dir /var/dokku/ \
            -m \
            dokku

  chown dokku:dokku /var/dokku/
  mkdir -p /var/dokku/.ssh/
  touch /var/dokku/.ssh/authorized_keys
  chown -R dokku:dokku /var/dokku/.ssh/
  gpasswd -a dokku docker > /dev/null

  echo "$1" | cut -d "-" -f 1 > /var/dokku/VERSION

  if [ ! -f "/var/dokku/HOSTNAME" ]; then
    hostname -f > "/var/dokku/HOSTNAME"
    chown dokku:dokku "/var/dokku/HOSTNAME"
  fi

  echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload nginx, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx

  mkdir -p /etc/nginx/conf.d

  DOKKU_LIB_ROOT="/var/lib/dokku"

  echo "Setting up plugin directories"
  # should be replaced by `plugn init`
  mkdir -p ${DOKKU_LIB_ROOT}/core-plugins/available ${DOKKU_LIB_ROOT}/plugins/available
  mkdir -p ${DOKKU_LIB_ROOT}/core-plugins/enabled ${DOKKU_LIB_ROOT}/plugins/enabled
  touch ${DOKKU_LIB_ROOT}/core-plugins/config.toml ${DOKKU_LIB_ROOT}/plugins/config.toml

  echo "Enabling all core plugins"
  find ${DOKKU_LIB_ROOT}/core-plugins/available -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do
    if [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then
      ln -s ${DOKKU_LIB_ROOT}/core-plugins/available/$plugin ${DOKKU_LIB_ROOT}/plugins/available/$plugin;
      PLUGIN_PATH=${DOKKU_LIB_ROOT}/core-plugins plugn enable $plugin
      PLUGIN_PATH=${DOKKU_LIB_ROOT}/plugins plugn enable $plugin
    fi
  done
  chown dokku:dokku -R ${DOKKU_LIB_ROOT}/plugins ${DOKKU_LIB_ROOT}/core-plugins

  echo "Install all core plugins"
  dokku plugin:install --core

  echo "
    Please add your ssh pubkey like:
      $ cat ~/.ssh/id_rsa.pub | sudo sshcommand acl-add dokku 'local key'

    To enable nginx autoconfiguration, add to your /etc/nginx/nginx.conf in http section:
      include /etc/nginx/conf.d/*.conf;
"
}

post_upgrade() {
  post_install $1
}

pre_remove() {
  userdel dokku &>/dev/null || true
  groupdel dokku &>/dev/null || true
}

post_remove() {
  rm -f /etc/init/dokku-installer.conf
  rm -f /etc/init/dokku-redeploy.conf
  rm -f /etc/systemd/system/dokku-installer.conf
  rm -f /etc/systemd/system/dokku-redeploy.service
  rm -f /etc/update-motd.d/99-dokku
  rm -rf /var/dokku
  rm -rf /etc/nginx/conf.d/dokku.conf
}