github.com/yggdrasil-network/yggdrasil-go@v0.5.6/contrib/deb/generate.sh (about) 1 #!/bin/sh 2 3 # This is a lazy script to create a .deb for Debian/Ubuntu. It installs 4 # yggdrasil and enables it in systemd. You can give it the PKGARCH= argument 5 # i.e. PKGARCH=i386 sh contrib/deb/generate.sh 6 7 if [ `pwd` != `git rev-parse --show-toplevel` ] 8 then 9 echo "You should run this script from the top-level directory of the git repo" 10 exit 1 11 fi 12 13 PKGBRANCH=$(basename `git name-rev --name-only HEAD`) 14 PKGNAME=$(sh contrib/semver/name.sh) 15 PKGVERSION=$(sh contrib/semver/version.sh --bare) 16 PKGARCH=${PKGARCH-amd64} 17 PKGFILE=$PKGNAME-$PKGVERSION-$PKGARCH.deb 18 PKGREPLACES=yggdrasil 19 20 if [ $PKGBRANCH = "master" ]; then 21 PKGREPLACES=yggdrasil-develop 22 fi 23 24 GOLDFLAGS="-X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultConfig=/etc/yggdrasil/yggdrasil.conf" 25 GOLDFLAGS="${GOLDFLAGS} -X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultAdminListen=unix:///var/run/yggdrasil/yggdrasil.sock" 26 27 if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build -l "${GOLDFLAGS}" 28 elif [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build -l "${GOLDFLAGS}" 29 elif [ $PKGARCH = "mipsel" ]; then GOARCH=mipsle GOOS=linux ./build -l "${GOLDFLAGS}" 30 elif [ $PKGARCH = "mips" ]; then GOARCH=mips64 GOOS=linux ./build -l "${GOLDFLAGS}" 31 elif [ $PKGARCH = "armhf" ]; then GOARCH=arm GOOS=linux GOARM=6 ./build -l "${GOLDFLAGS}" 32 elif [ $PKGARCH = "arm64" ]; then GOARCH=arm64 GOOS=linux ./build -l "${GOLDFLAGS}" 33 elif [ $PKGARCH = "armel" ]; then GOARCH=arm GOOS=linux GOARM=5 ./build -l "${GOLDFLAGS}" 34 else 35 echo "Specify PKGARCH=amd64,i386,mips,mipsel,armhf,arm64,armel" 36 exit 1 37 fi 38 39 echo "Building $PKGFILE" 40 41 mkdir -p /tmp/$PKGNAME/ 42 mkdir -p /tmp/$PKGNAME/debian/ 43 mkdir -p /tmp/$PKGNAME/usr/bin/ 44 mkdir -p /tmp/$PKGNAME/lib/systemd/system/ 45 46 cat > /tmp/$PKGNAME/debian/changelog << EOF 47 Please see https://github.com/yggdrasil-network/yggdrasil-go/ 48 EOF 49 echo 9 > /tmp/$PKGNAME/debian/compat 50 cat > /tmp/$PKGNAME/debian/control << EOF 51 Package: $PKGNAME 52 Version: $PKGVERSION 53 Section: contrib/net 54 Priority: extra 55 Architecture: $PKGARCH 56 Replaces: $PKGREPLACES 57 Conflicts: $PKGREPLACES 58 Maintainer: Neil Alexander <neilalexander@users.noreply.github.com> 59 Description: Yggdrasil Network 60 Yggdrasil is an early-stage implementation of a fully end-to-end encrypted IPv6 61 network. It is lightweight, self-arranging, supported on multiple platforms and 62 allows pretty much any IPv6-capable application to communicate securely with 63 other Yggdrasil nodes. 64 EOF 65 cat > /tmp/$PKGNAME/debian/copyright << EOF 66 Please see https://github.com/yggdrasil-network/yggdrasil-go/ 67 EOF 68 cat > /tmp/$PKGNAME/debian/docs << EOF 69 Please see https://github.com/yggdrasil-network/yggdrasil-go/ 70 EOF 71 cat > /tmp/$PKGNAME/debian/install << EOF 72 usr/bin/yggdrasil usr/bin 73 usr/bin/yggdrasilctl usr/bin 74 lib/systemd/system/*.service lib/systemd/system 75 EOF 76 cat > /tmp/$PKGNAME/debian/postinst << EOF 77 #!/bin/sh 78 79 systemctl daemon-reload 80 81 if ! getent group yggdrasil 2>&1 > /dev/null; then 82 groupadd --system --force yggdrasil 83 fi 84 85 if [ ! -d /etc/yggdrasil ]; 86 then 87 mkdir -p /etc/yggdrasil 88 chown root:yggdrasil /etc/yggdrasil 89 chmod 750 /etc/yggdrasil 90 fi 91 92 if [ ! -f /etc/yggdrasil/yggdrasil.conf ]; 93 then 94 test -f /etc/yggdrasil.conf && mv /etc/yggdrasil.conf /etc/yggdrasil/yggdrasil.conf 95 fi 96 97 if [ -f /etc/yggdrasil/yggdrasil.conf ]; 98 then 99 mkdir -p /var/backups 100 echo "Backing up configuration file to /var/backups/yggdrasil.conf.`date +%Y%m%d`" 101 cp /etc/yggdrasil/yggdrasil.conf /var/backups/yggdrasil.conf.`date +%Y%m%d` 102 103 echo "Normalising and updating /etc/yggdrasil/yggdrasil.conf" 104 /usr/bin/yggdrasil -useconf -normaliseconf < /var/backups/yggdrasil.conf.`date +%Y%m%d` > /etc/yggdrasil/yggdrasil.conf 105 106 chown root:yggdrasil /etc/yggdrasil/yggdrasil.conf 107 chmod 640 /etc/yggdrasil/yggdrasil.conf 108 else 109 echo "Generating initial configuration file /etc/yggdrasil/yggdrasil.conf" 110 /usr/bin/yggdrasil -genconf > /etc/yggdrasil/yggdrasil.conf 111 112 chown root:yggdrasil /etc/yggdrasil/yggdrasil.conf 113 chmod 640 /etc/yggdrasil/yggdrasil.conf 114 fi 115 116 systemctl enable yggdrasil 117 systemctl restart yggdrasil 118 119 exit 0 120 EOF 121 cat > /tmp/$PKGNAME/debian/prerm << EOF 122 #!/bin/sh 123 if command -v systemctl >/dev/null; then 124 if systemctl is-active --quiet yggdrasil; then 125 systemctl stop yggdrasil || true 126 fi 127 systemctl disable yggdrasil || true 128 fi 129 EOF 130 131 cp yggdrasil /tmp/$PKGNAME/usr/bin/ 132 cp yggdrasilctl /tmp/$PKGNAME/usr/bin/ 133 cp contrib/systemd/yggdrasil-default-config.service.debian /tmp/$PKGNAME/lib/systemd/system/yggdrasil-default-config.service 134 cp contrib/systemd/yggdrasil.service.debian /tmp/$PKGNAME/lib/systemd/system/yggdrasil.service 135 136 tar --no-xattrs -czvf /tmp/$PKGNAME/data.tar.gz -C /tmp/$PKGNAME/ \ 137 usr/bin/yggdrasil usr/bin/yggdrasilctl \ 138 lib/systemd/system/yggdrasil.service \ 139 lib/systemd/system/yggdrasil-default-config.service 140 tar --no-xattrs -czvf /tmp/$PKGNAME/control.tar.gz -C /tmp/$PKGNAME/debian . 141 echo 2.0 > /tmp/$PKGNAME/debian-binary 142 143 ar -r $PKGFILE \ 144 /tmp/$PKGNAME/debian-binary \ 145 /tmp/$PKGNAME/control.tar.gz \ 146 /tmp/$PKGNAME/data.tar.gz 147 148 rm -rf /tmp/$PKGNAME