Advertisement
Guest User

#tes3mp-deploy.sh unfucked edition

a guest
Nov 18th, 2017
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 29.71 KB | None | 0 0
  1. #!/bin/bash
  2. #tes3mp-deploy.sh unfucked edition
  3.  
  4. set -e
  5.  
  6. VERSION="2.6.2"
  7.  
  8. HELPTEXT="\
  9. TES3MP-deploy ($VERSION)
  10. Grim Kriegor <grimkriegor@krutt.org>
  11. Licensed under the GNU GPLv3 free license
  12.  
  13. Usage $0 MODE [OPTIONS]
  14.  
  15. Modes of operation:
  16.   -i, --install         Prepare and install TES3MP and its dependencies
  17.   -u, --upgrade         Upgrade TES3MP
  18.   -a, --auto-upgrade        Automatically upgrade TES3MP if there are changes on the remote repository
  19.   -r, --rebuild         Simply rebuild TES3MP
  20.   -y, --script-upgrade      Upgrade the TES3MP-deploy script
  21.   -p, --make-package        Make a portable package for easy distribution
  22.   -h, --help            This help text
  23.  
  24. Options:
  25.   -s, --server-only     Only build the server
  26.   -c, --cores N         Use N cores for building TES3MP and its dependencies
  27.   -v, --commit          HASH Checkout and build a specific TES3MP commit
  28.   -e, --version-string      STRING Set the version string for compatibility
  29.   -m, --build-master        Build the master server
  30.  
  31. Peculiar options:
  32.   --debug-symbols       Build with debug symbols
  33.   --skip-pkgs           Skip package installation
  34.   --cmake-local         Tell CMake to look in /usr/local/ for libraries
  35.  
  36. Please report bugs in the GitHub issue page or directly on the TES3MP Discord.
  37. https://github.com/GrimKriegor/TES3MP-deploy
  38. "
  39.  
  40. #PARSE ARGUMENTS
  41. if [ $# -eq 0 ]; then
  42.   echo -e "$HELPTEXT"
  43.   echo -e "No parameter specified."
  44.   exit 1
  45.  
  46. else
  47.   while [ $# -ne 0 ]; do
  48.     case $1 in
  49.  
  50.     #HELP TEXT
  51.     -h | --help )
  52.       echo -e "$HELPTEXT"
  53.       exit 1
  54.     ;;
  55.  
  56.     #INSTALL DEPENDENCIES AND BUILD TES3MP
  57.     -i | --install )
  58.       INSTALL=true
  59.       REBUILD=true
  60.     ;;
  61.  
  62.     #CHECK IF THERE ARE UPDATES, PROMPT TO REBUILD IF SO
  63.     -u | --upgrade )
  64.       UPGRADE=true
  65.     ;;
  66.  
  67.     #UPGRADE AUTOMATICALLY IF THERE ARE CHANGES IN THE UPSTREAM CODE
  68.     -a | --auto-upgrade )
  69.       UPGRADE=true
  70.       AUTO_UPGRADE=true
  71.     ;;
  72.  
  73.     #REBUILD TES3MP
  74.     -r | --rebuild )
  75.       REBUILD=true
  76.     ;;
  77.  
  78.     #UPGRADE THE SCRIPT
  79.     -y | --script-upgrade )
  80.       SCRIPT_UPGRADE=true
  81.     ;;
  82.  
  83.     #MAKE PACKAGE
  84.     -p | --make-package )
  85.       MAKE_PACKAGE=true
  86.     ;;
  87.  
  88.     #DEFINE INSTALLATION AS SERVER ONLY
  89.     -s | --server-only )
  90.       SERVER_ONLY=true
  91.       touch .serveronly
  92.     ;;
  93.  
  94.     #BUILD SPECIFIC COMMIT
  95.     -v | --commit )
  96.       if [[ "$2" =~ ^-.* || "$2" == "" ]]; then
  97.         echo -e "\nYou must specify a valid commit hash"
  98.         exit 1
  99.       else
  100.         BUILD_COMMIT=true
  101.         TARGET_COMMIT="$2"
  102.         shift
  103.       fi
  104.     ;;
  105.  
  106.     #CUSTOM VERSION STRING FOR COMPATIBILITY
  107.     -e | --version-string )
  108.       if [[ "$2" =~ ^-.* || "$2" == "" ]]; then
  109.         echo -e "\nYou must specify a valid version string"
  110.         exit 1
  111.       else
  112.         CHANGE_VERSION_STRING=true
  113.         TARGET_VERSION_STRING="$2"
  114.         shift
  115.       fi
  116.     ;;
  117.  
  118.     #NUMBER OF CPU THREADS TO USE IN COMPILATION
  119.     -c | --cores )
  120.       if [[ "$2" =~ ^-.* || "$2" == "" ]]; then
  121.         ARG_CORES=""
  122.       else
  123.         ARG_CORES=$2
  124.         shift
  125.       fi
  126.     ;;
  127.  
  128.     #BUILD MASTER SERVER
  129.     -m | --build-master )
  130.       BUILD_MASTER=true
  131.       touch .buildmaster
  132.     ;;
  133.  
  134.     #BUILD WITH DEBUG SYMBOLS
  135.     --debug-symbols )
  136.       DEBUG_SYMBOLS=true
  137.     ;;
  138.  
  139.     #SKIP PACKAGE INSTALLATION
  140.     --skip-pkgs )
  141.       SKIP_PACKAGE_INSTALL=true
  142.     ;;
  143.  
  144.     #TELL CMAKE TO LOOK FOR DEPENDENCIES ON /USR/LOCAL/
  145.     --cmake-local )
  146.       CMAKE_LOCAL=true
  147.     ;;
  148.  
  149.     esac
  150.     shift
  151.   done
  152.  
  153. fi
  154.  
  155. #EXIT IF NO OPERATION IS SPECIFIED
  156. if [[ ! $INSTALL && ! $UPGRADE && ! $REBUILD && ! $SCRIPT_UPGRADE && ! $MAKE_PACKAGE ]]; then
  157.   echo -e "\nNo operation specified, exiting."
  158.   exit 1
  159. fi
  160.  
  161. #NUMBER OF CPU CORES USED FOR COMPILATION
  162. if [[ "$ARG_CORES" == "" || "$ARG_CORES" == "0" ]]; then
  163.     CORES="$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l)"
  164. else
  165.     CORES="$ARG_CORES"
  166. fi
  167.  
  168. #DISTRO IDENTIFICATION
  169. DISTRO="$(lsb_release -si | awk '{print tolower($0)}')"
  170.  
  171. #FOLDER HIERARCHY
  172. BASE="$(pwd)"
  173. CODE="$BASE/code"
  174. DEVELOPMENT="$BASE/build"
  175. KEEPERS="$BASE/keepers"
  176. DEPENDENCIES="$BASE/dependencies"
  177. PACKAGE_TMP="$BASE/package"
  178. EXTRA="$BASE/extra"
  179.  
  180. #DEPENDENCY LOCATIONS
  181. CALLFF_LOCATION="$DEPENDENCIES"/callff
  182. RAKNET_LOCATION="$DEPENDENCIES"/raknet
  183. TERRA_LOCATION="$DEPENDENCIES"/terra
  184. OSG_LOCATION="$DEPENDENCIES"/osg
  185. BULLET_LOCATION="$DEPENDENCIES"/bullet
  186.  
  187. #CHECK IF THIS IS A SERVER ONLY INSTALL
  188. if [ -f "$BASE"/.serveronly ]; then
  189.   SERVER_ONLY=true
  190. fi
  191.  
  192. #CHECK IF MASTER SERVER IS SUPPOSED TO BE BUILT
  193. if [ -f "$BASE"/.buildmaster ]; then
  194.   BUILD_MASTER=true
  195. fi
  196.  
  197. echo -en "Setting QT_SELECT: was '$QT_SELECT' "
  198. QT_SELECT=qt5
  199. echo -e "now '$QT_SELECT'. qmake --version: "
  200. qmake --version
  201.  
  202. #INSTALL MODE
  203. if [ $INSTALL ]; then
  204.  
  205.   #CREATE FOLDER HIERARCHY
  206.   echo -e ">> Creating folder hierarchy"
  207.   mkdir -p "$DEVELOPMENT" "$KEEPERS" "$DEPENDENCIES"
  208.  
  209.   #CHECK DISTRO AND INSTALL DEPENDENCIES
  210.   if [ ! $SKIP_PACKAGE_INSTALL ]; then
  211.   echo -e "\n>> Checking which GNU/Linux distro is installed"
  212.   case $DISTRO in
  213.     "arch" | "parabola" | "manjarolinux" )
  214.         echo -e "You seem to be running either Arch Linux, Parabola GNU/Linux-libre or Manjaro"
  215.         echo -e "So I'm not going to \e[5m\e[4m\e[31mfuck your shit\e[0m, but you may need to install:"
  216.         PACKAGE_LIST="unzip wget git cmake boost openal openscenegraph mygui bullet qt5-base ffmpeg sdl2 unshield libxkbcommon-x11 ncurses"
  217.         #sudo pacman -Sy --needed unzip wget git cmake boost openal openscenegraph mygui bullet qt5-base ffmpeg sdl2 unshield libxkbcommon-x11 ncurses #clang35 llvm35
  218.  
  219.         if [ ! -d "/usr/share/licenses/gcc-libs-multilib/" ]; then
  220.               #sudo pacman -S --needed gcc-libs
  221.               PACKAGE_LIST="$PACKAGE_LIST gcc-libs"
  222.         fi
  223.        
  224.         echo -e "  $PACKAGE_LIST"
  225.        
  226.         PACMAN_CMD="sudo pacman -S $PACKAGE_LIST"
  227.         echo -e "\nDo you want to install the things? (will execute the following command)\n  \e[4m$PACMAN_CMD\e[0m?"
  228.         select yn in "Yes" "No" "Cancel"; do
  229.             case $yn in
  230.                 Yes ) eval $PACMAN_CMD; break;;
  231.                 No ) echo "skipping..."; break;;
  232.                 Cancel ) exit;;
  233.             esac
  234.         done
  235.  
  236.        
  237.         #echo -e "\nCreating symlinks for ncurses compatibility"
  238.         #LIBTINFO_VER=6
  239.         #NCURSES_VER="$(pacman -Q ncurses | awk '{print $2}' | cut -c 1-3)"
  240.         #sudo ln -sf /usr/lib/libncursesw.so."$NCURSES_VER" /usr/lib/libtinfo.so."$LIBTINFO_VER"
  241.         #sudo ln -sf /usr/lib/libtinfo.so."$LIBTINFO_VER" /usr/lib/libtinfo.so
  242.     ;;
  243.  
  244.     "debian" | "devuan" )
  245.         echo -e "You seem to be running Debian or Devuan"
  246.         sudo apt-get update
  247.         sudo apt-get install unzip wget git cmake libopenal-dev qt5-default libqt5opengl5-dev libopenthreads-dev libopenscenegraph-3.4-dev libsdl2-dev libqt4-dev libboost-filesystem-dev libboost-thread-dev libboost-program-options-dev libboost-system-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libmygui-dev libunshield-dev cmake build-essential libqt4-opengl-dev g++ libncurses5-dev #libbullet-dev
  248.         #echo -e "\nDebian users are required to build OpenSceneGraph from source\nhttps://wiki.openmw.org/index.php?title=Development_Environment_Setup#Build_and_install_OSG\n\nType YES if you want the script to do it automatically (THIS IS BROKEN ATM)\nIf you already have it installed or want to do it manually,\npress ENTER to continue"
  249.         #read INPUT
  250.         #if [ "$INPUT" == "YES" ]; then
  251.         #      echo -e "\nOpenSceneGraph will be built from source"
  252.         #      BUILD_OSG=true
  253.         #      sudo apt-get build-dep openscenegraph libopenscenegraph-dev
  254.         #fi
  255.         sudo sed -i "s,# deb-src,deb-src,g" /etc/apt/sources.list
  256.         sudo apt-get build-dep bullet
  257.         BUILD_BULLET=true
  258.     ;;
  259.  
  260.     "ubuntu" | "linuxmint" | "elementary" )
  261.         echo -e "You seem to be running Ubuntu, Mint or elementary OS"
  262.         echo -e "\nThe OpenMW PPA repository needs to be enabled\nhttps://wiki.openmw.org/index.php?title=Development_Environment_Setup#Ubuntu\n\nType YES if you want the script to do it automatically\nIf you already have it enabled or want to do it manually,\npress ENTER to continue"
  263.         read INPUT
  264.         if [ "$INPUT" == "YES" ]; then
  265.               echo -e "\nEnabling the OpenMW PPA repository..."
  266.               sudo add-apt-repository ppa:openmw/openmw
  267.               echo -e "Done!"
  268.         fi
  269.         sudo apt-get update
  270.         sudo apt-get install unzip wget git cmake libopenal-dev qt5-default libqt5opengl5-dev libopenthreads-dev libopenscenegraph-3.4-dev libsdl2-dev libqt4-dev libboost-filesystem-dev libboost-thread-dev libboost-program-options-dev libboost-system-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libmygui-dev libunshield-dev cmake build-essential libqt4-opengl-dev g++ libncurses5-dev #llvm-3.5 clang-3.5 libclang-3.5-dev llvm-3.5-dev libbullet-dev
  271.         sudo sed -i "s,# deb-src,deb-src,g" /etc/apt/sources.list
  272.         sudo apt-get build-dep bullet
  273.         BUILD_BULLET=true
  274.     ;;
  275.  
  276.     "fedora" )
  277.         echo -e "You seem to be running Fedora"
  278.         echo -e "\nFedora users are required to enable the RPMFusion FREE and NON-FREE repositories\nhttps://wiki.openmw.org/index.php?title=Development_Environment_Setup#Fedora_Workstation\n\nType YES if you want the script to do it automatically\nIf you already have it enabled or want to do it manually,\npress ENTER to continue"
  279.         read INPUT
  280.         if [ "$INPUT" == "YES" ]; then
  281.               echo -e "\nEnabling RPMFusion..."
  282.               su -c 'dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm'
  283.               echo -e "Done!"
  284.         fi
  285.         sudo dnf --refresh groupinstall development-tools
  286.         sudo dnf --refresh install unzip wget cmake openal-devel OpenSceneGraph-qt-devel SDL2-devel qt4-devel boost-filesystem git boost-thread boost-program-options boost-system ffmpeg-devel ffmpeg-libs bullet-devel gcc-c++ mygui-devel unshield-devel tinyxml-devel cmake #llvm35 llvm clang ncurses
  287.         BUILD_BULLET=true
  288.     ;;
  289.  
  290.     *)
  291.         echo -e "Your GNU/Linux distro is not supported yet, press ENTER to continue without installing dependency packages"
  292.         read
  293.     ;;
  294.   esac
  295.   fi
  296.  
  297.   #CHECK IF GCC HAS C++14 SUPPORT, DISPLAY A MESSAGE AND ABORT OTHERWISE
  298.   echo -e "\n>> Checking if the compiler has the necessary features"
  299.   GCCVERSION=$(gcc -dumpversion)
  300.   GCCVERSION_F=$(echo $GCCVERSION | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/')
  301.   GCCVERSION_P=$((${GCCVERSION_F}*(10**(5-${#GCCVERSION_F}))))
  302.   if [ $GCCVERSION_P -lt 60100 ]; then
  303.     echo -e "\nTES3MP requires some fairly recent C++ features.\nCurrent GCC version is $GCCVERSION.\nUpdate GCC to at least version 6.1 to proceed.\n\nOnly upgrade your toolchain if you know what you are doing.\nProceed at your own risk."
  304.     exit 1
  305.   fi
  306.  
  307.   #AVOID SOME DEPENDENCIES ON SERVER ONLY MODE
  308.   if [ $SERVER_ONLY ]; then
  309.     BUILD_OSG=""
  310.     BUILD_BULLET=""
  311.   fi
  312.  
  313.   #PULL SOFTWARE VIA GIT
  314.   echo -e "\n>> Downloading software"
  315.   ! [ -e "$CODE" ] && git clone https://github.com/TES3MP/openmw-tes3mp.git "$CODE"
  316.   ! [ -e "$DEPENDENCIES/"callff ] &&git clone https://github.com/Koncord/CallFF "$DEPENDENCIES/"callff --depth 1
  317.   if [ $BUILD_OSG ] && ! [ -e "$DEPENDENCIES"/osg ] ; then git clone https://github.com/openscenegraph/OpenSceneGraph.git "$DEPENDENCIES"/osg --depth 1; fi
  318.   if [ $BUILD_BULLET ] && ! [ -e "$DEPENDENCIES"/bullet ]; then git clone https://github.com/bulletphysics/bullet3.git "$DEPENDENCIES"/bullet; fi # cannot --depth 1 because we check out specific revision
  319.   ! [ -e "$DEPENDENCIES"/raknet ] && git clone https://github.com/TES3MP/RakNet.git "$DEPENDENCIES"/raknet --depth 1
  320.   ! [ -e "$DEPENDENCIES"/terra ] && if [ $BUILD_TERRA ]; then git clone https://github.com/zdevito/terra.git "$DEPENDENCIES"/terra --depth 1; else wget https://github.com/zdevito/terra/releases/download/release-2016-02-26/terra-Linux-x86_64-2fa8d0a.zip -O "$DEPENDENCIES"/terra.zip; fi
  321.   ! [ -e "$KEEPERS"/CoreScripts ] && git clone https://github.com/TES3MP/CoreScripts.git "$KEEPERS"/CoreScripts
  322.  
  323.   #COPY STATIC SERVER AND CLIENT CONFIGS
  324.   echo -e "\n>> Copying server and client configs to their permanent place"
  325.   cp "$CODE"/files/tes3mp/tes3mp-{client,server}-default.cfg "$KEEPERS"
  326.  
  327.   #SET home VARIABLE IN tes3mp-server-default.cfg
  328.   echo -e "\n>> Autoconfiguring"
  329.   sed -i "s|home = .*|home = $KEEPERS/CoreScripts|g" "${KEEPERS}"/tes3mp-server-default.cfg
  330.  
  331.   #DIRTY HACKS
  332.   echo -e "\n>> Applying some dirty hacks"
  333.   sed -i "s|tes3mp.lua,chat_parser.lua|server.lua|g" "${KEEPERS}"/tes3mp-server-default.cfg #Fixes server scripts
  334.   #sed -i "s|Y #key for switch chat mode enabled/hidden/disabled|Right Alt|g" "${KEEPERS}"/tes3mp-client-default.cfg #Changes the chat key
  335.   #sed -i "s|mp.tes3mp.com|grimkriegor.zalkeen.us|g" "${KEEPERS}"/tes3mp-client-default.cfg #Sets Grim's server as the default
  336.  
  337.   #BUILD CALLFF
  338.   echo -e "\n>> Building CallFF"
  339.   mkdir -p "$DEPENDENCIES"/callff/build
  340.   cd "$DEPENDENCIES"/callff/build
  341.   cmake ..
  342.   make -j$CORES
  343.  
  344.   cd "$BASE"
  345.  
  346.   #BUILD OPENSCENEGRAPH
  347.   if [ $BUILD_OSG ]; then
  348.       echo -e "\n>> Building OpenSceneGraph"
  349.       mkdir -p "$DEPENDENCIES"/osg/build
  350.       cd "$DEPENDENCIES"/osg/build
  351.       git checkout tags/OpenSceneGraph-3.4.0
  352.       rm -f CMakeCache.txt
  353.       cmake ..
  354.       make -j$CORES
  355.  
  356.       cd "$BASE"
  357.   fi
  358.  
  359.   #BUILD BULLET
  360.   if [ $BUILD_BULLET ]; then
  361.       echo -e "\n>> Building Bullet Physics"
  362.       mkdir -p "$DEPENDENCIES"/bullet/build
  363.       cd "$DEPENDENCIES"/bullet/build
  364.       git checkout tags/2.86
  365.       rm -f CMakeCache.txt
  366.       cmake -DCMAKE_INSTALL_PREFIX="$DEPENDENCIES"/bullet/install -DBUILD_SHARED_LIBS=1 -DINSTALL_LIBS=1 -DINSTALL_EXTRA_LIBS=1 -DCMAKE_BUILD_TYPE=Release ..
  367.       make -j$CORES
  368.  
  369.       make install
  370.  
  371.       cd "$BASE"
  372.   fi
  373.  
  374.   #BUILD RAKNET
  375.   echo -e "\n>> Building RakNet"
  376.   mkdir -p "$DEPENDENCIES"/raknet/build
  377.   cd "$DEPENDENCIES"/raknet/build
  378.   rm -f CMakeCache.txt
  379.   cmake -DCMAKE_BUILD_TYPE=Release -DRAKNET_ENABLE_DLL=OFF -DRAKNET_ENABLE_SAMPLES=OFF -DRAKNET_ENABLE_STATIC=ON -DRAKNET_GENERATE_INCLUDE_ONLY_DIR=ON ..
  380.   make -j$CORES
  381.  
  382.   ln -sf "$DEPENDENCIES"/raknet/include/RakNet "$DEPENDENCIES"/raknet/include/raknet #Stop being so case sensitive
  383.  
  384.   cd "$BASE"
  385.  
  386.   #BUILD TERRA
  387.   if [ $BUILD_TERRA ]; then
  388.       echo -e "\n>> Building Terra"
  389.       cd "$DEPENDENCIES"/terra/
  390.       make -j$CORES
  391.  
  392.   else
  393.     if ! [ -e "$DEPENDENCIES"/terra ]; then
  394.       echo -e "\n>> Unpacking and preparing Terra"
  395.       cd "$DEPENDENCIES"
  396.       unzip -o terra.zip
  397.       rm -rf ./terra
  398.       mv --no-target-directory terra-* terra
  399.       rm terra.zip
  400.     fi
  401.   fi
  402.  
  403.   cd "$BASE"
  404.  
  405. fi
  406.  
  407. #CHECK THE REMOTE REPOSITORY FOR CHANGES
  408. if [ $UPGRADE ]; then
  409.  
  410.   #CHECK IF THERE ARE CHANGES IN THE GIT REMOTE
  411.   echo -e "\n>> Checking the git repository for changes"
  412.   cd "$CODE"
  413.   git remote update
  414.   if [ "$(git rev-parse @)" != "$(git rev-parse @{u})" ]; then
  415.     echo -e "\nNEW CHANGES on the git repository"
  416.     GIT_CHANGES=true
  417.   else
  418.     echo -e "\nNo changes on the git repository"
  419.   fi
  420.   cd "$BASE"
  421.  
  422.   #AUTOMATICALLY UPGRADE IF THERE ARE GIT CHANGES
  423.   if [ $AUTO_UPGRADE ]; then
  424.     if [ $GIT_CHANGES ]; then
  425.       REBUILD="YES"
  426.       UPGRADE="YES"
  427.     else
  428.       echo -e "\nNo new commits, exiting."
  429.       exit 0
  430.     fi
  431.   else
  432.     echo -e "\nDo you wish to rebuild TES3MP? (type YES to continue)"
  433.     read REBUILD_PROMPT
  434.     if [ "$REBUILD_PROMPT" == "YES" ]; then
  435.       REBUILD="YES"
  436.       UPGRADE="YES"
  437.     fi
  438.   fi
  439.  
  440. fi
  441.  
  442. #REBUILD TES3MP
  443. if [ $REBUILD ]; then
  444.  
  445.   #CHECK WHICH DEPENDENCIES ARE PRESENT
  446.   if [ -d "$DEPENDENCIES"/osg ]; then
  447.     BUILD_OSG=true
  448.   fi
  449.   if [ -d "$DEPENDENCIES"/bullet ]; then
  450.     BUILD_BULLET=true
  451.   fi
  452.  
  453.   #SWITCH TO A SPECIFIC COMMIT
  454.   if [ $BUILD_COMMIT ]; then
  455.     cd "$CODE"
  456.     if [ "$TARGET_COMMIT" == "latest" ]; then
  457.       echo -e "\nChecking out the latest commit."
  458.       git stash
  459.       git pull
  460.       git checkout master
  461.     else
  462.       echo -e "\nChecking out $TARGET_COMMIT"
  463.       git stash
  464.       git pull
  465.       git checkout "$TARGET_COMMIT"
  466.     fi
  467.     cd "$BASE"
  468.   fi
  469.  
  470.   #CHANGE VERSION STRING
  471.   if [ $CHANGE_VERSION_STRING ]; then
  472.     cd "$CODE"
  473.  
  474.     if [[ "$TARGET_VERSION_STRING" == "" || "$TARGET_VERSION_STRING" == "latest" ]]; then
  475.       echo -e "\nUsing the upstream version string"
  476.       git stash
  477.       cd "$KEEPERS"/CoreScripts
  478.       git stash
  479.       cd "$CODE"
  480.     else
  481.       echo -e "\nUsing \"$TARGET_VERSION_STRING\" as version string"
  482.       sed -i "s|#define TES3MP_VERSION .*|#define TES3MP_VERSION \"$TARGET_VERSION_STRING\"|g" ./components/openmw-mp/Version.hpp
  483.       sed -i "s|    if tes3mp.GetServerVersion() ~= .*|    if tes3mp.GetServerVersion() ~= \"$TARGET_VERSION_STRING\" then|g" "$KEEPERS"/CoreScripts/scripts/server.lua
  484.     fi
  485.  
  486.     cd "$BASE"
  487.   fi
  488.  
  489.     #PULL CODE CHANGES FROM THE GIT REPOSITORY
  490.   if [ "$UPGRADE" == "YES" ]; then
  491.     echo -e "\n>> Pulling code changes from git"
  492.     cd "$CODE"
  493.     git stash
  494.     git pull
  495.     git checkout master
  496.     cd "$BASE"
  497.  
  498.     cd "$KEEPERS"/CoreScripts
  499.     git stash
  500.     git pull
  501.     git checkout master
  502.     cd "$BASE"
  503.   fi
  504.  
  505.   echo -e "\n>> Doing a clean build of TES3MP"
  506.  
  507.   rm -r "$DEVELOPMENT"
  508.   mkdir -p "$DEVELOPMENT"
  509.  
  510.   cd "$DEVELOPMENT"
  511.  
  512.   CMAKE_PARAMS="-Wno-dev \
  513.      -DCMAKE_BUILD_TYPE=Release \
  514.      -DBUILD_OPENCS=OFF \
  515.      -DCMAKE_CXX_STANDARD=14 \
  516.      -DCMAKE_CXX_FLAGS=\"-std=c++14\" \
  517.      -DCallFF_INCLUDES="${CALLFF_LOCATION}"/include \
  518.      -DCallFF_LIBRARY="${CALLFF_LOCATION}"/build/src/libcallff.a \
  519.      -DDESIRED_QT_VERSION="5" \
  520.      -DRakNet_INCLUDES="${RAKNET_LOCATION}"/include \
  521.      -DRakNet_LIBRARY_DEBUG="${RAKNET_LOCATION}"/build/lib/libRakNetLibStatic.a \
  522.      -DRakNet_LIBRARY_RELEASE="${RAKNET_LOCATION}"/build/lib/libRakNetLibStatic.a \
  523.      -DTerra_INCLUDES="${TERRA_LOCATION}"/include \
  524.      -DTerra_LIBRARY_RELEASE="${TERRA_LOCATION}"/lib/libterra.a"
  525.  
  526.   if [ $BUILD_OSG ]; then
  527.     CMAKE_PARAMS="$CMAKE_PARAMS \
  528.      -DOPENTHREADS_INCLUDE_DIR="${OSG_LOCATION}"/include \
  529.      -DOPENTHREADS_LIBRARY="${OSG_LOCATION}"/build/lib/libOpenThreads.so \
  530.      -DOSG_INCLUDE_DIR="${OSG_LOCATION}"/include \
  531.      -DOSG_LIBRARY="${OSG_LOCATION}"/build/lib/libosg.so \
  532.      -DOSGANIMATION_INCLUDE_DIR="${OSG_LOCATION}"/include \
  533.      -DOSGANIMATION_LIBRARY="${OSG_LOCATION}"/build/lib/libosgAnimation.so \
  534.      -DOSGDB_INCLUDE_DIR="${OSG_LOCATION}"/include \
  535.      -DOSGDB_LIBRARY="${OSG_LOCATION}"/build/lib/libosgDB.so \
  536.      -DOSGFX_INCLUDE_DIR="${OSG_LOCATION}"/include \
  537.      -DOSGFX_LIBRARY="${OSG_LOCATION}"/build/lib/libosgFX.so \
  538.      -DOSGGA_INCLUDE_DIR="${OSG_LOCATION}"/include \
  539.      -DOSGGA_LIBRARY="${OSG_LOCATION}"/build/lib/libosgGA.so \
  540.      -DOSGPARTICLE_INCLUDE_DIR="${OSG_LOCATION}"/include \
  541.      -DOSGPARTICLE_LIBRARY="${OSG_LOCATION}"/build/lib/libosgParticle.so \
  542.      -DOSGTEXT_INCLUDE_DIR="${OSG_LOCATION}"/include \
  543.      -DOSGTEXT_LIBRARY="${OSG_LOCATION}"/build/lib/libosgText.so\
  544.      -DOSGUTIL_INCLUDE_DIR="${OSG_LOCATION}"/include \
  545.      -DOSGUTIL_LIBRARY="${OSG_LOCATION}"/build/lib/libosgUtil.so \
  546.      -DOSGVIEWER_INCLUDE_DIR="${OSG_LOCATION}"/include \
  547.      -DOSGVIEWER_LIBRARY="${OSG_LOCATION}"/build/lib/libosgViewer.so"
  548.   fi
  549.  
  550.   if [ $BUILD_BULLET ]; then
  551.     CMAKE_PARAMS="$CMAKE_PARAMS \
  552.      -DBullet_INCLUDE_DIR="${BULLET_LOCATION}"/install/include/bullet \
  553.      -DBullet_BulletCollision_LIBRARY="${BULLET_LOCATION}"/install/lib/libBulletCollision.so \
  554.      -DBullet_LinearMath_LIBRARY="${BULLET_LOCATION}"/install/lib/libLinearMath.so"
  555.     export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"${BULLET_LOCATION}"/install/lib
  556.     export BULLET_ROOT="${BULLET_LOCATION}"/install
  557.   fi
  558.  
  559.   if [ $SERVER_ONLY ]; then
  560.     CMAKE_PARAMS="$CMAKE_PARAMS \
  561.      -DBUILD_OPENMW_MP=ON \
  562.      -DBUILD_BROWSER=OFF \
  563.      -DBUILD_BSATOOL=OFF \
  564.      -DBUILD_ESMTOOL=OFF \
  565.      -DBUILD_ESSIMPORTER=OFF \
  566.      -DBUILD_LAUNCHER=OFF \
  567.      -DBUILD_MWINIIMPORTER=OFF \
  568.      -DBUILD_MYGUI_PLUGIN=OFF \
  569.      -DBUILD_OPENMW=OFF \
  570.      -DBUILD_WIZARD=OFF"
  571.   fi
  572.  
  573.   if [ $BUILD_MASTER ]; then
  574.     CMAKE_PARAMS="$CMAKE_PARAMS \
  575.      -DBUILD_MASTER=ON"
  576.   fi
  577.  
  578.   if [ $DEBUG_SYMBOLS ]; then
  579.     CMAKE_PARAMS="$CMAKE_PARAMS \
  580.      -DCMAKE_BUILD_TYPE=Debug"
  581.   fi
  582.  
  583.   if [ $CMAKE_LOCAL ]; then
  584.     CMAKE_PARAMS="$CMAKE_PARAMS \
  585.      -DCMAKE_LIBRARY_PATH=/usr/local/lib64 \
  586.      -DBOOST_ROOT=/usr/local \
  587.      -DBoost_NO_SYSTEM_PATHS=ON"
  588.   fi
  589.  
  590.   echo -e "\n\n$CMAKE_PARAMS\n\n"
  591.   cmake "$CODE" $CMAKE_PARAMS || true
  592.   set -o pipefail # so that the "tee" below would not make build always return success
  593.   make -j $CORES 2>&1 | tee "${BASE}"/build.log
  594.  
  595.   cd "$BASE"
  596.  
  597.   #CREATE SYMLINKS FOR THE CONFIG FILES INSIDE THE NEW BUILD FOLDER
  598.   echo -e "\n>> Creating symlinks of the config files in the build folder"
  599.   for file in "$KEEPERS"/*.cfg
  600.   do
  601.     FILEPATH=$file
  602.     FILENAME=$(basename $file)
  603.     mv "$DEVELOPMENT/$FILENAME" "$DEVELOPMENT/$FILENAME.bkp" 2> /dev/null
  604.     ln -sf "../keepers/$FILENAME" "$DEVELOPMENT/"
  605.   done
  606.  
  607.   #CREATE SYMLINKS FOR RESOURCES INSIDE THE CONFIG FOLDER
  608.   echo -e "\n>> Creating symlinks for resources inside the config folder"
  609.   ln -sf ../"$(basename $DEVELOPMENT)"/resources "$KEEPERS"/resources 2> /dev/null
  610.  
  611.   #CREATE USEFUL SHORTCUTS ON THE BASE DIRECTORY
  612.   echo -e "\n>> Creating useful shortcuts on the base directory"
  613.   if [ $SERVER_ONLY ]; then
  614.     SHORTCUTS=( "tes3mp-server" )
  615.   else
  616.     SHORTCUTS=( "tes3mp" "tes3mp-browser" "tes3mp-server" )
  617.   fi
  618.   for i in ${SHORTCUTS[@]}; do
  619.     printf "#!/bin/bash\n\ncd build/\n./$i\ncd .." > "$i".sh
  620.     chmod +x "$i".sh
  621.   done
  622.  
  623.   #ALL DONE
  624.   echo -e "\n\n\nAll done! Press any key to exit.\nMay Vehk bestow his blessing upon your Muatra."
  625.  
  626. fi
  627.  
  628. #MAKE PORTABLE PACKAGE
  629. if [ $MAKE_PACKAGE ]; then
  630.   echo -e "\n>> Creating TES3MP package"
  631.  
  632.   PACKAGE_BINARIES=("tes3mp" "tes3mp-browser" "tes3mp-server" "openmw-launcher" "openmw-wizard" "openmw-essimporter" "openmw-iniimporter" "bsatool" "esmtool")
  633.   LIBRARIES_OPENMW=("libavcodec.so" "libavformat.so" "libavutil.so" "libboost_filesystem.so" "libboost_program_options.so" "libboost_system.so" "libboost_thread.so" "libBulletCollision.so" "libbz2.so" "libLinearMath.so" "libMyGUIEngine.so" "libopenal.so" "libOpenThreads.so" "libosgAnimation.so" "libosgDB.so" "libosgFX.so" "libosgGA.so" "libosgParticle.so" "libosg.so" "libosgText.so" "libosgUtil.so" "libosgViewer.so" "libosgWidget.so" "libSDL2" "libswresample.so" "libswscale.so" "libts.so" "libtxc_dxtn.so" "libunshield.so" "libuuid.so" "osgPlugins") #"libfreetype.so"
  634.   LIBRARIES_TES3MP=("libcallff.a" "libRakNetLibStatic.a" "libterra.a" "libtinfo.so")
  635.   LIBRARIES_EXTRA=("libpng16.so" "libpng12.so") #"libstdc++.so.6"
  636.  
  637.   #EXIT IF TES3MP hasn't been compiled yet
  638.   if [ ! -f "$DEVELOPMENT"/tes3mp ]; then
  639.     echo -e "\nTES3MP has to be built before packaging"
  640.     exit 1
  641.   fi
  642.  
  643.   cp -r "$DEVELOPMENT" "$PACKAGE_TMP"
  644.   cd "$PACKAGE_TMP"
  645.  
  646.   #CLEANUP UNNEEDED FILES
  647.   echo -e "\nCleaning up unneeded files"
  648.   find "$PACKAGE_TMP" -type d -name "CMakeFiles" -exec rm -rf "{}" \; || true
  649.   #find "$PACKAGE_TMP" -type d -name ".git" -exec rm -rf "{}" \; || true
  650.   find "$PACKAGE_TMP" -type l -exec rm -f "{}" \; || true
  651.   rm -f "$PACKAGE_TMP"/{Make*,CMake*,*cmake}
  652.   rm -f "$PACKAGE_TMP"/{*.bkp,*.desktop,*.xml}
  653.   rm -rf "$PACKAGE_TMP"/{apps,components,docs,extern,files}
  654.  
  655.   #COPY USEFUL FILES
  656.   echo -e "\nCopying useful files"
  657.   cp -r "$KEEPERS"/{CoreScripts,*.cfg} .
  658.   sed -i "s|home = .*|home = ./CoreScripts|g" "${PACKAGE_TMP}"/tes3mp-server-default.cfg
  659.  
  660.   #COPY WHATEVER EXTRA FILES ARE CURRENTLY PRESENT
  661.   if [ -d "$EXTRA" ]; then
  662.     echo -e "\nCopying some extra files"
  663.     cp -r --preserve=links "$EXTRA"/* "$PACKAGE_TMP"/
  664.   fi
  665.  
  666.   #LIST AND COPY ALL LIBS
  667.   mkdir -p lib
  668.   echo -e "\nCopying needed libraries"
  669.  
  670.   LIBRARIES=("${LIBRARIES_OPENMW[@]}" "${LIBRARIES_TES3MP[@]}" "${LIBRARIES_EXTRA[@]}")
  671.   for LIB in "${LIBRARIES[@]}"; do
  672.     find /lib /usr/lib /usr/local/lib /usr/local/lib64 "$DEPENDENCIES" -name "$LIB*" -exec cp -r --preserve=links "{}" ./lib \; 2> /dev/null || true
  673.     echo -ne "$LIB\033[0K\r"
  674.   done
  675.  
  676.   #MAKE SURE ALL SYMLINKS ARE RELATIVE
  677.   echo -e "\nMaking sure all symlinks are relative"
  678.   find ./lib -type l | while read LINK; do
  679.     LINK_BASENAME="$(basename $LINK)"
  680.     LINK_TARGET="$(readlink -f $LINK)"
  681.     LINK_TARGET_BASENAME="$(basename $LINK_TARGET)"
  682.     ln -sf ./"$LINK_TARGET_BASENAME" ./lib/"$LINK_BASENAME"
  683.     echo -ne "$LINK\033[0K\r"
  684.   done
  685.  
  686.   #for BINARY in "${PACKAGE_BINARIES[@]}"; do
  687.     #join <(ldd "$BINARY" | awk '{if(substr($3,0,1)=="/") print $1,$3}') <(patchelf --print-needed "$BINARY" ) | cut -d\  -f2 | \
  688.     #xargs -d '\n' -I{} cp --copy-contents {} ./lib
  689.   #done
  690.  
  691.   #PATCH LIBRARY PATHS ON THE EXECUTABLES
  692.   #echo -e "\nPatching binary library paths"
  693.   #for BINARY in "${PACKAGE_BINARIES[@]}"; do
  694.   #  echo -e "Patching: $BINARY"
  695.   #  patchelf --set-rpath "./lib" "$PACKAGE_TMP"/"$BINARY"
  696.   #done
  697.  
  698.   #PACKAGE INFO
  699.   PACKAGE_ARCH=$(uname -m)
  700.   PACKAGE_SYSTEM=$(uname -o  | sed 's,/,+,g')
  701.   PACKAGE_DISTRO=$(lsb_release -si)
  702.   PACKAGE_VERSION=$(cat "$CODE"/components/openmw-mp/Version.hpp | grep TES3MP_VERSION | awk -F'"' '{print $2}')
  703.   PACKAGE_COMMIT=$(git --git-dir=$CODE/.git rev-parse @ | head -c10)
  704.   PACKAGE_NAME="tes3mp-$PACKAGE_SYSTEM-$PACKAGE_ARCH-release-$PACKAGE_VERSION-$PACKAGE_COMMIT-$PACKAGE_DISTRO-$USER"
  705.   PACKAGE_DATE="$(date +"%Y-%m-%d")"
  706.   echo -e "TES3MP $PACKAGE_VERSION ($PACKAGE_COMMIT) built on $PACKAGE_SYSTEM $PACKAGE_ARCH ($PACKAGE_DISTRO) on $PACKAGE_DATE by $USER ($HOSTNAME)" > "$PACKAGE_TMP"/tes3mp-package-info.txt
  707.  
  708.   #CREATE PRE-LAUNCH SCRIPT
  709.   cat << 'EOF' > tes3mp-prelaunch
  710. #!/bin/bash
  711.  
  712. ARGS="$*"
  713. GAMEDIR="$(cd "$(dirname "$0")"; pwd -P)"
  714. TES3MP_HOME="$HOME/.config/openmw"
  715.  
  716. # If there are config files in the home directory, load those
  717. # Otherwise check the package/installation directory and load those
  718. # Otherwise copy them to the home directory
  719. if [[ "$ARGS" = 'tes3mp-server' ]]; then
  720.    if [[ -f "$TES3MP_HOME"/tes3mp-server.cfg ]]; then
  721.        echo -e "Loading server config from the home directory"
  722.        LOADING_FROM_HOME=true
  723.    elif [[ -f "$GAMEDIR"/tes3mp-server-default.cfg ]]; then
  724.        echo -e "Loading server config from the package directory"
  725.    else
  726.        echo -e "Server config not found in home and package directory, trying to copy from .example"
  727.        cp -f tes3mp-server-default.cfg.example "$TES3MP_HOME"/tes3mp-server.cfg
  728.        LOADING_FROM_HOME=true
  729.    fi
  730.    if [[ $LOADING_FROM_HOME ]]; then
  731.        if [[ -d "$TES3MP_HOME"/CoreScripts ]]; then
  732.            echo -e "Loading CoreScripts folder from the home directory"
  733.        else
  734.            echo -e "CoreScripts folder not found in home directory, copying from package directory"
  735.            cp -rf "$GAMEDIR"/CoreScripts/ "$TES3MP_HOME"/
  736.            sed -i "s|home = .*|home = $TES3MP_HOME/CoreScripts |g" "$TES3MP_HOME"/tes3mp-server.cfg
  737.        fi
  738.        #if [[ -e "$TES3MP_HOME"/resources ]]; then
  739.        #    echo -e "Loading resources folder from the home directory"
  740.        #else
  741.        #    echo -e "Resources folder not found in home directory, linking from package directory"
  742.        #    ln -sf "$GAMEDIR"/resources "$TES3MP_HOME"/
  743.        #fi
  744.    fi
  745. else
  746.    if [[ -f $TES3MP_HOME/tes3mp-client.cfg ]]; then
  747.        echo -e "Loading client config from the home directory"
  748.    elif [[ -f tes3mp-client-default.cfg ]]; then
  749.        echo -e "Loading client config from the package directory"
  750.    else
  751.        echo -e "Client config not found in home and package directory, trying to copy from .example"
  752.        cp -f "$GAMEDIR"/tes3mp-client-default.cfg.example "$TES3MP_HOME"/tes3mp-client.cfg
  753.    fi
  754. fi
  755. EOF
  756.  
  757.  #CREATE WRAPPERS
  758.  echo -e "\nCreating wrappers"
  759.  for BINARY in "${PACKAGE_BINARIES[@]}"; do
  760.    WRAPPER="$BINARY"
  761.    BINARY_RENAME="$BINARY.$PACKAGE_ARCH"
  762.    mv "$BINARY" "$BINARY_RENAME"
  763.    printf "#!/bin/bash\n\nWRAPPER=\"\$(basename \$0)\"\nGAMEDIR=\"\$(dirname \$0)\"\ncd \"\$GAMEDIR\"\nif test -f ./tes3mp-prelaunch; then bash ./tes3mp-prelaunch \"\$WRAPPER\"; fi\nLD_LIBRARY_PATH=\"./lib\" ./$BINARY_RENAME \"\$@\"" > "$WRAPPER"
  764.   done
  765.   chmod 755 *
  766.  
  767.   #CREATE ARCHIVE
  768.   echo -e "\nCreating archive"
  769.   mv "$PACKAGE_TMP" "$BASE"/TES3MP
  770.   PACKAGE_TMP="$BASE"/TES3MP
  771.   tar cvzf "$BASE"/package.tar.gz --directory="$BASE" TES3MP/
  772.  
  773.   #RENAME ARCHIVE
  774.   mv "$BASE"/package.tar.gz "$BASE"/"$PACKAGE_NAME".tar.gz
  775.  
  776.   #CLEANUP TEMPORARY FOLDER AND FINISH
  777.   rm -rf "$PACKAGE_TMP"
  778.   echo -e "\n>> Package created as \"$PACKAGE_NAME\""
  779.  
  780.   cd "$BASE"
  781. fi
  782.  
  783. #UPGRADE THE TES3MP-DEPLOY SCRIPT
  784. if [ $SCRIPT_UPGRADE ]; then
  785.  
  786.   SCRIPT_OLD_VERSION=$(cat tes3mp-deploy.sh | grep ^VERSION= | cut -d'"' -f2)
  787.  
  788.   if [ -d ./.git ]; then
  789.     echo -e "\n>>Upgrading the TES3MP-deploy git repository"
  790.     git pull
  791.   else
  792.     echo -e "\n>>Downloading TES3MP-deploy from GitHub"
  793.     mv "$0" "$BASE"/.tes3mp-deploy.sh.bkp
  794.     wget --no-verbose -O "$BASE"/tes3mp-deploy.sh https://raw.githubusercontent.com/GrimKriegor/TES3MP-deploy/master/tes3mp-deploy.sh
  795.     chmod +x ./tes3mp-deploy.sh
  796.   fi
  797.  
  798.   SCRIPT_NEW_VERSION=$(cat tes3mp-deploy.sh | grep ^VERSION= | cut -d'"' -f2)
  799.  
  800.   if [ "$SCRIPT_NEW_VERSION" == "" ]; then
  801.     echo -e "\nThere was a problem downloading the script, exiting."
  802.     exit 1
  803.   fi
  804.  
  805.   if [ "$SCRIPT_OLD_VERSION" != "$SCRIPT_NEW_VERSION" ]; then
  806.     echo -e "\nScript upgraded from ($SCRIPT_OLD_VERSION) to ($SCRIPT_NEW_VERSION)"
  807.     exit 0
  808.   else
  809.     echo -e "\nScript already at the latest avaliable version ($SCRIPT_OLD_VERSION)"
  810.     exit 0
  811.   fi
  812.  
  813. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement