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.

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