-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathrun.sh
More file actions
157 lines (134 loc) · 6.21 KB
/
Copy pathrun.sh
File metadata and controls
157 lines (134 loc) · 6.21 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# <App_BANNER_INJECTION>
# ============================================================================
# App Startup Banner - Auto-generated by CI
# ============================================================================
_show_startup_banner() {
# shellcheck disable=SC2034,SC2155
local VERSION
if ! VERSION=$(bashio::app.version 2>/dev/null || bashio::addon.version 2>/dev/null); then
VERSION="unknown"
fi
[ -z "$VERSION" ] && VERSION="unknown"
local SLUG="matterbridge"
local UNSUPPORTED="false"
local REPO="FaserF/hassio-addons"
local MAINTAINER="FaserF"
# Extract base version and commit from dev versions (1.2.3-dev+abc123)
local BASE_VERSION="${VERSION%%-dev*}"
local DEV_COMMIT=""
if [[ "$VERSION" == *"-dev+"* ]]; then
DEV_COMMIT="${VERSION##*+}"
fi
# Status indicator
if [ "$UNSUPPORTED" = "true" ]; then
bashio::log.error "🚨 STATUS: UNSUPPORTED"
bashio::log.error " This App is no longer maintained!"
elif [[ "$VERSION" == *"-dev"* ]]; then
bashio::log.warning "🚧 STATUS: DEVELOPMENT"
bashio::log.warning " This is a development build!"
elif [[ "${BASE_VERSION%%.*}" =~ ^[0-9]+$ ]] && [ "${BASE_VERSION%%.*}" -lt 1 ] 2>/dev/null; then
bashio::log.notice "🔬 STATUS: BETA"
bashio::log.notice " This App is in beta testing."
else
bashio::log.green "✅ STATUS: STABLE"
fi
# Helper for semantic version comparison
version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
# ========================================================================
# Smart Update Check
# ========================================================================
if command -v curl &>/dev/null; then
local UPDATE_MSG=""
# Get latest stable version from config.yaml
local LATEST_STABLE
LATEST_STABLE=$(curl -s --max-time 10 "https://raw.githubusercontent.com/$REPO/master/$SLUG/config.yaml" 2>/dev/null | grep -E "^version:" | head -1 | sed 's/version:[[:space:]]*["'"'"']\?\([^"'"'"'+]*\).*/\1/' | sed 's/-dev.*//' || true)
if [ -n "$LATEST_STABLE" ]; then
# For DEV versions: Check if there are newer commits for this App
if [[ "$VERSION" == *"-dev"* ]]; then
if [ -n "$DEV_COMMIT" ]; then
# Get latest commit for this App from GitHub
local LATEST_COMMIT
LATEST_COMMIT=$(curl -s --max-time 10 "https://api.github.com/repos/$REPO/commits?path=$SLUG&per_page=1" 2>/dev/null | grep -o '"sha": "[^"]*"' | head -1 | cut -d'"' -f4 | head -c7 || true)
if [ -n "$LATEST_COMMIT" ] && [ "$LATEST_COMMIT" != "$DEV_COMMIT" ]; then
UPDATE_MSG="⬆️ DEV UPDATE: New commits available"
bashio::log.yellow " Your commit: $DEV_COMMIT"
bashio::log.yellow " Latest: $LATEST_COMMIT"
fi
fi
# Also check if a stable release is available
if [ "$LATEST_STABLE" != "$BASE_VERSION" ]; then
# Compare versions
if version_gt "$LATEST_STABLE" "$BASE_VERSION" 2>/dev/null; then
UPDATE_MSG="⬆️ STABLE RELEASE: $LATEST_STABLE available!"
bashio::log.yellow " Consider upgrading to the stable release"
fi
fi
# For BETA versions (< 1.0.0): Check for newer beta OR stable
elif [[ "${BASE_VERSION%%.*}" =~ ^[0-9]+$ ]] && [ "${BASE_VERSION%%.*}" -lt 1 ] 2>/dev/null; then
if [ "$LATEST_STABLE" != "$BASE_VERSION" ]; then
# If stable is >= 1.0.0, it's definitely newer
local LATEST_MAJOR="${LATEST_STABLE%%.*}"
if [ "$LATEST_MAJOR" -ge 1 ] 2>/dev/null; then
UPDATE_MSG="⬆️ STABLE RELEASE: $LATEST_STABLE available!"
elif version_gt "$LATEST_STABLE" "$BASE_VERSION" 2>/dev/null; then
UPDATE_MSG="⬆️ UPDATE AVAILABLE: $LATEST_STABLE"
fi
fi
# For STABLE versions: Simple version comparison
else
if [ "$LATEST_STABLE" != "$BASE_VERSION" ]; then
if version_gt "$LATEST_STABLE" "$BASE_VERSION" 2>/dev/null; then
UPDATE_MSG="⬆️ UPDATE AVAILABLE: $LATEST_STABLE"
fi
fi
fi
fi
if [ -n "$UPDATE_MSG" ]; then
bashio::log.yellow "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
bashio::log.yellow "$UPDATE_MSG"
bashio::log.yellow " You are running: $VERSION"
bashio::log.yellow " Update via the App Store"
bashio::log.yellow "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
fi
fi
# Footer with links
bashio::log.blue "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
bashio::log.info "📝 Issues: https://github.com/$REPO/issues"
bashio::log.info "💖 Maintained by: $MAINTAINER"
bashio::log.blue "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
bashio::log.info ""
}
# Show banner on startup
if type bashio::log.blue &>/dev/null; then
_show_startup_banner
fi
# </App_BANNER_INJECTION>
# Enable strict mode
set -e
# shellcheck disable=SC1091,SC2034
# banner prints App version
config_path=$(bashio::config 'config_path')
log_level=$(bashio::config 'log_level')
if ! [ -f "$config_path" ]; then
echo "There is no $config_path file! Please create one for your needs! See here for an example: https://github.com/42wim/matterbridge/blob/master/matterbridge.toml.sample"
echo "Try restarting the App once your config file has been fully configured an been put somewhere on the HA /share folder."
exit 1
fi
echo "Found config file at $config_path . Copying it now."
cp "$config_path" /etc/matterbridge/matterbridge.toml
parameter="-conf /etc/matterbridge/matterbridge.toml"
if [ "$log_level" = "debug" ]; then
parameter="${parameter} -debug"
fi
echo "" >/var/log/matterbridge.log
echo "Starting Matterbridge..."
# SC2086: We want word splitting here for parameters, so we can't double quote "parameter"
# unless we use an array, but simplicity suggests checking if we can just disable the check
# or use array. Let's use array.
params=("-conf" "/etc/matterbridge/matterbridge.toml")
if [ "$log_level" = "debug" ]; then
params+=("-debug")
fi
exec /bin/matterbridge "${params[@]}"