binaryInstall.src 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. #!/bin/sh
  2. ##########################################################################
  3. #
  4. # IMPORTANT: The binaryInstall.src file is a source file, NOT an
  5. # executable shell script!! Used to generate grass-MAJ.MIN.VER-ARCH-DD_MM_YYYY-install.sh by
  6. # make bindist
  7. #
  8. # GRASS binary package installation tool
  9. # platform independent
  10. #
  11. # 1999-2000, 2010 by Markus Neteler, and the GRASS development team
  12. #
  13. ##########################################################################
  14. # Set a zero size variable for testing if this file is a source file. Note
  15. # that the make bindist command will change this line to TEST_STR = executable
  16. # without the spaces surrounding the equal sign
  17. TEST_STR=
  18. # Use a text string for sed to recognize to insert the proper version
  19. NAME_VER=BIN_DIST_VERSION
  20. TAR_FILE_SIZE=SIZE_TAR_FILE
  21. ARCH=ARCHITECTURE
  22. GRASSPRG=GRASSPRG_NAME
  23. # Set the default BINDIR and DESTDIR directories
  24. BINDIR=/usr/local/bin
  25. DESTDIR=/usr/local/grass$NAME_VER
  26. UNINSTALL=grass${NAME_VER}uninstall.sh
  27. # Check if this is a source file or not
  28. if [ -z "$TEST_STR" ] ; then
  29. echo "This is a source script, not an executable script which can be run."
  30. exit
  31. fi
  32. # Check for first parameter:
  33. if [ $# -lt 1 -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ] ; then
  34. echo "
  35. GRASS GIS $NAME_VER binary package installation tool
  36. Usage: grass-$NAME_VER-install.sh grass-$NAME_VER.tar.gz [dest_dir] [bin_dir]
  37. with:
  38. [dest_dir] - optional: FULL path name to the installation directory
  39. (default: /usr/local/grass$NAME_VER/)
  40. [bin_dir] - optional: FULL path name to the grass binary directory
  41. (default: /usr/local/bin/)
  42. Notes: 1) Only the grass executable file is stored here
  43. 2) If you want to change the binary directory only
  44. then you need to specify the destination
  45. directory as well
  46. You may need login as root for installation.
  47. "
  48. exit
  49. fi
  50. # Check for second parameter:
  51. if [ "$2" ] ; then
  52. DESTDIR=$2
  53. fi
  54. # Check for third parameter:
  55. if [ "$3" ] ; then
  56. BINDIR=$3
  57. fi
  58. # Print out script identification message
  59. echo ""
  60. echo "GRASS GIS $NAME_VER binary package installation tool"
  61. echo ""
  62. # Check for correct package name:
  63. if [ ! -f $1 ] ; then
  64. echo "ERROR: Wrong package name $1. File does not exists."
  65. echo ""
  66. exit
  67. fi
  68. # Obtain the package name and path
  69. CURR_DIR=`pwd`
  70. PACKAGE_NAME=`basename $1`
  71. PACKAGE_DIR=`dirname $1`
  72. # the dirname command uses . and .. if found so we need the absolute path
  73. cd $PACKAGE_DIR
  74. PACKAGE_DIR=`pwd`
  75. # Check if package is first parameter and in gz or bz2 compression:
  76. # is package in .tar.gz format?
  77. echo $PACKAGE_NAME | grep "\.tar\.gz" > /dev/null
  78. if [ $? -eq 0 ] ; then
  79. UNPACK=gunzip
  80. # Is gunzip there?
  81. IFSSAVE="$IFS"
  82. IFS=":"
  83. GUNZIP=""
  84. for TEST in $PATH ; do
  85. if [ -x $TEST/gunzip ] ; then
  86. GUNZIP="$TEST/gunzip"
  87. fi
  88. done
  89. # which gunzip | grep -v no > /dev/null
  90. IFS="$IFSSAVE"
  91. if [ ! "$GUNZIP" ] ; then
  92. echo "No gunzip installed. Please get from:"
  93. echo " http://www.gnu.org/software/gzip/gzip.html"
  94. exit
  95. fi
  96. else
  97. # not in .tar.gz format, perhaps in .tar.bz2 format?
  98. echo $PACKAGE_NAME | grep "\.tar\.bz2" > /dev/null
  99. if [ $? -eq 0 ] ; then
  100. UNPACK=bunzip2
  101. # Is bunzip2 there?
  102. IFSSAVE="$IFS"
  103. IFS=":"
  104. BUNZIP2=""
  105. for TEST in $PATH ; do
  106. if [ -x $TEST/bunzip2 ] ; then
  107. BUNZIP2="$TEST/bunzip2"
  108. fi
  109. done
  110. IFS="$IFSSAVE"
  111. # which bunzip2 | grep -v no > /dev/null
  112. if [ ! "$BUNZIP2" ] ; then
  113. echo "No bunzip2 installed. Please get from:"
  114. echo " http://sources.redhat.com/bzip2/index.html"
  115. exit
  116. fi
  117. else
  118. # not in .tar.gz or .tar.bz2 format, completely wrong!
  119. echo "ERROR: You need the GRASS binary package in .tar.gz compression "
  120. echo "or .tar.bz2."
  121. echo ""
  122. exit
  123. fi
  124. fi
  125. # Check if the size of the tar gzip file is the same as what was on the server
  126. SIZE=`ls -l $PACKAGE_NAME | tr -s " " | cut -d" " -f5`
  127. if [ $? -ne 0 ] ; then
  128. echo "ERROR while installing binaries!"
  129. echo "Exiting."
  130. exit
  131. fi
  132. if [ $SIZE -ne $TAR_FILE_SIZE ] ; then
  133. echo "ERROR: The size of the binary package is not correct."
  134. echo " Perhaps there was a transmission error. Please download"
  135. echo " the package again"
  136. echo ""
  137. exit
  138. fi
  139. echo "Using $UNPACK decompressor..."
  140. echo "The package $PACKAGE_NAME seems to be OK"
  141. echo "Proceeding..."
  142. echo ""
  143. # Check if the paths for the binary and the destination are the same
  144. BIN_PATH1=$BINDIR/grass-$NAME_VER
  145. BIN_PATH2=$BIN_PATH1/
  146. if [ $BIN_PATH1 = $DESTDIR -o $BIN_PATH2 = $DESTDIR ] ; then
  147. echo "ERROR:"
  148. echo "It appears that the destination directory path is the same as the"
  149. echo "path for the grass binary executable. This results in a name"
  150. echo "conflict between the destination directory and the executable."
  151. echo "Please run this script again with a different path name for the"
  152. echo "destination directory."
  153. exit
  154. fi
  155. # Check if BINDIR is a directory
  156. if [ ! -d "$BINDIR" ] ; then
  157. # Check if BINDIR is a file
  158. if [ -f "$BINDIR" ] ; then
  159. echo ""
  160. echo "ERROR: $BINDIR is a file not a directory."
  161. echo "Please specify a directory for the binary executable directory."
  162. exit
  163. fi
  164. mkdir -p $BINDIR
  165. if [ $? -ne 0 ] ; then
  166. echo "An error occurred trying to create $BINDIR ! Exiting."
  167. exit
  168. fi
  169. fi
  170. # Check if DESTDIR is appropriate
  171. echo "Checking and creating installation directory..."
  172. if [ ! -d "$DESTDIR" ] ; then
  173. # Check if a word "grass" is in string $DESTDIR
  174. echo $DESTDIR | grep "grass" > /dev/null
  175. if [ $? -eq 1 ] ; then
  176. echo "WARNING: Your destination path $DESTDIR does not contain the word 'grass'"
  177. echo "Continue (y/n)?"
  178. read ans
  179. if [ "$ans" = "n" -o "$ans" = "N" ] ; then
  180. exit
  181. fi
  182. fi
  183. # Check if DESTDIR is a file
  184. if [ -f "$DESTDIR" ] ; then
  185. echo ""
  186. echo "ERROR: $DESTDIR is a file not a directory."
  187. echo "Please specify a directory for the destination directory"
  188. exit
  189. fi
  190. mkdir -p $DESTDIR
  191. if [ $? -ne 0 ] ; then
  192. echo "An error occurred trying to create $DESTDIR! Exiting."
  193. exit
  194. fi
  195. else
  196. if [ -d $DESTDIR/bin ] ; then
  197. echo ""
  198. echo "ERROR: Old GRASS distribution existing in $DESTDIR!"
  199. echo "Remove first!"
  200. exit
  201. else
  202. # Check if a word "grass" is in string $DESTDIR
  203. echo $DESTDIR | grep "grass" > /dev/null
  204. if [ $? -eq 1 ] ; then
  205. echo "WARNING: Your destination path $DESTDIR does not contain the word 'grass'"
  206. echo "Continue (y/n)?"
  207. read ans
  208. if [ "$ans" = "n" -o "$ans" = "N" ] ; then
  209. exit
  210. fi
  211. fi
  212. # Check if DESTDIR is writable
  213. touch $DESTDIR/test$$ > /dev/null
  214. if [ $? -ne 0 ] ; then
  215. echo "ERROR: Destination directory $DESTDIR is not"
  216. echo "writable, try installing as root!"
  217. echo "Exiting."
  218. exit 1
  219. fi
  220. rm -f $DESTDIR/test$$ > /dev/null
  221. fi
  222. fi
  223. # Start the installation job...
  224. echo "Installing GRASS binaries into $DESTDIR"
  225. echo ""
  226. echo "Uncompressing the package and extracting to target directory..."
  227. PACK_FILE=`echo $PACKAGE_DIR/$PACKAGE_NAME | sed 's+^//+/+g'`
  228. cd $DESTDIR; $UNPACK -c $PACK_FILE | tar -xf -
  229. if [ $? -eq 1 ] ; then
  230. echo "An error occurred or user break while installing binaries! Exiting."
  231. exit
  232. fi
  233. # Get rid of any CVS directories
  234. find . -name CVS -exec rm -rf {} \; 2>/dev/null ; true
  235. cd $CURR_DIR
  236. # Creating start script
  237. echo "Creating start script:"
  238. echo "$BINDIR/$GRASSPRG -> $BINDIR/grass-$NAME_VER"
  239. sed -e "s#@GISBASE@#$DESTDIR#g" \
  240. $DESTDIR/$GRASSPRG.tmp > $BINDIR/grass-$NAME_VER
  241. if [ $? -eq 1 ] ; then
  242. echo "An error occurred trying to create the grass start script! Exiting."
  243. echo "You probably do not have permission to install into $BINDIR."
  244. echo "You may need to be the root user to install in that directory."
  245. exit
  246. fi
  247. ln -sf $BINDIR/grass-$NAME_VER $BINDIR/$GRASSPRG
  248. chmod ugo+x $BINDIR/grass-$NAME_VER
  249. if [ $? -eq 1 ] ; then
  250. echo "An error occurred trying to create the grass start script! Exiting."
  251. echo "You probably do not have permission to install into $BINDIR."
  252. echo "You may need to be the root user to install in that directory."
  253. exit
  254. fi
  255. echo "Creating the locks directory for monitors..."
  256. SERVERNAME=`uname -n | sed -e "s/\..*//"`
  257. if [ ! -d $DESTDIR/locks ] ; then
  258. mkdir $DESTDIR/locks
  259. fi
  260. rm -rf $DESTDIR/locks/*
  261. mkdir $DESTDIR/locks/$SERVERNAME
  262. chmod -R 1777 $DESTDIR/locks
  263. echo""
  264. echo "Generating display font configuration file..."
  265. GISBASE="$DESTDIR" GISRC=junk LD_LIBRARY_PATH_VAR="${DESTDIR}/lib:$LD_LIBRARY_PATH_VAR" "${DESTDIR}/bin/g.mkfontcap" -o
  266. echo""
  267. # fix include/Make/Platform.make file for g.extension
  268. mv ${DESTDIR}/include/Make/Platform.make ${DESTDIR}/include/Make/Platform.make.orig
  269. cat ${DESTDIR}/include/Make/Platform.make.orig | \
  270. sed "s+prefix = /usr/local+prefix = $DESTDIR+g" | \
  271. sed "s+INST_DIR = $prefix/grass-$NAME_VER+INST_DIR = $prefix+g" | \
  272. sed "s+^.*GRASS_HOME.*$+GRASS_HOME = $DESTDIR+" | \
  273. sed "s+^.*RUN_GISBASE.*$+RUN_GISBASE = $DESTDIR+" | \
  274. sed "s+^.*RUN_GISRC.*$+RUN_GISRC = +" > ${DESTDIR}/include/Make/Platform.make
  275. # rm -f ${DESTDIR}/include/Make/Platform.make.orig
  276. # Print out some messages
  277. echo "Installation finished. Start GRASS $NAME_VER with"
  278. echo " $BINDIR/grass-$NAME_VER"
  279. echo ""
  280. #echo "The graphical user interface can be started within GRASS GIS."
  281. #echo ""
  282. #echo "You can uninstall grass by typing"
  283. #echo " sh $UNINSTALL"
  284. #echo "in the directory $BINDIR"
  285. echo ""
  286. echo "Welcome to GRASS GIS. Enjoy this open source GRASS GIS!"
  287. echo ""