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
if bashio::config.true 'ssl'; then
bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths"
#set variables
bashio::log.info "SSL enabled. If web UI doesn't work, disable SSL or check your certificate paths."
CERTFILE="$(bashio::config 'certfile')"
KEYFILE="$(bashio::config 'keyfile')"
options+=(--sslcert /ssl/$CERTFILE)
options+=(--sslkey /ssl/$KEYFILE)
bashio::log.info "... ssl activated"
options+=(--sslcert /ssl/"$CERTFILE")
options+=(--sslkey /ssl/"$KEYFILE")
bashio::log.info "... SSL activated."
fi
################
# SET PASSWORD #
################
# Set password
CURRENTPASSWORD=""
PASSWORD="$(bashio::config 'password')"
# Set up the initial password
PASSWORD_FILE="/data/portainer_password"
HIDDEN_FILE="/data/hidden"
PASSWORD="${PASSWORD:-empty}"
if ! bashio::config.has_value 'password'; then
PASSWORD="empty"
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
if bashio::fs.file_exists "/data/hidden"; then
if [ "$CURRENTPASSWORD" != "$PASSWORD" ]; then
if bashio::fs.file_exists "$HIDDEN_FILE"; then
if [[ "$CURRENTPASSWORD" != "$PASSWORD" ]]; then
mv -f /data/portainer.db /data/portainer.old || true
rm /data/hidden || true
bashio::log.warning "... password changed, database reseted. Previous version stored in /share/portainer_$(date +%m-%d-%Y)_$RANDOM.backup"
rm "$HIDDEN_FILE" || true
bashio::log.warning "... password changed, database reset. Previous version stored in /share/portainer_$(date +%m-%d-%Y)_$RANDOM.backup"
fi
fi
# Define option
if bashio::config.has_value 'password' ; then
echo -n "${PASSWORD:-empty}" > /data/portainer_password
options+=(--admin-password-file /data/portainer_password)
bashio::log.info "... password set according to addon options"
echo -n "${PASSWORD:-empty}" > "$PASSWORD_FILE"
if bashio::config.has_value 'password'; then
options+=(--admin-password-file "$PASSWORD_FILE")
bashio::log.info "... password set according to add-on options."
else
echo -n "${PASSWORD:-empty}" > /data/portainer_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 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"
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 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."
fi
###################
@@ -67,24 +69,24 @@ fi
###################
# Hide Hassio containers by default, but only enforce on first run
if ! bashio::fs.file_exists "/data/hidden"; then
options+=(--hide-label io.hass.type=supervisor)
options+=(--hide-label io.hass.type=homeassistant)
options+=(--hide-label io.hass.type=base)
options+=(--hide-label io.hass.type=core)
# options+=(--hide-label io.hass.type=addon)
options+=(--hide-label io.hass.type=audio)
options+=(--hide-label io.hass.type=cli)
options+=(--hide-label io.hass.type=dns)
options+=(--hide-label io.hass.type=multicast)
options+=(--hide-label io.hass.type=observer)
bashio::log.info "... non-addon containers hidden"
touch /data/hidden
if ! bashio::fs.file_exists "$HIDDEN_FILE"; then
options+=(--hide-label io.hass.type=supervisor)
options+=(--hide-label io.hass.type=homeassistant)
options+=(--hide-label io.hass.type=base)
options+=(--hide-label io.hass.type=core)
# options+=(--hide-label io.hass.type=addon)
options+=(--hide-label io.hass.type=audio)
options+=(--hide-label io.hass.type=cli)
options+=(--hide-label io.hass.type=dns)
options+=(--hide-label io.hass.type=multicast)
options+=(--hide-label io.hass.type=observer)
bashio::log.info "... non-addon containers hidden."
touch "$HIDDEN_FILE"
fi
####################
# LAUNCH PORTAINER #
####################
bashio::log.info "... portainer launched"
bashio::log.info "... launching Portainer."
exec /opt/portainer/portainer "${options[@]}"