├── LICENSE ├── NOTICE ├── README.md ├── install-java.sh └── uninstall-java.sh /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | install-java 2 | Copyright 2014 Isuru Perera 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Java Development Kit (JDK) installation script for Linux 2 | ======================================================== 3 | 4 | "install-java.sh" is an installation script for setting up Java Development Kit (JDK) on Debian based Linux Operating Systems. 5 | 6 | Currently, the `install-java.sh` script supports `tar.gz` distributions from [Oracle](https://www.oracle.com/technetwork/java/index.html), [OpenJDK](http://openjdk.java.net/) and [AdoptOpenJDK](https://adoptopenjdk.net/) 7 | 8 | I'm mainly using Ubuntu and therefore this script is tested only on different versions of Ubuntu. 9 | 10 | ## Prerequisites 11 | 12 | The script uses "unzip" command. Therefore, please make sure it is installed. 13 | 14 | `sudo apt install unzip` 15 | 16 | The "install-java.sh" script will not download the Java distribution. You must download JDK `tar.gz` distribution. 17 | 18 | For Oracle JDK 7 & 8, `install-java.sh` supports installing demos and "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files". This files are picked up from the same directory. 19 | 20 | For example, if you want to install Java 7, then the following files should be downloaded and moved to a single directory. 21 | 22 | - jdk-7u80-linux-x64.tar.gz 23 | - jdk-7u80-linux-x64-demos.tar.gz 24 | - UnlimitedJCEPolicyJDK7.zip 25 | 26 | Similarly for Java 8, following are the files required 27 | 28 | - jdk-8u212-linux-x64.tar.gz 29 | - jdk-8u212-linux-x64-demos.tar.gz 30 | - jce_policy-8.zip 31 | 32 | The Java Demos and Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy files are optional. There are no demos from Java 9 upwards. Since Java 9, default JCE policy files already allow for "unlimited" cryptographic strengths. 33 | 34 | For any other JDK, you only need to have the Java binary distribution. 35 | 36 | ## Installation 37 | 38 | The script needs to be run as root. 39 | 40 | You need to provide the JDK distribution file (`tar.gz`) and the Java Installation Directory. The default value for Java installation directory is "/usr/lib/jvm" 41 | 42 | ```console 43 | $ sudo ./install-java.sh -h 44 | 45 | Usage: 46 | install-java.sh -f [-p ] 47 | 48 | -f: The jdk tar.gz file. 49 | -p: Java installation directory. Default: /usr/lib/jvm. 50 | -h: Display this help and exit. 51 | 52 | ``` 53 | 54 | Example: Installing Oracle JDK 12 55 | 56 | ```console 57 | $ sudo ./install-java.sh -f ~/software/java/jdk-12.0.1_linux-x64_bin.tar.gz 58 | Installing: jdk-12.0.1_linux-x64_bin.tar.gz 59 | Extracting /home/isuru/software/java/jdk-12.0.1_linux-x64_bin.tar.gz to /usr/lib/jvm 60 | JDK is extracted to /usr/lib/jvm/jdk-12.0.1 61 | Run update-alternatives commands? [y/N] 62 | Do you want to set JAVA_HOME environment variable in /home/isuru/.bashrc? [y/N] 63 | ``` 64 | 65 | ## Automate Java Installation 66 | 67 | You can automate the Java installation script by using the `yes` command. 68 | 69 | Example: Installing AdoptOpenJDK 11 70 | 71 | `yes | sudo ./install-java.sh -f ~/software/java/OpenJDK11U-jdk_x64_linux_hotspot_11.0.3_7.tar.gz` 72 | 73 | ## Java Mission Control 74 | 75 | The installation script will also create a shortcut for Oracle Java Mission Control (JMC). 76 | 77 | If the "Welcome" page is blank in JMC, try installing `libwebkitgtk-3.0-0` package. 78 | 79 | `sudo apt install libwebkitgtk-3.0-0` 80 | 81 | ## Uninstallation 82 | 83 | There is another script named "uninstall-java.sh" to uninstall Java. 84 | 85 | You need to provide Java distribution directory. 86 | 87 | ```console 88 | $ sudo ./uninstall-java.sh -h 89 | 90 | Usage: 91 | uninstall-java.sh -p 92 | 93 | -p: Java distribution directory. 94 | -h: Display this help and exit. 95 | ``` 96 | 97 | Example: Uninstall Oracle JDK 12 98 | 99 | `sudo ./uninstall-java.sh -p /usr/lib/jvm/jdk-12.0.1/` 100 | 101 | ## License 102 | 103 | Copyright (C) 2014 M. Isuru Tharanga Chrishantha Perera 104 | 105 | Licensed under the Apache License, Version 2.0 106 | -------------------------------------------------------------------------------- /install-java.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2014 M. Isuru Tharanga Chrishantha Perera 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # ---------------------------------------------------------------------------- 17 | # Installation script for setting up Java on Linux 18 | # ---------------------------------------------------------------------------- 19 | 20 | java_dist="" 21 | default_java_dir="/usr/lib/jvm" 22 | java_dir="$default_java_dir" 23 | 24 | function usage() { 25 | echo "" 26 | echo "This script will not download the Java distribution. You must download JDK tar.gz distribution. Then use this script to install it." 27 | echo "Usage: " 28 | echo "install-java.sh -f [-p ]" 29 | echo "" 30 | echo "-f: The jdk tar.gz file." 31 | echo "-p: Java installation directory. Default: $default_java_dir." 32 | echo "-h: Display this help and exit." 33 | echo "" 34 | } 35 | 36 | function confirm() { 37 | # call with a prompt string or use a default 38 | read -r -p "${1:-Are you sure?} [y/N] " response 39 | case $response in 40 | [yY][eE][sS] | [yY]) 41 | true 42 | ;; 43 | *) 44 | false 45 | ;; 46 | esac 47 | } 48 | 49 | # Make sure the script is running as root. 50 | if [ "$UID" -ne "0" ]; then 51 | echo "You must be root to run $0. Try following" 52 | echo "sudo $0" 53 | exit 9 54 | fi 55 | 56 | while getopts "f:p:h" opts; do 57 | case $opts in 58 | f) 59 | java_dist=${OPTARG} 60 | ;; 61 | p) 62 | java_dir=${OPTARG} 63 | ;; 64 | h) 65 | usage 66 | exit 0 67 | ;; 68 | \?) 69 | usage 70 | exit 1 71 | ;; 72 | esac 73 | done 74 | 75 | if [[ ! -f $java_dist ]]; then 76 | echo "Please specify the Java distribution file." 77 | echo "Use -h for help." 78 | exit 1 79 | fi 80 | 81 | # Validate Java Distribution 82 | java_dist_filename=$(basename $java_dist) 83 | 84 | if [[ ${java_dist_filename: -7} != ".tar.gz" ]]; then 85 | echo "Java distribution must be a valid tar.gz file." 86 | exit 1 87 | fi 88 | 89 | # Create the default directory if user has not specified any other path 90 | if [[ $java_dir == $default_java_dir ]]; then 91 | mkdir -p $java_dir 92 | fi 93 | 94 | #Validate java directory 95 | if [[ ! -d $java_dir ]]; then 96 | echo "Please specify a valid Java installation directory." 97 | exit 1 98 | fi 99 | 100 | echo "Installing: $java_dist_filename" 101 | 102 | # Check Java executable 103 | java_exec="$(tar -tzf $java_dist | grep ^[^/]*/bin/java$ || echo "")" 104 | 105 | if [[ -z $java_exec ]]; then 106 | echo "Could not find \"java\" executable in the distribution. Please specify a valid Java distribution." 107 | exit 1 108 | fi 109 | 110 | # JDK Directory with version 111 | jdk_dir="$(echo $java_exec | cut -f1 -d"/")" 112 | extracted_dirname=$java_dir"/"$jdk_dir 113 | 114 | # Extract Java Distribution 115 | if [[ ! -d $extracted_dirname ]]; then 116 | echo "Extracting $java_dist to $java_dir" 117 | tar -xof $java_dist -C $java_dir 118 | echo "JDK is extracted to $extracted_dirname" 119 | else 120 | echo "WARN: JDK was not extracted to $java_dir. There is an existing directory with the name \"$jdk_dir\"." 121 | if ! (confirm "Do you want to continue?"); then 122 | exit 1 123 | fi 124 | fi 125 | 126 | if [[ ! -f "${extracted_dirname}/bin/java" ]]; then 127 | echo "ERROR: The path $extracted_dirname is not a valid Java installation." 128 | exit 1 129 | fi 130 | 131 | # Oracle JDK: 7 to 8 132 | java_78_dir_regex="^jdk1\.([0-9]*).*$" 133 | # Oracle JDK / OpenJDK / AdoptOpenJDK: 9 and upwards 134 | java_9up_dir_regex="^jdk-([0-9]*).*$" 135 | 136 | # JDK Major Version 137 | jdk_major_version="" 138 | 139 | if [[ $jdk_dir =~ $java_78_dir_regex ]]; then 140 | jdk_major_version=$(echo $jdk_dir | sed -nE "s/$java_78_dir_regex/\1/p") 141 | else 142 | jdk_major_version=$(echo $jdk_dir | sed -nE "s/$java_9up_dir_regex/\1/p") 143 | fi 144 | 145 | # Install Demos 146 | 147 | if [[ $jdk_dir =~ $java_78_dir_regex ]]; then 148 | # Demos are only available for Java 7 and 8 149 | demos_dist=$(dirname $java_dist)"/"$(echo $java_dist_filename | sed 's/\.tar\.gz/-demos\0/') 150 | fi 151 | 152 | if [[ -f $demos_dist && ! -d $extracted_dirname/demo ]]; then 153 | # No demo directory 154 | if (confirm "Extract demos?"); then 155 | echo "Extracting $demos_dist to $java_dir" 156 | tar -xf $demos_dist -C $java_dir 157 | fi 158 | fi 159 | 160 | # Install Unlimited JCE Policy (only for Oracle JDK 7 & 8) 161 | # Java 9 and above: default JCE policy files already allow for \"unlimited\" cryptographic strengths. 162 | 163 | unlimited_jce_policy_dist="" 164 | 165 | if [[ $jdk_dir =~ ^jdk1\.7.* ]]; then 166 | unlimited_jce_policy_dist="$(dirname $java_dist)/UnlimitedJCEPolicyJDK7.zip" 167 | elif [[ $jdk_dir =~ ^jdk1\.8.* ]]; then 168 | unlimited_jce_policy_dist="$(dirname $java_dist)/jce_policy-8.zip" 169 | fi 170 | 171 | if [[ -f $unlimited_jce_policy_dist ]]; then 172 | #Check whether unzip command exsits 173 | if ! command -v unzip >/dev/null 2>&1; then 174 | echo "Please install unzip (apt -y install unzip)." 175 | exit 1 176 | fi 177 | if (confirm "Install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files?"); then 178 | echo "Extracting policy jars in $unlimited_jce_policy_dist to $extracted_dirname/jre/lib/security" 179 | unzip -j -o $unlimited_jce_policy_dist *.jar -d $extracted_dirname/jre/lib/security 180 | fi 181 | fi 182 | 183 | # Run update-alternatives commands 184 | if (confirm "Run update-alternatives commands?"); then 185 | echo "Running update-alternatives..." 186 | cmd="update-alternatives --install /usr/bin/java java $extracted_dirname/bin/java 10000" 187 | declare -a commands=($(ls -1 ${extracted_dirname}/bin | grep -v ^java$)) 188 | for command in "${commands[@]}"; do 189 | command_path=$extracted_dirname/bin/$command 190 | if [[ -x $command_path ]]; then 191 | cmd="$cmd --slave /usr/bin/$command $command $command_path" 192 | fi 193 | done 194 | lib_path=$extracted_dirname/jre/lib/amd64/libnpjp2.so 195 | if [[ -d "/usr/lib/mozilla/plugins/" ]] && [[ -f $lib_path ]]; then 196 | cmd="$cmd --slave /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so $lib_path" 197 | fi 198 | echo $cmd 199 | # Execute command 200 | $cmd 201 | update-alternatives --set java $extracted_dirname/bin/java 202 | fi 203 | 204 | # Create system preferences directory 205 | java_system_prefs_dir="/etc/.java/.systemPrefs" 206 | if [[ ! -d $java_system_prefs_dir ]]; then 207 | if (confirm "Create Java System Prefs Directory ($java_system_prefs_dir) and change ownership to $SUDO_USER:$SUDO_USER?"); then 208 | echo "Creating $java_system_prefs_dir" 209 | mkdir -p $java_system_prefs_dir 210 | chown -R $SUDO_USER:$SUDO_USER $java_system_prefs_dir 211 | fi 212 | fi 213 | 214 | USER_HOME="$(getent passwd $SUDO_USER | cut -d: -f6)" 215 | 216 | if [[ -d "$USER_HOME" ]] && (confirm "Do you want to set JAVA_HOME environment variable in $USER_HOME/.bashrc?"); then 217 | if grep -q "export JAVA_HOME=.*" $USER_HOME/.bashrc; then 218 | sed -i "s|export JAVA_HOME=.*|export JAVA_HOME=$extracted_dirname|" $USER_HOME/.bashrc 219 | else 220 | echo "export JAVA_HOME=$extracted_dirname" >>$USER_HOME/.bashrc 221 | fi 222 | fi 223 | 224 | applications_dir="$USER_HOME/.local/share/applications" 225 | 226 | create_jmc_shortcut() { 227 | shortcut_file="$applications_dir/jmc_$jdk_major_version.desktop" 228 | cat <<_EOF_ >$shortcut_file 229 | [Desktop Entry] 230 | Name=Java $jdk_major_version: JMC 231 | Comment=Oracle Java Mission Control for Java $jdk_major_version 232 | Type=Application 233 | Exec=$extracted_dirname/bin/jmc 234 | Icon=$extracted_dirname/lib/missioncontrol/icon.xpm 235 | Terminal=false 236 | _EOF_ 237 | chmod +x $shortcut_file 238 | } 239 | 240 | if [[ -d $applications_dir ]] && [[ -f $extracted_dirname/bin/jmc ]]; then 241 | if (confirm "Do you want to create a desktop shortcut to JMC?"); then 242 | create_jmc_shortcut 243 | fi 244 | fi 245 | -------------------------------------------------------------------------------- /uninstall-java.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2015 M. Isuru Tharanga Chrishantha Perera 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # ---------------------------------------------------------------------------- 17 | # Script for uninstalling Java 18 | # ---------------------------------------------------------------------------- 19 | 20 | java_dist_dir="" 21 | 22 | function usage() { 23 | echo "" 24 | echo "Usage: " 25 | echo "uninstall-java.sh -p " 26 | echo "" 27 | echo "-p: Java distribution directory." 28 | echo "-h: Display this help and exit." 29 | echo "" 30 | } 31 | 32 | function confirm() { 33 | # call with a prompt string or use a default 34 | read -r -p "${1:-Are you sure?} [y/N] " response 35 | case $response in 36 | [yY][eE][sS] | [yY]) 37 | true 38 | ;; 39 | *) 40 | false 41 | ;; 42 | esac 43 | } 44 | 45 | # Make sure the script is running as root. 46 | if [ "$UID" -ne "0" ]; then 47 | echo "You must be root to run $0. Try following" 48 | echo "sudo $0" 49 | exit 9 50 | fi 51 | 52 | while getopts "p:h" opts; do 53 | case $opts in 54 | p) 55 | java_dist_dir=${OPTARG} 56 | ;; 57 | h) 58 | usage 59 | exit 0 60 | ;; 61 | \?) 62 | usage 63 | exit 1 64 | ;; 65 | esac 66 | done 67 | 68 | if [[ -z $java_dist_dir ]]; then 69 | echo "Please provide Java installation directory." 70 | fi 71 | 72 | echo "Uninstalling: $java_dist_dir" 73 | 74 | if [[ ! -f $java_dist_dir/bin/java ]]; then 75 | echo "Please specify a valid Java distribution directory" 76 | exit 1 77 | fi 78 | 79 | # Run update-alternatives commands 80 | if (confirm "Run update-alternatives commands?"); then 81 | echo "Running update-alternatives..." 82 | update-alternatives --remove java ${java_dist_dir}/bin/java 83 | fi 84 | 85 | if (confirm "Remove directory '$java_dist_dir'?"); then 86 | rm -rf $java_dist_dir 87 | fi 88 | 89 | jdk_major_version="" 90 | 91 | if [[ $java_dist_dir =~ .*jdk1\.([0-9]*).* ]]; then 92 | jdk_major_version=$(echo $java_dist_dir | sed -nE 's/.*jdk1\.([0-9]*).*/\1/p') 93 | elif [[ $java_dist_dir =~ .*jdk-([0-9]*).* ]]; then 94 | jdk_major_version=$(echo $java_dist_dir | sed -nE 's/.*jdk-([0-9]*).*/\1/p') 95 | fi 96 | 97 | applications_dir="$HOME/.local/share/applications" 98 | jmc_shortcut_file="$applications_dir/jmc_$jdk_major_version.desktop" 99 | 100 | if [ -f $jmc_shortcut_file ] && (confirm "Remove JMC shortcut?"); then 101 | rm $jmc_shortcut_file 102 | fi 103 | --------------------------------------------------------------------------------