#!/bin/sh
#
# shellcheck disable=
#
# Copyright (c) 2021-2026 openmediavault plugin developers
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#

export LC_ALL=C.UTF-8

# Expand globs in the branch path, but do not split it on whitespace.
IFS=''

if [ -n "${1}" ]; then
  for dir in ${1}; do
    if [ "${dir}" = ".." ] || [ "${dir}" = "." ]; then
      continue
    fi
    if [ "$(basename "${dir}")" = "lost+found" ]; then
      continue
    fi
    if [ -d "${dir}" ]; then
      mnt="$(findmnt --first-only --noheadings --output TARGET --target "${dir}")"
      if [ -z "${mnt}" ] || [ "${mnt}" = "/" ]; then
        continue
      fi
      echo "${mnt}"
    fi
  done
fi | sort -u
