3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # Version = @@VERSION@@
9 HELPERTOOLS
=/Library
/PrivilegedHelperTools
10 SERVICE_NAME
=org.chromium.chromoting
11 CONFIG_FILE
="$HELPERTOOLS/$SERVICE_NAME.json"
12 SCRIPT_FILE
="$HELPERTOOLS/$SERVICE_NAME.me2me.sh"
13 USERS_TMP_FILE
="$SCRIPT_FILE.users"
14 PLIST
=/Library
/LaunchAgents
/org.chromium.chromoting.plist
15 ENABLED_FILE
="$HELPERTOOLS/$SERVICE_NAME.me2me_enabled"
16 ENABLED_FILE_BACKUP
="$ENABLED_FILE.backup"
18 # In case of errors, log the fact, but continue to unload launchd jobs as much
19 # as possible. When finished, this preflight script should exit successfully in
20 # case this is a Keystone-triggered update which must be allowed to proceed.
22 logger An error occurred during Chrome Remote Desktop setup.
25 function find_users_with_active_hosts
{
26 ps
-eo uid
,command |
awk -v script="$SCRIPT_FILE" '
27 $2 == "/bin/sh" && $3 == script && $4 == "--run-from-launchd" {
32 function find_login_window_for_user
{
33 # This function mimics the behaviour of pgrep, which may not be installed
36 ps
-ec -u "$user" -o comm,pid |
awk '$1 == "loginwindow" { print $2; exit }'
41 logger Running Chrome Remote Desktop preflight
script @@VERSION@@
43 # If there is an _enabled file, rename it while upgrading.
44 if [[ -f "$ENABLED_FILE" ]]; then
45 mv "$ENABLED_FILE" "$ENABLED_FILE_BACKUP"
48 # Stop and unload the service for each user currently running the service, and
49 # record the user IDs so the service can be restarted for the same users in the
51 rm -f "$USERS_TMP_FILE"
53 for uid
in $
(find_users_with_active_hosts
); do
54 if [[ -n "$uid" ]]; then
55 echo "$uid" >> "$USERS_TMP_FILE"
56 if [[ "$uid" = "0" ]]; then
61 pid
="$(find_login_window_for_user "$uid")"
62 if [[ -n "$pid" ]]; then
63 launchctl bsexec
"$pid" sudo
-u "#$uid" launchctl stop
"$SERVICE_NAME"
64 launchctl bsexec
"$pid" sudo
-u "#$uid" launchctl unload
-w -S \