home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / shell / 4739 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  4.4 KB

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!agate!ames!olivea!charnel!rat!koko.csustan.edu!altair.csustan.edu!alfredo
  2. From: alfredo@altair.csustan.edu (ALFREDO MARTINEZ)
  3. Newsgroups: comp.unix.shell
  4. Subject: Self extractable shell script archive.
  5. Summary: This is a shell script that archives files in uuencoded form.
  6. Message-ID: <1992Nov16.235131.27610@koko.csustan.edu>
  7. Date: 16 Nov 92 23:51:31 GMT
  8. Sender: news@koko.csustan.edu (USENET News System)
  9. Organization: CSU Stanislaus
  10. Lines: 107
  11.  
  12. Here is a little shell script that will allow you to contruct
  13. a self extractable shell script with files in uuencoded form.
  14. This can be particularly handy for posting or e-mailing binary
  15. and/or ordinary files.
  16.  
  17. Although I spend quite a deal of time trying to make this script
  18. bug-free, I am sure it is not perfect. Up until now I have found
  19. this script to come in very handy and works like a charm. 
  20. When you save this shell script be sure to remember to "chmod" it to
  21. make it executable. Otherwise you will have to be "sh" ing. To make
  22. it executable you can do one of the following:
  23. chmod u+x selfx
  24.     -or-
  25. chmod 700 selfx
  26. Where selfx is the name of the ifollowing shell script.
  27.  
  28.         Enjoy  :)
  29. ------------------------------CUT HERE-----------------------------
  30. #! /bin/sh
  31. # file: selfx
  32. # This is a shell script that will produce a self extracting archive
  33. # which is uuencoded. This can be useful for posting binary or executables.
  34. trap 'echo "Aborting...";/bin/rm ${OUTFILE};exit 1' 1 2 3 15
  35. OUTPUT=
  36. COUNTER=0
  37. if [ $# -le "1" ]
  38. then
  39.    echo "Usage: ${0} outputname sourcefile sourcefile2 ..."
  40.    echo "Where outputname is the name of the self extracting archive"
  41.    echo "and sourcefile(s) are the files that you wish to archive."
  42.    echo "Wildcards such as * and ? may be used if desired."
  43.    exit 1
  44. else
  45.    OUTFILE=${1}
  46.    if [ -s "${OUTFILE}" ] 
  47.    then
  48.       echo "File: ${OUTFILE} already exists"   
  49.       exit 1
  50.    else
  51.       echo "Creating self extractable archive  ${OUTFILE} "
  52.       echo ""
  53.       echo "#! /bin/sh" >> ${OUTFILE}
  54.       echo "# **********************************************************" >> \
  55.       ${OUTFILE}
  56.       echo "# This is a self extracting archive shell script." >> ${OUTFILE}
  57.       echo "# You can extract by typing:  sh filename, where filename" \
  58.       >> ${OUTFILE} 
  59.       echo "# is the name of this file." >> ${OUTFILE}
  60.       echo "# Created `date` by user `who am i|awk '{print $1}'`" >> ${OUTFILE}
  61.       echo "# This archive contains the following files:" >> ${OUTFILE}
  62.       echo  "Assessing file(s). One moment please ..."
  63.       for myfile in `ls $*`
  64.       do
  65.      if [ -f "${myfile}" -a "${myfile}" != "${OUTFILE}" ]
  66.      then
  67.         COUNTER=`expr ${COUNTER} + 1`
  68.         ls -l ${myfile}|awk '{print "# File    -----> " $8" : " $4 " bytes"}' \
  69.         >> ${OUTFILE}
  70.      fi
  71.       done
  72.       echo "# Total number of file(s) = ${COUNTER} " >> ${OUTFILE}
  73.       echo "# **********************************************************" >> \
  74.       ${OUTFILE}
  75.       echo "Archiving ${COUNTER} file(s)."
  76.       echo ""    
  77.       chmod 700 ${OUTFILE}
  78.       echo "" >> ${OUTFILE}
  79.       echo "" >> ${OUTFILE}
  80.       echo "trap 'echo "Aborting...";exit 1' 1 2 3 15" >> ${OUTFILE}
  81.       echo "echo 'Unarchiving all files in  ${OUTFILE} '"  \
  82.       >> ${OUTFILE}
  83.       echo "" >> ${OUTFILE}
  84.       shift
  85.       for arg do
  86.          if [ ! -s "${1}" ]
  87.          then
  88.             echo " ${1}  does not exist or is empty."
  89.          else
  90.             if [ ! -d "${1}" ]
  91.             then
  92.                OUTPUT="YES"
  93.                echo "Adding  ${1}  to ${OUTFILE}."
  94.                echo "echo 'Extracting ${1} ...'" >> ${OUTFILE}
  95.                echo 'uudecode << "XXXXEORXXXX"' >> ${OUTFILE}
  96.                uuencode ${1} ${1} >> ${OUTFILE}
  97.                echo "XXXXEORXXXX" >> ${OUTFILE}
  98.             fi
  99.          fi
  100.          shift
  101.       done
  102.       echo ""
  103.       if [ -z "${OUTPUT}"  ]
  104.       then
  105.          echo "No file(s) found."
  106.          echo "Archive ${OUTFILE} was not created."
  107.          /bin/rm ${OUTFILE}
  108.       else
  109.          echo "Archive ${OUTFILE}  is now a self extractable archive."
  110.       fi
  111.    fi
  112. fi
  113. ------------------------------CUT HERE-----------------------------
  114. -- 
  115. --------------------------------------------------------------------------------
  116.  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | Alfredo Martinez                       
  117. _______________________________________| e-mail (alfredo@altair.csustan.edu)   
  118.  Cogito cogito, ergo cogito sum.   ( I think I think, therefore I think I am.)
  119.