Skip to content

Instantly share code, notes, and snippets.

@cloudnull
Last active August 4, 2023 15:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudnull/8d03e581f5f2947dd168a8f9375844c4 to your computer and use it in GitHub Desktop.
Save cloudnull/8d03e581f5f2947dd168a8f9375844c4 to your computer and use it in GitHub Desktop.
compose omnibus protocol shell
function fig-up () {
function get_latest_release() {
curl $(curl --silent "https://api.github.com/repos/ovrclk/cosmos-omnibus/releases/latest" | jq ".url" -r) | jq -r .tag_name
}
function get_rpc_endpoint() {
curl --silent "https://cdn.jsdelivr.net/gh/cosmos/chain-registry@master/$1/chain.json" | jq ".apis.rpc[0].address" -r
}
if ! command -v jq &> /dev/null; then
echo 'install "jq" to go forward.'
fi
if ! command -v curl &> /dev/null; then
echo 'install "curl" to go forward.'
fi
if ! command -v git &> /dev/null; then
echo 'install "git" to go forward.'
fi
if ! command -v docker &> /dev/null; then
echo 'install "docker" to go forward.'
fi
PROTOCOL="$1"
RPC_URL="$(get_rpc_endpoint ${PROTOCOL})"
if [[ -d /tmp/cosmos-omnibus ]]; then
pushd /tmp/cosmos-omnibus
git checkout $(get_latest_release)
popd
else
git clone --branch $(get_latest_release) https://github.com/ovrclk/cosmos-omnibus /tmp/cosmos-omnibus
fi
pushd "/tmp/cosmos-omnibus/${PROTOCOL}"
docker compose up -d
docker compose exec -it -e NODE=$RPC_URL node_1 /bin/bash
COMPOSE_RC=$?
docker compose kill node_1 || true
docker compose rm --force node_1 || true
popd
if [[ ${COMPOSE_RC} == 0 ]]; then
rm -rf /tmp/cosmos-omnibus
fi
unset COMPOSE_RC
unset RPC_URL
unset PROTOCOL
unset -f get_rpc_endpoint
unset -f get_latest_release
}
@cloudnull
Copy link
Author

cloudnull commented Dec 19, 2022

Integration example

Add the function to your terminal RC file.

if [[ "$SHELL" =~ "zsh" ]]; then
  RC_FILE="${HOME}/.zshrc"
elif [[ "$SHELL" =~ "bash" ]]; then
  RC_FILE="${HOME}/.bashrc"
fi

curl -s https://gist.githubusercontent.com/cloudnull/8d03e581f5f2947dd168a8f9375844c4/raw/22e17c7241eb8eacedc018734318709979a0f1e5/fig-up.rc | tee -a "${RC_FILE}"

Once added restart the terminal emulator application.

Execution example

With the function installed, you can run it normally. The first positional argument is always assumed to be the protocol supported by cosmos-omnibus.

fig-up osmosis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment