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.

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