summaryrefslogtreecommitdiff
path: root/recipes-graphics/wayland/weston-init/am62xx/init
blob: fa3f0372cb2f54649bc7f24b6e8fa0825a92c35a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: weston
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

killproc() {
	all_pids=`/bin/pidof $1`

	# busybox pidof doesn't ommit the current pid
	# as this script is called weston on the target
	# in thinlinux with a busybox based utility load
	# later killproc operations end up killing this
	# script.
	for pid in $all_pids
	do
		if [ "$pid" != "$$" ]; then
			kill_pids+=$pid
		fi
	done

	[ "$kill_pids" != "" ] && kill $kill_pids
}

read CMDLINE < /proc/cmdline
for x in $CMDLINE; do
        case $x in
        weston=false)
		echo "Weston disabled"
		exit 0;
                ;;
        esac
done

case "$1" in
  start)
        . /etc/profile

        # Weston for some reason dies if these environment variables are set
        unset WAYLAND_DISPLAY

        # This is all a nasty hack
        if test -z "$XDG_RUNTIME_DIR"; then
            export XDG_RUNTIME_DIR=/run/user/root
        fi

        if [ ! -d "$XDG_RUNTIME_DIR" ] ; then
            mkdir --parents $XDG_RUNTIME_DIR
            chmod 0700 $XDG_RUNTIME_DIR
        fi

        echo "Starting Weston"

        if [ ! -d "/dev/input" ]; then
            echo "Waiting for input device..."
            killproc weston
            sleep 3
        fi

        openvt -c 4 -f runWeston

        # If there's no touchscreen device available, done
        if [ ! -e /dev/input/touchscreen0 ] ; then
            exit 0
        fi

        # If it was already calibrated, done
        if [ -f "$WS_CALUDEV_FILE" ] ; then
            exit 0
        fi

        # Check if SD card is mounted
        mount | grep /run/media/mmcblk0p1 | grep vfat > /dev/null 2>&1
        if [ "$?" = "0" ] ; then
            SD_MOUNTED="1"
        else
            SD_MOUNTED="0"
        fi

        # Check if SD card has a calibration rules file
        SD_CALUDEV_FILE=/run/media/mmcblk0p1/ws-calibrate.rules
        if [ "$SD_MOUNTED" = "1" -a -f "$SD_CALUDEV_FILE" ] ; then
            # Copy it over to udev location
            cp "$SD_CALUDEV_FILE" "$WS_CALUDEV_FILE"
        else
            # Run a calibration app and save output to udev rules
            echo    "Calibrating touchscreen (first time only)"
            echo
            echo    "*** To continue, please complete the touchscreen calibration"
            echo -n "*** by touching the crosshairs on the LCD screen"
            sleep 2
            CAL_VALUES=`weston-calibrator|cut -c21-`
            echo 'SUBSYSTEM=="input", ENV{WL_CALIBRATION}="'$CAL_VALUES'"' > $WS_CALUDEV_FILE
            echo "."
            # Copy it back to SD
            if [ "$SD_MOUNTED" = "1" ] ; then
                cp "$WS_CALUDEV_FILE" "$SD_CALUDEV_FILE"
            fi
        fi

        # Reload and re-run udev rules and restart weston
        udevadm control --reload
        udevadm trigger
        killproc weston
        sleep 2
        openvt -c 4 -f runWeston
  ;;

  stop)
        echo "Stopping Weston"
        killproc weston
  ;;

  restart)
	$0 stop
        sleep 2
        $0 start
  ;;

  *)
        echo "usage: $0 { start | stop | restart }"
  ;;
esac

exit 0