Skip to content

Commit

Permalink
Merge pull request #8 from benhylau/cjdns-deb
Browse files Browse the repository at this point in the history
Build cjdns deb packages for amd64 and armhf
  • Loading branch information
benhylau authored Feb 1, 2018
2 parents 8d55c6d + 249c309 commit ddc9a55
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 13 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ Note that only **raspberrypi2** 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 to enable the other boards you want.

Status
------

* cjdns .deb packages are not being generated

Usage
-----

Expand Down
4 changes: 4 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ Vagrant.configure("2") do |config|
config.vm.box = "debian/stretch64"
config.vm.box_version = "9.3.0"
config.vm.provision :shell, path: "bootstrap.sh"

config.vm.provider "virtualbox" do |v|
v.memory = 6144
end
end
23 changes: 22 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
#!/usr/bin/env bash

# Install standard tools
apt install -y build-essential git apache2 vim
apt install -y \
apache2 \
apt-transport-https \
build-essential \
ca-certificates \
curl \
git \
gnupg2 \
qemu-user-static \
software-properties-common \
swapspace \
vim

# Install docker-ce
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable"
apt-get update
apt-get install -y docker-ce

# Install golang
mkdir /tmp/golang
Expand All @@ -13,6 +30,10 @@ tar -C /usr/local -xzf /tmp/golang/go1.9.2.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin'
} >> /etc/profile

