[Frubar Paste] Hosted by SkyLime - Chat with us at XChannel IRC

Posted by nakem on Sun 17th Jan 21:59
Modification of post by nakem | view diff | download

  1. #!/bin/bash
  2. #
  3. ##############################################
  4. # Planeshift Build Script  by nakem & tereay #
  5. ##############################################
  6. #
  7. #
  8. # Fixing wrong linewraps... (I have to do it in one line to avoid failing because of the wrong linewraps.)
  9. a="$(echo -en "\r\n")"; grep "$a" "$0" > /dev/null && echo "Fixing..." && sed -i s/"$a"/"$(echo "")"/g "$0" && sh "$0" && exit "$?"
  10.  
  11. ## BEGIN - OS specific
  12. function has_pkg_installer() {
  13.   is_cmd zypper  # add the package manager for your system with " || is_cmd <command>"
  14.   return "$?"
  15. }
  16.  
  17. function install_pkgs() {
  18.   if is_cmd zypper; then
  19.     sudo zypper install subversion libtool autoconf automake make jam libpng-devel libjpg-devel libmng-devel openal-devel mesa-devel cg-devel $1
  20.   # Please add the equivalent command for your system like shown here:
  21.   # else if is_cmd <package manager>; then
  22.   #  <command>
  23.   #
  24.   fi
  25. }
  26.  
  27. # END - OS specific
  28.  
  29. function set_var() {
  30.   eval "$1=\"\$2\""
  31. }
  32.  
  33. function get_var() {
  34.   local __answer__
  35.   echo -n "$3 [$2]: "
  36.   read __answer__
  37.   [[ "$2" != "" ]] && [ "$__answer__" = "" ] && __answer__="$2"
  38.   set_var "$1" "$__answer__"
  39. }
  40.  
  41. function get_cmd() {
  42.   cmd="$(which "$1" 2>/dev/null)"
  43.   if [ "$?" = "1" ]; then
  44.     cmd=""
  45.   fi
  46. }
  47.  
  48. function is_cmd() {
  49.   which "$1" > /dev/null 2>/dev/null
  50.   return "$?"
  51. }
  52.  
  53. function run() {
  54.   if [ "$BUILD_VERBOSE" = "yes" ]; then
  55.     "$@"
  56.   else
  57.     "$@" > /dev/null
  58.   fi
  59. }
  60.  
  61. function _test() {
  62.   run "$@"
  63.   if [ ! "$?" = "0" ]; then
  64.     echo ""
  65.     echo "Test failed!"
  66.     exit 1
  67.   fi
  68. }
  69.  
  70. function cs_test() {
  71.   if [ "$1" = "--notice" ]; then
  72.     notice="yes"
  73.     shift
  74.   else
  75.     notice="no"
  76.   fi
  77.   if ! grep "cs_cv_$1=yes" config.log > /dev/null 2> /dev/null; then
  78.     echo "$1 is missing!"
  79.     [ "$notice" = "no" ] && abort="yes"
  80.   fi
  81. }
  82.  
  83. echo "###########################################"
  84. echo "# Welcome to the Planeshift Build Script! #"
  85. echo "###########################################"
  86. echo ""
  87.  
  88. echo "Before the automated build process can start, we have to ask some questions."
  89. get_var CLEAN "no" "Shall I do a clean build? (build EVERYTHING again?)"
  90. get_var BUILD_DIR "$HOME/planeshift_build" "Where do you want the files to be placed?"
  91. #get_var BUILD_INSTALL "no" "Do you want it to be installed?"
  92. get_var BUILD_SERVER "no" "Shall I compile the server, too?"
  93. get_var BUILD_VERBOSE "yes" "Do you want me to show all messages?"
  94.  
  95. ART_TYPE="none"
  96. get_var answer "no" "Do you want me to create the art directory?"
  97. if [ "$answer" = "yes" ]; then
  98.   get_var answer "no" "Do you have the official client installed?"
  99.   if [ "$answer" = "yes" ]; then
  100.     while true; do
  101.       get_var path "/opt/PlaneShift" "Where?"
  102.       if [ -d "$path/art" ]; then
  103.         break
  104.       else
  105.         echo "Wrong directory! Couldn't find $path/art !"
  106.       fi
  107.     done
  108.     ART_TYPE="copy"
  109.     ART_PATH="$path/art"
  110.   else
  111.     get_var answer "yes" "Do you want me to download the art? (will take MUCH time)"
  112.     if [ "$answer" = "yes" ]; then
  113.       ART_TYPE="dl"
  114.     else
  115.       echo "I won't create the art directory because I can't get its content."
  116.     fi
  117.   fi
  118. fi
  119. if [[ "$ART_TYPE" != "dl" ]]; then
  120.   get_var PATCH "yes" "Do you want me to fix the PS files (if there are any errors) after compilation?"
  121. fi
  122.  
  123. INSTALL_RPM="no"
  124. has_pkg_installer && get_var INSTALL_RPM "yes" "Do you want me to install the needed packages(with zypper) automatically?"
  125.  
  126. echo "***************************************"
  127. echo "Running install..."
  128.  
  129. [ ! "$(echo "$BUILD_DIR" | cut -b 1)" = "/" ] && BUILD_DIR="$PWD/$BUILD_DIR"  # It's a relative path. Make it absolute!
  130.  
  131. echo ""
  132. echo -n "Checking dependencies... "
  133.  
  134. add=""
  135. [ "$BUILD_SERVER" = "yes" ] && add="libmysqlclient-devel"
  136.  
  137. if has_pkg_installer; then
  138.   if [ "$INSTALL_RPM" = "yes" ]; then
  139.     echo "I'll install all needed packages now..."
  140.     #sudo zypper install subversion libtool autoconf automake make jam libpng-devel libjpg-devel libmng-devel openal-devel mesa-devel cg-devel $add
  141.     install_pkgs "$add"
  142.   fi
  143. else
  144.   list=""
  145.   for name in svn libtool autoconf make jam; do
  146.     if ! is_cmd "$name"; then
  147.       list="$name $list"
  148.     fi
  149.   done
  150.   if ! is_cmd cginfo; then
  151.     list="cg-devel $list"
  152.   fi
  153.  
  154.   if [[ "$list" != "" ]]; then
  155.     echo ""
  156.     echo "You need to following packages to start compiling: $list"
  157.     echo "You will also need these libraries to compile: libpng-devel libjpg-devel libmng-devel openal-devel mesa-devel cg-devel $add"
  158.     echo "Please note: These package names are taken from openSuse packages..."
  159.     echo "Please install them yourself!"
  160.     exit 1
  161.   fi
  162. fi
  163.  
  164. echo "Creating file structure..."
  165. [ ! -d "$BUILD_DIR" ] && mkdir "$BUILD_DIR"
  166. cd "$BUILD_DIR"
  167.  
  168. if [ "$CLEAN" = "yes" ]; then
  169.   echo "Cleaning directory..."
  170.   echo -n "cal3d "
  171.   rm -Rf cal
  172.   echo -n "cs "
  173.   rm -Rf cs
  174.   echo -n "planeshift "
  175.   rm -Rf planeshift
  176.   echo ""
  177. fi
  178.  
  179. echo "Starting downloads..."
  180. echo "Cal3D: http://svn.gna.org/svn/cal3d/trunk/cal3d"
  181. run svn co -r 507 http://svn.gna.org/svn/cal3d/trunk/cal3d cal3d
  182.  
  183. echo "Crystal Space: https://crystal.svn.sourceforge.net/svnroot/crystal/CS/trunk"
  184. run svn co https://crystal.svn.sourceforge.net/svnroot/crystal/CS/trunk cs
  185.  
  186. echo "Planeshift: https://planeshift.svn.sourceforge.net/svnroot/planeshift/trunk"
  187. run svn co https://planeshift.svn.sourceforge.net/svnroot/planeshift/trunk planeshift
  188.  
  189. echo "Configuring cal3d..."
  190. cd cal3d
  191.  
  192. sed -i 's/AM_USE_UNITTESTCPP/\# AM_USE_UNITTESTCPP/' configure.in
  193.  
  194. if [ "$CLEAN" = "yes" ]; then
  195.   run autoreconf --install --force
  196. else
  197.   run autoreconf --install
  198. fi
  199. run ./configure --prefix="$BUILD_DIR/cal3d"
  200. if [ "$?" = "1" ]; then
  201.   echo "Failed to configure cal3d!"
  202.   echo "Aborting!"
  203.   exit 1
  204. fi
  205.  
  206. echo "Compiling cal3d..."
  207. run make
  208. if [ ! "$?" = "0" ]; then
  209.   echo "Failed to compile cal3d!"
  210.   echo "Aborting!"
  211.   exit 1
  212. fi
  213.  
  214. run make install
  215. if [ ! "$?" = "0" ]; then
  216.   echo "Failed to install cal3d!"
  217.   echo "Aborting!"
  218.   exit 1
  219. fi
  220.  
  221. echo "Running tests..."
  222.  
  223. cd tests
  224. echo -n "Test 1/4 ..."
  225. _test sh run converter/skeleton
  226.  
  227. echo -en "\rTest 2/4 ..."
  228. _test sh run converter/mesh
  229.  
  230. echo -en "\rTest 3/4 ..."
  231. _test sh run converter/material
  232.  
  233. echo -en "\rTest 4/4 ..."
  234. _test sh run converter/animation
  235.  
  236. ## Needs valgrind and caused too much trouble...
  237. #echo -e "\rTest 5/5 ..."
  238. #_test sh run ./quaternion
  239.  
  240. cd ..
  241.  
  242. export LD_LIBRARY_PATH="$BUILD_DIR/cal3d/lib:$LD_LIBRARY_PATH"
  243.  
  244. echo "Configuring Crystal Space..."
  245. cd ../cs
  246. run ./configure --without-java --without-perl --without-python --without-3ds --with-cal3d="$BUILD_DIR/cal3d"
  247. if [ ! "$?" = "0" ]; then
  248.   echo "Failed to configure Crystal Space!"
  249.   echo "Aborting!"
  250.   exit 1
  251. fi
  252.  
  253. echo "Testing..."
  254.  
  255. abort="no"
  256. cs_test libCg
  257. cs_test libCgGL
  258. cs_test libcal3d
  259. cs_test libgl
  260. cs_test libpng
  261. cs_test libjpeg
  262. cs_test liblcms
  263. cs_test libmng
  264. cs_test libogg
  265. cs_test libvorbis
  266. cs_test libvorbisfile
  267. # Dumb, isn't it ?
  268. cs_test libx11
  269. cs_test libz
  270.  
  271. cs_test --notice libopenal
  272. cs_test --notice libasound
  273.  
  274. if [ "$abort" = "yes" ]; then
  275.   echo "Some libraries are missing!"
  276.   echo "Aborting!"
  277.   exit 1
  278. fi
  279.  
  280. echo "Compiling Crystal Space..."
  281. if [ "$CLEAN" = "yes" ]; then
  282.   run jam libs plugins cs-config walktest
  283. else
  284.   run jam -aq libs plugins cs-config walktest
  285. fi
  286.  
  287. export LD_LIBRARY_PATH="$BUILD_DIR/cs:$LD_LIBRARY_PATH"
  288. export CRYSTAL="$BUILD_DIR/cs"
  289.  
  290. echo "Configuring Planeshift..."
  291. cd ../planeshift
  292.  
  293. run ./autogen.sh
  294. run ./configure --with-cal3d="$BUILD_DIR/cal3d"
  295. if [ "$?" = "1" ]; then
  296.   echo "Failed to configure Planeshift!"
  297.   echo "Aborting!"
  298.   exit 1
  299. fi
  300.  
  301. echo "Compiling Planeshift..."
  302.  
  303. if [ "$CLEAN" = "yes" ]; then
  304.   run jam -aq client
  305. else
  306.   run jam client
  307. fi
  308.  
  309. if [ ! "$?" = "0" ]; then
  310.   echo "Failed to build Planeshift!"
  311.   echo "Aborting!"
  312.   exit 1
  313. fi
  314. if [ "$BUILD_SERVER" = "yes" ]; then
  315.   run jam server
  316.   if [ ! "$?" = "0" ]; then
  317.     echo "Failed to build the Server!"
  318.   fi
  319. fi
  320.  
  321. echo "Writing scripts..."
  322.  
  323. # To prevent overwriting our compiled files!
  324. if ! grep "Update.Platform = false" pslaunch.cfg > /dev/null; then
  325.   echo "Update.Platform = false" >> pslaunch.cfg
  326. fi
  327.  
  328. # Template
  329. sc="#!/bin/bash
  330. export CRYSTAL=\"../cs\"
  331. export LD_LIBRARY_PATH=\"../cal3d/lib:../cs:\$LD_LIBRARY_PATH\""
  332.  
  333. for script in psclient pslaunch pssetup psserver; do
  334.   if [ -f "$script" ]; then
  335.     mv "$script" "$script.bin"
  336.     echo "$sc" > "$script"
  337.     echo "./$script.bin \"\$@\"" >> "$script"
  338.     chmod +x "$script"
  339.   fi
  340. done
  341.  
  342. if [ "$ART_TYPE" = "copy" ]; then
  343.   echo "Copying art..."
  344.   cp -R "$ART_PATH" art
  345. fi
  346.  
  347. p="no"
  348. if [ "$ART_TYPE" = "dl" ]; then
  349.   echo "Downloading art..."
  350.   p="yes"
  351. else
  352.   if [ "$PATCH" = "yes" ]; then
  353.     echo "Patching install..."
  354.     p="yes"
  355.   fi
  356. fi
  357.  
  358. [ "$p" = "yes" ] && echo "y" | ./pslaunch --console --repair
  359.  
  360. echo "Updating..."
  361. echo "y" | ./pslaunch --console
  362.  
  363. echo "Done!"
  364. echo "***********************************************"
  365. read


Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.



Remember my name in a cookie


Code: To highlight particular lines, prefix each line with @@.
Include comments to indicate what you need feedback on.