Last active
July 4, 2019 21:34
Revisions
-
oznakn revised this gist
Jul 4, 2019 . No changes.There are no files selected for viewing
-
oznakn created this gist
Jul 4, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #!/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