diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d76a530 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +dist: xenial +sudo: required + +install: + - ./bootstrap.sh +before_script: + - source /etc/profile +script: + - cd $HOME + - make +before_deploy: + - cd $HOME + - make package +deploy: + - provider: releases + api_key: + secure: QhoV/L0862+DUInpkcaV8f1g8sWfzA0Md6hg4PX+SFMWntwxRIlrSAmilAGyU300WQn4euWMv2CW5R+hjGKbVBFED8vCJVFu4EZtfH4L+fpx58AjFFQkcQ/kgpjFMf2vSTS9VIvz7JGfUB3XodpSmBJvdH89MHx7q6VQXAVHGBUusw9p9PdXCZG27eT9/aNcVxRoqlWqrf9LmBSh+MBUCHdUCoLOwyZ9YLQ6/nTYsQsJlYEYbD9pseWHtHWQZdxYiNStkLhdEnF82RXYcDM3rOaSEHZt67Ae7O95UgXdfpsnRAqIL2+lmgHIQ7Mva+9l8yjxs9yiomnGqmocn8Y1/Woa5KrtiqlV7QRs4NM1k7cy39h+EL4DQ2TSNKTqQbcIg9mFn+qtyB7024KeAXJ+ejN3blESI5AqnXiHtaMhLmED+HBXAsQZ3Go5eLFyWD2Lx3lcZcTTDjSVqx4qk5Wh8gKyOS6WKpDOPPAoa2zBaaE63fZ/wqKuW57ARACnfZLs75We2deGbv16COaM6rq9rwa29VhBqGvtpB7SPi8H5K8mRqjDNYUJC33/J9+CqLOvYbs4KV3+HUT3tWSi1TpDIcQ0UmzJOAv2W96xN/mTn+t5RYV7kIydzULEKlkdGltEB8PC4G6yUa2FNvJwRVSl1e3ClSAhW22Fy7MzbASU6YI= + file_glob: true + file: /tmp/publish/* + skip_cleanup: true + on: + repo: benhylau/mesh-router-builder + tags: true diff --git a/README.md b/README.md index 476fae7..71374ac 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ to create mesh routers on ARM devices. The following single-board computers are supported by mesh-orange: * raspberrypi2 - * raspberrypi3 + * raspberrypi3 (for 3b and 3b+) * sun4i-a10-cubieboard * sun7i-a20-bananapi * sun8i-h2-plus-orangepi-zero @@ -27,21 +27,32 @@ supported by mesh-orange: Note that only **raspberrypi2**, **raspberrypi3**, and **sun8i-h2-plus-orangepi-zero** are enabled by default. Uncomment boards in -`/home/vagrant/mesh-orange-images/Makefile` after ssh-ing to your Vagrant machine +`~/mesh-orange-images/Makefile` after ssh-ing to your Vagrant machine to enable the other boards you want. Usage ----- -Ensure you have [Vagrant](https://www.vagrantup.com) installed, then clone -this repository and run: +You can use this builder in three environments: - $ vagrant up - $ vagrant ssh +| OS | Self-managed VM | Vagrant-managed VM | Travis CI | +|:---------|:---------------:|:--------------------------------------------------------------------:|:---------:| +|**Debian**| `stretch` | [debian/stretch64](https://app.vagrantup.com/debian/boxes/stretch64) | | +|**Ubuntu**| `xenial` | [ubuntu/xenial64](https://app.vagrantup.com/ubuntu/boxes/xenial64) | [![Build Status](https://travis-ci.org/benhylau/mesh-router-builder.svg?branch=master)](https://travis-ci.org/benhylau/mesh-router-builder) [![GitHub release](https://img.shields.io/github/release/benhylau/mesh-router-builder.svg)](https://github.com/benhylau/mesh-router-builder/releases) | -In the Vagrant machine, call `make` (optionally, `make PROFILE=custom-profile`). -When the build completes, call `exit` and find the built artifacts in the -**output** directory of your host: +### Self-managed VM + +It is highly recommended that you spin up a fresh **Debian Stretch** or **Ubuntu Xenial** +VM to use this builder. Using a non-root user with `sudo`, from its `$HOME` directory, +run the following commands: + + $ git clone https://github.com/benhylau/mesh-router-builder.git + $ ./bootstrap.sh + $ source /etc/profile + $ cd $HOME + $ make (optionally, make PROFILE=custom-profile) + +You will find built artifacts in the `~/mesh-router-builder/output` directory: ./output/debian-packages/yggdrasil-go_0.1-1_amd64.deb yggdrasil-go_0.1-1_armhf.deb @@ -50,14 +61,46 @@ When the build completes, call `exit` and find the built artifacts in the sun8i-h2-plus-orangepi-zero.img ... +### Vagrant-managed VM + +This is the recommended way to use this builder. Ensure you have +[Vagrant](https://www.vagrantup.com) installed, then clone this repository and run: + + $ vagrant up + $ vagrant ssh + +In the Vagrant machine, call `make` (optionally, `make PROFILE=custom-profile`). +When the build completes, call `exit` and find the built artifacts in the +**output** directory of your host. + Then you may destroy the Vagrant machine with `vagrant destroy`. +#### macOS High Sierra + +There is a known bug in macOS High Sierra that prevents Synced Folders from +working. You will have to get the built artifacts manually before destroying the +Vagrant machine: + + $ vagrant ssh-config > vagrant-ssh.conf + $ mkdir output-macos + $ scp -r -F vagrant-ssh.conf mesh-router-builder:/vagrant/output/* output-macos/ + +### Travis CI + +This repository auto-builds in a Ubuntu Xenial environment using Travis CI. See +[.travis.yml](https://github.com/benhylau/mesh-router-builder/blob/travis/.travis.yml) +for details. + Publish to GitHub Releases -------------------------- -If you wish to publish the built artifacts to _GitHub Releases_, create a file -named **.github_publish** in the project root before `vagrant up` with the -following information: +Travis CI is configured to publish official artifacts to +[GitHub Releases](https://github.com/benhylau/mesh-router-builder/releases) on each +release tag. + +If you wish to manually publish to GitHub Releases of a forked repository, create a file +named **.github_publish** in the project root before `vagrant up` with the following +information: GITHUB_USERNAME= GITHUB_REPOSITORY= @@ -75,15 +118,5 @@ images, and used to tag the release. Your file should look something like this: GITHUB_RELEASE_VERSION=0.1 After `make` completes, you can call `make publish` and all artifacts will be -published to _Github Releases_ in your repository. +published to Github Releases in your repository. -macOS High Sierra ------------------ - -There is a known bug in macOS High Sierra that prevents Synced Folders from -working. You will have to get the built artifacts manually before destroying the -Vagrant machine: - - $ vagrant ssh-config > vagrant-ssh.conf - $ mkdir output-macos - $ scp -r -F vagrant-ssh.conf mesh-router-builder:/vagrant/output/* output-macos/ diff --git a/Vagrantfile b/Vagrantfile index 9e5cedb..86593fa 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,7 +5,7 @@ Vagrant.configure("2") do |config| config.vm.define "mesh-router-builder" config.vm.box = "debian/stretch64" config.vm.box_version = "9.3.0" - config.vm.provision :shell, path: "bootstrap.sh" + config.vm.provision :shell, path: "bootstrap.sh", privileged: false config.vm.provider "virtualbox" do |v| v.memory = 2048 diff --git a/bootstrap.sh b/bootstrap.sh old mode 100644 new mode 100755 index e3318b2..4501430 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # Install standard tools -apt install -y \ +sudo apt update +sudo apt install -y \ apache2 \ apt-transport-https \ build-essential \ @@ -14,30 +15,120 @@ apt install -y \ # Install golang mkdir /tmp/golang wget --progress=bar:force https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz -P /tmp/golang -tar -C /usr/local -xzf /tmp/golang/go1.11.2.linux-amd64.tar.gz +sudo tar -C /usr/local -xzf /tmp/golang/go1.11.2.linux-amd64.tar.gz { echo '' echo '# Add golang path' echo 'export PATH=$PATH:/usr/local/go/bin' -} >> /etc/profile +} | sudo tee --append /etc/profile > /dev/null # Install nodejs -curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - -apt-get install -y nodejs +curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - +sudo apt-get install -y nodejs -# Copy build scripts from Synced Folder to Vagrant machine user home -cp -r /vagrant/src/* /home/vagrant/ -chown -R vagrant:vagrant /home/vagrant/* +################################### +# Platform specific configurations +################################### -# Copy github release publishing configurations -if [ -f /vagrant/.github_publish ]; then - . /vagrant/.github_publish +# Install keys required for ubuntu xenial +if [ `lsb_release -c -s` == 'xenial' ]; then + # See mesh-orange documentation regarding keys being installed + sudo apt-get -y install debian-archive-keyring + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EF0F382A1A7B6500 +fi + +################################### +# Build environment configurations +################################### + +# Configure for vagrant build environment +if [ "$USER" == 'vagrant' ]; then + echo 'Vagrant environment detected' + + # Set source directory to path in synced folder + echo 'Setting source directory to Synced Folder at /vagrant/src' + SOURCE_DIR=/vagrant/src + + # Set local directory for build artifacts to synced folder + echo 'Setting local directory for build artifacts at /vagrant/output' + { + echo '' + echo '# Set local directory for build artifacts' + echo 'export BUILD_ARTIFACTS_DIR=/vagrant/output' + } | sudo tee --append /etc/profile > /dev/null + + # Copy github release publishing configurations + if [ -f /vagrant/.github_publish ]; then + . /vagrant/.github_publish + echo "Setting GitHub Release version to $GITHUB_RELEASE_VERSION" + { + echo '' + echo '# GitHub Release publishing configurations' + echo "export GITHUB_USERNAME=$GITHUB_USERNAME" + echo "export GITHUB_REPOSITORY=$GITHUB_REPOSITORY" + echo "export GITHUB_TOKEN=$GITHUB_TOKEN" + echo "export GITHUB_RELEASE_VERSION=$GITHUB_RELEASE_VERSION" + } | sudo tee --append /etc/profile > /dev/null + fi + +# Configure for travis build environment +elif [ "$USER" == 'travis' ]; then + echo 'Travis environment detected' + + # Set source directory to path where travis clones repository + echo "Setting source directory to Travis build directory at $TRAVIS_BUILD_DIR/src" + SOURCE_DIR=$TRAVIS_BUILD_DIR/src + + # Set local directory for build artifacts + echo "Setting local directory for build artifacts at $HOME/output" + { + echo '' + echo '# Set local directory for build artifacts' + echo "export BUILD_ARTIFACTS_DIR=$HOME/output" + } | sudo tee --append /etc/profile > /dev/null + + # Set github release from travis publishing configurations + echo "Setting GitHub Release version to `$TRAVIS_TAG | sed 's/^v//'`" { echo '' echo '# GitHub Release publishing configurations' - echo "export GITHUB_USERNAME=$GITHUB_USERNAME" - echo "export GITHUB_REPOSITORY=$GITHUB_REPOSITORY" - echo "export GITHUB_TOKEN=$GITHUB_TOKEN" - echo "export GITHUB_RELEASE_VERSION=$GITHUB_RELEASE_VERSION" - } >> /etc/profile + echo "export GITHUB_RELEASE_VERSION=`echo $TRAVIS_TAG | sed 's/^v//'`" + } | sudo tee --append /etc/profile > /dev/null + + # Install tools required to cross-compile cjdns in travis environment + sudo apt install -y libc6-dev-armhf-cross + +# Configure for local build environment +else + # Set source directory to local path relative to this script + echo "Setting source directory to local directory at `cd "$(dirname "${BASH_SOURCE[0]}")" && pwd`/src" + SOURCE_DIR=`cd "$(dirname "${BASH_SOURCE[0]}")" && pwd`/src + + # Set local directory for build artifacts + echo "Setting local directory for build artifacts at `pwd`/output" + { + echo '' + echo '# Set local directory for build artifacts' + echo "export BUILD_ARTIFACTS_DIR=`pwd`/output" + } | sudo tee --append /etc/profile > /dev/null + + # Copy github release publishing configurations + if [ -f .github_publish ]; then + . .github_publish + echo "Setting GitHub Release version to $GITHUB_RELEASE_VERSION" + { + echo '' + echo '# GitHub Release publishing configurations' + echo "export GITHUB_USERNAME=$GITHUB_USERNAME" + echo "export GITHUB_REPOSITORY=$GITHUB_REPOSITORY" + echo "export GITHUB_TOKEN=$GITHUB_TOKEN" + echo "export GITHUB_RELEASE_VERSION=$GITHUB_RELEASE_VERSION" + } | sudo tee --append /etc/profile > /dev/null + fi fi + +# Copy build scripts to user home +cp -r $SOURCE_DIR/* /home/$USER/ +chown -R $USER:$USER /home/$USER/* + diff --git a/src/Makefile b/src/Makefile index ea07677..3c1d854 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,8 +5,8 @@ PACKAGES_DIR = debian-packages IMAGES_DIR = mesh-orange-images -BUILT_PACKAGES_DIR = /vagrant/output/debian-packages -BUILT_IMAGES_DIR = /vagrant/output/mesh-orange-images +BUILT_PACKAGES_DIR = ${BUILD_ARTIFACTS_DIR}/debian-packages +BUILT_IMAGES_DIR = ${BUILD_ARTIFACTS_DIR}/mesh-orange-images PUBLISH_DIR = /tmp/publish build_images: build_packages @@ -15,14 +15,16 @@ build_images: build_packages build_packages: $(MAKE) -C $(PACKAGES_DIR) -publish: - rm -rf $(PUBLISH_DIR) - mkdir $(PUBLISH_DIR) - cp $(BUILT_PACKAGES_DIR)/* $(PUBLISH_DIR)/ - cp $(BUILT_IMAGES_DIR)/* $(PUBLISH_DIR)/ +publish: package go get -u github.com/tcnksm/ghr go/bin/ghr \ -username ${GITHUB_USERNAME} \ -repository ${GITHUB_REPOSITORY} \ -token ${GITHUB_TOKEN} \ "v${GITHUB_RELEASE_VERSION}" $(PUBLISH_DIR) + +package: + rm -rf $(PUBLISH_DIR) + mkdir $(PUBLISH_DIR) + cp $(BUILT_PACKAGES_DIR)/* $(PUBLISH_DIR)/ + cp $(BUILT_IMAGES_DIR)/* $(PUBLISH_DIR)/ diff --git a/src/debian-packages/Makefile b/src/debian-packages/Makefile index ea20ded..e87543e 100644 --- a/src/debian-packages/Makefile +++ b/src/debian-packages/Makefile @@ -6,7 +6,7 @@ SUBDIRS += cjdns/ SUBDIRS += yggdrasil-go/ BUILD_DIR = /tmp/debian-repo -DEB_PACKAGES_DIR = /vagrant/output/debian-packages +DEB_PACKAGES_DIR = ${BUILD_ARTIFACTS_DIR}/debian-packages localhost_deb: package_deb rm -rf $(BUILD_DIR) diff --git a/src/debian-packages/cjdns/Makefile b/src/debian-packages/cjdns/Makefile index a668e00..278522b 100644 --- a/src/debian-packages/cjdns/Makefile +++ b/src/debian-packages/cjdns/Makefile @@ -11,7 +11,7 @@ SOURCE_URL = https://github.com/cjdelisle/cjdns TAG = cjdns-v20.2 ARCHS = amd64 armhf BUILD_DIR = /tmp/$(PACKAGE_NAME) -OUTPUT_DIR = /vagrant/output/debian-packages +OUTPUT_DIR = ${BUILD_ARTIFACTS_DIR}/debian-packages # Package deb for a particular architecture # diff --git a/src/debian-packages/yggdrasil-go/Makefile b/src/debian-packages/yggdrasil-go/Makefile index 884bff3..c54abb0 100644 --- a/src/debian-packages/yggdrasil-go/Makefile +++ b/src/debian-packages/yggdrasil-go/Makefile @@ -11,7 +11,7 @@ SOURCE_URL = https://github.com/yggdrasil-network/yggdrasil-go TAG = master ARCHS = amd64 armhf BUILD_DIR = /tmp/$(PACKAGE_NAME) -OUTPUT_DIR = /vagrant/output/debian-packages +OUTPUT_DIR = ${BUILD_ARTIFACTS_DIR}/debian-packages # Package deb for a particular architecture # diff --git a/src/mesh-orange-images/Makefile b/src/mesh-orange-images/Makefile index e9e2955..30bba59 100644 --- a/src/mesh-orange-images/Makefile +++ b/src/mesh-orange-images/Makefile @@ -7,7 +7,7 @@ PROFILE ?= default TAG = master BUILD_DIR = /tmp/mesh-orange -OUTPUT_DIR = /vagrant/output/mesh-orange-images +OUTPUT_DIR = ${BUILD_ARTIFACTS_DIR}/mesh-orange-images # raspberrypi3 is automatically generated when raspberrypi2 is enabled because they share the same image BOARDS += raspberrypi2 diff --git a/src/mesh-orange-images/mesh-orange/default/debian-config/.keep b/src/mesh-orange-images/mesh-orange/default/debian-config/.keep new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh-orange-images/mesh-orange/default/debian-config/debian.stretch.multistrap b/src/mesh-orange-images/mesh-orange/default/debian-config/debian.stretch.multistrap deleted file mode 100644 index f153e27..0000000 --- a/src/mesh-orange-images/mesh-orange/default/debian-config/debian.stretch.multistrap +++ /dev/null @@ -1,50 +0,0 @@ -[General] -bootstrap=Stretch Local -aptsources=Stretch -configscript=multistrap.configscript - -# this is only necessary for Local sourced packages but the config has to be global -# TODO sign local packages -noauth=true - -cleanup=true - -[Local] -source=http://localhost debian/ -omitdebsrc=true - -# mesh router -packages= cjdns yggdrasil-go - -[Stretch] -source=http://httpredir.debian.org/debian -suite=stretch -omitdebsrc=true -keyring=debian-archive-keyring -components=main contrib non-free - -# Base system needs these three packages -packages= systemd udev kmod - -# allow scripts to read .init style files -packages= confget - -# package management -packages= apt - -# network configuration tools -packages= iproute2 - -# allow us to reach the rest of the world -packages= openssh-client - -# allow the rest of the world to reach us -packages= dropbear-run - -# wireless management -packages= iw hostapd crda - -# local-net only network management -packages= mactelnet-server - -# libreadline7 ? gets /etc/inputrc, which should make ctrl-arrows work diff --git a/src/mesh-orange-images/mesh-orange/default/debian-config/packages.txt b/src/mesh-orange-images/mesh-orange/default/debian-config/packages.txt deleted file mode 100644 index 4916224..0000000 --- a/src/mesh-orange-images/mesh-orange/default/debian-config/packages.txt +++ /dev/null @@ -1,6 +0,0 @@ -# -# Any extra debian packages needed for the mesh build can be specified in this -# file. - -iputils-ping -nano-tiny