Initial version

This commit is contained in:
Knut Ahlers 2022-06-20 17:42:25 +02:00
commit 77b1d27c7f
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
5 changed files with 91 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
*
!config.default
!.gitignore
!he-tunnel
!he-tunnel.service
!PKGBUILD

24
PKGBUILD Normal file
View file

@ -0,0 +1,24 @@
pkgname=he-tunnel
pkgver=0.1.0
pkgrel=1
pkgdesc="Tunnel setup script and service"
arch=(any)
backup=('etc/default/he-tunnel')
license=('MIT')
depends=('curl' 'iproute2')
source=(
config.default
he-tunnel
he-tunnel.service
)
sha512sums=(
'49b4970ca50bd6858111edaa756f31b860e02cbbe336691b28f69dd0cdd74b818d43c4a16a3c272834c4f056bcbb65eb78bfbc3bdac236684f1311918a8114f6'
'78e3c2fbedba6b106eb682d0e493a7169787fba4c4b03f3d9e6fe32d14e25348cc5bb6c3cf95da7f551802b25f819c524daeea9e9f696fe3256d9b38585c75b8'
'11073404bc2f62ea0f104e03858777793079edad657571c9ab8893a50acfbbe64648d126d8625592cef464f25b9304bd04e2d381f630e320a01cccd61b3c039b'
)
package() {
install -Dm 0600 config.default "${pkgdir}/etc/default/he-tunnel"
install -Dm 0644 he-tunnel.service "${pkgdir}/etc/systemd/system/he-tunnel.service"
install -Dm 0755 he-tunnel "${pkgdir}/usr/bin/he-tunnel"
}

7
config.default Normal file
View file

@ -0,0 +1,7 @@
UPDATE_KEY=""
UPDATE_USER=""
TUNNEL_CLIENT_ADDR=""
TUNNEL_ID=""
TUNNEL_LOCAL=""
TUNNEL_REMOTE=""

42
he-tunnel Executable file
View file

@ -0,0 +1,42 @@
#!/bin/bash
set -euo pipefail
DEFAULT_CFG=/etc/default/he-tunnel
function log() {
echo "$@" >&2
}
[[ -f $DEFAULT_CFG ]] || {
echo "Missing default config: ${DEFAULT_CFG}"
exit 1
}
source ${DEFAULT_CFG}
case $1 in
start)
log "Configuring tunnel interface..."
/usr/bin/ip tunnel add he-ipv6 mode sit remote ${TUNNEL_REMOTE} local ${TUNNEL_LOCAL} ttl 255
/usr/bin/ip link set he-ipv6 up mtu 1480
/usr/bin/ip addr add ${TUNNEL_CLIENT_ADDR} dev he-ipv6
/usr/bin/ip -6 route add ::/0 dev he-ipv6
log "Tunnel interface configured."
;;
stop)
log "Removing tunnel interface configuration..."
/usr/bin/ip -6 route del ::/0 dev he-ipv6
/usr/bin/ip link set he-ipv6 down
/usr/bin/ip tunnel del he-ipv6
log "Tunnel interface removed."
;;
update-ip)
log "Updating remote IP with tunnel broker..."
curl -4 -sSf \
-o /dev/null \
"https://${UPDATE_USER}:${UPDATE_KEY}@ipv4.tunnelbroker.net/nic/update?hostname=${TUNNEL_ID}"
log "IP updated."
;;
esac

12
he-tunnel.service Normal file
View file

@ -0,0 +1,12 @@
[Unit]
Description=he.net IPv6 tunnel
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/he-tunnel start
ExecStop=/usr/bin/he-tunnel stop
[Install]
WantedBy=multi-user.target