Last active
January 1, 2016 06:29
-
-
Save DennisLfromGA/8105549 to your computer and use it in GitHub Desktop.
A shell script to mount or unmount your SMEStorage Cloud Provider folders for local access.<p>Refer to http://storagemadeeasy.com/ for features and details.
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
#!/bin/sh -e | |
# Mount SMEStorage Cloud folders locally | |
Bname="${0##*/}" | |
Crosh_Loc='' | |
Local_User="$(id -un)" | |
SMEmount='' | |
Umount='' | |
USAGE=" | |
${Bname} [options] | |
A script to mount or unmount your SMEStorage Cloud Provider folders for local access. | |
The default folder location is 'Downloads/SMEStorage', the location must either not currently exist or be empty. | |
( Placing it under the 'Downloads' folder allows access from both ChromeOS and your chroot environment. ) | |
This program should first be run from the chroot where SMEStorage is installed and then, optionally, in Crosh. | |
Also, when unmounting, it should first be unmounted in the chroot and then, optionally, in Crosh. | |
FORMAT: ${Bname} [Folder] [SMES_Username] [SMES_Password] | |
Options: | |
-h Help - prints this usage summary and exits. | |
-u Unmount 'Downloads/SMEStorage' or the location you specified. | |
" | |
# Function to exit with exit code $1, spitting out message $@ to stderr | |
error() { | |
local ecode="$1" | |
shift | |
echo "$*" 1>&2 | |
exit "$ecode" | |
} | |
while getopts hu OPT | |
do | |
case ${OPT} in | |
h*) error 0 "$USAGE";; | |
u) Umount='y' ;; | |
\?) error 2 "$USAGE";; | |
esac | |
shift | |
done | |
### *** EDIT THE TWO LINES BELOW WITH YOUR OPTIONS *** ### | |
Folder_Loc="${1:-Downloads/SMEStorage}" | |
Login_Creds="${2:-SMES_Username}:${3:-SMES_Password}" | |
### *** EDIT THE TWO LINES ABOVE WITH YOUR OPTIONS *** ### | |
### *** NO NEED TO CHANGE ANYTHING BELOW HERE *** ### | |
##################################################### | |
if [ "$#" -gt 0 ]; then | |
if [ -n "$1" ]; then echo "User specified - Folder Location: '$Folder_Loc'" | |
if [ ! -d "$HOME/$Folder_Loc" ]; then | |
error 1 "Sorry, the Folder Location must be in your \$HOME directory" | |
fi | |
fi | |
if [ -n "$2" ]; then echo "User specified - SMES Username : '$SMES_Username'"; fi | |
if [ -n "$3" ]; then echo "User specified - SMES Password : '$SMES_Password'"; fi | |
if [ -n "$4" ]; then error 1 "Sorry, parameters \$4 & up are not permitted..."; fi | |
fi | |
if [ "$Local_User" = 'chronos' ]; then | |
echo "Looking for Crosh mountpoint of '${Folder_Loc}' ..."; echo | |
Crosh_Loc="$(grep chroots /etc/mtab | grep ${Folder_Loc} 2>/dev/null|cut -d' ' -f2)" | |
if [ -n "${Crosh_Loc}" ]; then | |
echo "The SMEStorage folder is mounted at:" | |
echo "'${Crosh_Loc}'" | |
echo "#" | |
if mountpoint -q "${HOME}/${Folder_Loc}"; then | |
echo "# And it's already mounted in crosh at -" | |
echo "'${HOME}/${Folder_Loc}'" | |
echo "# and contains..."; echo | |
ls -l "${HOME}/${Folder_Loc}" | |
if [ -n "${Umount}" ]; then | |
echo; echo "# '-u' specified but it has to be unmounted on the chroots side first ..." | |
fi | |
else | |
echo "# Now attempting to 'bindmount' it at -" | |
echo "'${HOME}/${Folder_Loc}'" | |
echo " sudo mount --bind ${Crosh_Loc} ${Folder_Loc}" | |
sudo mount --bind "${Crosh_Loc}" "${HOME}/${Folder_Loc}" 2>/dev/null | |
if mountpoint -q "${HOME}/${Folder_Loc}"; then | |
echo "# It's now mounted and contains..."; echo | |
ls -l "${HOME}/${Folder_Loc}" | |
else | |
echo "# Sorry, couldn't bindmount '${Folder_Loc}' ..." | |
fi | |
fi | |
else | |
if mountpoint -q "${HOME}/${Folder_Loc}"; then | |
echo "# It's now mounted and contains..."; echo | |
ls -l "${HOME}/${Folder_Loc}" | |
if [ -n "${Umount}" ]; then | |
echo; echo "# Unmounting it now ..." | |
sudo umount "${HOME}/${Folder_Loc}" && sudo rm -r "${HOME}/${Folder_Loc}" | |
fi | |
else | |
echo "Sorry, the '${Folder_Loc}' folder is NOT mounted." | |
error 1 "Perhaps the chroot is not running or SMEStorage is not installed." | |
fi | |
fi | |
echo | |
exit | |
fi | |
SMEmount=$(which smemount) | |
if [ -z "$SMEmount" ]; then | |
echo "Sorry but 'smemount' cannot be located in your \$PATH..." | |
error 1 "Perhaps SMEStorage is not installed." | |
fi | |
if grep -q "${HOME}/${Folder_Loc}" /etc/mtab; then | |
echo "'${HOME}/${Folder_Loc}' is already mounted ..."; echo | |
ls -l "${HOME}/${Folder_Loc}" | |
if [ -n "${Umount}" ]; then | |
echo; echo "# Unmounting it now ..." | |
sudo umount "${HOME}/${Folder_Loc}" | |
fi | |
echo | |
exit | |
fi | |
if [ ! -d "${HOME}/${Folder_Loc}" ]; then | |
echo "Creating '${Folder_Loc}' ..." | |
mkdir -p "${HOME}/${Folder_Loc}" || (echo "Sorry, couldn't create folder ..." && exit 1); | |
fi | |
echo "Mounting '${HOME}/${Folder_Loc}' ..." | |
echo "$ sudo smemount ${HOME}/${Folder_Loc} ${Login_Creds} ${Local_User} --ao" | |
sudo smemount ${HOME}/${Folder_Loc} ${Login_Creds} ${Local_User} --ao | |
echo | |
echo "# It's now mounted and contains..."; echo | |
ls -l "${HOME}/${Folder_Loc}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment