|
| 1 | +#!/bin/bash |
| 2 | +#----------------------------------------------------------- |
| 3 | +# Detect architecture. In the case of OSX force it to x86_64 |
| 4 | +# otherwise let uname -m do it. |
| 5 | +#----------------------------------------------------------- |
| 6 | +architecture=`uname -s` # computer type e.g. Linux Darwin SunOS |
| 7 | +if [ "$architecture" = "Darwin" ]; then |
| 8 | + machine="x86_64" |
| 9 | +else |
| 10 | + machine=`uname -m` # CPU e.g. i386 x86_64 sun4u |
| 11 | +fi |
| 12 | +platform="auto-detect" # default platform |
| 13 | + |
| 14 | +#----------------------------------------------------------- |
| 15 | +# If auto-detection is active, interpret architecture |
| 16 | +#----------------------------------------------------------- |
| 17 | +if [ "$platform" = "auto-detect" ]; then |
| 18 | + # Add more architectures here as they become available. |
| 19 | + # Note: $architecture has been error-trapped above. |
| 20 | + case $architecture in |
| 21 | + Linux) platform="linux";; |
| 22 | + CYGWIN_NT-5.2 | CYGWIN_NT-5.1 | CYGWIN_NT-5.0 | CYGWIN_NT-6.0 | CYGWIN_NT-6.1 | CYGWIN_NT-6.1-WOW64 | CYGWIN_NT-10.0) platform="cygwin";; |
| 23 | + MINGW64_NT-10.0 |MINGW64_NT-6.1 |MINGW32_NT-6.1 | MINGW32_NT-5.2 | MINGW32_NT-5.1 | MSYS_NT-6.1 ) platform="mingw";; |
| 24 | + Darwin) platform="mac";; |
| 25 | + esac |
| 26 | +fi |
| 27 | + |
| 28 | +echo " "; |
| 29 | +echo "This script grabs the cutting-edge ESP-r repositories from Github, assembles"; |
| 30 | +echo "them for compiling and then, optionally, invokes the ESP-r Install script"; |
| 31 | +echo "to build ESP-r, its databases, exemplar models and places the distribution"; |
| 32 | +if [ "$platform" = "linux" ] || |
| 33 | + [ "$platform" = "cygwin" ] ; then |
| 34 | + echo "in a standard location on Linux based computers (/opt/esru)."; |
| 35 | +fi |
| 36 | +if [ "$platform" = "mac" ] ; then |
| 37 | + echo "in a standard location on OSX based computers (/opt/esru)."; |
| 38 | +fi |
| 39 | +if [ "$platform" = "mingw" ] ; then |
| 40 | + echo "in a standard location on Windows 7/10 computers (C:/ESRU)."; |
| 41 | + echo "when building within MSYS2 command window."; |
| 42 | +fi |
| 43 | +echo " "; |
| 44 | +echo "The script will create esru and an esru/tmp folders within the folder"; |
| 45 | +echo "where it is currently located. The assembled sources will be found in"; |
| 46 | +echo "a folder ESP-rMaster and the ESP-r distribution (executables, databases,"; |
| 47 | +echo "exemplars, and documentation) will be placed in /opt/esru and links"; |
| 48 | +if [ "$platform" = "linux" ] || |
| 49 | + [ "$platform" = "cygwin" ] ; then |
| 50 | + echo "to ESP-r executables will be placed in /usr/bin so that"; |
| 51 | + echo "they will be easily found by the operating system."; |
| 52 | +fi |
| 53 | +if [ "$platform" = "mac" ] ; then |
| 54 | + echo "to ESP-r executables will be placed in $HOME/bin so that"; |
| 55 | + echo "they will be easily found by the operating system."; |
| 56 | +fi |
| 57 | +if [ "$platform" = "mingw" ] ; then |
| 58 | + echo "The $PATH environment variable will be updated."; |
| 59 | +fi |
| 60 | + |
| 61 | +echo " "; |
| 62 | +echo "The script begins by checking for dependencies (e.g. gcc g++ gfortran"; |
| 63 | +echo "compilers and a git client). If they are not found you will need to"; |
| 64 | +echo "install these. You also need to have root permissions to run the script"; |
| 65 | +echo "(use sudo)."; |
| 66 | +echo " "; |
| 67 | +echo "The script will replace any existing ESP-r distribution so backup or"; |
| 68 | +echo "move anything in /opt/esru before you proceed. It will use typical"; |
| 69 | +echo "assumptions when invoking the ESP-r Install script (you have the"; |
| 70 | +echo "option to run Install manually). "; |
| 71 | +echo " "; |
| 72 | + |
| 73 | +echo "Proceed with these tasks?"; |
| 74 | +YN=none; |
| 75 | +while [ "$YN" != "y" ] && [ "$YN" != "n" ] && [ "$YN" != "" ] |
| 76 | +do |
| 77 | + if [ "$YN" != "none" ]; then |
| 78 | + echo " "; |
| 79 | + echo "Please answer yes or no (y/n) [y]."; |
| 80 | + fi |
| 81 | + read YN |
| 82 | +done |
| 83 | + |
| 84 | +if [ "$YN" = "n" ]; then |
| 85 | + # tell user to run Install manually. |
| 86 | + echo "Exiting the script."; |
| 87 | + exit; |
| 88 | +fi |
| 89 | + |
| 90 | +if [ "$platform" = "linux" ] || |
| 91 | + [ "$platform" = "mac" ] ; then |
| 92 | + echo "Step 0 Are you root?"; |
| 93 | + if [[ $EUID -ne 0 ]]; then |
| 94 | + echo "This script must be run as root, use sudo ./download_and_install_ESP-r.bash"; |
| 95 | + echo "... aborting"; |
| 96 | + exit; |
| 97 | + fi |
| 98 | + echo "Step 0 Are you root? ... DONE"; |
| 99 | +fi |
| 100 | +echo " "; |
| 101 | +echo "Step 1 Check for dependencies"; |
| 102 | + |
| 103 | +# Check for dependencies |
| 104 | +for SWARE in git gcc g++ gfortran rsync make |
| 105 | +do |
| 106 | + SWARE_PRESENT=`which $SWARE`; |
| 107 | + if [ -z "$SWARE_PRESENT" ]; then # check if string is not empty |
| 108 | + echo "ERROR: Install $SWARE before continuing ... aborting"; |
| 109 | + exit; |
| 110 | + else |
| 111 | + echo " Using $SWARE present at $SWARE_PRESENT"; |
| 112 | + fi |
| 113 | +done |
| 114 | + |
| 115 | +if [ "$platform" = "mac" ] ; then |
| 116 | + if [ -d "/opt/local/bin" ]; then |
| 117 | + echo " "; |
| 118 | + echo "Looks like you are using the MacPorts package manager so you will need to"; |
| 119 | + echo "use the --compiler_version option and run the Install script manually."; |
| 120 | + echo "looks like the available GNU compilers are:"; |
| 121 | + ls -l /opt/local/bin/gcc-m* |
| 122 | + ls -l /opt/local/bin/g++-m* |
| 123 | + ls -l /opt/local/bin/gfortran-m* |
| 124 | + echo "to find out more about Install command line options do a ./Install -h"; |
| 125 | + else |
| 126 | + if [ -d "/usr/local/Homebrew" ]; then |
| 127 | + echo " "; |
| 128 | + echo "Looks like you are using the Homebrew package manager. If the compilers"; |
| 129 | + echo "were found then you will need to use the --compiler_version -6 option when"; |
| 130 | + echo "invoking the Install command line."; |
| 131 | + else |
| 132 | + echo "Did not find MacPorts or Homebrew. If you are using something else"; |
| 133 | + echo "proceed with caution."; |
| 134 | + fi |
| 135 | + fi |
| 136 | + if [ ! -d "/Applications/Xcode.app" ]; then |
| 137 | + SWARE_PRESENT=`which make`; |
| 138 | + if [ -z "$SWARE_PRESENT" ]; then # check if string is not empty |
| 139 | + echo "ERROR: Install command line tools for XCode before continuing ... aborting"; |
| 140 | + exit; |
| 141 | + else |
| 142 | + echo " Using $SWARE present at $SWARE_PRESENT"; |
| 143 | + echo " So assuming a development tool-chain is present."; |
| 144 | + fi |
| 145 | + fi |
| 146 | +fi |
| 147 | + |
| 148 | +echo "Step 1 Check for dependencies ... DONE"; |
| 149 | +echo " "; |
| 150 | + |
| 151 | +echo "Step 2 Downloading source and checking out latest..."; |
| 152 | +# clone git repositories into esru/tmp |
| 153 | +if [ ! -d "esru" ]; then |
| 154 | + mkdir esru |
| 155 | +fi |
| 156 | +if [ ! -d "esru/tmp" ]; then |
| 157 | + mkdir esru/tmp |
| 158 | +else |
| 159 | + rm -rf esru/tmp/ESP-r* |
| 160 | +fi |
| 161 | +echo " "; |
| 162 | +git clone --recursive https://github.com/ESP-rCommunity/ESP-rSource.git esru/tmp/ESP-rSource |
| 163 | +echo " "; |
| 164 | +git clone --recursive https://github.com/ESP-rCommunity/ESP-rDatabases.git esru/tmp/ESP-rDatabases |
| 165 | +echo " "; |
| 166 | +git clone --recursive https://github.com/ESP-rCommunity/ESP-rModels.git esru/tmp/ESP-rModels |
| 167 | +echo " "; |
| 168 | +git clone --recursive https://github.com/ESP-rCommunity/ESP-rDoc.git esru/tmp/ESP-rDoc |
| 169 | +echo "Step 2 Downloading source...PASSED"; |
| 170 | +echo " "; |
| 171 | + |
| 172 | +# Copy the individual repositories to standard locations for Install script to work |
| 173 | +echo "Step 3 Assembling repositories into ESP-rMaster folders..."; |
| 174 | +if [ ! -d "ESP-rMaster" ]; then |
| 175 | + mkdir ESP-rMaster |
| 176 | +else |
| 177 | + rm -rf ESP-rMaster/* |
| 178 | +fi |
| 179 | +rsync -a esru/tmp/ESP-rSource/ ESP-rMaster/ |
| 180 | +rsync -a esru/tmp/ESP-rDatabases/ ESP-rMaster/data/ |
| 181 | +rsync -a esru/tmp/ESP-rDoc/ ESP-rMaster/doc/ |
| 182 | +rsync -a esru/tmp/ESP-rModels/ ESP-rMaster/models/ |
| 183 | +rm -rf ESP-rMaster/*/.git* |
| 184 | +echo "Step 3 Assembling repositories into ESP-rMaster folders... DONE"; |
| 185 | +echo " "; |
| 186 | + |
| 187 | +echo "Step 4 Install ESP-r distribution..."; |
| 188 | +if [ "$platform" = "linux" ] || |
| 189 | + [ "$platform" = "cygwin" ] || |
| 190 | + [ "$platform" = "mac" ] ; then |
| 191 | + if [ ! -d "/opt" ]; then |
| 192 | + mkdir /opt |
| 193 | + fi |
| 194 | + if [ ! -d "/opt/esru" ]; then |
| 195 | + mkdir /opt/esru |
| 196 | + else |
| 197 | + rm -rf /opt/esru/* |
| 198 | + fi |
| 199 | +fi |
| 200 | +if [ "$platform" = "mingw" ] ; then |
| 201 | + if [ ! -d "C:/ESRU" ]; then |
| 202 | + mkdir C:/ESRU |
| 203 | + echo "The $PATH environment variable will be updated."; |
| 204 | + else |
| 205 | + rm -rf C:/ESRU/* |
| 206 | + fi |
| 207 | +fi |
| 208 | + |
| 209 | +cd ESP-rMaster |
| 210 | +# Confirm running Install script. |
| 211 | +echo " "; |
| 212 | +echo "The default Install script parameters will be:"; |
| 213 | +if [ "$platform" = "linux" ] || |
| 214 | + [ "$platform" = "cygwin" ] ; then |
| 215 | + echo "./Install_o2 -d /opt/esru --debug --X11 --gcc4 --silent --force"; |
| 216 | +fi |
| 217 | +if [ "$platform" = "mac" ] ; then |
| 218 | + if [ -d "/usr/local/Homebrew" ]; then |
| 219 | + echo "Suggest invoking Install with --compiler_version -6 "; |
| 220 | + echo "./Install_o2 -d /opt/esru --debug --X11 --gcc4 --silent --force --compiler_version -6"; |
| 221 | + else |
| 222 | + echo "Suggest invoking Install with --compile_version -mp-5 "; |
| 223 | + echo "./Install_o2 -d /opt/esru --debug --X11 --gcc4 --silent --force --compiler_version -mp-5"; |
| 224 | + fi |
| 225 | +fi |
| 226 | +if [ "$platform" = "mingw" ] ; then |
| 227 | + echo "./Install_o2 -d C:/ESRU --debug --GTK --gcc4"; |
| 228 | +fi |
| 229 | +echo "and all databases and exemplars will be installed."; |
| 230 | +echo "To find out more about Install command line options do a ./Install -h"; |
| 231 | +if [ "$platform" = "mac" ] ; then |
| 232 | + echo "For OSX we suggest manual invocation of the Install script."; |
| 233 | +fi |
| 234 | +echo " "; |
| 235 | +echo "Proceed with running the ESP-r Install script? A no allows you"; |
| 236 | +echo "to invoke Install script manually."; |
| 237 | +YN=none; |
| 238 | +while [ "$YN" != "y" ] && [ "$YN" != "n" ] && [ "$YN" != "" ] |
| 239 | +do |
| 240 | + if [ "$YN" != "none" ]; then |
| 241 | + echo " " |
| 242 | + echo "Please answer yes or no (y/n) [y]." |
| 243 | + fi |
| 244 | + read YN |
| 245 | +done |
| 246 | + |
| 247 | +if [ "$YN" = "n" ]; then |
| 248 | + # tell user to run Install manually. |
| 249 | + echo "Manually run the Install script with your own options e.g."; |
| 250 | + echo "cd ESP-rMaster"; |
| 251 | + echo "sudo ./Install -d /opt/esru --debug --gcc4"; |
| 252 | + echo "and then manually remove the esru and esru/tmp folders."; |
| 253 | + if [ "$platform" = "mingw" ] ; then |
| 254 | + echo "After compiling you should also run the copy_dll_to_c_esru_esp-r_bin.bash"; |
| 255 | + echo "command in the ESPrMaster folder to place dependencies in the"; |
| 256 | + echo "C:/ESRU/esp-r/bin folder."; |
| 257 | + fi |
| 258 | + exit; |
| 259 | +fi |
| 260 | + |
| 261 | +if [ "$platform" = "linux" ] || |
| 262 | + [ "$platform" = "cygwin" ] ; then |
| 263 | + ./Install_o1 -d /opt/esru --debug --X11 --gcc4 --silent --force |
| 264 | +fi |
| 265 | +if [ "$platform" = "mac" ] ; then |
| 266 | + if [ -d "/usr/local/Homebrew" ]; then |
| 267 | + ./Install_o1 -d /opt/esru --debug --X11 --gcc4 --silent --force --compiler_version -6 |
| 268 | + else |
| 269 | + ./Install_o1 -d /opt/esru --debug --X11 --gcc4 --silent --force --compiler_version -mp-5 |
| 270 | + fi |
| 271 | +fi |
| 272 | +if [ "$platform" = "mingw" ] ; then |
| 273 | + echo "For MSYS2 say no to XML output, choose GTK, say yes to databases and models."; |
| 274 | + ./Install_o2 -d C:/ESRU --debug --GTK --gcc4 |
| 275 | + echo " "; |
| 276 | + echo "After compiling you should also run the copy_dll_to_c_esru_esp-r_bin.bash"; |
| 277 | + echo "command in the ESPrMaster folder to place dependencies in the"; |
| 278 | + echo "C:/ESRU/esp-r/bin folder."; |
| 279 | + echo "Do this BEFORE you clean up the folders!"; |
| 280 | + echo " "; |
| 281 | +fi |
| 282 | +echo " "; |
| 283 | +echo "Step 4 Install ESP-r distribution... DONE"; |
| 284 | +echo " "; |
| 285 | + |
| 286 | +echo "Step 5 Add executable links in /usr/bin so bash shell can find stuff"; |
| 287 | +if [ "$platform" = "mac" ] ; then |
| 288 | + if [ ! -d "$HOME/bin" ]; then |
| 289 | + mkdir $HOME/bin |
| 290 | + fi |
| 291 | +fi |
| 292 | +for executable in aco b2e bps dbm dfs cdb c2e clm e2r ecnv eco enet grd ish mfs mld mrt pdb prj res stats vew |
| 293 | +do |
| 294 | + if [ "$platform" = "linux" ] || |
| 295 | + [ "$platform" = "cygwin" ] ; then |
| 296 | + ln -s /opt/esru/esp-r/bin/$executable /usr/bin/$executable |
| 297 | + fi |
| 298 | + if [ "$platform" = "mac" ] ; then |
| 299 | + ln -s /opt/esru/esp-r/bin/$executable /$HOME/bin/$executable |
| 300 | + fi |
| 301 | +done |
| 302 | +echo " "; |
| 303 | +echo "Step 6 Cleaning object files from the compile in ESPrMaster ..."; |
| 304 | +echo " "; |
| 305 | +cd src |
| 306 | +make clean |
| 307 | + |
| 308 | +echo " "; |
| 309 | +echo "Step 7 Cleaning downloaded repositories (in esru/tmp) ..."; |
| 310 | +echo "[say n if you want to do this yourself]"; |
| 311 | +echo "Proceed with these tasks?"; |
| 312 | +YN=none; |
| 313 | +while [ "$YN" != "y" ] && [ "$YN" != "n" ] && [ "$YN" != "" ] |
| 314 | +do |
| 315 | + if [ "$YN" != "none" ]; then |
| 316 | + echo " "; |
| 317 | + echo "Please answer yes or no (y/n) [y]."; |
| 318 | + fi |
| 319 | + read YN |
| 320 | +done |
| 321 | + |
| 322 | +if [ "$YN" = "n" ]; then |
| 323 | + # tell user to cleanup manually. |
| 324 | + echo "Manually cleanup the folders esru and esru/tmp"; |
| 325 | + exit; |
| 326 | +else |
| 327 | +# At the end remove temporary files and folders |
| 328 | + cd .. |
| 329 | + rm -rf esru/tmp/* |
| 330 | + rm -rf esru/* |
| 331 | +fi |
| 332 | + |
| 333 | + |
| 334 | +# Check that prj can be found. |
| 335 | +PRJ_PRESENT=`which prj`; |
| 336 | +if [ -z "$PRJ_PRESENT" ]; then # check if string is not empty |
| 337 | + echo "ERROR: ESP-r Project Manager not yet found - check paths."; |
| 338 | +else |
| 339 | + echo "Checking ESP-r Project Manager is present at $PRJ_PRESENT"; |
| 340 | + echo "looks like you are good to go!"; |
| 341 | +fi |
0 commit comments