home *** CD-ROM | disk | FTP | other *** search
/ Sybex Virtual Trainer CCNP Switching / Sybex_Virtual_Trainer_CCNP_Switching.iso / autorun < prev    next >
Text File  |  2001-01-22  |  3KB  |  125 lines

  1. #!/bin/sh
  2.  
  3. # Autorun script. Will be launched by most Linux systems 
  4. # when CD is inserted. System can launch it immediately
  5. # or ask whether to launch it, depending on configuration
  6.  
  7. # Runs main install script in a new Xterm window if this 
  8. # Sybex course was not installed before
  9.  
  10.  
  11. # CompareCourses function - compares two courses lines.
  12. # Returns 0 if all the courses names in the second line
  13. # are present in the first line
  14. # Arguments:
  15. # $1 - courses line to be compared to 
  16. # (must be quoted to be passed as one argument)
  17. # $2 - thrown away using shift - usually key part of .ini file string
  18. # All remaining arguments (usually value part of .ini file string)
  19. # treated as course names and must be separated by spaces or tabs
  20. CompareCourses()
  21. {
  22.     # Keep first string
  23.     COMPARE_TO="$1";
  24.     
  25.     # Throw away not-course arguments
  26.     shift;
  27.     shift;
  28.     
  29.     for i in "$@"
  30.     do
  31.     case "$COMPARE_TO" in
  32.     *"$i"*)
  33.         # already installed course name found in the first string
  34.         ;;
  35.     *)
  36.         # new course name - not found in the first string
  37.         # must be installed
  38.         return 1;
  39.         ;;
  40.     esac
  41.     done
  42.     
  43.     # no new courses
  44.     return 0;
  45. }
  46.  
  47. #
  48. # Main script start
  49. #
  50.  
  51. # Change current directory to CD
  52. SRCPATH=`dirname "$0"`;
  53.  
  54. cd "$SRCPATH";
  55.  
  56. case `uname -s` in
  57. Linux)
  58.     # Linux autorun script
  59.     ;;
  60. *)
  61.     # No known autorun on Solaris
  62.     # Anyway, will not work on Solaris - 
  63.     # variables will not be kept outside .ini file reading cycles
  64.     echo "Sorry, only Linux autorun supported.";
  65.     exit 1;
  66.     ;;
  67. esac
  68.  
  69. if [ -s "$HOME/Sybex/sybex.jar" ] ; then
  70.     if [ -s "$HOME/Sybex/edugen.ini" ] ; then    
  71.     # Proper previous installation found
  72.     # Check whether this course is installed
  73.     
  74.     CD_COURSES="NONE";    
  75.     while read LINE
  76.     do
  77.         case $LINE in
  78.         "name="*)
  79.         # Courses on this CD - from disk.ini
  80.         CD_COURSES="$LINE";
  81.         break;
  82.         ;;
  83.         esac
  84.     done < "$SRCPATH/disk.ini"
  85.     
  86.     if [ "$CD_COURSES" = "NONE" ] ; then
  87.         # corrupted disk.ini - nothing to install
  88.         exit 1;
  89.     fi    
  90.     
  91.     INSTALLED="NONE";
  92.     while read LINE
  93.     do
  94.         case $LINE in
  95.         "installed="*)
  96.         # installed courses from edugen.ini
  97.         INSTALLED="$LINE";
  98.         break;
  99.         ;;
  100.         esac
  101.     done < "$HOME/Sybex/edugen.ini"
  102.     
  103.     if [ "$INSTALLED" = "NONE" ] ; then
  104.         # corrupted installation - reinstall
  105.         xterm -e "./install.sh";
  106.         exit 0;
  107.     fi
  108.     
  109.     
  110.     # make each course a separate argument by replacing
  111.     # .ini file symbols (=,) and DOS/WINDOWS carriage returns 
  112.     # by spaces
  113.     CD_COURSES=`echo "$CD_COURSES" | tr ",=\015" '   '`;
  114.     
  115.     if CompareCourses "$INSTALLED" $CD_COURSES; then
  116.             # all courses on this CD are already installed
  117.         exit 1;
  118.     fi    
  119.     fi
  120. fi
  121.  
  122. # THis Sybex course was not properly installed before - run installation
  123. xterm -e "./install.sh";
  124.  
  125. exit 0;