schuhpereira
(usa Ubuntu)
Enviado em 31/05/2016 - 19:45h
Olá amigos!
Meu nome é Eduardo Pereira. Gostaria de pedir uma ajudinha a vocês. Recentemente criei um programinha em shell script com a interface zenity. O script roda sem problemas ou erros, mas como eu criei várias opções no mesmo menu, fica um pouco "bagunçado". Então venho tentando criar submenus para deixar em categorias. Segue abaixo o código do meu script.
#!/bin/bash
while : ; do
# Mostra o menu na tela, com as ações disponíveis
opcao=$(zenity --list --title "Menu de manutenção"\
--text "O que deseja fazer?"\
--column "Opção" --column "descrição"\
--width="270" --height="330" \
1 'Atualiza pacotes' \
2 'Atualiza programas' \
3 'Atualiza a distro' \
4 'Manutenção do sistema' \
5 'Backup' \
6 'Agendar Backup' \
7 'Verificar conexão' \
8 'Programar desligamento' \
9 'Procurar por filmes' \
0 'Sair' )
while : ; do
# Se apertar CANCELAR ou ESC, então vamos sair...
[ $? -ne 0 ]
# De acordo com a opção escolhida, dispara programas
case "$opcao" in
# Atualiza as PPAs do sistema
1) sudo apt-get update
break ;;
###############################################################################################################
# Atualização os programas
2) sudo apt-get upgrade
break ;;
###############################################################################################################
# Atualiza a distro
3) sudo apt-get -f dist-upgrade
break ;;
###############################################################################################################
# Realiza a manutenção do sistema
4) sudo rm -rf /home/$USER/.local/share/Trash/files/*
zenity --info --text "Limpando a Lixeira" --timeout 3
sudo rm -rf /var/tmp/*
zenity --info --text "Limpando a Pasta Temporária" --timeout 3
sudo apt-get clean
zenity --info --text "Limpeza de cache e atualizações do gerenciador atual" --timeout 3
sudo apt-get autoremove -y
zenity --info --text "Remoção de pacotes que ainda estão no sistema" --timeout 3
sudo apt-get autoclean -y
zenity --info --text "Remoção de pacotes duplicados" --timeout 3
sudo apt-get -f install -y
zenity --info --text "Corrigido problemas de dependências" --timeout 3
sudo dpkg --configure -a
zenity --info --text "Recuperando pacotes" --timeout 3
zenity --info --text "Limpeza Concluida" --timeout 3
zenity --info --text "Seu sistema está recuperado." --timeout 5
break ;;
###############################################################################################################
# Faz backup da pasta .mozilla, home do usuário
5)
ORIGEM2="/home/$USER"
ORIGEM3="/etc/NetworkManager/system-connections"
DESTINO="/media/$USER/BACKUP/Backup/backup-`date`"
#echo
#Backup da pasta /home/$user
echo "Copiando a pasta /home do usuário" && sleep 1
total=$(du -s "$ORIGEM2" | awk '{print $1}')
cp -r "$ORIGEM2" "$DESTINO" &>/dev/null &
while true
do
[[ -z $(pidof cp) ]] && break
copiado=$(du -s "$DESTINO" | awk '{print $1}')
echo "# Copiando arquivos....$((copiado*100/total))%"
done | zenity --progress --auto-close --no-cancel --auto-kill
echo
# Salva as senhas da rede wifi
echo "Copiando a pasta contendo as redes wifi salvas!" && sleep 1
total=$(du -s "$ORIGEM3" | awk '{print $1}')
cp -r "$ORIGEM3" "$DESTINO" &>/dev/null &
while true
do
[[ -z $(pidof cp) ]] && break
copiado=$(du -s "$DESTINO" | awk '{print $1}')
echo "# Copiando arquivos....$((copiado*100/total))%"
done | zenity --progress --percentage=0 --auto-close --no-cancel --auto-kill
echo
echo "Backup realizado com sucesso." && sleep 5
echo "Saindo e voltando para o menu" && sleep 5
break ;;
###############################################################################################################
# ESTA OPÇÃO SERVER PARA AGENDAR UM BACKUP
6) zenity --calendar \
--title "Calendário" \
--text "Escolha uma data" \
break ;;
###############################################################################################################
7) nbwmon
break ;;
###############################################################################################################
8) qshutdown
break ;;
###############################################################################################################
9) java -jar /usr/local/VidMasta/vidmasta/VidMasta.jar
break ;;
###############################################################################################################
0) exit ;;
esac
done
done
Tentei fazer o mais simples possível, mas...
O problema todo é quando eu crio outro menu, aí ele mistura as opções e nada mais funciona.
Alguém sabe e pode me ajudar?
Obrigado.