Skip to content

Commit cd55088

Browse files
authored
feature - add in functions for Sam_Dev (#20)
* also works for any drives mounted in /media * also works for symlinks directed to $USER/USB-Drive, where $USER belongs to [users] group
1 parent f0c8eda commit cd55088

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

functions_library.sh

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,69 @@ change_branch() {
5555
fi
5656
}
5757

58+
###########################################################################
59+
#
60+
# USB drive stuff
61+
#
62+
###########################################################################
63+
64+
# get_usb_mount_point - get the USB drive directory (the mount point), if present
65+
#
66+
# writes the path name to stdout
67+
#
68+
# Returns: 0 on success or 1 on failure
69+
70+
71+
get_usb_mount_point() {
72+
# devmon mounts usb drive to /media/
73+
74+
active_drives=$(ls /dev/disk/by-partuuid/ | tr '\n' ' ' 2>/dev/null)
75+
real_media_points=""
76+
for active_drive in $active_drives
77+
do
78+
output=$(findmnt -rn -S PARTUUID="$active_drive" -o TARGET)
79+
errcode=$?
80+
if [[ $errcode == 0 ]]; then
81+
real_media_points="$real_media_points$output "
82+
fi
83+
done
84+
real_media_points=$(echo -e "$real_media_points")
85+
86+
OIFS="$IFS"
87+
IFS=$'\n'
88+
find /media -maxdepth 1 -mindepth 1 | while read media_point
89+
do
90+
# spaces in the compared strings must stay
91+
if [[ "$real_media_points " = *"$media_point "* ]]; then
92+
echo "$media_point"
93+
return 0
94+
fi
95+
done
96+
IFS="$OIFS"
97+
98+
return 1
99+
}
100+
101+
# get_usb_symlink_for_user - get the USB drive directory (the symlink to the user's home directory), if present
102+
#
103+
# writes the path name to stdout
104+
#
105+
# Returns: 0 on success or 1 on failure
106+
get_usb_symlink_for_user() {
107+
if [[ -L $HOME/USB-Drive ]]; then
108+
echo "$HOME/USB-Drive"
109+
return 0
110+
fi
111+
return 1
112+
}
113+
58114
#########################################################################
59115
#
60116
# FILE EDITION
61117
#
62118
#########################################################################
63119
delete_line_from_file() {
64-
# first parameter is the string to be matched
120+
# first parameter is the string to be matched
65121
# the lines that contain that string will get deleted
66122
# second parameter is the filename
67123
if [ -f $2 ]

0 commit comments

Comments
 (0)