Skip to content

Commit 2e66bdd

Browse files
committed
Changes to work with Debian 12 bookworm
1 parent bb045c9 commit 2e66bdd

File tree

5 files changed

+44
-115
lines changed

5 files changed

+44
-115
lines changed

base.Pifile

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,16 @@ RUN debconf-set-selections <<EOF
5757
$(cat files/debconf)
5858
EOF
5959

60+
INSTALL files/wlan0 /etc/network/interfaces.d/wlan0
61+
RUN systemctl restart networking
62+
6063
INSTALL files/dnsmasq_hotspot.conf /etc/dnsmasq.d/hotspot.conf
6164
INSTALL files/hostapd.conf /etc/hostapd/hostapd.conf
6265
INSTALL files/hostapd_5ghz.conf /etc/hostapd/hostapd_5ghz.conf
6366

67+
INSTALL 644 files/99-usb.rules /etc/udev/rules.d/99-usb.rules
6468
INSTALL 755 files/usb-mount.sh /usr/local/bin/usb-mount.sh
65-
INSTALL files/[email protected] /etc/systemd/system/[email protected]
66-
67-
RUN tee /etc/dhcpcd.conf <<EOF
68-
interface wlan0
69-
static ip_address=10.10.10.10/24
70-
nohook resolv.conf, wpa_supplicant
71-
EOF
69+
INSTALL 755 files/[email protected] /etc/systemd/system/[email protected]
7270

7371
RUN tee /etc/default/hostapd <<EOF
7472
DAEMON_CONF="/etc/hostapd/hostapd.conf"
@@ -78,11 +76,6 @@ RUN tee /etc/default/dnsmasq <<EOF
7876
DNSMASQ_EXCEPT=lo
7977
EOF
8078

81-
RUN tee /etc/udev/rules.d/99-local.rules <<EOF
82-
KERNEL=="sd[a-z]*[0-9]", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/bin/systemctl start usb-mount@%k.service"
83-
KERNEL=="sd[a-z]*[0-9]", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="/bin/systemctl stop usb-mount@%k.service"
84-
EOF
85-
8679
RUN rm /etc/nginx/sites-enabled/default
8780

8881
RUN systemctl enable hostapd

files/99-usb.rules

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", ENV{ID_FS_TYPE}!="", ENV{SYSTEMD_WANTS}="usb-mount@%k.service"
2+

files/usb-mount.sh

Lines changed: 26 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,34 @@
1-
#!/usr/bin/env bash
2-
# If you are executing this script in cron with a restricted environment,
3-
# modify the shebang to specify appropriate path; /bin/bash in most distros.
4-
# And, also if you aren't comfortable using(abuse?) env command.
1+
#!/bin/bash
52

6-
# This script is based on https://serverfault.com/a/767079 posted
7-
# by Mike Blackwell, modified to our needs. Credits to the author.
3+
DEVICE="/dev/$1"
84

9-
# This script is called from systemd unit file to mount or unmount
10-
# a USB drive.
5+
MOUNT_OPTS=""
6+
FS_UID_GID="vfat exfat ntfs fuseblk"
117

