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.

339 lines
15 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 (Arch Linux: $WORKING_DIR).$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 [[ $(echo $response | sed 's/ //g') =~ ^([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. attempts=5
  70. while [[ ! $(echo $number | sed 's/ //g') -eq 1 && ! $(echo $number | sed 's/ //g') -eq 2 && ! $(echo $number | sed 's/ //g') == "" ]]; do
  71. attempts=$(($attempts -1))
  72. if [[ $attempts -eq 0 ]]; then
  73. echo -e "\nMaximum attempts reached. Aborting.\n"
  74. break
  75. fi
  76. echo -e "\nInvalid answer. Expected number 1 or 2. Please type again ($attempts attempts left):\n"
  77. read number
  78. let number=$(echo $number | sed 's/ //g')
  79. done
  80. if [[ $number == "" ]]; then
  81. let number=2
  82. fi
  83. sleep 1
  84. rm $WORKING_DIR/data/linux/arch_linux/*.patch 2>/dev/null
  85. echo -e "\nDune 2 -- Question\n"
  86. read -r -p "Additionally, Dune 2 can be installed, too. Do you want to install it? [y/N] (Default: y) " dune2_install
  87. if [[ ! $(echo $dune2_install | sed 's/ //g') =~ ^([nN][oO]|[nN])$ ]]; then
  88. #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)
  89. cp ./data/patches/linux/*.patch ./data/linux/arch_linux/
  90. rm ./data/linux/arch_linux/linux-ra2-make.patch
  91. else
  92. #Copy all patch files excluding the ones for Dune 2.
  93. cp ./data/patches/linux/*.patch ./data/linux/arch_linux/
  94. rm ./data/linux/arch_linux/linux-d2*.patch
  95. fi
  96. if [[ ! $(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | wc -l) -eq 0 ]]; then
  97. echo -e "\nHotfixes -- Question\n"
  98. 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!"
  99. echo -e "\nAvailable hotfixes are:\n"
  100. echo -e $green_in$(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | sed -e 's/.*\///' -e 's/\.[^\.]*$//')$out
  101. echo -e "\nMore information about hotfixes: https://github.com/Fincer/openra-tibsunra2/#about-patches--hotfixes\n"
  102. read -r -p "Use these hotfixes? [y/N] " hotfixes
  103. if [[ $(echo $hotfixes | sed 's/ //g') =~ ^([nN][oO][nN]|)$ ]]; then
  104. echo -e "\nHotfixes ignored and skipped. Continuing."
  105. elif [[ $(echo $hotfixes | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
  106. cp ./data/hotfixes/linux/*.patch ./data/linux/arch_linux/
  107. echo -e "\nHotfixes applied. Continuing."
  108. else
  109. echo -e "\nHotfixes ignored and skipped. Continuing."
  110. fi
  111. fi
  112. if [[ $number -eq 1 ]]; then
  113. echo -e "\nSelected installation method:$bold_in Manual$out"
  114. else
  115. echo -e "\nSelected installation method:$bold_in Automatic$out"
  116. fi
  117. if [[ $(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | wc -l) -eq 0 ]]; then
  118. echo -e "Available hotfixes:$bold_in None$out"
  119. else
  120. if [[ $(echo $hotfixes | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
  121. echo -e "Use hotfixes:$bold_in Yes$out"
  122. else
  123. echo -e "Use hotfixes:$bold_in No$out"
  124. fi
  125. fi
  126. if [[ ! $(echo $dune2_install | sed 's/ //g') =~ ^([nN][oO]|[nN])$ ]]; then
  127. echo -e "Install Dune 2:$bold_in Yes$out"
  128. else
  129. echo -e "Install Dune 2:$bold_in No$out"
  130. fi
  131. sleep 3
  132. echo -e "$bold_in\n***Starting OpenRA compilation process.***$out\n"
  133. sleep 2
  134. #Find all old patch occurences in PKGBUILD file and delete them.
  135. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/,/sha1sums/{//!d}' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  136. if [[ ! $(grep -rnw $WORKING_DIR/data/linux/arch_linux/PKGBUILD -e d2.git | wc -l) -eq 0 ]]; then
  137. sed -i '/"git:\/\/github.com\/OpenRA\/d2.git"/d' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  138. cd $WORKING_DIR/data/linux/arch_linux/
  139. patch -Np1 -R < $WORKING_DIR/data/linux/linux-d2-archlinux-pkgbuild.patch 2>/dev/null #Revert Dune 2 special PKGBUILD patch. Silent errors.
  140. cd $WORKING_DIR
  141. fi
  142. sed -i '//i '${PATCHES}')' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  143. #Add Dune 2 to PKGBUILD if it is going to be installed
  144. if [[ ! $(echo $dune2_install | sed 's/ //g') =~ ^([nN][oO]|[nN])$ ]]; then
  145. #Add Dune 2 sources (PKGBUILD -- source variable) -- Add Dune 2 git source
  146. sed -i '/source=(/a "git:\/\/github.com\/OpenRA\/d2.git"' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  147. #Add Dune 2 specific strings (PKGBUILD) -- Move Dune 2 source files + get version from Github + remove buildtime files
  148. #This is a special patch file used ONLY to patch PKGBUILD file.
  149. cd $WORKING_DIR/data/linux/arch_linux/
  150. patch -Np1 -i $WORKING_DIR/data/linux/linux-d2-archlinux-pkgbuild.patch
  151. cd $WORKING_DIR
  152. fi
  153. #Find all patch files and list them in PKGBUILD
  154. 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')
  155. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/a '${PATCHES}')' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  156. cd ./data/linux/arch_linux
  157. rm -rf */
  158. if [[ -f $(find $WORKING_DIR/data/linux/arch_linux/ -type f -iname "*.tar.xz") ]]; then
  159. rm $WORKING_DIR/data/linux/arch_linux/*.tar.xz
  160. fi
  161. updpkgsums
  162. makepkg -c
  163. if [[ -f $(find $WORKING_DIR/data/linux/arch_linux/ -type f -iname "*.tar.xz") ]]; then
  164. mv *.tar.xz $WORKING_DIR
  165. else
  166. rm -rf */
  167. rm ./*.patch
  168. rm ./*.orig
  169. find . -name 'sed*' -delete
  170. endtext_fail
  171. exit 1
  172. fi
  173. PACKAGEMANAGER_INSTALL='sudo pacman -U'
  174. PACKAGEMANAGER_REMOVE='sudo pacman -Rs'
  175. INSTALL_NAME=$(sed -n '/pkgname/{p;q;}' ./PKGBUILD | sed -n 's/^pkgname=//p')
  176. PACKAGE_NAME=$(find $WORKING_DIR -maxdepth 1 -type f -iname "$INSTALL_NAME*.tar.xz" | sed -e 's/.*\///')
  177. if [[ ! $number -eq 1 ]]; then
  178. echo -e "$bold_in\n***Installing OpenRA (root password required).***$out\n"
  179. 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"
  180. sleep 2
  181. $PACKAGEMANAGER_INSTALL --noconfirm $WORKING_DIR/$PACKAGE_NAME
  182. echo -e "$bold_in\n***OpenRA installation completed.***$out"
  183. fi
  184. #Find all patch occurences in PKGBUILD file and delete them.
  185. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/,/sha1sums/{//!d}' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  186. sed -i '/"git:\/\/github.com\/OpenRA\/d2.git"/d' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  187. if [[ ! $(grep -rnw $WORKING_DIR/data/linux/arch_linux/PKGBUILD -e d2.git | wc -l) -eq 0 ]]; then
  188. cd $WORKING_DIR/data/linux/arch_linux/
  189. 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.
  190. fi
  191. cd $WORKING_DIR/data/linux/arch_linux #Yes, not needed but just makes extra sure we are in the right directory!
  192. rm -rf */ 2>/dev/null
  193. rm ./*.patch 2>/dev/null
  194. rm ./*.orig 2>/dev/null
  195. find . -name 'sed*' -delete 2>/dev/null
  196. cd $WORKING_DIR
  197. if [[ -z $PACKAGE_NAME ]]; then
  198. endtext_fail
  199. exit 1
  200. else
  201. endtext_ok
  202. exit 1
  203. fi
  204. elif [[ $(echo $response | sed 's/ //g') =~ ^([nN][oO]|[nN])$ ]]; then
  205. echo -e "\nCancelling OpenRA installation.\n"
  206. exit 1
  207. else
  208. echo -e "\nNot a valid answer. Expected [y/N].\n\nCancelling OpenRA installation.\n"
  209. exit 1
  210. fi
  211. fi
  212. ##-------------------------------------------------------------
  213. # If we're running Ubuntu or Linux Mint or Debian, then execute this
  214. if [[ $DISTRO =~ "$UBUNTU" ]] || [[ $DISTRO =~ "$DEBIAN" ]]; then
  215. if [[ $DISTRO =~ "$DEBIAN" ]]; then
  216. if [[ $(dpkg-query -W sudo 2>/dev/null | wc -l) -eq 0 ]]; then
  217. 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."
  218. exit 1
  219. fi
  220. fi
  221. bash ./data/linux/openra-installscript.sh
  222. PACKAGEMANAGER_INSTALL='sudo dpkg -i'
  223. PACKAGEMANAGER_REMOVE='sudo apt-get purge --remove'
  224. INSTALL_NAME=$(sed -n '/PACKAGE_NAME/{p;q;}' ./data/linux/openra-installscript.sh | sed -n 's/^PACKAGE_NAME=//p')
  225. PACKAGE_NAME=$(find $HOME -maxdepth 1 -type f -iname "$INSTALL_NAME*.deb" | sed -e 's/.*\///')
  226. if [[ -z $PACKAGE_NAME ]]; then
  227. endtext_fail
  228. if [[ -d $HOME/openra-master ]]; then
  229. echo -e "\n"
  230. read -r -p "Found temporary OpenRA compilation files in $HOME. Delete them now? [y/N] " response2
  231. if [[ $(echo $response2 | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
  232. echo -e "\nDeleting.\n"
  233. rm -Rf $HOME/openra-master
  234. fi
  235. fi
  236. exit 1
  237. else
  238. endtext_ok
  239. exit 1
  240. fi
  241. exit 1
  242. fi
  243. ##-------------------------------------------------------------
  244. # If we're running OpenSUSE or Fedora, then execute this
  245. if [[ $DISTRO =~ "$FEDORA" ]] || [[ $DISTRO =~ "$OPENSUSE" ]]; then
  246. bash ./data/linux/openra-installscript.sh
  247. if [[ $DISTRO =~ "$OPENSUSE" ]]; then
  248. PACKAGEMANAGER_INSTALL='sudo zypper install'
  249. PACKAGEMANAGER_REMOVE='sudo zypper remove'
  250. elif [[ $DISTRO =~ "$FEDORA" ]]; then
  251. PACKAGEMANAGER_INSTALL='sudo dnf install'
  252. PACKAGEMANAGER_REMOVE='sudo dnf remove'
  253. fi
  254. INSTALL_NAME=$(sed -n '/PACKAGE_NAME/{p;q;}' ./data/linux/openra-installscript.sh | sed -n 's/^PACKAGE_NAME=//p')
  255. PACKAGE_NAME=$(find $HOME -maxdepth 1 -type f -iname "$INSTALL_NAME*.rpm" | sed -e 's/.*\///')
  256. if [[ -z $PACKAGE_NAME ]]; then
  257. endtext_fail
  258. if [[ -d $HOME/openra-master ]]; then
  259. echo -e "\n"
  260. read -r -p "Found temporary OpenRA compilation files in $HOME. Delete them now? [y/N] " response3
  261. if [[ $(echo $response3 | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
  262. echo -e "\nDeleting.\n"
  263. rm -Rf $HOME/openra-master
  264. fi
  265. fi
  266. exit 1
  267. else
  268. endtext_ok
  269. exit 1
  270. fi
  271. exit 1
  272. fi
  273. ##-------------------------------------------------------------
  274. # If we don't have any of the supported distributions
  275. if [[ ! $DISTRO =~ "$ARCH" ]] || [[ ! $DISTRO =~ "$UBUNTU" ]] || [[ ! $DISTRO =~ "$DEBIAN" ]] || [[ ! $DISTRO =~ "$OPENSUSE" ]] || [[ ! $DISTRO =~ "$FEDORA" ]]; then
  276. echo "
  277. Your Linux Distribution is not supported. Please consider making a new OpenRA installation script for it.
  278. Supported distributions are: Ubuntu, Linux Mint, Debian, OpenSUSE, Fedora and Arch Linux.
  279. "
  280. exit 1
  281. fi