aglsetup script: fix interactive execution of the script generated from fragments
[AGL/meta-agl.git] / templates / base / 01_setup_EULAfunc.sh
1 find_and_ack_eula() {
2     # Handle EULA , if needed. This is a generic method to handle BSPs
3     # that might (or not) come with a EULA. If a machine has a EULA, we
4     # assume that its corresponding layers has conf/EULA/$MACHINE file
5     # with the EULA text, which we will display to the user and request
6     # for acceptance. If accepted, the variable ACCEPT_EULA_$MACHINE is
7     # set to 1 in local.conf, which can later be used by the BSP.
8     # If the env variable EULA_$MACHINE is set it is used by default,
9     # without prompting the user.
10     # FIXME: there is a potential issue if the same $MACHINE is set in more than one layer.. but we should assert that earlier
11     EULA=$(find $1 -print | grep "conf/eula/$MACHINE" | grep -v scripts | grep -v openembedded-core || true)
12     if [ -n "$EULA" ]; then
13         # remove '-' since we are constructing a bash variable name here
14         EULA_MACHINE="EULA_$(echo $MACHINE | sed 's/-//g')"
15         # NOTE: indirect reference / dynamic variable
16         if [ -n "${!EULA_MACHINE}" ]; then
17             # the EULA_$MACHINE variable is set in the environment, so we just configure
18             # ACCEPT_EULA_$MACHINE in local.conf
19             EULA_ACCEPT=${!EULA_MACHINE}
20         else
21             # so we need to ask user if he/she accepts the EULA:
22             cat <<EOF
23 The BSP for $MACHINE depends on packages and firmware which are covered by an 
24 End User License Agreement (EULA). To have the right to use these binaries
25 in your images, you need to read and accept the following...
26
27 The firmware package can contains several types of firmware (depending on BSP):
28
29 * bootloaders: the first stage bootloaders are proprietary for this
30   board, they are included in this firmware package.
31 * firmware for the power management 'companion' core: on QCOM SoC some
32   power management features are implemented in a companion core , called
33   RPM, and not on the main CPU.
34 * firmware for GPU, WLAN, DSP/GPS and video codecs. These firmware are
35   used by their respective linux drivers (DRM, wlan, v4l2, .. ) and are
36   loaded on-demand by the main CPU onto the various cores on the SoC.
37 EOF
38
39             echo
40             REPLY=
41             while [ -z "$REPLY" ]; do
42                 echo -n "Do you want to read the EULA ? (y/n) "
43                 read REPLY
44                 case "$REPLY" in
45                     y|Y)
46                         READ_EULA=1
47                         ;;
48                     n|N)
49                         READ_EULA=0
50                         ;;
51                     *)
52                         REPLY=
53                         ;;
54                 esac
55             done
56
57             if [ "$READ_EULA" == 1 ]; then
58                 more -d ${EULA}
59                 echo
60                 REPLY=
61                 while [ -z "$REPLY" ]; do
62                     echo -n "Do you accept the EULA you just read? (y/n) "
63                     read REPLY
64                     case "$REPLY" in
65                         y|Y)
66                             echo "EULA has been accepted."
67                             EULA_ACCEPT=1
68                             ;;
69                         n|N)
70                             echo "EULA has not been accepted."
71                             ;;
72                         *)
73                             REPLY=
74                             ;;
75                     esac
76                 done
77             fi
78         fi
79     fi
80 }
81
82 EULA_ACCEPT=0