2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2023 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
25 logger
-t
"extrahd" "${message}"
29 local _mountpoint
="${1}"
37 while IFS
=';' read -r device filesystem mountpoint rest
; do
38 # Filter by UUID or mountpoint
39 case
"${_mountpoint}" in
41 if [ "${device}" != "${_mountpoint}" ]; then
47 if [ -n
"${_mountpoint}" ] && [ "${mountpoint}" != "${_mountpoint}" ]; then
53 # Check that the mountpoint starts with a slash
54 if [ "${mountpoint:0:1}" != "/" ]; then
55 log "Skipping invalid mountpoint: ${mountpoint}"
59 # Skip mounting if something is already mounted at the mountpoint
60 if mountpoint
"${mountpoint}" &>/dev/null
; then
64 # Ensure the mountpoint exists
65 mkdir --parents
--mode
=777 "${mountpoint}" &>/dev/null
67 if mount
--types
"${filesystem}" "${device}" "${mountpoint}"; then
68 log "Successfully mounted ${device} to ${mountpoint}"
70 log "Could not mount ${device} to ${mountpoint}: $?"
73 done
< /var/ipfire
/extrahd/devices
79 local _mountpoint
="${1}"
87 while IFS
=';' read -r device filesystem mountpoint rest
; do
88 # Filter by UUID or mountpoint
89 case
"${_mountpoint}" in
91 if [ "${device}" != "${_mountpoint}" ]; then
97 if [ -n
"${_mountpoint}" ] && [ "${mountpoint}" != "${_mountpoint}" ]; then
103 # Do not try to umount if nothing is mounted
104 if ! mountpoint
"${mountpoint}" &>/dev/null
; then
108 # Umount and try lazy umount if failed
109 if umount
--quiet
--recursive
"${mountpoint}" || \
110 umount
--quiet
--recursive
--lazy
"${mountpoint}"; then
111 log "Successfully umounted ${device} from ${mountpoint}"
113 log "Could not umount ${device} from ${mountpoint}: $?"
116 done
< /var/ipfire
/extrahd/devices
119 handle_udev_event
() {
122 if [ -n
"${ID_FS_UUID}" ]; then
123 extrahd_mount
"UUID=${ID_FS_UUID}" || return $?
132 ( echo
"$@"; set
) > /tmp/extrahd
.$$
141 extrahd_mount
"${@}" || rc
="${?}"
144 extrahd_umount
"${@}" || rc
="${rc}"
147 handle_udev_event
"${@}" || rc
="${rc}"
150 exec /usr/local/bin/scanhd
"${@}"
155 echo
"${0}: No command given" >&2
161 echo
"${0}: Unsupported command: ${command}" >&2
170 main
"${@}" || exit ${?
}