summarylogtreecommitdiffstats
path: root/sidekick-browser-stable-bin.install
blob: 08d84703197bb5e827fc0766df66b63f2565bbbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
	#
	# Copyright (c) 2009 The Chromium Authors. All rights reserved.
	# Use of this source code is governed by a BSD-style license that can be
	# found in the LICENSE file.

post_install() {
	gtk-update-icon-cache -q -t -f usr/share/icons/hicolor

	# Add icons to the system icons
	XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null || true`"
	if [ ! -x "$XDG_ICON_RESOURCE" ]; then
	  echo "Error: Could not find xdg-icon-resource" >&2
	  exit 1
	fi
	for icon in product_logo_24.png product_logo_256.png product_logo_48.png product_logo_64.png product_logo_16.png product_logo_32.png product_logo_128.png ; do
	  size="$(echo ${icon} | sed 's/[^0-9]//g')"
	  "$XDG_ICON_RESOURCE" install --size "${size}" "/opt/meetsidekick.com/sidekick/${icon}" \
	    "sidekick-browser"
	done

	UPDATE_MENUS="`which update-mime-database usr/share/mime &> /dev/null 2> /dev/null || true`"
	if [ -x "$UPDATE_MENUS" ]; then
	  update-mime-database usr/share/mime &> /dev/null
	fi

	# Update cache of .desktop file MIME types. Non-fatal since it's just a cache.
	update-desktop-database > /dev/null 2>&1 || true

	# Updates defaults.list file if present.
	update_defaults_list() {
	  # $1: name of the .desktop file

	  local DEFAULTS_FILE="/usr/share/applications/defaults.list"

	  if [ ! -f "${DEFAULTS_FILE}" ]; then
	    return
	  fi

	  # Split key-value pair out of MimeType= line from the .desktop file,
	  # then split semicolon-separated list of mime types (they should not contain
	  # spaces).
	  mime_types="$(grep MimeType= /usr/share/applications/${1} |
	                cut -d '=' -f 2- |
	                tr ';' ' ')"
	  for mime_type in ${mime_types}; do
	    if egrep -q "^${mime_type}=" "${DEFAULTS_FILE}"; then
	      if ! egrep -q "^${mime_type}=.*${1}" "${DEFAULTS_FILE}"; then
	        default_apps="$(grep ${mime_type}= "${DEFAULTS_FILE}" |
	                        cut -d '=' -f 2-)"
	        egrep -v "^${mime_type}=" "${DEFAULTS_FILE}" > "${DEFAULTS_FILE}.new"
	        echo "${mime_type}=${default_apps};${1}" >> "${DEFAULTS_FILE}.new"
	        mv "${DEFAULTS_FILE}.new" "${DEFAULTS_FILE}"
	      fi
	    else
	      # If there's no mention of the mime type in the file, add it.
	      echo "${mime_type}=${1};" >> "${DEFAULTS_FILE}"
	    fi
	  done
	}

	update_defaults_list "sidekick-browser.desktop"

	# This function uses sed to insert the contents of one file into another file,
	# after the first line matching a given regular expression. If there is no
	# matching line, then the file is unchanged.
	insert_after_first_match() {
	  # $1: file to update
	  # $2: regular expression
	  # $3: file to insert
	  sed -i -e "1,/$2/ {
	    /$2/ r $3
	    }" "$1"
	}

	# If /usr/share/gnome-control-center/default-apps/gnome-default-applications.xml
	# exists, it may need to be updated to add ourselves to the default applications
	# list. If we find the file and it does not seem to contain our patch already
	# (the patch is safe to leave even after uninstall), update it.
	GNOME_DFL_APPS=/usr/share/gnome-control-center/default-apps/gnome-default-applications.xml
	if [ -f "$GNOME_DFL_APPS" ]; then
	# Conditionally insert the contents of the file "default-app-block" after the
	# first "<web-browsers>" line we find in gnome-default-applications.xml
	  fgrep -q "Sidekick Web Browser" "$GNOME_DFL_APPS" || insert_after_first_match \
	    "$GNOME_DFL_APPS" \
	    "^[ 	]*<web-browsers>[ 	]*$" \
	    "/opt/meetsidekick.com/sidekick/default-app-block"
	fi

	# System-wide package configuration.
	DEFAULTS_FILE="/etc/default/sidekick-browser"

	get_lib_dir() {
	  if [ "$DEFAULT_ARCH" = "i386" ]; then
	    LIBDIR=lib/i386-linux-gnu
	  elif [ "$DEFAULT_ARCH" = "amd64" ]; then
	    LIBDIR=lib/x86_64-linux-gnu
	  elif [ "$DEFAULT_ARCH" = "armhf" ]; then
	    LIBDIR=lib/arm-linux-gnueabihf
	  elif [ "$DEFAULT_ARCH" = "arm64" ]; then
	    LIBDIR=lib/aarch64-linux-gnu
	  elif [ "$DEFAULT_ARCH" = "mipsel" ]; then
	    LIBDIR=lib/mipsel-linux-gnu
	  elif [ "$DEFAULT_ARCH" = "mips64el" ]; then
	    LIBDIR=lib/mips64el-linux-gnuabi64
	  else
	    echo Unknown CPU Architecture: "$DEFAULT_ARCH"
	    exit 1
	  fi
	}

	NSS_FILES="libnspr4.so libplds4.so libplc4.so libssl3.so \
	    libnss3.so libsmime3.so libnssutil3.so"

	add_nss_symlinks() {
	  get_lib_dir
	  for f in $NSS_FILES
	  do
	    target=$(echo $f | sed 's/\.[01]d$//')
	    if [ -f "/$LIBDIR/$target" ]; then
	      ln -snf "/$LIBDIR/$target" "/opt/meetsidekick.com/sidekick/$f"
	    elif [ -f "/usr/$LIBDIR/$target" ]; then
	      ln -snf "/usr/$LIBDIR/$target" "/opt/meetsidekick.com/sidekick/$f"
	    else
	      echo $f not found in "/$LIBDIR/$target" or "/usr/$LIBDIR/$target".
	      exit 1
	    fi
	  done
	}

	remove_nss_symlinks() {
	  for f in $NSS_FILES
	  do
	    rm -rf "/opt/meetsidekick.com/sidekick/$f"
	  done
	}

	remove_udev_symlinks() {
	  rm -rf "/opt/meetsidekick.com/sidekick/libudev.so.0"
	}
	remove_udev_symlinks
	update-desktop-database -q
}

post_upgrade() {
	post_install
}

pre_remove() {
	# Remove icons from the system icons
	XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null || true`"
	if [ ! -x "$XDG_ICON_RESOURCE" ]; then
	  echo "Error: Could not find xdg-icon-resource" >&2
	  exit 1
	fi
	for icon in product_logo_24.png product_logo_256.png product_logo_48.png product_logo_64.png product_logo_16.png product_logo_32.png product_logo_128.png ; do
	  size="$(echo ${icon} | sed 's/[^0-9]//g')"
	  "$XDG_ICON_RESOURCE" uninstall --size "${size}" "sidekick-browser"
	done

	UPDATE_MENUS="`which update-mime-database usr/share/mime &> /dev/null 2> /dev/null || true`"
	if [ -x "$UPDATE_MENUS" ]; then
	  update-mime-database usr/share/mime &> /dev/null
	fi

	# Update cache of .desktop file MIME types. Non-fatal since it's just a cache.
	update-desktop-database > /dev/null 2>&1 || true

	# Remove from the alternatives system

}

post_remove() {
	gtk-update-icon-cache -q -t -f usr/share/icons/hicolor

	# System-wide package configuration.
	DEFAULTS_FILE="/etc/default/sidekick-browser"

	update-desktop-database -q
}