Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env sh
- already_did=$(sudo mount | grep "$1" | wc -l)
- if [[ "$already_did" == 0 ]]; then
- blkid_output=$(sudo blkid)
- result=$(echo "$blkid_output" | grep "$1" | grep -Po ' UUID="(.*?)"' | awk '{print substr($1, 7, length($1) - 7)}')
- if [[ ${#result} != 0 ]]; then
- label=$(echo "$blkid_output" | grep "$1" | grep -Po ' LABEL="(.*?)"' | awk '{print substr($1, 8, length($1) - 8)}')
- if [[ ${#label} == 0 ]]; then
- label=$(echo "$blkid_output" | grep "$1" | grep -Po ' PARTLABEL="(.*?)"' | awk '{print substr($1, 12, length($1) - 12)}')
- fi
- if [[ ${#label} == 0 ]]; then
- label="$result"
- fi
- device_type_output=$(echo "$blkid_output" | grep "$1")
- device_type=""
- if [[ $(echo "$device_type_output" | grep 'TYPE="ntfs"' | wc -l) == 1 ]]; then
- device_type="ntfs-3g"
- elif [[ $(echo "$device_type_output" | grep 'TYPE="vfat"' | wc -l) == 1 ]]; then
- device_type="vfat"
- elif [[ $(echo "$device_type_output" | grep 'TYPE="ext4"' | wc -l) == 1 ]]; then
- device_type="ext4"
- fi
- if [[ "$device_type" == "" ]]; then
- echo "device type not found"
- else
- sudo mkdir -p "/mnt/$label"
- sudo mount -t "$device_type" -o user,users,rw,uid=oznakn,gid=users,dmask=0022,fmask=0022,utf8 "$1" "/mnt/$label"
- echo "/mnt/$label"
- fi
- else
- echo "device not found"
- fi
- else
- echo "already mounted"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement