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 PAM_CONFIG
=/etc
/pam.d
/chrome-remote-desktop
16 ENABLED_FILE
="$HELPERTOOLS/$SERVICE_NAME.me2me_enabled"
17 ENABLED_FILE_BACKUP
="$ENABLED_FILE.backup"
19 KSADMIN
=/Library
/Google
/GoogleSoftwareUpdate
/GoogleSoftwareUpdate.bundle
/Contents
/MacOS
/ksadmin
20 KSUPDATE
=https
://tools.google.com
/service
/update2
21 KSPID
=com.google.chrome_remote_desktop
22 KSPVERSION
=@@VERSION@@
25 logger An error occurred during Chrome Remote Desktop setup.
29 function find_login_window_for_user
{
30 # This function mimics the behaviour of pgrep, which may not be installed
33 ps
-ec -u "$user" -o comm,pid |
awk '$1 == "loginwindow" { print $2; exit }'
37 trap 'rm -f "$USERS_TMP_FILE"' EXIT
39 logger Running Chrome Remote Desktop postflight
script @@VERSION@@
41 # Register a ticket with Keystone to keep this package up to date.
42 $KSADMIN --register --productid "$KSPID" --version "$KSPVERSION" \
43 --xcpath "$PLIST" --url "$KSUPDATE"
45 # If there is a backup _enabled file, re-enable the service.
46 if [[ -f "$ENABLED_FILE_BACKUP" ]]; then
47 mv "$ENABLED_FILE_BACKUP" "$ENABLED_FILE"
50 # Create the PAM configuration unless it already exists and has been edited.
52 CONTROL_LINE
="# If you edit this file, please delete this line."
53 if [[ -f "$PAM_CONFIG" ]] && ! grep -qF "$CONTROL_LINE" "$PAM_CONFIG"; then
57 if [[ "$update_pam" == "1" ]]; then
58 logger Creating PAM config.
59 cat > "$PAM_CONFIG" <<EOF
60 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
61 # Use of this source code is governed by a BSD-style license that can be
62 # found in the LICENSE file.
64 auth required pam_deny.so
65 account required pam_permit.so
66 password required pam_deny.so
67 session required pam_deny.so
69 # This file is auto-updated by the Chrome Remote Desktop installer.
73 logger PAM config has
local edits. Not updating.
76 # Load the service for each user for whom the service was unloaded in the
77 # preflight script (this includes the root user, in case only the login screen
78 # is being remoted and this is a Keystone-triggered update).
79 # Also, in case this is a fresh install, load the service for the user running
80 # the installer, so they don't have to log out and back in again.
81 if [[ -n "$USER" && "$USER" != "root" ]]; then
82 id
-u "$USER" >> "$USERS_TMP_FILE"
85 if [[ -r "$USERS_TMP_FILE" ]]; then
86 for uid
in $
(sort "$USERS_TMP_FILE" |
uniq); do
87 logger Starting service
for user
"$uid".
89 if [[ "$uid" = "0" ]]; then
95 # Load the launchd agent in the bootstrap context of user $uid's graphical
96 # session, so that screen-capture and input-injection can work. To do this,
97 # find the PID of a process which is running in that context. The
98 # loginwindow process is a good candidate since the user (if logged in to
99 # a session) will definitely be running it.
100 pid
="$(find_login_window_for_user "$uid")"
101 if [[ -n "$pid" ]]; then
102 launchctl bsexec
"$pid" sudo
-u "#$uid" launchctl load
-w -S Aqua
"$PLIST"
103 launchctl bsexec
"$pid" sudo
-u "#$uid" launchctl start
"$SERVICE_NAME"