################################################################
## SCRIPT DE INSTALAÇÃO PADRÃO PARA DESKTOP LINUX ##
################################################################
################################################################
## INICIO ##
################################################################
mv /etc/apt/sources.list /etc/apt/sources.list.bkp
touch /etc/apt/sources.list
cat << 'EOF' >> /etc/apt/sources.list
################################################################
# DEBIAN #
################################################################
########################### BULLSEYE ###########################
deb http://deb.debian.org/debian/ bullseye main contrib non-free
deb-src http://deb.debian.org/debian/ bullseye main contrib non-free
###################### BULLSEYE-UPDATES ########################
deb http://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb-src http://deb.debian.org/debian/ bullseye-updates main contrib non-free
##################### BULLSEYE-BACKPORTS #######################
deb http://deb.debian.org/debian/ bullseye-backports main contrib non-free
deb-src http://deb.debian.org/debian/ bullseye-backports main contrib non-free
################################################################
## DEBIAN-SECURITY ##
################################################################
##################### BULLSEYE-SECURITY ######################
deb http://security.debian.org/debian-security bullseye-security main contrib non-free
deb-src http://security.debian.org/debian-security bullseye-security main contrib non-free
EOF
################################################################
## ATUALIZAÇÕES E INSTALAÇÕES ##
################################################################
apt-get update
apt-get install apt-transport-https software-properties-common sudo unzip wget git aptitude curl make cmake gcc dirmngr gnupg2 build-essential winbind smbclient -y
echo "deb https://repo.skype.com/deb stable main" >> /etc/apt/sources.list
curl -s https://repo.skype.com/data/SKYPE-GPG-KEY | apt-key add -
apt-get update
apt-get install lxde-core catfish system-config-printer cups printer-driver-cups-pdf fonts-open-sans -y
apt-get install pidgin skypeforlinux evince -y
apt-get install libreoffice-l10n-pt-br thunderbird-l10n-pt-br libreoffice-impress libreoffice-writer libreoffice-calc -y
## Remove o repositorio duplicado do skype
rm /etc/apt/sources.list.d/skype-stable.list
###############################################################
## NAVEGADORES CHROMIUM / FIREFOX / CHROME / EDGE ##
###############################################################
## INSTALAÇÂO CHROMIUM
apt-get install chromium -y
## INSTALAÇÂO FIREFOX PT-BR
apt-get install firefox-esr-l10n-pt-br -y
## INSTALAÇÂO GOOGLE-CHROME-STABLE
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb -y
## INSTALAÇÃO MICROSOFT EDGE
apt-get install curl -y
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-stable.list'
sudo rm microsoft.gpg
sudo apt update && sudo apt install microsoft-edge-stable -y
################################################################
## INSTALAÇÃO OCSINVENTORY AGENT ##
################################################################
sudo apt install libmodule-install-perl dmidecode libxml-simple-perl libcompress-zlib-perl libnet-ip-perl libwww-perl libdigest-md5-perl libdata-uuid-perl -y
wget https://github.com/OCSInventory-NG/UnixAgent/releases/download/v2.9.1/Ocsinventory-Unix-Agent-2.9.1.tar.gz
tar -xf Ocsinventory-Unix-Agent-2.9.1.tar.gz
cd Ocsinventory-Unix-Agent-2.9.1
env PERL_AUTOINSTALL=1 perl Makefile.PL && make && make install && perl postinst.pl --nowizard --server=http://IP_SERVER_OCS/ocsinventory --realm=realm --logfile=/var/log/ocsinventory-client/ocsinventory-agent.log --now --crontab
sudo ocsinventory-agent --server http://IP_SERVER_OCS/ocsinventory
cd
################################################################
## ATALHOS DESKTOP PADRÃO ##
################################################################
## Cria os atalhos para Desktop para todos os usuários em /opt/CLIENT
mkdir /opt/CLIENT
touch /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/libreoffice-writer.desktop
[Desktop Entry]
Type=Link
Name=Editor de Texto
Icon=libreoffice-writer
URL=/usr/share/applications/libreoffice-writer.desktop
EOF
" >> /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/libreoffice-calc.desktop
[Desktop Entry]
Type=Link
Name=Planilhas
Icon=libreoffice-calc
URL=/usr/share/applications/libreoffice-calc.desktop
EOF
" >> /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/TotvsLinux.desktop
[Desktop Entry]
Encoding=UTF-8
Type=Link
Name=TotvsLinux
Icon= /PATH_DESTINO-1/totvs-icon.png
URL= /PATH_DESTINO-1/smartclient
StartupNotify=true
Terminal=false
Comment=Totvs
EOF
" >> /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/TotvsWindows.desktop
[Desktop Entry]
Encoding=UTF-8
Type=Link
Name=TotvsWindows
Icon= /PATH_DESTINO-2/totvs-icon.png
URL= /PATH_DESTINO-2/smartclient.exe
StartupNotify=true
Terminal=false
Comment=Totvs
EOF
" >> /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/org.kde.krfb.desktop
[Desktop Entry]
Type=Link
Name=Krfb
Icon=krfb
URL=/usr/share/applications/org.kde.krfb.desktop
EOF
" >> /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/chromium.desktop
[Desktop Entry]
Type=Link
Name=Navegador de Internet
Icon=chromium
URL=/usr/share/applications/chromium.desktop
EOF
" >> /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/pidgin.desktop
[Desktop Entry]
Type=Link
Name=Mensageiro
Icon=pidgin
URL=/usr/share/applications/pidgin.desktop
EOF
" >> /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/skypeforlinux.desktop
[Desktop Entry]
Type=Link
Name=Skype
Icon=skypeforlinux
URL=/usr/share/applications/skypeforlinux.desktop
EOF
" >> /opt/CLIENT/shortcuts.sh
echo "cat << 'EOF' > ~/Desktop/thunderbird.desktop
[Desktop Entry]
Type=Link
Name=Cliente de E-mail
Icon=thunderbird
URL=/usr/share/applications/thunderbird.desktop
EOF
" >> /opt/CLIENT/shortcuts.sh
chmod 755 /opt/CLIENT/shortcuts.sh
chmod +x /opt/CLIENT/shortcuts.sh
# Copiando scritp shortcuts.sh para a pasta do LXDE
cp /opt/CLIENT/shortcuts.sh /etc/xdg/lxsession/LXDE/shortcuts.sh
################################################################
# PROGRAMAS DE INICIALIZAÇÂO PADRAO DO SISTEMA AUTOSTART #
################################################################
## CRIANDO UM BACKUP DO ARQUIVO AUTOSTART PADRAO DO SISTEMA
mv /etc/xdg/lxsession/LXDE/autostart /etc/xdg/lxsession/LXDE/autostart.bkp
## CRIANDO UM NOVO ARQUIVO AUTOSTART E ADICIONANDO A TODOS OS USUARIOS
cat << 'EOF' >> /etc/xdg/lxsession/LXDE/autostart
@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
# Desativar Proteção de Tela
# @xscreensaver -no-splash
@xset s 0 0
@xset s noblank
@xset s noexpose
@xset dpms 0 0 0
# Inicia o PIDGIN
/usr/bin/pidgin
# Inicia o SKYPE
/usr/bin/skypeforlinux --password-store=basic %U
# Script de Atalhos Desktop
/etc/xdg/lxsession/LXDE/shortcuts.sh
# Define o Evince PDF como Leitor Padrão
xdg-mime default org.gnome.Evince.desktop application/pdf
# Desativa Proteção de Tela
@xset s noblack
@xset s off
@xset -dpms
EOF
################################################################
## ARQUIVO DE ACESSO REMOTO VNC ##
################################################################
apt-get install x11vnc -y
cat << 'EOF' >> /lib/systemd/system/x11vnc.service
[Unit]
Description=x11vnc service
After=display-manager.service
network.target syslog.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -forever -display :0 -auth guess -passwd SUASENHA
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable x11vnc.service
systemctl start x11vnc.service
################################################################
## ARQUIVO DE ACESSO REMOTO RDP ##
################################################################
# Ativando Acesso remoto com XRDP
apt-get install xrdp -y
sudo systemctl enable xrdp
echo xfce4-session >~/.xsession
sudo service xrdp restart
################################################################
## ARQUIVO DE ACESSO REMOTO KRFB ##
################################################################
apt-get install krfb -y
# Desabilita KDE Wallet do KRFB
mv /usr/share/dbus-1/services/org.kde.kwalletd5.service /usr/share/dbus-1/services/org.kde.kwalletd5.service.bkp
################################################################
## SMARTCLIENT TOTVS PROTHEUS ##
################################################################
## INSTALAÇÃO DEPENDÊNCIAS SMARTCLINET LINUX
dpkg --add-architecture i386
apt-get update
apt-get install qt5ct glibc-source mesa-common-dev gcc-multilib libqt5webenginewidgets5 libqt5websockets5 -y
# apt-get install zlib1g lib32z1 libglib2.0-0 libqt5xml5 libqt5scripttools5 lib32ncurses6 libxmu6:i386 lib32z1 libglib2.0-0 libxmu6 libxrender1 libdbus-1-3 libice6 libsm6 libx11-6 libxau6 libxext6 libxrender1 libuuid1 libxcb1 -y
## INSTALAÇÃO WINE PARA SMARTCLIENT WINDOWS
sudo dpkg --add-architecture i386
sudo apt update
wget -nc https://dl.winehq.org/wine-builds/winehq.key
sudo apt-key add winehq.key
sudo apt-add-repository https://dl.winehq.org/wine-builds/debian/
sudo apt update
sudo apt install --install-recommends winehq-stable winetricks -y
## CRIANDO PASTAS TOTVS WINDOWS E LINUX
mkdir /PATH_DESTINO-1
mkdir /PATH_DESTINO-2
## COPIANDO SMARTCLINET WINDOWS E LINUX
smbclient //IP_SERVER/SHARE -U LOGIN_USER --pass "PASSWD_USER" --max-protocol SMB2 -c "get /PATH_ORIGEM/ARQUIVO1.zip /PATH_DESTINO-1/ARQUIVO1.zip;"
smbclient //IP_SERVER/SHARE -U LOGIN_USER --pass "PASSWD_USER" --max-protocol SMB2 -c "get /PATH_ORIGEM/ARQUIVO2.zip /PATH_DESTINO-2/ARQUIVO2.zip;"
## DESCOMPACTANDO SMARTCLIENT WINDOWS E LINUX
unzip /PATH_DESTINO-1/ARQUIVO1.zip -d /PATH_DESTINO-1/
unzip /PATH_DESTINO-2/ARQUIVO2.zip -d /PATH_DESTINO-2/
## CRIANDO ARQUIVO DE CONFIGURAÇÃO SMARTCLIENT.INI WINDOWS E LINUX
## SMARTCLIENT.INI WINDOWS
cat << 'EOF' >>/PATH_DESTINO-1/smartclient.ini
[config]
lastmainprog=sigaadv,sigamdi
envserver=NAMESERVER
[drivers]
active=tcp
[tcp]
server=IP_SERVER
port=1238
EOF
## SMARTCLIENT.INI LINUX
cat << 'EOF' >> /PATH_DESTINO-2/smartclient.ini
[config]
lastmainprog=sigaadv,sigamdi
envserver=NAMESERVER
[drivers]
active=tcp
[tcp]
server=IP_SERVER
port=1238
EOF
## Para o erro "bash: ./smartclient: Permissão negada"
chmod +777 /PATH_DESTINO-1/
chmod +777 /PATH_DESTINO-2/
chmod +x /PATH_DESTINO-1/smartclient
chmod +x /PATH_DESTINO-2/smartclient.exe
## ld ./smartclient: Comando para validar as bibliotecas marcadas como notfound.
cd /PATH_DESTINO-1/
ldd ./smartclient
cd /
################################################################
## FIM ##
################################################################
## apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 871920D1991BC93C
## apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
## Fix para o Erro ldconfig: https://blog.desdelinux.net/pt/como-solucionar-error-dpkg-aviso-ldconfig-en-debian-testing/
## echo 'export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin' >> ~/.bashrc
## source /etc/profile
## apt install qtcreator qtdeclarative5-dev qt5-doc qt5-doc-html qtbase5-doc-html qtbase5-examples -y
## sudo apt install libaio1 libaio-dev libfontconfig1 libglu1-mesa-dev -y
## nano /etc/security/limits.conf
## * soft nofile 32768
## * hard nofile 32768