Erm..been 7 months...I'll get something new up here in a couple of days.
I decided to work on a bash script instead, and rather than go by the book, I just got help from some others and actually completed a task. This is really for 720degrees users who want to make a swap file, but I just want to post some sort of update...
----------------------------------------------------------------------------------------
#!/bin/sh
echo "How large of a swapfile would you like to create?
(in M
)"
read size
echo "What would you like to name your swapfile?
(Default is swapfile
)"
name=swapfile
read name_u
[ "$name_u" ] && name=$name_u
echo "Where would you like your swapfile to be?
(Default is /swap
)"
folder=/swap
read folder_u
if [ "$folder_u" != "" ];
then folder="$folder_u"; fi # fi = end if ...backwards, eh?
if ! echo $folder | grep "^/" > /dev/null;
then folder="/$folder";
fi
# so that I do not have to put a / in front of every $folder if the user forgot, and
# does not make an extra if they did
echo "Creating directory if it does not already exist..."
mkdir -p $folder
# -p ensures that it only creates the folder if necessary
echo
echo "Creating swapfile..."
# this is the actual command that users previously had to type by hand...and the
# reason for this script
dd if=/dev/zero of=$folder/$name bs=1k count=${size}000 > /dev/null 2>&1
# well dd likes to output plenty of garbage to the screen..sending it to
# /dev/null keeps things clean
mkswap $folder/$name > /dev/null 2>&1 # > /dev/null 2>&1 to keep things clean
chmod 0600 $folder/$name # swapfiles like to have this permission set
echo
echo "Adding swapfile entry to /etc/fstab..."
# This is the main intelligent part of the script - it checks to see if it has previously made
# an entry in /etc/fstab
(such as if a user ran the script before
), and does not create another
# entry if it sees one. This prevents the possibility of duplicates, which is never great.
if ! grep "^$folder/$name[[:space:]]" /etc/fstab > /dev/null 2>&1;
then echo -e "$folder/$name none swap sw 0 0" >> /etc/fstab;
fi
# the shortened way to do the if statement for the folder variable:
# name=foo; read name_u; [ "$name_u" ] && name=$name_u
# the shorter method is used for the name variable
Edited by ProgramSynthesiser 2006-11-26 6:46 PM