2018-03-01 21:01:18 +03: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"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
2018-03-03 01:36:22 +03:00
|
|
|
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
|
2018-03-05 23:20:17 +03:00
|
|
|
PKGNAME=$(sh contrib/semver/name.sh)
|
|
|
|
PKGVERSION=$(sh contrib/semver/version.sh | cut -c 2-)
|
2018-03-01 21:01:18 +03:00
|
|
|
PKGARCH=${PKGARCH-amd64}
|
|
|
|
PKGFILE=$PKGNAME-$PKGVERSION-$PKGARCH.deb
|
2018-06-15 13:02:45 +03:00
|
|
|
PKGREPLACES=yggdrasil
|
|
|
|
|
|
|
|
if [ $PKGBRANCH = "master" ]; then
|
|
|
|
PKGREPLACES=yggdrasil-develop
|
|
|
|
fi
|
2018-03-01 21:01:18 +03:00
|
|
|
|
2018-03-01 21:28:37 +03:00
|
|
|
if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build
|
|
|
|
elif [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build
|
2018-03-03 01:36:22 +03:00
|
|
|
elif [ $PKGARCH = "mipsel" ]; then GOARCH=mipsle GOOS=linux ./build
|
|
|
|
elif [ $PKGARCH = "mips" ]; then GOARCH=mips64 GOOS=linux ./build
|
2018-03-16 13:10:44 +03:00
|
|
|
elif [ $PKGARCH = "armhf" ]; then GOARCH=arm GOOS=linux GOARM=7 ./build
|
2018-07-20 12:04:04 +03:00
|
|
|
elif [ $PKGARCH = "arm64" ]; then GOARCH=arm64 GOOS=linux ./build
|
2018-03-01 21:28:37 +03:00
|
|
|
else
|
2018-07-20 12:04:04 +03:00
|
|
|
echo "Specify PKGARCH=amd64,i386,mips,mipsel,armhf,arm64"
|
2018-03-01 21:28:37 +03:00
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
2018-03-01 21:01:18 +03:00
|
|
|
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
|
2018-06-15 13:02:45 +03:00
|
|
|
Please see https://github.com/yggdrasil-network/yggdrasil-go/
|
2018-03-01 21:01:18 +03: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 13:02:45 +03:00
|
|
|
Replaces: $PKGREPLACES
|
|
|
|
Conflicts: $PKGREPLACES
|
2018-03-01 21:28:37 +03:00
|
|
|
Maintainer: Neil Alexander <neilalexander@users.noreply.github.com>
|
2018-03-01 21:01:18 +03:00
|
|
|
Description: Debian yggdrasil package
|
|
|
|
Binary yggdrasil package for Debian and Ubuntu
|
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/copyright << EOF
|
2018-06-15 13:02:45 +03:00
|
|
|
Please see https://github.com/yggdrasil-network/yggdrasil-go/
|
2018-03-01 21:01:18 +03:00
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/docs << EOF
|
2018-06-15 13:02:45 +03:00
|
|
|
Please see https://github.com/yggdrasil-network/yggdrasil-go/
|
2018-03-01 21:01:18 +03:00
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/install << EOF
|
2018-05-23 15:26:08 +03:00
|
|
|
usr/bin/yggdrasil usr/bin
|
|
|
|
usr/bin/yggdrasilctl usr/bin
|
2018-03-01 21:01:18 +03:00
|
|
|
etc/systemd/system/*.service etc/systemd/system
|
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/postinst << EOF
|
|
|
|
#!/bin/sh
|
2018-05-23 15:26:08 +03:00
|
|
|
if [ -f /etc/yggdrasil.conf ];
|
|
|
|
then
|
2018-05-23 23:31:52 +03:00
|
|
|
mkdir -p /var/backups
|
|
|
|
echo "Backing up configuration file to /var/backups/yggdrasil.conf.`date +%Y%m%d`"
|
|
|
|
cp /etc/yggdrasil.conf /var/backups/yggdrasil.conf.`date +%Y%m%d`
|
|
|
|
echo "Normalising /etc/yggdrasil.conf"
|
|
|
|
/usr/bin/yggdrasil -useconffile /var/backups/yggdrasil.conf.`date +%Y%m%d` -normaliseconf > /etc/yggdrasil.conf
|
2018-05-23 15:26:08 +03:00
|
|
|
fi
|
2018-03-01 21:01:18 +03:00
|
|
|
systemctl enable yggdrasil
|
|
|
|
systemctl start yggdrasil
|
|
|
|
EOF
|
|
|
|
cat > /tmp/$PKGNAME/debian/prerm << EOF
|
|
|
|
#!/bin/sh
|
|
|
|
systemctl disable yggdrasil
|
|
|
|
systemctl stop yggdrasil
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cp yggdrasil /tmp/$PKGNAME/usr/bin/
|
2018-05-21 01:46:02 +03:00
|
|
|
cp yggdrasilctl /tmp/$PKGNAME/usr/bin/
|
2018-03-01 21:01:18 +03:00
|
|
|
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/ \
|
2018-05-21 01:59:42 +03:00
|
|
|
usr/bin/yggdrasil usr/bin/yggdrasilctl \
|
2018-03-01 21:01:18 +03:00
|
|
|
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
|