Skip to content

Commit

Permalink
[mithril] client script adjustments (#1813)
Browse files Browse the repository at this point in the history
mithril-client.sh changes

- mithril-client.sh source env in offline mode
- mithril-client.sh Help text parsed first from -h, or --help.
- cnode.sh use -u  when calling mithril-client.sh to avoid update checks in non gui mode

Co-authored-by: RdLrT <[email protected]>
  • Loading branch information
TrevorBenson and rdlrt authored Sep 2, 2024
1 parent 7558c74 commit 5531f8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion scripts/cnode-helper-scripts/cnode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mithril_snapshot_download() {
if [[ ! -f "${MITHRIL_CLIENT}" ]] || [[ ! -e "${MITHRIL_CLIENT}" ]]; then
echo "ERROR: Could not locate mithril-client.sh script or script is not executable. Skipping mithril cardano-db snapshot download!!"
else
"${MITHRIL_CLIENT}" cardano-db download
"${MITHRIL_CLIENT}" -u cardano-db download
fi
}

Expand Down
20 changes: 15 additions & 5 deletions scripts/cnode-helper-scripts/mithril-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
usage() {
cat <<-EOF
Usage: $(basename "$0") [-u] <command> <subcommand> [<sub arg>]
Usage: $(basename "$0") [-h] [-u] <command> <subcommand> [<sub arg>]
A script to run Cardano Mithril Client
-u Skip script update check overriding UPDATE_CHECK value in env (must be first argument to script)
[ -h | --help] Print this help
[ -u | --skip-update ] Skip script update check overriding UPDATE_CHECK value in env (must be first argument to script)
Commands:
environment Manage mithril environment file
Expand All @@ -46,14 +47,25 @@ EOF
}

SKIP_UPDATE=N
[[ $1 = "-u" ]] && export SKIP_UPDATE=Y && shift
[[ $1 =~ "-u" ]] || [[ $1 =~ "--skip-update" ]] && export SKIP_UPDATE=Y && shift


#####################
# Execution/Main #
#####################

function parse_opt_for_help() {
for value in "$@"; do
if [[ $value == "-h" ]] || [[ $value == "--help" ]]; then
usage
exit 0
fi
done
}

function main() {
parse_opt_for_help "$@"

. "$(dirname $0)"/mithril.library

update_check "$@"
Expand Down Expand Up @@ -135,9 +147,7 @@ function main() {
esac
;;
*)
echo "Invalid $(basename "$0") command: $1" >&2
usage
exit 1
;;
esac

Expand Down
22 changes: 12 additions & 10 deletions scripts/cnode-helper-scripts/mithril.library
Original file line number Diff line number Diff line change
Expand Up @@ -235,30 +235,32 @@ set_node_minimum_version() {
}

update_check() {
# Check availability of checkUpdate function
if [[ ! $(command -v checkUpdate) ]]; then
echo -e "\nCould not find checkUpdate function in env, make sure you're using official guild docos for installation!"
exit 1
fi
# Check if flag is set by script to skip update check
[[ ${SKIP_UPDATE} == Y ]] && return 0
# Check if flag is set by user as a global (container environments etc.) to skip update check
if [[ ${UPDATE_CHECK} = Y ]]; then
# Check if flag is set by user as a global or script to skip update check
if [[ ${UPDATE_CHECK} = Y && ${SKIP_UPDATE} != Y ]]; then

echo "Checking for script updates..."

# Check availability of checkUpdate function
if [[ ! $(command -v checkUpdate) ]]; then
echo -e "\nCould not find checkUpdate function in env, make sure you're using official guild docos for installation!"
exit 1
fi

# check for env update
ENV_UPDATED=${BATCH_AUTO_UPDATE}
checkUpdate "${PARENT}"/env N N N
case $? in
1) ENV_UPDATED=Y ;;
2) exit 1 ;;
esac

# check for mithril.library update
checkUpdate "${PARENT}"/mithril.library N N N
# borrow ENV_UPDATED for mithril.library updates
case $? in
1) ENV_UPDATED=Y ;;
2) exit 1 ;;
esac

# check the script update
checkUpdate "${PARENT}"/"$(basename "$0")" ${ENV_UPDATED}
case $? in
Expand Down

0 comments on commit 5531f8a

Please sign in to comment.