Files
HAddons/sambanas/rootfs/etc/s6-overlay/s6-rc.d/cifs-supervisor-mount/run
ai-dev 4957b52f3a test
2025-10-11 12:15:25 +02:00

58 lines
2.6 KiB
Plaintext

#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Amoutomount Shares with new system!
# ==============================================================================
if [ -f /tmp/cifs_network ]; then
#bashio::log.level all
bashio::log.info "Automount Shares..."
ipaddress=$(bashio::addon.ip_address)
#username=$(bashio::config 'username')
#password=$(bashio::config 'password')
username=$(jq -r '.username' </tmp/auth.json)
password=$(jq -r '.password' </tmp/auth.json)
available_shares=$(awk '/\[(.*)\]/{ DISK=substr($1,2,length($1)-2); next } /.*path =(.*)/{ printf "%s\n",DISK,$0 }' /etc/samba/smb.conf)
#info=$(bashio::api.supervisor GET /host/info false)
#bashio::log "Info: ${info}"
#mounts=$(bashio::api.supervisor GET /mounts false)
#bashio::log "Mounts: ${mounts}"
#status=$(smbcontrol smbd ping)
#bashio::log "Samba Ready: ${status}"
#bashio::log "Children: $(smbcontrol smbd num-children)"
bashio::log.info "Wait Samba Server to going up..(max 60s)"
# timeout 30 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' ${ipaddress/\/*/} 445
bashio::net.wait_for 445 ${ipaddress/\/*/} 60
# smbstatus
while read -r -a device; do
[[ ${device,,} == @(share|config|addons|ssl|backup|media|addon_configs|homeassistant) ]] && continue
usage=$(jq -r --arg xshare "$device" '.acl[] | select(.share==$xshare) | .usage // "media"' <<<"$(bashio::addon.config)")
cmdshare=$(jq -nrc --arg usage "${usage:-media}" --arg share "$device" --arg ip "${ipaddress/\/*/}" --arg user "$username" --arg pwd "$password" '.name=$share|.usage=$usage|.type="cifs"|.server=$ip|.share=$share|.username=$user|.password=$pwd')
#bashio::log.info $(jq '.password="********"' <<<${cmdshare})
#bashio::log.info $(bashio::api.supervisor GET /mounts)
#bashio::log.info $(bashio::api.supervisor GET /mounts | jq -r --arg xshare "$device" '.mounts[] | select(.name == $xshare ) // empty')
if [[ ! -z $(bashio::api.supervisor GET /mounts | jq -r --arg xshare "$device" '.mounts[] | select(.name == $xshare ) // empty') ]]; then
bashio::log.info "Share Already Found ${device} - Remove!"
bashio::api.supervisor DELETE /mounts/${device} || true
fi
for rt in {1..3}; do
status=$(bashio::api.supervisor POST /mounts "${cmdshare}") && break
bashio::log.warning "Retry ${rt}/3 Error Automount ${device} Msg: $(jq -c '.password="********"' <<<${cmdshare})"
sleep 3
done
done <<<"${available_shares}"
fi