Save-file mount Script HOWTO

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
code_m
Posts: 65
Joined: Wed 02 Jul 2008, 19:11

Save-file mount Script HOWTO

#1 Post by code_m »

I made this as my first bash script, and thought someone might find it useful. If you don't like, then don't use it!

This script was written in the idea that you are starting from an unmounted drive. It can work with a mounted drive, but not a drive running your save file in use (/mnt/home drive)... See post below.

Step 1: open a text editor (preferably one with copy&paste ability to avoid typing mistakes) (geany works wonderfully)

Step 2: copy each of the following to a blank document in root folder:

File name: mntsave-2fs.sh

Code: Select all

#!/bin/bash

echo Script written by Cody A. Taylor
echo ' '

if [ -n "$DRIVE" ]
then
 echo Trying to mount "$DRIVE"
 mount /dev/$DRIVE /mnt/$DRIVE
else
 echo You need to set variable '$DRIVE'
 echo For Example
 echo '#export DRIVE=sdb1'
fi

echo ' '

if [ -n "$FILE" ]
then
 echo Making dir '"save"' and mounting "$FILE" there
 cd /mnt
 mkdir save
 mount -t ext2 -o loop /mnt/$DRIVE/$FILE /mnt/save
else
 echo You need to ser variable '$FILE'
 echo For Example
 echo '#export FILE=pup_save-name.2fs'
fi

echo ' '
echo 'Thanks for using the mount script'
echo 'Send questions to codemister99@gmail.com'

exit 0
file name: umntsave-2fs.sh

Code: Select all

#!/bin/bash

echo Written by Cody A. Taylor

umount /mnt/save

if [ -n "$DRIVE" ]
then
 umount /mnt/$DRIVE
 cd /mnt
 rmdir save
else
 echo You must set the variable '$DRIVE' again, sorry.
fi

echo Your now ready to use the mount script again.

exit 0
Step 3: Open a command prompt and make the scripts executable:

Code: Select all

cd /root
chmod +x mntsave-2fs.sh
chmod +x umntsave-2fs.sh
Step 4: Add aliases to .bashrc (geany will work fine again)

Code: Select all

alias mountsave='bash /root/mntsave-2fs.sh'
alias umountsave='bash /root/umntsave-2fs.sh'
Step 5: Attach drive if not already and then "set" the variables:

Code: Select all

export DRIVE=sda1
export FILE=pup_save.2fs
note: make sure to set your variables correctly, if you choose the wrong drive or wrong file, the script won't know that and you will likely get an error. I will not respond to errors due to incorrect variables.

Step 6: Finally run the mount script using the alias mountsave.

Step 7: Now you can cd /mnt/save and should be able to use the file

Step 8: Now that your done, clean up what your doing by running the second script with the alias umountsave.

I would be happy to answer any questions. This script should work with any linux at all.

note: This may or may not work if you encrypt your save file. Other people will have to verify being able to mount an encrypted save file.
Last edited by code_m on Thu 18 Sep 2008, 02:22, edited 1 time in total.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#2 Post by disciple »

Puppy must already have a script that does this, as he mounts and unmounts .2fs files when you click on them in rox. Or is there something special about your script?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

code_m
Posts: 65
Joined: Wed 02 Jul 2008, 19:11

#3 Post by code_m »

I wasn't aware of that.

The only way this is different is that you start with the drive unmounted, and the script mounts both the drive and the save file.

Which reminds me, this isn't meant to mount save files in the "/mnt/home" directory. It can work with any drive already mounted, just you will get an error saying the drive is already mounted, just ignor it.

Also, if your working from an already mounted drive, then the second script will unmount the drive as well. If you want the drive to stay mounted, then use the normal command:

Code: Select all

umount /mnt/save

User avatar
trapster
Posts: 2117
Joined: Mon 28 Nov 2005, 23:14
Location: Maine, USA
Contact:

#4 Post by trapster »

xfilemount and Edit-SFS Here
trapster
Maine, USA

Asus eeepc 1005HA PU1X-BK
Frugal install: Slacko
Currently using full install: DebianDog

code_m
Posts: 65
Joined: Wed 02 Jul 2008, 19:11

#5 Post by code_m »

well I was just trying to learn basic texts for scripting so that I can start to move on to C++ and the like.

I am now thinking that's what I want to go to college for.

It didn't really matter to me if someone had already created something better.

So like I said before, If you don't like it, don't use it!

Post Reply