#!/bin/sh #File: /u/kscott/work/src/makedisk #Author: K. Scott Rowe #Time-stamp: <05/07/1998 15:40:56 kscott@pescado.tcct.nmt.edu> # # future improvements # # if mount or cp fails, skip and moveing gracefully # # add a status bar for making CD's # # the linux ufs driver does not read OSF/ufs floppies well. # if ufs is not compiled in kernel or module the mount will # fail and makedisk will move on. it if is compiled in, mount # will not fail, but you wont be able to umount the image. SetUp() { USAGE="Usage: `basename $0` [-h]" HOME=/fs/holmium/disks cd ${HOME} TMPFILE=/tmp/makedisk.$$ touch ${TMPFILE} ERRFILE=/tmp/makedisk_err.$$ touch ${ERRFILE} IMGFILE=/tmp/makedisk_image.$$ touch ${IMGFILE} FLOPPY=/tmp/makedisk_floppy.$$ mkdir ${FLOPPY} } ParseArgs() { while [ "$*" != "" ] ; do if [ "$1" = "-h" ] ; then echo ${USAGE} exit 0 fi shift done } CleanUp() { rm ${TMPFILE} 2> /dev/null rm ${ERRFILE} 2> /dev/null rm ${IMGFILE} 2> /dev/null rm -rf ${FLOPPY} 2> /dev/null } DisplayDirs() { DIRS=".. .. ViewReadme ViewReadme MakeCDROM MakeCDROM ---- ----" # for x in * ; do for x in `ls -1 | sed -e 's/\.dd-.*$//' | uniq` ; do DIRS="${DIRS} $x $x" done dialog --title "$CWD" --clear --menu "pick one" 24 80 18 ${DIRS} 2> ${TMPFILE} } ViewReadme() { dialog --title "$CWD" --clear --textbox ${PWD}/README 24 80 } ChangeDir() { cd `cat $TMPFILE` CWD="`echo $PWD | sed -e 's#'$HOME'##'`" } CallError() { dialog --title "Error" --msgbox "`cat ${ERRFILE}`" 10 40 } MakeCDROM() { if [ "`whoami`" != "root" ] ; then dialog --title "Error" --msgbox "You must be root to do this" 10 40 return 1 fi if [ "`uname -s`" != "Linux" ] ; then dialog --title "Error" --msgbox "You must use Linux for this" 10 40 return 1 fi #kscott May 7 1998: kerlend doesn't always load modules correctly modprobe -a -t fs \* 2> ${ERRFILE} || CallError modprobe -t block loop 2> ${ERRFILE} || CallError basedir="${HOME}/${CWD}" dialog --title "Enter A Location" --inputbox "Enter directory for CD image" 10 40 2> ${TMPFILE} cdimage="`cat ${TMPFILE}`" if [ ! -d ${cdimage} ] ; then mkdir -p ${cdimage} 2> ${ERRFILE} || CallError fi master_readme="${cdimage}/master_readme" touch ${master_readme} for x in . `find -type d -print | cut -d'.' -f2-` ; do cd ${basedir}/$x for y in *.dd-* ; do imagename="`echo ${y} | sed -e 's/\.dd-.*$//'`" if [ ! -f ${y} ] ; then # see if its really there break fi if [ ! -d ${cdimage}/${x}/${imagename} ] ; then mkdir -p ${cdimage}/${x}/${imagename} 2> ${ERRFILE} || CallError fi cp $y ${IMGFILE} 2> ${ERRFILE} || CallError mount ${IMGFILE} ${FLOPPY} -o loop=/dev/loop3 2> ${ERRFILE} if [ "$?" != "0" ] ; then dialog --title "Warning" --infobox "${imagename} is on an unsopported filesystem. The image will not be copied." 10 40 else ( (cd ${FLOPPY} ; tar cf - .) | (cd ${cdimage}/${x}/${imagename} ; tar xfp -) ) 2> /dev/null umount ${FLOPPY} fi done if [ -f README ] ; then if [ ! -d ${cdimage}/${x} ] ; then mkdir -p ${cdimage}/${x} 2> ${ERRFILE} || CallError fi cp README ${cdimage}/${x}/README 2> ${ERRFILE} || CallError echo "--- ${x} ---" >> ${master_readme} cat README >> ${master_readme} echo "" >> ${master_readme} echo "" >> ${master_readme} fi done cd ${basedir} } MakeDisk() { image="`cat ${TMPFILE}`" numdisks="`ls -1 ${image}* | sed -e 's/\.dd-.*$//' | wc -l | sed -e 's/[ ]*//'`" dialog --title "Making Disks" --msgbox "There are ${numdisks} disk(s) in this set\nInsert disk 1\nPress RETURN to begin..." 10 40 for x in ${image}.dd* ; do # dialog --title "testing" --msgbox ${x} 10 40 dd if=${x} of=/dev/fd0 bs=8192 > /dev/null 2>&1 if [ "${numdisks}" = "1" ] ; then break fi numdisks=`echo "${numdisks} 1 - p" | dc` dialog --title "Making Disks" --msgbox "There are ${numdisks} disk(s) left in this set\nInsert disk 1\nPress RETURN to begin..." 10 40 done } DirOrImage() { if [ -d `cat $TMPFILE` ] ; then ChangeDir else MakeDisk fi } # # main program # SetUp ParseArgs $* while [ 1 ] ; do DisplayDirs [ "$?" = "1" ] && break choice="`cat ${TMPFILE}`" if [ "${choice}" = "ViewReadme" ] ; then ViewReadme elif [ "${choice}" = "README" ] ; then ViewReadme elif [ "${choice}" = "MakeCDROM" ] ; then MakeCDROM elif [ "${choice}" != "----" ] ; then DirOrImage fi done CleanUp