This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex1-rename-net-dev.sh
executable file
·68 lines (54 loc) · 1.91 KB
/
ex1-rename-net-dev.sh
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
#!/bin/sh
# ex1-rename-net-dev.sh: Change the network interface name in systemd scripts
#
# Copyright 2013, 2014 Sudaraka Wijesinghe <sudaraka.org/contact>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
echo '';
echo 'ex1-rename-net-dev Copyright 2013, 2014 Sudaraka Wijesinghe';
echo 'This program comes with ABSOLUTELY NO WARRANTY;';
echo 'This is free software, and you are welcome to redistribute it';
echo 'under certain conditions under GNU GPLv3 or later.';
echo '';
ND_OLD=$1;
shift;
ND_NEW=$1;
if [ 0 -ne $UID ]; then
echo 'Please run as root';
exit 1;
fi;
# Validate new network device
if [ -z $ND_OLD ]; then
echo 'Current network interface name was not provided.';
exit 1;
fi;
if [ -z $ND_NEW ]; then
echo 'New network interface name was not provided.';
exit 1;
fi;
if [ -z "`ip link show $ND_NEW 2>/dev/null|grep \": $ND_NEW:\"`" ]; then
echo "Invalid network interface '$ND_NEW'";
exit 1;
fi;
echo "Current network interface : $ND_OLD";
echo "New network interface : $ND_NEW";
echo '';
read -n1 -s -p 'Press any key to continue';
echo '';
echo '';
# Start replacing device name
sed "s/$ND_OLD/$ND_NEW/g" -i /etc/systemd/network/*
mv /etc/systemd/system/multi-user.target.wants/wpa_supplicant\@{$ND_OLD,$ND_NEW}.service;
mv /etc/wpa_supplicant/wpa_supplicant-{$ND_OLD,$ND_NEW}.conf;