Style, best-practise and efficiency fixes.

This commit is contained in:
clewsy 2020-02-20 21:45:17 +11:00
parent 6e6de7b85f
commit 704c00e286

View file

@ -5,6 +5,9 @@
# ============================================================================== # ==============================================================================
readonly CONF='/data/motioneye/motioneye.conf' readonly CONF='/data/motioneye/motioneye.conf'
readonly MOTION='/data/motioneye/motion.conf' readonly MOTION='/data/motioneye/motion.conf'
declare button_type
declare camera_number
declare button_command
# Ensure configuration exists # Ensure configuration exists
if ! bashio::fs.directory_exists '/data/motioneye'; then if ! bashio::fs.directory_exists '/data/motioneye'; then
@ -43,21 +46,21 @@ fi
# Remove any existing action buttons before recreating # Remove any existing action buttons before recreating
for old_action in lock unlock light alarm up right down left zoom preset; do for old_action in lock unlock light alarm up right down left zoom preset; do
if ls /data/motioneye/${old_action}* > /dev/null 2>&1; then find /data/motioneye/. -name "action*" -delete
rm /data/motioneye/${old_action}*
fi
done done
# Creates action button scripts if any are configured # Creates action button scripts if any are configured
if bashio::config.has_value 'action_buttons'; then if bashio::config.has_value 'action_buttons'; then
bashio::log.info "Configuring action buttons." bashio::log.info "Configuring action buttons."
for button in $(bashio::config "action_buttons|keys"); do for button in $(bashio::config "action_buttons|keys"); do
BUTTON_TYPE=$(bashio::config "action_buttons[${button}].type") button_type=$(bashio::config "action_buttons[${button}].type")
CAMERA_NUMBER=$(bashio::config "action_buttons[${button}].camera") camera_number=$(bashio::config "action_buttons[${button}].camera")
BUTTON_COMMAND=$(bashio::config "action_buttons[${button}].command") button_command=$(bashio::config "action_buttons[${button}].command")
bashio::log.debug "File: ${BUTTON_TYPE}_${CAMERA_NUMBER}, Command: ${BUTTON_COMMAND}" bashio::log.debug "File: ${button_type}_${camera_number}, Command: ${button_command}"
echo "#!/bin/bash" > "/data/motioneye/${BUTTON_TYPE}_${CAMERA_NUMBER}" {
echo "${BUTTON_COMMAND}" >> "/data/motioneye/${BUTTON_TYPE}_${CAMERA_NUMBER}" echo "#!/bin/bash"
chmod +x "/data/motioneye/${BUTTON_TYPE}_${CAMERA_NUMBER}" echo "${button_command}"
} > "/data/motioneye/${button_type}_${camera_number}"
chmod +x "/data/motioneye/${button_type}_${camera_number}"
done done
fi fi