mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-03-14 17:04:26 +01:00
Improve error handling in Chrome extensions script
Added error handling for downloading and unzipping Chrome extensions.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
set -e
|
||||
|
||||
EXTENSIONS_DIR="${CHROME_EXTENSIONS_DIR:-/usr/src/chrome/extensions}"
|
||||
|
||||
bashio::log.info "Refreshing Chromium extensions in ${EXTENSIONS_DIR}"
|
||||
|
||||
mkdir -p "${EXTENSIONS_DIR}"
|
||||
@@ -11,15 +10,32 @@ mkdir -p "${EXTENSIONS_DIR}"
|
||||
download_extension() {
|
||||
local name="$1"
|
||||
local extension_id="$2"
|
||||
local crx_path
|
||||
local crx_path rc
|
||||
|
||||
crx_path="$(mktemp)"
|
||||
curl -fsSL "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=120.0&acceptformat=crx2,crx3&x=id%3D${extension_id}%26installsource%3Dondemand%26uc" \
|
||||
-o "${crx_path}"
|
||||
|
||||
if ! curl -fsSL \
|
||||
"https://clients2.google.com/service/update2/crx?response=redirect&prodversion=120.0&acceptformat=crx2,crx3&x=id%3D${extension_id}%26installsource%3Dondemand%26uc" \
|
||||
-o "${crx_path}"; then
|
||||
rm -f "${crx_path}"
|
||||
bashio::log.warning "Failed to download extension ${name}. Continuing without refresh."
|
||||
return 0
|
||||
fi
|
||||
|
||||
rm -rf "${EXTENSIONS_DIR:?}/${name}"
|
||||
mkdir -p "${EXTENSIONS_DIR}/${name}"
|
||||
unzip -q "${crx_path}" -d "${EXTENSIONS_DIR}/${name}"
|
||||
|
||||
rc=0
|
||||
unzip -q "${crx_path}" -d "${EXTENSIONS_DIR}/${name}" || rc=$?
|
||||
rm -f "${crx_path}"
|
||||
|
||||
# unzip may return 1 even though files extracted (common with CRX zip metadata)
|
||||
if [ "${rc}" -ne 0 ] && [ "${rc}" -ne 1 ]; then
|
||||
bashio::log.warning "Failed to unzip extension ${name} (rc=${rc}). Continuing."
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
download_extension "i-dont-care-about-cookies" "fllaojicojecljbmefodhfapmkghcbnh"
|
||||
|
||||
Reference in New Issue
Block a user