Last active
February 5, 2024 19:42
-
-
Save tavinus/146bdce3695cae9cfec02b534c2ff30f to your computer and use it in GitHub Desktop.
Instalar Linx Autosystem Debian, Mint, Ubuntu (via Repo Fatux)
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 do pacote do Autosystem para Debian, Mint e Ubuntu | |
## as_deb_install.sh | |
## | |
## One-liner: | |
## wget 'https://gist.githubusercontent.com/tavinus/146bdce3695cae9cfec02b534c2ff30f/raw/as_deb_install.sh' && sudo chmod +x as_deb_install.sh && sudo ./as_deb_install.sh | |
## | |
## Descricao: | |
## Adiciona repositorios e instala os pacotes necessarios para rodar o autosystem | |
## Deve funcionar no Debian, Mint e Ubuntu | |
## Precisa rodar como root (sudo) | |
## | |
## Depois de instalar e configurar, adicionar ao cron para renovar mensalmente: | |
## 03 00 01 * * /usr/bin/as_manutencao --renovar-chave SENHA-AS | |
## | |
## Uso: | |
## sudo ./as_deb_install.sh | |
## | |
## Ajuda: | |
## ./as_deb_install.sh --help | |
## | |
## Gustavo Arnosti Neves - guneves <at-nospam> gmail <dot-nospam> com | |
## | |
## Original: 16 Jun 2016 | |
## Update: 28 Nov 2019 | |
## MODIFICADO PARA RODAR NO MINT 19.2 TINA XFCE 32BITS (TESTADO) | |
## POSSIVELMENTE FUNCIONARA EM DEBIAN E UBUNTU, MAS NAO FOI TESTADO | |
## | |
## Para rodar em linux 64bits ou ARM em chroot: | |
## https://gist.github.com/tavinus/559c6fef56a757e524c86deffdfb9dc0 | |
## | |
#################################################################################################### | |
VERSION="0.5.5" | |
QUIET=' -q' | |
ABORT=false | |
VERBOSE=false | |
IERROR=false | |
COUNTME=0 | |
FATUXRSYNC=false | |
INSTALLPOSTGRES=false | |
LOGUSER="$(who | awk '{print $1}' | head -n 1)" | |
ASPACKNAME='autosystem-3.2.6' | |
_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 Debian, Mint, Ubuntu (Online) v$VERSION" | |
} | |
function print_help { | |
print_version | |
echo " | |
Uso: | |
$0 [avVh] | |
Parametros: | |
-r | --rsync-fatux Usa o rsync do repositorio fatux | |
Padrao: usar o do Debian - via pin | |
-p | --postgres Instala o Postgres SQL Server (AS Server) | |
Padrao: nao instalar | |
-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 add_repo { | |
[[ -z $1 ]] || [[ -z $2 ]] && return 4 | |
SC_LIST='/etc/apt/sources.list' | |
EXISTS=$(cat $SC_LIST | grep $1) | |
if [[ -z $EXISTS ]]; then | |
echo $'\n'"$2" >> "$SC_LIST" | |
return $? | |
else | |
return 0 | |
fi | |
return 3 | |
} | |
function silent { | |
if [[ $VERBOSE = true ]]; then | |
"$@" 2>&1 | tee -a "$_INSTLOGFILE" | |
else | |
"$@" 2>&1 >"$_INSTLOGFILE" | |
fi | |
} | |
######################################################### | |
## EXECUTION STARTS | |
######################################################### | |
######################################################### | |
## get options | |
TEMP=`getopt -o rpvVha --long rsync-fatux,postgres,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 | |
-r | --rsync-fatux ) FATUXRSYNC=true; shift ;; | |
-p | --postgres ) INSTALLPOSTGRES=true; shift ;; | |
-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 | |
######################################################### | |
## Pre criar - sanidade | |
print_status "Pre-criando pastas autosystem com o usuario $LOGUSER" | |
su -c 'mkdir -p $HOME/.autosystem/log ; touch $HOME/.autosystem3.log ; touch $HOME/as_distribuidora.log' "$LOGUSER" | |
exec_status $? | |
######################################################### | |
## 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, aborting" | |
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 | |
######################################################### | |
## repo fatux | |
print_status "Adicionando repositorios em /etc/apt/sources.list.d/" | |
bash -c 'echo "deb [trusted=yes] http://fatux.myddns.com/fatux fatux main" > /etc/apt/sources.list.d/fatux.list' | |
exec_status $? "Repo Fatux" | |
######################################################### | |
## trava rsync | |
RSYNCFILE="/etc/apt/preferences.d/rsync.pref" | |
if [[ $FATUXRSYNC = true ]]; then | |
if [[ -f $RSYNCFILE ]]; then | |
print_status "Removendo prioridade do rsync padrao $RELEASE"$'\n'"| -> $RSYNCFILE" | |
rm "$RSYNCFILE" | |
exec_status $? | |
fi | |
else | |
print_status "Dando prioridade ao rsync padrao $RELEASE"$'\n'"| -> $RSYNCFILE" | |
echo -e "Package: rsync | |
Pin: release n=$RELEASE | |
Pin-Priority: 1001 | |
" > $RSYNCFILE | |
exec_status $? | |
fi | |
######################################################### | |
## atualiza cache | |
print_status "Atualizando repositorios"$'\n'"| -> apt-get update" | |
silent apt-get update | |
exec_status $? | |
######################################################### | |
## dependencias | |
print_status "Instalando rsync, cups-pdf e curl" | |
#silent apt-get install rsync cups-pdf curl libcanberra-gtk-module -y --allow-unauthenticated | |
silent apt-get install rsync cups-pdf curl -y --allow-unauthenticated | |
exec_status $? | |
######################################################### | |
## postgres server / client installs | |
if [[ $INSTALLPOSTGRES = true ]]; then | |
print_status "Adicionando repositorios do Postgres SQL server em /etc/apt/sources.list.d/" | |
bash -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ '"$RELEASE"'-pgdg main' > /etc/apt/sources.list.d/pgdg.list" | |
exec_status $? "Repo PostgreSQL" | |
print_status "Adicionando chaves gpg do repositorio do postgresql.org" | |
STAT=$("$wget_bin" -q -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -) | |
exec_status $? | |
PGDGFILE="/etc/apt/preferences.d/pgdg.pref" | |
print_status "Dando prioridade ao repositorio postgresql.org"$'\n'"| -> $PGDGFILE" | |
echo 'Package: * | |
Pin: release o=apt.postgresql.org | |
Pin-Priority: 1001' > $PGDGFILE | |
exec_status $? | |
print_status "Instalando pacotes referentes ao postgresql" | |
silent apt-get install postgresql-9.6 postgresql-client-9.6 | |
exec_status $? | |
print_status $'\n'"TALVEZ SEJA NECESSARIO EDITAR OS ARQUIVOS:" | |
print_status " - /etc/postgresql/9.6/main/pg_hba.conf" | |
print_status " - /etc/postgresql/9.6/main/ postgresql.conf"$'\n' | |
else | |
print_status "Instalando postgresql (client somente)" | |
silent apt-get install -y postgresql-client | |
exec_status $? | |
fi | |
######################################################### | |
## libssl0.9.8 | |
LIBSSLAPT="$(apt-cache search libssl0.9.8)" | |
if [[ ! -z $LIBSSLAPT ]]; then | |
print_status "Instalando libssl0.9.8 via apt-get"$'\n' | |
silent apt-get install -y libssl0.9.8 | |
exec_status $? | |
else | |
TMPLIBSSL="/tmp/libssl0.9.8_0.9.8o-7_i386.deb" | |
print_status "Instalando libssl0.9.8 manualmente"$'\n'"| Download e Instalacao dpkg"$'\n'"| -> $TMPLIBSSL" | |
silent "$wget_bin" -q -O $TMPLIBSSL http://snapshot.debian.org/archive/debian/20110406T213352Z/pool/main/o/openssl098/libssl0.9.8_0.9.8o-7_i386.deb | |
exec_status $? "Download" | |
silent dpkg -i $TMPLIBSSL | |
exec_status $? "Instalacao" | |
fi | |
######################################################### | |
## REPACK AutoSystem Deb | |
## Refazendo o .deb para que aceite instalar no Mint | |
CDIR="$(pwd)" | |
TMPDIR=`mktemp -d /tmp/asdeb.XXXXXXXXXX` || exit 1 | |
TMPEXTRACT="$TMPDIR/extract" | |
mkdir "$TMPEXTRACT" | |
OUTPUT="$TMPDIR/autosystem.modfied.deb" | |
cd "$TMPDIR" | |
print_status "Download do $ASPACKNAME ..." | |
silent apt-get download -y "$ASPACKNAME" --allow-unauthenticated | |
exec_status $? | |
DEBFILE="$(echo $(ls -1 $ASPACKNAME*) | awk '{ print $1 }')" | |
if [[ -e "$OUTPUT" ]]; then | |
echo "$OUTPUT exists." | |
rm -r "$TMPDIR" | |
cd "$CDIR" | |
exit 1 | |
fi | |
print_status "Extraindo $ASPACKNAME ..." | |
silent dpkg-deb -x "$DEBFILE" "$TMPEXTRACT" | |
exec_status $? "Main Pack" | |
silent dpkg-deb --control "$DEBFILE" "$TMPEXTRACT"/DEBIAN | |
exec_status $? "Control file" | |
CONTROL="$TMPEXTRACT"/DEBIAN/control | |
if [[ ! -e "$CONTROL" ]]; then | |
print_status "Erro! Arquivo Debian Control nao foi encontrado" | |
rm -r "$TMPDIR" | |
cd "$CDIR" | |
exit 1 | |
fi | |
MOD=`stat -c "%y" "$CONTROL"` | |
#nano "$CONTROL" | |
sed -i 's/ cups-pdf ( >= 0 ),//g; s/ curl ( <= 7.39 ),//g' "$CONTROL" | |
if [[ "$MOD" == `stat -c "%y" "$CONTROL"` ]]; then | |
print_status "O arquivo .deb nao foi modificado" | |
else | |
print_status "Reconstruindo arquivo .deb modificado" | |
silent dpkg -b "$TMPEXTRACT" "$OUTPUT" | |
exec_status $? | |
fi | |
#rm -r "$TMPDIR" | |
cd "$CDIR" | |
######################################################### | |
## Install AutoSystem | |
print_status "Instalando Deb Modificado $OUTPUT" | |
silent apt-get install -y "$OUTPUT" --allow-unauthenticated | |
exec_status $? | |
######################################################### | |
## rodar as_update | |
print_status "Rodando as_update" | |
silent as_update | |
exec_status $? | |
######################################################### | |
## 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 | |
######################################################### | |
## Repo Fatux disable | |
print_status "Desabilitando repositorio FATUX" | |
bash -c 'echo "#deb [trusted=yes] http://fatux.myddns.com/fatux fatux main" > /etc/apt/sources.list.d/fatux.list' | |
exec_status $? "Repo Fatux Desabilitado" | |
silent apt-get update | |
exec_status $? "Apt cache updated" | |
silent apt-get install --reinstall rsync | |
exec_status $? "Force reinstall rsync-upstream" | |
######################################################### | |
## 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 | |
######################################################### | |
## hints | |
print_status "Proximos passos:" | |
echo $' > Para ativar a licenca da sua maquina, rode "Autosystem Main / Gerencial".\n sudo as_main\n\n > Para configurar a estacao e acesso ao servidor, rode "Autosystem Config".\n sudo as_config' | |
#silent as_main 2>/dev/null && silent as_config 2>/dev/null && exec_status $? | |
######################################################### | |
## 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 |
Por algum motivo ele editou o as_update antes de rodar ele..
Depois da instalação
Buenas, os testes não foram muito bons pra terminal com Ubuntu 64 bits.
Nem consegui rodar nada em interface, só cli.
Enfim, acabei precisando instalar num Linux Mint 19.2 (Tina) XFCE 32bits e modifiquei totalmente o instalador.
Acabei de testar e instalou bem.
O pacote atual no repositório fatux é incompatível com o Mint, mas eu baixo ele, modifico e instalo. Parece tudo ok.
Eu tbm rodo uns tweaks e correções importantes no instalador.
A versão anterior do instalador estava quebrada de qualquer forma.
Mas servia de guia pra quem é esperto conseguir instalar.
Agora basta rodar o instalador e boa (ao menos no Mint 32bits).
wget 'https://gist.githubusercontent.com/tavinus/146bdce3695cae9cfec02b534c2ff30f/raw/as_deb_install.sh' && sudo chmod +x as_deb_install.sh && sudo ./as_deb_install.sh
Cheers!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dei uma inspecionada no servidor novo e achei algumas informações.
Provavelmente seu servidor tem as mesmas informações e arquivos.
Você pode usar o comando
history
pra ver o que fizeram, tanto no usuário de login, quanto no usuário root. A maioria das coisas eles fizeram no root, comsudo su -
.No nosso caso tinha uma pasta
/user/Als
que tinha os dumps dos nossos bancos de dados e também uma pasta com arquivos de instalação.Eles devem ter enviado essa pasta por scp ou rsync chamado externamente pois não há registro no histórico.
O arquivo
asinstall_full_20120504.sh
tem um tar dentro dele com o programa.Mas pra instalar usaram
Enfim, veja se acha aí no seu servidor os arquivos e consegue usá-los.
Gus