12-
PATH="$PATH:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:/bin:/sbin"
13-
log="logger -t usb-mount.sh -s "
14-
15-
usage()
16-
{
17-
${log} "Usage: $0 {add|remove} device_name (e.g. sdb1)"
8+
# Get filesystem type
9+
FSTYPE=$(blkid -o value -s TYPE "$DEVICE")
10+
if [ -z "$FSTYPE" ]; then
11+
logger "usb-mount: No filesystem type found for $DEVICE"
1812
exit 1
19-
}
20-
21-
if [[ $# -ne 2 ]]; then
22-
usage
2313
fi
2414

25-
ACTION=$1
26-
DEVBASE=$2
27-
DEVICE="/dev/${DEVBASE}"
28-
29-
# See if this drive is already mounted, and if so where
30-
MOUNT_POINT=$(mount | grep ${DEVICE} | awk '{ print $3 }')
31-
32-
DEV_LABEL=""
33-
34-
do_mount()
35-
{
36-
if [[ -n ${MOUNT_POINT} ]]; then
37-
${log} "Warning: ${DEVICE} is already mounted at ${MOUNT_POINT}"
38-
exit 1
39-
fi
40-
41-
# Get info for this drive: $ID_FS_LABEL and $ID_FS_TYPE
42-
eval $(blkid -o udev ${DEVICE} | grep -i -e "ID_FS_LABEL" -e "ID_FS_TYPE")
43-
44-
# Figure out a mount point to use
45-
LABEL=${ID_FS_LABEL}
46-
if grep -q " /media/${LABEL} " /etc/mtab; then
47-
# Already in use, make a unique one
48-
LABEL+="-${DEVBASE}"
49-
fi
50-
DEV_LABEL="${LABEL}"
51-
52-
# Use the device name in case the drive doesn't have label
53-
if [ -z ${DEV_LABEL} ]; then
54-
DEV_LABEL="${DEVBASE}"
55-
fi
56-
57-
MOUNT_POINT="/media/${DEV_LABEL}"
58-
59-
${log} "Mount point: ${MOUNT_POINT}"
60-
61-
mkdir -p ${MOUNT_POINT}
62-
63-
# Global mount options
64-
OPTS="rw,relatime"
65-
66-
# File system type specific mount options
67-
if [[ ${ID_FS_TYPE} == "vfat" ]]; then
68-
OPTS+=",users,gid=100,umask=000,shortname=mixed,utf8=1,flush"
69-
fi
70-
71-
if ! mount -o ${OPTS} ${DEVICE} ${MOUNT_POINT}; then
72-
${log} "Error mounting ${DEVICE} (status = $?)"
73-
rmdir "${MOUNT_POINT}"
74-
exit 1
75-
else
76-
# Track the mounted drives
77-
echo "${MOUNT_POINT}:${DEVBASE}" | cat >> "/var/log/usb-mount.track"
78-
fi
79-
80-
${log} "Mounted ${DEVICE} at ${MOUNT_POINT}"
81-
}
82-
83-
do_unmount()
84-
{
85-
if [[ -z ${MOUNT_POINT} ]]; then
86-
${log} "Warning: ${DEVICE} is not mounted"
87-
else
88-
umount -l ${DEVICE}
89-
${log} "Unmounted ${DEVICE} from ${MOUNT_POINT}"
90-
/bin/rmdir "${MOUNT_POINT}"
91-
sed -i.bak "\@${MOUNT_POINT}@d" /var/log/usb-mount.track
92-
fi
93-
15+
# Get label or use device name
16+
LABEL=$(blkid -o value -s LABEL "$DEVICE")
17+
if [ -z "$LABEL" ]; then
18+
LABEL=$(basename "$DEVICE")
19+
fi
9420

95-
}
21+
MOUNT_POINT="/media/usb/$LABEL"
22+
if echo "$FS_UID_GID" | grep -qw "$FSTYPE"; then
23+
MOUNT_OPTS="-o uid=1000,gid=1000"
24+
fi
9625

97-
case "${ACTION}" in
98-
add)
99-
do_mount
100-
;;
101-
remove)
102-
do_unmount
103-
;;
104-
*)
105-
usage
106-
;;
107-
esac
26+
mkdir -p "$MOUNT_POINT"
27+
mount $MOUNT_OPTS "$DEVICE" "$MOUNT_POINT"
28+
if [ $? -eq 0 ]; then
29+
#chown -R 1000:1000 "$MOUNT_POINT"
30+
logger "usb-mount: Mounted $DEVICE at $MOUNT_POINT"
31+
else
32+
logger "usb-mount: Failed to mount $DEVICE"
33+
rmdir "$MOUNT_POINT"
34+
fi

files/[email protected]

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[Unit]
2-
Description=Mount USB Drive on %i
2+
Description=Mount USB Device
3+
After=dev-%i.device
4+
35
[Service]
46
Type=oneshot
5-
RemainAfterExit=true
6-
ExecStart=/usr/local/bin/usb-mount.sh add %i
7-
ExecStop=/usr/local/bin/usb-mount.sh remove %i
7+
ExecStart=/usr/local/bin/usb-mount.sh %I
8+
9+
[Install]
10+
WantedBy=multi-user.target

files/wlan0

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
allow-hotplug wlan0
2+
iface wlan0 inet static
3+
address 10.10.10.10
4+
netmask 255.255.255.0

0 commit comments

Comments
 (0)