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.

272 lines
11 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. echo -e "$bold_in\n***OpenRA compilation script completed.\nPlease see further instructions below.***$out"
  54. sleep 2
  55. 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."
  56. sleep 4
  57. 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)$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, 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\n\nHave fun!\n"
  58. }
  59. ##-------------------------------------------------------------
  60. # If we're running Arch Linux, then execute this
  61. if [[ $DISTRO =~ "$ARCH" ]]; then
  62. echo -e "\n$bold_in***Welcome Comrade*** $out\n"
  63. echo -e "You are about to install OpenRA with Tiberian Sun & Red Alert 2 on Arch Linux.\n"
  64. read -r -p "Do you want to continue? [y/N] " response
  65. if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
  66. 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"
  67. read -r -p "Please type 1 or 2 (Default: 2): " number
  68. sleep 1
  69. rm $WORKING_DIR/data/linux/arch_linux/*.patch
  70. cp ./data/patches/linux/*.patch ./data/linux/arch_linux/
  71. if [[ ! $(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | wc -l) -eq 0 ]]; then
  72. echo -e "\nHotfixes -- Question\n"
  73. 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!"
  74. echo -e "\nAvailable hotfixes are:\n"
  75. echo -e $green_in$(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | sed -e 's/.*\///' -e 's/\.[^\.]*$//')$out
  76. echo -e "\nMore information about hotfixes: https://github.com/Fincer/openra-tibsunra2/#about-patches--hotfixes\n"
  77. read -r -p "Use these hotfixes? [y/N] " hotfixes
  78. if [[ $hotfixes =~ ^([nN][oO][nN]|)$ ]]; then
  79. echo -e "\nHotfixes ignored and skipped. Continuing."
  80. elif [[ $hotfixes =~ ^([yY][eE][sS]|[yY])$ ]]; then
  81. cp ./data/hotfixes/linux/*.patch ./data/linux/arch_linux/
  82. echo -e "\nHotfixes applied. Continuing."
  83. else
  84. echo -e "\nHotfixes ignored and skipped. Continuing."
  85. fi
  86. fi
  87. if [[ $number -eq 1 ]]; then
  88. echo -e "\nSelected installation method:$bold_in Manual$out"
  89. else
  90. echo -e "\nSelected installation method:$bold_in Automatic$out"
  91. fi
  92. if [[ $(find $WORKING_DIR/data/hotfixes/linux/ -type f -iname *.patch | wc -l) -eq 0 ]]; then
  93. echo -e "Available hotfixes:$bold_in None$out"
  94. else
  95. if [[ $hotfixes =~ ^([yY][eE][sS]|[yY])$ ]]; then
  96. echo -e "Use hotfixes:$bold_in Yes$out"
  97. else
  98. echo -e "Use hotfixes:$bold_in No$out"
  99. fi
  100. fi
  101. sleep 3
  102. echo -e "$bold_in\n***Starting OpenRA compilation process.***$out\n"
  103. sleep 2
  104. #Find all old patch occurences in PKGBUILD file and delete them.
  105. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/,/sha1sums/{//!d}' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  106. sed -i '//i '${PATCHES}')' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  107. #Find all patch files and list them in PKGBUILD
  108. 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')
  109. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/a '${PATCHES}')' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  110. cd ./data/linux/arch_linux
  111. rm -rf */
  112. if [[ -f $(find $WORKING_DIR/data/linux/arch_linux/ -type f -iname "*.tar.xz") ]]; then
  113. rm $WORKING_DIR/data/linux/arch_linux/*.tar.xz
  114. fi
  115. updpkgsums
  116. makepkg -c
  117. if [[ -f $(find $WORKING_DIR/data/linux/arch_linux/ -type f -iname "*.tar.xz") ]]; then
  118. mv *.tar.xz $WORKING_DIR
  119. else
  120. rm -rf */
  121. rm ./*.patch
  122. find . -name 'sed*' -delete
  123. endtext_fail
  124. exit 1
  125. fi
  126. PACKAGEMANAGER_INSTALL='sudo pacman -U'
  127. PACKAGEMANAGER_REMOVE='sudo pacman -Rs'
  128. INSTALL_NAME=$(sed -n '/pkgname/{p;q;}' ./PKGBUILD | sed -n 's/^pkgname=//p')
  129. PACKAGE_NAME=$(find $WORKING_DIR -maxdepth 1 -type f -iname "$INSTALL_NAME*.tar.xz" | sed -e 's/.*\///')
  130. if [[ ! $number -eq 1 ]]; then
  131. echo -e "$bold_in\n***Installing OpenRA (root password required).***$out\n"
  132. 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"
  133. sleep 2
  134. $PACKAGEMANAGER_INSTALL --noconfirm $WORKING_DIR/$PACKAGE_NAME
  135. echo -e "$bold_in\n***OpenRA installation completed.***$out"
  136. fi
  137. #Find all patch occurences in PKGBUILD file and delete them.
  138. sed -i '/"git:\/\/github.com\/OpenRA\/ra2.git"/,/sha1sums/{//!d}' $WORKING_DIR/data/linux/arch_linux/PKGBUILD
  139. rm -rf */
  140. rm ./*.patch
  141. find . -name 'sed*' -delete
  142. cd $WORKING_DIR
  143. if [[ -z $PACKAGE_NAME ]]; then
  144. endtext_fail
  145. exit 1
  146. else
  147. endtext_ok
  148. exit 1
  149. fi
  150. else
  151. echo -e "\nCancelling OpenRA installation.\n"
  152. exit 1
  153. fi
  154. fi
  155. ##-------------------------------------------------------------
  156. # If we're running Ubuntu or Linux Mint or Debian, then execute this
  157. if [[ $DISTRO =~ "$UBUNTU" ]] || [[ $DISTRO =~ "$DEBIAN" ]]; then
  158. if [[ $DISTRO =~ "$DEBIAN" ]]; then
  159. if [[ $(dpkg-query -W sudo 2>/dev/null | wc -l) -eq 0 ]]; then
  160. 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."
  161. exit 1
  162. fi
  163. fi
  164. bash ./data/linux/openra-installscript.sh
  165. PACKAGEMANAGER_INSTALL='sudo dpkg -i'
  166. PACKAGEMANAGER_REMOVE='sudo apt-get purge --remove'
  167. INSTALL_NAME=$(sed -n '/PACKAGE_NAME/{p;q;}' ./data/linux/openra-installscript.sh | sed -n 's/^PACKAGE_NAME=//p')
  168. PACKAGE_NAME=$(find $HOME -maxdepth 1 -type f -iname "$INSTALL_NAME*.deb" | sed -e 's/.*\///')
  169. if [[ -z $PACKAGE_NAME ]]; then
  170. endtext_fail
  171. if [[ -d $HOME/openra-master ]]; then
  172. echo -e "\n"
  173. read -r -p "Found temporary OpenRA compilation files in $HOME. Remove them now? [y/N] " response2
  174. if [[ $response2 =~ ^([yY][eE][sS]|[yY])$ ]]; then
  175. echo -e "\nDeleting.\n"
  176. rm -Rf $HOME/openra-master
  177. fi
  178. fi
  179. exit 1
  180. else
  181. endtext_ok
  182. exit 1
  183. fi
  184. exit 1
  185. fi
  186. ##-------------------------------------------------------------
  187. # If we're running OpenSUSE or Fedora, then execute this
  188. if [[ $DISTRO =~ "$FEDORA" ]] || [[ $DISTRO =~ "$OPENSUSE" ]]; then
  189. bash ./data/linux/openra-installscript.sh
  190. if [[ $DISTRO =~ "$OPENSUSE" ]]; then
  191. PACKAGEMANAGER_INSTALL='sudo zypper install'
  192. PACKAGEMANAGER_REMOVE='sudo zypper remove'
  193. elif [[ $DISTRO =~ "$FEDORA" ]]; then
  194. PACKAGEMANAGER_INSTALL='sudo dnf install'
  195. PACKAGEMANAGER_REMOVE='sudo dnf remove'
  196. fi
  197. INSTALL_NAME=$(sed -n '/PACKAGE_NAME/{p;q;}' ./data/linux/openra-installscript.sh | sed -n 's/^PACKAGE_NAME=//p')
  198. PACKAGE_NAME=$(find $HOME -maxdepth 1 -type f -iname "$INSTALL_NAME*.rpm" | sed -e 's/.*\///')
  199. if [[ -z $PACKAGE_NAME ]]; then
  200. endtext_fail
  201. if [[ -d $HOME/openra-master ]]; then
  202. echo -e "\n"
  203. read -r -p "Found temporary OpenRA compilation files in $HOME. Remove them now? [y/N] " response3
  204. if [[ $response3 =~ ^([yY][eE][sS]|[yY])$ ]]; then
  205. echo -e "\nDeleting.\n"
  206. rm -Rf $HOME/openra-master
  207. fi
  208. fi
  209. exit 1
  210. else
  211. endtext_ok
  212. exit 1
  213. fi
  214. exit 1
  215. fi
  216. ##-------------------------------------------------------------
  217. # If we don't have any of the supported distributions
  218. if [[ ! $DISTRO =~ "$ARCH" ]] || [[ ! $DISTRO =~ "$UBUNTU" ]] || [[ ! $DISTRO =~ "$DEBIAN" ]] || [[ ! $DISTRO =~ "$OPENSUSE" ]] || [[ ! $DISTRO =~ "$FEDORA" ]]; then
  219. echo "
  220. Your Linux Distribution is not supported. Please consider making a new OpenRA installation script for it.
  221. Supported distributions are: Ubuntu, Linux Mint, Debian, OpenSUSE, Fedora and Arch Linux.
  222. "
  223. exit 1
  224. fi