rych, did you manage to make your squashfs_mount more robust?
Added in 10 hours 1 minute 48 seconds:
I pimped
my ride my local /usr/local/bin/squashfs_mount a little bit but it still has not enough error checks.
Code: Select all
root@porteus:/usr/local/bin# cat squashfs_mount
#!/bin/bash
mnt_name=${1%.*}
umount "$mnt_name"
mkdir "$mnt_name"
echo DEBUG: ██ mount "$1" "$mnt_name" ██
mount "$1" "$mnt_name"
like when it's called without any parameter we get this:
Code: Select all
root@porteus:/usr/local/bin# squashfs_mount
umount: : no mount point specified.
mkdir: cannot create directory ‘’: No such file or directory
DEBUG: ██ mount ██
ntfs-3g: Failed to access volume '': No such file or directory
ntfs-3g 2021.8.22 integrated FUSE 27 - Third Generation NTFS Driver
Configuration type 1, XATTRS are on, POSIX ACLS are off
Copyright (C) 2005-2007 Yura Pakhuchiy
Copyright (C) 2006-2009 Szabolcs Szakacsits
Copyright (C) 2007-2021 Jean-Pierre Andre
Copyright (C) 2009-2020 Erik Larsson
Usage: ntfs-3g [-o option[,...]] <device|image_file> <mount_point>
Options: ro (read-only mount), windows_names, uid=, gid=,
umask=, fmask=, dmask=, streams_interface=.
Please see the details in the manual (type: man ntfs-3g).
Example: ntfs-3g /dev/sda1 /mnt/windows
Plugin path: /usr/lib64/ntfs-3g
News, support and information: http://tuxera.com
root@porteus:/usr/local/bin# echo $?
11
now, when we try the same test as in my post above with the module with whitespace in its name squashfs_mount
creates the correct folder and also
tries mounting the correct module,
but it could still fail:
Code: Select all
guest@porteus:/tmp/mount-test$ squashfs_mount audacity-linux-3.2.0-x86_64\ with\ whitespace.xzm
umount: audacity-linux-3.2.0-x86_64 with whitespace: No such file or directory
DEBUG: ██ mount audacity-linux-3.2.0-x86_64 with whitespace.xzm audacity-linux-3.2.0-x86_64 with whitespace ██
mount: audacity-linux-3.2.0-x86_64 with whitespace: failed to setup loop device for /tmp/mount-test/audacity-linux-3.2.0-x86_64 with whitespace.xzm.
guest@porteus:/tmp/mount-test$ ls
audacity-linux-3.2.0-x86_64\ with\ whitespace
audacity-linux-3.2.0-x86_64\ with\ whitespace.xzm
audacity-linux-3.2.0-x86_64.xzm
As you can see, the echo DEBUG line
cannot distinguish between the
parameters set in " or
not set in "…
And of course since the above error is about the loop devices it also fails trying to mount the module without whitespace in its name:
Code: Select all
guest@porteus:/tmp/mount-test$ squashfs_mount audacity-linux-3.2.0-x86_64.xzm
umount: audacity-linux-3.2.0-x86_64: No such file or directory
DEBUG: ██ mount audacity-linux-3.2.0-x86_64.xzm audacity-linux-3.2.0-x86_64 ██
mount: audacity-linux-3.2.0-x86_64: failed to setup loop device for /tmp/mount-test/audacity-linux-3.2.0-x86_64.xzm.
guest@porteus:/tmp/mount-test$ ls
audacity-linux-3.2.0-x86_64
audacity-linux-3.2.0-x86_64\ with\ whitespace
audacity-linux-3.2.0-x86_64\ with\ whitespace.xzm
audacity-linux-3.2.0-x86_64.xzm
guest@porteus:/tmp/mount-test$ ls -o */
audacity-linux-3.2.0-x86_64 with whitespace/:
total 0
audacity-linux-3.2.0-x86_64/:
total 0
guest@porteus:/tmp/mount-test$ du -scm */
0 audacity-linux-3.2.0-x86_64 with whitespace/
0 audacity-linux-3.2.0-x86_64/
0 total
and both newly created folders for mount are therefore empty.
Added in 15 minutes 1 second:
About the error checking, adding a check for one parameter and one parameter only is no great issue:
The below code
uses my colour codes as described here:
Ravas coding goodies (Post by Rava #91503)
also, it uses $MYNAME to refer to its own name.
Code: Select all
if [ $# -ne 1 ]; then
echo -e "$red$bold $MYNAME ERROR -- You must specify exactly one parameter.$off"
exit 1
fi
if [ ! -f "$1" ]; then
echo -e "$red$bold $MYNAME ERROR -- file "$1" not exists. Aborting.$off"
exit 2
fi
thus we get this code (I added a version number and added more info on what the parameter is about):
Code: Select all
#!/bin/bash
# blame Rava, this script is based on an idea by rych - see details here: https://forum.porteus.org/viewtopic.php?p=91537#p91537
MYNAME=squashfs_mount
MYVERSION=2022-11-21
bld="\033[1m" # bold
red="\033[31m" # red
off="\033[m" # off
if [ $# -ne 1 ]; then
echo -e "$red$bold$MYNAME V$MYVERSION ERROR -- You must specify exactly one parameter (=the file to me mounted).$off"
exit 1
fi
if [ ! -f "$1" ]; then
echo -e "$red$bold$MYNAME V$MYVERSION ERROR -- file "$1" not exists. Aborting.$off"
exit 2
fi
mnt_name=${1%.*}
umount "$mnt_name"
mkdir "$mnt_name"
echo DEBUG: ██ mount "$1" "$mnt_name" ██
mount "$1" "$mnt_name"
It handles file names with spaces
checks if exactly one parameter was given
checks if file exists
TODO
not checks if umount was even necessary or if a needed umount did fail
not checks if folder could be created (could be e.g. the folder-to-be-created exists as a file owned by another user that the current user cannot remove)
Added in 7 minutes 53 seconds:
Here I simulate both errors, one is using a non-existing file name, the other giving no parameter:
guest@porteus:/tmp/mount-test$ squashfs_mount audacity-linux-3.2.0-x86_64\ with\ whitespace-nonexisting.xzm
squashfs_mount V2022-11-21 ERROR -- file audacity-linux-3.2.0-x86_64 with whitespace-nonexisting.xzm not exists. Aborting.
guest@porteus:/tmp/mount-test$ squashfs_mount
squashfs_mount V2022-11-21 ERROR -- You must specify exactly one parameter (=the file to me mounted).
guest@porteus:/tmp/mount-test$