evenet/tinc-up

57 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2014-12-25 23:33:08 +00:00
#!/usr/bin/env bash
2014-12-25 20:47:26 +00:00
set -eu
2015-02-19 08:36:40 +00:00
if [[ -n "${TINC_DEBUG+1}" ]]; then
set -x
fi
2014-12-25 20:47:26 +00:00
2015-02-19 08:36:40 +00:00
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
source "$SCRIPT_DIR/lib/core.bash"
source "$SCRIPT_DIR/lib/cidr.bash"
source "$SCRIPT_DIR/lib/dhcp.bash"
source "$SCRIPT_DIR/lib/ip.bash"
source "$SCRIPT_DIR/lib/mac.bash"
source "$SCRIPT_DIR/lib/route.bash"
2014-12-25 20:47:26 +00:00
[ -z "${INTERFACE:-}" ] && die "no INTERFACE environment variable set"
2015-02-19 08:36:40 +00:00
MAC_ADDRESS_FILE="${SCRIPT_DIR}/tinc-macaddr"
LOCAL_HOOK_FILE="${SCRIPT_DIR}/tinc-up.local"
TINCRC="${SCRIPT_DIR}/tincrc"
2015-01-25 18:54:42 +00:00
MAC_ADDRESS=""
SUBNET=""
2015-01-26 12:53:10 +00:00
DHCP="yes"
2015-02-19 08:36:40 +00:00
ULA_IP6_TEMPLATE="fdc0:4992:6a6d:a:%x%x:%x%x::1"
PUBLIC_IP6_TEMPLATE="2a01:4f8:210:31fd:2:%x%x:%x%x:1"
2015-02-25 21:13:44 +00:00
PUBLIC_IP6=YES
ULA_IP6=YES
2015-01-26 12:53:10 +00:00
2015-01-25 18:54:42 +00:00
source "${TINCRC}" || true
2015-01-01 22:40:56 +00:00
2015-01-25 18:54:42 +00:00
if [ -z "$MAC_ADDRESS" ]; then
echo "${MAC_ADDRESS_FILE} does not exists. Generate it with ./tinc-generate-mac..."
"$DIR/tinc-generate-mac"
source "$TINCRC"
2014-12-25 20:47:26 +00:00
fi
set_mac "$INTERFACE" "$MAC_ADDRESS"
2015-02-19 08:36:40 +00:00
public_ip6="$(format_ip6_from_mac $PUBLIC_IP6_TEMPLATE $MAC_ADDRESS)"
ula_ip6="$(format_ip6_from_mac $ULA_IP6_TEMPLATE $MAC_ADDRESS)"
2015-02-25 21:13:44 +00:00
[[ "$PUBLIC_IP6" == "YES" ]] && add_ip6 "$INTERFACE" "$public_ip6" "80"
[[ "$ULA_IP6" == "YES" ]] && add_ip6 "$INTERFACE" "$ula_ip6" "64"
2015-02-19 08:36:40 +00:00
2015-01-25 18:54:42 +00:00
if [ -n "$SUBNET" ]; then
2015-01-26 12:53:10 +00:00
IFS=' ' read ip netmask <<< "$SUBNET"
[ -z "$ip" ] && die "no ip set in SUBNET"
[ -z "$netmask" ] && die "no netmask set in SUBNET"
2015-02-19 08:36:40 +00:00
add_ip4 "$INTERFACE" "$ip" "$netmask"
2015-01-25 18:54:42 +00:00
fi
2015-01-26 12:53:10 +00:00
if [ "${DHCP,,}" = "yes" ]; then
2014-12-25 23:30:02 +00:00
start_dhcp "$INTERFACE"
fi
2015-01-21 14:58:13 +00:00
2015-02-19 08:36:40 +00:00
[ -x "${SCRIPT_DIR}/tinc-up.local" ] && "${SCRIPT_DIR}/tinc-up.local" || true