]> git.ipfire.org Git - people/ms/network.git/blame - src/udev/network-hotplug-rename
Use autotools.
[people/ms/network.git] / src / udev / network-hotplug-rename
CommitLineData
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.
23LOG_FACILITY="network-hotplug-rename"
24LOG_DISABLE_STDOUT="true"
25
26. /usr/lib/network/functions
27
28# Setup the locking.
29LOCKFILE="${RUN_DIR}/.rename_lock"
30function cleanup() {
31 lock_release ${LOCKFILE}
32}
33trap cleanup EXIT TERM KILL
a1a8f0f4
MT
34
35# Check if the INTERFACE variable is properly set.
36assert isset INTERFACE
37
8c63fa13
MT
38# Log what we are doing here.
39log DEBUG "Called for interface '${INTERFACE}'."
40
2eaf16f3
MT
41# Just check if the device has already vanished.
42device_exists ${INTERFACE} || exit ${EXIT_ERROR}
43
8c63fa13
MT
44# Acquiring lock for this operation.
45lock_acquire ${LOCKFILE}
46
2eaf16f3
MT
47# Check if the device is already in use and
48# prevent the script to touch it in any way.
49if ! device_is_free ${INTERFACE}; then
50 log ERROR "The device '${INTERFACE}' is in use."
51 exit ${EXIT_ERROR}
52fi
53
54# Determine the type of the device and then see what
55# we need to do with it.
56type=$(device_get_type ${INTERFACE})
57log DEBUG "Interface '${INTERFACE}' is of type '${type}'."
58
59case "${type}" in
60 ethernet|real)
61 # Search within all the port configurations
62 # if this port has already been configured.
63 for port in $(ports_get_all); do
64 port_cmd hotplug_rename ${port} ${INTERFACE} &>/dev/null
65 if [ $? -eq ${EXIT_TRUE} ]; then
66 echo "${port}"
67 exit ${EXIT_OK}
68 fi
69 done
70
71 # If no port configuration could be found,
72 # we search for the next unused name and return that.
73 port=$(port_find_free ${PORT_PATTERN})
74 echo "${port}"
75
76 log DEBUG "Could not find an existing port configuration for '${INTERFACE}'."
77 log DEBUG "${INTERFACE} --> ${port}"
78 ;;
79esac
a1a8f0f4 80
2eaf16f3 81exit ${EXIT_OK}