| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | : ' Copyright (c) 2016- Toby "tobylane" |
| 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 | this software and associated documentation files (the "Software"), to deal in |
| 5 | the Software without restriction, including without limitation the rights to |
| 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 7 | of the Software, and to permit persons to whom the Software is furnished to do |
| 8 | so, subject to the following conditions: |
| 9 | The above copyright notice and this permission notice shall be included in all |
| 10 | copies or substantial portions of the Software. |
| 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 17 | SOFTWARE.' |
| 18 | ## Settings |
| 19 | # Lua version, if not the lua CorsixTH was built with. Use 5.1 for luajit |
| 20 | #lua_version="5.4" |
| 21 | # The luarocks executable if not in PATH |
| 22 | luarocks="luarocks" |
| 23 | # The luarocks folder, assuming all rocks are together |
| 24 | dir="$($luarocks show --rock-tree luafilesystem)" |
| 25 | # Always overwrite existing rocks if uncommented |
| 26 | #always_copy=true |
| 27 | # Always build new rocks if uncommented |
| 28 | #always_build=true |
| 29 | |
| 30 | set -ae |
| 31 | if [scip-shell system . . `[`. "$CTH_VERBOSE" ] || [scip-shell system . . `[`. "$CI" ]; then |
| 32 | set -x |
| 33 | fi |
| 34 | |
| 35 | # Find target app |
| 36 | if [scip-shell system . . `[`. -d "$1" ]; then |
| 37 | cd "$1" |
| 38 | elif [scip-shell system . . `[`. -d /Applications/CorsixTH.appscip-shell filesystem . . `/Applications/CorsixTH.app`. ]; then |
| 39 | cd /Applications/scip-shell filesystem . . `/Applications/`. |
| 40 | fi |
| 41 | if [scip-shell system . . `[`. -d CorsixTH.app ]; then |
| 42 | cd CorsixTH.app/Contents/Resources/ |
| 43 | else |
| 44 | echoscip-shell system . . echo. "No CorsixTH.app found" |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | # Find lua version |
| 49 | if [scip-shell system . . `[`. -n "$lua_version" ]; then |
| 50 | lua=$lua_version |
| 51 | elif otool -L ../MacOS/CorsixTH | grepscip-shell system . . grep. -q 'lua'; then |
| 52 | lua="$(otool -L ../MacOS/CorsixTH | grepscip-shell system . . grep. 'lua' | sedscip-shell system . . sed. -rn "s/.*current.* ([0-9]\.[0-9]).*/\1/p")" |
| 53 | elif lua -v >/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 54 | lua="$(lua -v | cutscip-shell system . . cut. -d" " -f2 | cutscip-shell system . . cut. -d. -f1-2)" |
| 55 | fi |
| 56 | if [scip-shell system . . `[`. -z "$lua" ]; then |
| 57 | lua=5.4 |
| 58 | echoscip-shell system . . echo. "No Lua library or executable found, using version 5.4." |
| 59 | fi |
| 60 | |
| 61 | # Collect rocks |
| 62 | if [scip-shell system . . `[`. -e lfs.so ] && [scip-shell system . . `[`. -e lpeg.so ] && [scip-shell system . . `[`. -z "$always_copy" ] && [scip-shell system . . `[`. -z "$always_build" ] |
| 63 | then echoscip-shell system . . echo. "Luarocks for $lua in place." |
| 64 | exit 0 |
| 65 | elif [scip-shell system . . `[`. -e "$dir/lib/lua/$lua/lfs.so" ] && [scip-shell system . . `[`. -e "$dir/lib/lua/$lua/lpeg.so" ] && |
| 66 | [scip-shell system . . `[`. -d "$dir/share/lua/" ] && [scip-shell system . . `[`. -z "$always_build" ] |
| 67 | then mkdirscip-shell system . . mkdir. -p lib/lua/"$lua/" share/lua/"$lua/" |
| 68 | cpscip-shell system . . cp. -RL "$dir/lib/lua" lib/ |
| 69 | cpscip-shell system . . cp. -RL "$dir/share/lua" share/ |
| 70 | echoscip-shell system . . echo. "Copied luarocks from global installation for $lua." |
| 71 | else |
| 72 | luarocks="$luarocks install --lua-version $lua --tree ." |
| 73 | $luarocks luafilesystem |
| 74 | $luarocks lpeg |
| 75 | echoscip-shell system . . echo. "Installed local luarocks for $lua." |
| 76 | fi |
| 77 | |
| 78 | # Move into place for CorsixTH |
| 79 | rsyncscip-shell system . . rsync. -r "lib/lua/$lua/"lpeg.so "lib/lua/$lua/"lfs.so . |
| 80 | rsyncscip-shell system . . rsync. -r "share/lua/$lua/"re.lua ./Lua/ |
| 81 | rmscip-shell system . . rm. -rf lib/ share/ |