Last active
April 11, 2018 20:49
-
-
Save tavinus/5a57c54d7303ec0a8cff9dcfc4b1bad4 to your computer and use it in GitHub Desktop.
Reseta permissões de um Autosystem Instalado (linux)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ######################################### | |
| # as_fix_permissions.sh | |
| # | |
| # Tenta resolver problemas com permissões | |
| # Deve ser rodado depois do as_update | |
| # | |
| # wget -O as_fix_permissions.sh 'https://gist.githubusercontent.com/tavinus/5a57c54d7303ec0a8cff9dcfc4b1bad4/raw' && chmod +x as_fix_permissions.sh | |
| # | |
| ######################################### | |
| VERSION=0.0.3 | |
| TRUE=0 | |
| FALSE=1 | |
| # Para detectar erros | |
| f=0 | |
| # Locais | |
| INSTLOC='/usr/local/bin' | |
| FOLDER_CHMOD='775' | |
| FILE_CHMOD='664' | |
| if [[ -z "$REALUSER" ]]; then | |
| [ $SUDO_USER ] && REALUSER=$SUDO_USER || REALUSER=`whoami` | |
| REALHOME="/home/$REALUSER" | |
| fi | |
| PERM_FOLDERS="$REALHOME/.autosystem $REALHOME/.autosystem/log" | |
| PERM_FILES="$REALHOME/.autosystem3.log /etc/autosystem.db /etc/autosystem.key $REALHOME/autosystem3.log" | |
| PERM_LIST="$PERM_FOLDERS $PERM_FILES" | |
| print_version() { | |
| echo "AutoSystem FixPermissions by Tavinus v$VERSION" | |
| } | |
| # checa se root | |
| check_root() { | |
| if [ "$(id -u)" != "0" ]; then | |
| print_version | |
| echo "Voce tem que rodar o instalador com privilegios de root." | |
| echo "Tente:" | |
| echo " sudo $0" | |
| exit 1 | |
| fi | |
| } | |
| chmod_rec() { | |
| ret=0 | |
| if ! is_file $1 && ! is_dir $1; then | |
| echo " > Fail" | |
| echo "Erro, item: $1 nao foi encontrado no disco!" | |
| return 35 | |
| fi | |
| find "$1" -type d -exec chmod "$FOLDER_CHMOD" {} \; | |
| ((ret=$ret+$?)) | |
| find "$1" -type f -exec chmod "$FILE_CHMOD" {} \; | |
| ((ret=$ret+$?)) | |
| return $ret | |
| } | |
| is_empty() { | |
| [[ -z "$1" ]] && return $TRUE | |
| return $FALSE | |
| } | |
| is_file() { | |
| is_empty "$1" && return $FALSE | |
| [[ -f "$1" ]] && return $TRUE | |
| return $FALSE | |
| } | |
| is_dir() { | |
| is_empty "$1" && return $FALSE | |
| [[ -d "$1" ]] && return $TRUE | |
| return $FALSE | |
| } | |
| ##### COMECA AQUI | |
| check_root | |
| print_version | |
| echo | |
| echo "Processando lista de permissoes" | |
| echo $'Mudando permissoes para arquivos e pastas\n' | |
| for p in $PERM_LIST; do | |
| echo -ne " > $p" | |
| chmod_rec "$p" && echo " > Ok" | |
| done | |
| echo $'\nTudo feito!\n' | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment