Skip to content

Instantly share code, notes, and snippets.

@samuelteixeiras
Created May 4, 2015 18:35
Show Gist options
  • Save samuelteixeiras/d1170b53cd53e41d6ffc to your computer and use it in GitHub Desktop.
Save samuelteixeiras/d1170b53cd53e41d6ffc to your computer and use it in GitHub Desktop.
#!/bin/bash
### BEGIN INIT INFO
# SCRIPT TO SET JAVA_HOME ON LINUX
### END INIT INFO</code>
# Author: Sam Teixeira [email protected]
next=menu
# loop principal
while : ; do
case "$next" in
menu)
resposta=$(
dialog --stdout \
--title 'Menu' \
--menu 'Select one option:' \
0 0 0 \
1 'Set Java Path.'\
0 'Exit' )
# CANCELAR or ESC, exir...
[ $? -ne 0 ] && break
# De acordo com a opção escolhida, dispara programas
case "$resposta" in
1)
next=setPath
back=menu
;;
0) break ;;
esac
;;
setPath)
next=$back
dir=$(dialog --stdout \
--title 'Set java Path' \
--inputbox 'Please, Insert the name of java path \n Ex: /usr/local/jdk1.8.0:' \
0 0)
bashFile=~/.bashrc
if [ -d "$dir" ]
then
echo "export JAVA_HOME=$dir" >> $bashFile
echo "export PATH=$PATH:$dir/bin" >> $bashFile
else
echo "$dir not found."
fi
source $bashFile
sudo update-alternatives --install "/usr/bin/java" "java" "$dir/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "$dir/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "$dir/bin/javaws" 1
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root $dir
break
;;
*)
echo "Bad Window '$next'."
echo Abort programm...
exit
esac
# Aqui é feito o tratamento genérico de Código de Retorno
# de todas as telas. Volta para a tela back se for
# CANCELAR, sai do programa se for ESC.
retorno=$?
[ $retorno -eq 1 ] && next=$back # cancel
[ $retorno -eq 255 ] && break # Esc
done
clear
sudo update-alternatives --config java
java -version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment