add tincrc
This commit is contained in:
parent
c92dd8f0b0
commit
de12862934
|
@ -2,10 +2,13 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
|
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
|
||||||
MACADDR_FILE="$DIR/tinc-macaddr"
|
TINCRC="$DIR/tincrc"
|
||||||
if [ -e "$MACADDR_FILE" ]; then
|
|
||||||
echo "Skip generating MAC: '$MACADDR_FILE' does already exists."
|
source "$TINCRC" || true
|
||||||
|
|
||||||
|
if [ -z "$MAC_ADDRESS" ]; then
|
||||||
|
echo "Skip generating MAC: MACDDR with value '$MAC_ADDRESS' already defined in '$TINCRC'."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Locally Administered Address Ranges:
|
# Locally Administered Address Ranges:
|
||||||
|
@ -14,8 +17,7 @@ else
|
||||||
#xA-xx-xx-xx-xx-xx
|
#xA-xx-xx-xx-xx-xx
|
||||||
#xE-xx-xx-xx-xx-xx
|
#xE-xx-xx-xx-xx-xx
|
||||||
# Replacing x with any hex value.
|
# Replacing x with any hex value.
|
||||||
printf '02:1F:%02X:%02X:%02X:%02X\n' \
|
printf 'export MAC_ADDRESS=02:1F:%02X:%02X:%02X:%02X\n' \
|
||||||
$[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] \
|
$[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] \
|
||||||
> "$MACADDR_FILE"
|
| tee -a "$TINCRC"
|
||||||
fi
|
fi
|
||||||
cat $MACADDR_FILE
|
|
||||||
|
|
39
tinc-up
39
tinc-up
|
@ -14,6 +14,11 @@ set_mac() {
|
||||||
local interface=$1
|
local interface=$1
|
||||||
local mac_address=$2
|
local mac_address=$2
|
||||||
if has ifconfig; then
|
if has ifconfig; then
|
||||||
|
current_mac=$(ifconfig "$interface" | awk '/ether/ {print $2}')
|
||||||
|
if [[ "${current_mac,,}" == "${mac_address,,}" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
ifconfig "$interface" down
|
ifconfig "$interface" down
|
||||||
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
||||||
ifconfig "$interface" hw ether "$mac_address"
|
ifconfig "$interface" hw ether "$mac_address"
|
||||||
|
@ -104,27 +109,37 @@ disable_ipv6_privacy() {
|
||||||
|
|
||||||
DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
|
DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
|
||||||
MAC_ADDRESS_FILE="${DIR}/tinc-macaddr"
|
MAC_ADDRESS_FILE="${DIR}/tinc-macaddr"
|
||||||
SUBNET_FILE="${DIR}/tinc-subnet"
|
|
||||||
LOCAL_HOOK_FILE="${DIR}/tinc-up.local"
|
LOCAL_HOOK_FILE="${DIR}/tinc-up.local"
|
||||||
|
TINCRC="${DIR}/tincrc"
|
||||||
|
|
||||||
if [ ! -f "$MAC_ADDRESS_FILE" ]; then
|
MAC_ADDRESS=""
|
||||||
die "${MAC_ADDRESS_FILE} does not exists. Generate it with ./tinc-generate-mac"
|
SUBNET=""
|
||||||
|
DHCP="YES"
|
||||||
|
IPV6_PRIVACY="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
|
fi
|
||||||
|
|
||||||
read -r MAC_ADDRESS <"$MAC_ADDRESS_FILE"
|
|
||||||
set_mac "$INTERFACE" "$MAC_ADDRESS"
|
set_mac "$INTERFACE" "$MAC_ADDRESS"
|
||||||
|
|
||||||
if [ -e $SUBNET_FILE ]; then
|
if [ -n "$SUBNET" ]; then
|
||||||
read -a SUBNET <"$SUBNET_FILE"
|
IFS=' ' read IP NETMASK <<< "SUBNET"
|
||||||
IP=${SUBNET[0]}
|
[ -z "$IP" ] && die "no ip set in SUBNET"
|
||||||
NETMASK=${SUBNET[1]}
|
[ -z "$NETMASK" ] && die "no netmask set in SUBNET"
|
||||||
[ -z "$IP" ] && die "no ip set in '$SUBNET_FILE'"
|
|
||||||
[ -z "$NETMASK" ] && die "no netmask set in '$SUBNET_FILE'"
|
|
||||||
set_ip "$INTERFACE" "$IP" "$NETMASK"
|
set_ip "$INTERFACE" "$IP" "$NETMASK"
|
||||||
else
|
fi
|
||||||
|
|
||||||
|
if [ "$DHCP" = "YES" ]; then
|
||||||
start_dhcp "$INTERFACE"
|
start_dhcp "$INTERFACE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
disable_ipv6_privacy "$INTERFACE"
|
if [[ "$IPV6_PRIVACY" != "YES" ]]; then
|
||||||
|
disable_ipv6_privacy "$INTERFACE"
|
||||||
|
fi
|
||||||
|
|
||||||
[ -x "$LOCAL_HOOK_FILE" ] && "$LOCAL_HOOK_FILE" || true
|
[ -x "$LOCAL_HOOK_FILE" ] && "$LOCAL_HOOK_FILE" || true
|
||||||
|
|
Loading…
Reference in New Issue