2018-03-01 18:01:18 +00:00
|
|
|
#!/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"
|
2018-12-08 10:33:33 +00:00
|
|
|
exit 1
|
2018-03-01 18:01:18 +00:00
|
|
|
fi
|
|
|
|
|
2018-03-02 22:36:22 +00:00
|
|
|
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
|
2018-03-05 20:20:17 +00:00
|
|
|
PKGNAME=$(sh contrib/semver/name.sh)
|
2018-12-08 10:54:47 +00:00
|
|
|
PKGVERSION=$(sh contrib/semver/version.sh --bare)
|
2018-03-01 18:01:18 +00:00
|
|
|
PKGARCH=${PKGARCH-amd64}
|
|
|
|
PKGFILE=$PKGNAME-$PKGVERSION-$PKGARCH.deb
|
2018-06-15 10:02:45 +00:00
|
|
|
PKGREPLACES=yggdrasil
|
|
|
|
|
|
|
|
if [ $PKGBRANCH = "master" ]; then
|
|
|
|
PKGREPLACES=yggdrasil-develop
|
|
|
|
fi
|
2018-03-01 18:01:18 +00:00
|
|
|
|
2023-10-28 13:58:52 +00:00
|
|
|
export LDFLAGS="-X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultConfig=/etc/yggdrasil/yggdrasil.conf"
|
|
|
|
export LDFLAGS="${LDFLAGS} -X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultAdminListen=unix://var/run/yggdrasil/yggdrasil.sock"
|
|
|
|
|
2018-03-01 18:28:37 +00:00
|
|
|
if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build
|
|
|
|
elif [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build
|
2018-03-02 22:36:22 +00:00
|
|
|
elif [ $PKGARCH = "mipsel" ]; then GOARCH=mipsle GOOS=linux ./build
|
|
|
|
elif [ $PKGARCH = "mips" ]; then GOARCH=mips64 GOOS=linux ./build
|
2018-12-18 17:28:15 +00:00
|
|
|
elif [ $PKGARCH = "armhf" ]; then GOARCH=arm GOOS=linux GOARM=6 ./build
|
2018-07-20 09:04:04 +00:00
|
|
|
elif [ $PKGARCH = "arm64" ]; then GOARCH=arm64 GOOS=linux ./build
|
2019-04-07 19:06:24 +00:00
|
|
|
elif [ $PKGARCH = "armel" ]; then GOARCH=arm GOOS=linux GOARM=5 ./build
|
2018-03-01 18:28:37 +00:00
|
|
|
else
|
2019-04-07 22:14:37 +00:00
|
|
|
echo "Specify PKGARCH=amd64,i386,mips,mipsel,armhf,arm64,armel"
|
2018-12-08 10:33:33 +00:00
|
|
|
exit 1
|
2018-03-01 18:28:37 +00:00
|
|
|
fi
|
|
|
|
|
2018-03-01 18:01:18 +00:00
|
|
|
echo "Building $PKGFILE"
|
|
|
|
|
|
|
|
mkdir -p /tmp/$PKGNAME/
|
|
|
|
mkdir -p /tmp/$PKGNAME/debian/
|
|
|
|
mkdir -p /tmp/$PKGNAME/usr/bin/
|
2023-10-28 13:58:52 +00:00
|
|
|
mkdir -p /tmp/$PKGNAME/usr/lib/systemd/system/
|
2018-03-01 18:01:18 +00:00
|
|
|
|
|
|
|
cat > /tmp/$PKGNAME/debian/changelog << EOF
|
2018-06-15 10:02:45 +00:00
|
|
|
Please see https://github.com/yggdrasil-network/yggdrasil-go/
|
2018-03-01 18:01:18 +00:00
|
|
|
EOF
|
|
|
|
echo 9 > /tmp/$PKGNAME/debian/compat
|
|
|
|
cat > /tmp/$PKGNAME/debian/control << EOF
|
|
|
|
Package: $PKGNAME
|
|
|
|
Version: $PKGVERSION
|
|
|
|
Section: contrib/net
|
|
|
|
Priority: extra
|
|
|
|
Architecture: $PKGARCH
|
2018-06-15 10:02:45 +00:00
|
|
|
Replaces: $PKGREPLACES
|
|
|
|
Conflicts: $PKGREPLACES
|
2018-03-01 18:28:37 +00:00
|
|
|
Maintainer: Neil Alexander <neilalexander@users.noreply.github.com>
|
2018-12-12 20:29:56 +00:00
|
|
|
Description: Yggdrasil Network
|
|
|
|
Yggdrasil is an early-stage implementation of a fully end-to-end encrypted IPv6
|
|
|
|
network. It is lightweight, self-arranging, supported on multiple platforms and
|
|
|
|
allows pretty much any IPv6-capable application to communicate securely with
|
|
|
|
other Yggdrasil nodes.
|
2018-03-01 18:01:18 +00:00
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/copyright << EOF
|
2018-06-15 10:02:45 +00:00
|
|
|
Please see https://github.com/yggdrasil-network/yggdrasil-go/
|
2018-03-01 18:01:18 +00:00
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/docs << EOF
|
2018-06-15 10:02:45 +00:00
|
|
|
Please see https://github.com/yggdrasil-network/yggdrasil-go/
|
2018-03-01 18:01:18 +00:00
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/install << EOF
|
2018-05-23 12:26:08 +00:00
|
|
|
usr/bin/yggdrasil usr/bin
|
|
|
|
usr/bin/yggdrasilctl usr/bin
|
2023-10-28 13:58:52 +00:00
|
|
|
usr/lib/systemd/system/*.service usr/lib/systemd/system
|
2018-03-01 18:01:18 +00:00
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/postinst << EOF
|
|
|
|
#!/bin/sh
|
2018-12-14 14:25:26 +00:00
|
|
|
|
2023-10-28 13:58:52 +00:00
|
|
|
systemctl daemon-reload
|
|
|
|
|
2018-12-14 14:25:26 +00:00
|
|
|
if ! getent group yggdrasil 2>&1 > /dev/null; then
|
2023-10-28 13:58:52 +00:00
|
|
|
groupadd --system --force yggdrasil
|
2018-12-14 14:25:26 +00:00
|
|
|
fi
|
|
|
|
|
2023-10-28 13:58:52 +00:00
|
|
|
if [ ! -d /etc/yggdrasil ];
|
|
|
|
then
|
|
|
|
mkdir -p /etc/yggdrasil
|
|
|
|
chown root:yggdrasil /etc/yggdrasil
|
|
|
|
chmod 750 /etc/yggdrasil
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /etc/yggdrasil/yggdrasil.conf ];
|
|
|
|
then
|
|
|
|
test -f /etc/yggdrasil.conf && mv /etc/yggdrasil.conf /etc/yggdrasil/yggdrasil.conf
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /etc/yggdrasil/yggdrasil.conf ];
|
2018-05-23 12:26:08 +00:00
|
|
|
then
|
2018-05-23 20:31:52 +00:00
|
|
|
mkdir -p /var/backups
|
|
|
|
echo "Backing up configuration file to /var/backups/yggdrasil.conf.`date +%Y%m%d`"
|
2023-10-28 13:58:52 +00:00
|
|
|
cp /etc/yggdrasil/yggdrasil.conf /var/backups/yggdrasil.conf.`date +%Y%m%d`
|
|
|
|
|
|
|
|
echo "Normalising and updating /etc/yggdrasil/yggdrasil.conf"
|
|
|
|
/usr/bin/yggdrasil -useconf -normaliseconf < /var/backups/yggdrasil.conf.`date +%Y%m%d` > /etc/yggdrasil/yggdrasil.conf
|
|
|
|
|
|
|
|
chown root:yggdrasil /etc/yggdrasil/yggdrasil.conf
|
|
|
|
chmod 640 /etc/yggdrasil/yggdrasil.conf
|
2018-12-14 14:25:26 +00:00
|
|
|
else
|
2023-10-28 13:58:52 +00:00
|
|
|
echo "Generating initial configuration file /etc/yggdrasil/yggdrasil.conf"
|
|
|
|
/usr/bin/yggdrasil -genconf > /etc/yggdrasil/yggdrasil.conf
|
|
|
|
|
|
|
|
chown root:yggdrasil /etc/yggdrasil/yggdrasil.conf
|
|
|
|
chmod 640 /etc/yggdrasil/yggdrasil.conf
|
2018-12-12 20:29:56 +00:00
|
|
|
fi
|
2023-10-28 13:58:52 +00:00
|
|
|
|
|
|
|
systemctl enable yggdrasil
|
|
|
|
systemctl restart yggdrasil
|
|
|
|
|
|
|
|
exit 0
|
2018-03-01 18:01:18 +00:00
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/prerm << EOF
|
|
|
|
#!/bin/sh
|
2018-12-12 20:29:56 +00:00
|
|
|
if command -v systemctl >/dev/null; then
|
|
|
|
if systemctl is-active --quiet yggdrasil; then
|
|
|
|
systemctl stop yggdrasil || true
|
|
|
|
fi
|
2018-12-14 14:25:26 +00:00
|
|
|
systemctl disable yggdrasil || true
|
2018-12-12 20:29:56 +00:00
|
|
|
fi
|
2018-03-01 18:01:18 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cp yggdrasil /tmp/$PKGNAME/usr/bin/
|
2018-05-20 22:46:02 +00:00
|
|
|
cp yggdrasilctl /tmp/$PKGNAME/usr/bin/
|
2023-10-28 13:58:52 +00:00
|
|
|
cp contrib/systemd/yggdrasil-default-config.service.debian /tmp/$PKGNAME/usr/lib/systemd/system/yggdrasil-default-config.service
|
|
|
|
cp contrib/systemd/yggdrasil.service.debian /tmp/$PKGNAME/usr/lib/systemd/system/yggdrasil.service
|
2018-03-01 18:01:18 +00:00
|
|
|
|
2023-10-28 13:58:52 +00:00
|
|
|
tar --no-xattrs -czvf /tmp/$PKGNAME/data.tar.gz -C /tmp/$PKGNAME/ \
|
2018-05-20 22:59:42 +00:00
|
|
|
usr/bin/yggdrasil usr/bin/yggdrasilctl \
|
2023-10-28 13:58:52 +00:00
|
|
|
usr/lib/systemd/system/yggdrasil.service \
|
|
|
|
usr/lib/systemd/system/yggdrasil-default-config.service
|
|
|
|
tar --no-xattrs -czvf /tmp/$PKGNAME/control.tar.gz -C /tmp/$PKGNAME/debian .
|
2018-03-01 18:01:18 +00:00
|
|
|
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
|