Rendere le directory eseguibili: differenze tra le versioni
Da Slacky.eu.
(→Script) |
(→Download) |
||
| (2 revisioni intermedie di un utente non mostrate) | |||
| Riga 2: | Riga 2: | ||
= Descrizione = |
= Descrizione = |
||
Questo script rende tutte le directory eseguibili o non eseguibili in modo ricorsivo (Serve specialmente quando abbiamo sbagliato a giocare con chmod). |
Questo script rende tutte le directory eseguibili o non eseguibili in modo ricorsivo (Serve specialmente quando abbiamo sbagliato a giocare con chmod). |
||
| + | |||
= Download = |
= Download = |
||
http://www.slacky.eu/misto/concorso/nitrogl/dirx.sh |
http://www.slacky.eu/misto/concorso/nitrogl/dirx.sh |
||
| + | <br />La versione qui sotto è più aggiornata di quella presente in questo link. |
||
| + | |||
= Script = |
= Script = |
||
<pre> |
<pre> |
||
Versione attuale delle 06:32, 21 mar 2010
[modifica] Descrizione
Questo script rende tutte le directory eseguibili o non eseguibili in modo ricorsivo (Serve specialmente quando abbiamo sbagliato a giocare con chmod).
[modifica] Download
http://www.slacky.eu/misto/concorso/nitrogl/dirx.sh
La versione qui sotto è più aggiornata di quella presente in questo link.
[modifica] Script
#!/bin/bash
# ======================================================================
# Date : Cagliari, 14 october 2007
# Author : Roberto Paolo Antonio Metere
# ======================================================================
#
# This script recursively makes all directories (not)executable by: a u g o
#
dir=""
permtype=""
firstp="false"
verbose=0
arg[0]="$0"
arg[1]="$1"
arg[2]="$2"
arg[3]="$3"
arg[4]="$4"
# Permissions
permissions="u+ g+ o+ ug+ gu+ go+ og+ uo+ ou+ ugo+ uog+ oug+ ogu+ gou+ guo+ a+ u- g- o- ug- gu- go- og- uo- ou- ugo- uog- oug- ogu- gou- guo- a-"
numpermissions=0
for i in $permissions
do
numpermissions=$(($numpermissions + 1))
done
# Error function. It will return to the shell if any error occurs
Error ()
{
error_code="$1"
ERRORS[0]="no errors occurred"
ERRORS[1]="too many arguments given"
ERRORS[2]="no argument given"
ERRORS[3]="wrong permission type or directory does not exists"
ERRORS[4]="missing permission type"
ERRORS[5]="argument after the permission string detected.\n (You cannot exchange the order of the syntax)"
if [ "$error_code" -gt "0" ]
then
# Print internal error and usage
printf "\n ERROR: ${ERRORS[$error_code]}."
printf "\n Syntax: ${arg[0]} [-v] [directory] permissiontype\n"
printf "\n -v : if you want the script more verbose"
printf "\n it could be only the first argument\n"
printf "\n directory : target directory. You can omit the"
printf "\n directory: the default one is the"
printf "\n current. Must be BEFORE permissiontype\n"
printf "\n permission type : should be any of the follows"
printf "\n u+ g+ o+ ug+ gu+ go+ og+ uo+ ou+ ugo+"
printf "\n uog+ oug+ ogu+ gou+ guo+ a+ u- g- o-"
printf "\n ug- gu- go- og- uo- ou- ugo- uog- oug-"
printf "\n ogu- gou- guo- a-"
printf "\n Where u means user"
printf "\n g means group"
printf "\n o means others"
printf "\n a means all (ugo)"
printf "\n + means executable"
printf "\n - means not-executable\n\n"
# Exit
exit 1
else
printf "\n ERROR: ${ERRORS[$error_code]}.\n\n"
fi
}
# Verbose or not
if [ "${arg[1]}" == "-v" ]
then
verbose=1
arg[1]="${arg[2]}"
arg[2]="${arg[3]}"
arg[3]="${arg[4]}"
fi
# Welcome screen
if [ "$verbose" -eq "1" ]
then
printf "\n ========================================================="
printf "\n Makes directories executable recursively - by NitroGL "
printf "\n =========================================================\n\n"
fi
# check the third argument (too many arguments)
if [ "${arg[3]}" != "" ]
then
Error 1
fi
# check the first argument
if [ "${arg[1]}" != "" ]
then
if test -d "${arg[1]}"
then
if [ "$verbose" -eq "1" ]
then
printf "\n First argument accepted: directory" # VERBOSITY
fi
dir="${arg[1]}"
firstp="false"
else
i=1
while [ "$i" -le "$numpermissions" ]
do
if [ "${arg[1]}" == "`echo "$permissions" | awk '{print $'$i'}'`" ]
then
if [ "$verbose" -eq "1" ]
then
printf "\n First argument accepted: permission"
fi
permtype="${arg[1]}"x
firstp="true"
i=$(($numpermissions + 1))
fi
i=$(($i + 1))
done
if [ "$permtype" == "" ]
then
Error 3
fi
fi
else
Error 2
fi
# check the second argument
if [ "$firstp" == "false" ]
then
i=1
while [ "$i" -le "$numpermissions" ]
do
if [ "${arg[2]}" == "`echo "$permissions" | awk '{print $'$i'}'`" ]
then
if [ "$verbose" -eq "1" ]
then
printf "\n Second argument accepted: permission"
fi
permtype="${arg[2]}"x
i=$(($numpermissions + 1))
fi
i=$(($i + 1))
done
if [ "$permtype" == "" ]
then
Error 4
fi
else
if [ "${arg[2]}" != "" ]
then
Error 1
fi
fi
# setting the directory "." if non specified
if [ "$dir" == "" ]
then
dir="."
if [ "$verbose" -eq 1 ]
then
printf "\n Default directory: current directory"
fi
fi
# if all right, work!
chmod "$permtype" "$dir";
find "$dir" -type d -exec chmod "$permtype" {} \;
if [ "$verbose" -eq "1" ]
then
Error 0
fi
exit 0
#
# Copyright (c) Roberto Metere
- Data: 21/10/2007
- Autore: Nitrogl