Version racy-5.3 :
Code: Select all
#!/bin/bash
############## ROX app.: Click image files to mount & unmount. by: Terry Becker aka: SunBurnt
############## File types = ".2fs, .3fs, .sfs, .iso, & initrd.gz".
#v423 detect wrong squashfs version 3.x or 4.x.
#v424 advise of sfs-version-converter.
#100606 have backported squashfs4 to kernel 2.6.27.47.
#100831 fix KERNELSUBVER for olpc people, have 'uname -r' returning version with '_'.
#101221 yaf-splash fix.
#111016 fix for 3.x kernel.
#111110 handle encrypted save-files.
#111112 small fixes.
#120201 rodin.s: internationalization.
#120220 npierce: improved test and message for already mounted file, also prevent mkdir if file not found, and fix adding pwd prefix
#120220 npierce: add slash to pwd prefix; exit on failed stat. refer: http://murga-linux.com/puppy/viewtopic.php?t=71767&start=450
#120323 replace 'xmessage' with 'pupmessage'.
export TEXTDOMAIN=filemnt
export OUTPUT_CHARSET=UTF-8
. gettext.sh
#v423...
KERNELVER="`uname -r`"
if vercmp $KERNELVER ge 3.0;then #111016
SFSSTR='squashfs, version 4'
SFSMAJOR=4
else
KERNELSUBVER=`echo -n "$KERNELVER" | cut -f 3 -d '.' | cut -f 1 -d '-' | cut -f 1 -d '_'` #100831
KERNELSUBSUBVER=`echo -n "$KERNELVER" | cut -f 4 -d '.' | cut -f 1 -d '-'`
SFSSTR='squashfs, version 3'
SFSMAJOR=3
if [ $KERNELSUBVER -eq 27 ];then
if [ $KERNELSUBSUBVER -gt 46 ];then #100606
SFSSTR='squashfs, version 4'
SFSMAJOR=4
fi
fi
if [ $KERNELSUBVER -gt 28 ];then
SFSSTR='squashfs, version 4'
SFSMAJOR=4
fi
fi
imgFile="$1"
if [ ! -f "$imgFile" ];then echo "No regular file: $imgFile";exit 1;fi #120220
if [ "`dirname "$imgFile"`" = '.' ] ;then #120220
imgFile="`pwd`/`echo "$imgFile" |sed 's/^\.//'`" #120220
fi
MntPt='/mnt/'`echo "$imgFile" |sed "s#^\.##g" |sed "s#/#+#g"`
if [ 1 -eq 2 ] ;then ############################################## JUMP OVER this SECTION.
loMnts="`mount |grep '/dev/loop' |awk '{print $1}'`"
echo "$loMnts" |while read LOOP ### test if file's mounted
do
loFile="`losetup-FULL $LOOP |sed 's/^.*(//' |sed 's/).*$//'`"
if [ "$loFile" = "$imgFile" ] ;then
echo -e "\n ### Loop File: $loFile"
break
fi
i=`expr $i + 1`
done
fi ############################################## END of JUMP SECTION.
### file's not mounted, mount it
# if [ $i -eq 16 ] ;then
imgFileBASE="`basename "$imgFile"`" #BK
imgFileDEV_INODE="`stat -L -c "%d_%i" "$imgFile"`" || exit 160 #120220
if [ ! -d "$MntPt" ] ;then
DISK_TYPE=`disktype "${imgFile}"`
Type=`echo "$DISK_TYPE" |grep -m1 -E 'file system|Linux squashfs' |sed 's#^Linux##' |tr -d ',' |awk '{print $1}' |tr '[[:upper:]]' '[[:lower:]]'`
[ "$Type" ] || { DISK_TYPE=`file -z "$imgFile"`;Type=`echo "$DISK_TYPE" |cut -f 2 -d ':' |grep 'filesystem' |awk '{print $2}' |tr '[[:upper:]]' '[[:lower:]]'`; }
file -z "$imgFile" |cut -f 2 -d ':'
[ "$Type" ] || { echo "Warning : disktype and file commands were unable to determine a file system.";[ "$DISPLAY" ] && pupmessage -bg red2 "WARNING:
dsktype and file commands had been unable to fetch the filesystem type for
$imgFile";exit 150; }
cat /proc/filesystems |grep -w "$Type" || { echo "No Support in kernel $KERNELVER
for filesystem type '$Type' .";[ "$DISPLAY" ] && pupmessage -bg red2 "No Support in kernel $KERNELVER
for filesystem type '$Type' .";exit 151; }
#BK check if already mounted elsewhere...
for ONELOOP in `mount | grep '^/dev/loop' | cut -f 1 -d ' ' | tr '\n' ' '`
do
MNTDIMG_MNT_PT=`mount | grep "^$ONELOOP " | sed 's#.* on \(.*\) type .*#\1#'` #120220...
MNTDIMG=""
[ "`echo $MNTDIMG_MNT_PT | cut -f 2 -d /`" = "initrd" ] && MNTDIMG="/initrd"
MNTDIMG="${MNTDIMG}`losetup-FULL $ONELOOP | cut -f 2 -d '(' | cut -f 1 -d ')'`"
LONG_MNTDIMG=`echo "$MNTDIMG" | sed 's/\*$//'`
losetup-FULL $ONELOOP
ls "$LONG_MNTDIMG"*
MNTDIMG_DEV_INODE=`stat -L -c "%d_%i" "$LONG_MNTDIMG"*` #120220
#not perfect, but paths may be symlinks...
if [ "$MNTDIMG_DEV_INODE" = "$imgFileDEV_INODE" ];then #120220...
pupmessage -bg '#FF8080' "Sorry $imgFile is already mounted and in-use by Puppy
on $MNTDIMG_MNT_PT from $MNTDIMG" #120220
exit
fi
done
Ext=`echo "$imgFile" |sed 's/^.*\.//'` # get file type from extention
if [ "$Ext" = 'fs' ] ;then
Type=`file -z "$imgFile" |cut -f 2 -d ':' |awk '{print $2}' |tr '[[:upper:]]' '[[:lower:]]'`
cat /proc/filesystems |grep -w "$Type" || { echo "No Support in kernel $KERNELVER
for filesystem type '$Type' .";[ "$DISPLAY" ] && pupmessage -bg red2 "No Support in kernel $KERNELVER
for filesystem type '$Type' .";exit 151; }
elif [ "$Ext" = '2fs' ] ;then
Type='ext2'
elif [ "$Ext" = '3fs' ] ;then
Type='ext3'
elif [ "$Ext" = '4fs' ] ;then #v423 planning for the future!
Type='ext4'
elif [ "$Ext" = 'sfs' -o "$Ext" = 'squashfs' -o "$Ext" = 'sqfs' ] ;then
Type='squashfs'
elif [ "$Ext" = 'iso' ] ;then
Type=`echo "$DISK_TYPE" |grep -m1 'file system' |awk '{print $1}' |tr '[[:upper:]]' '[[:lower:]]'`
[ "$Type" ] || Type='iso9660'
# BK
#elif [ "$imgFile" = 'initrd.gz' ] ;then
# Type='ext2'
# gunzip $imgFile # handle gzip image file
# imgFile="echo "$imgFile" |sed 's/.gz$//'"
fi
#v423 detect wrong squashfs version...
if [ "$Type" = "squashfs" ];then
#DISK_TYPE=`disktype "${imgFile}"`
echo "$DISKTYPE" ##Squashfs filesystem, little endian, version 2.1,
if [ "`echo "${DISK_TYPE}" | grep 'Linux squashfs, version'`" ];then
SFS_V_STR=`echo "${DISK_TYPE}" | grep -o 'Linux squashfs, version.*' |awk -F ',' '{print $1" "$2" "$3}'`
if [ "`echo "${DISK_TYPE}" |grep "$SFSSTR"`" = "" ];then
if [ $SFSMAJOR -eq 4 ];then #100606
pupmessage -center -bg '#FFC0C0' "`gettext \"NOTICE:
${SFS_V_STR}, not usable.
All Linux kernels 2.6.29 or later require version 4.x squashfs files
(note, some 2.6.27.47+ kernels have Squashfs4 backported to them).
Note, there is an SFS-version-converter in the Utility menu, run that first.\"`"
else
pupmessage -center -bg '#FFC0C0' "`gettext \"NOTICE:
${SFS_V_STR}, not usable.
All Linux kernels 2.6.28 or earlier require version 3.x squashfs files
(note, an exception is some 2.6.27.47+ kernels that have Squashfs4 backported).
Note, there is an SFS-version-converter in the Utility menu, run that first.\"`"
fi
exit 0
fi
else
pupmessage -center -bg '#FFC0C0' "`gettext \"NOTICE: Could not find a squash filesystem indside
$imgFile. Is the file type extension correct ?\"`"
fi
fi
# echo -e "\nimgFile = $imgFile\t\tExt = $Ext"
# echo -e "MntPt = $MntPt\t\tType = $Type\n"
echo -e "\n ### Mount: $imgFile\n"
mkdir -p "$MntPt"
#111110 handle encrypted save-files...
CRYPTO=""; Err=0
DEVLOOP="`losetup-FULL -f`" #next free loop device.
case $Type in
ext2|ext3|ext4)
case $imgFileBASE in
*_cryptx*) #light encryption.
CRYPTO='light'
modprobe cryptoloop
rxvt -geometry 25x3 -title "$(gettext 'Enter password')" -bg orange -e losetup-FULL -E 1 $DEVLOOP "$imgFile"
#losetup-FULL -E 1 $DEVLOOP $imgFile
Err=$?
;;
*_crypt*) #heavy encryption.
CRYPTO='heavy'
modprobe cryptoloop
modprobe aes_generic 2>/dev/null #v407 aes name change.
modprobe aes 2>/dev/null #for older kernel <2.6.25
modprobe crypto_blkcipher 2>/dev/null #v407 blkcipher name change.
modprobe blkcipher 2>/dev/null #old kernel.
modprobe cbc
MYPASS="`pupdialog --title "$(gettext 'Password required')" --stdout --inputbox "$(gettext 'Password required to open') ${imgFileBASE}:" 0 0`"
Err=$?
if [ $Err -eq 0 ];then
echo "$MYPASS" | losetup-FULL -p 0 -e aes $DEVLOOP "$imgFile"
Err=$?
fi
;;
esac
;;
esac
if [ "$CRYPTO" ];then
[ $Err -eq 0 ] && mount -t $Type $DEVLOOP "$MntPt"
Err=$?
else #normal, no encryption...
mount -t $Type -o loop "$imgFile" "$MntPt"
Err=$?
fi
if [ $Err -eq 0 ] ;then
rox -d "$MntPt" # mount good, run rox filer
# yaf-splash -timeout 6 -font "8x16" -outline 0 -margin 4 -bg green -text "SUCCESS! Click $imgFileBASE icon again to unmount it" & #BK
# /usr/X11R7/bin/yaf-splash -timeout 6 -font "8x16" -outline 0 -margin 4 -bg green -text "SUCCESS! Click $imgFileBASE icon again to unmount it" & #BK
yaf-splash -timeout 6 -bg green -text "`eval_gettext \"SUCCESS! Click \\\$imgFileBASE icon again to unmount it\"`" #BK
else
[ -d "$MntPt" ] && { [ "`ls -1A "$MntPt"`" ] || rmdir "$MntPt"; }
fi
else ### file's mounted, unmount it
rox -D "$MntPt" #BK
sync #111112
umount "$MntPt"
Err=$?
#if [ "$imgFileBASE" = 'initrd' ] ;then gzip -9 $imgFile ;fi #111112 bug fix. no, remove.
# yaf-splash -timeout 3 -font "8x16" -outline 0 -margin 4 -bg orange -text "Unmounting $imgFileBASE" #BK
# /usr/X11R7/bin/yaf-splash -timeout 3 -font "8x16" -outline 0 -margin 4 -bg orange -text "Unmounting $imgFileBASE" #BK
yaf-splash -timeout 3 -bg orange -text "$(gettext 'Unmounting') $imgFileBASE" #BK
#Xdialog --title " Notice..." --no-button \
# --infobox "
#UnMounting: $imgFile
#" 0 0 2000
echo -e "\n ### UnMount: $imgFile\n"
sync #111112
sleep 2
[ -d "$MntPt" ] && { [ "`ls -1A "$MntPt"`" ] || rmdir "$MntPt"; }
fi
if [ $Err -ne 0 ] ;then # ERROR: mount/unmount
#xmessage -title " ERROR..." " Failed mounting or unmounting. "
pupdialog --background red --title "$(gettext 'ERROR')" --msgbox "$(gettext 'Failed mounting or unmounting')" 0 0 &
fi
exit $Err
###END###
Added several ""double quotings .
Added removal of created directory if mount fails .
Removed the & fork from yaf-splash to be less disturbant on urxvt .
Added support for .squash and .sqfs extensions .
Added support for iso check if other then iso9660 ie udf .
Added support for determining and messaging the correct squashfs version ie found one older iso with squashfs-2.x .
Added fallback if disktype fails with file -z command .
Added sanity check if kernel supports the filesystem by checking /proc/filesystem .