Yuta HIGUCHI | 328acd8 | 2014-03-27 12:51:42 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | SILENT="" |
| 4 | |
| 5 | while getopts “hy” OPTION |
| 6 | do |
| 7 | case OPTION in |
| 8 | y) |
| 9 | SILENT="-y" |
| 10 | ;; |
| 11 | *) |
| 12 | echo |
| 13 | echo "This script will install Oracle JDK 7 and set JAVA_HOME" |
| 14 | echo "Usage: $ $0" |
| 15 | echo |
| 16 | exit 1 |
| 17 | ;; |
| 18 | esac |
| 19 | done |
| 20 | |
| 21 | if [ "$SILENT" = "-y" ]; then |
| 22 | sudo apt-get install -y software-properties-common python-software-properties |
| 23 | fi |
| 24 | |
| 25 | # print what's going on |
| 26 | set -x |
| 27 | |
| 28 | sudo add-apt-repository ${SILENT} ppa:webupd8team/java |
| 29 | if [ $? -ne 0 ]; then |
| 30 | { set +x; } 2>/dev/null |
| 31 | echo |
| 32 | echo "Registering Oracle Java repository failed." |
| 33 | echo "If the error was about add-apt-repository command not found," |
| 34 | echo "try one of the following and retry running this script" |
| 35 | echo |
| 36 | echo "$ sudo apt-get install software-properties-common" |
| 37 | echo "$ sudo apt-get install software-properties-common python-software-properties" |
| 38 | echo |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | # fail on error |
| 43 | set -e |
| 44 | |
| 45 | sudo apt-get update |
Yuta HIGUCHI | d4793b2 | 2014-04-07 19:35:21 -0700 | [diff] [blame] | 46 | { |
| 47 | sudo apt-get install ${SILENT} oracle-java7-set-default |
| 48 | } || { |
| 49 | { set +x; } 2>/dev/null |
| 50 | echo |
| 51 | echo "Installing Oracle Java failed." |
| 52 | echo "This script cannot be used if ubuntu release has reached end of life." |
| 53 | echo "Check if your ubuntu release is still supported." |
| 54 | echo " https://wiki.ubuntu.com/Releases" |
| 55 | echo |
| 56 | lsb_release -a |
| 57 | exit 1 |
| 58 | } |
Yuta HIGUCHI | 328acd8 | 2014-03-27 12:51:42 -0700 | [diff] [blame] | 59 | { set +x; } 2>/dev/null |
| 60 | echo |
| 61 | echo "Done. You may need to relogin for the environment variable change to take effect." |
| 62 | |
| 63 | |