Last active
July 17, 2023 13:02
-
-
Save AmaralMarti/3c80625c7daca712772089571cc78f6a to your computer and use it in GitHub Desktop.
Ubuntu Setup
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 | |
echo "Atualizando o Ubuntu..." | |
sudo apt update && sudo apt upgrade -y && apt install -y dialog wget curl network-manager | |
export TERM=xterm-color | |
# Armazena a saída do comando dialog em uma variável | |
opcoes=$(dialog --colors --stdout --separate-output \ | |
--title "" \ | |
--checklist "Preparacao do Servidor Ubuntu 22.04 LTS:" 0 0 0 \ | |
1 "Instalar ZSH com Oh My Zsh" on \ | |
2 "Criar um usuario" on \ | |
3 "Instalar e habilitar servidor SSH" on \ | |
4 "Ativar acesso SSH como root" on \ | |
5 "Instalar Docker" on \ | |
6 "Instalar Speedtest by Ookla" on \ | |
7 "Instalar vim" on \ | |
8 "Instalar git" on \ | |
9 "Instalar htop" on \ | |
10 "Instalar net-tools" on \ | |
11 "Instalar neofetch" on \ | |
) | |
# Verifica se o usuário pressionou Esc ou Cancelar | |
if [ $? -eq 1 ] || [ $? -eq 255 ]; then | |
clear | |
echo "Operação cancelada pelo usuário." | |
exit 1 | |
fi | |
user_exists () { | |
local user=$1 | |
id $user | |
if [ $? -eq 0 ]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Processa as opções selecionadas pelo usuário | |
for opcao in $opcoes; do | |
case $opcao in | |
1) | |
echo "Instalando ZSH com Oh My Zsh..." | |
apt install -y git zsh | |
wget --no-check-certificate http://install.ohmyz.sh -O - | sh | |
sed -i 's/ZSH_THEME=".*"/ZSH_THEME="bira"/g' ~/.zshrc | |
echo "alias ll='ls -la'" >> ~/.zshrc | |
sudo usermod -s /usr/bin/zsh $USER | |
source ~/.zshrc | |
;; | |
2) | |
username="" | |
while [ -z "$username" ]; do | |
dialog --title "Criando um novo usuario" --inputbox "Digite o nome do usuario:" 8 80 2>ans.txt | |
ret=$? | |
if [ $ret -eq 1 ] || [ $ret -eq 255 ]; then | |
dialog --yesno 'Deseja mesmo cancelar?' 0 0 ; | |
ret=$? | |
if [ $ret -eq 0 ]; then | |
clear | |
echo "Operação cancelada pelo usuário." | |
exit 1 | |
fi | |
else | |
username=$(<ans.txt) | |
if [ -z "$username" ]; then | |
dialog --title "Erro" --msgbox "O nome do usuario nao pode ser vazio." 5 80 | |
else | |
user_exists $username | |
if [ $? -eq 0 ]; then | |
dialog --msgbox "O usuario \"$username\" ja existe no sistema." 5 80 | |
username="" | |
fi | |
fi | |
fi | |
done | |
password="" | |
confirm="" | |
while [ -z "$password" ] || [ "$password" != "$confirm" ]; do | |
dialog --title "Criando um novo usuario" --insecure --passwordbox "Digite a senha do usuario:" 8 80 2>ans.txt | |
ret=$? | |
if [ $ret -eq 1 ] || [ $ret -eq 255 ]; then | |
dialog --yesno 'Deseja mesmo cancelar?' 0 0 ; | |
ret=$? | |
if [ $ret -eq 0 ]; then | |
clear | |
echo "Operação cancelada pelo usuário." | |
exit 1 | |
fi | |
else | |
password=$(<ans.txt) | |
if [ -z "$password" ]; then | |
dialog --title "Erro" --msgbox "A senha nao pode ser vazia." 5 80 | |
else | |
dialog --title "Criando um novo usuario" --insecure --passwordbox "Confirme a senha do usuario:" 8 80 2>ans.txt | |
ret=$? | |
if [ $ret -eq 1 ] || [ $ret -eq 255 ]; then | |
dialog --yesno 'Deseja mesmo cancelar?' 0 0 ; | |
ret=$? | |
if [ $ret -eq 0 ]; then | |
clear | |
echo "Operação cancelada pelo usuário." | |
exit 1 | |
fi | |
else | |
confirm=$(<ans.txt) | |
if [ "$password" != "$confirm" ]; then | |
dialog --title "Erro" --msgbox "As senhas nao correspondem." 5 80 | |
fi | |
fi | |
fi | |
fi | |
done | |
rm -f ans.txt | |
useradd -m -p $(openssl passwd -1 $password) $username | |
sudo adduser $username sudo | |
sudo -u $username ssh-keygen -t rsa -b 2048 -N "" -f /home/$username/.ssh/id_rsa | |
if which zsh > /dev/null; then | |
cp ~/.zshrc /home/$username/ | |
cp -R ~/.oh-my-zsh /home/$username/ | |
chown $username:$username /home/$username/.zshrc | |
chown $username:$username -R /home/$username/.oh-my-zsh | |
sudo usermod -s /usr/bin/zsh $username | |
fi | |
;; | |
3) | |
echo "Instalando e habilitando servidor SSH..." | |
sudo apt install -y openssh-server | |
sudo systemctl enable sshd | |
sudo systemctl start sshd | |
;; | |
4) | |
echo "Ativando acesso SSH como root..." | |
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config | |
sudo systemctl restart sshd | |
;; | |
5) | |
echo "Instalando Docker..." | |
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt update | |
sudo apt install -y docker-ce docker-ce-cli containerd.io | |
;; | |
6) | |
echo "Instalando Speedtest by Ookla..." | |
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash | |
sudo apt update && sudo apt install -y speedtest | |
;; | |
7) | |
echo "Instalando vim..." | |
sudo apt install -y vim | |
;; | |
8) | |
echo "Instalando git..." | |
sudo apt install -y git | |
;; | |
9) | |
echo "Instalando htop..." | |
sudo apt install -y htop | |
;; | |
10) | |
echo "Instalando net-tools..." | |
sudo apt install -y net-tools | |
;; | |
11) | |
echo "Instalando neofetch..." | |
sudo apt install -y neofetch | |
;; | |
esac | |
done | |
clear | |
# Exibe o endereço IP das interfaces de rede | |
echo "Enderecos IP das interfaces de rede:" | |
ip -4 -o addr show | grep -v ' lo\|docker' | awk '{print $2 ": " $4}' | |
echo "Operação concluída." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment