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