install.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #!/usr/bin/env bash
  2. #
  3. # Free Pascal installation script for Unixy platforms.
  4. # Copyright 1996-2004 Michael Van Canneyt, Marco van de Voort and Peter Vreman
  5. #
  6. # Don't edit this file.
  7. # Everything can be set when the script is run.
  8. #
  9. # Release Version %version% will be replaced by makepack
  10. VERSION=%version%
  11. # some useful functions
  12. # ask displays 1st parameter, and ask new value for variable, whose name is
  13. # in the second parameter.
  14. ask ()
  15. {
  16. askvar=$2
  17. eval old=\$$askvar
  18. eval echo -n \""$1 [$old] : "\"
  19. read $askvar
  20. eval test -z \"\$$askvar\" && eval $askvar=\'$old\'
  21. }
  22. # yesno gives 1 on no, 0 on yes $1 gives text to display.
  23. yesno ()
  24. {
  25. while true; do
  26. echo -n "$1 (Y/n) ? "
  27. read ans
  28. case X$ans in
  29. X|Xy|XY) return 0;;
  30. Xn|XN) return 1;;
  31. esac
  32. done
  33. }
  34. # Untar files ($3,optional) from file ($1) to the given directory ($2)
  35. unztar ()
  36. {
  37. tar -xzf $HERE/$1 --directory $2 $3
  38. }
  39. # Untar tar.gz file ($2) from file ($1) and untar result to the given directory ($3)
  40. unztarfromtar ()
  41. {
  42. tar -xOf $HERE/$1 $2 | tar --directory $3 -xzf -
  43. }
  44. # Get file list from tar archive ($1) in variable ($2)
  45. # optionally filter result through sed ($3)
  46. listtarfiles ()
  47. {
  48. askvar=$2
  49. if [ ! -z $3 ]; then
  50. list=`tar tvf $1 | awk '{ print $(NF) }' | sed -n /$3/p`
  51. else
  52. list=`tar tvf $1 | awk '{ print $(NF) }'`
  53. fi
  54. eval $askvar='$list'
  55. }
  56. # Make all the necessary directories to get $1
  57. makedirhierarch ()
  58. {
  59. OLDDIR=`pwd`
  60. case $1 in
  61. /*) cd /;;
  62. esac
  63. OLDIFS=$IFS;IFS=/;eval set $1; IFS=$OLDIFS
  64. for i
  65. do
  66. test -d $i || mkdir $i || break
  67. cd $i ||break
  68. done
  69. cd $OLDDIR
  70. }
  71. # check to see if something is in the path
  72. checkpath ()
  73. {
  74. ARG=$1
  75. OLDIFS=$IFS; IFS=":";eval set $PATH;IFS=$OLDIFS
  76. for i
  77. do
  78. if [ $i = $ARG ]; then
  79. return 0
  80. fi
  81. done
  82. return 1
  83. }
  84. # Install files from binary-*.tar
  85. # $1 = cpu-target
  86. # $2 = cross prefix
  87. installbinary ()
  88. {
  89. if [ "$2" == "" ]; then
  90. FPCTARGET=$1
  91. CROSSPREFIX=
  92. else
  93. FPCTARGET=`echo $2 | sed 's/-$//'`
  94. CROSSPREFIX=$2
  95. fi
  96. BINARYTAR=${CROSSPREFIX}binary.$1.tar
  97. # conversion from long to short archname for ppc<x>
  98. case $FPCTARGET in
  99. m68k*)
  100. PPCSUFFIX=68k;;
  101. sparc*)
  102. PPCSUFFIX=sparc;;
  103. i386*)
  104. PPCSUFFIX=386;;
  105. powerpc*)
  106. PPCSUFFIX=ppc;;
  107. arm*)
  108. PPCSUFFIX=arm;;
  109. x86_64*)
  110. PPCSUFFIX=x64;;
  111. esac
  112. # Install compiler/RTL. Mandatory.
  113. echo "Installing compiler and RTL for $FPCTARGET..."
  114. unztarfromtar $BINARYTAR ${CROSSPREFIX}base.$1.tar.gz $PREFIX
  115. # Install symlink
  116. rm -f $EXECDIR/ppc${PPCSUFFIX}
  117. ln -sf $LIBDIR/ppc${PPCSUFFIX} $EXECDIR/ppc${PPCSUFFIX}
  118. echo "Installing utilities..."
  119. unztarfromtar $BINARYTAR ${CROSSPREFIX}utils.$1.tar.gz $PREFIX
  120. if yesno "Install Textmode IDE"; then
  121. unztarfromtar $BINARYTAR ${CROSSPREFIX}ide.$1.tar.gz $PREFIX
  122. fi
  123. if yesno "Install FCL"; then
  124. unztarfromtar $BINARYTAR ${CROSSPREFIX}units-fcl.$1.tar.gz $PREFIX
  125. fi
  126. if yesno "Install packages"; then
  127. listtarfiles $BINARYTAR packages units
  128. for f in $packages
  129. do
  130. if [ $f != ${CROSSPREFIX}units-fcl.$1.tar.gz ]; then
  131. p=`echo "$f" | sed -e 's+^.*units-\([^\.]*\)\..*+\1+'`
  132. echo "Installing $p"
  133. unztarfromtar $BINARYTAR $f $PREFIX
  134. fi
  135. done
  136. fi
  137. rm -f *.$1.tar.gz
  138. }
  139. # --------------------------------------------------------------------------
  140. # welcome message.
  141. #
  142. clear
  143. echo "This shell script will attempt to install the Free Pascal Compiler"
  144. echo "version $VERSION with the items you select"
  145. echo
  146. # Here we start the thing.
  147. HERE=`pwd`
  148. # Install in /usr/local or /usr ?
  149. if checkpath /usr/local/bin; then
  150. PREFIX=/usr/local
  151. else
  152. PREFIX=/usr
  153. fi
  154. # If we can't write on prefix, select subdir of home dir
  155. if [ ! -w $PREFIX ]; then
  156. PREFIX=$HOME/fpc-$VERSION
  157. fi
  158. ask "Install prefix (/usr or /usr/local) " PREFIX
  159. makedirhierarch $PREFIX
  160. # Set some defaults.
  161. LIBDIR=$PREFIX/lib/fpc/$VERSION
  162. SRCDIR=$PREFIX/src/fpc-$VERSION
  163. EXECDIR=$PREFIX/bin
  164. OSNAME=`uname -s | tr A-Z a-z`
  165. BSDHIER=0
  166. case $OSNAME in
  167. *bsd)
  168. BSDHIER=1;;
  169. esac
  170. SHORTARCH=$ARCHNAME
  171. FULLARCH=$ARCHNAME-$OSNAME
  172. DOCDIR=$PREFIX/share/doc/fpc-$VERSION
  173. DEMODIR=$DOCDIR/examples
  174. # Install all binary releases
  175. for f in *binary*.tar
  176. do
  177. target=`echo $f | sed 's+^.*binary\.\(.*\)\.tar$+\1+'`
  178. cross=`echo $f | sed 's+binary\..*\.tar$++'`
  179. installbinary $target $cross
  180. done
  181. echo Done.
  182. echo
  183. # Install the sources. Optional.
  184. if yesno "Install sources"; then
  185. echo Installing sources in $SRCDIR ...
  186. unztarfromtar sources.tar base.source.tar.gz $PREFIX
  187. if yesno "Install compiler source"; then
  188. unztarfromtar sources.tar compiler.source.tar.gz $PREFIX
  189. fi
  190. if yesno "Install RTL source"; then
  191. unztarfromtar sources.tar rtl.source.tar.gz $PREFIX
  192. fi
  193. if yesno "Install FCL source"; then
  194. unztarfromtar sources.tar fcl.source.tar.gz $PREFIX
  195. fi
  196. if yesno "Install IDE source"; then
  197. unztarfromtar sources.tar ide.source.tar.gz $PREFIX
  198. fi
  199. if yesno "Install installer source"; then
  200. unztarfromtar sources.tar installer.source.tar.gz $PREFIX
  201. fi
  202. if yesno "Install Packages source"; then
  203. listtarfiles sources.tar packages units
  204. for f in $packages
  205. do
  206. p=`echo "$f" | sed -e 's+^.*units-\([^\.]*\)\..*+\1+'`
  207. echo "Installing sources for $p"
  208. unztarfromtar sources.tar $f $PREFIX
  209. done
  210. fi
  211. rm -f *.source.tar.gz
  212. echo Done.
  213. fi
  214. echo
  215. # Install the documentation. Optional.
  216. if yesno "Install documentation"; then
  217. echo Installing documentation in $DOCDIR ...
  218. unztar docs.tar.gz $DOCDIR
  219. echo Done.
  220. fi
  221. echo
  222. # Install the demos. Optional.
  223. if yesno "Install demos"; then
  224. ask "Install demos in" DEMODIR
  225. echo Installing demos in $DEMODIR ...
  226. makedirhierarch $DEMODIR
  227. unztar demo.tar.gz $DEMODIR
  228. echo Done.
  229. fi
  230. echo
  231. # Install /etc/fpc.cfg, this is done using the samplecfg script
  232. $LIBDIR/samplecfg $LIBDIR
  233. # The End
  234. echo
  235. echo End of installation.
  236. echo
  237. echo Refer to the documentation for more information.
  238. echo