home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Applix / install.cd / pkg / install.sh < prev   
Linux/UNIX/POSIX Shell Script  |  1998-05-09  |  11KB  |  469 lines

  1. #!/bin/bash
  2. #
  3. #install.sh  (shell d'installation)
  4. #---------------------------------------------------------------
  5. #
  6.  
  7. TMP="/var/lib/applix-setup"
  8. tmp="$TMP"
  9.  
  10. DIALOG="$CHEMIN/bin/dialog"
  11. export DIALOGRC="$CHEMIN/bin/.dialogrc"
  12. umask 022
  13.  
  14. if [ ! -f $tmp/ROOT_DIR ]; then
  15. BACKTITLE="Installation APPLIXware 4.3.7 Office - $LANGUE (DEMO - Expire le 31/08/98)"
  16. else
  17. BACKTITLE="Installation APPLIXware 4.3.7 Office - $LANGUE (DEMO - Expire le 31/08/98)"
  18. fi
  19.  
  20. file_pkg="$FILE_PKG"
  21.  
  22. TempFile="$tmp/apx_inst.$$"
  23.  
  24. # Shell interface to "dialog"
  25. # Bruce Perens, November 1995
  26. # This is free software under the GNU General Public License.
  27.  
  28. # Global options
  29. #    The variable $BACKTITLE specifies the back title.
  30. #    The variable $DIALOG_OPTIONS, initialized here to --clear, provides
  31. #    options you want on the command line of each dialog invocation.
  32. #    The variable $DIALOG_TEST can be set to "echo" to see the calls
  33. #    to dialog without executing them.
  34.  
  35. DIALOG_OPTIONS=""
  36.  
  37. # Make any dialogue box, with default settings and backtitle from
  38. # $BACKTITLE in the environment.
  39. #
  40. # dialog --type arg arg ...
  41. #---------------------------------------------------------------
  42. #
  43. dialogBox () {
  44.     local type="$1"
  45.     shift
  46.     local title=""
  47.     local backtitle=""
  48.  
  49.     local text="$1"
  50.     shift
  51.  
  52.     if [ $# -ge 1 ]; then
  53.       title="$1"
  54.       shift
  55.     fi
  56.  
  57.     if [ -n "$BACKTITLE" ]; then
  58.       backtitle="$BACKTITLE"
  59.     fi
  60.  
  61.     #$DIALOG_TEST 
  62.     $DIALOG $DIALOG_OPTIONS --title "$title" --backtitle \
  63.      "$backtitle" "$type" "$text" 0 0 "$@" 2>&1 1>/dev/tty
  64.     local result=$?
  65.     Selection="$result" 
  66.     return $result
  67. }
  68.  
  69. # Display a file.
  70. #
  71. # fileBox filename [title]
  72. #---------------------------------------------------------------
  73. #
  74. fileBox () {
  75.     dialogBox --textbox "$1" "$2"
  76. }
  77.  
  78. #
  79. # textBox [title]
  80. #---------------------------------------------------------------
  81. #
  82. textBox () {
  83.     dialogBox --textbox $TempFile "$1"
  84.     local result=$?
  85.     rm -f $TempFile
  86.     return $result
  87. }
  88.  
  89. #
  90. # message box
  91. #---------------------------------------------------------------
  92. #
  93. msgBox () {
  94.     dialogBox --msgbox "$1" "$2"
  95. }
  96.  
  97. #
  98. # info box
  99. #---------------------------------------------------------------
  100. #
  101. infoBox () {
  102.     dialogBox --infobox "$1" "$2"
  103. }
  104.  
  105. #
  106. # yes ou no box
  107. #---------------------------------------------------------------
  108. #
  109. yesNoBox () {
  110.     dialogBox --yesno "$1" "$2"
  111. }
  112.  
  113. #
  114. # input box
  115. #---------------------------------------------------------------
  116. #
  117. inputBox () {
  118.     dialogBox --inputbox "$1" "$2" "$3"
  119. }
  120.  
  121. #
  122. # menu text title tag1 item1 ...
  123. #---------------------------------------------------------------
  124. #
  125. menu () {
  126.     local text="$1"
  127.     shift
  128.     local title="$1"
  129.     shift
  130.     dialogBox --menu "$text" "$title" 0 "$@"
  131. }
  132.  
  133. #
  134. # checklist
  135. # menu text title tag1 item1 status1 ...
  136. #---------------------------------------------------------------
  137. #
  138. checklist () {
  139.     local text="$1"
  140.     shift
  141.     local title="$1"
  142.     shift
  143.     dialogBox --checklist "$text" "$title" $hauteur_check "$@"
  144.  
  145.     if [ $Selection = "1" -o $Selection = "255" ]; then
  146.       Selection="Cancel"
  147.       echo $Selection >> $tmp/selection
  148.     fi
  149. }
  150.  
  151. #
  152. # radio list
  153. # menu text title tag1 item1 status1 ...
  154. #---------------------------------------------------------------
  155. #
  156. radiolist () {
  157.     local text="$1"
  158.     shift
  159.     local title="$1"
  160.     shift
  161.     dialogBox --radiolist "$text" "$title" 0 "$@"
  162. }
  163.  
  164. #
  165. # installation des packages sΘlectionΘs 
  166. #---------------------------------------------------------------
  167. #
  168. install_pkg() {
  169.     if [ ! -f $tmp/ROOT_DIR ]; then    
  170.       echo "$DEST_DIR" > $tmp/ROOT_DIR
  171.     fi
  172.  
  173.     if [ ! -d $DEST_DIR/applix/log/packages ]; then    # test rep packages  joel
  174.       mkdir -p $DEST_DIR/applix/log/packages
  175.     fi
  176.  
  177.     if [ ! -d $DES_DIR/applix/log/scripts ]; then     # test rep scripts joel
  178.       mkdir -p $DEST_DIR/applix/log/scripts
  179.     fi
  180.  
  181.     local file=$1
  182.     SOURCE="`pwd`"
  183.     desc="`grep "D:$file:" $file_pkg | sed -n "s/^.*:.*://p"`"
  184.     infoBox "$desc" "Installation de $file"
  185.  
  186.     if [ ! -d $DEST_DIR ]; then
  187.       mkdir -p $DEST_DIR 2> /dev/null
  188.     fi
  189.  
  190.     (cd $DEST_DIR
  191. #    tar zxf $SOURCE/$file.tgz 2> /dev/null ;
  192.     echo "NOM DU PACKAGE:        $file"           > $DEST_DIR/applix/log/packages/$file
  193.     f="$SOURCE/$file"; taille_fichier $f; 
  194.     echo "TAILLE DECOMPRESSEE:   $taille Ko"     >> $DEST_DIR/applix/log/packages/$file
  195.     echo "PACKAGE DESCRIPTION:"                  >> $DEST_DIR/applix/log/packages/$file
  196.     DESCRIPT="`grep "A:$file:" $SOURCE/$file_pkg`"   #>> $DEST_DIR/applix/log/packages/$file
  197.     if [ -z "$DESCRIPT" ]; then
  198.       DESCRIPT="`grep "AON:$file:" $SOURCE/$file_pkg`"  #>> $DEST_DIR/applix/log/packages/$file
  199.     fi
  200.     echo $DESCRIPT >> $DEST_DIR/applix/log/packages/$file
  201.     echo "`grep "D:$file:" $SOURCE/$file_pkg`"   >> $DEST_DIR/applix/log/packages/$file
  202.     echo "FILE LIST:"                         >> $DEST_DIR/applix/log/packages/$file
  203.     ( tar -xzlpvf - ) < $SOURCE/$file.tgz     >> $DEST_DIR/applix/log/packages/$file 2> /dev/null ;   #joel
  204.     if [ -r install/doinst.sh ] ; then
  205.       bash install/doinst.sh $DEST_DIR
  206.       rm -f install/doinst.sh
  207.       rm -rf install
  208.     fi)
  209. }
  210.  
  211. #
  212. # taille dΘcompressΘe du fichier α installer
  213. ##---------------------------------------------------------------
  214.  
  215. taille_fichier() {
  216.         taille=`gzip -l $f.tgz | sed -n '$ p' | cut -b10-19`  #joel
  217.     taille=`expr $taille / 1024`
  218. }
  219.  
  220. #
  221. #
  222. # recherche des packages 
  223. recherche () {
  224.     infoBox "Patientez pendant que je recherche la liste des applications de la\nversion $LANGUE dans le rΘpertoire $CHEMIN." "Patientez!"
  225.     sleep 1
  226.     file_lst=`cat file.lst`
  227. }
  228.  
  229. #
  230. # menu de sΘlection des packages α installer 
  231. #---------------------------------------------------------------
  232. #
  233. main_menu () {
  234.     # titre de la procΘdure d'installation 
  235.     title=`grep "T:TITRE:" $file_pkg | sed -n "s/^.*:.*://p"`
  236.  
  237.     #creation de la checkliste
  238.     chk_file="$tmp/chk.lst.$$"
  239.     cat << END > $chk_file
  240.     checklist \\
  241. "Choisissez les applications avec les flΦches.
  242. Validez avec  la  barre  d'espacement. Ne pas
  243. suprimer les fichiers prΘsΘlectionnez.
  244.     
  245. Installation dans $DEST_DIR""$APPLIX." "$title" \\
  246. END
  247.  
  248.     for file in $file_lst
  249.     do
  250.       # recherche des packages prΘsΘlectionΘs
  251.       auto_inst=`grep "A:$file:" $file_pkg | cut -c1-2`
  252.       if [ "$auto_inst" = "A:" ]; then
  253.         desc=`grep "A:$file:" $file_pkg | sed -n "s/^.*:.*://p"`
  254.         
  255.             if [ ! -f $DEST_DIR/applix/log/packages/$file ]; then
  256.           echo " $file \"$desc\" \"off\" \\" >> $chk_file
  257.         fi
  258.         
  259.       else
  260.         desc=`grep "AON:$file:" $file_pkg | sed -n "s/^.*:.*://p"`
  261.         echo " $file \"$desc\" \"on\" \\" >> $chk_file
  262.       fi
  263.     done
  264.  
  265.     echo " " >> $chk_file
  266.     file_lst=`. $chk_file`
  267.         rm -r $chk_file    
  268. }
  269.  
  270. #
  271. # dΘtermination de la taille totale des fichiers α installer 
  272. # et de la place disponible sur le disque dur de destination 
  273. #---------------------------------------------------------------
  274. #
  275. taille_totale () {
  276.     total_taille_fichier=0
  277.     for file in $file_lst
  278.     do
  279.       f=`echo $file | sed -n "s/\"//gp"`
  280.       taille_fichier $f
  281.       total_taille_fichier=`expr $taille + $total_taille_fichier`
  282.     done
  283.  
  284.     if [ ! -d $DEST_DIR ]; then
  285.       mkdir -p $DEST_DIR 2> /dev/null
  286.     fi 
  287.  
  288.     devices=`df $DEST_DIR | grep "/dev" | cut -c1-11`
  289.     disque_free=`df $DEST_DIR | grep "/dev" | cut -c38-46`
  290.     disque_free=`expr $disque_free`
  291.     
  292.     if [ ! $DEST_DIR = "/" ]; then
  293.       rmdir -p $DEST_DIR  2> /dev/null
  294.     fi
  295.  
  296.     taille_reste=`expr $disque_free - $total_taille_fichier`
  297.  
  298.     cat <<EOF>> $TempFile
  299. Place disponible sur le disque $devices: $disque_free Ko
  300. Taille totale des fichiers α installer    : $total_taille_fichier Ko
  301. EOF
  302.  
  303.     if [ "$taille_reste" -le "0" ]; then
  304.       temp2="INSTALLATION IMPOSSIBLE!!!"
  305.       cat <<EOF>> $TempFile
  306.  
  307. Installation impossible! La place disponible sur le disque dur
  308. est insuffisante. Choisir un autre disque dur ou suprimer  des
  309. packages.
  310.  
  311. L'espace disque pour cette installation doit Ωtre de $total_taille_fichier Ko.
  312. EOF
  313.  
  314.       temp1=`cat $TempFile`
  315.       msgBox "$temp1" "$temp2"
  316.       rm -f $TempFile
  317.       rm -f $tmp_file
  318.     else
  319.       temp2="DEBUTER L'INSTALLATION"
  320.       cat <<EOF>> $TempFile
  321.  
  322. Taille restante sur le disque  $devices: $taille_reste Ko
  323.  
  324. La  place disponible sur votre disque dur vous permet de lancer
  325. la procΘdure  d'installation  d'APPLIXware. Confirmez  par  Oui 
  326. (Installation) ou Non (Annuler l'installation).
  327.  
  328. EOF
  329.  
  330.       temp1=`cat $TempFile`
  331.       yesNoBox "$temp1" "$temp2"
  332.       rm -f $TempFile 
  333.       rm -f $tmp_file
  334.  
  335.       # $disque_free = place disponible sur le disque d'installation  
  336.       # $total_taille_fichier = taille totale des fichiers α installer
  337.  
  338.       if [ "$Selection" = "0" ]; then
  339.         installation
  340.       fi
  341.  
  342.     fi
  343. }
  344.  
  345. #
  346. # passage des fichier a installer a la fonction install_pkg
  347. #---------------------------------------------------------------
  348. #
  349. installation () {
  350.     for file in $file_lst
  351.     do
  352.       f=`echo $file | sed -n "s/\"//gp"`
  353.       install_pkg $f
  354.     done
  355.     rm -f $tmp_file
  356. }
  357.  
  358. #
  359. # recherche les packages prΘinstallΘs
  360. #---------------------------------------------------------------
  361. #
  362. pre_install () {
  363.     file_lst=`cat file.lst`
  364.     ligne_tempo=
  365.  
  366.     for file in $file_lst
  367.     do
  368.       auto_inst=`grep "AON:$file:" $FILE_PKG | cut -c1-4` 
  369.       if [ "$auto_inst" = "AON:" ]; then
  370.         ligne_tempo="$ligne_tempo; $file"           # ligne temporaire     
  371.         longueur_ligne=`expr "$ligne_tempo" : ".*"` # longueur de la ligne 
  372.  
  373.         if [ $longueur_ligne -le 50 ]; then  # tant que ligne a moins de 50c
  374.           ligne="$ligne $file"               # ajout fichier dans la ligne  
  375.         else
  376.           echo $ligne >> $tmp/file.txt       # sauve la ligne
  377.           ligne="$file"                      # Initialise les variable
  378.           ligne_tempo="$file"               
  379.           longueur_ligne=                    #
  380.         fi
  381.       fi
  382.     done
  383.  
  384.     echo $ligne >> $tmp/file.txt             # sauve derniere ligne si inferieure a 50 c
  385.  
  386.     # prΘparation du fichier $TempFile 
  387.  
  388.     cat << EOF >> $TempFile
  389. Installation de la version $LANGUE
  390. ---------------------------------------------------------
  391. Les packages suivants ont  ΘtΘ  sΘlectionnΘs  pour  vous:
  392.  
  393. EOF
  394.  
  395.     cat $tmp/file.txt >> $TempFile
  396.     rm -f $tmp/file.txt
  397.     cat << EOF >> $TempFile
  398.  
  399. Vous ne devez en aucun cas  les dΘsΘlectionner sous peine
  400. de rendre instable la version $LANGUE. Vous pouvez
  401. complΘter l'installation  d'APPLIXware  en  sΘlectionnant
  402. des packages suplΘmentaires."
  403. EOF
  404.  
  405. }
  406.  
  407. #
  408. # calcul du nombre de ligne dans le fichier $TempFile 
  409. #--------------------------------------------------------
  410. #
  411. nb_ligne () {
  412.     nombre_ligne=`wc -l $TempFile | cut -d/ -f1`
  413.  
  414.     if [ "$nombre_ligne" -le "18" ]; then
  415.       hauteur="0"
  416.       largeur="0"
  417.     else
  418.       hauteur="18"
  419.       largeur="61"
  420.     fi
  421. }
  422.  
  423. #
  424. # DΘbut du shell
  425. #---------------------------------------------------------------
  426. #
  427.     
  428.     if [ ! -f $tmp/ROOT_DIR ]; then
  429.       pre_install
  430.       textBox "IMPORTANT!!!"
  431.     fi
  432.  
  433.     recherche
  434.  
  435. # Test si tous les packages sont installes
  436.         a=0
  437.     hauteur_check=0
  438.         for file in $file_lst
  439.     do            
  440.         if [ ! -r $DEST_DIR/applix/log/packages/$file ]; then
  441.           a=`expr $a + 1`
  442.       hauteur_check=`expr $a`
  443.       if [ "$hauteur_check" -ge "10" ]; then
  444.         hauteur_check=10
  445.       fi  
  446.     fi
  447.     done
  448.     
  449.     if [ $a = "0" ]; then
  450.           infoBox "\nTous les packages sont dΘjα installΘs.\n" "ATTENTION!"
  451.           sleep 3
  452.           exit
  453.         fi    
  454.     
  455.     main_menu
  456.  
  457.     if [ -r $tmp/selection ]; then
  458.       Selection=`cat $tmp/selection`
  459.       rm -f $tmp/selection
  460.     fi
  461.  
  462.     if [ ! $Selection = "Cancel" ]; then
  463.       taille_totale
  464.     fi
  465.  
  466.     exit
  467.     
  468. #-----FIN-------------------------------------------------------
  469.