]>
Commit | Line | Data |
---|---|---|
a1a8f0f4 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2011 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
8c63fa13 MT |
22 | # Setup logging. |
23 | LOG_FACILITY="network-hotplug-rename" | |
24 | LOG_DISABLE_STDOUT="true" | |
25 | ||
26 | . /usr/lib/network/functions | |
27 | ||
e9df08ad MT |
28 | # Read network settings |
29 | network_settings_read | |
df468241 | 30 | |
8c63fa13 MT |
31 | # Setup the locking. |
32 | LOCKFILE="${RUN_DIR}/.rename_lock" | |
1c6a4e30 | 33 | cleanup() { |
8c63fa13 MT |
34 | lock_release ${LOCKFILE} |
35 | } | |
36 | trap cleanup EXIT TERM KILL | |
a1a8f0f4 MT |
37 | |
38 | # Check if the INTERFACE variable is properly set. | |
39 | assert isset INTERFACE | |
40 | ||
8c63fa13 MT |
41 | # Log what we are doing here. |
42 | log DEBUG "Called for interface '${INTERFACE}'." | |
43 | ||
2eaf16f3 MT |
44 | # Just check if the device has already vanished. |
45 | device_exists ${INTERFACE} || exit ${EXIT_ERROR} | |
46 | ||
8c63fa13 MT |
47 | # Acquiring lock for this operation. |
48 | lock_acquire ${LOCKFILE} | |
49 | ||
2eaf16f3 MT |
50 | # Check if the device is already in use and |
51 | # prevent the script to touch it in any way. | |
52 | if ! device_is_free ${INTERFACE}; then | |
53 | log ERROR "The device '${INTERFACE}' is in use." | |
54 | exit ${EXIT_ERROR} | |
55 | fi | |
56 | ||
57 | # Determine the type of the device and then see what | |
58 | # we need to do with it. | |
59 | type=$(device_get_type ${INTERFACE}) | |
60 | log DEBUG "Interface '${INTERFACE}' is of type '${type}'." | |
61 | ||
62 | case "${type}" in | |
5dfc94a8 | 63 | ethernet) |
2eaf16f3 MT |
64 | # Search within all the port configurations |
65 | # if this port has already been configured. | |
66 | for port in $(ports_get_all); do | |
67 | port_cmd hotplug_rename ${port} ${INTERFACE} &>/dev/null | |
68 | if [ $? -eq ${EXIT_TRUE} ]; then | |
69 | echo "${port}" | |
70 | exit ${EXIT_OK} | |
71 | fi | |
72 | done | |
73 | ||
74 | # If no port configuration could be found, | |
75 | # we search for the next unused name and return that. | |
76 | port=$(port_find_free ${PORT_PATTERN}) | |
77 | echo "${port}" | |
78 | ||
7c9afeb4 MT |
79 | log DEBUG "Could not find an existing port configuration for '${INTERFACE}'" |
80 | log DEBUG "Renaming interface '${INTERFACE}' to '${port}'" | |
2eaf16f3 MT |
81 | ;; |
82 | esac | |
a1a8f0f4 | 83 | |
2eaf16f3 | 84 | exit ${EXIT_OK} |