6. 附录 -- 相应的脚本 1. msinfo.sh 脚本 #!/bin/sh # # msinfo.sh This shell script displays the boot sector of the # given partition. # # Author: Rahul U. Joshi # # Modifications Removed the use of expr and replaced it by the let # command.
# check for command line arguments if [ $# -ne 1 ]; then echo "Usage: msinfo " exit 1 fi
# check whether the input name is a block device if [ ! -b $1 ]; then echo "msinfo: $1 is not a block device" exit 1 fi
# create two temporary files for use TMPFILE=`mktemp -q /tmp/$0.XXXXXX` if [ $? -ne 0 ]; then echo "msinfo: Can't create temp file, exiting..." exit 1 fi
TXTFILE=`mktemp -q /tmp/$0.XXXXXX` if [ $? -ne 0 ]; then echo "msinfo: Can't create temp file, exiting..." rm -f $TMPFILE exit 1 fi
back_title="`printf "%78s" "msinfo, Information about FAT16 filesystem -- Rahul Joshi"`"
dialog --title "Boot sector of $1" --backtitle "$back_title" --infobox "\nAnalysing boot sector for $1\nPlease wait ..." 14 60
# truncate TXTFILE to zero length echo > $TXTFILE
# get Formatting DOS version dd 2>/dev/null if=$1 bs=1 count=8 skip=3 | dd 2>/dev/null of=$TMPFILE printf >>$TXTFILE "%30s : %s\n" "Formatting DOS version" "`cat $TMPFILE`"
# check if filesystem in a FAT16 if [ "`cat $TMPFILE`" != "FAT16 " ]; then dialog --title "Boot sector of $1" --backtitle "$back_title" --infobox "\nCan't find a FAT16 filesystem on $1" 14 60 exit 2 fi
# get volume label in boot sector dd 2>/dev/null if=$1 bs=1 count=11 skip=43 | dd 2>/dev/null of=$TMPFILE printf >>$TXTFILE "%30s : %s\n" "Volume label in boot sector" "`cat $TMPFILE`"
2. swapinit.sh #!/bin/sh # # /etc/rc.d/init.d/swapinit.sh - activate the swap partition # # written by Rahul U. Joshi # Verify and initialize swap space #
echo -n 'Verifying swap space... '
loopcount=0
# flag to indicate whether the partition has been activated or not
activated=0
# check for signatures 6 times before giving up while [ $loopcount -lt 6 ] do if [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=10 skip=4086`" = 'SWAPSPACE2' ]; then
if [ $activated -ne 1 ] ; then echo "Swap signature not found after $loopcount tries" echo "No swapping partitions activated" exit 1 fi
3. swaphalt.sh #!/bin/sh # # /etc/rc.d/init.d/swapinit.sh - activate the swap partition # # written by Rahul U. Joshi # Verify and initialize swap space #
echo -n 'Verifying swap space... '
loopcount=0
# flag to indicate whether the partition has been activated or not activated=0
# check for signatures 6 times before giving up while [ $loopcount -lt 6 ] do if [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=10 skip=4086`" = 'SWAPSPACE2' ]; then