tinc-up: add locale hook
This commit is contained in:
parent
e37e5ec635
commit
20cfcba959
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ ecdsa_key.priv
|
|||||||
tinc.conf
|
tinc.conf
|
||||||
tinc-macaddr
|
tinc-macaddr
|
||||||
tinc-subnet
|
tinc-subnet
|
||||||
|
tinc-up.local
|
||||||
|
21
tinc-up
21
tinc-up
@ -1,10 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
|
|
||||||
MAC_ADDRESS_FILE=${DIR}/tinc-macaddr
|
|
||||||
TINC_SUBNET_FILE=${DIR}/tinc-subnet
|
|
||||||
|
|
||||||
has() {
|
has() {
|
||||||
command -v "$1" >/dev/null 2>&1
|
command -v "$1" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
@ -74,8 +70,7 @@ start_dhcp() {
|
|||||||
dhcpcd "$interface"
|
dhcpcd "$interface"
|
||||||
elif has dhclient; then
|
elif has dhclient; then
|
||||||
dhclient "$interface"
|
dhclient "$interface"
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then # TODO
|
elif [[ "$OSTYPE" == "darwin"* ]]; then # TODO untested
|
||||||
untested
|
|
||||||
ipconfig set "$interface" DHCP
|
ipconfig set "$interface" DHCP
|
||||||
else
|
else
|
||||||
die "no suitable dhcp program found, need dhcpcd or dhclient"
|
die "no suitable dhcp program found, need dhcpcd or dhclient"
|
||||||
@ -84,6 +79,11 @@ start_dhcp() {
|
|||||||
|
|
||||||
[ -z "${INTERFACE:-}" ] && die "no INTERFACE environment variable set"
|
[ -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
|
if [ ! -f "$MAC_ADDRESS_FILE" ]; then
|
||||||
die "${MAC_ADDRESS_FILE} does not exists. Generate it with ./tinc-generate-mac"
|
die "${MAC_ADDRESS_FILE} does not exists. Generate it with ./tinc-generate-mac"
|
||||||
fi
|
fi
|
||||||
@ -91,13 +91,14 @@ fi
|
|||||||
read -r MAC_ADDRESS <"$MAC_ADDRESS_FILE"
|
read -r MAC_ADDRESS <"$MAC_ADDRESS_FILE"
|
||||||
set_mac "$INTERFACE" "$MAC_ADDRESS"
|
set_mac "$INTERFACE" "$MAC_ADDRESS"
|
||||||
|
|
||||||
if [ -e $TINC_SUBNET_FILE ]; then
|
if [ -e $SUBNET_FILE ]; then
|
||||||
read -a SUBNET <"$TINC_SUBNET_FILE"
|
read -a SUBNET <"$SUBNET_FILE"
|
||||||
IP=${SUBNET[0]}
|
IP=${SUBNET[0]}
|
||||||
NETMASK=${SUBNET[1]}
|
NETMASK=${SUBNET[1]}
|
||||||
[ -z "$IP" ] && die "no ip set in '$TINC_SUBNET_FILE'"
|
[ -z "$IP" ] && die "no ip set in '$SUBNET_FILE'"
|
||||||
[ -z "$NETMASK" ] && die "no netmask set in '$TINC_SUBNET_FILE'"
|
[ -z "$NETMASK" ] && die "no netmask set in '$SUBNET_FILE'"
|
||||||
set_ip "$INTERFACE" "$IP" "$NETMASK"
|
set_ip "$INTERFACE" "$IP" "$NETMASK"
|
||||||
else
|
else
|
||||||
start_dhcp "$INTERFACE"
|
start_dhcp "$INTERFACE"
|
||||||
fi
|
fi
|
||||||
|
[ -x "$LOCAL_HOOK_FILE" ] && "$LOCAL_HOOK_FILE"
|
||||||
|
Loading…
Reference in New Issue
Block a user