2 # Convert an ls-style permission string, like drwxr----x and -rw-r-x-wx
3 # to the equivalent chmod --mode (-m) argument, (=,u=rwx,g=r,o=x and
4 # =,u=rw,g=rx,o=wx). Ignore ACLs.
6 # Copyright (C) 2000, 2005 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *) echo "$0: wrong number of arguments" 1>&2
24 echo "Usage: $0 ls-style-mode-string" 1>&2
29 [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
30 [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]+) ;;
31 *) echo "$0: invalid mode string: $rwx" 1>&2; exit 1;;
34 # Perform these conversions:
39 # The `T' and `t' ones are only valid for `other'.
40 s='s/S/@/;s/s/x@/;s/@/s/'
41 t='s/T/@/;s/t/x@/;s/@/t/'
43 u=`echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s`
44 g=`echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s`
45 o=`echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t`