home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / BBS / AMC0995.ZIP / install.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2004-07-03  |  5KB  |  244 lines

  1. #!/bin/sh
  2. #
  3. #  AMC (Automatic Message Creator) installation script
  4. #    (c) 2004/11/06  -  J/D.H. Beekhuizen
  5. #
  6.  
  7. #  Version number
  8. VERSION=0.99.5/Linux
  9.  
  10. declare -i Count
  11.  
  12. # some useful functions
  13.  
  14. #  Request displays the first parameter, and asks a new value for 
  15. #  variable, which name is # in the second parameter
  16.  
  17. Request ()
  18. {
  19. qvar=$2
  20. eval oldvar=\$$qvar
  21. eval echo -n \""$1 [$oldvar] : "\" 
  22. read $qvar
  23. eval test -z \"\$$qvar\" && eval $qvar=\'$oldvar\'
  24. }
  25.  
  26. #  YesNo gives you value 1 on "no", value 0 on "yes"
  27. #  The parameter specifies the text to display
  28.  
  29. YesNo ()
  30. {
  31.     while true
  32.         do
  33.         echo -n "$1 (Y/n) ? "
  34.         read qans
  35.         case Q$qans in
  36.             Q|Qy|QY) return 0;;
  37.             Qn|QN)   return 1;;
  38.         esac
  39.     done
  40. }
  41.  
  42. #  Well...
  43. #
  44.  
  45. Sorry ()
  46. {
  47.     echo
  48.     echo "I'm sorry I couldn't be of any help."
  49.     echo
  50.     exit 5
  51. }
  52.  
  53. #  Things could go wrong...
  54. #
  55.  
  56. InstallProblem ()
  57. {
  58.     echo
  59.     echo "The 'install' utility returned an error."
  60.     echo "Unable to proceed!"
  61.     echo
  62.     if [ "" = "True" ]
  63.         then
  64.         rm -rf  2>&1 > /dev/null
  65.     fi
  66.     exit 7
  67. }
  68.  
  69. LinkProblem ()
  70. {
  71.     echo
  72.     echo "The symbolic link could not be made."
  73.     echo "Please investigate this and do it manually."
  74.     echo
  75. }
  76.     
  77. #  You must be root to use this script
  78. #
  79.  
  80. if [ "`id -un`" != "root" ]
  81.     then
  82.     echo
  83.     echo "You must be root to install AMC for general use!"
  84.     echo "Please read 00INSTALL for instructions on installation."
  85.     echo
  86.     exit 3
  87. fi
  88.  
  89.  
  90. #  Blurb
  91. #
  92.  
  93. clear
  94. echo
  95. echo "This script will install"
  96. echo "Automatic Message Creator  v$VERSION"
  97. echo "for general use."
  98. echo
  99.  
  100. #  The default is to install in /opt/amc
  101.  
  102. PREFIX=/opt
  103.  
  104. #  Get the installation directory
  105.  
  106. Request "Please specify the directory to install AMC in" PREFIX
  107.  
  108. AMC_ROOT=$PREFIX/amc
  109. AMC_BIN=$AMC_ROOT/bin
  110. AMC_OLDLANG=$AMC_BIN/lang
  111. AMC_LIB=$AMC_ROOT/lib
  112. AMC_LANG=$AMC_LIB/lang
  113. AMC_ETC=$AMC_ROOT/etc
  114. AMC_DOC=$AMC_ROOT/doc
  115. AMC_LOG=$AMC_ROOT/log  
  116. AMC_LOGfile=$AMC_ROOT/log/amc.log
  117.  
  118. #  Check if it exists already
  119.  
  120. if [ -d $AMC_ROOT ]
  121.     then
  122.     echo
  123.     echo "There already exists a directory $AMC_ROOT."
  124.     echo "If you choose to overwrite it, any existing default configuration files"
  125.     echo "and language resource files will be saved."
  126.     if YesNo "Do you want to overwrite it"
  127.         then
  128.         if YesNo "Are you absolutely sure"
  129.             then
  130.             AMC_New=False
  131.             Count=10
  132.             while [ $Count -gt 0 ]
  133.                 do
  134.                 echo -en "Starting in $Count seconds; use <Ctrl>C to bail out "\\r
  135.                 sleep 1
  136.                 Count=$(($Count-1))
  137.             done
  138.             echo
  139.             echo
  140.         else
  141.             Sorry
  142.         fi
  143.     else
  144.         Sorry
  145.     fi
  146. else
  147.     AMC_New=True
  148. fi
  149.     
  150. #  OK, now do the installation
  151. #
  152.  
  153. #  Make the directories
  154. #
  155.  
  156. install -o root -g root -m 755 -d $AMC_ROOT      ||  InstallProblem
  157. install -o root -g root -m 755 -d $AMC_BIN       ||  InstallProblem
  158. install -o root -g root -m 755 -d $AMC_LANG      ||  InstallProblem
  159. install -o root -g root -m 755 -d $AMC_DOC       ||  InstallProblem
  160. install -o root -g root -m 755 -d $AMC_ETC       ||  InstallProblem
  161. install -o root -g root -m 755 -d $AMC_LOG       ||  InstallProblem
  162.  
  163. #  Save old default configuration and language resource files
  164. #
  165.  
  166. if [ "$AMC_New" = "False" ]
  167.     then
  168.     if [ -d $AMC_OLDLANG ]
  169.         then
  170.         mv $AMC_OLDLANG/* $AMC_LANG/  > /dev/null 2>&1
  171.         rm -r $AMC_OLDLANG             > /dev/null 2>&1
  172.         echo "NOTICE: the language resource files have been moved"
  173.         echo "            from $AMC_OLDLANG"
  174.         echo "              to $AMC_LANG"
  175.     fi
  176.     for ll in en nl de
  177.         do
  178.         LFILE=amc_messages.$ll.po
  179.         if [ -f $AMC_LANG/$LFILE    ]
  180.             then
  181.             mv $AMC_LANG/$IFILE $AMC_LANG/$LFILE.sav  > /dev/null 2>&1
  182.             echo "NOTICE: file $AMC_LANG/$LFILE has been saved as"
  183.             echo "             $AMC_LANG/$LFILE.sav"
  184.         fi
  185.     done
  186.     for ff in amc.cfg amc.txt amcbirth.day
  187.         do
  188.         if [ -f $AMC_ETC/$ff    ]
  189.             then
  190.             mv $AMC_ETC/$ff $AMC_ETC/$ff.sav  > /dev/null 2>&1
  191.             echo "NOTICE: file $AMC_ETC/$ff has been saved as"
  192.             echo "             $AMC_ETC/$ff.sav"
  193.         fi
  194.     done
  195. fi
  196.  
  197. #  Install the contents            
  198. #
  199.  
  200. install -o root -g root -m 755 -s bin/* $AMC_BIN
  201. install -o root -g root -m 666 lib/lang/* $AMC_LANG
  202. install -o root -g root -m 644 doc/* $AMC_DOC
  203. install -o root -g root -m 644 etc/* $AMC_ETC
  204. install -o root -g root -m 666 /dev/null $AMC_LOGfile
  205.  
  206. chmod 444 $AMC_LANG/README
  207. chmod 444 $AMC_LANG/amc_messages.00.po
  208.  
  209. #  Installation done
  210. #
  211.  
  212. echo
  213. echo "The installation is finished."
  214. echo "The executable file is:                  " $AMC_BIN
  215. echo "The language resource files are in:      " $AMC_LANG
  216. echo "The default configuration files are in:  " $AMC_ETC
  217. echo "The default log file is:                 " $AMC_LOGfile
  218. echo "Documentation is in:                     " $AMC_DOC
  219.  
  220. #  Make a link?
  221. #
  222.  
  223. echo
  224. echo "It is possible to create a symbolic link to AMC"
  225. echo "either in /usr/local/bin or in /usr/bin"
  226. echo
  227.  
  228. if YesNo "Do you want to create a symbolic link in /usr/local/bin"
  229.     then
  230.     ln -sf $AMC_BIN/amc /usr/local/bin/amc  ||  LinkProblem
  231. else
  232.     if YesNo "Do you want to create a symbolic link in /usr/bin"
  233.         then
  234.         ln -sf $AMC_BIN/amc /usr/bin/amc    ||  LinkProblem
  235.     fi
  236. fi
  237.  
  238. echo
  239. echo "AMC is now installed and ready for use."
  240. echo "Please change the configuration to your own needs."
  241. echo
  242. echo "Have fun with it!"
  243. echo
  244.