Last active
June 29, 2022 21:34
-
-
Save abenezeradane/d766a3af6257ca585e00a7d0bf3f377c to your computer and use it in GitHub Desktop.
UNIX external storage mount for Windows Subsystem for Linux (WSL)
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
| #!/usr/bin/env bash | |
| # Determine if it's a network storage or external hard drive | |
| read -p "(N)etwork or (D)rive? " -n1 external | |
| echo "" | |
| # Blank input check | |
| if [ -z "$external" ]; then | |
| echo 'Inputs cannot be blank!' | |
| exit 0 | |
| # Numeric input check | |
| elif [[ "$external" =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then | |
| echo "Input must be a character!" | |
| exit 0 | |
| # Mount logic | |
| elif [[ "${external^}" == "N" ]]; then | |
| # Mount network storage | |
| if ! [ -d /mnt/share ]; then | |
| sudo mkdir /mnt/share | |
| echo "Created /mnt/share" | |
| else | |
| echo "/mnt/share directory already exists" | |
| fi | |
| sudo mount -t drvfs '\\server\share' /mnt/share | |
| echo "Mounted network storage" | |
| echo 0 | |
| elif [[ "${external^}" == "D" ]]; then | |
| # Get mount drive letter | |
| read -p "Enter Drive Letter: " -n1 drive | |
| echo "" | |
| # Numeric input check | |
| if [[ "$drive" =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then | |
| echo "Input must be a character!" | |
| exit 0 | |
| else | |
| # Mount external drive | |
| if ! [ -d /mnt/"${drive,}" ]; then | |
| sudo mkdir /mnt/"${drive,}" | |
| echo "Created /mnt/${drive,}" | |
| else | |
| echo "/mnt/${drive,} directory already exists" | |
| fi | |
| sudo mount -t drvfs "${drive,}": /mnt/"${drive,}" | |
| echo "Mounted ${drive^}: drive" | |
| exit 0 | |
| fi | |
| else | |
| echo "Input was invalid!" | |
| exit 0 | |
| fi | |
| #SHELL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment