From a2e6fcdc36cb10807e1fbf1e8232d64945536f1a Mon Sep 17 00:00:00 2001 From: ccamel Date: Sun, 20 Aug 2023 18:15:58 +0200 Subject: [PATCH] style(shell): make linter happy again --- starship/scripts/dev-setup.sh | 10 +++--- starship/scripts/port-forward.sh | 53 +++++++++++++++----------------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/starship/scripts/dev-setup.sh b/starship/scripts/dev-setup.sh index 72dec3010..7e03ab6fc 100644 --- a/starship/scripts/dev-setup.sh +++ b/starship/scripts/dev-setup.sh @@ -35,19 +35,19 @@ install_linux() { # Define a function to install a binary install_binary() { if [[ $(uname -s) == "Darwin" ]]; then - install_macos $1 + install_macos "$1" else - install_linux $1 + install_linux "$1" fi } # Define a function to check for the presence of a binary check_binary() { - if ! command -v $1 &> /dev/null + if ! command -v "$1" &> /dev/null then echo "$1 is not installed" - install_binary $1 - if ! command -v $1 &> /dev/null + install_binary "$1" + if ! command -v "$1" &> /dev/null then color red "Installation of $1 failed, exiting..." color red "Please install $1 manually, then run me again to verify the installation" diff --git a/starship/scripts/port-forward.sh b/starship/scripts/port-forward.sh index f14a80675..c5d400a30 100644 --- a/starship/scripts/port-forward.sh +++ b/starship/scripts/port-forward.sh @@ -12,9 +12,9 @@ function color() { function stop_port_forward() { color green "Trying to stop all port-forward, if any...." - PIDS=$(ps -ef | grep -i -e 'kubectl port-forward' | grep -v 'grep' | cat | awk '{print $2}') || true + PIDS=$(pgrep -f 'kubectl port-forward') || true for p in $PIDS; do - kill -15 $p + kill -15 "$p" done } @@ -28,16 +28,15 @@ REGISTRY_GRPC_PORT=9090 for i in "$@"; do case $i in - -c=*|--config=*) - CONFIGFILE="${i#*=}" - shift # past argument=value - ;; - -*|--*) - echo "Unknown option $i" - exit 1 - ;; - *) - ;; + -c=* | --config=*) + CONFIGFILE="${i#*=}" + shift # past argument=value + ;; + --* | -*) + echo "Unknown option $i" + exit 1 + ;; + *) ;; esac done @@ -45,36 +44,34 @@ stop_port_forward echo "Port forwarding for config ${CONFIGFILE}" echo "Port forwarding all chains" -num_chains=$(yq -r ".chains | length - 1" ${CONFIGFILE}) +num_chains=$(yq -r ".chains | length - 1" "${CONFIGFILE}") if [[ $num_chains -lt 0 ]]; then echo "No chains to port-forward: num: $num_chains" exit 1 fi -for i in $(seq 0 $num_chains); do - chain=$(yq -r ".chains[$i].name" ${CONFIGFILE} ) - localrpc=$(yq -r ".chains[$i].ports.rpc" ${CONFIGFILE} ) - locallcd=$(yq -r ".chains[$i].ports.rest" ${CONFIGFILE} ) - localexp=$(yq -r ".chains[$i].ports.exposer" ${CONFIGFILE}) - [[ "$localrpc" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $localrpc:$CHAIN_RPC_PORT > /dev/null 2>&1 & - [[ "$locallcd" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $locallcd:$CHAIN_LCD_PORT > /dev/null 2>&1 & - [[ "$localexp" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $localexp:$CHAIN_EXPOSER_PORT > /dev/null 2>&1 & +for i in $(seq 0 "$num_chains"); do + chain=$(yq -r ".chains[$i].name" "${CONFIGFILE}") + localrpc=$(yq -r ".chains[$i].ports.rpc" "${CONFIGFILE}") + locallcd=$(yq -r ".chains[$i].ports.rest" "${CONFIGFILE}") + localexp=$(yq -r ".chains[$i].ports.exposer" "${CONFIGFILE}") + [[ "$localrpc" != "null" ]] && kubectl port-forward pods/"$chain"-genesis-0 "$localrpc":$CHAIN_RPC_PORT >/dev/null 2>&1 & + [[ "$locallcd" != "null" ]] && kubectl port-forward pods/"$chain"-genesis-0 "$locallcd":$CHAIN_LCD_PORT >/dev/null 2>&1 & + [[ "$localexp" != "null" ]] && kubectl port-forward pods/"$chain"-genesis-0 "$localexp":$CHAIN_EXPOSER_PORT >/dev/null 2>&1 & sleep 1 color yellow "chains: forwarded $chain lcd to http://localhost:$locallcd, rpc to http://localhost:$localrpc" done echo "Port forward services" -if [[ $(yq -r ".registry.enabled" $CONFIGFILE) == "true" ]]; -then - kubectl port-forward service/registry 8081:$REGISTRY_LCD_PORT > /dev/null 2>&1 & - kubectl port-forward service/registry 9091:$REGISTRY_GRPC_PORT > /dev/null 2>&1 & +if [[ $(yq -r ".registry.enabled" "$CONFIGFILE") == "true" ]]; then + kubectl port-forward service/registry 8081:$REGISTRY_LCD_PORT >/dev/null 2>&1 & + kubectl port-forward service/registry 9091:$REGISTRY_GRPC_PORT >/dev/null 2>&1 & sleep 1 color yellow "registry: forwarded registry lcd to grpc http://localhost:8081, to http://localhost:9091" fi -if [[ $(yq -r ".explorer.enabled" $CONFIGFILE) == "true" ]]; -then - kubectl port-forward service/explorer 8080:$EXPLORER_LCD_PORT > /dev/null 2>&1 & +if [[ $(yq -r ".explorer.enabled" "$CONFIGFILE") == "true" ]]; then + kubectl port-forward service/explorer 8080:$EXPLORER_LCD_PORT >/dev/null 2>&1 & sleep 1 color green "Open the explorer to get started.... http://localhost:8080" fi