Ok, so I've finally gotten around to playing with preinit and various posts, and decided to hone my shell scripting in the process. Attached is a script that will format /dev/hda2 and set up a mount entry (/programs0) for it. It will also create 'rwp' and 'rop' entries for manipulating it in a similar way to rw and ro. If you have a second drive then it will also create /programs1 on /dev/hdc1. The script also goes on and populates /etc/preinit.d with a few shell scripts for starting apps, although I'm sure there's a few more that will need to be added.

Note: You will still need to install the preinit binary and the apps themselves. I have defaulted telnetd to live in /bin, but everything else under /programs0, but you can modify these to suit your needs.





#!/bin/sh

#This script sets stuff up for preinit and 3rd party apps.
#It formats and sets up /dev/hda2 (and /dev/hdc2 if present) for use, and is
#reasonably intelligent - if it can mount a partition then it wont reformat it
#It also provides a couple of utilities for mounting the partitions.
#It then creates /etc/preinit.d and populates it with some useful start scripts - again, if /etc/preinit.d
#already exists, then it will skip this stage.

#CMA Warning: Do not leave this script with executable permissions on your home linux boxes. chmod it to 600.

# copyright: Ian Danby. 2002.
# GPL Version 2 or later. See www.fsf.org for legalese.

#Put root into rw mode.
rw || exit

#Create mountpoints
mkdir /programs0
mkdir /programs1
chmod 755 /programs0
chmod 755 /programs1

#Format partitions. We'll try mounting the partitions first.
#If we can grep them in /proc/mounts then we alread have a valid fs and should skip.

mount -n -r -t ext2 /dev/hda2 /programs0
[ -e /proc/ide/hdb ] && mount -n -r -t ext2 /dev/hdc2 /programs1

grep /dev/hda2 /proc/mounts > /tmpfile
if [ -s /tmpfile ]; then
echo "/dev/hda2 already formatted. Skipping."
else
mke2fs /dev/hda2
fi
rm /tmpfile

if [ -e /proc/ide/hdb ]; then
grep /dev/hdc2 /proc/mounts > /tmpfile
if [ -s /tmpfile ]; then
echo "/dev/hdc2 already formatted. Skipping."
else
mke2fs /dev/hdc2
fi
rm /tmpfile
fi

#Modify /etc/fstab

grep /dev/hda2 /etc/fstab > /tmpfile
if [ -s /tmpfile ]; then
echo "/etc/fstab already contains an entry for /dev/hda2. Skipping."
else
echo "/dev/hda2 /programs0 ext2 defaults,ro 1 1" >> /etc/fstab
echo "Entry for /dev/hda2 appended to /etc/fstab"
fi
rm /tmpfile

if [ -e /proc/ide/hdb ]; then
grep /dev/hdc2 /etc/fstab > /tmpfile
if [ -s /tmpfile ]; then
echo "/etc/fstab already contains an entry for /dev/hdc2. Skipping."
else
echo "/dev/hdc2 /programs1 ext2 defaults,ro 1 1" >> /etc/fstab
echo "Entry for /dev/hdc2 appended to /etc/fstab"
fi
rm /tmpfile
fi


#Create a couple of useful 'binaries', /bin/rwp and /bin/rop. Guess what they do.
cat <<-END > /bin/rwp
#!/bin/sh
mount -n -o remount,rw /programs0
[ -e /proc/ide/hdb ] && mount -n -o remount,rw /programs1
END
chmod 755 /bin/rwp

cat <<-END > /bin/rop
#!/bin/sh
mount -n -o remount,ro /programs0
[ -e /proc/ide/hdb ] && mount -n -o remount,ro /programs1
END
chmod 755 /bin/rop



#Create /etc/preinit.d and populate it. Skip and exit if it already exists.
if [ -e /etc/preinit.d ]; then
echo "/etc/preinit.d already exists!. Skipping."
ro
exit
else
mkdir /etc/preinit.d
fi

#It shouldn't matter if we try to preinit stuff that doesn't exist. The shell deals with missing binaries
####

#telnetd. Best put in the /bin partition so that we can access it immediately. Lets do this first just in case.
#Note that the 'N' prefix tells preinit to do this before config.ini is read (ie drives aren't mounted yet)
cat <<-END > /etc/preinit.d/N10telnetd
#!/bin/bash
/bin/telnetd
END
chmod 755 /etc/preinit.d/N10telnetd

#mount the new drives. Also done before config.ini is read.
cat <<-END > /etc/preinit.d/N20mount
#!/bin/bash
mount -n /programs0
[ /proc/ide/hdb ] && mount -n /programs1
END
chmod 755 /etc/preinit.d/N20mount


#Everything else that follows should probably live in the new parition(s), so need the 'M' prefix.
#For now, let's stuff everything in /programs0...Edit to suit
#Let me know what I've missed.
####

#empacman. The reason I finally got around to doing this...Great stuff.
cat <<-END > /etc/preinit.d/M10empacman
#!/bin/bash
/programs0/empacman
END
chmod 755 /etc/preinit.d/M10empacman


#emptris
cat <<-END > /etc/preinit.d/M20emptris
#!/bin/bash
/programs0/emptris
END
chmod 755 /etc/preinit.d/M20emptris

#emptriv. Note that this is a subdir.
cat <<-END > /etc/preinit.d/M30emptriv
#!/bin/bash
/programs0/emptriv/emptriv
END
chmod 755 /etc/preinit.d/M30emptriv

#empan. AFAIK, there is is command line only at the moment, hence the commenting out.
#Maybe some nice soul will hijackify it, and give a means of menu-selecting a file from a named directory
#cat <<-END > /etc/preinit.d/M40empan
# #!/bin/bash
# /programs0/empan
#END
#chmod 755 /etc/preinit.d/M40empan


#Lets be paranoid before exiting.
ro
rop

exit


Attachments
104935-mkprgpt (520 downloads)

_________________________
Mk2a 60GB Blue. Serial 030102962 sig.mp3: File Format not Valid.