summaryrefslogtreecommitdiffstats
path: root/meta/classes/rootfs-postcommands.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-05 17:52:06 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-06 15:27:33 +0000
commit0051510ae3e8f5d4dcd1f074bba1bd9c7e2362d9 (patch)
treeb0b2de5246440fe2552e45b172741b010d06c467 /meta/classes/rootfs-postcommands.bbclass
parent3428eddcd1c433c52f1886598479c5970dd400d5 (diff)
downloadpoky-0051510ae3e8f5d4dcd1f074bba1bd9c7e2362d9.tar.gz
image/rootfs-postcommands: Separate out post rootfs commands to separate class
Reading image.bbclass is a little difficult as it has many post rootfs helper functions and its hard to separate those from the core contents of the rootfs/image code. Moving it to a separate class would be one way of making it clearer what these functions are. There are some comment layout improvements but no code changes. (From OE-Core rev: df4cb51c8e60fa46d4d15be8da3d84287ff08ae7) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/rootfs-postcommands.bbclass')
-rw-r--r--meta/classes/rootfs-postcommands.bbclass258
1 files changed, 258 insertions, 0 deletions
diff --git a/meta/classes/rootfs-postcommands.bbclass b/meta/classes/rootfs-postcommands.bbclass
new file mode 100644
index 0000000000..7c440acf00
--- /dev/null
+++ b/meta/classes/rootfs-postcommands.bbclass
@@ -0,0 +1,258 @@
1
2# Zap the root password if debug-tweaks feature is not enabled
3ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password ; ",d)}'
4
5# Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks is enabled
6ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-empty-password' ], "ssh_allow_empty_password; ", "",d)}'
7
8# Enable postinst logging if debug-tweaks is enabled
9ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'post-install-logging' ], "postinst_enable_logging; ", "",d)}'
10
11# Create /etc/timestamp during image construction to give a reasonably sane default time setting
12ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp ; "
13
14# Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled
15ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}'
16
17# Write manifest
18IMAGE_MANIFEST = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.manifest"
19ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest ; "
20# Set default postinst log file
21POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log"
22# Set default target for systemd images
23SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains("IMAGE_FEATURES", "x11-base", "graphical.target", "multi-user.target", d)}'
24ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target; ", "", d)}'
25
26ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;'
27
28# Disable DNS lookups, the SSH_DISABLE_DNS_LOOKUP can be overridden to allow
29# distros to choose not to take this change
30SSH_DISABLE_DNS_LOOKUP ?= " ssh_disable_dns_lookup ; "
31ROOTFS_POSTPROCESS_COMMAND_append_qemuall = "${SSH_DISABLE_DNS_LOOKUP}"
32
33
34
35#
36# A hook function to support read-only-rootfs IMAGE_FEATURES
37#
38read_only_rootfs_hook () {
39 # Tweak the mount option and fs_passno for rootfs in fstab
40 sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab
41
42 # If we're using openssh and the /etc/ssh directory has no pre-generated keys,
43 # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly
44 # and the keys under /var/run/ssh.
45 if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then
46 if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then
47 echo "SYSCONFDIR=/etc/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh
48 echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh
49 else
50 echo "SYSCONFDIR=/var/run/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh
51 echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh
52 fi
53 fi
54
55 # Also tweak the key location for dropbear in the same way.
56 if [ -d ${IMAGE_ROOTFS}/etc/dropbear ]; then
57 if [ -e ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ]; then
58 echo "DROPBEAR_RSAKEY_DIR=/etc/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear
59 else
60 echo "DROPBEAR_RSAKEY_DIR=/var/lib/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear
61 fi
62 fi
63
64
65 if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then
66 # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes
67 if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then
68 sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS
69 fi
70 # Run populate-volatile.sh at rootfs time to set up basic files
71 # and directories to support read-only rootfs.
72 if [ -x ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
73 ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
74 fi
75 fi
76
77 if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then
78 # Update user database files so that services don't fail for a read-only systemd system
79 for conffile in ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd.conf ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd-remote.conf; do
80 [ -e $conffile ] || continue
81 grep -v "^#" $conffile | sed -e '/^$/d' | while read type name id comment; do
82 if [ "$type" = "u" ]; then
83 useradd_params=""
84 [ "$id" != "-" ] && useradd_params="$useradd_params --uid $id"
85 [ "$comment" != "-" ] && useradd_params="$useradd_params --comment $comment"
86 useradd_params="$useradd_params --system $name"
87 eval useradd --root ${IMAGE_ROOTFS} $useradd_params || true
88 elif [ "$type" = "g" ]; then
89 groupadd_params=""
90 [ "$id" != "-" ] && groupadd_params="$groupadd_params --gid $id"
91 groupadd_params="$groupadd_params --system $name"
92 eval groupadd --root ${IMAGE_ROOTFS} $groupadd_params || true
93 fi
94 done
95 done
96 fi
97}
98
99#
100# This function is intended to disallow empty root password if 'debug-tweaks' is not in IMAGE_FEATURES.
101#
102zap_empty_root_password () {
103 if [ -e ${IMAGE_ROOTFS}/etc/shadow ]; then
104 sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/shadow
105 fi
106 if [ -e ${IMAGE_ROOTFS}/etc/passwd ]; then
107 sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/passwd
108 fi
109}
110
111#
112# allow dropbear/openssh to accept root logins and logins from accounts with an empty password string
113#
114ssh_allow_empty_password () {
115 if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
116 sed -i 's/^[#[:space:]]*PermitRootLogin.*/PermitRootLogin yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
117 sed -i 's/^[#[:space:]]*PermitEmptyPasswords.*/PermitEmptyPasswords yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
118 fi
119
120 if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then
121 if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null ; then
122 if ! grep -q "DROPBEAR_EXTRA_ARGS=.*-B" ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear ; then
123 sed -i 's/^DROPBEAR_EXTRA_ARGS="*\([^"]*\)"*/DROPBEAR_EXTRA_ARGS="\1 -B"/' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
124 fi
125 else
126 printf '\nDROPBEAR_EXTRA_ARGS="-B"\n' >> ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
127 fi
128 fi
129
130 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/pam.d ] ; then
131 sed -i 's/nullok_secure/nullok/' ${IMAGE_ROOTFS}${sysconfdir}/pam.d/*
132 fi
133}
134
135ssh_disable_dns_lookup () {
136 if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
137 sed -i -e 's:#UseDNS yes:UseDNS no:' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
138 fi
139}
140
141#
142# Enable postinst logging if debug-tweaks is enabled
143#
144postinst_enable_logging () {
145 mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default
146 echo "POSTINST_LOGGING=1" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
147 echo "LOGFILE=${POSTINST_LOGFILE}" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
148}
149
150#
151# Modify systemd default target
152#
153set_systemd_default_target () {
154 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ]; then
155 ln -sf ${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/systemd/system/default.target
156 fi
157}
158
159# If /var/volatile is not empty, we have seen problems where programs such as the
160# journal make assumptions based on the contents of /var/volatile. The journal
161# would then write to /var/volatile before it was mounted, thus hiding the
162# items previously written.
163#
164# This change is to attempt to fix those types of issues in a way that doesn't
165# affect users that may not be using /var/volatile.
166empty_var_volatile () {
167 if [ -e ${IMAGE_ROOTFS}/etc/fstab ]; then
168 match=`awk '$1 !~ "#" && $2 ~ /\/var\/volatile/{print $2}' ${IMAGE_ROOTFS}/etc/fstab 2> /dev/null`
169 if [ -n "$match" ]; then
170 find ${IMAGE_ROOTFS}/var/volatile -mindepth 1 -delete
171 fi
172 fi
173}
174
175# Turn any symbolic /sbin/init link into a file
176remove_init_link () {
177 if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
178 LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
179 rm ${IMAGE_ROOTFS}/sbin/init
180 cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
181 fi
182}
183
184make_zimage_symlink_relative () {
185 if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
186 (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
187 fi
188}
189
190insert_feed_uris () {
191
192 echo "Building feeds for [${DISTRO}].."
193
194 for line in ${FEED_URIS}
195 do
196 # strip leading and trailing spaces/tabs, then split into name and uri
197 line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
198 feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
199 feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"
200
201 echo "Added $feed_name feed with URL $feed_uri"
202
203 # insert new feed-sources
204 echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf
205 done
206}
207
208python write_image_manifest () {
209 from oe.rootfs import image_list_installed_packages
210 with open(d.getVar('IMAGE_MANIFEST', True), 'w+') as image_manifest:
211 image_manifest.write(image_list_installed_packages(d, 'ver'))
212 image_manifest.write("\n")
213}
214
215# Can be use to create /etc/timestamp during image construction to give a reasonably
216# sane default time setting
217rootfs_update_timestamp () {
218 date -u +%4Y%2m%2d%2H%2M%2S >${IMAGE_ROOTFS}/etc/timestamp
219}
220
221# Prevent X from being started
222rootfs_no_x_startup () {
223 if [ -f ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm ]; then
224 chmod a-x ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm
225 fi
226}
227
228rootfs_trim_schemas () {
229 for schema in ${IMAGE_ROOTFS}/etc/gconf/schemas/*.schemas
230 do
231 # Need this in case no files exist
232 if [ -e $schema ]; then
233 oe-trim-schemas $schema > $schema.new
234 mv $schema.new $schema
235 fi
236 done
237}
238
239rootfs_check_host_user_contaminated () {
240 contaminated="${WORKDIR}/host-user-contaminated.txt"
241 HOST_USER_UID="$(PSEUDO_UNLOAD=1 id -u)"
242 HOST_USER_GID="$(PSEUDO_UNLOAD=1 id -g)"
243
244 find "${IMAGE_ROOTFS}" -wholename "${IMAGE_ROOTFS}/home" -prune \
245 -user "$HOST_USER_UID" -o -group "$HOST_USER_GID" >"$contaminated"
246
247 if [ -s "$contaminated" ]; then
248 echo "WARNING: Paths in the rootfs are owned by the same user or group as the user running bitbake. See the logfile for the specific paths."
249 cat "$contaminated" | sed "s,^, ,"
250 fi
251}
252
253# Make any absolute links in a sysroot relative
254rootfs_sysroot_relativelinks () {
255 sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT}
256}
257
258