# Install nodejs
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
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/*
63 changes: 61 additions & 2 deletions src/debian-packages/cjdns/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,64 @@
# Build and package cjdns
#

package_deb:
echo TODO
PACKAGE_NAME = cjdns
VERSION = 20.0
DEBIAN_REVISION = 1
MAINTAINER = Benedict Lau <[email protected]>
SOURCE_URL = https://github.com/cjdelisle/cjdns

TAG = cjdns-v20
ARCHS = amd64 armhf
BUILD_DIR = /tmp/$(PACKAGE_NAME)
OUTPUT_DIR = /vagrant/output/debian-packages

# Package deb for a particular architecture
#
# $1 is the architecture
define package_deb_arch
mkdir -p $(BUILD_DIR)/debian/$(1)
cp -r debian $(BUILD_DIR)/debian/$(1)/ # Copy deb package files
sed -i "s|__PACKAGE__|$(PACKAGE_NAME)|g" $(BUILD_DIR)/debian/$(1)/debian/DEBIAN/control # Replace __PACKAGE__ macro in control file
sed -i "s|__VERSION__|$(VERSION)-$(DEBIAN_REVISION)|g" $(BUILD_DIR)/debian/$(1)/debian/DEBIAN/control # Replace __VERSION__ macro in control file
sed -i "s|__ARCHITECTURE__|$(1)|g" $(BUILD_DIR)/debian/$(1)/debian/DEBIAN/control # Replace __ARCHITECTURE__ macro in control file
sed -i "s|__MAINTAINER__|$(MAINTAINER)|g" $(BUILD_DIR)/debian/$(1)/debian/DEBIAN/control # Replace __MAINTAINER__ macro in control file
sed -i "s|__HOMEPAGE__|$(SOURCE_URL)|g" $(BUILD_DIR)/debian/$(1)/debian/DEBIAN/control # Replace __HOMEPAGE__ macro in control file
sed -i "s|__PACKAGE__|$(PACKAGE_NAME)|g" $(BUILD_DIR)/debian/$(1)/debian/usr/share/doc/$(PACKAGE_NAME)/copyright # Replace __PACKAGE__ macro in copyright file
sed -i "s|__MAINTAINER__|$(MAINTAINER)|g" $(BUILD_DIR)/debian/$(1)/debian/usr/share/doc/$(PACKAGE_NAME)/copyright # Replace __MAINTAINER__ macro in copyright file
sed -i "s|__SOURCE__|$(SOURCE_URL)|g" $(BUILD_DIR)/debian/$(1)/debian/usr/share/doc/$(PACKAGE_NAME)/copyright # Replace __SOURCE__ macro in copyright file
cp $(BUILD_DIR)/bin/$(1)/cjdroute $(BUILD_DIR)/debian/$(1)/debian/usr/bin/ # Copy binary
mkdir -p $(BUILD_DIR)/debian/$(1)/debian/lib/systemd/system # Make directories for systemd service files
cp $(BUILD_DIR)/src/contrib/systemd/* $(BUILD_DIR)/debian/$(1)/debian/lib/systemd/system/ # Copy systemd service files
cd $(BUILD_DIR)/debian/$(1); \
dpkg-deb --build debian; \
cp debian.deb $(OUTPUT_DIR)/$(PACKAGE_NAME)_$(VERSION)-$(DEBIAN_REVISION)_$(1).deb
endef

package_deb: build_bin_amd64 build_bin_armhf
$(foreach arch,$(ARCHS),$(call package_deb_arch,$(arch));)

build_bin_amd64: download_source
mkdir -p $(BUILD_DIR)/bin/amd64
cd $(BUILD_DIR)/src; \
./clean; \
./do; \
cp cjdroute $(BUILD_DIR)/bin/amd64/

build_bin_armhf: mkdir_build
mkdir -p $(BUILD_DIR)/bin/armhf
cp -r docker $(BUILD_DIR)/
sed -i "s|__TAG__|$(TAG)|g" $(BUILD_DIR)/docker/Dockerfile # Replace __TAG__ macro in Dockerfile
mkdir -p $(BUILD_DIR)/docker/build
cd $(BUILD_DIR)/docker; \
sudo docker build -t cjdns-armv7hf . # Build armv7hf docker container
sudo docker run --memory="5g" -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static -v $(BUILD_DIR)/docker/build:/tmp/cjdns cjdns-armv7hf # Build binary in emulated ARM docker
cd $(BUILD_DIR)/docker/build; \
cp cjdroute $(BUILD_DIR)/bin/armhf/

download_source: mkdir_build
git clone https://github.com/cjdelisle/cjdns.git -b $(TAG) $(BUILD_DIR)/src

mkdir_build:
sudo rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
mkdir -p $(OUTPUT_DIR)
9 changes: 9 additions & 0 deletions src/debian-packages/cjdns/debian/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: __PACKAGE__
Version: __VERSION__
Architecture: __ARCHITECTURE__
Maintainer: __MAINTAINER__
Section: net
Priority: optional
Homepage: __HOMEPAGE__
Description: An encrypted IPv6 network using public-key cryptography for
address allocation and a distributed hash table for routing.
19 changes: 19 additions & 0 deletions src/debian-packages/cjdns/debian/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh -e

## from /usr/share/debhelper/autoscripts/postinst-systemd-enable :

# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask cjdns.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled cjdns.service; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable cjdns.service >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state cjdns.service >/dev/null || true
fi

exit 0
21 changes: 21 additions & 0 deletions src/debian-packages/cjdns/debian/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh -e

## from /usr/share/debhelper/autoscripts/postrm-systemd :

if [ "$1" = "remove" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper mask cjdns.service >/dev/null
fi
fi

if [ "$1" = "purge" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge cjdns.service >/dev/null
deb-systemd-helper unmask cjdns.service >/dev/null
fi

# Remove user configurations
rm -rf /etc/cjdroute.conf
fi

exit 0
Empty file.
16 changes: 16 additions & 0 deletions src/debian-packages/cjdns/debian/usr/share/doc/cjdns/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This package was put together by

__MAINTAINER__

from sources obtained from

__SOURCE__

__PACKAGE__ may be used, modified and redistributed only under the terms of
the GNU General Public License, found in the file

/usr/share/common-licenses/GPL-3

on Debian systems, or at

http://www.fsf.org/licensing/licenses/gpl.html
26 changes: 26 additions & 0 deletions src/debian-packages/cjdns/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM resin/armv7hf-debian:stretch

ARG DEBIAN_FRONTEND=noninteractive

RUN [ "cross-build-start" ]

# Get tools
RUN { \
cd /tmp; \
apt-get update; \
apt-get install -y build-essential curl git python2.7; \
ln -s /usr/bin/python2.7 /usr/bin/python; \
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -; \
apt-get install -y nodejs; \
}

# Download source and build binary
ENTRYPOINT { \
mkdir /tmp/cjdns; \
git clone https://github.com/cjdelisle/cjdns.git -b __TAG__ /tmp/cjdns; \
cd /tmp/cjdns; \
git checkout __TAG__; \
NO_TEST=1 Seccomp_NO=1 ./do; \
}

RUN [ "cross-build-end" ]
7 changes: 3 additions & 4 deletions src/debian-packages/yggdrasil-go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ define package_deb_arch
sed -i "s|__MAINTAINER__|$(MAINTAINER)|g" $(BUILD_DIR)/debian/$(1)/debian/usr/share/doc/$(PACKAGE_NAME)/copyright # Replace __MAINTAINER__ macro in copyright file
sed -i "s|__SOURCE__|$(SOURCE_URL)|g" $(BUILD_DIR)/debian/$(1)/debian/usr/share/doc/$(PACKAGE_NAME)/copyright # Replace __SOURCE__ macro in copyright file
cp $(BUILD_DIR)/bin/$(1)/yggdrasil $(BUILD_DIR)/debian/$(1)/debian/usr/bin/ # Copy binary
chmod +x $(BUILD_DIR)/debian/$(1)/debian/usr/bin/yggdrasil # Make executable (not sure why it lost execution perm after copy)
mkdir -p $(BUILD_DIR)/debian/$(1)/debian/lib/systemd/system # Make directories for systemd service files
cp $(BUILD_DIR)/src/contrib/systemd/* $(BUILD_DIR)/debian/$(1)/debian/lib/systemd/system/ # Copy systemd service files
cd $(BUILD_DIR)/debian/$(1); \
Expand All @@ -40,14 +39,14 @@ package_deb: build_bin_amd64 build_bin_armhf
$(foreach arch,$(ARCHS),$(call package_deb_arch,$(arch));)

build_bin_amd64: download_source
mkdir -p $(BUILD_DIR)/bin/amd64
mkdir -p $(BUILD_DIR)/bin/amd64
cd $(BUILD_DIR)/src; \
./clean; \
./build; \
cp yggdrasil $(BUILD_DIR)/bin/amd64/

build_bin_armhf: download_source
mkdir -p $(BUILD_DIR)/bin/armhf
mkdir -p $(BUILD_DIR)/bin/armhf
cd $(BUILD_DIR)/src; \
./clean; \
GOARCH=arm GOARM=7 ./build; \
Expand All @@ -57,6 +56,6 @@ download_source: mkdir_build
git clone https://github.com/Arceliar/yggdrasil-go.git -b $(TAG) $(BUILD_DIR)/src

mkdir_build:
rm -rf $(BUILD_DIR)
sudo rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
mkdir -p $(OUTPUT_DIR)
Empty file modified src/debian-packages/yggdrasil-go/debian/usr/bin/yggdrasil
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ omitdebsrc=true

# mesh router
# TODO get selected mesh router from node-profiles
packages= yggdrasil-go
packages= cjdns yggdrasil-go

[Stretch]
source=http://httpredir.debian.org/debian
Expand Down

0 comments on commit ddc9a55

Please sign in to comment.