mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Updated Linux install script to be flexible about different desktop folder locations.
This commit is contained in:
parent
22496e14d5
commit
7d4787bcff
103
build/linux/dist/install.sh
vendored
103
build/linux/dist/install.sh
vendored
@ -11,11 +11,17 @@ RESOURCE_NAME=arduino-arduinoide
|
|||||||
# Get absolute path from which this script file was executed
|
# Get absolute path from which this script file was executed
|
||||||
# (Could be changed to "pwd -P" to resolve symlinks to their target)
|
# (Could be changed to "pwd -P" to resolve symlinks to their target)
|
||||||
SCRIPT_PATH=$( cd $(dirname $0) ; pwd )
|
SCRIPT_PATH=$( cd $(dirname $0) ; pwd )
|
||||||
cd "$SCRIPT_PATH"
|
cd "${SCRIPT_PATH}"
|
||||||
|
|
||||||
# Default mode is to install.
|
# Default mode is to install.
|
||||||
UNINSTALL=false
|
UNINSTALL=false
|
||||||
|
|
||||||
|
# If possible, get location of the desktop folder. Default to ~/Desktop
|
||||||
|
XDG_DESKTOP_DIR="${HOME}/Desktop"
|
||||||
|
if [ -f "${XDG_CONFIG_HOME:-${HOME}/.config}/user-dirs.dirs" ]; then
|
||||||
|
. "${XDG_CONFIG_HOME:-${HOME}/.config}/user-dirs.dirs"
|
||||||
|
fi
|
||||||
|
|
||||||
# Install using xdg-utils
|
# Install using xdg-utils
|
||||||
xdg_install_f() {
|
xdg_install_f() {
|
||||||
|
|
||||||
@ -76,17 +82,19 @@ simple_install_f() {
|
|||||||
sed -e "s,<BINARY_LOCATION>,${SCRIPT_PATH}/arduino,g" \
|
sed -e "s,<BINARY_LOCATION>,${SCRIPT_PATH}/arduino,g" \
|
||||||
-e "s,<ICON_NAME>,${SCRIPT_PATH}/lib/arduino.png,g" "${SCRIPT_PATH}/lib/desktop.template" > "${TMP_DIR}/${RESOURCE_NAME}.desktop"
|
-e "s,<ICON_NAME>,${SCRIPT_PATH}/lib/arduino.png,g" "${SCRIPT_PATH}/lib/desktop.template" > "${TMP_DIR}/${RESOURCE_NAME}.desktop"
|
||||||
|
|
||||||
mkdir -p ~/.local/share/applications
|
mkdir -p "${HOME}/.local/share/applications"
|
||||||
cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" ~/.local/share/applications/
|
cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" "${HOME}/.local/share/applications/"
|
||||||
|
|
||||||
# Create desktop icon if dir exists
|
# Copy desktop icon if desktop dir exists (was found)
|
||||||
if [ -d ~/Desktop ]; then
|
if [ -d "${XDG_DESKTOP_DIR}" ]; then
|
||||||
cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" ~/Desktop/
|
cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" "${XDG_DESKTOP_DIR}/"
|
||||||
|
# Altering file permissions to avoid "Untrusted Application Launcher" error on Ubuntu
|
||||||
|
chmod u+x "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up
|
# Clean up temp dir
|
||||||
rm "${TMP_DIR}/${RESOURCE_NAME}.desktop"
|
rm "${TMP_DIR}/${RESOURCE_NAME}.desktop"
|
||||||
rmdir "$TMP_DIR"
|
rmdir "${TMP_DIR}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,15 +108,15 @@ xdg_uninstall_f() {
|
|||||||
xdg-desktop-icon uninstall ${RESOURCE_NAME}.desktop
|
xdg-desktop-icon uninstall ${RESOURCE_NAME}.desktop
|
||||||
|
|
||||||
# Remove icons
|
# Remove icons
|
||||||
xdg-icon-resource uninstall --size 16 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 16 ${RESOURCE_NAME}
|
||||||
xdg-icon-resource uninstall --size 24 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 24 ${RESOURCE_NAME}
|
||||||
xdg-icon-resource uninstall --size 32 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 32 ${RESOURCE_NAME}
|
||||||
xdg-icon-resource uninstall --size 48 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 48 ${RESOURCE_NAME}
|
||||||
xdg-icon-resource uninstall --size 64 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 64 ${RESOURCE_NAME}
|
||||||
xdg-icon-resource uninstall --size 72 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 72 ${RESOURCE_NAME}
|
||||||
xdg-icon-resource uninstall --size 96 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 96 ${RESOURCE_NAME}
|
||||||
xdg-icon-resource uninstall --size 128 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 128 ${RESOURCE_NAME}
|
||||||
xdg-icon-resource uninstall --size 256 $RESOURCE_NAME
|
xdg-icon-resource uninstall --size 256 ${RESOURCE_NAME}
|
||||||
|
|
||||||
# Remove MIME type icons
|
# Remove MIME type icons
|
||||||
xdg-icon-resource uninstall --size 16 text-x-arduino
|
xdg-icon-resource uninstall --size 16 text-x-arduino
|
||||||
@ -129,20 +137,20 @@ xdg_uninstall_f() {
|
|||||||
# Uninstall by simply removing desktop files (fallback), incl. old one
|
# Uninstall by simply removing desktop files (fallback), incl. old one
|
||||||
simple_uninstall_f() {
|
simple_uninstall_f() {
|
||||||
|
|
||||||
if [ -f ~/.local/share/applications/arduino.desktop ]; then
|
if [ -f "${HOME}/.local/share/applications/arduino.desktop" ]; then
|
||||||
rm ~/.local/share/applications/arduino.desktop
|
rm "${HOME}/.local/share/applications/arduino.desktop"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f ~/.local/share/applications/${RESOURCE_NAME}.desktop ]; then
|
if [ -f "${HOME}/.local/share/applications/${RESOURCE_NAME}.desktop" ]; then
|
||||||
rm ~/.local/share/applications/${RESOURCE_NAME}.desktop
|
rm "${HOME}/.local/share/applications/${RESOURCE_NAME}.desktop"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f ~/Desktop/arduino.desktop ]; then
|
if [ -f "${XDG_DESKTOP_DIR}/arduino.desktop" ]; then
|
||||||
rm ~/Desktop/arduino.desktop
|
rm "${XDG_DESKTOP_DIR}/arduino.desktop"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f ~/Desktop/${RESOURCE_NAME}.desktop ]; then
|
if [ -f "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop" ]; then
|
||||||
rm ~/Desktop/${RESOURCE_NAME}.desktop
|
rm "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -150,15 +158,15 @@ simple_uninstall_f() {
|
|||||||
# Update desktop file and mime databases (if possible)
|
# Update desktop file and mime databases (if possible)
|
||||||
updatedbs_f() {
|
updatedbs_f() {
|
||||||
|
|
||||||
if [ -d ~/.local/share/applications ]; then
|
if [ -d "${HOME}/.local/share/applications" ]; then
|
||||||
if command -v update-desktop-database > /dev/null; then
|
if command -v update-desktop-database > /dev/null; then
|
||||||
update-desktop-database ~/.local/share/applications
|
update-desktop-database "${HOME}/.local/share/applications"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d ~/.local/share/mime ]; then
|
if [ -d "${HOME}/.local/share/mime" ]; then
|
||||||
if command -v update-mime-database > /dev/null; then
|
if command -v update-mime-database > /dev/null; then
|
||||||
update-mime-database ~/.local/share/mime
|
update-mime-database "${HOME}/.local/share/mime"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -177,25 +185,19 @@ xdg_exists_f() {
|
|||||||
|
|
||||||
# Shows a description of the available options
|
# Shows a description of the available options
|
||||||
display_help_f() {
|
display_help_f() {
|
||||||
echo "\n"
|
printf "\nThis script will add a Arduino IDE desktop shortcut, menu item,\n"
|
||||||
echo "This script will add a Arduino IDE desktop shortcut, menu item,"
|
printf "icons and file associations for the current user.\n"
|
||||||
echo "icons and file associations for the current user."
|
|
||||||
if ! xdg_exists_f; then
|
if ! xdg_exists_f; then
|
||||||
echo "\n"
|
printf "\nxdg-utils are recommended to be installed, so this script can use them.\n"
|
||||||
echo "xdg-utils are recommended to be installed, so this script can use them."
|
|
||||||
fi
|
fi
|
||||||
echo "\n"
|
printf "\nOptional arguments are:\n\n"
|
||||||
echo "Optional arguments are:"
|
printf "\t-u, --uninstall\t\tRemoves shortcut, menu item and icons.\n\n"
|
||||||
echo "\n"
|
printf "\t-h, --help\t\tShows this help again.\n\n"
|
||||||
echo "\t-u, --uninstall\t\tRemoves shortcut, menu item and icons."
|
|
||||||
echo "\n"
|
|
||||||
echo "\t-h, --help\t\tShows this help again."
|
|
||||||
echo "\n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for provided arguments
|
# Check for provided arguments
|
||||||
while [ $# -gt 0 ] ; do
|
while [ $# -gt 0 ] ; do
|
||||||
ARG="$1"
|
ARG="${1}"
|
||||||
case $ARG in
|
case $ARG in
|
||||||
-u|--uninstall)
|
-u|--uninstall)
|
||||||
UNINSTALL=true
|
UNINSTALL=true
|
||||||
@ -206,8 +208,7 @@ while [ $# -gt 0 ] ; do
|
|||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "\n"
|
printf "\nInvalid option -- '${ARG}'\n"
|
||||||
echo "Invalid option -- '$ARG'"
|
|
||||||
display_help_f
|
display_help_f
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
@ -216,27 +217,27 @@ done
|
|||||||
|
|
||||||
# If possible, use xdg-utils, if not, use a more basic approach
|
# If possible, use xdg-utils, if not, use a more basic approach
|
||||||
if xdg_exists_f; then
|
if xdg_exists_f; then
|
||||||
if [ "$UNINSTALL" = true ]; then
|
if [ ${UNINSTALL} = true ]; then
|
||||||
echo "Removing desktop shortcut and menu item for Arduino IDE..."
|
printf "Removing desktop shortcut and menu item for Arduino IDE..."
|
||||||
xdg_uninstall_f
|
xdg_uninstall_f
|
||||||
simple_uninstall_f
|
simple_uninstall_f
|
||||||
else
|
else
|
||||||
echo "Adding desktop shortcut, menu item and file associations for Arduino IDE..."
|
printf "Adding desktop shortcut, menu item and file associations for Arduino IDE..."
|
||||||
xdg_uninstall_f
|
xdg_uninstall_f
|
||||||
simple_uninstall_f
|
simple_uninstall_f
|
||||||
xdg_install_f
|
xdg_install_f
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "$UNINSTALL" = true ]; then
|
if [ ${UNINSTALL} = true ]; then
|
||||||
echo "Removing desktop shortcut and menu item for Arduino IDE..."
|
printf "Removing desktop shortcut and menu item for Arduino IDE..."
|
||||||
simple_uninstall_f
|
simple_uninstall_f
|
||||||
else
|
else
|
||||||
echo "Adding desktop shortcut and menu item for Arduino IDE..."
|
printf "Adding desktop shortcut and menu item for Arduino IDE..."
|
||||||
simple_uninstall_f
|
simple_uninstall_f
|
||||||
simple_install_f
|
simple_install_f
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
updatedbs_f
|
updatedbs_f
|
||||||
echo "...done!"
|
printf " done!\n"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user