Provides automatic installation scripts for OpenRA with Tiberian Sun & Red Alert 2 + Dune 2 (Windows, Linux)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

363 lines
17 KiB

  1. #!/bin/bash
  2. # Allow interruption of the script at any time (Ctrl + C)
  3. trap "exit" INT
  4. #*********************************************************************************************************
  5. ## VARIABLES USED IN THE SCRIPT
  6. #
  7. # Package name & version
  8. PACKAGE_NAME=openra-bleed-tibsunra2
  9. PACKAGE_VERSION=1
  10. PACKAGE=$PACKAGE_NAME-$PACKAGE_VERSION
  11. # Get our Linux distribution
  12. DISTRO=$(cat /etc/os-release | sed -n '/PRETTY_NAME/p' | grep -o '".*"' | sed -e 's/"//g' -e s/'([^)]*)'/''/g -e 's/ .*//' -e 's/[ \t]*$//')
  13. UBUNTU="Ubuntu"
  14. DEBIAN="Debian"
  15. OPENSUSE="openSUSE"
  16. FEDORA="Fedora"
  17. # Get the current directory
  18. WORKING_DIR=$(pwd)
  19. if [[ $DISTRO =~ $UBUNTU ]] || [[ $DISTRO =~ $DEBIAN ]]; then
  20. # Find out used Linux distribution
  21. RELEASE=$(lsb_release -d | sed 's/Description:\t//g')
  22. # Check if the used OS is Ubuntu 14.04 LTS/14.10 or Linux Mint
  23. RELEASE_VERSION=$(lsb_release -r | sed 's/[^0-9]*//g')
  24. RELEASE_MINT=$(lsb_release -i 2>/dev/null |grep -c "Mint")
  25. # Check for critical build dependencies (especially for Ubuntu 14.04 LTS/14.10 & Linux Mint)
  26. PKG1_CHECK=$(dpkg-query -W -f='${Status}' libnuget-core-cil 2>/dev/null | grep -c "ok installed")
  27. PKG2_CHECK=$(dpkg-query -W -f='${Status}' mono-devel 2>/dev/null | grep -c "ok installed")
  28. PKG3_CHECK=$(dpkg-query -W -f='${Status}' nuget 2>/dev/null | grep -c "ok installed")
  29. # Do we have any OpenRA packages on the system?
  30. PKG4_CHECK=$(dpkg-query -W -f='${Status}' openra 2>/dev/null | grep -c "ok installed")
  31. PKG5_CHECK=$(dpkg-query -W -f='${Status}' openra-playtest 2>/dev/null | grep -c "ok installed")
  32. PKG6_CHECK=$(dpkg-query -W -f='${Status}' openra-bleed 2>/dev/null | grep -c "ok installed")
  33. elif [[ $DISTRO =~ $OPENSUSE ]]; then
  34. # Find out used OpenSUSE version
  35. RELEASE=$(cat /etc/os-release | sed -n 4p | grep -o '".*"' | sed -e 's/"//g' -e s/'([^)]*)'/''/g -e 's/[ \t]*$//')
  36. # Do we have any OpenRA packages on the system?
  37. PKG1_CHECK=$(rpm -qa openra | wc -l)
  38. PKG2_CHECK=$(rpm -qa openra-playtest | wc -l)
  39. PKG3_CHECK=$(rpm -qa openra-bleed | wc -l)
  40. elif [[ $DISTRO =~ $FEDORA ]]; then
  41. # Find out used Fedora version
  42. RELEASE=$(cat /etc/os-release | sed -n '/PRETTY_NAME/p' | grep -o '".*"' | sed -e 's/"//g' -e s/'([^)]*)'/''/g -e 's/[ \t]*$//')
  43. # Do we have any OpenRA packages on the system?
  44. PKG1_CHECK=$(rpm -qa openra | wc -l)
  45. PKG2_CHECK=$(rpm -qa openra-playtest | wc -l)
  46. PKG3_CHECK=$(rpm -qa openra-bleed | wc -l)
  47. fi
  48. # Check for missing RA2 directories.
  49. RA2_MISSINGDIR1="$HOME/openra-master/$PACKAGE/mods/ra2/bits/vehicles"
  50. RA2_MISSINGDIR2="$HOME/openra-master/$PACKAGE/mods/ra2/bits/themes"
  51. # Check if we already have sudo password in memory (timeout/timestamp check)
  52. SUDO_CHECK=$(sudo -n uptime 2>&1|grep "load"|wc -l)
  53. BASH_CHECK=$(ps | grep `echo $$` | awk '{ print $4 }')
  54. bold_in='\e[1m'
  55. line_in='\e[4m'
  56. dim_in='\e[2m'
  57. green_in='\e[32m'
  58. red_in='\e[91m'
  59. out='\e[0m'
  60. #*********************************************************************************************************
  61. ## PRE-CHECK
  62. #
  63. # Check if we're using bash or sh to run the script. If bash, OK. If sh, ask user to run the script with bash.
  64. if [ ! $BASH_CHECK = "bash" ]; then
  65. echo "
  66. Please run this script using bash (/usr/bin/bash).
  67. "
  68. exit 1
  69. fi
  70. # Check if we are root or not. If yes, then terminate the script.
  71. if [[ $UID = 0 ]]; then
  72. echo -e "\nPlease run this script as a regular user. Do not use root or sudo. Some commands used in the script require regular user permissions.\n"
  73. exit 1
  74. fi
  75. #If package dir exists already, delete it.
  76. if [ -d "$HOME/openra-master/" ]; then
  77. rm -rf "$HOME/openra-master"
  78. fi
  79. if [[ $DISTRO =~ $UBUNTU ]] || [[ $DISTRO =~ $DEBIAN ]]; then
  80. #If deb package exists already, delete it.
  81. if [ -f $HOME/$PACKAGE_NAME*.deb ]; then
  82. rm -f $HOME/$PACKAGE_NAME*.deb
  83. fi
  84. elif [[ $DISTRO =~ $OPENSUSE ]] || [[ $DISTRO =~ $FEDORA ]]; then
  85. if [ -f $HOME/$PACKAGE_NAME*.rpm ]; then
  86. rm -f $HOME/$PACKAGE_NAME*.rpm
  87. fi
  88. fi
  89. # Stop execution if we encounter an error
  90. set -e
  91. #*********************************************************************************************************
  92. ## PART 1/7
  93. #
  94. ## Installation of OpenRA compilation dependencies and user notification message
  95. echo -e "\n$bold_in***Welcome Comrade*** $out\n"
  96. echo -e "This script compiles and installs OpenRA from source with Tiberian Sun & Red Alert 2.\n
  97. - The script is NOT made by the developers of OpenRA and may contain bugs.
  98. - The script creates an installation package using OpenRA source code and additional Red Alert 2 mod files from Github.\n\nNOTE: As the development of OpenRA & Red Alert 2 continues, this script will likely become unusable some day. Please, feel free to modify it if necessary."
  99. if [[ $DISTRO =~ $UBUNTU ]]; then
  100. echo -e "$line_in\nThe script has been tested on:\n\nDistribution\t\tStatus$out\nUbuntu 16.04 LTS$green_in\tOK$out\nUbuntu 15.10$green_in\t\tOK$out\nUbuntu 15.04 LTS$green_in\tOK$out\nUbuntu 14.10$green_in\t\tOK$out\nUbuntu 14.04 LTS$green_in\tOK$out\nLinux Mint 17.3$green_in\t\tOK$out\nLinux Mint 17.2$green_in\t\tOK$out\nLinux Mint 17.1$green_in\t\tOK$out\nLinux Mint 16$red_in\t\tFailure$out$dim_in (can't find required packages)$out\n"
  101. elif [[ $DISTRO =~ $DEBIAN ]]; then
  102. echo -e "$line_in\nThe script has been tested on:\n\nDistribution\t\tStatus$out\nDebian 8.3 $green_in\t\tOK$out\n"
  103. elif [[ $DISTRO =~ $OPENSUSE ]]; then
  104. echo -e "$line_in\nThe script has been tested on:\n\nDistribution\t\tStatus$out\nOpenSUSE Tumbleweed $green_in\tOK$out\nOpenSUSE Leap 42.1 $green_in\tOK$out\nOpenSUSE 13.2 $green_in\t\tOK$out\nOpenSUSE 13.1 $red_in\t\tFailure$out$dim_in (can't find required packages)$out\n"
  105. elif [[ $DISTRO =~ $FEDORA ]]; then
  106. echo -e "$line_in\nThe script has been tested on:\n\nDistribution\t\tStatus$out\nFedora 23 $green_in\t\tOK$out\nFedora 22 $green_in\t\tOK$out\n"
  107. fi
  108. echo -e "You are using $RELEASE.\n"
  109. read -r -p "Do you want to continue? [y/N] " response
  110. if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
  111. sleep 1
  112. if [[ $DISTRO =~ $UBUNTU ]] || [[ $DISTRO =~ $DEBIAN ]]; then
  113. echo -e "\nAllright, let's continue. Do you want $bold_in\n\n1.$out manually check which OpenRA build dependencies (packages) will be installed on your system and manually install OpenRA after compilation? $dim_in(manual apt-get + deb packages installation)$bold_in\n2.$out automatically accept the installation of the OpenRA build dependencies during the script execution and automatically install OpenRA after compilation? $dim_in(apt-get with -y option + automatic .deb packages installation)$out\n"
  114. elif [[ $DISTRO =~ $OPENSUSE ]] || [[ $DISTRO =~ $FEDORA ]]; then
  115. echo -e "\nAllright, let's continue. Do you want $bold_in\n\n1.$out manually check which OpenRA build dependencies (packages) will be installed on your system and manually install OpenRA after compilation? $dim_in(manual rpm packages installation)$bold_in\n2.$out automatically accept the installation of the OpenRA build dependencies during the script execution and automatically install OpenRA after compilation? $dim_in(automatic installation of rpm packages)$out\n"
  116. fi
  117. read -r -p "Please type 1 or 2 (Default: 2): " number
  118. sleep 1
  119. if [[ $number -eq 1 ]]; then
  120. METHOD=''
  121. echo -e "\nSelected installation method:$bold_in Manual$out"
  122. else
  123. if [[ $DISTRO =~ $UBUNTU ]] || [[ $DISTRO =~ $DEBIAN ]] || [[ $DISTRO =~ $FEDORA ]]; then
  124. METHOD=-y
  125. echo -e "\nSelected installation method:$bold_in Automatic$out"
  126. elif [[ $DISTRO =~ $OPENSUSE ]]; then
  127. METHOD='--non-interactive --no-gpg-checks'
  128. echo -e "\nSelected installation method:$bold_in Automatic$out"
  129. fi
  130. fi
  131. if [ $SUDO_CHECK -eq 0 ]; then
  132. if [[ -z $METHOD ]]; then
  133. echo -e "\nOpenRA compilation requires that you install some packages first. Your permission for installation is asked (yes/no) everytime it's needed. This script asks for a required root password now, so you don't have to type it multiple times later on while the script is running.\n\nPlease type sudo/root password now.\n"
  134. else
  135. echo -e "\nOpenRA compilation requires that you install some packages first. This script asks for a required root password now, so you don't have to type it multiple times later on while the script is running.\n\nPlease type sudo/root password now.\n"
  136. fi
  137. sudo echo -e "\nRoot password OK."
  138. sleep 1
  139. else
  140. true
  141. fi
  142. sleep 2
  143. #-----------------------------------------------------------------------------------------------------------------------------------------------------------
  144. echo -e "$bold_in\n1/7 ***OpenRA build dependencies***\n$out"
  145. sleep 2
  146. if [[ $DISTRO =~ $UBUNTU ]] || [[ $DISTRO =~ $DEBIAN ]]; then
  147. echo -e "Updating package lists with APT.\n"
  148. sleep 2
  149. sudo apt-get update || true
  150. fi
  151. echo -e "Installing required OpenRA build dependencies.\n"
  152. sleep 4
  153. if [[ $DISTRO =~ $UBUNTU ]] || [[ $DISTRO =~ $DEBIAN ]]; then
  154. sudo apt-get $METHOD install git dpkg-dev dh-make mono-devel libfreetype6 libopenal1 libsdl2-2.0-0 curl liblua5.1-0 zenity xdg-utils build-essential gcc make libfile-fcntllock-perl
  155. mozroots --import --sync && \
  156. sudo apt-key update || exit 1
  157. elif [[ $DISTRO =~ $OPENSUSE ]]; then
  158. if [[ ! $RELEASE = "openSUSE Leap 42.1" ]] || [[ ! $RELEASE = "openSUSE Tumbleweed" ]]; then
  159. sudo zypper $METHOD install rpm-build git mono-devel libfreetype6 libopenal1 libSDL2-2_0-0 curl lua51 liblua5_1 zenity xdg-utils gcc make
  160. else
  161. sudo zypper $METHOD install rpm-build git mono-devel libfreetype6 libopenal1 libSDL2-2_0-0 curl lua51 liblua5_1 zenity xdg-utils gcc make
  162. fi
  163. mozroots --import --sync
  164. elif [[ $DISTRO =~ $FEDORA ]]; then
  165. sudo dnf $METHOD install rpm-build git mono-devel freetype openal-soft SDL2 libgdiplus-devel libcurl compat-lua zenity xdg-utils gcc make
  166. cd /etc/yum.repos.d/
  167. if [[ $RELEASE = "Fedora 23" ]]; then
  168. sudo wget http://download.opensuse.org/repositories/games:openra/Fedora_23/games:openra.repo
  169. sudo dnf $METHOD --best --allowerasing install mono-core
  170. elif [[ $RELEASE = "Fedora 22" ]]; then
  171. sudo wget http://download.opensuse.org/repositories/games:openra/Fedora_22/games:openra.repo
  172. sudo dnf $METHOD --best --allowerasing install mono-core
  173. fi
  174. cd $WORKING_DIR
  175. mozroots --import --sync
  176. fi
  177. #*********************************************************************************************************
  178. ## PART 2/7
  179. #
  180. ## Download the latest OpenRA & Red Alert 2 source files from Github, create build directories to the user's home directory.
  181. ## Once Red Alert 2 source files have been downloaded, move them to the OpenRA parent source directory.
  182. ## Add several missing directories for Red Alert 2.
  183. echo -e "$bold_in\n2/7 ***Downloading OpenRA source code & Red Alert 2 mod files from Github***\n$out"
  184. sleep 2
  185. echo -e "Part 1 (OpenRA source code):\n"
  186. mkdir -p $HOME/openra-master/{$PACKAGE,ra2} && \
  187. git clone -b bleed https://github.com/OpenRA/OpenRA.git $HOME/openra-master/$PACKAGE
  188. echo -e "\nPart 2 (Red Alert 2 mod files):\n"
  189. git clone -b master https://github.com/OpenRA/ra2.git $HOME/openra-master/ra2 && \
  190. mv $HOME/openra-master/ra2/OpenRA.Mods.RA2 $HOME/openra-master/$PACKAGE && \
  191. mv $HOME/openra-master/ra2 $HOME/openra-master/$PACKAGE/mods/
  192. if [ ! -d "$RA2_MISSINGDIR1" ]; then
  193. mkdir "$RA2_MISSINGDIR1"
  194. fi
  195. if [ ! -d "$RA2_MISSINGDIR2" ]; then
  196. mkdir "$RA2_MISSINGDIR2"
  197. fi
  198. cp ./data/patches/linux/*.patch $HOME/openra-master/
  199. #*********************************************************************************************************
  200. ## PART 3/7
  201. #
  202. ## Patch several OpenRA source files (Makefile and such) for Tiberian Sun & Red Alert 2
  203. echo -e "$bold_in\n3/7 ***Preparing OpenRA source files for Tiberian Sun & Red Alert 2***\n$out"
  204. sleep 2
  205. for i in $HOME/openra-master/*.patch; do patch -d $HOME/openra-master/$PACKAGE -Np1 < $i; done
  206. # Get version number for Red Alert 2 mod (Github)
  207. RA2_VERSION=git-$(git ls-remote https://github.com/OpenRA/ra2.git | head -1 | sed "s/HEAD//" | sed 's/^\(.\{7\}\).*/\1/')
  208. sed -i "s/Version: {DEV_VERSION}/Version: $RA2_VERSION/g" $HOME/openra-master/$PACKAGE/mods/ra2/mod.yaml
  209. #*********************************************************************************************************
  210. ## PART 4/7
  211. #
  212. ## Compile the game
  213. echo -e "$bold_in\n4/7 ***Starting OpenRA compilation with Tiberian Sun & Red Alert 2***$out"
  214. sleep 2
  215. if [[ $DISTRO =~ $UBUNTU ]] || [[ $DISTRO =~ $DEBIAN ]]; then
  216. cd $HOME/openra-master/$PACKAGE && \
  217. make version && \
  218. make dependencies && \
  219. make all [DEBUG=false]
  220. echo -e "$bold_in\n5/7 ***Preparing OpenRA deb package. This takes a while. Please wait.***\n$out"
  221. dh_make --createorig -s -y && \
  222. echo -e "\noverride_dh_auto_install:\n\tmake install-all install-linux-shortcuts prefix='$HOME/openra-master/$PACKAGE/debian/$PACKAGE_NAME/usr'\n\tsed -i '2s%.*%cd /usr/lib/openra%' '$HOME/openra-master/$PACKAGE/debian/$PACKAGE_NAME/usr/bin/openra'\noverride_dh_usrlocal:\noverride_dh_auto_test:" >> $HOME/openra-master/$PACKAGE/debian/rules && \
  223. sed -i 's/Depends: ${shlibs:Depends}, ${misc:Depends}/Depends: libopenal1, mono-runtime (>= 2.10), libmono-system-core4.0-cil, libmono-system-drawing4.0-cil, libmono-system-data4.0-cil, libmono-system-numerics4.0-cil, libmono-system-runtime-serialization4.0-cil, libmono-system-xml-linq4.0-cil, libfreetype6, libc6, libasound2, libgl1-mesa-glx, libgl1-mesa-dri, xdg-utils, zenity, libsdl2 | libsdl2-2.0-0, liblua5.1-0/g' $HOME/openra-master/$PACKAGE/debian/control && \
  224. sed -i 's/<insert up to 60 chars description>/A multiplayer re-envisioning of early RTS games by Westwood Studios\nConflicts: openra, openra-playtest, openra-bleed/g' $HOME/openra-master/$PACKAGE/debian/control && \
  225. sed -i 's/ <insert long description, indented with spaces>/ ./g' $HOME/openra-master/$PACKAGE/debian/control && \
  226. dpkg-buildpackage -rfakeroot -b -nc -uc -us
  227. #*********************************************************************************************************
  228. ## PART 6/7
  229. #
  230. ## Remove temporary OpenRA build files & directories
  231. echo -e "$bold_in\n6/7 ***Compilation process completed. Moving compiled deb package into '$HOME'***\n$out"
  232. sleep 2
  233. mv $HOME/openra-master/$PACKAGE_NAME*.deb $HOME
  234. elif [[ $DISTRO =~ $OPENSUSE ]] || [[ $DISTRO =~ $FEDORA ]]; then
  235. echo -e "$bold_in\n5/7 ***Compiling OpenRA rpm package.***\n$out"
  236. mkdir -p $HOME/openra-master/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
  237. cp ./data/linux/opensuse/openra.spec $HOME/openra-master/rpmbuild/SPECS/
  238. cp ./data/linux/opensuse/{GeoLite2-Country.mmdb.gz,thirdparty.tar.gz} $HOME/openra-master/rpmbuild/SOURCES/
  239. cd $HOME/openra-master
  240. tar -czf $HOME/openra-master/rpmbuild/SOURCES/$PACKAGE.tar.gz ./$PACKAGE
  241. cd $WORKING_DIR
  242. rpmbuild --define "_topdir $HOME/openra-master/rpmbuild" -bb --clean $HOME/openra-master/rpmbuild/SPECS/openra.spec
  243. echo -e "$bold_in\n6/7 ***Compilation process completed. Moving compiled rpm package into '$HOME'***\n$out"
  244. sleep 2
  245. mv $HOME/openra-master/rpmbuild/RPMS/noarch/$PACKAGE_NAME*.rpm $HOME
  246. fi
  247. echo -e "Removing temporary files."
  248. rm -rf $HOME/openra-master
  249. #*********************************************************************************************************
  250. ## PART 7/7
  251. #
  252. ## Install OpenRA
  253. echo -e "$bold_in\n7/7 ***Starting OpenRA installation process***\n$out"
  254. sleep 2
  255. if [[ $DISTRO =~ $UBUNTU ]] || [[ $DISTRO =~ $DEBIAN ]]; then
  256. if [ $PKG4_CHECK -eq 1 ] || [ $PKG5_CHECK -eq 1 ] || [ $PKG6_CHECK -eq 1 ] ; then
  257. echo -e "\nCan't install '$PACKAGE_NAME' because of conflicting packages.\nPlease remove previously installed openra package from your system and try again.\nBuilt $PACKAGE_NAME deb package can be found in '$HOME'.\n"
  258. else
  259. if [[ $number -eq 1 ]]; then
  260. read -r -p "Install '$PACKAGE_NAME' now? [y/N] " response4
  261. if [[ $response4 =~ ^([yY][eE][sS]|[yY])$ ]]; then
  262. sudo dpkg -i $HOME/$PACKAGE_NAME*.deb
  263. else
  264. echo -e "\nPlease install '$PACKAGE_NAME' manually. You find the compiled package in '$HOME'."
  265. sleep 2
  266. fi
  267. else
  268. sudo dpkg -i $HOME/$PACKAGE_NAME*.deb
  269. fi
  270. fi
  271. elif [[ $DISTRO =~ $OPENSUSE ]] || [[ $DISTRO =~ $FEDORA ]]; then
  272. if [ $PKG1_CHECK -eq 1 ] || [ $PKG2_CHECK -eq 1 ] || [ $PKG3_CHECK -eq 1 ] ; then
  273. echo -e "\nCan't install '$PACKAGE_NAME' because of conflicting packages.\nPlease remove previously installed openra package from your system and try again.\nBuilt $PACKAGE_NAME rpm package can be found in '$HOME'.\n"
  274. else
  275. if [[ $number -eq 1 ]]; then
  276. read -r -p "Install '$PACKAGE_NAME' now? [y/N] " response4
  277. if [[ $response4 =~ ^([yY][eE][sS]|[yY])$ ]]; then
  278. if [[ $DISTRO =~ $FEDORA ]]; then
  279. sudo dnf $METHOD --best --allowerasing install $HOME/$PACKAGE_NAME*.rpm
  280. elif [[ $DISTRO =~ $OPENSUSE ]]; then
  281. sudo zypper $METHOD install $HOME/$PACKAGE_NAME*.rpm
  282. fi
  283. else
  284. echo -e "\nPlease install '$PACKAGE_NAME' manually. You find the compiled package in '$HOME'."
  285. sleep 2
  286. fi
  287. else
  288. if [[ $DISTRO =~ $FEDORA ]]; then
  289. sudo dnf $METHOD --best --allowerasing install $HOME/$PACKAGE_NAME*.rpm
  290. elif [[ $DISTRO =~ $OPENSUSE ]]; then
  291. sudo zypper $METHOD install $HOME/$PACKAGE_NAME*.rpm
  292. fi
  293. fi
  294. fi
  295. fi
  296. #*********************************************************************************************************
  297. else
  298. echo -e "\nAborted.\n"
  299. fi