Skip to content

Commit 7d4787b

Browse files
fiechrFederico Fissore
authored and
Federico Fissore
committed
Updated Linux install script to be flexible about different desktop folder locations.
1 parent 22496e1 commit 7d4787b

File tree

1 file changed

+52
-51
lines changed

1 file changed

+52
-51
lines changed

build/linux/dist/install.sh

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ RESOURCE_NAME=arduino-arduinoide
1111
# Get absolute path from which this script file was executed
1212
# (Could be changed to "pwd -P" to resolve symlinks to their target)
1313
SCRIPT_PATH=$( cd $(dirname $0) ; pwd )
14-
cd "$SCRIPT_PATH"
14+
cd "${SCRIPT_PATH}"
1515

1616
# Default mode is to install.
1717
UNINSTALL=false
1818

19+
# If possible, get location of the desktop folder. Default to ~/Desktop
20+
XDG_DESKTOP_DIR="${HOME}/Desktop"
21+
if [ -f "${XDG_CONFIG_HOME:-${HOME}/.config}/user-dirs.dirs" ]; then
22+
. "${XDG_CONFIG_HOME:-${HOME}/.config}/user-dirs.dirs"
23+
fi
24+
1925
# Install using xdg-utils
2026
xdg_install_f() {
2127

@@ -76,17 +82,19 @@ simple_install_f() {
7682
sed -e "s,<BINARY_LOCATION>,${SCRIPT_PATH}/arduino,g" \
7783
-e "s,<ICON_NAME>,${SCRIPT_PATH}/lib/arduino.png,g" "${SCRIPT_PATH}/lib/desktop.template" > "${TMP_DIR}/${RESOURCE_NAME}.desktop"
7884

79-
mkdir -p ~/.local/share/applications
80-
cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" ~/.local/share/applications/
85+
mkdir -p "${HOME}/.local/share/applications"
86+
cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" "${HOME}/.local/share/applications/"
8187

82-
# Create desktop icon if dir exists
83-
if [ -d ~/Desktop ]; then
84-
cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" ~/Desktop/
88+
# Copy desktop icon if desktop dir exists (was found)
89+
if [ -d "${XDG_DESKTOP_DIR}" ]; then
90+
cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" "${XDG_DESKTOP_DIR}/"
91+
# Altering file permissions to avoid "Untrusted Application Launcher" error on Ubuntu
92+
chmod u+x "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop"
8593
fi
8694

87-
# Clean up
95+
# Clean up temp dir
8896
rm "${TMP_DIR}/${RESOURCE_NAME}.desktop"
89-
rmdir "$TMP_DIR"
97+
rmdir "${TMP_DIR}"
9098

9199
}
92100

@@ -100,15 +108,15 @@ xdg_uninstall_f() {
100108
xdg-desktop-icon uninstall ${RESOURCE_NAME}.desktop
101109

102110
# Remove icons
103-
xdg-icon-resource uninstall --size 16 $RESOURCE_NAME
104-
xdg-icon-resource uninstall --size 24 $RESOURCE_NAME
105-
xdg-icon-resource uninstall --size 32 $RESOURCE_NAME
106-
xdg-icon-resource uninstall --size 48 $RESOURCE_NAME
107-
xdg-icon-resource uninstall --size 64 $RESOURCE_NAME
108-
xdg-icon-resource uninstall --size 72 $RESOURCE_NAME
109-
xdg-icon-resource uninstall --size 96 $RESOURCE_NAME
110-
xdg-icon-resource uninstall --size 128 $RESOURCE_NAME
111-
xdg-icon-resource uninstall --size 256 $RESOURCE_NAME
111+
xdg-icon-resource uninstall --size 16 ${RESOURCE_NAME}
112+
xdg-icon-resource uninstall --size 24 ${RESOURCE_NAME}
113+
xdg-icon-resource uninstall --size 32 ${RESOURCE_NAME}
114+
xdg-icon-resource uninstall --size 48 ${RESOURCE_NAME}
115+
xdg-icon-resource uninstall --size 64 ${RESOURCE_NAME}
116+
xdg-icon-resource uninstall --size 72 ${RESOURCE_NAME}
117+
xdg-icon-resource uninstall --size 96 ${RESOURCE_NAME}
118+
xdg-icon-resource uninstall --size 128 ${RESOURCE_NAME}
119+
xdg-icon-resource uninstall --size 256 ${RESOURCE_NAME}
112120

113121
# Remove MIME type icons
114122
xdg-icon-resource uninstall --size 16 text-x-arduino
@@ -129,36 +137,36 @@ xdg_uninstall_f() {
129137
# Uninstall by simply removing desktop files (fallback), incl. old one
130138
simple_uninstall_f() {
131139

132-
if [ -f ~/.local/share/applications/arduino.desktop ]; then
133-
rm ~/.local/share/applications/arduino.desktop
140+
if [ -f "${HOME}/.local/share/applications/arduino.desktop" ]; then
141+
rm "${HOME}/.local/share/applications/arduino.desktop"
134142
fi
135143

136-
if [ -f ~/.local/share/applications/${RESOURCE_NAME}.desktop ]; then
137-
rm ~/.local/share/applications/${RESOURCE_NAME}.desktop
144+
if [ -f "${HOME}/.local/share/applications/${RESOURCE_NAME}.desktop" ]; then
145+
rm "${HOME}/.local/share/applications/${RESOURCE_NAME}.desktop"
138146
fi
139147

140-
if [ -f ~/Desktop/arduino.desktop ]; then
141-
rm ~/Desktop/arduino.desktop
148+
if [ -f "${XDG_DESKTOP_DIR}/arduino.desktop" ]; then
149+
rm "${XDG_DESKTOP_DIR}/arduino.desktop"
142150
fi
143151

144-
if [ -f ~/Desktop/${RESOURCE_NAME}.desktop ]; then
145-
rm ~/Desktop/${RESOURCE_NAME}.desktop
152+
if [ -f "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop" ]; then
153+
rm "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop"
146154
fi
147155

148156
}
149157

150158
# Update desktop file and mime databases (if possible)
151159
updatedbs_f() {
152160

153-
if [ -d ~/.local/share/applications ]; then
161+
if [ -d "${HOME}/.local/share/applications" ]; then
154162
if command -v update-desktop-database > /dev/null; then
155-
update-desktop-database ~/.local/share/applications
163+
update-desktop-database "${HOME}/.local/share/applications"
156164
fi
157165
fi
158166

159-
if [ -d ~/.local/share/mime ]; then
167+
if [ -d "${HOME}/.local/share/mime" ]; then
160168
if command -v update-mime-database > /dev/null; then
161-
update-mime-database ~/.local/share/mime
169+
update-mime-database "${HOME}/.local/share/mime"
162170
fi
163171
fi
164172

@@ -177,25 +185,19 @@ xdg_exists_f() {
177185

178186
# Shows a description of the available options
179187
display_help_f() {
180-
echo "\n"
181-
echo "This script will add a Arduino IDE desktop shortcut, menu item,"
182-
echo "icons and file associations for the current user."
188+
printf "\nThis script will add a Arduino IDE desktop shortcut, menu item,\n"
189+
printf "icons and file associations for the current user.\n"
183190
if ! xdg_exists_f; then
184-
echo "\n"
185-
echo "xdg-utils are recommended to be installed, so this script can use them."
191+
printf "\nxdg-utils are recommended to be installed, so this script can use them.\n"
186192
fi
187-
echo "\n"
188-
echo "Optional arguments are:"
189-
echo "\n"
190-
echo "\t-u, --uninstall\t\tRemoves shortcut, menu item and icons."
191-
echo "\n"
192-
echo "\t-h, --help\t\tShows this help again."
193-
echo "\n"
193+
printf "\nOptional arguments are:\n\n"
194+
printf "\t-u, --uninstall\t\tRemoves shortcut, menu item and icons.\n\n"
195+
printf "\t-h, --help\t\tShows this help again.\n\n"
194196
}
195197

196198
# Check for provided arguments
197199
while [ $# -gt 0 ] ; do
198-
ARG="$1"
200+
ARG="${1}"
199201
case $ARG in
200202
-u|--uninstall)
201203
UNINSTALL=true
@@ -206,8 +208,7 @@ while [ $# -gt 0 ] ; do
206208
exit 0
207209
;;
208210
*)
209-
echo "\n"
210-
echo "Invalid option -- '$ARG'"
211+
printf "\nInvalid option -- '${ARG}'\n"
211212
display_help_f
212213
exit 1
213214
;;
@@ -216,27 +217,27 @@ done
216217

217218
# If possible, use xdg-utils, if not, use a more basic approach
218219
if xdg_exists_f; then
219-
if [ "$UNINSTALL" = true ]; then
220-
echo "Removing desktop shortcut and menu item for Arduino IDE..."
220+
if [ ${UNINSTALL} = true ]; then
221+
printf "Removing desktop shortcut and menu item for Arduino IDE..."
221222
xdg_uninstall_f
222223
simple_uninstall_f
223224
else
224-
echo "Adding desktop shortcut, menu item and file associations for Arduino IDE..."
225+
printf "Adding desktop shortcut, menu item and file associations for Arduino IDE..."
225226
xdg_uninstall_f
226227
simple_uninstall_f
227228
xdg_install_f
228229
fi
229230
else
230-
if [ "$UNINSTALL" = true ]; then
231-
echo "Removing desktop shortcut and menu item for Arduino IDE..."
231+
if [ ${UNINSTALL} = true ]; then
232+
printf "Removing desktop shortcut and menu item for Arduino IDE..."
232233
simple_uninstall_f
233234
else
234-
echo "Adding desktop shortcut and menu item for Arduino IDE..."
235+
printf "Adding desktop shortcut and menu item for Arduino IDE..."
235236
simple_uninstall_f
236237
simple_install_f
237238
fi
238239
fi
239240
updatedbs_f
240-
echo "...done!"
241+
printf " done!\n"
241242

242243
exit 0

0 commit comments

Comments
 (0)