Skip to content

Commit

Permalink
v7.0
Browse files Browse the repository at this point in the history
+ DietPi-Drive_Manager | Change comment in fstab to indicate that dietpi-drive_manager is not a must, but an offer, and that it overwrites and re-creates physical drive mount entries on use
+ DietPi-Drive_Manager | Append df/blkid/lsblk outputs to detection loops directly: It creates a temporary file as well, but assures a unique safe path and auto-removal in a native way, faster as well.
+ DietPi-Drive_Manager | Add /dev/root workaround right into df output pipe to let mawk handle the possibly left duplicate
  • Loading branch information
MichaIng authored Feb 15, 2021
1 parent 2dc001b commit 4171e1d
Showing 1 changed file with 14 additions and 33 deletions.
47 changes: 14 additions & 33 deletions dietpi/dietpi-drive_manager
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ tmpfs /var/log tmpfs size=${var_log_size:-50}M,noatime,lazytime,nodev,nosuid,mod

fi

echo "# Please use \"dietpi-drive_manager\" to setup mounts
echo "# You can use \"dietpi-drive_manager\" to setup mounts.
# NB: It overwrites and re-creates physical drive mount entries on use.
#----------------------------------------------------------------
# NETWORK
#----------------------------------------------------------------
Expand All @@ -151,21 +152,16 @@ $swap_mounts
# PHYSICAL DRIVES
#----------------------------------------------------------------" > $fp_fstab_tmp

# Detect mounted drives
G_DIETPI-NOTIFY 2 'Detecting drives, please wait...'

# Detect mounted drives via df
# - Exclude special treated fs types: tmpfs, ecryptfs, vboxsf, glusterfs
# - Workaround for /dev/root on RPi: Replace with actual device path $G_ROOTFS_DEV
# - Only detect mounts with "/" in source path, which excludes other special/pseudo fs types
# - Remove duplicates, which excludes bind mounts: https://github.com/MichaIng/DietPi/issues/2013#issuecomment-417413867
df -a --output=source --exclude-type=tmpfs --exclude-type=ecryptfs --exclude-type=vboxsf --exclude-type=glusterfs | mawk '/\// && !x[$0]++' > .df_out_tmp

# Process df result
# shellcheck disable=SC2094
# - Remove duplicates, e.g. from bind mounts and due to /dev/root conversion: https://github.com/MichaIng/DietPi/issues/2013#issuecomment-417413867
while read -r line
do

# Workaround for /dev/root under RPi, force physical location
[[ $line == '/dev/root' ]] && { grep -q "^$G_ROOTFS_DEV$" .df_out_tmp && continue || line=$G_ROOTFS_DEV; }

Init_New_Device

aDRIVE_ISMOUNTED[$index]=1
Expand Down Expand Up @@ -270,11 +266,9 @@ $swap_mounts

fi

done < .df_out_tmp
rm .df_out_tmp
done < <(df -a --output=source --exclude-type=tmpfs --exclude-type=ecryptfs --exclude-type=vboxsf --exclude-type=glusterfs | sed "\|^/dev/root$|c$G_ROOTFS_DEV" | mawk '/\// && !x[$0]++')

# Check blkid for unmounted drives, if drive is not mounted, add entry as disabled/commented mount
blkid -o device > .blkid_out_tmp
while read -r line
do

Expand All @@ -283,9 +277,7 @@ $swap_mounts
# Exclude drives already found
for i in "${aDRIVE_MOUNT_SOURCE[@]}"
do

[[ $i == $line* ]] && continue 2

[[ $i == "$line"* ]] && continue 2
done

# Must have a valid UUID! (this excludes /dev/mmcblk0)
Expand All @@ -311,12 +303,10 @@ $swap_mounts

echo "#UUID=${aDRIVE_UUID[$index]} ${aDRIVE_MOUNT_TARGET[$index]} ${type:-auto} noatime,lazytime,rw,nofail,noauto,x-systemd.automount" >> $fp_fstab_tmp

done < .blkid_out_tmp
rm .blkid_out_tmp
done < <(blkid -o device)

# Find unformated drives
# - Exclude mtdblock devices: https://github.com/MichaIng/DietPi/issues/2067#issuecomment-422400520
lsblk -nro NAME | sed '/^mtdblock[0-9]/d' > .lsblk_out_tmp
while read -r line
do

Expand All @@ -325,9 +315,7 @@ $swap_mounts
# Exclude drives already found
for i in "${aDRIVE_SOURCE_DEVICE[@]}"
do

[[ $line == $i* ]] && continue 2

done

G_DIETPI-NOTIFY 2 " - Detected unformated drive: /dev/$line"
Expand All @@ -338,8 +326,7 @@ $swap_mounts
aDRIVE_MOUNT_TARGET[$index]="/tmp/$line"
aDRIVE_SOURCE_DEVICE[$index]=$line

done < .lsblk_out_tmp
rm .lsblk_out_tmp
done < <(lsblk -nro NAME | sed '/^mtdblock[0-9]/d')

# Set required global flags and deps for all drives found
for i in "${!aDRIVE_MOUNT_SOURCE[@]}"
Expand Down Expand Up @@ -371,7 +358,6 @@ $swap_mounts
G_DIETPI-NOTIFY 0 'DEBUG INFO:'
for i in "${!aDRIVE_MOUNT_SOURCE[@]}"
do

G_DIETPI-NOTIFY 0 "Index=$i
aDRIVE_UUID ${aDRIVE_UUID[$i]}
aDRIVE_PART_UUID ${aDRIVE_PART_UUID[$i]}
Expand Down Expand Up @@ -422,15 +408,10 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]}
local i
[[ $MENU_DRIVE_TARGET ]] && for i in "${!aDRIVE_MOUNT_TARGET[@]}"
do

if [[ $MENU_DRIVE_TARGET == "${aDRIVE_MOUNT_TARGET[$i]}" ]]; then

MENU_DRIVE_INDEX=$i
[[ $G_DEBUG == 1 ]] && echo "[DEBUG$i] EDIT | ${aDRIVE_MOUNT_TARGET[$MENU_DRIVE_INDEX]} | ${aDRIVE_MOUNT_SOURCE[$MENU_DRIVE_INDEX]} | ${aDRIVE_SOURCE_DEVICE[$MENU_DRIVE_INDEX]}"
break

fi

[[ $MENU_DRIVE_TARGET == "${aDRIVE_MOUNT_TARGET[$i]}" ]] || continue
MENU_DRIVE_INDEX=$i
[[ $G_DEBUG == 1 ]] && echo "[DEBUG$i] EDIT | ${aDRIVE_MOUNT_TARGET[$MENU_DRIVE_INDEX]} | ${aDRIVE_MOUNT_SOURCE[$MENU_DRIVE_INDEX]} | ${aDRIVE_SOURCE_DEVICE[$MENU_DRIVE_INDEX]}"
break
done

}
Expand Down

0 comments on commit 4171e1d

Please sign in to comment.