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 |
| 46 | sudo apt-get install ${SILENT} oracle-java7-set-default |
| 47 | |
| 48 | { set +x; } 2>/dev/null |
| 49 | echo |
| 50 | echo "Done. You may need to relogin for the environment variable change to take effect." |
| 51 | |
| 52 | |