From 5d2d3b5cdad978c5323b15ecd7aaf7b10afb4222 Mon Sep 17 00:00:00 2001
From: pierreozoux <pierre@ozoux.net>
Date: Sat, 26 Nov 2016 16:31:06 +0000
Subject: [PATCH] better installation steps

---
 INSTALL.md         | 116 ++++++++-------------------------------------
 INSTALL_HETZNER.md |  84 +++-----------------------------
 user_data          | 101 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+), 174 deletions(-)
 create mode 100644 user_data

diff --git a/INSTALL.md b/INSTALL.md
index 8a7ba7f..8c4cd05 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -1,114 +1,36 @@
 # Instructions to install libre.sh
 
 ## Recommendation
-- API key on Namecheap (if you want to automatically buy domain name)
+- you'd need API key on Namecheap (if you want to automatically buy and configure domain name)
 
 ## Installation
 
-First, you need a server.
-You can take it from a cloud provider, like DigitalOcean or Scaleway and choose to spin up a VM with CoreOS already installed on it.
+These instructions depend a bit on your cloud provider.
 
-You can also buy a baremetal at [Hetzner](https://serverboerse.de/index.php?country=EN) as they are the cheapest options around. Follow these [instructions](INSTALL_HETZNER.md) in this case.
+### [Digital Ocean](https://m.do.co/c/1b468ce0671f)
 
- - If you use a cloud provider that support `user_data`, just copy the file bellow.
- - If not, use boot a live cd, and issue that command:
+ 1. Install [doctl](https://github.com/digitalocean/doctl/)
+ 2. Issue the following command:
 
 ```
-wget https://raw.github.com/coreos/init/master/bin/coreos-install
-bash coreos-install -d /dev/sda -c cloud-config.tmp
+doctl compute droplet create libre.sh --user-data-file ./user_data --wait --ssh-keys $KEY_ID --size 1gb --region lon1 --image coreos-stable
 ```
 
-*Don't forget to change the hostname and your ssh key!*
+### Provider with user_data support
 
-```
-#cloud-config
+If you use a cloud provider that support `user_data`, like [Scaleway](http://scaleway.com/), just use [this user_data](https://raw.githubusercontent.com/indiehosters/libre.sh/master/user_data).
+
+### Hetzner
+
+You can also buy a baremetal at [Hetzner](https://serverboerse.de/index.php?country=EN) as they are the cheapest options around. Follow these [instructions](INSTALL_HETZNER.md) in this case.
+
+### Provider without user_data support
+
+Use boot a live cd, and issue that command:
 
-hostname: $hostname
-ssh_authorized_keys:
-  - #your ssh public key here
-write_files:
-  - path: /etc/sysctl.d/aio-max.conf
-    permissions: 0644
-    owner: root
-    content: "fs.aio-max-nr = 1048576"
-  - path: /etc/hosts
-    permissions: 0644
-    owner: root
-    content: |
-      127.0.0.1 localhost
-      255.255.255.255 broadcasthost
-      ::1 localhost
-  - path: /etc/environment
-    permission: 0644
-    owner: root
-    content: |
-      NAMECHEAP_URL="namecheap.com"
-      NAMECHEAP_API_USER="pierreo"
-      NAMECHEAP_API_KEY=
-      IP=`curl -s http://icanhazip.com/`
-      FirstName="Pierre"
-      LastName="Ozoux"
-      Address="23CalcadaSaoVicente"
-      PostalCode="1100-567"
-      Country="Portugal"
-      Phone="+351.967184553"
-      EmailAddress="pierre@ozoux.net"
-      City="Lisbon"
-      CountryCode="PT"
-      BACKUP_DESTINATION=root@xxxxx:port
-      MAIL_USER=contact%40indie.host
-      MAIL_PASS=
-      MAIL_HOST=mail.indie.host
-      MAIL_PORT=587
-coreos:
-  update:
-    reboot-strategy: off
-  units:
-    - name: systemd-sysctl.service
-      command: restart
-    - name: swap.service
-      command: start
-      content: |
-        [Unit]
-        Description=Turn on swap
-        [Service]
-        Type=oneshot
-        RemainAfterExit=true
-        ExecStartPre=-/bin/bash -euxc ' \
-          fallocate -l 8192m /swap &&\
-          chmod 600 /swap &&\
-          mkswap /swap'
-        ExecStart=/sbin/swapon /swap
-        ExecStop=/sbin/swapoff /swap
-        [Install]
-        WantedBy=local.target
-    - name: install-compose.service
-      command: start
-      content: |
-        [Unit]
-        Description=Install Docker Compose
-        [Service]
-        Type=oneshot
-        RemainAfterExit=true
-        ExecStart=-/bin/bash -euxc ' \
-          mkdir -p /opt/bin &&\
-          url=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r \'.assets[].browser_download_url | select(contains("Linux") and contains("x86_64"))\') &&\
-          curl -L $url > /opt/bin/docker-compose &&\
-          chmod +x /opt/bin/docker-compose'
-    - name: install-indiehosters.service
-      command: start
-      content: |
-        [Unit]
-        Description=Install IndieHosters
-        [Service]
-        Type=oneshot
-        RemainAfterExit=true
-        ExecStart=-/bin/bash -euxc ' \
-          git clone https://github.com/indiehosters/libre.sh.git /indiehosters &&\
-          mkdir /{data,system} &&\
-          mkdir /data/trash &&\
-          cp /indiehosters/unit-files/* /etc/systemd/system && systemctl daemon-reload &&\
-          cp /indiehosters/utils/* /opt/bin/'
+```
+wget https://raw.github.com/coreos/init/master/bin/coreos-install
+bash coreos-install -d /dev/sda -c user_data
 ```
 
 And voila, your first libre.sh node is ready!
diff --git a/INSTALL_HETZNER.md b/INSTALL_HETZNER.md
index 6dafde5..844dbf9 100644
--- a/INSTALL_HETZNER.md
+++ b/INSTALL_HETZNER.md
@@ -63,83 +63,13 @@ MAILADDR xxx@xxx.org
 # Start service
 systemctl start  mdmonitor.service
 
-# Add swap
-fallocate -l 8192m /swap
-chmod 600 /swap
-mkswap /swap
-
-cat > /var/lib/coreos-install/user_data << EOF
-#cloud-config
-
-hostname: $hostname
-ssh_authorized_keys:
-  - #your ssh public key here
-write_files:
-  - path: /etc/sysctl.d/aio-max.conf
-    permissions: 0644
-    owner: root
-    content: "fs.aio-max-nr = 1048576"
-  - path: /etc/hosts
-    permissions: 0644
-    owner: root
-    content: |
-      127.0.0.1 localhost
-      255.255.255.255 broadcasthost
-      ::1 localhost
-  - path: /etc/environment
-    permission: 0644
-    owner: root
-    content: |
-      NAMECHEAP_URL="namecheap.com"
-      NAMECHEAP_API_USER="pierreo"
-      NAMECHEAP_API_KEY=
-      IP=`curl -s http://icanhazip.com/`
-      FirstName="Pierre"
-      LastName="Ozoux"
-      Address="23CalcadaSaoVicente"
-      PostalCode="1100-567"
-      Country="Portugal"
-      Phone="+351.967184553"
-      EmailAddress="pierre@ozoux.net"
-      City="Lisbon"
-      CountryCode="PT"
-      BACKUP_DESTINATION=root@xxxxx:port
-      MAIL_USER=contact%40indie.host
-      MAIL_PASS=
-      MAIL_HOST=mail.indie.host
-      MAIL_PORT=587
-coreos:
-  update:
-    reboot-strategy: off
-  units:
-    - name: systemd-sysctl.service
-      command: restart
-    - name: data.mount
-      command: start
-      content: |
-        [Mount]
-        What=/dev/md0
-        Where=/data
-        Type=ext4
-    - name: swap.service
-      command: start
-      content: |
-        [Service]
-        Type=oneshot
-        ExecStart=/sbin/swapon /swap
+cat > /etc/systemd/system/data.mont << EOF
+[Mount]
+What=/dev/md0
+Where=/data
+Type=ext4
 EOF
 
-# Create Directory structure
-git clone https://github.com/indiehosters/libre.sh.git /indiehosters
-mkdir /{data,system}
-mkdir /data/trash
-
-mkdir -p /opt/bin
-
-# Install unit-files and utils
-cp /indiehosters/unit-files/* /etc/systemd/system && systemctl daemon-reload
-cp /indiehosters/utils/* /opt/bin/
+wget https://raw.githubusercontent.com/indiehosters/libre.sh/master/user_data -O /var/lib/coreos-install/user_data
 
-DOCKER_COMPOSE_VERSION=1.6.0
-curl -L https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-`uname -s`-`uname -m` > /opt/bin/docker-compose
-chmod +x /opt/bin/docker-compose
+coreos-cloudinit /var/lib/coreos-install/user_data
diff --git a/user_data b/user_data
new file mode 100644
index 0000000..0df227e
--- /dev/null
+++ b/user_data
@@ -0,0 +1,101 @@
+#cloud-config
+
+write_files:
+  - path: /etc/sysctl.d/aio-max.conf
+    permissions: 0644
+    owner: root
+    content: "fs.aio-max-nr = 1048576"
+  - path: /etc/hosts
+    permissions: 0644
+    owner: root
+    content: |
+      127.0.0.1 localhost
+      255.255.255.255 broadcasthost
+      ::1 localhost
+  - path: /etc/environment
+    permission: 0644
+    owner: root
+    content: |
+      NAMECHEAP_URL="namecheap.com"
+      NAMECHEAP_API_USER="pierreo"
+      NAMECHEAP_API_KEY=
+      IP=`curl -s http://icanhazip.com/`
+      FirstName="Pierre"
+      LastName="Ozoux"
+      Address=""
+      PostalCode=""
+      Country="Portugal"
+      Phone="+351.967184553"
+      EmailAddress="pierre@ozoux.net"
+      City="Lisbon"
+      CountryCode="PT"
+      BACKUP_DESTINATION=root@xxxxx:port
+      MAIL_USER=
+      MAIL_PASS=
+      MAIL_HOST=mail.indie.host
+      MAIL_PORT=587
+coreos:
+  update:
+    reboot-strategy: off
+  units:
+    - name: systemd-sysctl.service
+      command: restart
+    - name: swap.service
+      enable: true
+      command: start
+      content: |
+        [Unit]
+        Description=Turn on swap
+        [Service]
+        Type=oneshot
+        RemainAfterExit=true
+        ExecStartPre=-/bin/bash -euxc ' \
+          fallocate -l 8192m /swap &&\
+          chmod 600 /swap &&\
+          mkswap /swap'
+        ExecStart=/sbin/swapon /swap
+        ExecStop=/sbin/swapoff /swap
+        [Install]
+        WantedBy=local.target
+    - name: install-compose.service
+      command: start
+      content: |
+        [Unit]
+        Description=Install Docker Compose
+        [Service]
+        Type=oneshot
+        RemainAfterExit=true
+        ExecStart=-/bin/bash -euxc ' \
+          mkdir -p /opt/bin &&\
+          url=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r \'.assets[].browser_download_url | select(contains("Linux") and contains("x86_64"))\') &&\
+          curl -L $url > /opt/bin/docker-compose &&\
+          chmod +x /opt/bin/docker-compose'
+    - name: install-indiehosters.service
+      command: start
+      content: |
+        [Unit]
+        Description=Install IndieHosters
+        [Service]
+        Type=oneshot
+        RemainAfterExit=true
+        ExecStart=-/bin/bash -euxc ' \
+          git clone https://github.com/indiehosters/libre.sh.git /libre.sh &&\
+          mkdir /{data,system} &&\
+          mkdir /data/trash &&\
+          cp /libre.sh/unit-files/* /etc/systemd/system && systemctl daemon-reload &&\
+          cp /libre.sh/utils/* /opt/bin/'
+    - name: web-net.service
+      enable: true
+      command: start
+      content: |
+        [Unit]
+        Description=Create lb_web network
+        Requires=docker.service
+        After=docker.service
+        [Service]
+        Type=oneshot
+        RemainAfterExit=true
+        ExecStart=/usr/bin/docker network create lb_web
+        ExecStop=/usr/bin/docker network rm lb_web
+        [Install]
+        WantedBy=local.target
-- 
GitLab