Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- F=/tmp/out-$RANDOM
- C=/etc/network/interfaces
- H=/etc/hostname
- R=/etc/resolv.conf
- HN=$(hostname)
- IP=$(ifconfig eth0 | grep inet\ | awk '{print $2}' | cut -f 2 -d :)
- MSK=$(ifconfig eth0 | grep inet\ | awk '{print $4}' | cut -f 2 -d :)
- GW=$(route -n|tail -1| awk '{print $2}')
- NS=$(cat $R|grep nameserver|awk '{print $2}')
- function c() { echo $1 | tr '.' '\n' | wc -l; }
- function inp() {
- OK=1
- while [ $OK -eq 1 ] ; do
- dialog --no-collapse --nocancel --title "IP configuration" \
- --form "Please enter network settings"\
- 0 0 0\
- "Hostname (FQDN)" 1 1 "$HN" 1 20 24 0 \
- "IP address" 2 1 "$IP" 2 20 20 0 \
- "Netmask" 3 1 "$MSK" 3 20 20 0 \
- "Gateway" 4 1 "$GW" 4 20 20 0 \
- "Name server" 5 1 "$NS" 5 20 20 0 \
- 2> $F && {
- HN=$(cat $F | head -1)
- IP=$(cat $F | head -2 | tail -1)
- MSK=$(cat $F | head -3 | tail -1)
- GW=$(cat $F | head -4 | tail -1)
- NS=$(cat $F | head -5 | tail -1)
- OK=0
- [ $(c $HN) -lt 2 ] && { dialog --msgbox "Hostname must be FQDN" 6 32 ; OK=1; }
- [ $OK=0 -a $(c $IP) -lt 4 ] && { dialog --msgbox "Invalid IP address" 6 32 ; OK=1; }
- [ $OK=0 -a $(c $MSK) -lt 4 ] && { dialog --msgbox "Invalid network mask" 6 32 ; OK=1; }
- [ $OK=0 -a $(c $GW) -lt 4 ] && { dialog --msgbox "Invalid gateway address" 6 32 ; OK=1; }
- [ $OK=0 -a $(c $NS) -lt 4 ] && { dialog --msgbox "Invalid name server address" 6 32 ; OK=1; }
- }
- if [ $? -eq 255 ] ; then { rm $F ; return; } fi
- done
- echo -e "auto lo\niface lo inet loopback\n\nauto eth0\niface eth0 inet static" > $C
- echo " address $IP">>$C
- echo " netmask $MSK">>$C
- echo " gateway $GW">>$C
- chgrp www-data $C
- chmod 664 $C
- echo $HN > $H
- hostname -F $H
- perl -p -i -e "s/^$IP\s.*/$IP $HN $(echo $HN|cut -f 1 -d .)/" /etc/hosts
- grep -q "$IP[ ]" /etc/hosts || echo "$IP $HN $(echo $HN|cut -f 1 -d .)" >>/etc/hosts
- perl -p -i -e "s/option domain-name \"[^\"]*\";/option domain-name \"`dnsdomainname`\";/" /etc/dhcpd.conf
- perl -p -i -e "s/option domain-name-servers .*/option domain-name-servers $NS;/" /etc/dhcpd.conf
- perl -p -i -e "s/option subnet-mask .*/option subnet-mask $MSK;/" /etc/dhcpd.conf
- perl -p -i -e "s/next-server .*/next-server $IP;/" /etc/dhcpd.conf
- perl -p -i -e "s/option routers .*/option routers $GW;/" /etc/dhcpd.conf
- echo search $(dnsdomainname) > $R
- echo nameserver $NS >> $R
- /etc/init.d/networking restart
- rm $F
- }
- [ -s /etc/network/interfaces ] || {
- inp
- }
- while [ true ]; do
- dialog --colors --no-collapse --nocancel --title Configuration --menu \
- "\nhostname: $(hostname)\n\nPlease connect to \n http://$IP" 17 0 6 \
- "Access log" "" "Error log" "" Reconfigure "" Reboot "" Shutdown "" 2> $F
- O=$(head -1 $F)
- case $O in
- "Access log") dialog --title "scroll left/right with 'h' and 'l' or arrows" --tailbox /var/log/lighttpd/access.log 0 0;;
- "Error log") dialog --title "scroll left/right with 'h' and 'l' or arrows" --tailbox /var/log/lighttpd/error.log 0 0;;
- "Reconfigure") inp;;
- "Reboot") shutdown -r now;;
- "Shutdown") shutdown -h now;;
- *) sleep 1;;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement