Skip to content

Instantly share code, notes, and snippets.

@mokshchadha
Created September 8, 2024 12:51
Show Gist options
  • Save mokshchadha/1a352570dd8ba19ca43d827407233be0 to your computer and use it in GitHub Desktop.
Save mokshchadha/1a352570dd8ba19ca43d827407233be0 to your computer and use it in GitHub Desktop.
freebsd install intellij IDEA
#!/bin/sh
# Function to check the exit status of the last command and handle errors
check_error() {
if [ $? -ne 0 ]; then
echo "Error: $1 failed. Exiting."
exit 1
fi
}
# Update package repository
echo "Updating package repository..."
pkg update
check_error "Package repository update"
# Install OpenJDK (recommended version is 17)
echo "Installing OpenJDK 17..."
pkg install -y openjdk17
check_error "OpenJDK installation"
# Set the default Java version to OpenJDK 17
echo "Setting default Java version to OpenJDK 17..."
sysrc java_version="openjdk17"
check_error "Setting Java version"
# Install wget (needed for downloading IntelliJ)
echo "Installing wget..."
pkg install -y wget
check_error "wget installation"
# Download IntelliJ IDEA Community Edition
echo "Downloading IntelliJ IDEA Community Edition..."
wget -O /tmp/intellij.tar.gz "https://download.jetbrains.com/idea/ideaIC-2023.2.1.tar.gz"
check_error "Downloading IntelliJ IDEA"
# Extract the downloaded archive
echo "Extracting IntelliJ IDEA to /opt/intellij..."
mkdir -p /opt/intellij
tar -xzf /tmp/intellij.tar.gz -C /opt/intellij --strip-components=1
check_error "Extracting IntelliJ IDEA"
# Check for bin directory
if [ -d "/opt/intellij/bin" ]; then
echo "bin directory found."
echo "Contents of /opt/intellij/bin:"
ls -la /opt/intellij/bin
else
echo "Error: bin directory not found in /opt/intellij"
fi
# Check for idea.sh
if [ -f "/opt/intellij/bin/idea.sh" ]; then
echo "idea.sh found."
else
echo "Error: idea.sh not found in /opt/intellij/bin"
fi
# Clean up the downloaded file
echo "Cleaning up the downloaded file..."
rm "/tmp/intellij.tar.gz"
check_error "Cleanup of downloaded file"
# Create a symlink for easy access (only if idea.sh exists)
if [ -f "/opt/intellij/bin/idea.sh" ]; then
ln -sf /opt/intellij/bin/idea.sh /usr/local/bin/intellij
echo "Symlink created: /usr/local/bin/intellij -> /opt/intellij/bin/idea.sh"
else
echo "Symlink not created because idea.sh was not found"
fi
echo "Installation script completed. Please check the output above for any errors."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment