feature: add version command and check-update
This commit is contained in:
42
mc
42
mc
@@ -1,6 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
args=("$@")
|
args=("$@")
|
||||||
|
CYAN="\033[1;96m"
|
||||||
|
RED="\033[0;91m"
|
||||||
|
GREEN="\033[0;92m"
|
||||||
|
RESET='\033[0m'
|
||||||
|
|
||||||
readonly base_url="https://api.my-mc.link/"
|
readonly base_url="https://api.my-mc.link/"
|
||||||
readonly headers=( -H "Accept: application/json" -H "Content-Type: application/json" -H "x-my-mc-auth: ${MY_MC_API_KEY}" )
|
readonly headers=( -H "Accept: application/json" -H "Content-Type: application/json" -H "x-my-mc-auth: ${MY_MC_API_KEY}" )
|
||||||
|
|
||||||
@@ -39,8 +44,45 @@ declare -rA commands=(
|
|||||||
[mod-list]='mod-list GET'
|
[mod-list]='mod-list GET'
|
||||||
[backup]='backup FUNC'
|
[backup]='backup FUNC'
|
||||||
[connect]='connect FUNC'
|
[connect]='connect FUNC'
|
||||||
|
[check-update]='check_update FUNC'
|
||||||
|
[version]='version FUNC'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
function version() {
|
||||||
|
local message="$(mc console version | jq -r '.message')"
|
||||||
|
|
||||||
|
if [[ $message =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
|
||||||
|
local version="${BASH_REMATCH[0]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$version"
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_update() {
|
||||||
|
local version="${1:-$(version)}"
|
||||||
|
local url_base="$(mc website | jq -r '.message')"
|
||||||
|
local mods="$(curl -sS ${url_base}/mods.json | jq -c '.'))"
|
||||||
|
|
||||||
|
local -a result=("MOD\tID\tAVAILABLE\n")
|
||||||
|
local item id name latest available has_version available_versions
|
||||||
|
while read -r item; do
|
||||||
|
name="$(jq -r '.name' <<<"$item")"
|
||||||
|
id="$(jq -r '.id' <<<"$item")"
|
||||||
|
available_versions="$(curl -sS -X GET "https://api.modrinth.com/v2/project/$id" | jq -r '.game_versions')"
|
||||||
|
has_version="$(jq "contains([\"$version\"])" <<<"$available_versions")"
|
||||||
|
|
||||||
|
if [[ "$has_version" == "true" ]]; then
|
||||||
|
available="${GREEN}true${RESET}";
|
||||||
|
else
|
||||||
|
available="${RED}false${RESET}";
|
||||||
|
fi
|
||||||
|
|
||||||
|
result+=("$name\t$id\t$available\n")
|
||||||
|
done < <(jq -c '.[]' <<<"$mods")
|
||||||
|
|
||||||
|
echo -e "${result[*]}" | column -t -s $'\t'
|
||||||
|
}
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
if [[ ! $(which docker) ]]; then echo "docker is required"; exit 1; fi
|
if [[ ! $(which docker) ]]; then echo "docker is required"; exit 1; fi
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
|
Reference in New Issue
Block a user