Skip to content

Instantly share code, notes, and snippets.

@neilcsmith-net
Last active March 28, 2024 14:36
Show Gist options
  • Save neilcsmith-net/69bcb23bcc6698815438dc4e3df6caa3 to your computer and use it in GitHub Desktop.
Save neilcsmith-net/69bcb23bcc6698815438dc4e3df6caa3 to your computer and use it in GitHub Desktop.
Apache NetBeans AppImage creation script
#!/usr/bin/env bash
# Bash script to download Apache NetBeans and (optionally) a JDK, then package into an AppImage.
#
# Use at own risk! Will create a /build directory inside current directory for downloading and
# building. AppImage will be created in current directory.
#
# (c) 2020 Neil C Smith - [email protected]
shopt -s extglob
# System architecture to create AppImage for - see options at https://github.com/AppImage/AppImageKit/releases/continuous/
SYSTEM_ARCH="x86_64"
# NetBeans version to download - change NETBEANS_URL if archived release.
NETBEANS_VERSION="12.2"
# Optional JDK tar.gz file to include
JDK_URL="https://github.com/AdoptOpenJDK/openjdk15-binaries/releases/download/jdk-15.0.1%2B9/OpenJDK15U-jdk_x64_linux_hotspot_15.0.1_9.tar.gz"
NETBEANS_URL="https://www.apache.org/dyn/closer.lua?action=download&filename=netbeans/netbeans/${NETBEANS_VERSION}/netbeans-${NETBEANS_VERSION}-bin.zip"
APPIMAGETOOL_URL="https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$SYSTEM_ARCH.AppImage"
# create build directory for needed resources
mkdir -p build/
cd build/
# download AppImage tool
wget -c $APPIMAGETOOL_URL
chmod +x "./appimagetool-${SYSTEM_ARCH}.AppImage"
# download and extract Apache NetBeans release
wget -c -O netbeans-${NETBEANS_VERSION}-bin.zip $NETBEANS_URL
unzip -o netbeans-${NETBEANS_VERSION}-bin.zip
# create AppDir structure
mkdir -p AppDir/
mkdir -p AppDir/usr/lib/
mv netbeans/ AppDir/usr/lib/
mkdir -p AppDir/usr/bin/
ln -s ../lib/netbeans/bin/netbeans AppDir/usr/bin/netbeans
mkdir -p AppDir/usr/share/applications/
mkdir -p AppDir/usr/share/icons/hicolor/32x32/
cp AppDir/usr/lib/netbeans/nb/netbeans.png AppDir/usr/share/icons/hicolor/32x32/netbeans.png
cat > AppDir/usr/share/applications/netbeans.desktop <<EOF
[Desktop Entry]
Encoding=UTF-8
Name=Apache NetBeans IDE
Exec=netbeans
Icon=netbeans
Categories=Development;Java;IDE;
Version=1.0
Type=Application
Terminal=false
EOF
ln -s usr/share/applications/netbeans.desktop AppDir/netbeans.desktop
ln -s usr/share/icons/hicolor/32x32/netbeans.png AppDir/netbeans.png
ln -s usr/share/icons/hicolor/32x32/netbeans.png AppDir/.DirIcon
# download and extract JDK into AppDir if provided
if [ -n $JDK_URL ]
then
wget -c $JDK_URL
mkdir -p jdk/
cd jdk/
tar xf ../*.tar.gz
mv * jdk
cd ../
mv jdk/jdk AppDir/usr/lib/
fi
# create AppRun script with JDK lookup
cat > AppDir/AppRun << "EOF"
#!/usr/bin/env bash
HERE="$(dirname "$(readlink -f "${0}")")"
if [ -d "$HERE/usr/lib/jdk" ] ; then
if [ -z "$JAVA_HOME" ] ; then
export JAVA_HOME="$HERE/usr/lib/jdk/"
fi
exec "$HERE/usr/bin/netbeans" --jdkhome "$HERE/usr/lib/jdk" "$@"
else
exec "$HERE/usr/bin/netbeans" "$@"
fi
EOF
chmod +x AppDir/AppRun
# build AppImage
ARCH=${SYSTEM_ARCH} "./appimagetool-${SYSTEM_ARCH}.AppImage" AppDir/ "../Apache-NetBeans-${NETBEANS_VERSION}-${SYSTEM_ARCH}.AppImage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment