Leaner code

This commit is contained in:
Alexandre
2024-10-06 14:28:35 +02:00
committed by GitHub
parent 3992402cca
commit 906e6fe8cc

View File

@@ -19,47 +19,49 @@ options+=(--host unix:///var/run/docker.sock)
bashio::config.require.ssl bashio::config.require.ssl
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths" bashio::log.info "SSL enabled. If web UI doesn't work, disable SSL or check your certificate paths."
#set variables
CERTFILE="$(bashio::config 'certfile')" CERTFILE="$(bashio::config 'certfile')"
KEYFILE="$(bashio::config 'keyfile')" KEYFILE="$(bashio::config 'keyfile')"
options+=(--sslcert /ssl/$CERTFILE) options+=(--sslcert /ssl/"$CERTFILE")
options+=(--sslkey /ssl/$KEYFILE) options+=(--sslkey /ssl/"$KEYFILE")
bashio::log.info "... ssl activated" bashio::log.info "... SSL activated."
fi fi
################ ################
# SET PASSWORD # # SET PASSWORD #
################ ################
# Set password # Set up the initial password
CURRENTPASSWORD="" PASSWORD_FILE="/data/portainer_password"
PASSWORD="$(bashio::config 'password')" HIDDEN_FILE="/data/hidden"
PASSWORD="${PASSWORD:-empty}"
if ! bashio::config.has_value 'password'; then if ! bashio::config.has_value 'password'; then
PASSWORD="empty" PASSWORD="empty"
fi fi
touch "/data/portainer_password"
CURRENTPASSWORD="$( cat /data/portainer_password )" # Check current password
CURRENTPASSWORD=""
touch "$PASSWORD_FILE"
CURRENTPASSWORD="$(cat "$PASSWORD_FILE")"
# Reset password if not first run # Reset password if not first run
if bashio::fs.file_exists "/data/hidden"; then if bashio::fs.file_exists "$HIDDEN_FILE"; then
if [ "$CURRENTPASSWORD" != "$PASSWORD" ]; then if [[ "$CURRENTPASSWORD" != "$PASSWORD" ]]; then
mv -f /data/portainer.db /data/portainer.old || true mv -f /data/portainer.db /data/portainer.old || true
rm /data/hidden || true rm "$HIDDEN_FILE" || true
bashio::log.warning "... password changed, database reseted. Previous version stored in /share/portainer_$(date +%m-%d-%Y)_$RANDOM.backup" bashio::log.warning "... password changed, database reset. Previous version stored in /share/portainer_$(date +%m-%d-%Y)_$RANDOM.backup"
fi fi
fi fi
# Define option # Define option
if bashio::config.has_value 'password' ; then echo -n "${PASSWORD:-empty}" > "$PASSWORD_FILE"
echo -n "${PASSWORD:-empty}" > /data/portainer_password if bashio::config.has_value 'password'; then
options+=(--admin-password-file /data/portainer_password) options+=(--admin-password-file "$PASSWORD_FILE")
bashio::log.info "... password set according to addon options" bashio::log.info "... password set according to add-on options."
else else
echo -n "${PASSWORD:-empty}" > /data/portainer_password bashio::log.info "... starting without predefined password."
bashio::log.info "... starting without predefined password" bashio::log.warning "If this is your first boot, you have a 5 minutes time period to perform the initial set-up."
bashio::log.warning "If this is your first boot, you have a 5 minutes time period to perform the initial set-up" bashio::log.warning "If you don't do it, you would be faced with a 404 error and will need to restart the add-on to access the set-up page."
bashio::log.warning "If you don't do it, you would be faced with a 404 error and will need to restart the addon to access the set-up page"
fi fi
################### ###################
@@ -67,7 +69,7 @@ fi
################### ###################
# Hide Hassio containers by default, but only enforce on first run # Hide Hassio containers by default, but only enforce on first run
if ! bashio::fs.file_exists "/data/hidden"; then if ! bashio::fs.file_exists "$HIDDEN_FILE"; then
options+=(--hide-label io.hass.type=supervisor) options+=(--hide-label io.hass.type=supervisor)
options+=(--hide-label io.hass.type=homeassistant) options+=(--hide-label io.hass.type=homeassistant)
options+=(--hide-label io.hass.type=base) options+=(--hide-label io.hass.type=base)
@@ -78,13 +80,13 @@ if ! bashio::fs.file_exists "/data/hidden"; then
options+=(--hide-label io.hass.type=dns) options+=(--hide-label io.hass.type=dns)
options+=(--hide-label io.hass.type=multicast) options+=(--hide-label io.hass.type=multicast)
options+=(--hide-label io.hass.type=observer) options+=(--hide-label io.hass.type=observer)
bashio::log.info "... non-addon containers hidden" bashio::log.info "... non-addon containers hidden."
touch /data/hidden touch "$HIDDEN_FILE"
fi fi
#################### ####################
# LAUNCH PORTAINER # # LAUNCH PORTAINER #
#################### ####################
bashio::log.info "... portainer launched" bashio::log.info "... launching Portainer."
exec /opt/portainer/portainer "${options[@]}" exec /opt/portainer/portainer "${options[@]}"