57 lines
1.5 KiB
Bash
Executable File
57 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eu
|
|
|
|
if [[ -n "${TINC_DEBUG+1}" ]]; then
|
|
set -x
|
|
fi
|
|
|
|
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"
|
|
|
|
[ -z "${INTERFACE:-}" ] && die "no INTERFACE environment variable set"
|
|
|
|
MAC_ADDRESS_FILE="${SCRIPT_DIR}/tinc-macaddr"
|
|
LOCAL_HOOK_FILE="${SCRIPT_DIR}/tinc-up.local"
|
|
TINCRC="${SCRIPT_DIR}/tincrc"
|
|
|
|
MAC_ADDRESS=""
|
|
SUBNET=""
|
|
DHCP="yes"
|
|
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"
|
|
PUBLIC_IP6=YES
|
|
ULA_IP6=YES
|
|
|
|
source "${TINCRC}" || true
|
|
|
|
if [ -z "$MAC_ADDRESS" ]; then
|
|
echo "${MAC_ADDRESS_FILE} does not exists. Generate it with ./tinc-generate-mac..."
|
|
"$DIR/tinc-generate-mac"
|
|
source "$TINCRC"
|
|
fi
|
|
|
|
set_mac "$INTERFACE" "$MAC_ADDRESS"
|
|
public_ip6="$(format_ip6_from_mac $PUBLIC_IP6_TEMPLATE $MAC_ADDRESS)"
|
|
ula_ip6="$(format_ip6_from_mac $ULA_IP6_TEMPLATE $MAC_ADDRESS)"
|
|
[[ "$PUBLIC_IP6" == "YES" ]] && add_ip6 "$INTERFACE" "$public_ip6" "80"
|
|
[[ "$ULA_IP6" == "YES" ]] && add_ip6 "$INTERFACE" "$ula_ip6" "64"
|
|
|
|
if [ -n "$SUBNET" ]; then
|
|
IFS=' ' read ip netmask <<< "$SUBNET"
|
|
[ -z "$ip" ] && die "no ip set in SUBNET"
|
|
[ -z "$netmask" ] && die "no netmask set in SUBNET"
|
|
add_ip4 "$INTERFACE" "$ip" "$netmask"
|
|
fi
|
|
|
|
if [ "${DHCP,,}" = "yes" ]; then
|
|
start_dhcp "$INTERFACE"
|
|
fi
|
|
|
|
[ -x "${SCRIPT_DIR}/tinc-up.local" ] && "${SCRIPT_DIR}/tinc-up.local" || true
|