nayuos: Modifications:
[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 TEST_LOG={{ instance_log_dir }}/tests_nayuos_image.log
26 {{ depot_tools_export_path_cmd }}
27 cd {{ cros_location }}/{{ branch }}
28
29 # create chroot environment (exit on failure)
30 cros_sdk --download || exit 1
31
32 # compile Python with sqlite support (-> change USE flag) for dev-lang/python
33 # it is needed by re6st
34 # just need to change -sqlite by sqlite on the right line
35 PACKAGE_USE_FILE=${CHROMIUM_OVERLAY}/profiles/targets/chromeos/package.use
36 line_number=$(sed -n '/dev-lang\/python/=' ${PACKAGE_USE_FILE})
37 if [ $line_number ] ; then
38     echo $line_number
39     sed -i "${line_number}s/-sqlite/sqlite/" ${PACKAGE_USE_FILE}
40     if [[ ! $(sed -n ${line_number}p ${PACKAGE_USE_FILE} | grep ipv6) ]]; then
41         sed -i "${line_number}s/$/ ipv6/" ${PACKAGE_USE_FILE}
42     fi
43 fi
44
45 # add custom ebuilds
46 for category in $( ls {{ ebuilds_dir }} ); do
47   echo ${category}
48   cp -R {{ ebuilds_dir }}/${category}/* ${CHROMIUM_OVERLAY}/${category}/
49 done
50
51 install -m 770 "{{ scripts_dir }}/test_nayuos_image" "{{ cros_location }}/{{ branch }}/src/scripts/test_nayuos_image"
52
53 ### packages management ###
54
55 BASE_CHROMEOS_DEV_ROOT_EBUILD=${CHROMIUM_OVERLAY}/chromeos-base/chromeos-dev-root/chromeos-dev-root-0.0.1.ebuild
56 VIRTUAL_CHROMEOS_OS_DEV_EBUILD=${CHROMIUM_OVERLAY}/virtual/target-chromium-os-dev/target-chromium-os-dev-1.ebuild
57
58 # change the virtual ebuild responsible for installing all packages to add the ones
59 # needed for NayuOS
60 for package in {{ nayu_dev_packages }} ; do
61   echo $package
62   if [[ $( grep "${package}" "${VIRTUAL_CHROMEOS_OS_DEV_EBUILD}" ) ]] ; then
63     echo "no need to change ${VIRTUAL_CHROMEOS_OS_DEV_EBUILD} file to add ${package}..." >> "${BUILD_LOG}"
64   else
65     printf "\n\nRDEPEND=\"\${RDEPEND}\n          ${package}\"\n">> ${VIRTUAL_CHROMEOS_OS_DEV_EBUILD}
66   fi
67 done
68
69 # do not install the Upstart init script that starts ssh daemon at boot time
70 rm ${CHROMIUM_OVERLAY}/chromeos-base/chromeos-sshd-init/files/openssh-server.conf
71 sed -i -n '/src_install/q;p' ${CHROMIUM_OVERLAY}/chromeos-base/openssh-server-init/openssh-server-init-0.0.1.ebuild
72 sed -i -n '/src_install/q;p' ${CHROMIUM_OVERLAY}/chromeos-base/chromeos-sshd-init/chromeos-sshd-init-0.0.1.ebuild
73
74 # increase the revision number (XXX: is there a problem with md5-cache otherwise?)
75 # XXX: remove hardcoded revision numbers
76 cd ${CHROMIUM_OVERLAY}/chromeos-base/openssh-server-init/
77 mv openssh-server-init-0.0.1-r24.ebuild openssh-server-init-0.0.1-r25.ebuild
78 cd ${CHROMIUM_OVERLAY}/chromeos-base/chromeos-sshd-init/
79 mv chromeos-sshd-init-0.0.1-r5.ebuild chromeos-sshd-init-0.0.1-r6.ebuild
80
81 # bashrc modifications
82 BASH_EBUILD={{ cros_location }}/{{ branch }}/src/third_party/portage-stable/app-shells/bash
83 if [[ $(grep "git --exec-path" "${BASH_EBUILD}/files/dot-bashrc") ]] ; then
84   echo "git alias already set"
85 else
86   echo "# git quickfix for finding right git executables
87 if [ -d /usr/local/libexec/git-core/ ] ; then
88     alias git='git --exec-path=/usr/local/libexec/git-core/'
89 fi
90
91 # git quickfix for finding 'less' and using it as pager
92 if [ $(which less) ] ; then
93     git config --global core.pager $(which less)
94 fi
95 " >> ${BASH_EBUILD}/files/dot-bashrc
96 fi
97 #XXX: change bash ebuild revision number (as it is made for sshd removal)
98
99 ######################################## Build ##############################################
100 BOARDS="{{ boards_list }}"
101 KEEP_CACHE="{{ keep_cache }}"
102 for board in ${BOARDS} ; do
103   echo ${board}
104   if [ ${board} == daisy ] ; then
105     echo "daisy board: accepting license for Mali drivers..."
106     cros_sdk -- sudo sh -c "cp /etc/make.conf.user /etc/make.conf.user.save"
107     cros_sdk -- sudo sh -c "echo 'ACCEPT_LICENSE=\"*\"' >> /etc/make.conf.user"
108   fi
109
110   # preparing packages (for chroot and image)
111   date >> "${BUILD_LOG}"
112   echo "building packages for a ${board}-flavoured Chromium OS..." >> "${BUILD_LOG}"
113   cros_sdk -- ./build_packages --board=${board} >> "${BUILD_LOG}"
114
115   # change boot pictures
116   cros_sdk -- cros_workon --board=${board} start chromiumos-assets
117   cros_sdk -- cros_workon_make --board=${board} chromiumos-assets
118   cros_sdk -- cros_workon_make --board=${board} chromiumos-assets --test
119   cros_sdk -- cros_workon_make --board=${board} chromiumos-assets --install
120   cp {{ logo_dir }}/* {{ cros_location }}/{{ branch }}/src/platform/chromiumos-assets/images_100_percent/
121   cp {{ logo_dir }}/* {{ cros_location }}/{{ branch }}/src/platform/chromiumos-assets/images_200_percent/
122   #cros_sdk -- git commit -a -m "Changing boot pictures." # TODO: should not be necessary
123
124   NAYU_IMAGE_LOCATION=${board}.nayuos.img
125
126   # rebuild packages with boot pictures
127   cros_sdk -- ./build_packages --board=${board} >> "${BUILD_LOG}"
128
129   # NayuOS
130   date >> "${BUILD_LOG}"
131   echo "building image" >> "${BUILD_LOG}"
132   cros_sdk -- ./build_image --board=${board} dev >> "${BUILD_LOG}" \
133     && cros_sdk -- rm -f $NAYU_IMAGE_LOCATION && cros_sdk -- touch $NAYU_IMAGE_LOCATION \
134     && cros_sdk -- cros flash --board=${board} file://$NAYU_IMAGE_LOCATION >> "${BUILD_LOG}" \
135     && cros_sdk -- ./test_nayuos_image ${board} > "${TEST_LOG}" \
136     || exit 1
137
138   # TODO: test produced image (ex: make a diff of grandenet script from ebuild dir,
139   # check that <mountpoint>/usr/local is not empty, ...)
140
141   # save ~15Go/device but delete cache (next build will be as long)
142   if [ ${KEEP_CACHE,,} == "no" ] ; then
143     cros_sdk -- sudo rm -R /var/cache/chromeos-chrome/chrome-src/src/out_${board}
144   fi
145
146   if [ ${board} == daisy ]; then
147     echo "daisy board: removing accepted license for the next builds..."
148     cros_sdk -- sudo sh -c "mv /etc/make.conf.user.save /etc/make.conf.user"
149   fi
150 done
151
152 ####################################### Post build ##########################################
153 # keep only the substring between - as current release
154 RELEASE=$(echo ${BRANCH} | cut -d- -f2)
155 DIR_IMAGE_LOCATION={{ cros_location }}/images/${RELEASE}/$(date +'%F')
156 install ${DIR_IMAGE_LOCATION} -d
157 mv {{ cros_location }}/{{ branch }}/src/scripts/*.img ${DIR_IMAGE_LOCATION}
158
159 cd ${DIR_IMAGE_LOCATION}
160 for hashfunction in md5sum sha1sum sha256sum sha512sum; do
161   echo ${hashfunction} >> hashes.txt
162   ${hashfunction} *.img >> hashes.txt
163   printf "\n\n" >> hashes.txt
164 done
165
166 for file in $(ls *.img); do
167   gzip -9 ${file}
168 done
169
170 exit 0