Hey everyone, I recently opened a PR on the official The Lounge addon in order to add user management to the platform for custom usernames, multiple users, and easy user creation/deletion.
I have added some relevant scripting to the startup bash script and I need to find a way to search a config entry for a matching string to see if the username loaded from a file exists in the users list in config. This allows for users removed from config to be deleted on next startup. I have already implemented the user creation system and I simply need to find a way to accomplish the commented out section of lines 34/35.
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: The Lounge
# This installs any requested themes and adds/removes users using config key
# ==============================================================================
export THELOUNGE_HOME=/data/thelounge
if ! bashio::fs.directory_exists "/data/thelounge";
then
bashio::log.info "No user directory found. Creating /thelounge/users/..."
mkdir -p /data/thelounge/users
if bashio::config.is_empty "users";
then
bashio::log.info "Users config entry empty. Creating default hassio user."
cp /etc/thelounge/users/hassio.json /data/thelounge/users
fi
fi
# Create users defined in config using thelounge shell
for user in $(bashio::config "users")
do
if ! bashio::fs.file_exists "${user}.json";
then
bashio::log.info "Creating new user with default password 'hassio': ${user}";
cp /etc/thelounge/users/hassio.json /data/thelounge/users/"${user}.json"
fi
done
# Delete users not in config
for userfile in data/thelounge/users
do
fileusername=${userfile::-5}
# if bashio::config "users" contains fileusername all good
# else /usr/local/bin/thelounge remove "${fileusername}"
done
# Install themes
for theme in $(bashio::config "themes")
do
/usr/local/bin/thelounge install "${theme}"
done
Link to file: thelounge.sh (Github Gist)
Essentially, bashio::config “users” contains a list of usernames (passwords default to hassio) and line 33 removes the .json and assigns it to fileusername. I would like to be able to check if the value of fileusername exists in the hassio config users entry. If it does not, then the user is deleted.
The Lounge uses the json filename as the username and has a hashed password inside of the json file, but I simply copy the hassio.json file with a new name in order to create a new user while also using the same default password.
Any help would be greatly appreciated, and feel free to comment any questions or concerns. Thanks.