From a63a8b289a128125f88a905993d5da48ca8b95b5 Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 11 Aug 2017 01:44:06 +0200 Subject: Near full working prototype for autoDHCP --- Makefile | 2 ++ autoDHCP | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index a722122..859968e 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ install: sudo cp -i light2.sh /usr/bin/light2 sudo cp -i toMp3.sh /usr/bin/toMp3 sudo cp -i track.py /usr/bin/track + sudo cp -i autoDHCP /usr/bin/autoDHCP sudo chmod +rx /usr/bin/autoWall sudo chmod +rx /usr/bin/bot4chan sudo chmod +rx /usr/bin/coWifi @@ -15,3 +16,4 @@ install: sudo chmod +rx /usr/bin/light2 sudo chmod +rx /usr/bin/toMp3 sudo chmod +rx /usr/bin/track + sudo chmod +rx /usr/bin/autoDHCP diff --git a/autoDHCP b/autoDHCP index 5f52c70..aee73c9 100755 --- a/autoDHCP +++ b/autoDHCP @@ -7,14 +7,53 @@ range="/24" # Todo : List interface ✓ # Select first ✓ -# Select dhcpd or dnsmasq ❌ -# Select ip range ⍻ -# Select ip ⍻ -# Help ❌ -# Install from Makefile ❌ +# Select dhcpd or dnsmasq ✓ +# Select ip range ✓ +# Select ip ✓ +# Help ✓ +# Install from Makefile ✓ # Default interface is the first non-wireless interfaces (sorted alpha-num) +if [ "$1" == "dns" ] ; then + server="dnsmasq" + shift +fi + +if [ "$1" == "help" -o "$1" == "-h" -o "$1" == "--help" ] ; then + echo 'Usage : autoDHCP [interface] [ip/range] [dns]' + echo '' + echo 'You also put the server type at the start of the command' + echo 'Ex :' + echo '> autoDHCP wlp3s0 10.5.5.11/24' + echo '> autoDHCP eth0 192.168.0.1 dns' + echo '> autoDHCP dns eth0 192.168.0.1/30' +fi + + + +if [ "$1" ] ; then + interface="$1" + echo "Interface set to ${interface}" +fi + +if [ "$2" ] ; then + if [[ "$2" =~ .*/.* ]] ; then + ip=$(echo $2 | cut -d'/' -f1) + range="`echo $2 | cut -d'/' -f2 `" + echo "Range set to ${range}" + else + ip="$2" + fi + echo "Ip set to ${ip}" +fi + +if [ "$3" == "dns" ] ; then + server="dnsmasq" +fi + + + @@ -39,13 +78,13 @@ if [ -z "$interface" ] ; then guess_nowifi fi - - -echo "Working on $interface" - - - - sudo ip l set "$interface" up sudo ip a r "${ip}${range}" dev "$interface" -sudo /usr/bin/dhcpd -4 -q -pf /run/dhcpd4.pid "$interface" + +if [ "$server" == "dhcpd" ] ; then + sudo /usr/bin/dhcpd -4 -q -pf /run/dhcpd4.pid "$interface" +elif [ "$server" == "dnsmasq" ] ; then + echo 'Not yet implemented' +else + echo "Server name ${server} unknow" +fi -- cgit v1.2.3