Make username and password optional

This commit is contained in:
ViViDboarder 2023-12-07 09:12:19 -08:00
parent 1175215a2d
commit 061d88d8af
4 changed files with 35 additions and 21 deletions

View File

@ -29,8 +29,8 @@ options:
cron: "" cron: ""
delete: false delete: false
credentials: credentials:
username: homeassistant username: null
password: homeassistant password: null
tls: tls:
ssl: false ssl: false
certfile: fullchain.pem certfile: fullchain.pem

View File

@ -2,11 +2,19 @@
bashio::log.info "Configuring rclone..." bashio::log.info "Configuring rclone..."
bashio::config.require.username 'credentials.username' if bashio::config.true 'tls.ssl'; then
bashio::config.require.password 'credentials.password' bashio::config.require.ssl 'tls' 'tls.certfile' 'tls.keyfile'
else
bashio::log.warning
bashio::log.warning "It's recommended to set tsl settings if exposing to the network and not through the proxy."
bashio::log.warning
fi
bashio::config.suggest.true 'tls.ssl' if ! bashio::config.has_value 'credentials.username' || ! bashio::config.has_value 'credentials.password'; then
bashio::config.require.ssl 'tls' 'tls.certfile' 'tls.keyfile' bashio::log.warning
bashio::log.warning "It's recommended to set credentials.username and credentials.password settings if exposing to the network and not through the proxy."
bashio::log.warning
fi
echo "$(bashio::config 'cron') /run_rclone.sh" >> /etc/crontabs/root echo "$(bashio::config 'cron') /run_rclone.sh" >> /etc/crontabs/root
crontab -l crontab -l

View File

@ -4,23 +4,25 @@ bashio::log.info "Starting rclone web..."
# Configure tls # Configure tls
if bashio::config.true 'tls.ssl'; then if bashio::config.true 'tls.ssl'; then
ssl_flags=(\ bashio::config.require.ssl 'tls' 'tls.certfile' 'tls.keyfile'
"--rc-cert" "/ssl/$(bashio::config 'tls.certfile')" \ rclone_flags=(\
"--rc-key" "/ssl/$(bashio::config 'tls.keyfile')" \ "--rc-cert" "/ssl/$(bashio::config 'tls.certfile')" \
) "--rc-key" "/ssl/$(bashio::config 'tls.keyfile')" \
)
fi fi
# TODO: Something with UN and PASS # Optionally set a user and pass
# Maybe switch to --rc-no-auth and use proxy if bashio::config.has_value 'credentials.username' && bashio::config.has_value 'credentials.password'; then
username=$(bashio::config 'credentials.username') rclone_flags+=("--rc-user" "$(bashio::config 'credentials.username')")
password=$(bashio::config 'credentials.password') rclone_flags+=("--rc-pass" "$(bashio::config 'credentials.password')")
else
rclone_flags+=("--rc-no-auth")
fi
exec rclone rcd \ exec rclone rcd \
--rc-web-gui \ --rc-web-gui \
--rc-serve \ --rc-serve \
--rc-addr :5572 \ --rc-addr :5572 \
--rc-user "$username" \
--rc-pass "$password" \
--rc-web-gui-update \ --rc-web-gui-update \
--rc-web-gui-no-open-browser \ --rc-web-gui-no-open-browser \
"${ssl_flags[@]}" "${rclone_flags[@]}"

View File

@ -5,9 +5,6 @@ bashio::log.info "Running rclone..."
SYNC_COMMAND=$(bashio::config 'sync_command') SYNC_COMMAND=$(bashio::config 'sync_command')
DESTINATION=$(bashio::config 'destination') DESTINATION=$(bashio::config 'destination')
USERNAME=$(bashio::config 'credentials.username')
PASSWORD=$(bashio::config 'credentials.password')
set +x set +x
FILTER='{"IncludeRule": ["*.tar"]}' FILTER='{"IncludeRule": ["*.tar"]}'
@ -17,4 +14,11 @@ fi
bashio::log.info "Filter: $FILTER" bashio::log.info "Filter: $FILTER"
rclone rc --user "$USERNAME" --pass "$PASSWORD" "sync/$SYNC_COMMAND" srcFs=/backup "dstFs=$DESTINATION" _async=true _filter="$FILTER"
# Maybe add the username and password
if bashio::config.has_value 'credentials.username' && bashio::config.has_value 'credentials.password'; then
rclone_flags+=("--rc-user" "$(bashio::config 'credentials.username')")
rclone_flags+=("--rc-pass" "$(bashio::config 'credentials.password')")
fi
rclone rc "${rclone_flags[@]}" "sync/$SYNC_COMMAND" srcFs=/backup "dstFs=$DESTINATION" _async=true _filter="$FILTER"