fix: extract main api call to function. Script no longer needs to be in $PATH to work. And check-update command now pulls directly from mod-list endpoint.
This commit is contained in:
27
mc
27
mc
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
args=("$@")
|
ARGS=("$@")
|
||||||
CYAN="\033[1;96m"
|
CYAN="\033[1;96m"
|
||||||
RED="\033[0;91m"
|
RED="\033[0;91m"
|
||||||
GREEN="\033[0;92m"
|
GREEN="\033[0;92m"
|
||||||
@@ -49,7 +49,7 @@ declare -rA commands=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
function version() {
|
function version() {
|
||||||
local message="$(mc console version | jq -r '.message')"
|
local message="$(call_api console version | jq -r '.message')"
|
||||||
|
|
||||||
if [[ $message =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
|
if [[ $message =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
|
||||||
local version="${BASH_REMATCH[0]}"
|
local version="${BASH_REMATCH[0]}"
|
||||||
@@ -60,8 +60,7 @@ function version() {
|
|||||||
|
|
||||||
function check_update() {
|
function check_update() {
|
||||||
local version="${1:-$(version)}"
|
local version="${1:-$(version)}"
|
||||||
local url_base="$(mc website | jq -r '.message')"
|
local mods="$(call_api mod-list | jq -c '.mods')"
|
||||||
local mods="$(curl -sS ${url_base}/mods.json | jq -c '.'))"
|
|
||||||
|
|
||||||
local -a result=("MOD\tID\tAVAILABLE\n")
|
local -a result=("MOD\tID\tAVAILABLE\n")
|
||||||
local item id name latest available has_version available_versions
|
local item id name latest available has_version available_versions
|
||||||
@@ -98,7 +97,7 @@ function connect() {
|
|||||||
function backup() {
|
function backup() {
|
||||||
if [[ ! $(which lftp) ]]; then echo "lftp is required"; exit 1; fi
|
if [[ ! $(which lftp) ]]; then echo "lftp is required"; exit 1; fi
|
||||||
|
|
||||||
local sftp_credentials="$(mc my-sftp)"
|
local sftp_credentials="$(call_api my-sftp)"
|
||||||
if [[ "$(jq -r '.success' <<<"${sftp_credentials}" )" != "true" ]]; then
|
if [[ "$(jq -r '.success' <<<"${sftp_credentials}" )" != "true" ]]; then
|
||||||
echo "ERROR: failed to get sftp login info";
|
echo "ERROR: failed to get sftp login info";
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -136,13 +135,9 @@ function usage() {
|
|||||||
echo -e "${message[*]}" | column -t -s $'\t'
|
echo -e "${message[*]}" | column -t -s $'\t'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function call_api() {
|
||||||
function main() {
|
|
||||||
# remove command from arg list while preserving quoted strings.
|
# remove command from arg list while preserving quoted strings.
|
||||||
args=("${args[@]:1}")
|
local args=("${ARGS[@]:1}")
|
||||||
|
|
||||||
if [[ ! $(which curl) ]]; then echo "curl is required"; exit 1; fi
|
|
||||||
if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
|
|
||||||
|
|
||||||
# Check if key does NOT exists in command array
|
# Check if key does NOT exists in command array
|
||||||
if [[ ! -v commands[$1] ]]; then
|
if [[ ! -v commands[$1] ]]; then
|
||||||
@@ -171,11 +166,19 @@ function main() {
|
|||||||
echo "ERROR: Invalid state. Check for typo in command array."
|
echo "ERROR: Invalid state. Check for typo in command array."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
if [[ ! $(which curl) ]]; then echo "curl is required"; exit 1; fi
|
||||||
|
if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
|
||||||
|
|
||||||
|
call_api "${ARGS[@]}"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if [[ "$(basename "$0")" == "mc" ]]; then
|
if [[ "$(basename "$0")" == "mc" ]]; then
|
||||||
main "${args[@]}"
|
main
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user