Skip to content

Instantly share code, notes, and snippets.

@marshki
Last active July 16, 2023 18:01
Show Gist options
  • Save marshki/6f92ecc9058cfa5858cb6a6c2da9f9df to your computer and use it in GitHub Desktop.
Save marshki/6f92ecc9058cfa5858cb6a6c2da9f9df to your computer and use it in GitHub Desktop.
Add MATLAB icon launcher in Ubuntu.
#!/usr/bin/env bash
#
# add_matlab_launcher
#
# Author: M. Krinitz <mjk235 [at] nyu [dot] edu>
#
# Add a MATLAB icon launcher in Ubuntu.
# Date: 2023.07.14
# License: MIT
MATLAB_PNG="http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png"
MATLAB_VERSION="2019a"
ICON_PATH="/usr/share/icons/matlab.png"
LAUNCHER_FILE="/usr/share/applications/matlab.desktop"
# Is current UID 0? If not, exit.
root_check() {
if [ "$EUID" -ne "0" ] ; then
printf "%s\n" "ERROR: ROOT PRIVILEGES ARE REQUIRED TO CONTINUE. EXITING." >&2
exit 1
fi
}
# Is wget installed? If not, install it.
wget_check() {
if [ "$(dpkg-query --show --showformat='${Status}' wget 2>/dev/null \
| grep --count "ok installed")" -eq "0" ]; then
printf "%s\n" "WGET IS NOT INSTALLED. LET'S INSTALL IT..."
apt-get install wget
fi
}
# Place MATLAB icon from 'da interwebs in: /usr/share/icons/.
get_icon() {
if ! wget --progress=bar --tries=3 --wait=5 --continue $MATLAB_PNG --output-document="$ICON_PATH"; then
printf "%s\n" "ERROR: FAILED TO DOWNLOAD MATLAB ICON. EXITING." >&2
exit 1
fi
}
# Create matlab.desktop file in: /usr/share/applications/matlab.desktop.
make_file() {
cat > "$LAUNCHER_FILE" << EOF
#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Icon=$ICON_PATH
Name=$MATLAB_VERSION
Comment=Start MATLAB - The Language of Technical Computing
Exec=matlab -desktop
Categories=Development;
EOF
if ! [ -e "LAUNCHER_FILE" ]; then
printf "%s\n" "ERROR: FAILED TO CREATE MATLAB LAUNCHER. EXITING." >&2
exit 1
fi
}
main() {
root_check
wget_check
get_icon
make_file
printf "%s\n" "SUCCESSFULLY CREATED MATLAB LAUNCHER."
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment