diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2015-05-16 01:06:01 +0200 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2015-05-16 01:06:01 +0200 |
commit | cde05af0f6f8406177d3075ef29470c46c8c7bfa (patch) | |
tree | 4c326c5dc7611f55ea54ed172c0c645e2eae53aa | |
parent | 2db8da301c90026fa01e4579ddae010c68f84e0a (diff) | |
download | bin-cde05af0f6f8406177d3075ef29470c46c8c7bfa.tar.xz |
Add ancient addstatip script
This script was used to add static IPs to dnsmasq's dhcp server when
running a small experiment cluster thing at school. Import so that it's
in the history.
-rwxr-xr-x | addstatip | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/addstatip b/addstatip new file mode 100755 index 0000000..6a7c0a2 --- /dev/null +++ b/addstatip @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh + +scriptname=${0##*/} + +usage() { + cat <<EOF +usage: $scriptname [mac] [ip] + +$scriptname assign ip to specified mac-address +EOF +} +if [[ -z $1 ]]; then + usage + exit 0 +fi + +zmodload zsh/mapfile + +dhosts_name=/etc/dnsmasq-dhcp_hosts.conf +dhosts=$mapfile[$dhosts_name] + +valid_mac="^([[:xdigit:]][[:xdigit:]]:?){6}$" + +if ! [[ $1 =~ $valid_mac ]] ; then + print >&2 "Invalid mac address.\n" + exit 1 +fi + +if print $dhosts | grep -q $1; then + printf >&2 "An entry with MAC-address %s already exists.\n" $1 + exit 1 +fi + +if print $dhosts | grep -q $2; then + printf >&2 "An entry with IP-address %s already exist.\n" $2 + exit 1 +fi + +print "$1,$2" >> $dhosts_name +pkill -x -HUP dnsmasq |