dra7xx-evm: weston: add changes for AGL home screen
[AGL/meta-agl.git] / meta-agl-bsp / meta-ti / recipes-arago / weston-init / weston-init / init
1 #!/bin/sh
2 #
3 ### BEGIN INIT INFO
4 # Provides: weston
5 # Required-Start: $local_fs $remote_fs
6 # Required-Stop: $local_fs $remote_fs
7 # Default-Start:     2 3 4 5
8 # Default-Stop:      0 1 6
9 ### END INIT INFO
10
11 killproc() {
12         pid=`/bin/pidof $1`
13         [ "$pid" != "" ] && kill $pid
14 }
15
16 read CMDLINE < /proc/cmdline
17 for x in $CMDLINE; do
18         case $x in
19         weston=false)
20                 echo "Weston disabled"
21                 exit 0;
22                 ;;
23         esac
24 done
25
26 case "$1" in
27   start)
28         . /etc/profile
29
30         # Weston for some reason dies if these environment variables are set
31         unset WAYLAND_DISPLAY
32
33         # This is all a nasty hack
34         if test -z "$XDG_RUNTIME_DIR"; then
35             export XDG_RUNTIME_DIR=/run/user/root
36         fi
37
38         if [ ! -d "$XDG_RUNTIME_DIR" ] ; then
39             mkdir --parents $XDG_RUNTIME_DIR
40             chmod 0700 $XDG_RUNTIME_DIR
41         fi
42
43         openvt -c 4 -f runWeston
44
45         # If there's no touchscreen device available, done
46         if [ ! -e /dev/input/touchscreen0 ] ; then
47             exit 0
48         fi
49
50         # If it was already calibrated, done
51         if [ -f "$WS_CALUDEV_FILE" ] ; then
52             exit 0
53         fi
54
55         # Check if SD card is mounted
56         mount | grep /run/media/mmcblk0p1 | grep vfat > /dev/null 2>&1
57         if [ "$?" = "0" ] ; then
58             SD_MOUNTED="1"
59         else
60             SD_MOUNTED="0"
61         fi
62
63         # Check if SD card has a calibration rules file
64         SD_CALUDEV_FILE=/run/media/mmcblk0p1/ws-calibrate.rules
65         if [ "$SD_MOUNTED" = "1" -a -f "$SD_CALUDEV_FILE" ] ; then
66             # Copy it over to udev location
67             cp "$SD_CALUDEV_FILE" "$WS_CALUDEV_FILE"
68         else
69             # Run a calibration app and save output to udev rules
70             echo    "Calibrating touchscreen (first time only)"
71             echo
72             echo    "*** To continue, please complete the touchscreen calibration"
73             echo -n "*** by touching the crosshairs on the LCD screen"
74             sleep 1
75             CAL_VALUES=`weston-calibrator|cut -c21-`
76             echo 'SUBSYSTEM=="input", ENV{WL_CALIBRATION}="'$CAL_VALUES'"' > $WS_CALUDEV_FILE
77             echo "."
78             # Copy it back to SD
79             if [ "$SD_MOUNTED" = "1" ] ; then
80                 cp "$WS_CALUDEV_FILE" "$SD_CALUDEV_FILE"
81             fi
82         fi
83
84         # Reload and re-run udev rules and restart weston
85         udevadm control --reload
86         udevadm trigger
87         killproc weston
88         sleep 2
89         openvt -c 4 -f runWeston
90   ;;
91
92   stop)
93         echo "Stopping Weston"
94         killproc weston
95   ;;
96
97   restart)
98         $0 stop
99         sleep 2
100         $0 start
101   ;;
102
103   *)
104         echo "usage: $0 { start | stop | restart }"
105   ;;
106 esac
107
108 exit 0