Skip to content
Snippets Groups Projects
Commit 97a65848 authored by Luiz Reis's avatar Luiz Reis
Browse files

Rewrite prepare_usb


Signed-off-by: default avatarLuiz Reis <luizreis@outlook.com>
parent 5ba9d6e8
No related branches found
No related tags found
No related merge requests found
...@@ -3,36 +3,39 @@ DIR_USB=/media/usb_drive/ ...@@ -3,36 +3,39 @@ DIR_USB=/media/usb_drive/
DIR_OPENSLX=/Openslx/ DIR_OPENSLX=/Openslx/
user_name=`users | cut -f 1 -d ' '` user_name=`users | cut -f 1 -d ' '`
# prepares openslx partition to be used
# mounts partition if not mounted
# blocks program execution if it is not a openslx partition
# param $1 is the devpath to be mounted
# param $2 is the uuid of the partition
# return is done via the mountpath global variable, which is also used here
function prepare_usb { function prepare_usb {
# get the usb_drive's path # get the usb_drive's path
devpath=`readlink -f $usb_drives` local devpath="/dev/"$1
# check if the usb_drive is mounted mountpath=""
mount_msg=`mount | grep $devpath` if [ ! 0 -eq $(mount | grep -q $devpath) ]; then
# if it is mounted, show the path echo $0": Device $devpath is already mounted"
if [[ -n $mount_msg ]]; then mountpath=$(mount | grep -w $devpath | cut -d' ' -f3)
echo $mount_msg
mount_path=`mount | grep $devpath | cut -f 3 -d ' '`
counter=4
part_path=`mount | grep $devpath | cut -f 4 -d ' '`
while [ "$part_path" != "type" ];
do
mount_path=$mount_path"\ "$part_path
counter=$(($counter+1))
part_path=`mount | grep $devpath | cut -f $counter -d ' '`
done
echo $mount_path
echo $mount_path$DIR_OPENSLX
# If it is not mounted, mount it
else else
echo "$devpath não está montado"; echo $0": Device $devpath is not mounted"
mkdir -p /media/openslx/$2
if [ ! -d "$DIR_USB" ]; then if $(mount $devpath /media/openslx/$2); then
mkdir /media/usb_drive echo $0": Device $devpath mounted successfully"
echo "não existe" mountpath="/media/openslx/"$2
else
echo $0": Device $devpath could not be mounted"
exit 1
fi
fi
if [ -e "$mountpath/Openslx/config" ]; then
echo $0": $devpath is an openslx ready drive"
else
echo $0": $devpath is not ready to be used as an openslx drive"
if [ $mountpath = "/media/openslx/$2" ]; then
echo $0": umounting $devpath"
umount $devpath
fi fi
echo "Montando dispositivo..." exit 2
mount -o uid="$user_name" $devpath /media/usb_drive
mount_path=/media/usb_drive
fi fi
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment