Last active
September 16, 2020 14:25
-
-
Save tavinus/24d0ddcb3b8ded9372756a41c8bcaf3d to your computer and use it in GitHub Desktop.
Autosystem Cleaner install
This file contains 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
#!/bin/bash | |
#################################################################################################### | |
## | |
## Instalador AutoSystem Cleaner para Debian, Mint e Ubuntu | |
## as_clean_install.sh | |
## | |
## One-liner: | |
## wget 'https://gist.githubusercontent.com/tavinus/24d0ddcb3b8ded9372756a41c8bcaf3d/raw/as_clean_install.sh' && sudo chmod +x as_clean_install.sh && sudo ./as_clean_install.sh | |
## | |
## Descricao: | |
## Rotina de limpeza para logs e outros arquivos temporários do AutoSystem | |
## | |
## Uso: | |
## sudo ./as_clean_install.sh | |
## | |
## Ajuda: | |
## ./as_clean_install.sh --help | |
## | |
## Gustavo Arnosti Neves - guneves <at-nospam> gmail <dot-nospam> com | |
## | |
## Original: 16 Jun 2016 | |
## Update: 10 Jun 2020 | |
## MODIFICADO PARA RODAR NO MINT 19.2 TINA XFCE 32BITS (TESTADO) | |
## POSSIVELMENTE FUNCIONARA EM DEBIAN E UBUNTU, MAS NAO FOI TESTADO | |
## | |
#################################################################################################### | |
VERSION="0.0.3" | |
QUIET=' -q' | |
ABORT=false | |
VERBOSE=false | |
IERROR=false | |
COUNTME=0 | |
LOGUSER="$(who | awk '{print $1}' | head -n 1)" | |
_INSTLOGFILE="$(pwd)/$(basename $0).log" | |
# checa se root | |
function 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 | |
} | |
function print_status { | |
cc='' | |
[[ $COUNTME -lt 10 ]] && cc="0$COUNTME" || cc="$COUNTME" | |
separador='+---------------------------------------------------------------------------------------+' | |
echo $'\n'"$separador" | |
echo '| '"$cc - $1" | |
echo "$separador"$'\n' | |
((COUNTME++)) | |
} | |
function exec_status { | |
mess_str='' | |
if [[ ! -z $2 ]]; then | |
mess_str=" - $2" | |
fi | |
if [[ $1 -eq 0 ]]; then | |
echo " => OK$mess_str" | |
else | |
IERROR=true | |
echo " => ERRO$mess_str" | |
if [[ $ABORT = true ]]; then | |
exit 2; | |
fi | |
fi | |
} | |
function print_version { | |
echo "Instalador AutoSystem Cleaner v$VERSION" | |
} | |
function print_help { | |
print_version | |
echo " | |
Uso: | |
$0 [avVh] | |
Parametros: | |
-a | --abort Cancela execucao se algum passo indicou erros | |
Padrao: nao abortar | |
-v | --verbose Exibe mensagens de execucao dentro de cada passo | |
Padrao = nao imprimir | |
-V | --version Exibe a versao do instalador e termina execucao | |
-h | --help Exibe esta ajuda e termina execucao | |
Arquivo de log sera gerado em | |
$_INSTLOGFILE | |
Exemplos: | |
$0 | |
$0 -v | |
$0 --abort -v | |
" | |
} | |
function silent { | |
if [[ $VERBOSE = true ]]; then | |
"$@" 2>&1 | tee -a "$_INSTLOGFILE" | |
else | |
"$@" 2>&1 >"$_INSTLOGFILE" | |
fi | |
} | |
######################################################### | |
## EXECUTION STARTS | |
######################################################### | |
######################################################### | |
## get options | |
TEMP=`getopt -o vVha --long verbose,version,help,abort -n "$0" -- "$@"` | |
if [ $? != 0 ] ; then echo "Opcao invalida, saindo..." >&2 ; exit 1 ; fi | |
# Note the quotes around `$TEMP': they are essential! | |
eval set -- "$TEMP" | |
while true; do | |
case "$1" in | |
-v | --verbose ) VERBOSE=true; QUIET=""; shift ;; | |
-V | --version ) print_version; exit 0 ;; | |
-h | --help ) print_help; exit 0 ;; | |
-a | --abort ) ABORT=true; shift ;; | |
-- ) shift; break ;; | |
* ) invalid_param "$1"; exit 1 ;; | |
esac | |
done | |
######################################################### | |
## checa se temos privilegios | |
check_root | |
######################################################### | |
## it begins! | |
print_version | |
print_status "Rotina de instalacao iniciada! " | |
exec_status 0 | |
######################################################### | |
## Check Distro | |
######################################################### | |
## Checar se temos os modulos LSB instalados | |
## command lsb_release &>/dev/null || echo "O 'lsb_release' nao esta instalado!"$'\nInstale e rode o instalador do AS novamente:\n sudo apt-get install lsb-release' | |
if [[ ! -f /etc/lsb-release ]]; then | |
echo "Instalando 'lsb_release' para identificar a distro atual corretamente!" | |
silent apt-get install lsb-release | |
fi | |
if [[ ! -f /etc/lsb-release ]]; then | |
echo "Erro! /etc/lsb-release nao foi encontrado!" | |
exit 4 | |
fi | |
######################################################### | |
## pega info | |
MINT=$(cat /etc/lsb-release 2>/dev/null | grep -i 'mint') | |
[[ -z $MINT ]] && DEBIAN="$(cat /etc/*release 2>/dev/null | grep -i 'PRETTY_NAME' | grep -i 'debian')" | |
[[ (-z $MINT) && (-z $DEBIAN) ]] && UBUNTU="$(cat /etc/*release 2>/dev/null | grep -i 'DISTRIB_DESCRIPTION' | grep -i 'ubuntu')" | |
#echo "MINT: $MINT DEBIAN: $DEBIAN UBUNTU: $UBUNTU" | |
######################################################### | |
## check sanidade | |
RELEASE="" | |
if [[ ! -z $MINT ]]; then | |
# adicionada checagem para novos Linux Mint (v18+) | |
RELEASE="$(bash <(cat /etc/os-release; echo 'echo ${UBUNTU_CODENAME/*, /}') | head -n1 | awk '{print tolower($1);}')" | |
[[ -z "$RELEASE" ]] && RELEASE="$(bash <(cat /etc/os-release; echo 'echo ${VERSION/*, /}') | head -n1 | awk '{print tolower($1);}')" | |
elif [[ (! -z $UBUNTU) || (! -z $DEBIAN) ]]; then | |
RELEASE="$(lsb_release -cs)" | |
else | |
echo "Your system is not supported" | |
#exit 2 | |
fi | |
######################################################### | |
## wget | |
wget_bin=$(which wget 2>/dev/null) | |
if [[ -z $wget_bin ]]; then | |
print_status "Instalando WGET via apt-get"$'\n'"| -> apt-get update && apt-get install wget" | |
silent apt-get update && silent apt-get install wget | |
exec_status $? | |
else | |
print_status "WGET ja esta disponivel"$'\n'"| -> $wget_bin" | |
exec_status $? | |
fi | |
######################################################### | |
## reset permissoes | |
print_status "Setando permissoes para arquivos do Auto System (user: $LOGUSER)" | |
chown -R "$LOGUSER":"$LOGUSER" "$HOME"/.autosystem && chmod -R 777 "$HOME"/.autosystem && | |
chown "$LOGUSER":"$LOGUSER" "$HOME"/.autosystem3.log && chmod 664 "$HOME"/.autosystem3.log && | |
chown -R "$LOGUSER":"$LOGUSER" "/usr/local/autosystem3" && chmod -R 775 "/usr/local/autosystem3" | |
exec_status $? "/usr/local/autosystem3" | |
touch "/etc/autosystem.db" && chown "$LOGUSER":"$LOGUSER" "/etc/autosystem.db" && chmod 664 "/etc/autosystem.db" | |
exec_status $? "/etc/autosystem.db" | |
touch "/etc/autosystem.key" && chown "$LOGUSER":"$LOGUSER" "/etc/autosystem.key" && chmod 664 "/etc/autosystem.key" | |
exec_status $? "/etc/autosystem.key" | |
######################################################### | |
## FIX LZT LIBS FOLDER - Troca a pasta antiga LZT por | |
## um symlink da pasta atual que atualiza pelo as_update | |
## Esse mod corrige diversos erros do autosystem!! | |
if [[ -d /usr/lib/python2.2/lzt ]] && [[ ! -L /usr/lib/python2.2/lzt ]] && [[ -d /usr/local/autosystem3/lzt ]]; then | |
print_status "Corrigindo pasta LZT Libs" | |
mv /usr/lib/python2.2/lzt /usr/lib/python2.2/lzt-old | |
exec_status $? "Move /usr/lib/python2.2/lzt > /usr/lib/python2.2/lzt-old" | |
ln -s /usr/local/autosystem3/lzt /usr/lib/python2.2/lzt | |
exec_status $? "Symlink /usr/local/autosystem3/lzt > /usr/lib/python2.2/lzt" | |
fi | |
######################################################### | |
## Script para limpar / remover itens no boot | |
print_status "Criando script /usr/local/autosystem3/as_boot_clean.sh" | |
cat << EOF > /usr/local/autosystem3/as_boot_clean.sh | |
#!/bin/bash | |
rm -r /home/*/.autosystem/work/distribuidora/* 2>/dev/null | |
#rm /home/*/.autosystem3.log 2>/dev/null | |
#rm /home/*/as_distribuidora.log 2>/dev/null | |
#rm /home/*/.autosystem/log/* 2>/dev/null # remove logs arquivados | |
EOF | |
exec_status $? 'Criar arquivo' | |
chmod 775 /usr/local/autosystem3/as_boot_clean.sh | |
exec_status $? 'Tornar executavel' | |
######################################################### | |
## Roda script no boot | |
print_status "Adicionando as_boot_clean.sh ao autostart do sistema" | |
su $LOGUSER -c "mkdir -p /home/$LOGUSER/.config/autostart" | |
cat << EOF > /home/$LOGUSER/.config/autostart/AutoSystemClean.desktop | |
[Desktop Entry] | |
Encoding=UTF-8 | |
Version=0.9.4 | |
Type=Application | |
Name=AutoSystemClean | |
Comment=Limpa arquivos e pastas AS | |
Exec=/usr/local/autosystem3/as_boot_clean.sh | |
StartupNotify=false | |
Terminal=true | |
Hidden=false | |
EOF | |
exec_status $? "Criar /home/$LOGUSER/.config/autostart/AutoSystemClean.desktop" | |
chmod 775 /home/$LOGUSER/.config/autostart/AutoSystemClean.desktop | |
exec_status $? 'Tornar executavel' | |
######################################################### | |
## Roda script no boot (DESATIVADO) | |
#print_status "Adicionando as_boot_clean ao /etc/rc.local" | |
#if [[ -f /etc/rc.local ]]; then | |
# echo $' > ATENCAO!\n O arquivo /etc/rc.local ja existe!' | |
# hasCall="$(grep '/usr/local/autosystem3/as_boot_clean.sh' /etc/rc.local)" | |
# if [[ -z "$hasCall" ]]; then | |
# echo -e $'\n/usr/local/autosystem3/as_boot_clean.sh\nexit 0\n' >> /etc/rc.local | |
# exec_status $? "Append no final" | |
# else | |
# exec_status 0 "Ignorado pois ja esta chamando /usr/local/autosystem3/as_boot_clean.sh" | |
# fi | |
#else | |
# echo -e $'#!/bin/bash\n/usr/local/autosystem3/as_boot_clean.sh\nexit 0\n' > /etc/rc.local | |
# exec_status $? "Criar arquivo" | |
#fi | |
# | |
#chmod +x /etc/rc.local | |
#exec_status $? "Tornar executavel" | |
# | |
#sep='----/etc/rc.local---------------------------------------------' | |
#echo $'\n>>> VERIFIQUE SE O ARQUIVO /etc/rc.local FICOU CORRETO! <<<\n NAO PODE EXISTIR exit 0 ANTES DA CHAMADA!\n' ; echo $sep ; cat /etc/rc.local ; echo $sep | |
####echo $sep ; cat /etc/rc.local ; echo $sep | |
######################################################### | |
## final status | |
if [[ $IERROR = false ]]; then | |
print_status "Fim"$'\n'"| Nenhum erro detectado!"$'\n'"| A instalacao concluiu com exito!" | |
exit 0 | |
fi | |
print_status "Fim"$'\n'"| Algum erro foi detectado!"$'\n'"| A instalacao falhou!" | |
exit 55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment