source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/install.sh @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

  • Property svn:executable set to *
File size: 9.5 KB
Line 
1#!/bin/sh
2
3# This script adds a menu item, icons and mime type for Arduino for the current
4# user. If possible, it will use the xdg-utils - or fall back to just creating
5# and copying a desktop file to the user's dir.
6# If called with the "-u" option, it will undo the changes.
7
8# Resource name to use (including vendor prefix)
9RESOURCE_NAME=cc.arduino.arduinoide
10
11# Get absolute path from which this script file was executed
12# (Could be changed to "pwd -P" to resolve symlinks to their target)
13SCRIPT_PATH=$( cd $(dirname $0) ; pwd )
14cd "${SCRIPT_PATH}"
15
16# Default mode is to install.
17UNINSTALL=false
18
19# If possible, get location of the desktop folder. Default to ~/Desktop
20XDG_DESKTOP_DIR="${HOME}/Desktop"
21if [ -f "${XDG_CONFIG_HOME:-${HOME}/.config}/user-dirs.dirs" ]; then
22  . "${XDG_CONFIG_HOME:-${HOME}/.config}/user-dirs.dirs"
23fi
24
25# Install using xdg-utils
26xdg_install_f() {
27
28  # Create a temp dir accessible by all users
29  TMP_DIR=`mktemp --directory`
30
31  # Create *.desktop file using the existing template file
32  sed -e "s,<BINARY_LOCATION>,${SCRIPT_PATH}/arduino,g" \
33      -e "s,<ICON_NAME>,${RESOURCE_NAME},g" "${SCRIPT_PATH}/lib/desktop.template" > "${TMP_DIR}/${RESOURCE_NAME}.desktop"
34
35  # Install the icon files using name and resolutions
36  xdg-icon-resource install --context apps --size 16 "${SCRIPT_PATH}/lib/icons/16x16/apps/arduino.png" $RESOURCE_NAME
37  xdg-icon-resource install --context apps --size 24 "${SCRIPT_PATH}/lib/icons/24x24/apps/arduino.png" $RESOURCE_NAME
38  xdg-icon-resource install --context apps --size 32 "${SCRIPT_PATH}/lib/icons/32x32/apps/arduino.png" $RESOURCE_NAME
39  xdg-icon-resource install --context apps --size 48 "${SCRIPT_PATH}/lib/icons/48x48/apps/arduino.png" $RESOURCE_NAME
40  xdg-icon-resource install --context apps --size 64 "${SCRIPT_PATH}/lib/icons/64x64/apps/arduino.png" $RESOURCE_NAME
41  xdg-icon-resource install --context apps --size 72 "${SCRIPT_PATH}/lib/icons/72x72/apps/arduino.png" $RESOURCE_NAME
42  xdg-icon-resource install --context apps --size 96 "${SCRIPT_PATH}/lib/icons/96x96/apps/arduino.png" $RESOURCE_NAME
43  xdg-icon-resource install --context apps --size 128 "${SCRIPT_PATH}/lib/icons/128x128/apps/arduino.png" $RESOURCE_NAME
44  xdg-icon-resource install --context apps --size 256 "${SCRIPT_PATH}/lib/icons/256x256/apps/arduino.png" $RESOURCE_NAME
45
46  # Install the created *.desktop file
47  xdg-desktop-menu install "${TMP_DIR}/${RESOURCE_NAME}.desktop"
48
49  # Create icon on the desktop
50  xdg-desktop-icon install "${TMP_DIR}/${RESOURCE_NAME}.desktop"
51
52  # Install Arduino mime type
53  xdg-mime install "${SCRIPT_PATH}/lib/${RESOURCE_NAME}.xml"
54
55  # Install icons for mime type
56  xdg-icon-resource install --context mimetypes --size 16 "${SCRIPT_PATH}/lib/icons/16x16/apps/arduino.png" text-x-arduino
57  xdg-icon-resource install --context mimetypes --size 24 "${SCRIPT_PATH}/lib/icons/24x24/apps/arduino.png" text-x-arduino
58  xdg-icon-resource install --context mimetypes --size 32 "${SCRIPT_PATH}/lib/icons/32x32/apps/arduino.png" text-x-arduino
59  xdg-icon-resource install --context mimetypes --size 48 "${SCRIPT_PATH}/lib/icons/48x48/apps/arduino.png" text-x-arduino
60  xdg-icon-resource install --context mimetypes --size 64 "${SCRIPT_PATH}/lib/icons/64x64/apps/arduino.png" text-x-arduino
61  xdg-icon-resource install --context mimetypes --size 72 "${SCRIPT_PATH}/lib/icons/72x72/apps/arduino.png" text-x-arduino
62  xdg-icon-resource install --context mimetypes --size 96 "${SCRIPT_PATH}/lib/icons/96x96/apps/arduino.png" text-x-arduino
63  xdg-icon-resource install --context mimetypes --size 128 "${SCRIPT_PATH}/lib/icons/128x128/apps/arduino.png" text-x-arduino
64  xdg-icon-resource install --context mimetypes --size 256 "${SCRIPT_PATH}/lib/icons/256x256/apps/arduino.png" text-x-arduino
65
66  # Make Arduino IDE the default application for *.ino
67  xdg-mime default ${RESOURCE_NAME}.desktop text/x-arduino
68
69  # Clean up
70  rm "${TMP_DIR}/${RESOURCE_NAME}.desktop"
71  rmdir "$TMP_DIR"
72
73}
74
75# Install by simply copying desktop file (fallback)
76simple_install_f() {
77
78  # Create a temp dir accessible by all users
79  TMP_DIR=`mktemp --directory`
80
81  # Create *.desktop file using the existing template file
82  sed -e "s,<BINARY_LOCATION>,${SCRIPT_PATH}/arduino,g" \
83      -e "s,<ICON_NAME>,${SCRIPT_PATH}/lib/arduino.png,g" "${SCRIPT_PATH}/lib/desktop.template" > "${TMP_DIR}/${RESOURCE_NAME}.desktop"
84
85  mkdir -p "${HOME}/.local/share/applications"
86  cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" "${HOME}/.local/share/applications/"
87
88  mkdir -p "${HOME}/.local/share/metainfo"
89  cp "${SCRIPT_PATH}/lib/appdata.xml" "${HOME}/.local/share/metainfo/${RESOURCE_NAME}.appdata.xml"
90
91  # Copy desktop icon if desktop dir exists (was found)
92  if [ -d "${XDG_DESKTOP_DIR}" ]; then
93   cp "${TMP_DIR}/${RESOURCE_NAME}.desktop" "${XDG_DESKTOP_DIR}/"
94   # Altering file permissions to avoid "Untrusted Application Launcher" error on Ubuntu
95   chmod u+x "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop"
96  fi
97
98  # Clean up temp dir
99  rm "${TMP_DIR}/${RESOURCE_NAME}.desktop"
100  rmdir "${TMP_DIR}"
101
102}
103
104# Uninstall using xdg-utils
105xdg_uninstall_f() {
106
107  # Remove *.desktop file
108  xdg-desktop-menu uninstall ${RESOURCE_NAME}.desktop
109
110  # Remove icon from desktop
111  xdg-desktop-icon uninstall ${RESOURCE_NAME}.desktop
112
113  # Remove icons
114  xdg-icon-resource uninstall --size 16 ${RESOURCE_NAME}
115  xdg-icon-resource uninstall --size 24 ${RESOURCE_NAME}
116  xdg-icon-resource uninstall --size 32 ${RESOURCE_NAME}
117  xdg-icon-resource uninstall --size 48 ${RESOURCE_NAME}
118  xdg-icon-resource uninstall --size 64 ${RESOURCE_NAME}
119  xdg-icon-resource uninstall --size 72 ${RESOURCE_NAME}
120  xdg-icon-resource uninstall --size 96 ${RESOURCE_NAME}
121  xdg-icon-resource uninstall --size 128 ${RESOURCE_NAME}
122  xdg-icon-resource uninstall --size 256 ${RESOURCE_NAME}
123
124  # Remove MIME type icons
125  xdg-icon-resource uninstall --size 16  text-x-arduino
126  xdg-icon-resource uninstall --size 24  text-x-arduino
127  xdg-icon-resource uninstall --size 32  text-x-arduino
128  xdg-icon-resource uninstall --size 48  text-x-arduino
129  xdg-icon-resource uninstall --size 64  text-x-arduino
130  xdg-icon-resource uninstall --size 72  text-x-arduino
131  xdg-icon-resource uninstall --size 96  text-x-arduino
132  xdg-icon-resource uninstall --size 128  text-x-arduino
133  xdg-icon-resource uninstall --size 256  text-x-arduino
134
135  # Remove Arduino MIME type
136  xdg-mime uninstall "${SCRIPT_PATH}/lib/${RESOURCE_NAME}.xml"
137
138}
139
140# Uninstall by simply removing desktop files (fallback), incl. old one
141simple_uninstall_f() {
142
143  # delete legacy cruft .desktop file
144  if [ -f "${HOME}/.local/share/applications/arduino.desktop" ]; then
145    rm "${HOME}/.local/share/applications/arduino.desktop"
146  fi
147
148  # delete another legacy .desktop file
149  if [ -f "${HOME}/.local/share/applications/arduino-arduinoide.desktop" ]; then
150    rm "${HOME}/.local/share/applications/arduino-arduinoide.desktop"
151  fi
152
153  if [ -f "${HOME}/.local/share/applications/${RESOURCE_NAME}.desktop" ]; then
154    rm "${HOME}/.local/share/applications/${RESOURCE_NAME}.desktop"
155  fi
156
157  if [ -f "${HOME}/.local/share/metainfo/${RESOURCE_NAME}.appdata.xml" ]; then
158    rm "${HOME}/.local/share/metainfo/${RESOURCE_NAME}.appdata.xml"
159  fi
160
161  if [ -f "${XDG_DESKTOP_DIR}/arduino.desktop" ]; then
162    rm "${XDG_DESKTOP_DIR}/arduino.desktop"
163  fi
164
165  if [ -f "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop" ]; then
166    rm "${XDG_DESKTOP_DIR}/${RESOURCE_NAME}.desktop"
167  fi
168
169}
170
171# Update desktop file and mime databases (if possible)
172updatedbs_f() {
173
174  if [ -d "${HOME}/.local/share/applications" ]; then
175    if command -v update-desktop-database > /dev/null; then
176      update-desktop-database "${HOME}/.local/share/applications"
177    fi
178  fi
179
180  if [ -d "${HOME}/.local/share/mime" ]; then
181    if command -v update-mime-database > /dev/null; then
182      update-mime-database "${HOME}/.local/share/mime"
183    fi
184  fi
185
186}
187
188# Check availability of xdg-utils
189xdg_exists_f() {
190
191  if ! command -v xdg-icon-resource > /dev/null; then return 1; fi
192  if ! command -v xdg-desktop-menu > /dev/null; then return 1; fi
193  if ! command -v xdg-desktop-icon > /dev/null; then return 1; fi
194  if ! command -v xdg-mime > /dev/null; then return 1; fi
195  return 0
196
197}
198
199# Shows a description of the available options
200display_help_f() {
201  printf "\nThis script will add a Arduino IDE desktop shortcut, menu item,\n"
202  printf "icons and file associations for the current user.\n"
203  if ! xdg_exists_f; then
204    printf "\nxdg-utils are recommended to be installed, so this script can use them.\n"
205  fi
206  printf "\nOptional arguments are:\n\n"
207  printf "\t-u, --uninstall\t\tRemoves shortcut, menu item and icons.\n\n"
208  printf "\t-h, --help\t\tShows this help again.\n\n"
209}
210
211# Check for provided arguments
212while [ $# -gt 0 ] ; do
213  ARG="${1}"
214  case $ARG in
215      -u|--uninstall)
216        UNINSTALL=true
217        shift
218      ;;
219      -h|--help)
220        display_help_f
221        exit 0
222      ;;
223      *)
224        printf "\nInvalid option -- '${ARG}'\n"
225        display_help_f
226        exit 1
227      ;;
228  esac
229done
230
231# If possible, use xdg-utils, if not, use a more basic approach
232if xdg_exists_f; then
233  if [ ${UNINSTALL} = true ]; then
234    printf "Removing desktop shortcut and menu item for Arduino IDE..."
235    xdg_uninstall_f
236    simple_uninstall_f
237  else
238    printf "Adding desktop shortcut, menu item and file associations for Arduino IDE..."
239    xdg_uninstall_f
240    simple_uninstall_f
241    xdg_install_f
242  fi
243else
244  if [ ${UNINSTALL} = true ]; then
245    printf "Removing desktop shortcut and menu item for Arduino IDE..."
246    simple_uninstall_f
247  else
248    printf "Adding desktop shortcut and menu item for Arduino IDE..."
249    simple_uninstall_f
250    simple_install_f
251  fi
252fi
253updatedbs_f
254printf " done!\n"
255
256exit 0
Note: See TracBrowser for help on using the repository browser.