Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for macOS and arm arch #21

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bin/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ notify_discord() {
echo_stderr "$RESULT"
fi

if echo "$RESULT" | $JQ_BIN -e .message &>/dev/null; then
if echo "$RESULT" | $JQ_BIN -e .message 1>/dev/null; then
echo_stderr "$RESULT"
echo_stderr "> failed Discord notification"
else
Expand Down Expand Up @@ -107,7 +107,7 @@ notify_gotify() {
echo_stderr "$RESULT"
fi

if echo "$RESULT" | $JQ_BIN -e .error &>/dev/null; then
if echo "$RESULT" | $JQ_BIN -e .error 1>/dev/null; then
echo_stderr "$RESULT"
echo_stderr "> failed Gotify notification"
else
Expand All @@ -131,7 +131,7 @@ notify_opsgenie() {
echo_stderr "$RESULT"
fi

if echo "$RESULT" | $JQ_BIN -e '.result | length > 0' &>/dev/null; then
if echo "$RESULT" | $JQ_BIN -e '.result | length > 0' 1>/dev/null; then
echo "> sent OpsGenie notification"
else
echo_stderr "$RESULT"
Expand All @@ -158,7 +158,7 @@ notify_telegram() {
echo_stderr "$RESULT"
fi

if echo "$RESULT" | $JQ_BIN -e .ok &>/dev/null; then
if echo "$RESULT" | $JQ_BIN -e .ok 1>/dev/null; then
echo "> sent Telegram notification"
else
echo_stderr "$RESULT"
Expand All @@ -185,7 +185,7 @@ get_catalog() {
ovh_url="${OVH_API_ENDPOINTS["$ENDPOINT"]}/order/catalog/public/eco?ovhSubsidiary=${country}"
data=$(curl -qSs "${ovh_url}")

if test -z "$data" || ! echo "$data" | $JQ_BIN -e . &>/dev/null || echo "$data" | $JQ_BIN -e '.plans | length == 0' &>/dev/null; then
if test -z "$data" || ! echo "$data" | $JQ_BIN -e . 1>/dev/null || echo "$data" | $JQ_BIN -e '.plans | length == 0' 1>/dev/null; then
echo_stderr "> failed to fetch data from $ovh_url"
exit 2
fi
Expand Down Expand Up @@ -404,7 +404,7 @@ main() {
fi

# Check for error: empty data, invalid json, or empty list
if test -z "$DATA" || ! echo "$DATA" | $JQ_BIN -e . &>/dev/null || echo "$DATA" | $JQ_BIN -e '. | length == 0' &>/dev/null; then
if test -z "$DATA" || ! echo "$DATA" | $JQ_BIN -e . 1>/dev/null || echo "$DATA" | $JQ_BIN -e '. | length == 0' 1>/dev/null; then
echo_stderr "> failed to fetch data from $endpoint"
exit 2
fi
Expand All @@ -415,7 +415,7 @@ main() {
fi

# Check for datacenters availability
if ! echo "$DATA" | $JQ_BIN -e '.[].datacenters[] | select(.availability != "unavailable")' &>/dev/null; then
if ! echo "$DATA" | $JQ_BIN -e '.[].datacenters[] | select(.availability != "unavailable")' 1>/dev/null; then
echo "> checked $PLAN_CODE unavailable in $DATACENTERS_MESSAGE"
exit 4
fi
Expand Down
17 changes: 16 additions & 1 deletion bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,20 @@ install_tool() {
}

install_tools() {
install_tool "${JQ_BIN}" "${JQ_VERSION}" "https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64"
os=""
case "$OSTYPE" in
darwin*) os="macos" ;;
linux*) os="linux" ;;
*) echo "unsupported OS: $OSTYPE"; exit ;;
esac

arch=""
case "$(uname -m)" in
x86_64) arch="amd64" ;;
arm*) arch="arm64" ;;
aarch*) arch="arm64" ;;
*) echo "unsupported architecture: $(uname -m)"; exit ;;
esac

install_tool "${JQ_BIN}" "${JQ_VERSION}" "https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-${os}-${arch}"
}
2 changes: 1 addition & 1 deletion bin/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ main() {
fi

# Check for error: empty data, invalid json, or empty list
if test -z "$DATA" || ! echo "$DATA" | $JQ_BIN -e . &>/dev/null || echo "$DATA" | $JQ_BIN -e '.plans | length == 0' &>/dev/null; then
if test -z "$DATA" || ! echo "$DATA" | $JQ_BIN -e . 1>/dev/null || echo "$DATA" | $JQ_BIN -e '.plans | length == 0' 1>/dev/null; then
echo_stderr "> failed to fetch data from $OVH_URL"
exit 2
fi
Expand Down
Loading