From bc8da539a990523cc3ff6e85d47a68399873517e Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 22 Aug 2022 10:18:37 +0200 Subject: [PATCH] Uses PUID and PGID to mount local shares https://github.com/alexbelgium/hassio-addons/issues/433 --- .templates/92-local_mounts.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.templates/92-local_mounts.sh b/.templates/92-local_mounts.sh index b55a16f18..0e04acc9d 100644 --- a/.templates/92-local_mounts.sh +++ b/.templates/92-local_mounts.sh @@ -11,6 +11,16 @@ if bashio::config.has_value 'localdisks'; then MOREDISKS=$(bashio::config 'localdisks') echo "Local Disks mounting..." + # Mount using UID/GID values + if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then + echo "Using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')" + PUID="$(bashio::config 'PUID')" + PGID="$(bashio::config 'PGID')" + else + PUID="$(id -u)" + PGID="$(id -g)" + fi + # Separate comma separated values # shellcheck disable=SC2086 for disk in ${MOREDISKS//,/ }; do @@ -25,13 +35,13 @@ if bashio::config.has_value 'localdisks'; then # Creates dir mkdir -p /mnt/"$disk" - chown -R "$(id -u)":"$(id -g)" /mnt/"$disk" + chown -R "PUID:PGID" /mnt/"$disk" # Legacy mounting : mount to share if still exists (avoid breaking changes) # shellcheck disable=SC2015 [ -d /share/"$disk" ] && mount "$devpath"/"$disk" /share/"$disk" || true # Mount # shellcheck disable=SC2015 - mount "$devpath"/"$disk" /mnt/"$disk" && bashio::log.info "Success! $disk mounted to /mnt/$disk" || (bashio::log.fatal "Unable to mount local drives! Please check the name." && rmdir /mnt/$disk) + mount "$devpath"/"$disk" -o "uid=$PUID,gid=$PGID" /mnt/"$disk" && bashio::log.info "Success! $disk mounted to /mnt/$disk" || (bashio::log.fatal "Unable to mount local drives! Please check the name." && rmdir /mnt/$disk) done