|
| 1 | +#!/bin/sh |
| 2 | +# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 4 -*- |
| 3 | +# |
| 4 | +# Copyright (C) 2011,2013,2016 Canonical Ltd |
| 5 | +# |
| 6 | +# This program is free software: you can redistribute it and/or modify it under |
| 7 | +# the terms of the GNU General Public License as published by the Free Software |
| 8 | +# Foundation, version 3 of the License. |
| 9 | +# |
| 10 | +# See http://www.gnu.org/copyleft/gpl.html the full text of the license. |
| 11 | + |
| 12 | +# This wrapper merely ensures that init and friends live only as long as this |
| 13 | +# script does. Otherwise, it's very easy for some processes to not notice that |
| 14 | +# the session died. We could try to do this in-process, but we want to do this |
| 15 | +# cleanup even if the greeter aborts. |
| 16 | + |
| 17 | +trap cleanup TERM EXIT |
| 18 | + |
| 19 | +cleanup() |
| 20 | +{ |
| 21 | + trap - TERM EXIT |
| 22 | + # Kill upstart and indicators |
| 23 | + if [ -n "$INIT_PID" ]; then |
| 24 | + kill "$INIT_PID" |
| 25 | + fi |
| 26 | + if [ -n "$CMD_PID" ]; then |
| 27 | + kill "$CMD_PID" |
| 28 | + fi |
| 29 | + exit 0 |
| 30 | +} |
| 31 | + |
| 32 | +set_greeter_var() |
| 33 | +{ |
| 34 | + export "$1=$2" |
| 35 | + gdbus call --session --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method org.freedesktop.DBus.UpdateActivationEnvironment "{'$1': '$2'}" |
| 36 | + if [ -n "$INIT_PID" ]; then |
| 37 | + initctl set-env --global "$1=$2" |
| 38 | + fi |
| 39 | +} |
| 40 | + |
| 41 | +SUB_SOCKET=$XDG_RUNTIME_DIR/mir_socket |
| 42 | +rm -f $SUB_SOCKET # clear socket in case we were hard shut down |
| 43 | + |
| 44 | +echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}" >"$XDG_RUNTIME_DIR/dbus-session" |
| 45 | + |
| 46 | +# If touch session script (which sets up grid units and mir variables) is available, use it |
| 47 | +TOUCH_WRAPPER= |
| 48 | +if [ -x /usr/bin/ubuntu-touch-session ]; then |
| 49 | + TOUCH_WRAPPER=/usr/bin/ubuntu-touch-session |
| 50 | +fi |
| 51 | + |
| 52 | +# Pretend that we're in an ubuntu-touch session, so that indicator-network |
| 53 | +# will start. |
| 54 | +export DESKTOP_SESSION=ubuntu-touch |
| 55 | + |
| 56 | +# We disable ofono using pulse. It causes problems with racing with the user's |
| 57 | +# pulse. We need to come up with a better long-term fix for this, because we |
| 58 | +# eventually need the greeter to play ringtones for users that aren't logged in. |
| 59 | +set_greeter_var PA_DISABLED 1 |
| 60 | + |
| 61 | +# Normal unity8 sessions are entirely driven by Upstart. But greeters |
| 62 | +# are special. They need access to the file descriptors that lightdm |
| 63 | +# creates for them and don't want to start all the services that a normal |
| 64 | +# session would. So it's inconvenient to live within an upstart session. |
| 65 | +# But... we still want to use Upstart for some services. So launch here. |
| 66 | +MIR_SOCKET=$SUB_SOCKET $TOUCH_WRAPPER /sbin/upstart --user --no-startup-event & |
| 67 | +INIT_PID=$! |
| 68 | +while [ ! -e "$XDG_RUNTIME_DIR/upstart/sessions/$INIT_PID.session" ]; do sleep 0.1; done |
| 69 | +. "$XDG_RUNTIME_DIR/upstart/sessions/$INIT_PID.session" |
| 70 | +export UPSTART_SESSION |
| 71 | + |
| 72 | +# Connect upstart to system, but do first command in a loop to avoid any |
| 73 | +# race condition between the session file above being written and upstart being |
| 74 | +# ready to handle requests. |
| 75 | +while ! /sbin/initctl notify-dbus-address "$DBUS_SESSION_BUS_ADDRESS"; do sleep 0.1; done |
| 76 | +/sbin/initctl start notify-cgmanager |
| 77 | + |
| 78 | +# Start any pre-greeter tasks if needed (like wizard) |
| 79 | +/sbin/initctl emit unity8-greeter-starting |
| 80 | + |
| 81 | +# Define language here for phone if available. When phone user switches their |
| 82 | +# language, they expect that to affect the greeter too. But the user doesn't |
| 83 | +# have permission to switch system language, only their own. So we notice if |
| 84 | +# the phablet user exists and use their language if so. TODO: talk to design |
| 85 | +# about whether we should switch language on fly as users are selected (this |
| 86 | +# is very hard to do technically). |
| 87 | +# |
| 88 | +# Do this after unity8-greeter-starting, in case a customization upstart job |
| 89 | +# changes language. |
| 90 | +if [ "$(id -u phablet 2>/dev/null)" = "32011" ]; then |
| 91 | + USER_LANG=$(gdbus call --system --dest org.freedesktop.Accounts --object-path /org/freedesktop/Accounts/User32011 --method org.freedesktop.DBus.Properties.Get org.freedesktop.Accounts.User Language | cut -d\' -f2) |
| 92 | + if [ -n "$USER_LANG" ]; then |
| 93 | + set_greeter_var LANGUAGE "$USER_LANG" |
| 94 | + fi |
| 95 | + USER_LOCALE=$(gdbus call --system --dest org.freedesktop.Accounts --object-path /org/freedesktop/Accounts/User32011 --method org.freedesktop.DBus.Properties.Get org.freedesktop.Accounts.User FormatsLocale | cut -d\' -f2) |
| 96 | + if [ -n "$USER_LOCALE" ]; then |
| 97 | + set_greeter_var LANG "$USER_LOCALE" |
| 98 | + set_greeter_var LC_ALL "$USER_LOCALE" |
| 99 | + fi |
| 100 | +fi |
| 101 | + |
| 102 | +# And finally actually start the greeter |
| 103 | +exec env QT_QPA_PLATFORM=ubuntumirclient MIR_SERVER_FILE=$SUB_SOCKET $TOUCH_WRAPPER $@ & |
| 104 | +CMD_PID=$! |
| 105 | +wait $CMD_PID |
| 106 | +CMD_PID= |
0 commit comments