mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 10:21:02 +01:00
lint
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
# ==============================================================================
|
||||
# Displays a simple add-on banner on startup
|
||||
# ==============================================================================
|
||||
echo "hello"
|
||||
if bashio::supervisor.ping; then
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
|
||||
@@ -19,14 +19,14 @@ if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then
|
||||
fi
|
||||
|
||||
# Check if config file is there, or create one from template
|
||||
if [ -f $CONFIGSOURCE ]; then
|
||||
if [ -f "$CONFIGSOURCE" ]; then
|
||||
# Create symlink if not existing yet
|
||||
[ ! -L /data/config.yaml ] && ln -sf $CONFIGSOURCE /data
|
||||
[ ! -L /data/config.yaml ] && ln -sf "$CONFIGSOURCE" /data
|
||||
bashio::log.info "Using config file found in $CONFIGSOURCE"
|
||||
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed $CONFIGSOURCE &>ERROR || EXIT_CODE=$?
|
||||
yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$?
|
||||
if [ $EXIT_CODE = 0 ]; then
|
||||
echo "Config file is a valid yaml"
|
||||
else
|
||||
@@ -37,10 +37,10 @@ if [ -f $CONFIGSOURCE ]; then
|
||||
else
|
||||
# Create symlink for addon to create config
|
||||
touch ${CONFIGSOURCE}
|
||||
ln -sf $CONFIGSOURCE /data
|
||||
ln -sf "$CONFIGSOURCE" /data
|
||||
rm $CONFIGSOURCE
|
||||
# Need to restart
|
||||
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in "$CONFIGSOURCE" before restarting."
|
||||
fi
|
||||
|
||||
# Remove previous link or file
|
||||
|
||||
@@ -9,4 +9,4 @@ mkdir -p "$CONFIGSOURCE/import_files" || true
|
||||
mkdir -p "$CONFIGSOURCE/configurations" || true
|
||||
|
||||
# Make sure permissions are right
|
||||
chown -R $(id -u):$(id -g) "$CONFIGSOURCE"
|
||||
chown -R "$(id -u):$(id -g)" "$CONFIGSOURCE"
|
||||
|
||||
@@ -10,7 +10,7 @@ CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
chmod 755 $CONFIGSOURCE
|
||||
|
||||
# Check if config file is there, or create one from template
|
||||
if [ -f $CONFIGSOURCE ]; then
|
||||
if [ -f "$CONFIGSOURCE" ]; then
|
||||
echo "Using config file found in $CONFIGSOURCE"
|
||||
else
|
||||
echo "No config file, creating one from template"
|
||||
@@ -26,13 +26,13 @@ else
|
||||
curl -L -f -s $TEMPLATESOURCE --output $CONFIGSOURCE
|
||||
fi
|
||||
# Need to restart
|
||||
bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
bashio::log.fatal "Config file not found, creating a new one. Please customize the file in "$CONFIGSOURCE" before restarting."
|
||||
# bashio::exit.nok
|
||||
fi
|
||||
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed $CONFIGSOURCE &>ERROR || EXIT_CODE=$?
|
||||
yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$?
|
||||
if [ $EXIT_CODE = 0 ]; then
|
||||
echo "Config file is a valid yaml"
|
||||
else
|
||||
|
||||
@@ -31,7 +31,7 @@ RUN \
|
||||
&& curl -s -S -J -L -o /tmp/joal.tar.gz $(curl -s https://api.github.com/repos/anthonyraymond/joal/releases/latest | grep -o "http.*joal.tar.gz") >/dev/null \
|
||||
&& mkdir -p /data/joal \
|
||||
&& tar zxvf /tmp/joal.tar.gz -C /data/joal >/dev/null \
|
||||
&& chown -R $(id -u):$(id -g) /data/joal \
|
||||
&& chown -R "$(id -u):$(id -g)" /data/joal \
|
||||
&& rm /data/joal/jack-of* || true
|
||||
|
||||
##################
|
||||
|
||||
@@ -16,14 +16,14 @@ fi
|
||||
|
||||
# download latest version
|
||||
|
||||
if [ $VERBOSE = true ]; then
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
curl -J -L -o /tmp/joal.tar.gz $(curl -s https://api.github.com/repos/anthonyraymond/joal/releases/latest | grep -o "http.*joal.tar.gz")
|
||||
else
|
||||
curl -s -S -J -L -o /tmp/joal.tar.gz $(curl -s https://api.github.com/repos/anthonyraymond/joal/releases/latest | grep -o "http.*joal.tar.gz") >/dev/null
|
||||
fi
|
||||
mkdir -p /data/joal
|
||||
tar zxvf /tmp/joal.tar.gz -C /data/joal >/dev/null
|
||||
chown -R $(id -u):$(id -g) /data/joal
|
||||
chown -R "$(id -u):$(id -g)" /data/joal
|
||||
rm /data/joal/jack-of*
|
||||
bashio::log.info "Joal updated"
|
||||
|
||||
@@ -84,7 +84,7 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
|
||||
# LAUNCH APPS #
|
||||
###############
|
||||
|
||||
if [ $VERBOSE = true ]; then
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
nohup java -jar /joal/joal.jar --joal-conf=/data/joal --spring.main.web-environment=true --server.port="8081" --joal.ui.path.prefix=${UIPATH} --joal.ui.secret-token=$TOKEN
|
||||
else
|
||||
nohup java -jar /joal/joal.jar --joal-conf=/data/joal --spring.main.web-environment=true --server.port="8081" --joal.ui.path.prefix=${UIPATH} --joal.ui.secret-token=$TOKEN >/dev/null
|
||||
|
||||
@@ -17,4 +17,4 @@ if [ -d /data/config ]; then
|
||||
fi
|
||||
|
||||
# Make sure permissions are right
|
||||
chown -R $(id -u):$(id -g) $CONFIGLOCATION
|
||||
chown -R "$(id -u):$(id -g)" $CONFIGLOCATION
|
||||
|
||||
@@ -5,39 +5,39 @@ JSONTOCHECK='/config/transmission/settings.json'
|
||||
JSONSOURCE='/defaults/settings.json'
|
||||
|
||||
# If json already exists
|
||||
if [ -f ${JSONTOCHECK} ]; then
|
||||
if [ -f "${JSONTOCHECK}" ]; then
|
||||
# Variables
|
||||
echo "Checking settings.json format"
|
||||
|
||||
# Check if json file valid or not
|
||||
jq . -S ${JSONTOCHECK} &>/dev/null && ERROR=false || ERROR=true
|
||||
jq . -S "${JSONTOCHECK}" &>/dev/null && ERROR=false || ERROR=true
|
||||
if [ $ERROR = true ]; then
|
||||
bashio::log.fatal "Settings.json structure is abnormal, restoring options from scratch. Your old file is renamed as settings.json_old"
|
||||
mv ${JSONSOURCE} ${JSONSOURCE}_old
|
||||
cp ${JSONSOURCE} ${JSONTOCHECK}
|
||||
mv "${JSONSOURCE}" "${JSONSOURCE}"_old
|
||||
cp "${JSONSOURCE}" "${JSONTOCHECK}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get the default keys from the original file
|
||||
mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE})
|
||||
mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
|
||||
|
||||
# Check if all keys are still there, or add them
|
||||
# spellcheck disable=SC2068
|
||||
# shellcheck disable=SC2086
|
||||
for KEYS in "${arr[@]}"; do
|
||||
# Check if key exists
|
||||
KEYSTHERE=$(jq "has(\"${KEYS}\")" ${JSONTOCHECK})
|
||||
KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}")
|
||||
if [ "$KEYSTHERE" != "true" ]; then
|
||||
#Fetch initial value
|
||||
JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" ${JSONSOURCE})
|
||||
JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}")
|
||||
#Add key
|
||||
sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," ${JSONTOCHECK}
|
||||
sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}"
|
||||
# Message
|
||||
bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}"
|
||||
fi
|
||||
done
|
||||
|
||||
# Show structure in a nice way
|
||||
jq . -S ${JSONTOCHECK} | cat >temp.json && mv temp.json ${JSONTOCHECK}
|
||||
jq . -S "${JSONTOCHECK}" | cat >temp.json && mv temp.json "${JSONTOCHECK}"
|
||||
|
||||
# Message
|
||||
bashio::log.info "Your settings.json was checked and seems perfectly normal!"
|
||||
|
||||
Reference in New Issue
Block a user