Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Robert Labudda
utils
Commits
a671ba3a
Commit
a671ba3a
authored
Mar 18, 2019
by
Robert Labudda
Browse files
smount tool
parent
9a0826db
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
a671ba3a
...
...
@@ -27,6 +27,32 @@ ask you for it.
Requirements: bash, gpg, pinentry
smount
------
A wrapper around
`udisksctl`
for mounting volumes without
`sudo`
. The script
understands three commands:
*
`mount`
*
`umount`
*
no parameter lists all connected devices (a leading
`*`
) indicates that it
is mounted
`mount`
and
`umount`
accept either the block device name or the name of the
volume (usually the label). It matches the given name case-insensitive.
$ smount
* data /dev/sdb1
usb-stick /dev/sdc
$ smount umount data
Unmounted /dev/sdb1
$ smount
data /dev/sdb1
usb-stick /dev/sdc3
$ smount mount sdc
Mounted /dev/sdc3 at /run/media/baldrick/usb-stick.
sshmount
--------
...
...
smount
0 → 100755
View file @
a671ba3a
#!/bin/bash
COMMAND
=
"
$1
"
DEVICES
=
$(
udisksctl dump |
grep
PreferredDevice |
cut
-c
33-
)
shopt
-qs
nocasematch
for
i
in
$DEVICES
do
LABEL
=
$(
udisksctl info
-b
$i
|
grep
IdLabel |
cut
-c
33-
)
MOUNTPOINT
=
$(
udisksctl info
-b
$i
|
grep
MountPoints |
cut
-c
25-
)
MOUNTED
=
" "
if
[
-n
"
$MOUNTPOINT
"
]
then
MOUNTED
=
"* "
fi
if
[
-n
"
$LABEL
"
]
then
if
[[
"
$COMMAND
"
=
"umount"
&&
(
"
$i
"
=
~
"
$2
"
||
"
$LABEL
"
=
~
"
$2
"
)
]]
then
if
[
-n
"
$MOUNTPOINT
"
]
then
udisksctl unmount
-b
$i
exit
0
else
echo
"
$i
is not mounted"
exit
-1
fi
elif
[[
"
$COMMAND
"
=
"mount"
&&
(
"
$i
"
=
~
"
$2
"
||
"
$LABEL
"
=
~
"
$2
"
)
]]
then
if
[
-z
"
$MOUNTPOINT
"
]
then
udisksctl mount
-b
$i
exit
0
else
echo
"
$i
is already mounted"
exit
-1
fi
elif
[
-z
"
$COMMAND
"
]
then
echo
-e
"
$MOUNTED$LABEL
\t
$i
"
fi
fi
done
if
[
-n
"
$COMMAND
"
]
then
if
[[
"
$COMMAND
"
=
~
"^(umount|mount)$"
]]
then
echo
"Unknown command."
else
echo
"'
$2
' not found"
fi
fi
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment