Created
December 26, 2014 18:34
-
-
Save rxw1/9eb232ebb235cabf8a91 to your computer and use it in GitHub Desktop.
Try to mount all found partitions. Usage: mount-all DIR
This file contains 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/zsh | |
#vi: colorscheme delek | |
# | |
# beware | |
# 2012,2015 (c) [email protected] | |
# | |
if [ ! $#@ -eq 1 ] | |
then | |
echo "Usage: $0 mntdir (e.g. /mnt)" | |
exit 0 | |
else | |
MNTDIR=$1; shift | |
fi | |
lsblk -P -o 'NAME,LABEL,TYPE' | while IFS= read -r line | |
do | |
eval $line | |
if [[ $TYPE == "part" ]]; then | |
if [ ! -z $LABEL ] | |
then | |
LABEL=${${LABEL:l}//[^a-z0-9]/} | |
else | |
LABEL=$NAME | |
fi | |
egrep -qw "$LABEL" /proc/mounts | |
if [[ $? == 0 ]] | |
then | |
LABEL=${LABEL}-2 | |
fi | |
egrep -qw "$NAME" /proc/mounts | |
if [[ $? == 0 ]] | |
then | |
mount | grep $NAME | awk '{printf "Skipping %s: already mounted on %s\n",$1,$3}' | |
continue | |
fi | |
sudo mkdir -p $MNTDIR/$LABEL | |
sudo mount /dev/$NAME $MNTDIR/$LABEL && echo "Mounting $(mount | grep $NAME | awk '{print $1,$2,$3}')" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment