config() { NEW="$1" OLD="$(dirname $NEW)/$(basename $NEW .new)" # If there's no config file by that name, mv it over: if [ ! -r $OLD ]; then mv $NEW $OLD elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then # toss the redundant copy rm $NEW fi # Otherwise, we leave the .new copy for the admin to consider... } preserve_perms() { NEW="$1" OLD="$(dirname ${NEW})/$(basename ${NEW} .new)" if [ -e ${OLD} ]; then cp -a ${OLD} ${NEW}.incoming cat ${NEW} > ${NEW}.incoming mv ${NEW}.incoming ${NEW} fi mv ${NEW} ${OLD} } if [ -e etc/HOSTNAME ]; then sed -i "s,yourhostname,$(cat etc/HOSTNAME | cut -f1 -d .)," \ etc/NetworkManager/NetworkManager.conf.new fi # Preserve permissions, but move this into place. Otherwise the net # connection could be lost at a remote location. preserve_perms etc/rc.d/rc.networkmanager.new config etc/NetworkManager/NetworkManager.conf.new # Since the .pid file may have relocated, we need to check both places # and restart if NetworkManager is in use: if [ -x /etc/rc.d/rc.networkmanager ]; then # Shut down any DHCP connections, otherwise the processes will be orphaned # and the connections will not come up when NetworkManager restarts. if ps ax | grep /sbin/dhcpcd | grep -q libexec/nm-dhcp ; then ps ax | grep /sbin/dhcpcd | grep libexec/nm-dhcp | while read line ; do kill -HUP $(echo $line | cut -b 1-5) done fi killall NetworkManager 2> /dev/null rm -f /var/run/NetworkManager/NetworkManager.pid rm -f /var/run/NetworkManager.pid sleep 5 sh /etc/rc.d/rc.networkmanager start fi