xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-graphics/wayland/weston-init/weston-start (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/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() {
8	cat <<EOF
9	$0 [<weston options>]
10EOF
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 module to --modules argument
22add_weston_module() {
23	if [[ "x${weston_modules}" == "x" ]]; then
24		weston_modules="--modules "
25	fi;
26	weston_modules+="${1},"
27}
28
29if [ -n "$WAYLAND_DISPLAY" ]; then
30	echo "ERROR: A Wayland compositor is already running, nested Weston instance is not supported yet."
31	exit 1
32fi
33
34if [ -n "$WESTON_USER" ]; then
35	if [ -z "$WESTON_GROUP" ]; then
36		# no explicit WESTON_GROUP given, therefore use WESTON_USER
37		export WESTON_GROUP="${WESTON_USER}"
38	fi
39fi
40
41weston_args=$*
42
43# Load and run modules
44if [ -d "$modules_dir" ]; then
45	for m in "$modules_dir"/*; do
46		# Skip backup files
47		if [ "`echo $m | sed -e 's/\~$//'`" != "$m" ]; then
48			continue
49		fi
50
51		# process module
52		. $m
53		if [[ x"{$weston_modules}" != "x" ]]; then
54			add_weston_argument "${weston_modules}"
55		fi;
56	done
57fi
58
59if test -z "$XDG_RUNTIME_DIR"; then
60	export XDG_RUNTIME_DIR=/run/user/`id -u ${WESTON_USER}`
61	if ! test -d "$XDG_RUNTIME_DIR"; then
62		mkdir --parents $XDG_RUNTIME_DIR
63		chmod 0700 $XDG_RUNTIME_DIR
64	fi
65	if [ -n "$WESTON_USER" ]
66	then
67		chown $WESTON_USER:$WESTON_GROUP $XDG_RUNTIME_DIR
68	fi
69fi
70
71su -c "XDG_RUNTIME_DIR=/run/user/`id -u ${WESTON_USER}` weston $weston_args --log=/tmp/weston.log" $WESTON_USER
72