|
9 | 9 | RESOURCE_NAME=arduino-arduinoide
|
10 | 10 |
|
11 | 11 | # Get absolute path from which this script file was executed
|
12 |
| -# Use "pwd -P" to resolve symlinks to their target |
| 12 | +# (Could be changed to "pwd -P" to resolve symlinks to their target) |
13 | 13 | SCRIPT_PATH=$( cd $(dirname $0) ; pwd )
|
14 | 14 | cd "$SCRIPT_PATH"
|
15 | 15 |
|
| 16 | +# Default mode is to install. |
| 17 | +UNINSTALL=false |
| 18 | + |
16 | 19 | # Install using xdg-utils
|
17 | 20 | xdg_install_f() {
|
18 | 21 |
|
@@ -172,24 +175,63 @@ xdg_exists_f() {
|
172 | 175 |
|
173 | 176 | }
|
174 | 177 |
|
| 178 | +# Shows a description of the available options |
| 179 | +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." |
| 183 | + if ! xdg_exists_f; then |
| 184 | + echo "\n" |
| 185 | + echo "xdg-utils are recommended to be installed, so this script can use them." |
| 186 | + 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" |
| 194 | +} |
| 195 | + |
| 196 | +# Check for provided arguments |
| 197 | +while [ $# -gt 0 ] ; do |
| 198 | + ARG="$1" |
| 199 | + case $ARG in |
| 200 | + -u|--uninstall) |
| 201 | + UNINSTALL=true |
| 202 | + shift |
| 203 | + ;; |
| 204 | + -h|--help) |
| 205 | + display_help_f |
| 206 | + exit 0 |
| 207 | + ;; |
| 208 | + *) |
| 209 | + echo "\n" |
| 210 | + echo "Invalid option -- '$ARG'" |
| 211 | + display_help_f |
| 212 | + exit 1 |
| 213 | + ;; |
| 214 | + esac |
| 215 | +done |
| 216 | + |
175 | 217 | # If possible, use xdg-utils, if not, use a more basic approach
|
176 | 218 | if xdg_exists_f; then
|
177 |
| - if [ "$1" = "-u" ]; then |
178 |
| - echo "Removing menu item, icons and file association for Arduino IDE..." |
| 219 | + if [ "$UNINSTALL" = true ]; then |
| 220 | + echo "Removing desktop shortcut and menu item for Arduino IDE..." |
179 | 221 | xdg_uninstall_f
|
180 | 222 | simple_uninstall_f
|
181 | 223 | else
|
182 |
| - echo "Adding menu item, icons and file association for Arduino IDE..." |
| 224 | + echo "Adding desktop shortcut, menu item and file associations for Arduino IDE..." |
183 | 225 | xdg_uninstall_f
|
184 | 226 | simple_uninstall_f
|
185 | 227 | xdg_install_f
|
186 | 228 | fi
|
187 | 229 | else
|
188 |
| - if [ "$1" = "-u" ]; then |
189 |
| - echo "Removing menu item for Arduino IDE..." |
| 230 | + if [ "$UNINSTALL" = true ]; then |
| 231 | + echo "Removing desktop shortcut and menu item for Arduino IDE..." |
190 | 232 | simple_uninstall_f
|
191 | 233 | else
|
192 |
| - echo "Adding menu item for Arduino IDE..." |
| 234 | + echo "Adding desktop shortcut and menu item for Arduino IDE..." |
193 | 235 | simple_uninstall_f
|
194 | 236 | simple_install_f
|
195 | 237 | fi
|
|
0 commit comments