- mount | grep "on /mnt/utmp/${PND_NAME} type"
- if [ $? -ne 0 ];then
- mount | grep "on /mnt/pnd/${PND_NAME} type"
- if [ $? -ne 0 ];then
- echo not mounted on loop yet, doing so
- #check if pnd is already attached to loop
- LOOP=$(losetup -a | grep "$PND" | tail -n1 | awk -F: '{print $1}')
- #check if the loop device is already mounted
- if ! [ -z "$LOOP" ];then
- echo "Found a loop ($LOOP), using it"
- loopmountedon=$( mount | grep "$(mount | grep "$LOOP" | awk '{print $3}')" | grep utmp | awk '{print $3}' )
- else
- loopmountedon=""
- fi
- echo "LoopMountedon: $loopmountedon"
- if [ ! "$loopmountedon" ]; then #check if the pnd is already attached to some loop device but not used
- FREELOOP=$LOOP
- #reuse existing loop
- if [ ! "$LOOP" ]; then
- FREELOOP=$(/sbin/losetup -f) #get first free loop device
- echo $FREELOOP
- if [ ! "$FREELOOP" ]; then # no free loop device, create a new one
- #find a free loop device and use it
- usedminor=$(/sbin/losetup -a | tail -n1)
- usedminor=${usedminor:9:1}
- echo usedminor $usedminor
- freeminor=$(($usedminor+1))
- echo freeminor $freeminor
- mknod -m777 /dev/loop$freeminor b 7 $freeminor
- FREELOOP=/dev/loop$freeminor
- fi
- fi
- #detect fs
-
- case $PND_FSTYPE in
- ISO)
- /sbin/losetup $FREELOOP "$PND" #attach the pnd to the loop device
- mntline="mount" #setup the mountline for later
- mntdev="${FREELOOP}"
- #mntline="mount -o loop,mode=777 $PND /mnt/pnd/$PND_NAME"
- echo "Filetype is $PND_FSTYPE";;
- directory)
- #we bind the folder, now it can be treated in a unified way
- #ATENTION: -o ro doesnt work for --bind at least on 25, on 26 its possible using remount, may have changed on 27
- mntline="mount --bind -o ro"
- mntdev="${PND}"
- echo "Filetype is $PND_FSTYPE";;
- Squashfs)
- /sbin/losetup $FREELOOP "$PND" #attach the pnd to the loop device
- mntline="mount -t squashfs"
- mntdev="${FREELOOP}"
- echo "Filetype is $PND_FSTYPE";;
- *)
- echo "error determining fs, output was $PND_FSTYPE"
- exit 1;;
- esac
- echo "Mounting PND ($mntline) :"
- $mntline "$mntdev" "/mnt/pnd/${PND_NAME}" #mount the pnd/folder
-
- else #the pnd is already mounted but a mount was requested with a different basename/uid, just link it there
- echo $LOOP already mounted on $loopmountedon skipping losetup - putting link to old mount
- #this is bullshit
- rmdir "/mnt/utmp/$PND_NAME"
- ln -s $loopmountedon "/mnt/utmp/$PND_NAME"
- fi
-
- mount | grep "on /mnt/pnd/${PND_NAME} type"
- if [ $? -ne 0 ];then
- echo "The PND File-system is not mounted ! - Union wont work anyway"
- return 2
- fi
-