Last active
January 6, 2024 00:17
-
-
Save GloriousEggroll/81a4685aa34f5a0fe2587bb78f64491c to your computer and use it in GitHub Desktop.
Tries to mount any partitions that are not mounted under user id 1000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while IFS= read -r partition; do | |
# get all partitions that are not mounted. column 7 lists active mountpoints | |
if [[ "$(echo $partition | awk '{ print $7 }')" == "" ]]; then | |
# for all partitions without a mountpoint get partition name, device path, and filesystem type | |
partition_name="$(echo $partition|awk '{ print $1 }' | sed 's/^..//')" | |
tomount="/dev/$partition_name" | |
filesystem=$(lsblk -f | grep $partition_name | awk '{ print $2 }') | |
# if the filesystem type isn't a lux partition, attempt to automount it | |
if [[ "$filesystem" != "crypto_LUKS" ]]; then | |
mountopts="" | |
ownershipcomm="" | |
partsize=$(lsblk | grep $partition_name | awk '{ print $4 }') | |
rwuser="$(sudo id -nu 1000)" | |
# make sure the filesystem type isn't blank or empty | |
if [[ "$filesystem" != "" ]]; then | |
# don't mount partitions that are smaller than 1GB. | |
# by doing this we prevent things like ntfs recovery or /boot and efi | |
# partitions on non-booted OS disks from being mounted | |
# most people just want their main parititions to be mounted | |
# for game or content access. | |
if [[ "$partsize" == "*M*" ]] | [[ "$partsize" != "1G" ]] ; then | |
sudo mkdir -p /run/media/$rwuser/$partition_name | |
if [[ "$filesystem" == "btrfs" ]] || [[ "$filesystem" == "ext4" ]] || [[ "$filesystem" == "ext3" ]] || [[ "$filesystem" == "ext2" ]] || [[ "$filesystem" == "xfs" ]]; then | |
ownershipcomm="sudo chown $rwuser:$rwuser --recursive /run/media/$rwuser/$partition_name" | |
else | |
mountopts="-o umask=000" | |
fi | |
# Prevent ntfs metadata mount failure | |
if [[ "$filesystem" == "ntfs" ]]; then | |
sudo ntfsfix $tomount &>/dev/null | |
fi | |
$ownershipcomm | |
sudo mount -t $filesystem $mountopts $tomount /run/media/$rwuser/$partition_name | |
# We only need to echo the command for debugging purposes. | |
# echo "sudo mount -t $filesystem $mountopts $tomount /run/media/$rwuser/$partition_name" | |
fi | |
fi | |
fi | |
fi | |
done < <( lsblk | grep part ) # list all partitions with lsblk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment