weekly-changelog-report: make script more general
[openembedded.git] / classes / rootfs_rpm.bbclass
blobe3e306450e60ece4fbdfabaa345145f5594c9928
2 # Creates a root filesystem out of rpm packages
5 ROOTFS_PKGMANAGE = "rpm yum"
7 ROOTFS_PKGMANAGE_BOOTSTRAP  = "run-postinsts"
9 do_rootfs[depends] += "rpm-native:do_populate_staging yum-native:do_populate_staging createrepo-native:do_populate_staging fakechroot-native:do_populate_staging"
10 do_rootfs[recrdeptask] += "do_package_write_rpm"
12 YUMCONF = "${IMAGE_ROOTFS}/etc/yum.conf"
13 YUMARGS = "-c ${YUMCONF} --installroot ${IMAGE_ROOTFS}"
14 export YUM_ARCH_FORCE = "${TARGET_ARCH}"
16 AWKPOSTINSTSCRIPT = "${STAGING_BINDIR_NATIVE}/extract-postinst.awk"
18 RPM_PREPROCESS_COMMANDS = ""
19 RPM_POSTPROCESS_COMMANDS = "rpm_insert_feeds_uris"
21 rpm_insert_feeds_uris () {
23         echo "Building from feeds activated!"
25         mkdir -p ${IMAGE_ROOTFS}/etc/yum/repos.d/
26         for line in ${RPM_FEED_URIS}
27         do
28                 # strip leading and trailing spaces/tabs, then split into name and uri
29                 line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
30                 feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
31                 feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"
33                 echo "Added $feed_name feed with URL $feed_uri"
35                 FEED_FILE=${IMAGE_ROOTFS}/etc/yum/repos.d/$feed_name
37                 echo "[${DISTRO}-feed-$feed_name]" >> $FEED_FILE
38                 echo "name = $feed_name" >> $FEED_FILE
39                 echo "baseurl = $feed_uri" >> $FEED_FILE
40                 echo "gpgcheck = 0" >> $FEED_FILE
41         done
44 fakeroot rootfs_rpm_do_rootfs () {
45         set -x
47         ${RPM_PREPROCESS_COMMANDS}
49         mkdir -p ${IMAGE_ROOTFS}/etc/rpm/
50         echo "${TARGET_ARCH}-linux" >${IMAGE_ROOTFS}/etc/rpm/platform
52         # Generate an apprpriate yum.conf
53         rm -rf ${YUMCONF}
54         cat > ${YUMCONF} << EOF
55 [main]
56 cachedir=/var/cache2/yum
57 keepcache=1
58 debuglevel=10
59 logfile=/var/log2/yum.log
60 exactarch=0
61 obsoletes=1
62 tolerant=1
64 EOF
66         #priority=1
67         mkdir -p ${IMAGE_ROOTFS}${DEPLOY_DIR_RPM}
69         for arch in ${PACKAGE_ARCHS}; do
70                 if [ ! -d ${DEPLOY_DIR_RPM}/$arch ]; then
71                         continue;
72                 fi
73                 createrepo ${DEPLOY_DIR_RPM}/$arch
75                 echo "[${DISTRO}-feed-$arch]" >> ${YUMCONF}
76                 echo "name = ${DISTRO} RPM $arch Feed" >> ${YUMCONF}
77                 echo "baseurl=file://${DEPLOY_DIR_RPM}/$arch" >> ${YUMCONF}
78                 echo "gpgcheck=0" >> ${YUMCONF}
79                 echo "" >> ${YUMCONF}
80                 #priority=$(expr $priority + 5)
82                 # Copy the packages into the target image
83                 # Ugly ugly ugly but rpm is braindead and can't see outside the chroot
84                 # when installing :(
85                 cp -r ${DEPLOY_DIR_RPM}/$arch ${IMAGE_ROOTFS}${DEPLOY_DIR_RPM}/
86         done
88         # Uclibc builds don't provide this stuff...
89         if [ x${TARGET_OS} = "xlinux" ] || [ x${TARGET_OS} = "xlinux-gnueabi" ] ; then 
90                 if [ ! -z "${LINGUAS_INSTALL}" ]; then
91                         for i in ${LINGUAS_INSTALL}; do
92                                 fakechroot yum ${YUMARGS} -y install $i 
93                         done
94                 fi
95         fi
96         if [ ! -z "${PACKAGE_INSTALL}" ]; then
97                 fakechroot yum ${YUMARGS} -y install ${PACKAGE_INSTALL}
98         fi
100         # Add any recommended packages to the image
101         # (added as an extra script since yum itself doesn't support this)
102         yum-install-recommends.py ${IMAGE_ROOTFS} "fakechroot yum ${YUMARGS} -y install"
104         # Symlinks created under fakeroot are wrong, now we have to fix them...
105         cd ${IMAGE_ROOTFS}
106         for f in `find . -type l -print`
107         do
108                 link=`readlink $f | sed -e 's#${IMAGE_ROOTFS}##'`
109                 rm $f
110                 ln -s $link $f
111         done
113         export D=${IMAGE_ROOTFS}
114         export OFFLINE_ROOT=${IMAGE_ROOTFS}
115         export IPKG_OFFLINE_ROOT=${IMAGE_ROOTFS}
116         export OPKG_OFFLINE_ROOT=${IMAGE_ROOTFS}
118         ${ROOTFS_POSTINSTALL_COMMAND}
120         mkdir -p ${IMAGE_ROOTFS}/etc/rpm-postinsts/
121         rpm --root ${IMAGE_ROOTFS} -aq --queryformat 'Name: %{NAME}\n' --scripts > ${IMAGE_ROOTFS}/etc/rpm-postinsts/combined
122         awk -f ${AWKPOSTINSTSCRIPT} < ${IMAGE_ROOTFS}/etc/rpm-postinsts/combined
123         rm ${IMAGE_ROOTFS}/etc/rpm-postinsts/combined   
125         for i in ${IMAGE_ROOTFS}/etc/rpm-postinsts/*.sh; do
126                 if [ -f $i ] && sh $i; then
127                         # rm $i
128                         mv $i $i.done
129                 fi
130         done
132         install -d ${IMAGE_ROOTFS}/${sysconfdir}/rcS.d
133         # Stop $i getting expanded below...
134         i=\$i
135         cat > ${IMAGE_ROOTFS}${sysconfdir}/rcS.d/S98configure << EOF
136 #!/bin/sh
137 for i in /etc/rpm-postinsts/*.sh; do
138         echo "Running postinst $i..."
139         if [ -f $i ] && sh $i; then
140                 # rm $i
141                 mv $i $i.done
142         else
143                 echo "ERROR: postinst $i failed."
144         fi
145 done
146 rm -f ${sysconfdir}/rcS.d/S98configure
148         chmod 0755 ${IMAGE_ROOTFS}${sysconfdir}/rcS.d/S98configure
150         install -d ${IMAGE_ROOTFS}/${sysconfdir}
151         echo ${BUILDNAME} > ${IMAGE_ROOTFS}/${sysconfdir}/version
153         ${RPM_POSTPROCESS_COMMANDS}
154         ${ROOTFS_POSTPROCESS_COMMAND}
155         
156         rm -rf ${IMAGE_ROOTFS}/var/cache2/
157         rm -rf ${IMAGE_ROOTFS}/var/run2/
158         rm -rf ${IMAGE_ROOTFS}/var/log2/
159         rm -rf ${IMAGE_ROOTFS}${DEPLOY_DIR_RPM}/
161         # remove lock files
162         rm -f ${IMAGE_ROOTFS}/var/lib/rpm/__db.*
164         # remove no longer used yum.conf
165         rm -f ${IMAGE_ROOTFS}/etc/yum.conf
167         log_check rootfs
170 rootfs_rpm_log_check() {
171         target="$1"
172         lf_path="$2"
174         lf_txt="`cat $lf_path`"
175         for keyword_die in "Cannot find package" "exit 1" ERR Fail
176         do
177                 if (echo "$lf_txt" | grep -v log_check | grep "$keyword_die") >/dev/null 2>&1
178                 then
179                         echo "log_check: There were error messages in the logfile"
180                         echo -e "log_check: Matched keyword: [$keyword_die]\n"
181                         echo "$lf_txt" | grep -v log_check | grep -C 5 -i "$keyword_die"
182                         echo ""
183                         do_exit=1
184                 fi
185         done
186         test "$do_exit" = 1 && exit
187         true
190 remove_packaging_data_files() {
191 # empty for now
192         :
195 install_all_locales() {
196 # empty for now
197         :
200 python () {
201     import bb
202     if bb.data.getVar('BUILD_IMAGES_FROM_FEEDS', d, True):
203         flags = bb.data.getVarFlag('do_rootfs', 'recrdeptask', d)
204         flags = flags.replace("do_package_write_rpm", "")
205         flags = flags.replace("do_deploy", "")
206         flags = flags.replace("do_populate_staging", "")
207         bb.data.setVarFlag('do_rootfs', 'recrdeptask', flags, d)
208         bb.data.setVar('RPM_PREPROCESS_COMMANDS', "rpm_insert_feed_uris", d)
209         bb.data.setVar('RPM_POSTPROCESS_COMMANDS', '', d)