-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
repositories.sh
106 lines (95 loc) · 3.7 KB
/
repositories.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
# ==============================================================================
# Home Assistant Community Add-ons: Bashio
# Bashio is a bash function library for use with Home Assistant add-ons.
#
# It contains a set of commonly used operations and can be used
# to be included in add-on scripts to reduce code duplication across add-ons.
# ==============================================================================
# ------------------------------------------------------------------------------
# Returns a JSON object with generic version information about repositories.
#
# Arguments:
# $1 Add-on slug (optional)
# $1 Cache key to store results in (optional)
# $2 jq Filter to apply on the result (optional)
# ------------------------------------------------------------------------------
function bashio::repositories() {
local slug=${1:-false}
local cache_key=${2:-'repositories.list'}
local filter=${3:-'.repositories[].slug'}
local info
local response
bashio::log.trace "${FUNCNAME[0]}" "$@"
if bashio::cache.exists "${cache_key}"; then
bashio::cache.get "${cache_key}"
return "${__BASHIO_EXIT_OK}"
fi
if bashio::var.false "${slug}"; then
if bashio::cache.exists "repositories.list"; then
info=$(bashio::cache.get 'repositories.list')
else
info=$(bashio::api.supervisor GET "/addons" false)
bashio::cache.set "repositories.list" "${info}"
fi
else
if bashio::cache.exists "repositories.${slug}.info"; then
info=$(bashio::cache.get "repositories.${slug}.info")
else
info=$(bashio::api.supervisor GET "/addons" \
false ".repositories[] | select(.slug==\"${slug}\")")
bashio::cache.set "repositories.${slug}.info" "${info}"
fi
fi
response="${info}"
if bashio::var.has_value "${filter}"; then
response=$(bashio::jq "${info}" "${filter}")
fi
bashio::cache.set "${cache_key}" "${response}"
printf "%s" "${response}"
return "${__BASHIO_EXIT_OK}"
}
# ------------------------------------------------------------------------------
# Returns the name of a repository.
#
# Arguments:
# $1 Repository slug
# ------------------------------------------------------------------------------
function bashio::repository.name() {
local slug=${1}
bashio::log.trace "${FUNCNAME[0]}" "$@"
bashio::repositories "${slug}" "repositories.${slug}.name" '.name'
}
# ------------------------------------------------------------------------------
# Returns the source of a repository.
#
# Arguments:
# $1 Repository slug
# ------------------------------------------------------------------------------
function bashio::repository.source() {
local slug=${1}
bashio::log.trace "${FUNCNAME[0]}" "$@"
bashio::repositories "${slug}" "repositories.${slug}.source" '.source'
}
# ------------------------------------------------------------------------------
# Returns the URL of a repository.
#
# Arguments:
# $1 Repository slug
# ------------------------------------------------------------------------------
function bashio::repository.url() {
local slug=${1}
bashio::log.trace "${FUNCNAME[0]}" "$@"
bashio::repositories "${slug}" "repositories.${slug}.url" '.url'
}
# ------------------------------------------------------------------------------
# Returns the maintainer of a repository.
#
# Arguments:
# $1 Repository slug
# ------------------------------------------------------------------------------
function bashio::repository.maintainer() {
local slug=${1}
bashio::log.trace "${FUNCNAME[0]}" "$@"
bashio::repositories "${slug}" "repositories.${slug}.maintainer" '.maintainer'
}