nayuos: Add logo, hash names in hashes.txt, keep_cache parameter (experimental),...
[slapos.git] / scripts / cros_full_build.in
1 #!/bin/bash
2 #XXX: should not depend on the host's bash ^
3
4 ######################## Download of sources using the "repo" command ########################
5 DL_LOG={{ instance_log_dir }}/cros_sources_dl.log
6 BRANCH={{ branch }}
7 CHROMIUM_OVERLAY={{ cros_location }}/{{ branch }}/src/third_party/chromiumos-overlay
8
9 echo "getting Chromium OS sources..." >> $DL_LOG
10 {{ depot_tools_export_path_cmd }}
11 echo "{{ cros_location }}/{{ branch }}"
12 install -d "{{ cros_location }}/{{ branch }}"
13 cd "{{ cros_location }}/{{ branch }}"
14
15 repo init -u https://chromium.googlesource.com/chromiumos/manifest.git -b {{ branch }} >> $DL_LOG
16
17 # in case code was already there, stash changes to be able to pull
18 cd ${CHROMIUM_OVERLAY}
19 git stash
20
21 repo sync >> $DL_LOG
22
23 ############################## Prepare chroot environment ###################################
24 BUILD_LOG={{ instance_log_dir }}/cros_build.log
25 {{ depot_tools_export_path_cmd }}
26 cd {{ cros_location }}/{{ branch }}
27
28 # create chroot environment (exit on failure)
29 cros_sdk --download || exit 1
30
31 # compile Python with sqlite support (-> change USE flag) for dev-lang/python
32 # it is needed by re6st
33 # just need to change -sqlite by sqlite on the right line
34 PACKAGE_USE_FILE=${CHROMIUM_OVERLAY}/profiles/targets/chromeos/package.use
35 line_number=$(sed -n '/dev-lang\/python/=' ${PACKAGE_USE_FILE})
36 if [ $line_number ] ; then
37     echo $line_number
38     sed -i "${line_number}s/-sqlite/sqlite/" ${PACKAGE_USE_FILE}
39     if [[ ! $(sed -n ${line_number}p ${PACKAGE_USE_FILE} | grep ipv6) ]]; then
40         sed -i "${line_number}s/$/ ipv6/" ${PACKAGE_USE_FILE}
41     fi
42 fi
43
44 # add custom ebuilds
45 for category in $( ls {{ ebuilds_dir }} ); do
46   echo ${category}
47   cp -R {{ ebuilds_dir }}/${category}/* ${CHROMIUM_OVERLAY}/${category}/
48 done
49
50 ### packages management ###
51
52 BASE_CHROMEOS_DEV_ROOT_EBUILD=${CHROMIUM_OVERLAY}/chromeos-base/chromeos-dev-root/chromeos-dev-root-0.0.1.ebuild
53 VIRTUAL_CHROMEOS_OS_DEV_EBUILD=${CHROMIUM_OVERLAY}/virtual/target-chromium-os-dev/target-chromium-os-dev-1.ebuild
54
55 # change the virtual ebuild responsible for installing all packages to add the ones
56 # needed for NayuOS
57 for package in {{ nayu_dev_packages }} ; do
58   echo $package
59   if [[ $( cat "${VIRTUAL_CHROMEOS_OS_DEV_EBUILD}" | grep "${package}" ) ]] ; then
60     echo "no need to change ${VIRTUAL_CHROMEOS_OS_DEV_EBUILD} file to add ${package}..." >> "${BUILD_LOG}"
61   else
62     printf "\n\nRDEPEND=\"\${RDEPEND}\n          ${package}\"\n">> ${VIRTUAL_CHROMEOS_OS_DEV_EBUILD}
63   fi
64 done
65
66 # do not install the Upstart init script that starts ssh daemon at boot time
67 sed -i '/openssh-server-init/ d' ${BASE_CHROMEOS_DEV_ROOT_EBUILD}
68
69 ######################################## Build ##############################################
70 BOARDS="{{ boards_list }}"
71 KEEP_CACHE = "{{ keep_cache }}"
72 for board in ${BOARDS}; do
73   echo ${board}
74   if [ ${board} == daisy ]; then
75     echo "daisy board: accepting license for Mali drivers..."
76     cros_sdk -- sudo sh -c "cp /etc/make.conf.user /etc/make.conf.user.save"
77     cros_sdk -- sudo sh -c "echo 'ACCEPT_LICENSE=\"*\"' >> /etc/make.conf.user"
78   fi
79
80   # preparing packages (for chroot and image)
81   date >> "${BUILD_LOG}"
82   echo "building packages for a ${board}-flavoured Chromium OS..." >> "${BUILD_LOG}"
83   cros_sdk -- ./build_packages --board=${board} >> "${BUILD_LOG}"
84
85   # change boot pictures
86   cros_sdk -- cros_workon --board=${board} start chromiumos-assets
87   cros_sdk -- cros_workon_make --board=${board} chromiumos-assets
88   cros_sdk -- cros_workon_make --board=${board} chromiumos-assets --test
89   cros_sdk -- cros_workon_make --board=${board} chromiumos-assets --install
90   cp {{ logo_dir }}/* {{ cros_location }}/{{ branch }}/src/platform/chromiumos-assets/images_100_percent/
91   cp {{ logo_dir }}/* {{ cros_location }}/{{ branch }}/src/platform/chromiumos-assets/images_200_percent/
92   #cros_sdk -- git commit -a -m "Changing boot pictures." # TODO: should not be necessary
93
94   IMAGE_LOCATION=${board}.chromiumos.img
95   NAYU_IMAGE_LOCATION=${board}.nayuos.img
96
97   # rebuild packages with boot pictures
98   cros_sdk -- ./build_packages --board=${board} >> "${BUILD_LOG}"
99
100   # NayuOS
101     # /usr/local/usr/lib/debug is needed because of symbolic links that leads
102     # to this directory when installing some packages (babeld-re6stnet in particular)
103     # because installation will fail if the symbolic link is broken
104   date >> "${BUILD_LOG}"
105   echo "rebuilding image with noenable_rootfs_verification" >> "${BUILD_LOG}"
106   cros_sdk -- ./build_image --noenable_rootfs_verification --board=${board} dev >> "${BUILD_LOG}" \
107     && echo "adding packages image, removing old image if any and creating image file $NAYU_IMAGE_LOCATION..." >> "${BUILD_LOG}" \
108     && cros_sdk -- sudo install -d /usr/local/usr/lib/debug \
109     && cros_sdk -- rm -f $NAYU_IMAGE_LOCATION && cros_sdk -- touch $NAYU_IMAGE_LOCATION \
110     && cros_sdk -- cros flash --board=${board} file://$NAYU_IMAGE_LOCATION >> "${BUILD_LOG}" \
111     || exit 1
112
113   # save ~15Go/device but delete cache (next build will be as long)
114   if [ !${KEEP_CACHE} -o ${KEEP_CACHE,,} == "no" ] ; then
115     cros_sdk -- sudo rm -R /var/cache/chromeos-chrome/chrome-src/src/out_${board}
116   fi
117
118   if [ ${board} == daisy ]; then
119     echo "daisy board: removing accepted license for the next builds..."
120     cros_sdk -- sudo sh -c "mv /etc/make.conf.user.save /etc/make.conf.user"
121   fi
122 done
123
124 ####################################### Post build ##########################################
125 # keep only the substring between - as current release
126 RELEASE=$(echo ${BRANCH} | cut -d- -f2)
127 DIR_IMAGE_LOCATION={{ cros_location }}/{{ branch }}/images/${RELEASE}/$(date +'%F')
128 install ${DIR_IMAGE_LOCATION} -d
129 mv {{ cros_location }}/{{ branch }}/src/scripts/*.img ${DIR_IMAGE_LOCATION}
130
131 cd ${DIR_IMAGE_LOCATION}
132 for hashfunction in md5sum sha1sum sha256sum sha512sum; do
133   echo ${hashfunction} >> hashes.txt
134   ${hashfunction} *.img >> hashes.txt
135   printf "\n\n" >> hashes.txt
136 done
137
138 for file in $(ls *.img); do
139   gzip -9 ${file}
140 done
141
142 exit 0