new configuration templates based on 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
28 of firmware (depending on BSP):
29
30 * bootloaders: the first stage bootloaders are proprietary for this
31   board, they are included in this firmware package.
32 * firmware for the power management 'companion' core: on QCOM SoC some
33   power management features are implemented in a companion core , called
34   RPM, and not on the main CPU.
35 * firmware for GPU, WLAN, DSP/GPS and video codecs. These firmware are
36   used by their respective linux drivers (DRM, wlan, v4l2, .. ) and are
37   loaded on-demand by the main CPU onto the various cores on the SoC.
38 EOF
39
40             echo
41             REPLY=
42             while [ -z "$REPLY" ]; do
43                 echo -n "Do you read the EULA ? (y/n) "
44                 read REPLY
45                 case "$REPLY" in
46                     y|Y)
47                         READ_EULA=1
48                         ;;
49                     n|N)
50                         READ_EULA=0
51                         ;;
52                     *)
53                         REPLY=
54                         ;;
55                 esac
56             done
57
58             if [ "$READ_EULA" == 1 ]; then
59                 more -d ${EULA}
60                 echo
61                 REPLY=
62                 while [ -z "$REPLY" ]; do
63                     echo -n "Do you accept the EULA you just read? (y/n) "
64                     read REPLY
65                     case "$REPLY" in
66                         y|Y)
67                             echo "EULA has been accepted."
68                             EULA_ACCEPT=1
69                             ;;
70                         n|N)
71                             echo "EULA has not been accepted."
72                             ;;
73                         *)
74                             REPLY=
75                             ;;
76                     esac
77                 done
78             fi
79         fi
80     fi
81 }
82
83 EULA_ACCEPT=0