-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_oracle_jdk.sh
executable file
·38 lines (30 loc) · 1.02 KB
/
install_oracle_jdk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Define the URL and the installation path
JDK_URL="https://archive.org/download/jdk-8u391-macosx-x64/jdk-8u391-macosx-x64.dmg"
DMG_FILE="jdk-8u391-macosx-x64.dmg"
INSTALL_PATH="/Library/Java/JavaVirtualMachines"
# Download the JDK using curl
echo "Downloading Oracle JDK..."
curl -L -o "$DMG_FILE" $JDK_URL
# Check if the download was successful
if [ ! -f "$DMG_FILE" ]; then
echo "Download failed. DMG file not found."
exit 1
fi
# Mount the downloaded DMG file
echo "Mounting DMG file..."
MOUNT_DIR=`hdiutil attach jdk-8u391-macosx-x64.dmg -nobrowse -noautoopen -noverify $
# Check if the mounting was successful
if [ -z "$MOUNT_DIR" ]; then
echo "Failed to mount DMG file."
exit 1
fi
# Perform silent installation using osascript for administrative privileges
echo "Installing JDK..."
cp -rf $MOUNT_DIR/*.pkg /tmp/oracle-jdk.pkg
sudo installer -pkg /tmp/oracle-jdk.pkg -target /
# Eject the mounted image
hdiutil detach "$MOUNT_DIR"
# Clean up downloaded file
rm "$DMG_FILE"
echo "Installation complete."