Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / tools / register_local_nm_hosts.sh
blobaba87ef04b9578b62050e4960c896b7ae4647774
1 #!/bin/sh
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 # Script that can be used to register native messaging hosts in the output
7 # directory.
9 set -e
11 SRC_DIR="$(readlink -f "$(dirname "$0")/../..")"
12 ME2ME_HOST_NAME="com.google.chrome.remote_desktop"
13 IT2ME_HOST_NAME="com.google.chrome.remote_assistance"
15 install_manifest() {
16 local manifest_template="$1"
17 local host_path="$2"
18 local host_path_var_name="$3"
19 local target_dir="$4"
21 local template_name="$(basename ${manifest_template})"
22 local manifest_name="${template_name%.*}"
23 local target_manifest="${target_dir}/${manifest_name}"
25 echo Registering ${host_path} in ${target_manifest}
26 mkdir -p "${target_dir}"
27 sed -e "s#{{ ${host_path_var_name} }}#${host_path}#g" \
28 < "$manifest_template" > "$target_manifest"
31 register_hosts() {
32 local build_dir="$1"
33 local chrome_data_dir="$2"
35 install_manifest \
36 "${SRC_DIR}/remoting/host/setup/${ME2ME_HOST_NAME}.json.jinja2" \
37 "${build_dir}/native_messaging_host" \
38 ME2ME_HOST_PATH "${chrome_data_dir}"
40 install_manifest \
41 "${SRC_DIR}/remoting/host/it2me/${IT2ME_HOST_NAME}.json.jinja2" \
42 "${build_dir}/remote_assistance_host" \
43 IT2ME_HOST_PATH "${chrome_data_dir}"
46 register_hosts_for_all_channels() {
47 local build_dir="$1"
49 if [ -n "$CHROME_USER_DATA_DIR" ]; then
50 register_hosts "${build_dir}" \
51 "${CHROME_USER_DATA_DIR}/NativeMessagingHosts"
52 elif [ $(uname -s) == "Darwin" ]; then
53 register_hosts "${build_dir}" \
54 "${HOME}/Library/Application Support/Google/Chrome/NativeMessagingHosts"
55 register_hosts "${build_dir}" \
56 "${HOME}/Library/Application Support/Chromium/NativeMessagingHosts"
57 else
58 register_hosts "${build_dir}" \
59 "${HOME}/.config/google-chrome/NativeMessagingHosts"
60 register_hosts "${build_dir}" \
61 "${HOME}/.config/google-chrome-beta/NativeMessagingHosts"
62 register_hosts "${build_dir}" \
63 "${HOME}/.config/google-chrome-unstable/NativeMessagingHosts"
64 register_hosts "${build_dir}" \
65 "${HOME}/.config/chromium/NativeMessagingHosts"
69 unregister_hosts() {
70 local chrome_data_dir="$1"
72 rm -f "${chrome_data_dir}/${ME2ME_HOST_NAME}.json"
73 rm -f "${chrome_data_dir}/${IT2ME_HOST_NAME}.json"
76 unregister_hosts_for_all_channels() {
77 if [ -n "$CHROME_USER_DATA_DIR" ]; then
78 unregister_hosts \
79 "${CHROME_USER_DATA_DIR}/NativeMessagingHosts"
80 elif [ $(uname -s) == "Darwin" ]; then
81 unregister_hosts \
82 "${HOME}/Library/Application Support/Google/Chrome/NativeMessagingHosts"
83 unregister_hosts \
84 "${HOME}/Library/Application Support/Chromium/NativeMessagingHosts"
85 else
86 unregister_hosts "${HOME}/.config/google-chrome/NativeMessagingHosts"
87 unregister_hosts "${HOME}/.config/google-chrome-beta/NativeMessagingHosts"
88 unregister_hosts \
89 "${HOME}/.config/google-chrome-unstable/NativeMessagingHosts"
90 unregister_hosts "${HOME}/.config/chromium/NativeMessagingHosts"
94 print_usage() {
95 echo "Usage: $0 [-r|-u]" >&2
96 echo " -r Register Release build instead of Debug" >&2
97 echo " -u Unregister" >&2
100 build_dir="Debug"
102 if [[ $# -gt 1 ]]; then
103 print_usage
104 elif [[ $# -eq 1 ]]; then
105 case "$1" in
106 "-r")
107 build_dir="Release"
109 "-u")
110 unregister_hosts_for_all_channels
111 exit 0
114 print_usage
115 exit 1
117 esac
120 register_hosts_for_all_channels "${SRC_DIR}/out/${build_dir}"