@@ -11,11 +11,17 @@ RESOURCE_NAME=arduino-arduinoide
11
11
# Get absolute path from which this script file was executed
12
12
# (Could be changed to "pwd -P" to resolve symlinks to their target)
13
13
SCRIPT_PATH=$( cd $( dirname $0 ) ; pwd )
14
- cd " $SCRIPT_PATH "
14
+ cd " ${ SCRIPT_PATH} "
15
15
16
16
# Default mode is to install.
17
17
UNINSTALL=false
18
18
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
+
19
25
# Install using xdg-utils
20
26
xdg_install_f () {
21
27
@@ -76,17 +82,19 @@ simple_install_f() {
76
82
sed -e " s,<BINARY_LOCATION>,${SCRIPT_PATH} /arduino,g" \
77
83
-e " s,<ICON_NAME>,${SCRIPT_PATH} /lib/arduino.png,g" " ${SCRIPT_PATH} /lib/desktop.template" > " ${TMP_DIR} /${RESOURCE_NAME} .desktop"
78
84
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/"
81
87
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"
85
93
fi
86
94
87
- # Clean up
95
+ # Clean up temp dir
88
96
rm " ${TMP_DIR} /${RESOURCE_NAME} .desktop"
89
- rmdir " $TMP_DIR "
97
+ rmdir " ${ TMP_DIR} "
90
98
91
99
}
92
100
@@ -100,15 +108,15 @@ xdg_uninstall_f() {
100
108
xdg-desktop-icon uninstall ${RESOURCE_NAME} .desktop
101
109
102
110
# 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}
112
120
113
121
# Remove MIME type icons
114
122
xdg-icon-resource uninstall --size 16 text-x-arduino
@@ -129,36 +137,36 @@ xdg_uninstall_f() {
129
137
# Uninstall by simply removing desktop files (fallback), incl. old one
130
138
simple_uninstall_f () {
131
139
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"
134
142
fi
135
143
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"
138
146
fi
139
147
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"
142
150
fi
143
151
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"
146
154
fi
147
155
148
156
}
149
157
150
158
# Update desktop file and mime databases (if possible)
151
159
updatedbs_f () {
152
160
153
- if [ -d ~ /.local/share/applications ]; then
161
+ if [ -d " ${HOME} /.local/share/applications" ]; then
154
162
if command -v update-desktop-database > /dev/null; then
155
- update-desktop-database ~ /.local/share/applications
163
+ update-desktop-database " ${HOME} /.local/share/applications"
156
164
fi
157
165
fi
158
166
159
- if [ -d ~ /.local/share/mime ]; then
167
+ if [ -d " ${HOME} /.local/share/mime" ]; then
160
168
if command -v update-mime-database > /dev/null; then
161
- update-mime-database ~ /.local/share/mime
169
+ update-mime-database " ${HOME} /.local/share/mime"
162
170
fi
163
171
fi
164
172
@@ -177,25 +185,19 @@ xdg_exists_f() {
177
185
178
186
# Shows a description of the available options
179
187
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"
183
190
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"
186
192
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"
194
196
}
195
197
196
198
# Check for provided arguments
197
199
while [ $# -gt 0 ] ; do
198
- ARG=" $1 "
200
+ ARG=" ${1} "
199
201
case $ARG in
200
202
-u|--uninstall)
201
203
UNINSTALL=true
@@ -206,8 +208,7 @@ while [ $# -gt 0 ] ; do
206
208
exit 0
207
209
;;
208
210
* )
209
- echo " \n"
210
- echo " Invalid option -- '$ARG '"
211
+ printf " \nInvalid option -- '${ARG} '\n"
211
212
display_help_f
212
213
exit 1
213
214
;;
@@ -216,27 +217,27 @@ done
216
217
217
218
# If possible, use xdg-utils, if not, use a more basic approach
218
219
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..."
221
222
xdg_uninstall_f
222
223
simple_uninstall_f
223
224
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..."
225
226
xdg_uninstall_f
226
227
simple_uninstall_f
227
228
xdg_install_f
228
229
fi
229
230
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..."
232
233
simple_uninstall_f
233
234
else
234
- echo " Adding desktop shortcut and menu item for Arduino IDE..."
235
+ printf " Adding desktop shortcut and menu item for Arduino IDE..."
235
236
simple_uninstall_f
236
237
simple_install_f
237
238
fi
238
239
fi
239
240
updatedbs_f
240
- echo " ... done!"
241
+ printf " done!\n "
241
242
242
243
exit 0
0 commit comments