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