54 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/bash
 | |
| # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
 | |
| source "$(dirname "$0")/lib/ulib/ulib" || exit 1
 | |
| urequire DEFAULTS
 | |
| 
 | |
| function display_help() {
 | |
|     uecho "$scriptname: forcer le mode d'une liste de fichiers
 | |
| 
 | |
| USAGE
 | |
|     $scriptname [options] [dirs|files....]
 | |
| 
 | |
| Le mode forcé pour les répertoires est rwxr-xr-x
 | |
| Le mode forcé pour les fichiers est rw-r--r--
 | |
| 
 | |
| OPTIONS
 | |
|     -x, --executable
 | |
|         Forcer le mode rwX-r-Xr-X pour les fichiers"
 | |
| }
 | |
| 
 | |
| executable=
 | |
| parse_opts "${PRETTYOPTS[@]}" \
 | |
|     --help '$exit_with display_help' \
 | |
|     -x,--executable executable=1 \
 | |
|     @ args -- "$@" && set -- "${args[@]}" || die "$args"
 | |
| 
 | |
| [ $# -gt 0 ] || set -- .
 | |
| 
 | |
| dmode=755
 | |
| if [ -n "$executable" ]; then
 | |
|     fmode=u=rwX,g=rX,o=rX
 | |
| else
 | |
|     fmode=644
 | |
| fi
 | |
| 
 | |
| r=0
 | |
| for i in "$@"; do
 | |
|     if [ -d "$i" ]; then
 | |
|         etitle "$i"
 | |
|         estep "correction répertoires"
 | |
|         find "$i" -type d -print -exec chmod "$dmode" {} \; || r=$?
 | |
|         estep "correction fichiers"
 | |
|         find "$i" -type f -print -exec chmod "$fmode" {} \; || r=$?
 | |
|         eend
 | |
|     elif [ -f "$i" ]; then
 | |
|         estep "$i"
 | |
|         chmod "$fmode" "$i" || r=$?
 | |
|     else
 | |
|         eerror "$i: fichier introuvable"
 | |
|         r=1
 | |
|     fi
 | |
| done
 | |
| 
 | |
| exit $r
 | 
