diff --git a/system/10-obscreen-media-automount.rules b/system/10-obscreen-media-automount.rules deleted file mode 100644 index d88377a..0000000 --- a/system/10-obscreen-media-automount.rules +++ /dev/null @@ -1,25 +0,0 @@ -# normally we start at sdb to ignore the system hard drive but we're in rpi, sdcard is the system hard drive -KERNEL!="sd[a-z]*", GOTO="obscreen_automount_end" -ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="obscreen_automount_end" - -# import some useful filesystem info as variables -IMPORT{program}="/sbin/blkid -o udev -p %N" - -# set mountpoint directory output -ENV{dir_name}="/home/pi/obscreen/var/run/storage" -ACTION=="add", RUN+="/bin/mkdir -p '%E{dir_name}'" - -# global mount options -ACTION=="add", ENV{mount_options}="relatime" - -# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat) -ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8" - -# automount all other filesystems -ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/usr/bin/systemd-mount --no-block --automount=yes --collect -o %E{mount_options} /dev/%k '%E{dir_name}'" - -# clean up after device removal -ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/bin/systemd-umount '%E{dir_name}'" - -# exit -LABEL="obscreen_automount_end" \ No newline at end of file diff --git a/system/autostart-browser-x11.sh b/system/autostart-browser-x11.sh old mode 100644 new mode 100755 diff --git a/system/external-storage/10-obscreen-media-automount.rules b/system/external-storage/10-obscreen-media-automount.rules new file mode 100644 index 0000000..b59ca80 --- /dev/null +++ b/system/external-storage/10-obscreen-media-automount.rules @@ -0,0 +1,6 @@ +KERNEL!="sd[a-z][0-9]*", GOTO="obscreen_automount_end" +ENV{dir_name}="/home/pi/obscreen/var/run/storage" +ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="obscreen_automount_end" +ACTION=="add", RUN+="/home/pi/obscreen/system/external-storage/obscreen-media-automount.sh /dev/%k '%E{dir_name}'" +ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/bin/systemd-umount '%E{dir_name}'" +LABEL="obscreen_automount_end" diff --git a/system/external-storage/obscreen-media-automount.sh b/system/external-storage/obscreen-media-automount.sh new file mode 100755 index 0000000..8d2d3a4 --- /dev/null +++ b/system/external-storage/obscreen-media-automount.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +MOUNT_DIR=$2 + +get_partition_size() { + local partition=$1 + lsblk -bno SIZE "$partition" +} + +find_largest_partition() { + local device=$1 + local largest_partition="" + local largest_size=0 + + for partition in $(lsblk -lnp "$device" | awk '{print $1}'); do + size=$(get_partition_size "$partition") + if (( size > largest_size )); then + largest_size=$size + largest_partition=$partition + fi + done + + echo $largest_partition +} + +# Get device (e.g., /dev/sda) +base_device=$(echo $1 | sed 's/[0-9]*$//') +largest_partition=$(find_largest_partition "$base_device") + +# Mount largest partition +if [ -n "$largest_partition" ]; then + mkdir -p "$MOUNT_DIR" + mount_options="relatime" + if blkid -o value -s TYPE "$largest_partition" | grep -qE "vfat|ntfs"; then + mount_options="$mount_options,gid=100,dmask=000,fmask=111,utf8" + if blkid -o value -s TYPE "$largest_partition" | grep -q "ntfs"; then + systemd-mount -t ntfs-3g --no-block --automount=yes --collect -o $mount_options "$largest_partition" "$MOUNT_DIR" + else + systemd-mount -t auto --no-block --automount=yes --collect -o $mount_options "$largest_partition" "$MOUNT_DIR" + fi + else + systemd-mount -t auto --no-block --automount=yes --collect -o $mount_options "$largest_partition" "$MOUNT_DIR" + fi + logger "Mounted $largest_partition with filesystem type $(blkid -o value -s TYPE "$largest_partition")" +fi diff --git a/system/install-autorun-rpi.sh b/system/install-autorun-rpi.sh old mode 100644 new mode 100755 index 8e8a093..8f00f30 --- a/system/install-autorun-rpi.sh +++ b/system/install-autorun-rpi.sh @@ -73,7 +73,7 @@ grep -qxF "needs_root_rights=yes" /etc/X11/Xwrapper.config || echo "needs_root_r curl https://raw.githubusercontent.com/jr-k/obscreen/master/system/obscreen-player.service | sed "s#/home/pi#$WORKING_DIR#g" | sed "s#=pi#=$OWNER#g" | tee /etc/systemd/system/obscreen-player.service # Configure external storage automount -curl https://raw.githubusercontent.com/jr-k/obscreen/master/system/10-obscreen-media-automount.rules | sed "s#/home/pi#$WORKING_DIR#g" | tee /etc/udev/rules.d/10-obscreen-media-automount.rules +curl https://raw.githubusercontent.com/jr-k/obscreen/master/system/external-storage/10-obscreen-media-automount.rules | sed "s#/home/pi#$WORKING_DIR#g" | tee /etc/udev/rules.d/10-obscreen-media-automount.rules udevadm control --reload-rules systemctl restart udev udevadm trigger