summaryrefslogtreecommitdiffstats
path: root/source.local/n/NetworkManager/doinst.sh
blob: 6769a72ea6f9cbebf1eacaa8528c93382d3c5422 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

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