home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / Pudd < prev    next >
Encoding:
Text File  |  2005-11-17  |  25.6 KB  |  681 lines

  1. #!/bin/sh
  2. #this is a frontend to dd
  3. # will copy corrupted partitions, as well as healthy ones.
  4.  
  5.  
  6. BKCOLOR='#ffe0e0'
  7. BLURBERR=""
  8. > /tmp/umounterr.txt
  9.  
  10. #recognise IDE Zip drive...
  11. FOUNDZIP=""
  12. #ZIPDETAIL="`probedisk | grep -i "zip" | head -n 1 -`"
  13. #if [ ! "$ZIPDETAIL" = "" ];then
  14. # #load ide-floppy.o to access atapi zip drive...
  15. # ZIPMODULE="`lsmod | grep "ide-floppy"`"
  16. # if [ "$ZIPMODULE" = "" ];then
  17. #  modprobe ide-floppy
  18. # fi
  19. #fi
  20.  
  21. #recognise floppy...
  22. PROBEFD0="`disktype /dev/fd0 2>&1`"
  23. echo "$PROBEFD0" | grep "No such device"
  24. if [ $? -eq 0 ];then
  25.  FOUNDFD0=""
  26. else
  27.  FINDFD0="`echo "$PROBEFD0" | head -n 4 | tail -n 1`"
  28.  FD0FS="`echo "$FINDFD0" | cut -f 1 -d " " | grep -i "fat"`"
  29.  if [ $? -eq 0 ];then
  30.   FD0FS="vfat"
  31.  else
  32.   FD0FS="`echo "$FINDFD0" | cut -f 1 -d " " | grep -i "ext"`"
  33.   if [ $? -eq 0 ];then
  34.    FD0FS="ext2"
  35.   else
  36.    FD0FS="msdos"
  37.   fi
  38.  fi
  39.  FOUNDFD0="/dev/fd0|${FD0FS}||floppy disk
  40. "
  41. fi
  42.  
  43.  
  44. while [ 1 ];do #first loop.
  45.  
  46.  
  47.  BLURB2="If all is well, click a button to choose source drive/partition/image-file..."
  48.  RETMSG0="`probepart -k 2>&1`"
  49.  if [ ! $? -eq 0 ];then
  50.   BLURB2="...HOWEVER, Puppy detects an error probing the partitions!!!"
  51.   USBERR="`echo -n "$RETMSG0" | grep "/dev/sd"`"
  52.   if [ ! "$USBERR" = "" ];then
  53.    sync
  54.    #find what usb mounted on and unmount (don't assume /mnt/flash)...
  55.    USBMNTD="`mount | grep "/dev/sd" | cut -f 3 -d " " | tr "\n" " "`"
  56.    for ONEUSBMNT in $USBMNTD
  57.    do
  58.     rox -D "$ONEUSBMNT"
  59.     #fuser -k -m $ONEUSBMNT
  60.     sync
  61.     umount -r $ONEUSBMNT 2> /tmp/umounterr.txt
  62.    done
  63.    modprobe -r usb-storage
  64.    BLURB2="...HOWEVER, Puppy detects an error probing the USB partitions!!!"
  65.   fi
  66.   BKCOLOR='#ffc0c0'
  67.  else
  68.   BKCOLOR='#e0ffe0'
  69.  fi
  70.  PROBEPART0="`probepart -k | grep "/dev/"`"
  71.  PROBEPARTALL="$FOUNDZIP$FOUNDFD0$PROBEPART0"
  72.  PROBEDISK0="`probedisk | grep "/dev/"`"
  73.  PROBEDISKALL="$FOUNDFD0$PROBEDISK0"
  74.  
  75.  #we should not copy from/to anything that is mounted...
  76.  MNTLIST="`df | grep "/dev/" | cut -f 1 -d " " | tr "\n" " "`"
  77.  for MNTONE in $MNTLIST
  78.  do
  79.   NONMATCH="`echo -n "$PROBEPARTALL" | grep -v "$MNTONE"`"
  80.   PROBEPARTALL="$NONMATCH"
  81.  done
  82.  #...PROBEPARTALL has mounted partitions removed.
  83.  DISKLIST="`echo -n "$PROBEDISKALL" | cut -f 1 -d "|" | tr "\n" " "`"
  84.  for DISKONE in $DISKLIST
  85.  do
  86.   if [ ! "`echo "$MNTLIST" | grep "$DISKONE"`" = "" ];then
  87.    NONMATCH="`echo -n "$PROBEDISKALL" | grep -v "$DISKONE"`"
  88.    PROBEDISKALL="$NONMATCH"
  89.   fi
  90.  done
  91.  #...if PROBEDISKALL contains any mounted partitions, drive is removed.
  92.  
  93. BLURB1="Welcome to Pudd, the Puppy universal dd drive/partition/image-file backup/rescue program!
  94. This program will copy any drive, partition, or image-file to another drive, partition
  95. or file, on the same PC or over a network. You can use Pudd to make copies of floppy
  96. disks, to make clones of a drive/partition, or to rescue a failing drive/partition.
  97.  
  98. Okay, the first thing to do is decide on the source:
  99.  1. If the source is a file, it must be a complete filesystem, such as produced by a 
  100.     previous usage of Pudd to copy a partition or drive  to a file -- such a \"file\" is
  101.     not like an ordinary text or graphic file, it is an image of a partition or complete
  102.     drive. An image file can be copied to a partition or drive,  an ordinary file cannot.
  103.  2. If the source is a drive, for example /dev/sda, the entire drive is copied. However, if
  104.     source is a partition, example: /dev/sda1, then it only is copied (sda1, sda2, etc. are
  105.     partitions in drive sda. Some drives do not have individual partitions, ex: /dev/fd0,
  106.     that is, there is only one partition that occupies the entire drive).
  107.  
  108. These are the partitions that Puppy knows about (Note: mounted partitions not
  109. shown. A mounted partition should be unmounted before copying from/to it):
  110. $PROBEPARTALL
  111.  
  112. ...if USB partitions are missing or incorrect, click the \"Probe USB\" button...
  113. ...if ZIP partitions are missing or incorrect, click the \"Probe ZIP\" button...
  114. ...if floppy disk partition missing or incorrect, click \"Probe FLOPPY\" button...
  115. $BLURB2"
  116.  
  117. if [ -s /tmp/umounterr.txt ];then
  118.  BKCOLOR="#ff8080"
  119.  CATERR="`cat /tmp/umounterr.txt`"
  120.  BLURBERR="ERROR: Puppy experienced a problem trying to unmount a partition:
  121. $CATERR
  122. "
  123. fi
  124.  
  125. xmessage -bg "$BKCOLOR" -center -name "Pudd" -title "Puppy universal dd" -buttons "Probe USB":14,"Probe ZIP":15,"Probe FLOPPY":16,"Choose drive":17,"Choose partition":11,"Choose file":10,HELP:12,EXIT:13 -file -<<MSG1
  126. $BLURBERR$BLURB1
  127. MSG1
  128.  
  129. RETVAL=$?
  130. BLURBERR=""
  131. > /tmp/umounterr.txt
  132. case ${RETVAL} in
  133.    10)# file
  134.      SOURCECHOICE="file"
  135.      break
  136.      ;;
  137.    11)# partition
  138.      SOURCECHOICE="partition"
  139.      break
  140.      ;;
  141.    17)# drive
  142.      SOURCECHOICE="drive"
  143.      break
  144.      ;;
  145.    12)# HELP
  146.      dillo file:///usr/share/doc/Pudd.htm &
  147.      ;;
  148.    13)# EXIT
  149.      exit
  150.      ;;
  151.    14)# probe USB
  152.      sync
  153.      #find what usb mounted on and unmount (don't assume /mnt/flash)...
  154.      USBMNTD="`mount | grep "/dev/sd" | cut -f 3 -d " " | tr "\n" " "`"
  155.      for ONEUSBMNT in $USBMNTD
  156.      do
  157.       rox -D "$ONEUSBMNT"
  158.       #fuser -k -m $ONEUSBMNT
  159.       sync
  160.       umount $ONEUSBMNT 2> /tmp/umounterr.txt
  161.      done
  162.      modprobe -r usb-storage
  163.      xmessage -bg "#ff00ff" -title "Puppy universal dd: probe USB" -center -buttons "" "Wait awhile for the usb-storage driver to reload..." &
  164.      modprobe usb-storage
  165.      killall xmessage
  166.      ;;
  167.    15)# probe ZIP
  168.     FOUNDZIP=""
  169.     ZIPPART=""
  170.      RETZIPMNT="`mount | grep "/mnt/zip"`"
  171.      if [ ! "$RETZIPMNT" = "" ];then
  172.       rox -D "/mnt/zip"
  173.       #fuser -k -m /mnt/zip
  174.       sync
  175.       umount /mnt/zip 2> /tmp/umounterr.txt
  176.      fi
  177.     #is it a ide or parallel-port Zip?...
  178.     xmessage -bg "#ffe0e0" -center -name "Pudd" -title "Puppy universal dd: probe ZIP" -buttons "Parallel port ZIP":14,"IDE (internal) ZIP":15,"none of these:10" "Please choose what type of ZIP drive you have..."
  179.     RETVAL=$?
  180.     if [ $RETVAL -eq 14 ];then
  181.      modprobe -r imm #won't be loaded first time probably.
  182.      sleep 1
  183.      modprobe imm
  184.      if [ $? -eq 0 ];then
  185.       ZIPLOADED="imm"
  186.      fi
  187.     fi
  188.     if [ $RETVAL -eq 15 ];then
  189.      modprobe -r ide-floppy
  190.      sleep 1
  191.      modprobe ide-floppy
  192.      if [ $? -eq 0 ];then
  193.       ZIPLOADED="ide-floppy"
  194.      fi
  195.     fi
  196.     if [ ! "ZIPLOADED" = "" ];then
  197.      sleep 1
  198.      PROBEZIP="`probedisk | grep "|floppy|"`"
  199.      if [ ! "$PROBEZIP" = "" ];then
  200.       #the problem is, probedisk shows drive, but probepart shows nothing.
  201.       #have to find the partition...
  202.       #(got code for this out of rc.sysinit)...
  203.       ZIPDRIVE="`echo "$PROBEZIP" | cut -f 1 -d '|'`"
  204.       ZIPDRIVX="`echo -n $ZIPDRIVE | cut -f 3 -d '/'`"
  205.       PHOM4="`
  206. echo -n $ZIPDRIVX
  207. echo "4"
  208. `"
  209.       PHOM1="`
  210. echo -n $ZIPDRIVX
  211. echo "1"
  212. `"
  213.       if [ ! "$ZIPDRIVE" = "" ];then
  214.        PROBEPHOME="`disktype /dev/$PHOM4 2>&1`"
  215.        echo "$PROBEPHOME" | grep "No such device"
  216.        if [ $? -eq 0 ];then
  217.         #failed to find the partition...
  218.         PROBEPHOME="`disktype /dev/$PHOM1 2>&1`"
  219.         echo "$PROBEPHOME" | grep "No such device"
  220.         if [ ! $? -eq 0 ];then
  221.          ZIPPART="/dev/$PHOM1"
  222.         fi
  223.        else
  224.         ZIPPART="/dev/$PHOM4"
  225.        fi
  226.       fi
  227.      fi
  228.      if [ ! "$ZIPPART" = "" ];then
  229.       #now find f.s. type...
  230.       FINDZIP="`echo "$PROBEHOME" | head -n 4 | tail -n 1`"
  231.       ZIPFS="`echo "$FINDZIP" | cut -f 1 -d " "`"
  232.        #if [ ! "`echo "$ZIPFS" | grep -i "fat"`" = "" ];then
  233.        # ZIPFS="vfat"
  234.        #fi
  235.       FOUNDZIP="${ZIPPART}|${ZIPFS}||floppy zip drive
  236. "
  237.       #a final check, in case probepart is showing it...
  238.       #(danleff reported it did, in case of imm.o driver)
  239.       if [ ! "`probepart -k | grep "$ZIPPART"`" = "" ];then
  240.        FOUNDZIP=""
  241.       fi
  242.      fi
  243.     fi
  244.     ;;
  245.    16)# probe FLOPPY
  246.      RETZIPMNT="`mount | grep "/mnt/floppy"`"
  247.      if [ ! "$RETZIPMNT" = "" ];then
  248.       rox -D "/mnt/zip"
  249.       #fuser -k -m /mnt/floppy
  250.       sync
  251.       umount /mnt/floppy 2> /tmp/umounterr.txt
  252.      fi
  253.     PROBEFD0="`disktype /dev/fd0 2>&1`"
  254.     echo "$PROBEFD0" | grep "No such device"
  255.     if [ $? -eq 0 ];then
  256.      FOUNDFD0=""
  257.     else
  258.      FINDFD0="`echo "$PROBEFD0" | head -n 4 | tail -n 1`"
  259.      FD0FS="`echo "$FINDFD0" | cut -f 1 -d " " | grep -i "fat"`"
  260.      if [ $? -eq 0 ];then
  261.       FD0FS="vfat"
  262.      else
  263.       FD0FS="`echo "$FINDFD0" | cut -f 1 -d " " | grep -i "ext"`"
  264.       if [ $? -eq 0 ];then
  265.        FD0FS="ext2"
  266.       else
  267.        FD0FS="msdos"
  268.       fi
  269.      fi
  270.      FOUNDFD0="/dev/fd0|${FD0FS}||floppy disk
  271. "
  272.     fi
  273.     ;;
  274.    *) 
  275.     exit
  276.     ;;
  277. esac
  278. done
  279.  
  280.  
  281. #now process SOURCECHOICE...
  282. ALLPARTSM="`echo "$PROBEPARTALL" | grep -n "/dev/" | tr " " "_" | sed -e 's/:/PART /g'`"
  283. ALLPARTSS="`echo "$ALLPARTSM" | tr "\n" ":" | sed -e 's/:/ /g'`" #single line.
  284.  
  285. ALLDISKSM="`echo "$PROBEDISKALL" | grep -n "/dev/" | tr " " "_" | sed -e 's/:/PART /g'`"
  286. ALLDISKSS="`echo "$ALLDISKSM" | tr "\n" ":" | sed -e 's/:/ /g'`" #single line.
  287.  
  288.  
  289. if [ "$SOURCECHOICE" = "partition" ];then
  290.  SOURCETAG="`Xdialog --wmclass "Pudd" --title "Puppy universal dd: choose source partition" --stdout \
  291.  --no-tags --menubox "Choose the partition to be copied from:" 0 0 0 $ALLPARTSS 2> /dev/null `"
  292.  if [ ! $? -eq 0 ];then
  293.   exit
  294.  fi
  295.  SOURCEPART="`echo "$ALLPARTSM" | grep "$SOURCETAG" | cut -f 2 -d " " | cut -f 1 -d "|"`"
  296.  SOURCEFS="`echo "$ALLPARTSM" | grep "$SOURCETAG" | cut -f 2 -d " " | cut -f 2 -d "|"`"
  297.  SOURCEBYTES=`disktype $SOURCEPART | grep "Volume size" | tr "(" " " | tr -s " " | cut -f 6 -d " "`
  298.  SOURCESIZE=`expr $SOURCEBYTES \/ 1024`
  299. fi
  300.  
  301. if [ "$SOURCECHOICE" = "drive" ];then
  302.  SOURCETAG="`Xdialog --wmclass "Pudd" --title "Puppy universal dd: choose source drive" --stdout \
  303.  --no-tags --menubox "Choose the drive to be copied from:" 0 0 0 $ALLDISKSS 2> /dev/null `"
  304.  if [ ! $? -eq 0 ];then
  305.   exit
  306.  fi
  307.  SOURCEPART="`echo "$ALLDISKSM" | grep "$SOURCETAG" | cut -f 2 -d " " | cut -f 1 -d "|"`"
  308.  SOURCEFS=""
  309.  SOURCEBYTES=`disktype $SOURCEPART | grep "Block device" | tr "(" " " | tr -s " " | cut -f 6 -d " "`
  310.  SOURCESIZE=`expr $SOURCEBYTES \/ 1024`
  311. fi
  312.  
  313. UNCOMPRPATHNAME=""
  314. WARNING1=""
  315. if [ "$SOURCECHOICE" = "file" ];then
  316.  WARNING1="WARNING1: be careful what you write that file to. If it is an image of a partition
  317.           then it should be written to a partition. If an image of a whole drive, then it
  318.           should be written to a whole drive.
  319. "
  320.  while [ 1 ];do
  321.   SOURCEPART="`Xdialog --wmclass "Pudd" --title "Puppy universal dd: choose source file" --stdout --no-buttons --fselect "" 0 0`"
  322.   if [ ! $? -eq 0 ];then
  323.    exit
  324.   fi
  325.   echo "$SOURCEPART" | grep ".gz"
  326.   if [ $? -eq 0 ];then
  327.    UNCOMPRPATHNAME="`echo "$SOURCEPART" | cut -f 1 -d "."`"
  328.    UNCOMPRPATHNAME="${UNCOMPRPATHNAME}.tmp"
  329.    gunzip -c $SOURCEPART > $UNCOMPRPATHNAME
  330.    if [ ! $? -eq 0 ];then
  331.     xmessage -bg "#ff0000" -center "Error uncompressing $SOURCEPART. Click button to quit..."
  332.     rm -f $UNCOMPRPATHNAME
  333.     exit
  334.    fi
  335.    WARNING1="${WARNING1}WARNING2: $SOURCEPART file has been uncompressed as $UNCOMPRPATHNAME.
  336.           Pudd will delete it, but aborting before completion may prevent this.
  337. "
  338.    SOURCEPART="$UNCOMPRPATHNAME"
  339.    sync
  340.   fi
  341.   SOURCEFS="`disktype $SOURCEPART | grep "file system" | head -n 1 | tr -s " " | cut -f 1 -d " "`"
  342.   if [ "$SOURCEFS" = "" ];then
  343.    xmessage -bg "#ff0000" -name Pudd -title "Puppy universal dd: ERROR" -center "Sorry, this file does not have a filesystem inside it. 
  344. Pudd is not intended for copying ordinary files. A file with a filesystem inside it is an
  345. image of a drive or partition, and may be copied back to a drive or partition. Try again..."
  346.   else
  347.    SOURCEBYTES=`disktype $SOURCEPART | grep "Volume size" | tr "(" " " | tr -s " " | cut -f 6 -d " "`
  348.    SOURCESIZE=`expr $SOURCEBYTES \/ 1024`
  349.    break
  350.   fi
  351.  done
  352. fi
  353.  
  354. #now process DESTCHOICE...
  355. #enter here with SOURCEPART (example: /dev/hda2), SOURCEFS (example: vfat).
  356.  
  357. BLURB7="Ok, you have chosen a source of: ${SOURCEPART}
  358. $WARNING1
  359. Now to choose the destination. This Pudd program will first try to use the \"dd\"
  360. program in normal mode, but if the source has an error it will abort.
  361. Pudd will then try an alternate mode of dd to ignore read errors, which means
  362. that the destination will have errors in it also.
  363.  
  364. If the destination is a file, it will be compressed with the \"gzip\" program. This
  365. means that the file will be about half the size of the source drive/partition.
  366. Well, even though the destination file is compressed, you will still need to 
  367. uncompress it if you ever want to mount it by loopback device, and Pudd also will
  368. uncompress it if it has to be copied to another drive/partition.
  369.  
  370. If the destination is a drive/partition, it must be at least as large as the source
  371. drive/partition -- Pudd will display some info about this in the next window. 
  372.  
  373. If the destination is a partition, Pudd will offer to grow the filesystem to fill
  374. the partition. However, this only applies if the source partition is an ext2,
  375. ext3, or fat12/16/32 (this includes what we call msdos and vfat) filesystem.
  376. (NOTE: destination f.s. does not matter as will be overwritten)
  377. (WARNING: fat resize code is immature. Do not use on anything critical!)
  378.  
  379. Click on \"Run_fdisk\" button to create/edit/delete partitions...
  380.  
  381. If no need to run fdisk, click a button to choose destination...
  382. (Note, if destination not on current PC, click \"Choose_remote\" button)..."
  383.  
  384. BKCOLOR='#ffe0e0'
  385. BUTTONS2="Run_fdisk:16,Choose_drive:14,Choose_partition:11,Choose_file:10,Choose_remote:18,HELP:12,EXIT:13"
  386. if [ "$SOURCECHOICE" = "drive" ];then
  387.  BUTTONS2="Run_fdisk:16,Choose_drive:14,Choose_file:10,Choose_remote:18,HELP:12,EXIT:13"
  388. fi
  389. if [ "$SOURCECHOICE" = "partition" ];then
  390.  BUTTONS2="Run_fdisk:16,Choose_partition:11,Choose_file:10,Choose_remote:18,HELP:12,EXIT:13"
  391. fi
  392.  
  393. while [ 1 ];do #STARTWHILE3
  394.  
  395. xmessage -bg "$BKCOLOR" -center -name "Pudd" -title "Puppy universal dd: choose destination" -buttons "$BUTTONS2" -file -<<MSG1
  396. $BLURB7
  397. MSG1
  398.  
  399. RETVAL=$?
  400.  
  401. case ${RETVAL} in
  402.    10)# file 
  403.      DESTCHOICE="file"
  404.      break
  405.      ;;
  406.    11)# partition
  407.      DESTCHOICE="partition"
  408.      break
  409.      ;;
  410.    14)# drive
  411.      DESTCHOICE="drive"
  412.      break
  413.      ;;
  414.    18)# remote
  415.      DESTCHOICE="remote"
  416.      break
  417.      ;;
  418.    12)# HELP
  419.      dillo file:///usr/share/doc/Pudd.htm &
  420.      ;;
  421.    13)# EXIT
  422.      rm -f $UNCOMPRPATHNAME
  423.      exit
  424.      ;;
  425.    16)# fdisk
  426.      FDISKTAG="`Xdialog --wmclass "Pudd" --title "Puppy universal dd: run fdisk" --stdout \
  427.  --no-tags --menubox "Choose the drive to be examined by fdisk:" 0 0 0 $ALLDISKSS 2> /dev/null `"
  428.      if [ $? -eq 0 ];then
  429.       FDISKPART="`echo "$ALLDISKSM" | grep "$FDISKTAG" | cut -f 2 -d " " | cut -f 1 -d "|"`"
  430.       rxvt -e fdisk $FDISKPART
  431.      fi
  432.      ;;
  433.    *)
  434.     rm -f $UNCOMPRPATHNAME
  435.     exit
  436.     ;;
  437. esac
  438. done #ENDWHILE3
  439.  
  440. ALLOWGROW=""
  441.  
  442. REMOTEADDR="196.108.56.10"
  443. REMOTEPORT="1234"
  444. if [ "$DESTCHOICE" = "remote" ];then
  445.  ERRBLURB=""
  446.  while [ 1 ];do #WHILE9
  447.   RETSTR=`Xdialog --wmclass "Pudd" --title "Puppy universal dd: choose remote" --stdout --left --separator "|" --2inputsbox "${ERRBLURB}To transfer to a remote computer, you have to start the netcat/nc program\nrunning on the remote computer. If the destination is a drive or partition,\nit must be unmounted. The setup could be as simple as a ethernet cross-over\ncable between two PCs, or over the Internet.\nThis is what you need to execute on the remote PC:\n # nc -l -p ${REMOTEPORT} < /dev/null | gunzip -c | dd of=DESTDEV bs=512\n...where DESTDEV is whatever you want to write to, for example /dev/hda1\n...you may be able to leave the bs= parameter off, or make it 1024 for ext2/3.\n...I think for msdos/vfat, bs=512 is correct.\n...the -l parameter means that nc will listen for data incoming at the port.\n...THIS MUST BE DONE RIGHT NOW!\n\nThe local PC needs to know where the remote PC is, and the address may be\na URL or IP. For example, www.goosee.com, or 196.108.56.10.\nThe Port number at local and remote must be the same. I suggest 1234.\n\nPLEASE START THE REMOTE nc PROGRAM RUNNING BEFORE CLICKING OK BUTTON" 0 0 "Remote address:" "$REMOTEADDR" "Port:" "$REMOTEPORT"`
  448.   if [ ! $? -eq 0 ];then
  449.    exit
  450.   fi
  451.   REMOTEADDR=`echo -n "$RETSTR" | cut -f 1 -d "|"`
  452.   REMOTEPORT=`echo -n "$RETSTR" | cut -f 2 -d "|"`
  453.   #need to know that remote PC is reachable...
  454.   RETSTR="`ping -c 1 -q $REMOTEADDR | grep ' 0% '`" #not to REMOTEPORT, as will mess up data transfer.
  455.   if [ "$RETSTR" = "" ];then
  456.    ERRBLURB="ERROR, $REMOTEADDR IS NOT REACHABLE!
  457.  
  458. "
  459.   else #ping was ok.
  460.    DESTFS=""
  461.    DESTPART=""
  462.    DESTINFO=""
  463.    break
  464.   fi
  465.  done #WHILE9
  466. fi
  467.  
  468. if [ "$DESTCHOICE" = "partition" ];then
  469.  while [ 1 ];do #WHILE4
  470.   DESTTAG="`Xdialog --wmclass "Pudd" --title "Puppy universal dd: choose destination partition" --stdout \
  471.  --no-tags --menubox "Choose the partition to be copied to:" 0 0 0 $ALLPARTSS 2> /dev/null `"
  472.   if [ ! $? -eq 0 ];then
  473.    exit
  474.   fi
  475.   DESTPART="`echo "$ALLPARTSM" | grep "$DESTTAG" | cut -f 2 -d " " | cut -f 1 -d "|"`"
  476.   DESTFS="`echo "$ALLPARTSM" | grep "$DESTTAG" | cut -f 2 -d " " | cut -f 2 -d "|"`"
  477.   DESTBYTES=`disktype $DESTPART | grep "Volume size" | tr "(" " " | tr -s " " | cut -f 6 -d " "`
  478.   DESTSIZE=`expr $DESTBYTES \/ 1024`
  479.   if [ $DESTSIZE -gt $SOURCESIZE ];then
  480.    ALLOWGROW="`echo "$SOURCEFS" | grep --extended-regexp "ext2|ext3|Ext2|Ext3|FAT12|FAT16|FAT32|msdos|vfat"`"
  481.    if [ ! "$ALLOWGROW" = "" ];then
  482.     Xdialog --wmclass "Pudd" --title "Puppy universal dd: grow filesystem" --stdout --yesno "Do you want to grow the filesystem to fill the partition?\n(after it is copied to the partition)\n(ext2, ext3 and fat12/16/32 (msdos/vfat) filesystems only)" 0 0
  483.     if [ ! $? -eq 0 ];then
  484.      ALLOWGROW=""
  485.     fi
  486.    fi
  487.    break
  488.   fi
  489.   if [ $DESTSIZE -eq $SOURCESIZE ];then
  490.    break
  491.   fi
  492.   #dest part is too small...
  493.   xmessage -bg "#ff8080" -center -name "Pudd" -title "Puppy universal dd: ERROR" "Sorry, the destination partition is too small. The source 
  494. $SOURCEPART is $SOURCESIZE Kbytes but the destination 
  495. $DESTPART is $DESTSIZE Kbytes. Try again..."
  496.  done #WHILE4
  497. fi
  498.  
  499. if [ "$DESTCHOICE" = "drive" ];then
  500.  while [ 1 ];do
  501.   DESTTAG="`Xdialog --wmclass "Pudd" --title "Puppy universal dd: choose destination drive" --stdout --no-tags --menubox "Choose the drive to be copied to:" 0 0 0 $ALLDISKSS 2> /dev/null `"
  502.   if [ ! $? -eq 0 ];then
  503.    exit
  504.   fi
  505.   DESTPART="`echo "$ALLDISKSM" | grep "$DESTTAG" | cut -f 2 -d " " | cut -f 1 -d "|"`"
  506.   #DESTFS="`echo "$ALLDISKSM" | grep "$DESTTAG" | cut -f 2 -d " " | cut -f 2 -d "|"`"
  507.   DESTFS=""
  508.   DESTBYTES=`disktype $DESTPART | grep "Block device" | tr "(" " " | tr -s " " | cut -f 6 -d " "`
  509.   DESTSIZE=`expr $DESTBYTES \/ 1024`
  510.   if [ $DESTSIZE -ge $SOURCESIZE ];then
  511.    break
  512.   fi
  513.   #dest drive is too small...
  514.   xmessage -bg "#ff8080" -center -name "Pudd" -title "Puppy universal dd: ERROR" "Sorry, the destination drive is too small. The source 
  515. $SOURCEPART is $SOURCESIZE Kbytes but the destination 
  516. $DESTPART is $DESTSIZE Kbytes. Try again..."
  517.  done
  518. fi
  519.  
  520.  
  521. if [ "$DESTCHOICE" = "file" ];then
  522.   DESTPART="`Xdialog --wmclass "Pudd" --title "Pudd: new or choose existing (replace) dest. file" --no-buttons --stdout --fselect "myfile.img" 0 0`"
  523.   if [ ! $? -eq 0 ];then
  524.    exit
  525.   fi
  526.  DESTFS=""
  527. fi
  528.  
  529. SOURCEINFO="`disktype $SOURCEPART`"
  530. if [ "$DESTFS" ];then
  531.  DESTTYPE="`disktype $DESTPART`"
  532.  DESTINFO="Here is what Puppy knows about ${DESTPART} ${DESTCHOICE}:
  533. ${DESTTYPE}
  534. "
  535. else
  536.  DESTINFO=""
  537. fi
  538.  
  539. #v1.0.7
  540. #SPACEINFO="`df | grep -v "rootfs" | grep -v "/dev/loop0"`"
  541. SPACEINFO="`df -k | grep -v "rootfs" | grep -v "/dev/loop0" | grep -v "/dev/loop3" | grep -v "none"`"
  542.  
  543. if [ "$DESTCHOICE" = "file" ];then
  544.  DESTXTN="${DESTPART}.gz"
  545. else
  546.  DESTXTN="$DESTPART"
  547. fi
  548. if [ "$DESTCHOICE" = "remote" ];then
  549.  DESTXTN="${REMOTEADDR}:${REMOTEPORT}"
  550. fi
  551.  
  552. BLURB8="Last chance to backout!
  553. You have chosen to copy ${SOURCEPART} to destination ${DESTXTN}
  554.  
  555. Here is what Puppy knows about ${SOURCEPART}:
  556. $SOURCEINFO
  557. $DESTINFO
  558. ...for a destination partition, make sure that it is at least as big as the source.
  559. ...for a destination file, make sure that the mounted partition where it will reside
  560.    has enough free space. A summary of the space in the local mounted partitions:
  561. $SPACEINFO
  562.  
  563. If everything looks ok, click the \"Continue\" button..."
  564.  
  565. xmessage -bg "$BKCOLOR" -center -name "Pudd" -title "Puppy universal dd: final check" -buttons Continue:10,EXIT:13 -file -<<MSG1
  566. $BLURB8
  567. MSG1
  568.  
  569. RETVAL=$?
  570.  
  571. case ${RETVAL} in
  572.    10)# continue
  573.      #finally, get to try dd...
  574.      echo '#!/bin/sh' > /tmp/backuppartition.sh
  575.      if [ "$DESTCHOICE" = "file" ];then
  576.  
  577.       #if source is partition, zeroise unused part for max compression...
  578.       if [ "$SOURCECHOICE" = "partition" ];then
  579.        ALLOWZERO="`echo "$SOURCEFS" | grep --extended-regexp "ext2|ext3|Ext2|Ext3|FAT12|FAT16|FAT32|msdos|vfat|ReiserFS|reiserfs"`"
  580.        if [ ! "$ALLOWZERO" = "" ];then
  581.         Xdialog --wmclass "Pudd" --title "Puppy universal dd: optimise compression" --stdout --yesno "$SOURCEPART will be copied to $DESTPART.gz, compressed with gzip.
  582. Compression may be greatly improved if the unused part of $SOURCEPART
  583. is zeroised. This involves temporarily mounting it on /mnt/tmp,
  584. writing zeroes to the unused areas, then unmounting it.
  585. Would you like to do this size optimisation?" 0 0
  586.         if [ $? -eq 0 ];then
  587.          mkdir /mnt/tmp 2> /dev/null
  588.          if [ ! "`echo "$SOURCEFS" | grep --extended-regexp "ext2|ext3|Ext2|Ext3"`" = "" ];then
  589.           APPLYFS="`echo -n "$SOURCEFS" | tr "E" "e"`"
  590.          else
  591.           if [ ! "`echo "$SOURCEFS" | grep --extended-regexp "FAT12|FAT16|FAT32|msdos|vfat"`" = "" ];then
  592.            APPLYFS="vfat"
  593.           else
  594.            APPLYFS="reiserfs"
  595.           fi
  596.          fi
  597.          echo 'echo "Now zeroising unused areas of $2 ..."' >> /tmp/backuppartition.sh
  598.          echo 'echo "For a large partition, this may take awhile..."'  >> /tmp/backuppartition.sh
  599.          echo "mount -t $APPLYFS $SOURCEPART /mnt/tmp"  >> /tmp/backuppartition.sh
  600.          echo 'PARTFREE=`df | grep "$2" | tr -s " " | head -n 1 | cut -f 4 -d " "`'  >> /tmp/backuppartition.sh
  601.          echo 'cd /mnt/tmp'  >> /tmp/backuppartition.sh
  602.          echo 'dd if=/dev/zero of=empty.tmp bs=1024 count=$PARTFREE'  >> /tmp/backuppartition.sh
  603.          echo 'sync'  >> /tmp/backuppartition.sh
  604.          echo 'rm -f empty.tmp'  >> /tmp/backuppartition.sh
  605.          echo 'sync'  >> /tmp/backuppartition.sh
  606.          echo 'cd /'  >> /tmp/backuppartition.sh
  607.          echo 'umount /mnt/tmp'  >> /tmp/backuppartition.sh
  608.          echo 'rmdir /mnt/tmp'  >> /tmp/backuppartition.sh
  609.          echo 'echo "...done"'  >> /tmp/backuppartition.sh
  610.          echo 'echo'  >> /tmp/backuppartition.sh
  611.         fi
  612.        fi
  613.       fi
  614.  
  615.       echo 'echo "Now copying $2 to $1, please wait very patiently..."' >> /tmp/backuppartition.sh
  616.       echo "dd if=$SOURCEPART | gzip - > $DESTPART.gz" >>  /tmp/backuppartition.sh
  617.       echo 'if [ ! $? -eq 0 ];then' >>  /tmp/backuppartition.sh
  618.       echo ' echo' >> /tmp/backuppartition.sh
  619.       echo ' echo "Read error, starting again, ignoring errors..."' >> /tmp/backuppartition.sh
  620.       echo " dd if=$SOURCEPART  conv=noerror | gzip - > $DESTPART.gz" >> /tmp/backuppartition.sh
  621.       echo 'fi' >> /tmp/backuppartition.sh
  622.      else
  623.       if [ "$DESTCHOICE" = "remote" ];then
  624.        echo 'echo "Now copying $2 to remote PC, please wait very patiently..."' >> /tmp/backuppartition.sh
  625.        echo "dd if=$SOURCEPART | gzip -c | nc $REMOTEADDR $REMOTEPORT" >> /tmp/backuppartition.sh
  626.        echo 'if [ ! $? -eq 0 ];then' >> /tmp/backuppartition.sh
  627.        echo ' echo' >> /tmp/backuppartition.sh
  628.        echo ' echo "Read error, starting again and will ignore errors..."' >> /tmp/backuppartition.sh
  629.        echo ' echo "KILL THE NETCAT LISTENER ON REMOTE PC, AND START IT AGAIN"' >> /tmp/backuppartition.sh
  630.        echo ' echo -n "DO THAT RIGHT NOW, THEN PRESS ENTER KEY: "' >> /tmp/backuppartition.sh
  631.        echo ' read mmmm' >> /tmp/backuppartition.sh
  632.        echo " dd if=$SOURCEPART conv=noerror | gzip -c | nc $REMOTEADDR $REMOTEPORT" >> /tmp/backuppartition.sh
  633.        echo 'fi' >> /tmp/backuppartition.sh
  634.       else
  635.        echo 'echo "Now copying $2 to $1, please wait very patiently..."' >> /tmp/backuppartition.sh
  636.        echo "dd if=$SOURCEPART of=$DESTPART" >> /tmp/backuppartition.sh
  637.        echo 'if [ ! $? -eq 0 ];then' >> /tmp/backuppartition.sh
  638.        echo ' echo' >> /tmp/backuppartition.sh
  639.        echo ' echo "Read error, starting again and will ignore errors..."' >> /tmp/backuppartition.sh
  640.        echo " dd if=$SOURCEPART of=$DESTPART conv=noerror" >> /tmp/backuppartition.sh
  641.        echo 'fi' >> /tmp/backuppartition.sh
  642.       fi
  643.      fi
  644.  
  645.      echo 'sync' >> /tmp/backuppartition.sh
  646.      echo 'echo' >> /tmp/backuppartition.sh
  647.      if [ ! "$ALLOWGROW" = "" ];then
  648.       echo 'echo "Resizing $4 filesystem to fill $3 Kbyte partition..."' >> /tmp/backuppartition.sh
  649.       if [ ! "`echo "$ALLOWGROW" | grep --extended-regexp "ext2|ext3|Ext2|Ext3"`" = "" ];then
  650.        echo 'echo "First check and fix f.s...."' >> /tmp/backuppartition.sh
  651.        echo "e2fsck -f -y $DESTPART" >> /tmp/backuppartition.sh
  652.        echo "sync" >> /tmp/backuppartition.sh
  653.        echo 'echo "Now resizing f.s...."' >> /tmp/backuppartition.sh
  654.        echo "resize2fs -f $DESTPART" >> /tmp/backuppartition.sh
  655.       else
  656.        if [ ! "`echo "$ALLOWGROW" | grep --extended-regexp "FAT12|FAT16|FAT32|msdos|vfat"`" = "" ];then
  657.         echo 'echo "WARNING: Immature code, do not use for anything critical!"' >> /tmp/backuppartition.sh
  658.         echo 'echo "         Changes have been backed up in /tmp/fsresizebackup.dat"' >> /tmp/backuppartition.sh
  659.         echo 'echo "         (see fsresize doc page how to restore f.s.)"' >> /tmp/backuppartition.sh
  660.         echo "fsresize $DESTPART $DESTSIZE -b /tmp/fsresizebackup.dat" >> /tmp/backuppartition.sh
  661.        fi
  662.       fi
  663.       echo 'echo "...done"' >> /tmp/backuppartition.sh
  664.       #echo 'fi' >> /tmp/backuppartition.sh
  665.      fi
  666.      echo 'echo -n "Backup finished. Press ENTER key to exit: "' >> /tmp/backuppartition.sh
  667.      echo 'read nnn' >> /tmp/backuppartition.sh
  668.      sync
  669.      chmod 755 /tmp/backuppartition.sh
  670.      rxvt -name Pudd -title "Puppy universal dd: copying" -bg "#ffff00" -geometry 80x8 -e /tmp/backuppartition.sh ${DESTPART} ${SOURCEPART} ${DESTSIZE} ${ALLOWGROW} 
  671.      ;;
  672.    13)# EXIT
  673.      ;;
  674.    *)
  675.     ;;
  676. esac
  677.  
  678. rm -f $UNCOMPRPATHNAME
  679.  
  680. ###END###
  681.