From 3089f2326e2ad3ab546662c29fa0a46b2ca4c4f3 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 1 Mar 2018 18:01:18 +0000 Subject: [PATCH 1/5] Add generate script for Debian .debs into contrib --- contrib/deb/generate.sh | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 contrib/deb/generate.sh diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh new file mode 100644 index 00000000..fed5c84f --- /dev/null +++ b/contrib/deb/generate.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# This is a lazy script to create a .deb for Debian/Ubuntu. It installs +# yggdrasil and enables it in systemd. You can give it the PKGARCH= argument +# i.e. PKGARCH=i386 sh contrib/deb/generate.sh + +if [ `pwd` != `git rev-parse --show-toplevel` ] +then + echo "You should run this script from the top-level directory of the git repo" + exit -1 +fi + +PKGNAME=debian-yggdrasil +PKGARCH=${PKGARCH-amd64} +PKGVERSION=0.$(git rev-list HEAD --count 2>/dev/null | xargs printf "%04d") +PKGFILE=$PKGNAME-$PKGVERSION-$PKGARCH.deb + +echo "Building $PKGFILE" + +mkdir -p /tmp/$PKGNAME/ +mkdir -p /tmp/$PKGNAME/debian/ +mkdir -p /tmp/$PKGNAME/usr/bin/ +mkdir -p /tmp/$PKGNAME/etc/systemd/system/ + +cat > /tmp/$PKGNAME/debian/changelog << EOF +Insert changelog here +EOF +echo 9 > /tmp/$PKGNAME/debian/compat +cat > /tmp/$PKGNAME/debian/control << EOF +Package: $PKGNAME +Version: $PKGVERSION +Section: contrib/net +Priority: extra +Architecture: $PKGARCH +Maintainer: Neil Alexander +Description: Debian yggdrasil package + Binary yggdrasil package for Debian and Ubuntu +EOF +cat > /tmp/$PKGNAME/debian/copyright << EOF +Insert copyright notice here +EOF +cat > /tmp/$PKGNAME/debian/docs << EOF +Insert docs here +EOF +cat > /tmp/$PKGNAME/debian/install << EOF +usr/bin/yggdrasil usr/bin +etc/systemd/system/*.service etc/systemd/system +EOF +cat > /tmp/$PKGNAME/debian/postinst << EOF +#!/bin/sh +systemctl enable yggdrasil +systemctl start yggdrasil +EOF +cat > /tmp/$PKGNAME/debian/prerm << EOF +#!/bin/sh +systemctl disable yggdrasil +systemctl stop yggdrasil +EOF + +GOOS=linux GOARCH=$PKGARCH ./build + +cp yggdrasil /tmp/$PKGNAME/usr/bin/ +cp contrib/systemd/yggdrasil.service /tmp/$PKGNAME/etc/systemd/system/ +cp contrib/systemd/yggdrasil-resume.service /tmp/$PKGNAME/etc/systemd/system/ + +tar -czvf /tmp/$PKGNAME/data.tar.gz -C /tmp/$PKGNAME/ \ + usr/bin/yggdrasil \ + etc/systemd/system/yggdrasil.service \ + etc/systemd/system/yggdrasil-resume.service +tar -czvf /tmp/$PKGNAME/control.tar.gz -C /tmp/$PKGNAME/debian . +echo 2.0 > /tmp/$PKGNAME/debian-binary + +ar -r $PKGFILE \ + /tmp/$PKGNAME/debian-binary \ + /tmp/$PKGNAME/control.tar.gz \ + /tmp/$PKGNAME/data.tar.gz + +rm -rf /tmp/$PKGNAME + From 9285e0fe25335b1d317747acf966e3cfa5a87200 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 1 Mar 2018 18:06:53 +0000 Subject: [PATCH 2/5] Mismatching GOARCH and debian arch --- contrib/deb/generate.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index fed5c84f..f3c64d85 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -57,7 +57,8 @@ systemctl disable yggdrasil systemctl stop yggdrasil EOF -GOOS=linux GOARCH=$PKGARCH ./build +if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build; fi +if [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build; fi cp yggdrasil /tmp/$PKGNAME/usr/bin/ cp contrib/systemd/yggdrasil.service /tmp/$PKGNAME/etc/systemd/system/ @@ -76,4 +77,3 @@ ar -r $PKGFILE \ /tmp/$PKGNAME/data.tar.gz rm -rf /tmp/$PKGNAME - From 390f7527f62bb2d47b9b020ffcba811c132b19a4 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 1 Mar 2018 18:28:37 +0000 Subject: [PATCH 3/5] Update generate.sh --- contrib/deb/generate.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index f3c64d85..891d3064 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -10,11 +10,18 @@ then exit -1 fi -PKGNAME=debian-yggdrasil +PKGNAME=yggdrasil PKGARCH=${PKGARCH-amd64} PKGVERSION=0.$(git rev-list HEAD --count 2>/dev/null | xargs printf "%04d") PKGFILE=$PKGNAME-$PKGVERSION-$PKGARCH.deb +if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build +elif [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build +else + echo "Specify PKGARCH=amd64 or PKGARCH=i386" + exit -1 +fi + echo "Building $PKGFILE" mkdir -p /tmp/$PKGNAME/ @@ -23,7 +30,7 @@ mkdir -p /tmp/$PKGNAME/usr/bin/ mkdir -p /tmp/$PKGNAME/etc/systemd/system/ cat > /tmp/$PKGNAME/debian/changelog << EOF -Insert changelog here +Please see https://github.com/Arceliar/yggdrasil-go/ EOF echo 9 > /tmp/$PKGNAME/debian/compat cat > /tmp/$PKGNAME/debian/control << EOF @@ -32,15 +39,15 @@ Version: $PKGVERSION Section: contrib/net Priority: extra Architecture: $PKGARCH -Maintainer: Neil Alexander +Maintainer: Neil Alexander Description: Debian yggdrasil package Binary yggdrasil package for Debian and Ubuntu EOF cat > /tmp/$PKGNAME/debian/copyright << EOF -Insert copyright notice here +Please see https://github.com/Arceliar/yggdrasil-go/ EOF cat > /tmp/$PKGNAME/debian/docs << EOF -Insert docs here +Please see https://github.com/Arceliar/yggdrasil-go/ EOF cat > /tmp/$PKGNAME/debian/install << EOF usr/bin/yggdrasil usr/bin @@ -57,9 +64,6 @@ systemctl disable yggdrasil systemctl stop yggdrasil EOF -if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build; fi -if [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build; fi - cp yggdrasil /tmp/$PKGNAME/usr/bin/ cp contrib/systemd/yggdrasil.service /tmp/$PKGNAME/etc/systemd/system/ cp contrib/systemd/yggdrasil-resume.service /tmp/$PKGNAME/etc/systemd/system/ From 3c1e00f23f54f1411018c5d63a5e54283bd424bc Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 2 Mar 2018 19:13:20 +0000 Subject: [PATCH 4/5] Add CircleCI config.yml This is an alternative to the TravisCI build file. CircleCI can automatically collect build artifacts which is nice! --- .circleci/config.yml | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..8cd85715 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,56 @@ +# Golang CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-go/ for more details +version: 2 +jobs: + build: + docker: + - image: circleci/golang:1.9 + + working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} + + steps: + - checkout + - run: + name: Create artifact upload directory + command: mkdir /tmp/upload + + - run: + name: Build for Linux (including Debian packages) + command: | + PKGARCH=amd64 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/yggdrasil-linux-amd64; + PKGARCH=i386 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/yggdrasil-linux-i386; + PKGARCH=mipsel sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/yggdrasil-linux-mipsel; + PKGARCH=mips sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/yggdrasil-linux-mips; + mv *.deb /tmp/upload/ + + - run: + name: Build for macOS + command: | + GOOS=darwin GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/yggdrasil-darwin-amd64; + GOOS=darwin GOARCH=386 ./build && mv yggdrasil /tmp/upload/yggdrasil-darwin-i386; + + - run: + name: Build for OpenBSD + command: | + GOOS=openbsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/yggdrasil-linux-amd64; + GOOS=openbsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/yggdrasil-linux-i386; + + - run: + name: Build for Windows + command: | + GOOS=windows GOARCH=amd64 ./build && mv yggdrasil.exe /tmp/upload/yggdrasil-windows-amd64.exe; + GOOS=windows GOARCH=386 ./build && mv yggdrasil.exe /tmp/upload/yggdrasil-windows-i386.exe; + + - run: + name: Build for EdgeRouter + command: | + git clone https://github.com/neilalexander/vyatta-yggdrasil /tmp/vyatta-yggdrasil; + cd /tmp/vyatta-yggdrasil; + BUILDDIR_YGG=$CIRCLE_WORKING_DIRECTORY ./build-edgerouter-x $CIRCLE_BRANCH; + BUILDDIR_YGG=$CIRCLE_WORKING_DIRECTORY ./build-edgerouter-lite $CIRCLE_BRANCH; + mv *.deb /tmp/upload; + + - store_artifacts: + path: /tmp/upload + destination: / From 674830799d157d3bf1a5a0bf720f7fe5bc7864b3 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 2 Mar 2018 22:36:22 +0000 Subject: [PATCH 5/5] Add branch name into repo name --- contrib/deb/generate.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index 891d3064..e2c98208 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -10,15 +10,19 @@ then exit -1 fi -PKGNAME=yggdrasil +PKGBRANCH=$(basename `git name-rev --name-only HEAD`) +if [ "$PKGBRANCH" = "master" ]; then PKGNAME=yggdrasil +else PKGNAME=yggdrasil-${PKGBRANCH}; fi PKGARCH=${PKGARCH-amd64} PKGVERSION=0.$(git rev-list HEAD --count 2>/dev/null | xargs printf "%04d") PKGFILE=$PKGNAME-$PKGVERSION-$PKGARCH.deb if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build elif [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build +elif [ $PKGARCH = "mipsel" ]; then GOARCH=mipsle GOOS=linux ./build +elif [ $PKGARCH = "mips" ]; then GOARCH=mips64 GOOS=linux ./build else - echo "Specify PKGARCH=amd64 or PKGARCH=i386" + echo "Specify PKGARCH=amd64,i386,mips,mipsel" exit -1 fi