tinc-up: add locale hook

This commit is contained in:
root 2015-01-01 23:40:56 +01:00
parent e37e5ec635
commit 20cfcba959
2 changed files with 12 additions and 10 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ ecdsa_key.priv
tinc.conf
tinc-macaddr
tinc-subnet
tinc-up.local

21
tinc-up
View File

@ -1,10 +1,6 @@
#!/usr/bin/env bash
set -eu
DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
MAC_ADDRESS_FILE=${DIR}/tinc-macaddr
TINC_SUBNET_FILE=${DIR}/tinc-subnet
has() {
command -v "$1" >/dev/null 2>&1
}
@ -74,8 +70,7 @@ start_dhcp() {
dhcpcd "$interface"
elif has dhclient; then
dhclient "$interface"
elif [[ "$OSTYPE" == "darwin"* ]]; then # TODO
untested
elif [[ "$OSTYPE" == "darwin"* ]]; then # TODO untested
ipconfig set "$interface" DHCP
else
die "no suitable dhcp program found, need dhcpcd or dhclient"
@ -84,6 +79,11 @@ start_dhcp() {
[ -z "${INTERFACE:-}" ] && die "no INTERFACE environment variable set"
DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
MAC_ADDRESS_FILE="${DIR}/tinc-macaddr"
SUBNET_FILE="${DIR}/tinc-subnet"
LOCAL_HOOK_FILE="${DIR}/tinc-up.local"
if [ ! -f "$MAC_ADDRESS_FILE" ]; then
die "${MAC_ADDRESS_FILE} does not exists. Generate it with ./tinc-generate-mac"
fi
@ -91,13 +91,14 @@ fi
read -r MAC_ADDRESS <"$MAC_ADDRESS_FILE"
set_mac "$INTERFACE" "$MAC_ADDRESS"
if [ -e $TINC_SUBNET_FILE ]; then
read -a SUBNET <"$TINC_SUBNET_FILE"
if [ -e $SUBNET_FILE ]; then
read -a SUBNET <"$SUBNET_FILE"
IP=${SUBNET[0]}
NETMASK=${SUBNET[1]}
[ -z "$IP" ] && die "no ip set in '$TINC_SUBNET_FILE'"
[ -z "$NETMASK" ] && die "no netmask set in '$TINC_SUBNET_FILE'"
[ -z "$IP" ] && die "no ip set in '$SUBNET_FILE'"
[ -z "$NETMASK" ] && die "no netmask set in '$SUBNET_FILE'"
set_ip "$INTERFACE" "$IP" "$NETMASK"
else
start_dhcp "$INTERFACE"
fi
[ -x "$LOCAL_HOOK_FILE" ] && "$LOCAL_HOOK_FILE"