├── .gitignore ├── LICENSE ├── README.md ├── build.sbt ├── project ├── build.properties └── plugins.sbt └── sbtw /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.class 3 | \#*\# 4 | \.\#* 5 | **/target/** 6 | .DS_Store 7 | tmp/* 8 | sbt-ethereum.log* 9 | 10 | 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | # The launcher shell script 'eth-command-line' is taken almost entirely from 2 | # 3 | # https://github.com/paulp/sbt-extras/blob/715a3a8ba9bf16796eee0b034143acb4594c1d2d/sbt 4 | # 5 | # (C) 2018, Paul Phillips. All Rights Reserved. 6 | # 7 | # and is distributed here under its original (BSD) license: 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are 11 | # met: 12 | # 13 | # * Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | # * Neither the name of the author nor the names of its contributors 19 | # may be used to endorse or promote products derived from this software 20 | # without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28 | # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | # All other work in this distribution, and derivations of the launcher, are 35 | # 36 | # (C) 2018 Machinery For Change, Inc. All Rights Reserved. 37 | # 38 | # and distributed under the same BSD licence, reproduced redundantly below. 39 | # 40 | # Redistribution and use in source and binary forms, with or without 41 | # modification, are permitted provided that the following conditions are 42 | # met: 43 | # 44 | # * Redistributions of source code must retain the above copyright 45 | # notice, this list of conditions and the following disclaimer. 46 | # * Redistributions in binary form must reproduce the above copyright 47 | # notice, this list of conditions and the following disclaimer in the 48 | # documentation and/or other materials provided with the distribution. 49 | # * Neither the name of the author nor the names of its contributors 50 | # may be used to endorse or promote products derived from this software 51 | # without specific prior written permission. 52 | # 53 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 54 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 55 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 56 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 57 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 58 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 59 | # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 60 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 61 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 62 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 63 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 | 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eth-command-line 2 | 3 | **An instant-gratification command line for interacting with ethereum smart-contracts and accounts** 4 | 5 | * [Prerequisites](#prerequisites) 6 | * [Quick\-Start](#quick-start) 7 | * [Introduction](#introduction) 8 | * [Quick Example: Import a contract ABI and call a constant method of a smart contract to check its state](#quick-example-import-a-contract-abi-and-call-a-constant-method-of-a-smart-contract-to-check-its-state) 9 | * [Tab completion is your friend\.](#tab-completion-is-your-friend) 10 | * [Upgrade / Downgrade](#upgrade--downgrade) 11 | * [RTFM](#rtfm) 12 | 13 | ## Prerequisites 14 | 15 | You need a Java runtime environment installed on your machine. If you don't 16 | already have one, you can download a [JRE](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html) 17 | (or a full [Java Development Kit](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)) 18 | from Oracle. 19 | 20 | `eth-command-line` will run [under Java 8 or Java 11](https://www.sbt-ethereum.io/appendix/prerequisites.html#java-8-or-11-runtime). 21 | 22 | ## Quick-Start 23 | 24 | 1. Clone or download this project 25 | 2. In the top-level project directory, make sure that the shell script `eth-command-line` has 26 | execute permissions. (If not, on a Unix-like system, type `chmod +x ./eth-command-line`) 27 | 3. Execute the shell script `eth-command-line`. The first time you do this, a whole bunch of 28 | downloads will likely be triggered 29 | 4. At the prompt, you can begin typing ethereum-related command. To see a list 30 | of all commands, type `eth`. To see a description of all commands, type `tasks -V eth` 31 | 32 | _Note: `sbt-ethereum` commands are really verbose! They are not intended to be typed. Use the key, Luke! 33 | For example, to enter `ethKeystoreWalletV3Create` (yuk, right?), just type `etKWC`. 34 | Another way of visualizing this is_ **et**h**K**eystore**W**alletV3**C**reate. _Only the keys in bold 35 | need to be typed, the rest get taken care of by ``. `sbt-ethereum` tries very hard to require 36 | very few non-`` keypresses, usually just one capital letter takes you down a level of its hierarchically 37 | organized commands._ 38 | 39 | 40 | 5. For operations that require the payment of Ether, such as sending ether (`ethTransactionEtherSend`) or 41 | invoking state-changing smart-contract methods (`ethTransactionInvoke`), you will need to define the 42 | ethereum address from which the operation will originate. You can create a new address using 43 | `ethKeystoreWalletV3Create` command. 44 | ``` 45 | sbt:eth-command-line> ethKeystoreWalletV3Create 46 | [info] Generated keypair for address '0xe10280702f233573b2dca5a81bda8dd3a0867fcc' 47 | [info] Generating V3 wallet, alogorithm=scrypt, n=262144, r=8, p=1, dklen=32 48 | Enter passphrase for new wallet: ******************* 49 | Please retype to confirm: ******************* 50 | [success] Total time: 30 s, completed Feb 23, 2018 6:50:33 PM 51 | 52 | ``` 53 | You can also import existing `geth` wallets into the `sbt-ethereum` repository directory. 54 | See the [sbt-ethereum docs](https://github.com/swaldman/sbt-ethereum/blob/master/README.md). 55 | 56 | **Be sure to back up your `sbt-ethereum` repository directory to avoid losing your wallets and accounts!** 57 | 58 | ...but using your own Ethereum address of course! 59 | 60 | 61 | ## Introduction 62 | 63 | `eth-command-line` is just a thin wrapper around [sbt-ethereum](https://www.sbt-ethereum.io/). 64 | 65 | To use _sbt-ethereum_, you have to go through 66 | the ceremony of setting up a project directory and run a synced ethereum node. This project takes care of that for you. 67 | 68 | In order for the instant gratification thing to work, _sbt-ethereum_ may be preconfigured to interact with a public 69 | _ethereum_ node. **No guarantees are 70 | made about how long this Ethereum node will be exposed for public use!** It's best to [get access to a more reliable 71 | node, and define that as your default node URL](https://www.sbt-ethereum.io/tutorials/getting-started.html#connect-to-a-node). 72 | 73 | ### Quick Example: Import a contract ABI and call a constant method of a smart contract to check its state 74 | 75 | ``` 76 | sbt:eth-command-line> ethContractAbiImport 77 | Contract address in hex: 0x82ea8ab1e836272322f376a5f71d5a34a71688f1 78 | Contract ABI: [{"outputs":[],"constant":false,"payable":false,"inputs":[{"name":"fortune","type":"string"}],"name":"addFortune","stateMutability":"nonpayable","type":"function"},{"outputs":[{"name":"count","type":"uint256"}],"constant":true,"payable":false,"inputs":[],"name":"countFortunes","stateMutability":"view","type":"function"},{"outputs":[{"name":"fortune","type":"string"}],"constant":true,"payable":false,"inputs":[],"name":"drawFortune","stateMutability":"view","type":"function"},{"outputs":[{"name":"","type":"string"}],"constant":true,"payable":false,"inputs":[{"name":"","type":"uint256"}],"name":"fortunes","stateMutability":"view","type":"function"},{"inputs":[{"name":"author","type":"address","indexed":false},{"name":"fortune","type":"string","indexed":false}],"name":"FortuneAdded","anonymous":false,"type":"event"},{"payable":false,"inputs":[{"name":"initialFortune","type":"string"}],"stateMutability":"nonpayable","type":"constructor"}] 79 | [info] ABI is now known for the contract at address '0x82ea8ab1e836272322f376a5f71d5a34a71688f1' 80 | [success] Total time: 37 s, completed Dec 29, 2016 9:33:13 AM 81 | sbt:eth-command-line> ethTransactionView 0x57d0dfa84161e565c9f9ba4aab24d6b22654cca1 sayHello 82 | [info] The function 'sayHello' yields 1 result. 83 | [info] + Result 1 of type 'string' is "Hello, world!!!" 84 | [success] Total time: 1 s, completed Feb 23, 2018 6:59:28 PM 85 | ``` 86 | 87 | ## Tab completion is your friend. 88 | 89 | If you try to type everything in, you will find this to be an annoyingly verbose 90 | command line interface. `eth-command-line` tasks support completion *extensively*. **When in doubt, just hit 91 | a few times in quick succession, and maybe things will get clearer.** 92 | 93 | ## Upgrade / Downgrade 94 | 95 | To upgrade (or downgrade) versions of _sbt-ethereum_, just run 96 | 97 | ``` 98 | $ cd eth-command-line 99 | $ git fetch 100 | $ git checkout 0.3.5 101 | ``` 102 | 103 | (Substitute whatever version you desire for `0.3.5`.) 104 | 105 | ## RTFM 106 | 107 | Please just see the [_sbt-ethereum_ docs](https://www.sbt-ethereum.io/). 108 | 109 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | name := "eth-command-line" 2 | 3 | enablePlugins(SbtEthereumPlugin) // make sure the build fails if the plugin is not present 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | #sbt.version=1.2.8 2 | sbt.version=1.3.13 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | // only necessary if running against a local snapshot 2 | // resolvers += Resolver.mavenLocal 3 | 4 | // only necessary while using a SNAPSHOT version of sbt-ethereum 5 | resolvers += ("snapshots" at "https://oss.sonatype.org/content/repositories/snapshots") 6 | 7 | addSbtPlugin("com.mchange" % "sbt-ethereum" % "0.6.0") 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sbtw: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # A more capable sbt runner, coincidentally also called sbt. 4 | # Author: Paul Phillips 5 | # https://github.com/paulp/sbt-extras 6 | 7 | set -o pipefail 8 | 9 | declare -r sbt_release_version="1.3.2" 10 | declare -r sbt_unreleased_version="1.3.2" 11 | 12 | declare -r latest_213="2.13.1" 13 | declare -r latest_212="2.12.10" 14 | declare -r latest_211="2.11.12" 15 | declare -r latest_210="2.10.7" 16 | declare -r latest_29="2.9.3" 17 | declare -r latest_28="2.8.2" 18 | 19 | declare -r buildProps="project/build.properties" 20 | 21 | declare -r sbt_launch_ivy_release_repo="https://repo.typesafe.com/typesafe/ivy-releases" 22 | declare -r sbt_launch_ivy_snapshot_repo="https://repo.scala-sbt.org/scalasbt/ivy-snapshots" 23 | declare -r sbt_launch_mvn_release_repo="https://repo.scala-sbt.org/scalasbt/maven-releases" 24 | declare -r sbt_launch_mvn_snapshot_repo="https://repo.scala-sbt.org/scalasbt/maven-snapshots" 25 | 26 | declare -r default_jvm_opts_common="-Xms512m -Xss2m" 27 | declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" 28 | 29 | declare sbt_jar sbt_dir sbt_create sbt_version sbt_script sbt_new 30 | declare sbt_explicit_version 31 | declare verbose noshare batch trace_level 32 | declare debugUs 33 | 34 | declare java_cmd="java" 35 | declare sbt_launch_dir="$HOME/.sbt/launchers" 36 | declare sbt_launch_repo 37 | 38 | # pull -J and -D options to give to java. 39 | declare -a java_args scalac_args sbt_commands residual_args 40 | 41 | # args to jvm/sbt via files or environment variables 42 | declare -a extra_jvm_opts extra_sbt_opts 43 | 44 | echoerr () { echo >&2 "$@"; } 45 | vlog () { [[ -n "$verbose" ]] && echoerr "$@"; } 46 | die () { echo "Aborting: $*" ; exit 1; } 47 | 48 | setTrapExit () { 49 | # save stty and trap exit, to ensure echo is re-enabled if we are interrupted. 50 | SBT_STTY="$(stty -g 2>/dev/null)" 51 | export SBT_STTY 52 | 53 | # restore stty settings (echo in particular) 54 | onSbtRunnerExit() { 55 | [ -t 0 ] || return 56 | vlog "" 57 | vlog "restoring stty: $SBT_STTY" 58 | stty "$SBT_STTY" 59 | } 60 | 61 | vlog "saving stty: $SBT_STTY" 62 | trap onSbtRunnerExit EXIT 63 | } 64 | 65 | # this seems to cover the bases on OSX, and someone will 66 | # have to tell me about the others. 67 | get_script_path () { 68 | local path="$1" 69 | [[ -L "$path" ]] || { echo "$path" ; return; } 70 | 71 | local -r target="$(readlink "$path")" 72 | if [[ "${target:0:1}" == "/" ]]; then 73 | echo "$target" 74 | else 75 | echo "${path%/*}/$target" 76 | fi 77 | } 78 | 79 | script_path="$(get_script_path "${BASH_SOURCE[0]}")" 80 | declare -r script_path 81 | script_name="${script_path##*/}" 82 | declare -r script_name 83 | 84 | init_default_option_file () { 85 | local overriding_var="${!1}" 86 | local default_file="$2" 87 | if [[ ! -r "$default_file" && "$overriding_var" =~ ^@(.*)$ ]]; then 88 | local envvar_file="${BASH_REMATCH[1]}" 89 | if [[ -r "$envvar_file" ]]; then 90 | default_file="$envvar_file" 91 | fi 92 | fi 93 | echo "$default_file" 94 | } 95 | 96 | sbt_opts_file="$(init_default_option_file SBT_OPTS .sbtopts)" 97 | jvm_opts_file="$(init_default_option_file JVM_OPTS .jvmopts)" 98 | 99 | build_props_sbt () { 100 | [[ -r "$buildProps" ]] && \ 101 | grep '^sbt\.version' "$buildProps" | tr '=\r' ' ' | awk '{ print $2; }' 102 | } 103 | 104 | set_sbt_version () { 105 | sbt_version="${sbt_explicit_version:-$(build_props_sbt)}" 106 | [[ -n "$sbt_version" ]] || sbt_version=$sbt_release_version 107 | export sbt_version 108 | } 109 | 110 | url_base () { 111 | local version="$1" 112 | 113 | case "$version" in 114 | 0.7.*) echo "https://simple-build-tool.googlecode.com" ;; 115 | 0.10.* ) echo "$sbt_launch_ivy_release_repo" ;; 116 | 0.11.[12]) echo "$sbt_launch_ivy_release_repo" ;; 117 | 0.*-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]) # ie "*-yyyymmdd-hhMMss" 118 | echo "$sbt_launch_ivy_snapshot_repo" ;; 119 | 0.*) echo "$sbt_launch_ivy_release_repo" ;; 120 | *-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]) # ie "*-yyyymmddThhMMss" 121 | echo "$sbt_launch_mvn_snapshot_repo" ;; 122 | *) echo "$sbt_launch_mvn_release_repo" ;; 123 | esac 124 | } 125 | 126 | make_url () { 127 | local version="$1" 128 | 129 | local base="${sbt_launch_repo:-$(url_base "$version")}" 130 | 131 | case "$version" in 132 | 0.7.*) echo "$base/files/sbt-launch-0.7.7.jar" ;; 133 | 0.10.* ) echo "$base/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;; 134 | 0.11.[12]) echo "$base/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;; 135 | 0.*) echo "$base/org.scala-sbt/sbt-launch/$version/sbt-launch.jar" ;; 136 | *) echo "$base/org/scala-sbt/sbt-launch/$version/sbt-launch-${version}.jar" ;; 137 | esac 138 | } 139 | 140 | addJava () { vlog "[addJava] arg = '$1'" ; java_args+=("$1"); } 141 | addSbt () { vlog "[addSbt] arg = '$1'" ; sbt_commands+=("$1"); } 142 | addScalac () { vlog "[addScalac] arg = '$1'" ; scalac_args+=("$1"); } 143 | addResidual () { vlog "[residual] arg = '$1'" ; residual_args+=("$1"); } 144 | 145 | addResolver () { addSbt "set resolvers += $1"; } 146 | addDebugger () { addJava "-Xdebug" ; addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"; } 147 | setThisBuild () { 148 | vlog "[addBuild] args = '$*'" 149 | local key="$1" && shift 150 | addSbt "set $key in ThisBuild := $*" 151 | } 152 | setScalaVersion () { 153 | [[ "$1" == *"-SNAPSHOT" ]] && addResolver 'Resolver.sonatypeRepo("snapshots")' 154 | addSbt "++ $1" 155 | } 156 | setJavaHome () { 157 | java_cmd="$1/bin/java" 158 | setThisBuild javaHome "_root_.scala.Some(file(\"$1\"))" 159 | export JAVA_HOME="$1" 160 | export JDK_HOME="$1" 161 | export PATH="$JAVA_HOME/bin:$PATH" 162 | } 163 | 164 | getJavaVersion() { 165 | local -r str=$("$1" -version 2>&1 | grep -E -e '(java|openjdk) version' | awk '{ print $3 }' | tr -d '"') 166 | 167 | # java -version on java8 says 1.8.x 168 | # but on 9 and 10 it's 9.x.y and 10.x.y. 169 | if [[ "$str" =~ ^1\.([0-9]+)\..*$ ]]; then 170 | echo "${BASH_REMATCH[1]}" 171 | elif [[ "$str" =~ ^([0-9]+)\..*$ ]]; then 172 | echo "${BASH_REMATCH[1]}" 173 | elif [[ -n "$str" ]]; then 174 | echoerr "Can't parse java version from: $str" 175 | fi 176 | } 177 | 178 | checkJava() { 179 | # Warn if there is a Java version mismatch between PATH and JAVA_HOME/JDK_HOME 180 | 181 | [[ -n "$JAVA_HOME" && -e "$JAVA_HOME/bin/java" ]] && java="$JAVA_HOME/bin/java" 182 | [[ -n "$JDK_HOME" && -e "$JDK_HOME/lib/tools.jar" ]] && java="$JDK_HOME/bin/java" 183 | 184 | if [[ -n "$java" ]]; then 185 | pathJavaVersion=$(getJavaVersion java) 186 | homeJavaVersion=$(getJavaVersion "$java") 187 | if [[ "$pathJavaVersion" != "$homeJavaVersion" ]]; then 188 | echoerr "Warning: Java version mismatch between PATH and JAVA_HOME/JDK_HOME, sbt will use the one in PATH" 189 | echoerr " Either: fix your PATH, remove JAVA_HOME/JDK_HOME or use -java-home" 190 | echoerr " java version from PATH: $pathJavaVersion" 191 | echoerr " java version from JAVA_HOME/JDK_HOME: $homeJavaVersion" 192 | fi 193 | fi 194 | } 195 | 196 | java_version () { 197 | local -r version=$(getJavaVersion "$java_cmd") 198 | vlog "Detected Java version: $version" 199 | echo "$version" 200 | } 201 | 202 | # MaxPermSize critical on pre-8 JVMs but incurs noisy warning on 8+ 203 | default_jvm_opts () { 204 | local -r v="$(java_version)" 205 | if [[ $v -ge 8 ]]; then 206 | echo "$default_jvm_opts_common" 207 | else 208 | echo "-XX:MaxPermSize=384m $default_jvm_opts_common" 209 | fi 210 | } 211 | 212 | build_props_scala () { 213 | if [[ -r "$buildProps" ]]; then 214 | versionLine="$(grep '^build.scala.versions' "$buildProps")" 215 | versionString="${versionLine##build.scala.versions=}" 216 | echo "${versionString%% .*}" 217 | fi 218 | } 219 | 220 | execRunner () { 221 | # print the arguments one to a line, quoting any containing spaces 222 | vlog "# Executing command line:" && { 223 | for arg; do 224 | if [[ -n "$arg" ]]; then 225 | if printf "%s\n" "$arg" | grep -q ' '; then 226 | printf >&2 "\"%s\"\n" "$arg" 227 | else 228 | printf >&2 "%s\n" "$arg" 229 | fi 230 | fi 231 | done 232 | vlog "" 233 | } 234 | 235 | setTrapExit 236 | 237 | if [[ -n "$batch" ]]; then 238 | "$@" < /dev/null 239 | else 240 | "$@" 241 | fi 242 | } 243 | 244 | jar_url () { make_url "$1"; } 245 | 246 | is_cygwin () { [[ "$(uname -a)" == "CYGWIN"* ]]; } 247 | 248 | jar_file () { 249 | is_cygwin \ 250 | && cygpath -w "$sbt_launch_dir/$1/sbt-launch.jar" \ 251 | || echo "$sbt_launch_dir/$1/sbt-launch.jar" 252 | } 253 | 254 | download_url () { 255 | local url="$1" 256 | local jar="$2" 257 | 258 | mkdir -p "${jar%/*}" && { 259 | if command -v curl > /dev/null 2>&1; then 260 | curl --fail --silent --location "$url" --output "$jar" 261 | elif command -v wget > /dev/null 2>&1; then 262 | wget -q -O "$jar" "$url" 263 | fi 264 | } && [[ -r "$jar" ]] 265 | } 266 | 267 | acquire_sbt_jar () { 268 | { 269 | sbt_jar="$(jar_file "$sbt_version")" 270 | [[ -r "$sbt_jar" ]] 271 | } || { 272 | sbt_jar="$HOME/.ivy2/local/org.scala-sbt/sbt-launch/$sbt_version/jars/sbt-launch.jar" 273 | [[ -r "$sbt_jar" ]] 274 | } || { 275 | sbt_jar="$(jar_file "$sbt_version")" 276 | jar_url="$(make_url "$sbt_version")" 277 | 278 | echoerr "Downloading sbt launcher for ${sbt_version}:" 279 | echoerr " From ${jar_url}" 280 | echoerr " To ${sbt_jar}" 281 | 282 | download_url "${jar_url}" "${sbt_jar}" 283 | 284 | case "${sbt_version}" in 285 | 0.*) vlog "SBT versions < 1.0 do not have published MD5 checksums, skipping check"; echo "" ;; 286 | *) verify_sbt_jar "${sbt_jar}" ;; 287 | esac 288 | } 289 | } 290 | 291 | verify_sbt_jar() { 292 | local jar="${1}" 293 | local md5="${jar}.md5" 294 | 295 | download_url "$(make_url "${sbt_version}").md5" "${md5}" > /dev/null 2>&1 296 | 297 | if command -v md5sum > /dev/null 2>&1; then 298 | if echo "$(cat "${md5}") ${jar}" | md5sum -c -; then 299 | rm -rf "${md5}" 300 | return 0 301 | else 302 | echoerr "Checksum does not match" 303 | return 1 304 | fi 305 | elif command -v md5 > /dev/null 2>&1; then 306 | if [ "$(md5 -q "${jar}")" == "$(cat "${md5}")" ]; then 307 | rm -rf "${md5}" 308 | return 0 309 | else 310 | echoerr "Checksum does not match" 311 | return 1 312 | fi 313 | elif command -v openssl > /dev/null 2>&1; then 314 | if [ "$(openssl md5 -r "${jar}" | awk '{print $1}')" == "$(cat "${md5}")" ]; then 315 | rm -rf "${md5}" 316 | return 0 317 | else 318 | echoerr "Checksum does not match" 319 | return 1 320 | fi 321 | else 322 | echoerr "Could not find an MD5 command" 323 | return 1 324 | fi 325 | } 326 | 327 | usage () { 328 | set_sbt_version 329 | cat < display stack traces with a max of frames (default: -1, traces suppressed) 348 | -debug-inc enable debugging log for the incremental compiler 349 | -no-colors disable ANSI color codes 350 | -sbt-create start sbt even if current directory contains no sbt project 351 | -sbt-dir path to global settings/plugins directory (default: ~/.sbt/) 352 | -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11+) 353 | -ivy path to local Ivy repository (default: ~/.ivy2) 354 | -no-share use all local caches; no sharing 355 | -offline put sbt in offline mode 356 | -jvm-debug Turn on JVM debugging, open at the given port. 357 | -batch Disable interactive mode 358 | -prompt Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted 359 | -script Run the specified file as a scala script 360 | 361 | # sbt version (default: sbt.version from $buildProps if present, otherwise $sbt_release_version) 362 | -sbt-force-latest force the use of the latest release of sbt: $sbt_release_version 363 | -sbt-version use the specified version of sbt (default: $sbt_release_version) 364 | -sbt-dev use the latest pre-release version of sbt: $sbt_unreleased_version 365 | -sbt-jar use the specified jar as the sbt launcher 366 | -sbt-launch-dir directory to hold sbt launchers (default: $sbt_launch_dir) 367 | -sbt-launch-repo repo url for downloading sbt launcher jar (default: $(url_base "$sbt_version")) 368 | 369 | # scala version (default: as chosen by sbt) 370 | -28 use $latest_28 371 | -29 use $latest_29 372 | -210 use $latest_210 373 | -211 use $latest_211 374 | -212 use $latest_212 375 | -213 use $latest_213 376 | -scala-home use the scala build at the specified directory 377 | -scala-version use the specified version of scala 378 | -binary-version use the specified scala version when searching for dependencies 379 | 380 | # java version (default: java from PATH, currently $(java -version 2>&1 | grep version)) 381 | -java-home alternate JAVA_HOME 382 | 383 | # passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution 384 | # The default set is used if JVM_OPTS is unset and no -jvm-opts file is found 385 | $(default_jvm_opts) 386 | JVM_OPTS environment variable holding either the jvm args directly, or 387 | the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts') 388 | Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument. 389 | -jvm-opts file containing jvm args (if not given, .jvmopts in project root is used if present) 390 | -Dkey=val pass -Dkey=val directly to the jvm 391 | -J-X pass option -X directly to the jvm (-J is stripped) 392 | 393 | # passing options to sbt, OR to this runner 394 | SBT_OPTS environment variable holding either the sbt args directly, or 395 | the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts') 396 | Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument. 397 | -sbt-opts file containing sbt args (if not given, .sbtopts in project root is used if present) 398 | -S-X add -X to sbt's scalacOptions (-S is stripped) 399 | EOM 400 | } 401 | 402 | process_args () { 403 | require_arg () { 404 | local type="$1" 405 | local opt="$2" 406 | local arg="$3" 407 | 408 | if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then 409 | die "$opt requires <$type> argument" 410 | fi 411 | } 412 | while [[ $# -gt 0 ]]; do 413 | case "$1" in 414 | -h|-help) usage; exit 0 ;; 415 | -v) verbose=true && shift ;; 416 | -d) addSbt "--debug" && shift ;; 417 | -w) addSbt "--warn" && shift ;; 418 | -q) addSbt "--error" && shift ;; 419 | -x) debugUs=true && shift ;; 420 | -trace) require_arg integer "$1" "$2" && trace_level="$2" && shift 2 ;; 421 | -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;; 422 | -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;; 423 | -no-share) noshare=true && shift ;; 424 | -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;; 425 | -sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;; 426 | -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;; 427 | -offline) addSbt "set offline in Global := true" && shift ;; 428 | -jvm-debug) require_arg port "$1" "$2" && addDebugger "$2" && shift 2 ;; 429 | -batch) batch=true && shift ;; 430 | -prompt) require_arg "expr" "$1" "$2" && setThisBuild shellPrompt "(s => { val e = Project.extract(s) ; $2 })" && shift 2 ;; 431 | -script) require_arg file "$1" "$2" && sbt_script="$2" && addJava "-Dsbt.main.class=sbt.ScriptMain" && shift 2 ;; 432 | 433 | -sbt-create) sbt_create=true && shift ;; 434 | -sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;; 435 | -sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;; 436 | -sbt-force-latest) sbt_explicit_version="$sbt_release_version" && shift ;; 437 | -sbt-dev) sbt_explicit_version="$sbt_unreleased_version" && shift ;; 438 | -sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;; 439 | -sbt-launch-repo) require_arg path "$1" "$2" && sbt_launch_repo="$2" && shift 2 ;; 440 | -scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;; 441 | -binary-version) require_arg version "$1" "$2" && setThisBuild scalaBinaryVersion "\"$2\"" && shift 2 ;; 442 | -scala-home) require_arg path "$1" "$2" && setThisBuild scalaHome "_root_.scala.Some(file(\"$2\"))" && shift 2 ;; 443 | -java-home) require_arg path "$1" "$2" && setJavaHome "$2" && shift 2 ;; 444 | -sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;; 445 | -jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;; 446 | 447 | -D*) addJava "$1" && shift ;; 448 | -J*) addJava "${1:2}" && shift ;; 449 | -S*) addScalac "${1:2}" && shift ;; 450 | -28) setScalaVersion "$latest_28" && shift ;; 451 | -29) setScalaVersion "$latest_29" && shift ;; 452 | -210) setScalaVersion "$latest_210" && shift ;; 453 | -211) setScalaVersion "$latest_211" && shift ;; 454 | -212) setScalaVersion "$latest_212" && shift ;; 455 | -213) setScalaVersion "$latest_213" && shift ;; 456 | new) sbt_new=true && : ${sbt_explicit_version:=$sbt_release_version} && addResidual "$1" && shift ;; 457 | *) addResidual "$1" && shift ;; 458 | esac 459 | done 460 | } 461 | 462 | # process the direct command line arguments 463 | process_args "$@" 464 | 465 | # skip #-styled comments and blank lines 466 | readConfigFile() { 467 | local end=false 468 | until $end; do 469 | read -r || end=true 470 | [[ $REPLY =~ ^# ]] || [[ -z $REPLY ]] || echo "$REPLY" 471 | done < "$1" 472 | } 473 | 474 | # if there are file/environment sbt_opts, process again so we 475 | # can supply args to this runner 476 | if [[ -r "$sbt_opts_file" ]]; then 477 | vlog "Using sbt options defined in file $sbt_opts_file" 478 | while read -r opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbt_opts_file") 479 | elif [[ -n "$SBT_OPTS" && ! ("$SBT_OPTS" =~ ^@.*) ]]; then 480 | vlog "Using sbt options defined in variable \$SBT_OPTS" 481 | IFS=" " read -r -a extra_sbt_opts <<< "$SBT_OPTS" 482 | else 483 | vlog "No extra sbt options have been defined" 484 | fi 485 | 486 | [[ -n "${extra_sbt_opts[*]}" ]] && process_args "${extra_sbt_opts[@]}" 487 | 488 | # reset "$@" to the residual args 489 | set -- "${residual_args[@]}" 490 | argumentCount=$# 491 | 492 | # set sbt version 493 | set_sbt_version 494 | 495 | checkJava 496 | 497 | # only exists in 0.12+ 498 | setTraceLevel() { 499 | case "$sbt_version" in 500 | "0.7."* | "0.10."* | "0.11."* ) echoerr "Cannot set trace level in sbt version $sbt_version" ;; 501 | *) setThisBuild traceLevel "$trace_level" ;; 502 | esac 503 | } 504 | 505 | # set scalacOptions if we were given any -S opts 506 | [[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[*]}\"" 507 | 508 | [[ -n "$sbt_explicit_version" && -z "$sbt_new" ]] && addJava "-Dsbt.version=$sbt_explicit_version" 509 | vlog "Detected sbt version $sbt_version" 510 | 511 | if [[ -n "$sbt_script" ]]; then 512 | residual_args=( "$sbt_script" "${residual_args[@]}" ) 513 | else 514 | # no args - alert them there's stuff in here 515 | (( argumentCount > 0 )) || { 516 | vlog "Starting $script_name: invoke with -help for other options" 517 | residual_args=( shell ) 518 | } 519 | fi 520 | 521 | # verify this is an sbt dir, -create was given or user attempts to run a scala script 522 | [[ -r ./build.sbt || -d ./project || -n "$sbt_create" || -n "$sbt_script" || -n "$sbt_new" ]] || { 523 | cat <