Source6: haltest.target
Source7: reboot-haltest
Source8: reboot-normal
-Source9: hal-rpmdb-checker.service
-Source10: hal-rpmdb-checker
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%prep
%setup -q
-%define hal_rpmdb_checker_path /opt/etc/hal
-
cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DCMAKE_LIBDIR_PREFIX=%{_libdir} \
-DENABLE_DLOG=1
%make_install
mkdir -p %{buildroot}/hal
-mkdir -p %{buildroot}%{hal_rpmdb_checker_path}
install -D -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/ld.so.conf.d/libhal-api.conf
install -D -m 0755 %{SOURCE3} %{buildroot}%{_systemdgeneratordir}/systemd-hal-firmware-generator
install -D -m 0755 %{SOURCE4} %{buildroot}%{_systemdgeneratordir}/systemd-hal-compatibility-checker-generator
install -D -m 0644 %{SOURCE6} %{buildroot}%{_unitdir}/haltest.target
install -D -m 0755 %{SOURCE7} %{buildroot}%{_bindir}/reboot-haltest
install -D -m 0755 %{SOURCE8} %{buildroot}%{_bindir}/reboot-normal
-install -D -m 0644 %{SOURCE9} %{buildroot}%{_unitdir}/hal-rpmdb-checker.service
-install -D -m 0755 %{SOURCE10} %{buildroot}%{_bindir}/hal-rpmdb-checker
-
-%install_service sysinit.target.wants hal-rpmdb-checker.service
%clean
rm -rf %{buildroot}
%post -n %{test_name}
/sbin/ldconfig
-chsmack -a "System" -t %{hal_rpmdb_checker_path}
-systemd-tmpfiles /usr/lib/tmpfiles.d/hal-rpmdb-checker.conf --create
%postun
/sbin/ldconfig
%{_sysconfdir}/rpm/macros.hal-api
%files -n %{test_name}
-%dir %{hal_rpmdb_checker_path}
-%attr(0755,system_fw,system_fw) %{hal_rpmdb_checker_path}
%{_unitdir}/haltest.target
%{_bindir}/reboot-haltest
%{_bindir}/reboot-normal
-%{_unitdir}/sysinit.target.wants/hal-rpmdb-checker.service
-%{_unitdir}/hal-rpmdb-checker.service
-%{_bindir}/hal-rpmdb-checker
-/usr/lib/tmpfiles.d/hal-rpmdb-checker.conf
+++ /dev/null
-#!/bin/bash
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-### Define constant variables
-UNKNOWN="UNKNOWN"
-ROOT_OWNER="root"
-
-HAL_RPMDB_DIR_PATH='/hal/lib/rpm'
-HAL_RPMDB_ETC_DIR_PATH='/hal/etc/rpm'
-HAL_RPMDB_FILE_PATH='/hal/etc/hal-rpmdb.ini'
-HAL_IMG_INFO_FILE_PATH='/hal/etc/hal-info.ini'
-
-FIRST_BOOTING_FILE_PATH="/opt/etc/hal/.first-booting"
-HAL_IMG_VERSION_FILE_PATH="/opt/etc/hal/.hal-img-version.ini"
-
-### Define variables
-first_booting=0
-hal_img=0
-hal_rpmdb_match=1
-hal_img_version=$UNKNOWN
-cur_hal_img_version=$UNKNOWN
-owner=$UNKNOWN
-
-### Define functions
-
-backup_core_rpmdb() {
- if [ "$hal_img" -eq 0 ]; then
- return
- elif [ "$owner" != "$ROOT_OWNER" ]; then
- return
- elif [ "$first_booting" -eq 0 ]; then
- return
- fi
-
- if ! [ -e /opt/etc/hal/Packages.origin ] ; then
- cp /var/lib/rpm/Packages /opt/etc/hal/Packages.origin
- echo "HAL_RPMDB: Backup Core RPMDB"
- fi
-}
-
-import_hal_rpmdb_to_core_rpmdb() {
- if [ "$hal_img" -eq 0 ]; then
- return
- elif [ "$hal_rpmdb_match" -eq 0 ]; then
- return
- elif [ "$owner" != "$ROOT_OWNER" ]; then
- return
- fi
-
- # Restore core-rpmdb from core-rpmdb backup
- if [ -e /opt/etc/hal/Packages.origin ] ; then
- rm -rf /var/lib/rpm/Packages
- cp /opt/etc/hal/Packages.origin /var/lib/rpm/Packages
- echo "HAL_RPMDB: Restore Core RPMDB"
- fi
-
- # Import hal-rpmdb into core-rpmdb
- if [ -e "$HAL_RPMDB_FILE_PATH" ] ; then
- /usr/bin/rpmdb --importdb < $HAL_RPMDB_FILE_PATH
- echo "HAL_RPMDB: Import hal-rpdmb into core-rpmdb"
- else
- echo "HAL_RPMDB: Failed to find $HAL_RPMDB_FILE_PATH"
- fi
-}
-
-init() {
- first_booting=0
- hal_img=0
- owner=`whoami`
- local_hal_part=`/usr/bin/lsblk | grep hal`
-
- if [ "$local_hal_part" == "" ]; then
- echo "HAL_RPMDB: It doesnt' contain both /hal partition and hal.img"
- exit 0
- elif ! [ -e "$HAL_RPMDB_DIR_PATH" ] ; then
- echo "HAL_RPMDB: Failed to find $HAL_RPMDB_DIR_PATH path"
- exit 0
- elif ! [ -e "$HAL_RPMDB_ETC_DIR_PATH" ] ; then
- echo "HAL_RPMDB: Failed to find $HAL_RPMDB_ETC_DIR_PATH path"
- exit 0
- elif ! [ -e "$HAL_IMG_INFO_FILE_PATH" ] ; then
- echo "HAL_RPMDB: Failed to find $HAL_IMG_INFO_FILE_PATH"
- exit 0
- else
- if ! [ -e /opt/etc/hal/.first-booting ] ; then
- /usr/bin/echo "0" > $FIRST_BOOTING_FILE_PATH
- first_booting=1
- fi
-
- hal_img=1
-
- backup_core_rpmdb
- fi
-}
-
-get_hal_img_version() {
- if [ "$hal_img" -eq 0 ]; then
- return
- fi
-
- # Get hal_img_version from /hal/etc/hal-info.ini
- tmp=`cat $HAL_IMG_INFO_FILE_PATH | grep Build=`
- hal_img_version=`echo ${tmp:6}`
-
- # Get current hal_img_version from $HAL_IMG_VERSION_FILE_PATH
-
- if ! [ -e "$HAL_IMG_VERSION_FILE_PATH" ] ; then
- cur_hal_img_version="$HAL_IMG_VERSION_UNKNOWN"
- else
- cur_hal_img_version=`cat $HAL_IMG_VERSION_FILE_PATH`
- fi
-
- echo "HAL_RPMDB: hal.img version ($hal_img_version) of /hal/etc/hal-info.ini"
- echo "HAL_RPMDB: hal.img version ($cur_hal_img_version) of $HAL_IMG_VERSION_FILE_PATH"
-}
-
-check_hal_rpmdb() {
- if [ "$hal_img" -eq 0 ]; then
- return
- fi
-
- echo "HAL_RPMDB: Start hal-rpmdb dependency check ... "
-
- hal_rpmdb_match=1
- HAL_BACKEND_PKGS=`/usr/bin/ls $HAL_RPMDB_ETC_DIR_PATH`
- for hal_backend_pkg in ${HAL_BACKEND_PKGS}; do
- while read line; do
- IS_INSTALLED_IN_RPM=`/usr/bin/rpm -q $line`
-
- if [[ $IS_INSTALLED_IN_RPM != $line ]]; then
- IS_INSTALLED_IN_HAL_RPM=`/usr/bin/rpm --dbpath=$HAL_RPMDB_DIR_PATH -q $line`
-
- if [[ $IS_INSTALLED_IN_HAL_RPM != $line ]]; then
- echo "HAL_RPMDB: WARNING!!! $line is not installed for $hal_backend_pkg"
- hal_rpmdb_match=0
- fi
- fi
- done < $HAL_RPMDB_ETC_DIR_PATH/$hal_backend_pkg
- done
-
- if [ "$hal_rpmdb_match" -eq 1 ]; then
- # Update hal.img version when version matched
- /usr/bin/echo "$hal_img_version" > $HAL_IMG_VERSION_FILE_PATH
-
- echo "HAL_RPMDB: Finish hal-rpmdb dependency check (Version Matched) "
- else
- # Remove hal.img version file when version mismatched
- if [ -e "$HAL_IMG_VERSION_FILE_PATH" ] ; then
- rm -rf $HAL_IMG_VERSION_FILE_PATH
- fi
-
- echo "HAL_RPMDB: Finish hal-rpmdb dependency check (Version Mismatched) "
- exit 0
- fi
-}
-
-main() {
- # Check whether h/w device is using hal.img or not
- init
- # Get hal.img version info
- get_hal_img_version
-
- if [ "$cur_hal_img_version" == "$hal_img_version" ] ; then
- # Have finished the version check of hal rpmdb
- # and imported hal rpmdb into core rpmdb.
- echo "HAL_RPMDB: Already Version Matched!"
- return
- elif [ "$cur_hal_img_version" == "$HAL_IMG_VERSION_UNKNOWN" ] ; then
- # In case of among,
- # - first booting or
- # - core.img is only updated or
- # - hal.img was only updated but, version mismatched
- check_hal_rpmdb
- else
- # In case of hal.img is only updated, must need to restore
- # the core rpmdb and then execute check_hal_rpmdb
- echo "HAL_RPMDB: hal.img is only updated!"
- check_hal_rpmdb
-
- # Import hal-rpmdb (/hal/lib/rpm) into core-rpmdb (/var/lib/rpm)
- import_hal_rpmdb_to_core_rpmdb
- fi
-}
-
-### Execute main function
-main