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.

321 lines
14 KiB

  1. #!/bin/bash
  2. ##-------------------------------------------------------------
  3. # Allow interruption of the script at any time (Ctrl + C)
  4. trap "exit" INT
  5. ##-------------------------------------------------------------
  6. # 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.
  7. BASH_CHECK=$(ps | grep `echo $$` | awk '{ print $4 }')
  8. if [ ! $BASH_CHECK = "bash" ]; then
  9. echo "
  10. Please run this script using bash (/usr/bin/bash).
  11. "
  12. exit 1
  13. fi
  14. ##-------------------------------------------------------------
  15. # Check if we are root or not. If yes, then terminate the script.
  16. if [[ $UID = 0 ]]; then
  17. 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"
  18. exit 1
  19. fi
  20. ##-------------------------------------------------------------
  21. # Check internet connection
  22. INTERNET_TEST=$(ping -c 3 github.com 2>&1 | grep -c "unknown host") #Ping Github three times and look for string 'unknown host'
  23. if [[ ! $INTERNET_TEST -eq 0 ]]; then #If 'unknown host' string is found, then
  24. echo -e "\nCan't connect to Github. Please check your internet connection and try again.\n"
  25. exit 1
  26. fi
  27. ##-------------------------------------------------------------
  28. # Get our current directory
  29. WORKING_DIR=$(pwd)
  30. # Get our Linux distribution
  31. DISTRO=$(cat /etc/os-release | sed -n '/PRETTY_NAME/p' | grep -o '".*"' | sed -e 's/"//g' -e s/'([^)]*)'/''/g -e 's/ .*//' -e 's/[ \t]*$//')
  32. ARCH="Arch"
  33. UBUNTU="Ubuntu"
  34. DEBIAN="Debian"
  35. OPENSUSE="openSUSE"
  36. FEDORA="Fedora"
  37. ##-------------------------------------------------------------
  38. #Post-installation instructions
  39. bold_in='\e[1m'
  40. dim_in='\e[2m'
  41. green_in='\e[32m'
  42. out='\e[0m'
  43. PACKAGEMANAGER_INSTALL=1
  44. PACKAGEMANAGER_REMOVE=1
  45. PACKAGE_NAME=1
  46. INSTALL_NAME=1
  47. function endtext_fail() {
  48. echo -e "\nWhoops! Something went wrong. Please check possible error messages above.\n"
  49. }
  50. function endtext_ok() {
  51. OPENRA_GITVERSION=git-$(git ls-remote https://github.com/OpenRA/OpenRA.git | head -1 | sed "s/HEAD//" | sed 's/^\(.\{7\}\).*/\1/')
  52. RA2_GITVERSION=git-$(git ls-remote https://github.com/OpenRA/ra2.git | head -1 | sed "s/HEAD//" | sed 's/^\(.\{7\}\).*/\1/')
  53. D2_GITVERSION=git-$(git ls-remote https://github.com/OpenRA/d2.git | head -1 | sed "s/HEAD//" | sed 's/^\(.\{7\}\).*/\1/')
  54. echo -e "$bold_in\n***OpenRA compilation script completed.\nPlease see further instructions below.***$out"
  55. sleep 2
  56. echo -e "$bold_in\n***MANUAL INSTALLATION***$out\n\nInstall OpenRA by typing '$PACKAGEMANAGER_INSTALL $WORKING_DIR/$PACKAGE_NAME' (without quotations) in a terminal window."
  57. sleep 4
  58. echo -e "$bold_in\n***TIBERIAN SUN & RED ALERT 2 - HOWTO***$out\n\nTO PLAY TIBERIAN SUN: Launch the game and download the required asset files from the web when the game asks you to do so.\n\nTO PLAY RED ALERT 2: You must install language.mix, multi.mix, ra2.mix and theme.mix into '$HOME/.openra/Content/ra2/' folder. You find these files from original RA2 installation media (CD's):\n\n-theme.mix, multi.mix = RA2 CD Root folder\n-ra2.mix, language.mix = RA2 CD Root/INSTALL/Game1.CAB (inside that archive file)\n\nTO PLAY DUNE 2 (if installed): Please see https://github.com/Fincer/openra-tibsunra2/ front page for further instructions.$bold_in\n\n***LAUNCHING OPENRA***$out\n\nTo launch OpenRA, simply type 'openra' (without quotations) in your terminal or use a desktop shortcut file.$bold_in\n\n***UNINSTALLATION***$out\n\nIf you want to remove OpenRA, just type '$PACKAGEMANAGER_REMOVE $INSTALL_NAME' (without quotations)\n\nYou can find package of $INSTALL_NAME in '$HOME' for further usage.$bold_in\n\n***MULTIPLAYER***$out\n\nIt's recommended to build OpenRA using exactly same GIT source files for multiplayer usage to minimize possible version differences/conflicts between players. Please make sure all players have exactly same git versions of their in-game mods (RA, CNC, D2, D2K, TS, RA2). Version numbers are formatted like 'git-e0d7445' etc. and can be found in each mod description in the mod selection menu.\n\nFor this compilation, the version numbers are as follows:\nOpenRA version: $OPENRA_GITVERSION\nRA2 version: $RA2_GITVERSION\nDune 2 version (if installed): $D2_GITVERSION\n\nHave fun!\n"
  59. }
  60. ##-------------------------------------------------------------
  61. # If we're running Arch Linux, then execute this
  62. if [[ $DISTRO =~ "$ARCH" ]]; then
  63. echo -e "\n$bold_in***Welcome Comrade*** $out\n"
  64. echo -e "You are about to install OpenRA with Tiberian Sun & Red Alert 2 on Arch Linux.\n"
  65. read -r -p "Do you want to continue? [y/N] " response
  66. if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
  67. echo -e "\nAllright, let's continue. Do you want $bold_in\n\n1.$out manually install OpenRA after its compilation? $dim_in(manual pacman installation)$bold_in\n2.$out automatically install OpenRA after its compilation? $dim_in(pacman -U <compiled_openra_package>)$out\n"
  68. read -r -p "Please type 1 or 2 (Default: 2): " number
  69. sleep 1
  70. rm $WORKING_DIR/data/linux/arch_linux/*.patch
  71. echo -e "\nDune 2 -- Question\n"
  72. read -r -p "Additionally, Dune 2 can be installed, too. Do you want to install it? [y/N] (Default: y) " dune2_install
  73. if [[ ! $dune2_install =~ ^([nN][oO]|[nN])$ ]]; then
  74. #Copy all patch files excluding the one which modifies 'mods' string in the Linux Makefile (double patching it will cause conflicts between D2 and RA2)
  75. cp ./data/patches/linux/*.patch ./data/linux/arch_linux/
  76. rm ./data/linux/arch_linux/linux-ra2-make-modstrings.patch
  77. else
  78. #Copy all patch files excluding the ones for Dune 2.
  79. cp ./data/patches/linux/*.patch ./data/linux/arch_linux/
  80. rm ./data/linux/arch_linux/linux-d2*.patch
  81. fi
  82. if [[ ! $(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | wc -l) -eq 0 ]]; then
  83. echo -e "\nHotfixes -- Question\n"
  84. echo -e "Use custom hotfixes if added by the user (Default: No)?\nNOTE: If you choose YES (y), be aware that your OpenRA/RA2 version will likely not be compatible with the other players unless they've applied exactly same hotfixes in their game versions, too!"
  85. echo -e "\nAvailable hotfixes are:\n"
  86. echo -e $green_in$(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | sed -e 's/.*\///' -e 's/\.[^\.]*$//')$out
  87. echo -e "\nMore information about hotfixes: https://github.com/Fincer/openra-tibsunra2/#about-patches--hotfixes\n"
  88. read -r -p "Use these hotfixes? [y/N] " hotfixes
  89. if [[ $hotfixes =~ ^([nN][oO][nN]|)$ ]]; then
  90. echo -e "\nHotfixes ignored and skipped. Continuing."
  91. elif [[ $hotfixes =~ ^([yY][eE][sS]|[yY])$ ]]; then
  92. cp ./data/hotfixes/linux/*.patch ./data/linux/arch_linux/
  93. echo -e "\nHotfixes applied. Continuing."
  94. else
  95. echo -e "\nHotfixes ignored and skipped. Continuing."
  96. fi
  97. fi
  98. if [[ $number -eq 1 ]]; then
  99. echo -e "\nSelected installation method:$bold_in Manual$out"
  100. else
  101. echo -e "\nSelected installation method:$bold_in Automatic$out"
  102. fi
  103. if [[ $(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | wc -l) -eq 0 ]]; then
  104. echo -e "Available hotfixes:$bold_in None$out"
  105. else
  106. if [[ $hotfixes =~ ^([yY][eE][sS]|[yY])$ ]]; then
  107. echo -e "Use hotfixes:$bold_in Yes$out"
  108. else
  109. echo -e "Use hotfixes:$bold_in No$out"
  110. fi
  111. fi
  112. if [[ ! $dune2_install =~ ^([nN][oO]|[nN])$ ]]; then
  113. echo -e "Install Dune 2:$bold_in Yes$out"
  114. else
  115. echo -e "Install Dune 2:$bold_in No$out"
  116. fi
  117. sleep 3
  118. echo -e "$bold_in\n***Starting OpenRA compilation process.***$out\n"
  119. sleep 2
  120. #Find all old patch occurences in PKGBUILD file and delete them.
  121. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/,/sha1sums/{//!d}' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  122. if [[ ! $(grep -rnw $WORKING_DIR/data/linux/arch_linux/PKGBUILD -e d2.git | wc -l) -eq 0 ]]; then
  123. sed -i '/"git:\/\/github.com\/OpenRA\/d2.git"/d' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  124. cd $WORKING_DIR/data/linux/arch_linux/
  125. patch -Np1 -R < $WORKING_DIR/data/linux/linux-d2-archlinux-pkgbuild.patch 2>/dev/null #Revert Dune 2 special PKGBUILD patch. Silent errors.
  126. cd $WORKING_DIR
  127. fi
  128. sed -i '//i '${PATCHES}')' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  129. #Add Dune 2 to PKGBUILD if it is going to be installed
  130. if [[ ! $dune2_install =~ ^([nN][oO]|[nN])$ ]]; then
  131. #Add Dune 2 sources (PKGBUILD -- source variable) -- Add Dune 2 git source
  132. sed -i '/source=(/a "git:\/\/github.com\/OpenRA\/d2.git"' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  133. #Add Dune 2 specific strings (PKGBUILD) -- Move Dune 2 source files + get version from Github + remove buildtime files
  134. #This is a special patch file used ONLY to patch PKGBUILD file.
  135. cd $WORKING_DIR/data/linux/arch_linux/
  136. patch -Np1 -i $WORKING_DIR/data/linux/linux-d2-archlinux-pkgbuild.patch
  137. cd $WORKING_DIR
  138. fi
  139. #Find all patch files and list them in PKGBUILD
  140. PATCHES=$(find ./data/linux/arch_linux/ -maxdepth 1 -type f -iname "*.patch" | sed -e 's/.*\///' | sed -e ':a;N;$!ba;s/\n/ /g' -e 's/ \+/\\n/g')
  141. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/a '${PATCHES}')' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  142. cd ./data/linux/arch_linux
  143. rm -rf */
  144. if [[ -f $(find $WORKING_DIR/data/linux/arch_linux/ -type f -iname "*.tar.xz") ]]; then
  145. rm $WORKING_DIR/data/linux/arch_linux/*.tar.xz
  146. fi
  147. updpkgsums
  148. makepkg -c
  149. if [[ -f $(find $WORKING_DIR/data/linux/arch_linux/ -type f -iname "*.tar.xz") ]]; then
  150. mv *.tar.xz $WORKING_DIR
  151. else
  152. rm -rf */
  153. rm ./*.patch
  154. rm ./*.orig
  155. find . -name 'sed*' -delete
  156. endtext_fail
  157. exit 1
  158. fi
  159. PACKAGEMANAGER_INSTALL='sudo pacman -U'
  160. PACKAGEMANAGER_REMOVE='sudo pacman -Rs'
  161. INSTALL_NAME=$(sed -n '/pkgname/{p;q;}' ./PKGBUILD | sed -n 's/^pkgname=//p')
  162. PACKAGE_NAME=$(find $WORKING_DIR -maxdepth 1 -type f -iname "$INSTALL_NAME*.tar.xz" | sed -e 's/.*\///')
  163. if [[ ! $number -eq 1 ]]; then
  164. echo -e "$bold_in\n***Installing OpenRA (root password required).***$out\n"
  165. echo -e "NOTE: If the installation fails, this may happen because multiple openra-tibsunra2 tar.xz files have been found in $WORKING_DIR folder.\n"
  166. sleep 2
  167. $PACKAGEMANAGER_INSTALL --noconfirm $WORKING_DIR/$PACKAGE_NAME
  168. echo -e "$bold_in\n***OpenRA installation completed.***$out"
  169. fi
  170. #Find all patch occurences in PKGBUILD file and delete them.
  171. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/,/sha1sums/{//!d}' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  172. sed -i '/"git:\/\/github.com\/OpenRA\/d2.git"/d' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  173. if [[ ! $(grep -rnw $WORKING_DIR/data/linux/arch_linux/PKGBUILD -e d2.git | wc -l) -eq 0 ]]; then
  174. cd $WORKING_DIR/data/linux/arch_linux/
  175. patch -Np1 -R -s < $WORKING_DIR/data/linux/linux-d2-archlinux-pkgbuild.patch 2>/dev/null #Revert Dune 2 special PKGBUILD patch. Silent all messages.
  176. fi
  177. cd $WORKING_DIR/data/linux/arch_linux #Yes, not needed but just makes extra sure we are in the right directory!
  178. rm -rf */ 2>/dev/null
  179. rm ./*.patch 2>/dev/null
  180. rm ./*.orig 2>/dev/null
  181. find . -name 'sed*' -delete 2>/dev/null
  182. cd $WORKING_DIR
  183. if [[ -z $PACKAGE_NAME ]]; then
  184. endtext_fail
  185. exit 1
  186. else
  187. endtext_ok
  188. exit 1
  189. fi
  190. else
  191. echo -e "\nCancelling OpenRA installation.\n"
  192. exit 1
  193. fi
  194. fi
  195. ##-------------------------------------------------------------
  196. # If we're running Ubuntu or Linux Mint or Debian, then execute this
  197. if [[ $DISTRO =~ "$UBUNTU" ]] || [[ $DISTRO =~ "$DEBIAN" ]]; then
  198. if [[ $DISTRO =~ "$DEBIAN" ]]; then
  199. if [[ $(dpkg-query -W sudo 2>/dev/null | wc -l) -eq 0 ]]; then
  200. echo -e "\Please install sudo and add your username to sudo group.\nRun the following commands:\nsu root\nadduser <username> sudo\n\nRe-run this script again then.\nExiting now."
  201. exit 1
  202. fi
  203. fi
  204. bash ./data/linux/openra-installscript.sh
  205. PACKAGEMANAGER_INSTALL='sudo dpkg -i'
  206. PACKAGEMANAGER_REMOVE='sudo apt-get purge --remove'
  207. INSTALL_NAME=$(sed -n '/PACKAGE_NAME/{p;q;}' ./data/linux/openra-installscript.sh | sed -n 's/^PACKAGE_NAME=//p')
  208. PACKAGE_NAME=$(find $HOME -maxdepth 1 -type f -iname "$INSTALL_NAME*.deb" | sed -e 's/.*\///')
  209. if [[ -z $PACKAGE_NAME ]]; then
  210. endtext_fail
  211. if [[ -d $HOME/openra-master ]]; then
  212. echo -e "\n"
  213. read -r -p "Found temporary OpenRA compilation files in $HOME. Remove them now? [y/N] " response2
  214. if [[ $response2 =~ ^([yY][eE][sS]|[yY])$ ]]; then
  215. echo -e "\nDeleting.\n"
  216. rm -Rf $HOME/openra-master
  217. fi
  218. fi
  219. exit 1
  220. else
  221. endtext_ok
  222. exit 1
  223. fi
  224. exit 1
  225. fi
  226. ##-------------------------------------------------------------
  227. # If we're running OpenSUSE or Fedora, then execute this
  228. if [[ $DISTRO =~ "$FEDORA" ]] || [[ $DISTRO =~ "$OPENSUSE" ]]; then
  229. bash ./data/linux/openra-installscript.sh
  230. if [[ $DISTRO =~ "$OPENSUSE" ]]; then
  231. PACKAGEMANAGER_INSTALL='sudo zypper install'
  232. PACKAGEMANAGER_REMOVE='sudo zypper remove'
  233. elif [[ $DISTRO =~ "$FEDORA" ]]; then
  234. PACKAGEMANAGER_INSTALL='sudo dnf install'
  235. PACKAGEMANAGER_REMOVE='sudo dnf remove'
  236. fi
  237. INSTALL_NAME=$(sed -n '/PACKAGE_NAME/{p;q;}' ./data/linux/openra-installscript.sh | sed -n 's/^PACKAGE_NAME=//p')
  238. PACKAGE_NAME=$(find $HOME -maxdepth 1 -type f -iname "$INSTALL_NAME*.rpm" | sed -e 's/.*\///')
  239. if [[ -z $PACKAGE_NAME ]]; then
  240. endtext_fail
  241. if [[ -d $HOME/openra-master ]]; then
  242. echo -e "\n"
  243. read -r -p "Found temporary OpenRA compilation files in $HOME. Remove them now? [y/N] " response3
  244. if [[ $response3 =~ ^([yY][eE][sS]|[yY])$ ]]; then
  245. echo -e "\nDeleting.\n"
  246. rm -Rf $HOME/openra-master
  247. fi
  248. fi
  249. exit 1
  250. else
  251. endtext_ok
  252. exit 1
  253. fi
  254. exit 1
  255. fi
  256. ##-------------------------------------------------------------
  257. # If we don't have any of the supported distributions
  258. if [[ ! $DISTRO =~ "$ARCH" ]] || [[ ! $DISTRO =~ "$UBUNTU" ]] || [[ ! $DISTRO =~ "$DEBIAN" ]] || [[ ! $DISTRO =~ "$OPENSUSE" ]] || [[ ! $DISTRO =~ "$FEDORA" ]]; then
  259. echo "
  260. Your Linux Distribution is not supported. Please consider making a new OpenRA installation script for it.
  261. Supported distributions are: Ubuntu, Linux Mint, Debian, OpenSUSE, Fedora and Arch Linux.
  262. "
  263. exit 1
  264. fi