diff --git a/README.md b/README.md index 750efff..a31dcf3 100644 --- a/README.md +++ b/README.md @@ -12,31 +12,32 @@ __work in progress__ (is being tested on digitalocean ubuntu 16.04) -## Ubuntu ## +## Remote Linux via SSH ## -Create a server (e.g., digitalocean on some other place) with Ubuntu 16.04 on it. +Create a server (e.g., digitalocean on some other place) with one of the following tested OS on it: +* Ubuntu 17.10 x64 +* Ubuntu 16.04 x64 +* Debian 8.10 x64 Clone this repository on your local machine. Now run: ``` -ssh root@[ip exit node] 'bash -s' < create_exitnode.sh [ip exit node] +exit_node_ip=165.227.241.194 +./build/remote root@$exit_node_ip ``` -Expected output should be something like: +This should SSH to the exit node, configure it, reboot, and wait for the reboot to complete. + +Expected Output will be like ``` -Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] -Hit:2 http://ams2.mirrors.digitalocean.com/ubuntu xenial InRelease -Get:3 http://security.ubuntu.com/ubuntu xenial-security/main Sources [108 kB] -Get:5 http://security.ubuntu.com/ubuntu xenial-security/restricted Sources [2,116 B] -[...] -Cloning into '/opt/exitnode'... -tunneldigger.service is not a native service, redirecting to systemd-sysv-install -Executing /lib/systemd/systemd-sysv-install enable tunneldigger -babeld.service is not a native service, redirecting to systemd-sysv-install -Executing /lib/systemd/systemd-sysv-install enable babeld +⚡ ./build/remote root@165.227.241.194 +testing ssh to root@165.227.241.194 +... # lots more stuff +. +remote exitnode provisioned, rebooted ``` # Testing diff --git a/build/bin/install-dependencies b/build/bin/install-dependencies new file mode 100755 index 0000000..0b14c4c --- /dev/null +++ b/build/bin/install-dependencies @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +usage () { +cat < /dev/null 2>&1 + do + printf "." + sleep 2 + done +} diff --git a/build/remote b/build/remote new file mode 100755 index 0000000..3709bef --- /dev/null +++ b/build/remote @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +usage () { +cat < /dev/null 2>&1 +rsync -a "$this_dir/../" "$exitnode_ssh:$EXITNODE_DIR" + +# configure +ssh "$exitnode_ssh" "apt-get clean && apt-get update && dpkg --configure -a" + # shellcheck disable=SC2029 +ssh -t "$exitnode_ssh" "DEBIAN_FRONTEND=$DEBIAN_FRONTEND PUBLIC_IP=$PUBLIC_IP EXITNODE_DIR=$EXITNODE_DIR $EXITNODE_DIR/create_exitnode.sh" + +# reboot +echo "rebooting $exitnode_ssh" +ssh "$exitnode_ssh" 'nohup sudo reboot &>/dev/null & exit' +# wait for ssh after reboot +echo "Waiting for ssh $exitnode_ssh" +wait_for_ssh "$exitnode_ssh" + +ssh "$exitnode_ssh" 'echo remote exitnode provisioned, rebooted' \ No newline at end of file diff --git a/build/variables b/build/variables new file mode 100644 index 0000000..d3217eb --- /dev/null +++ b/build/variables @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2034 + +GATEWAY_IP=$2 + +MESH_IP=100.64.0.42 +MESH_PREFIX=32 +MESHNET=100.64.0.0/10 +ETH_IF=eth0 +PUBLIC_IP="${PUBLIC_IP:-$IP}" +PUBLIC_SUBNET="$PUBLIC_IP/29" +IP="${IP:-$PUBLIC_IP}" + +TUNNELDIGGER_HOME=/opt/tunneldigger diff --git a/create_exitnode.sh b/create_exitnode.sh index 19f9811..6ca5526 100755 --- a/create_exitnode.sh +++ b/create_exitnode.sh @@ -1,56 +1,27 @@ -#!/bin/sh +#!/usr/bin/env bash + +cd "$(dirname $0)" + +# set -e # stop on first error +# set -x # print every line before executing (to debug) + +source ./build/variables -IP=$1 -GATEWAY_IP=$2 - -MESH_IP=100.64.0.42 -MESH_PREFIX=32 -MESHNET=100.64.0.0/10 -ETH_IF=eth0 -PUBLIC_IP=$IP -PUBLIC_SUBNET="$IP/29" - - -apt-get update && apt-get install -y --force-yes \ - build-essential \ - ca-certificates \ - curl \ - git \ - libssl-dev \ - libxslt1-dev \ - module-init-tools \ - bridge-utils \ - openssh-server \ - openssl \ - perl \ - dnsmasq \ - procps \ - python-psycopg2 \ - python-software-properties \ - software-properties-common \ - python \ - python-dev \ - python-pip \ - iproute \ - libnetfilter-conntrack3 \ - libevent-dev \ - ebtables \ - vim \ - tmux +cat < /proc/sys/net/ipv4/ip_forward - sed -i.backup 's/\(.*net.ipv4.ip_forward.*\)/# Enable forwarding for mesh (altered by provisioning script)\nnet.ipv4.ip_forward=1/' /etc/sysctl.conf + ip_forward="$(cat /proc/sys/net/ipv4/ip_forward)" + echo "PUBLIC_IP=$PUBLIC_IP" + echo "ip_forward=$ip_forward" + echo "whoami=$(whoami)" + if [ $ip_forward != "1" ]; then + echo 1 > /proc/sys/net/ipv4/ip_forward + sed -i.backup 's/\(.*net.ipv4.ip_forward.*\)/# Enable forwarding for mesh (altered by provisioning script)\nnet.ipv4.ip_forward=1/' /etc/sysctl.conf + fi # make sure that protocol is status to make babeld distribute gateway route # see https://github.com/jech/babeld/blob/1a6135dca042f0f22dc450699a900e3ca7bc06ca/README#L88