Rendere le directory eseguibili: differenze tra le versioni
Da Slacky.eu.
(→Download) |
|||
| (4 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> |
||
#!/bin/bash |
#!/bin/bash |
||
# ====================================================================== |
# ====================================================================== |
||
| − | # Data : Cagliari, 14 october 2007 |
+ | # Date : Cagliari, 14 october 2007 |
| − | # Autore : Roberto Paolo Antonio Metere |
+ | # Author : Roberto Paolo Antonio Metere |
# ====================================================================== |
# ====================================================================== |
||
# |
# |
||
| − | # Questo script rende tutte le directory eseguibili o non eseguibili |
+ | # This script recursively makes all directories (not)executable by: a u g o |
| − | # in modo ricorsivo |
||
| − | # |
||
| − | # (Serve specialmente quando abbiamo sbagliato a giocare con chmod) |
||
# |
# |
||
dir="" |
dir="" |
||
| Riga 24: | Riga 27: | ||
arg[4]="$4" |
arg[4]="$4" |
||
| − | # Permessi |
+ | # 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-" |
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 |
numpermissions=0 |
||
| Riga 32: | Riga 35: | ||
done |
done |
||
| − | # Funzione degli errori (TORNA NELLA SHELL se ci sono errori) |
+ | # Error function. It will return to the shell if any error occurs |
Error () |
Error () |
||
{ |
{ |
||
error_code="$1" |
error_code="$1" |
||
| − | ERRORS[0]="nessun errore" |
+ | ERRORS[0]="no errors occurred" |
| − | ERRORS[1]="hai dato troppi argomenti" |
+ | ERRORS[1]="too many arguments given" |
| − | ERRORS[2]="non hai dato nessun argomento" |
+ | ERRORS[2]="no argument given" |
| − | ERRORS[3]="tipo di permessi errato o directory specificata non esistente" |
+ | ERRORS[3]="wrong permission type or directory does not exists" |
| − | ERRORS[4]="tipo di permessi omesso" |
+ | 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 ] |
+ | if [ "$error_code" -gt "0" ] |
then |
then |
||
| − | # Stampa gli errori interni e l'uso dello script |
+ | # Print internal error and usage |
| − | printf "\n ERRORE: ${ERRORS[$error_code]}." |
+ | printf "\n ERROR: ${ERRORS[$error_code]}." |
| − | printf "\n Sintassi: ${arg[0]} [-v] [directory] tipodipermessi\n" |
+ | printf "\n Syntax: ${arg[0]} [-v] [directory] permissiontype\n" |
| − | printf "\n -v : se vuoi che lo script scriva qualcosa" |
+ | printf "\n -v : if you want the script more verbose" |
| − | printf "\n puo' solamente essere il primo argomento\n" |
+ | printf "\n it could be only the first argument\n" |
| − | printf "\n directory : directory di destinazione. Puoi omettere" |
+ | printf "\n directory : target directory. You can omit the" |
| − | printf "\n la directory: quella di default e' quella" |
+ | printf "\n directory: the default one is the" |
| − | printf "\n corrente. Va PRIMA del tipodipermessi.\n" |
+ | printf "\n current. Must be BEFORE permissiontype\n" |
| − | printf "\n tipodipermessi : puo' essere uno dei seguenti:" |
+ | printf "\n permission type : should be any of the follows" |
printf "\n u+ g+ o+ ug+ gu+ go+ og+ uo+ ou+ ugo+" |
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 uog+ oug+ ogu+ gou+ guo+ a+ u- g- o-" |
||
printf "\n ug- gu- go- og- uo- ou- ugo- uog- oug-" |
printf "\n ug- gu- go- og- uo- ou- ugo- uog- oug-" |
||
printf "\n ogu- gou- guo- a-" |
printf "\n ogu- gou- guo- a-" |
||
| − | printf "\n Dove u significa utente" |
+ | printf "\n Where u means user" |
| − | printf "\n g significa gruppo" |
+ | printf "\n g means group" |
| − | printf "\n o significa altri" |
+ | printf "\n o means others" |
| − | printf "\n a significa tutti (ugo)" |
+ | printf "\n a means all (ugo)" |
| − | printf "\n + significa eseguibile" |
+ | printf "\n + means executable" |
| − | printf "\n - significa non eseguibile\n\n" |
+ | printf "\n - means not-executable\n\n" |
| − | |||
| − | # Esci |
+ | # Exit |
exit 1 |
exit 1 |
||
else |
else |
||
| − | printf "\n ERRORE: ${ERRORS[$error_code]}.\n\n" |
+ | printf "\n ERROR: ${ERRORS[$error_code]}.\n\n" |
fi |
fi |
||
} |
} |
||
| − | # Se vogliamo che il programma produca delle scritte in output scriviamo -v come primo argomento |
+ | # Verbose or not |
if [ "${arg[1]}" == "-v" ] |
if [ "${arg[1]}" == "-v" ] |
||
then |
then |
||
| Riga 82: | Riga 85: | ||
fi |
fi |
||
| − | # Schermata di benvenuto |
+ | # Welcome screen |
if [ "$verbose" -eq "1" ] |
if [ "$verbose" -eq "1" ] |
||
then |
then |
||
| − | printf "\n =============================================================" |
+ | printf "\n =========================================================" |
| − | printf "\n Rende eseguibili le directory ricorsivamente - by NitroGL " |
+ | printf "\n Makes directories executable recursively - by NitroGL " |
| − | printf "\n =============================================================\n\n" |
+ | printf "\n =========================================================\n\n" |
fi |
fi |
||
| − | # Controlla il terzo argomento (troppi argomenti) |
+ | # check the third argument (too many arguments) |
if [ "${arg[3]}" != "" ] |
if [ "${arg[3]}" != "" ] |
||
then |
then |
||
| Riga 96: | Riga 99: | ||
fi |
fi |
||
| − | # Controlla il primo argomento |
+ | # check the first argument |
if [ "${arg[1]}" != "" ] |
if [ "${arg[1]}" != "" ] |
||
then |
then |
||
| Riga 104: | Riga 107: | ||
if [ "$verbose" -eq "1" ] |
if [ "$verbose" -eq "1" ] |
||
then |
then |
||
| − | printf "\n Primo argomento accettato: directory" # verboso |
+ | printf "\n First argument accepted: directory" # VERBOSITY |
fi |
fi |
||
| Riga 119: | Riga 122: | ||
if [ "$verbose" -eq "1" ] |
if [ "$verbose" -eq "1" ] |
||
then |
then |
||
| − | printf "\n Primo argomento accettato: permesso" |
+ | printf "\n First argument accepted: permission" |
fi |
fi |
||
| Riga 138: | Riga 141: | ||
fi |
fi |
||
| − | # Controlla il secondo argomento |
+ | # check the second argument |
if [ "$firstp" == "false" ] |
if [ "$firstp" == "false" ] |
||
then |
then |
||
| Riga 149: | Riga 152: | ||
if [ "$verbose" -eq "1" ] |
if [ "$verbose" -eq "1" ] |
||
then |
then |
||
| − | printf "\n Secondo argomento accettato: permesso" |
+ | printf "\n Second argument accepted: permission" |
fi |
fi |
||
| Riga 170: | Riga 173: | ||
fi |
fi |
||
| − | # Impostazione della directory a "." se nessuna specificata |
+ | # setting the directory "." if non specified |
if [ "$dir" == "" ] |
if [ "$dir" == "" ] |
||
then |
then |
||
| Riga 177: | Riga 180: | ||
if [ "$verbose" -eq 1 ] |
if [ "$verbose" -eq 1 ] |
||
then |
then |
||
| − | printf "\n Directory di default: directory corrente" |
+ | printf "\n Default directory: current directory" |
fi |
fi |
||
fi |
fi |
||
| − | # Se tutto va bene, al lavoro! (due righe...) |
+ | # if all right, work! |
chmod "$permtype" "$dir"; |
chmod "$permtype" "$dir"; |
||
| − | find "$dir" -type d -exec chmod "$permtype" {} \ >& stdin; |
+ | find "$dir" -type d -exec chmod "$permtype" {} \; |
if [ "$verbose" -eq "1" ] |
if [ "$verbose" -eq "1" ] |
||
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