comparison sbin/ftjail @ 453:5194d87e0b4b

Move "_get_mounts_at_directory()" into common.subr
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 14 May 2024 09:46:54 +0200
parents ccd6c36da449
children 263b4d382155
comparison
equal deleted inserted replaced
452:d5591ebc303d 453:5194d87e0b4b
61 . "${_p_datadir}/common.subr" 61 . "${_p_datadir}/common.subr"
62 62
63 63
64 # Reset to standard umask 64 # Reset to standard umask
65 umask 0022 65 umask 0022
66
67
68 #:
69 #: Search for mounts and sub-mounts at a given directory.
70 #:
71 #: The output is sorted by the mountpoint.
72 #:
73 #: Args:
74 #: $1: the directory where to start for mounts and sub-mounts
75 #:
76 #: Output (stdout):
77 #: The sorted list (lines) of mounts in :manpage:`fstab(5)` format.
78 #: This list may be empty.
79 #:
80 #: Exit:
81 #: 1: on fatal errors (usage et al.)
82 #:
83 #: Important:
84 #: The input directory **must** be an absolute path.
85 #:
86 _get_mounts_at_directory() {
87 local _directory
88
89 local _fstab
90
91 _directory=${1-}
92 case "${_directory}" in
93 */)
94 echo "ERROR: a trailing slash in directory name given" 1>&2;
95 exit 1;
96 ;;
97 /*)
98 :
99 ;;
100 '')
101 echo "ERROR: no directory given" 1>&2;
102 exit 1;
103 ;;
104 *)
105 echo "ERROR: directory must be an absolute path" 1>&2;
106 exit 1;
107 ;;
108 esac
109 _fstab="$(mount -p | awk -v pa1="^${_directory}\$" -v pa2="^${_directory}/" '($2 ~ pa1) || ($2 ~ pa2 ) { print; }' | sort -k3)"
110 echo "${_fstab}"
111 }
112 66
113 67
114 # 68 #
115 # PARENT-BASE NAME DRY-RUN 69 # PARENT-BASE NAME DRY-RUN
116 # 70 #