blob: 0f1bc4c29d19a13c9be6d297e13fb5559304ae06 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/bin/sh
2# Copyright (C) 2016 O.S. Systems Software LTDA.
3# Copyright (C) 2016 Freescale Semiconductor
4
5export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
6
7usage() {
Brad Bishopc342db32019-05-15 21:57:59 -04008 cat <<EOF
9 $0 [<openvt arguments>] [-- <weston options>]
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010EOF
11}
12
13## Module support
14modules_dir=@DATADIR@/weston-start
15
16# Add weston extra argument
17add_weston_argument() {
18 weston_args="$weston_args $1"
19}
20
21# Add openvt extra argument
22add_openvt_argument() {
23 openvt_args="$openvt_args $1"
Andrew Geisslereff27472021-10-29 15:35:00 -050024
25}
26## Add module to --modules argument
27add_weston_module() {
28 if [[ "x${weston_modules}" == "x" ]]; then
29 weston_modules="--modules "
30 fi;
31 weston_modules+="${1},"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032}
33
34if [ -n "$WAYLAND_DISPLAY" ]; then
35 echo "ERROR: A Wayland compositor is already running, nested Weston instance is not supported yet."
36 exit 1
37fi
Brad Bishopc342db32019-05-15 21:57:59 -040038
39if [ -n "$WESTON_USER" ]; then
40 if [ -z "$WESTON_TTY" ]; then
41 echo "ERROR: If you have WESTON_USER variable set, you also need WESTON_TTY."
42 exit 1
43 fi
Andrew Geissler6ce62a22020-11-30 19:58:47 -060044 if [ -z "$WESTON_GROUP" ]; then
45 # no explicit WESTON_GROUP given, therefore use WESTON_USER
46 export WESTON_GROUP="${WESTON_USER}"
47 fi
Brad Bishopc342db32019-05-15 21:57:59 -040048 weston_args_user="-u $WESTON_USER -t $WESTON_TTY"
49fi
50
Patrick Williamsc0f7c042017-02-23 20:41:17 -060051if [ -n "$DISPLAY" ]; then
52 launcher="weston"
53else
Brad Bishopc342db32019-05-15 21:57:59 -040054 launcher="weston-launch $weston_args_user --"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060055fi
56
57openvt_args="-s"
58while [ -n "$1" ]; do
59 if [ "$1" = "--" ]; then
60 shift
61 break
62 fi
63 openvt_args="$openvt_args $1"
64 shift
65done
66
67weston_args=$*
68
69# Load and run modules
70if [ -d "$modules_dir" ]; then
71 for m in "$modules_dir"/*; do
72 # Skip backup files
73 if [ "`echo $m | sed -e 's/\~$//'`" != "$m" ]; then
74 continue
75 fi
76
77 # process module
78 . $m
Andrew Geisslereff27472021-10-29 15:35:00 -050079 if [[ x"{$weston_modules}" != "x" ]]; then
80 add_weston_argument "${weston_modules}"
81 fi;
Patrick Williamsc0f7c042017-02-23 20:41:17 -060082 done
83fi
84
85if test -z "$XDG_RUNTIME_DIR"; then
Brad Bishopc342db32019-05-15 21:57:59 -040086 export XDG_RUNTIME_DIR=/run/user/`id -u ${WESTON_USER}`
87 if ! test -d "$XDG_RUNTIME_DIR"; then
88 mkdir --parents $XDG_RUNTIME_DIR
89 chmod 0700 $XDG_RUNTIME_DIR
90 fi
91 if [ -n "$WESTON_USER" ]
92 then
Andrew Geissler6ce62a22020-11-30 19:58:47 -060093 chown $WESTON_USER:$WESTON_GROUP $XDG_RUNTIME_DIR
Brad Bishopc342db32019-05-15 21:57:59 -040094 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -060095fi
96
97exec openvt $openvt_args -- $launcher $weston_args --log=@LOCALSTATEDIR@/log/weston.log