-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-nm
More file actions
executable file
·76 lines (61 loc) · 2 KB
/
setup-nm
File metadata and controls
executable file
·76 lines (61 loc) · 2 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash -e
#This script will setup network connections in network manager automatically.
#I run with two settings on my system, dhcp and a static ip. This script will
#automatically set up network manager with the required connections.
#
#The static IP keyfile has been kept from the repository.
#
#More information:
# http://arstechnica.com/civis/viewtopic.php?t=1163023
# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html
#Make sure we are root
if [[ "$UID" != 0 ]] ; then
echo 'You must be root to do this.'
echo "usage: sudo $0"
exit 1
fi
#This scripts directory, used to find the pprint script
DIR=$(cd $(dirname "$0"); pwd)
source $DIR/pprint
#Location of the script's etc directory
ETC="$DIR/etc"
#This is the location for system connection key files
SYSCONS=/etc/NetworkManager/system-connections/
#Get the file name of the current auto-created Dhcp configuration
for f in $SYSCONS/* ; do
#Make sure the file is an ethernet file and setup for Dhcp
if grep -q '802-3-ethernet' "$f" && grep -q 'method=auto' "$f" ; then
DHCP="$f"
break
fi
done
if [ -z "$DHCP" ] ; then
die 'Failed to find the auto-created Dhcp network key file'
exit 2
fi
#Change the name of the connection to Dhcp
info 'Fixing Dhcp key file'
sed -i 's/^id=.*$/id=Dhcp/' "$DHCP"
info 'Locating mac-address'
MAC=$( grep 'mac-address=' $DHCP | cut -d '=' -f 2 )
if [ -z "$MAC" ] ; then
die 'Failed to discover the network mac address'
exit 3
fi
#Fix up and place the manual connections
info 'Placing manual configuration files'
for f in $ETC/* ; do
#Only process network manager key files
if ! grep -q '^\[802-3-ethernet\]' "$f" ; then
continue
fi
FNAME=$( basename "$f" )
DEST="$SYSCONS/$FNAME"
UUID=$( uuidgen )
info "\tPlacing $FNAME key file"
sed -e "s/mac-address=.*$/mac-address=$MAC/" \
-e "s/uuid=.*$/uuid=$UUID/" "$f" > "$DEST"
chmod 600 "$DEST"
done
info "Restarting network-manager"
service network-manager restart