# -*-mic2-options-*- -A aarch64 -f loop --pack-to=@NAME@.tar.gz -*-mic2-options-*-

# 
# Do not Edit! Generated by:
# kickstarter.py
# 

lang en_US.UTF-8
keyboard us
timezone --utc America/Los_Angeles
part /boot --fstype="vfat" --size=128 --ondisk=mmcblk0 --active --label boot --fsoptions=defaults,noatime
part /lib/modules --fstype="ext4" --size=100 --ondisk=mmcblk0 --active --label modules --fsoptions=defaults,noatime
part /hal --fstype="ext4" --size=64 --ondisk=mmcblk0 --active --label hal --fsoptions=defaults,noatime


rootpw tizen 
xconfig --startxonboot
bootloader  --timeout=3  --append="rw vga=current splash rootwait rootfstype=ext4"   --ptable=gpt --menus="install:Wipe and Install:systemd.unit=system-installer.service:test"

desktop --autologinuser=guest  
user --name guest  --groups audio,video --password 'tizen'


repo --name=gbs_repo --baseurl=http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Unified/tizen-unified_20260429.102925/repos/standard/packages/ --ssl_verify=no --priority=1
repo --name=gbs_base_repo_0 --baseurl=http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Base/tizen-base_20260420.100502/repos/standard/packages/ --ssl_verify=no --priority=99


%packages

# @ IoT Boot VIM3
linux-kernel-amlogic-kvim
linux-kernel-modules-amlogic-kvim
linux-tizen-modules-amlogic-kvim
u-boot-vim3
u-boot-vim3l
# @ IoT Hal Base
capi-system-info
coreutils
gawk
grep
lscm
package-groups
rpm
sed
tizen-release
xmlstarlet
# @ IoT Hal Backend VIM3
building-blocks-sub1-Preset_boards-VIM3_HAL_Backend
# Others




%end


%attachment
/var/tmp/u-boot-amlogic/u-boot-vim3.bin
/var/tmp/u-boot-amlogic/u-boot-vim3l.bin
%end

%post
#!/bin/sh
echo "############### iot-hal-backend.post ################"

if [ -d /hal ]; then
	echo "Initialize rpmdb for HaL Backend"
	mkdir -p /hal/lib/rpm
	cp /var/lib/rpm/Packages /hal/lib/rpm/
	rpm --rebuilddb --dbpath=/hal/lib/rpm
fi

check_building_block() {
	PKG=`/usr/bin/rpm -qR $1 | /usr/bin/uniq | /bin/grep -v "^rpmlib" | /bin/grep -v ".\+\.so\..\+" | /bin/grep -v "^\/" | /bin/grep -v "=" | /bin/grep -v "(.\+)"`
	for pkgs in ${PKG}; do
		INSTALLED=`/usr/bin/rpm -q $pkgs`
		RET=$?
		if [[ $pkgs =~ "building-blocks" ]]; then
			check_building_block $pkgs
		elif [ $RET -eq 0 ]; then
			FILE_PATH=`/usr/bin/rpm -ql $INSTALLED | /bin/grep -v "^\/hal\/"`
			if [ "$FILE_PATH" ]; then
				echo "WARNING!!! $INSTALLED packages was installed to wrong path"
				for wrong_path in $FILE_PATH; do
					echo $wrong_path
				done
			fi
			echo -e $INSTALLED >> /hal/list/hal-backend-list.ini
		fi
	done
}


#FIXME: Need to check how to parse specific package
BACKEND_PACKAGE=("hal-backend-device-common");

create_backend_dependency_file() {
	echo "Creating Backend Dependency List"

	PKG=`/usr/bin/rpm -qa`
	/usr/bin/mkdir -p /hal/temp

	for packages in ${PKG}; do
		/usr/bin/rpm -qP $packages > /hal/temp/${packages}
	done

	for lists in ${BACKEND_PACKAGE[@]}; do
		/usr/bin/grep -lr $lists /hal/temp/ | /bin/sed "s/\/hal\/temp\\///" >> /hal/list/hal-backend-list.ini
	done

	for packages in ${PKG}; do
		FOUND=0
		while read line; do
			if [ $line == $packages ]; then
				FOUND=1
				break
			fi
		done < /hal/list/hal-backend-list.ini

		if [ $FOUND -eq 0 ]; then
			/usr/bin/rpm -e --justdb $packages --nodeps --noscripts --dbpath=/hal/lib/rpm
		fi
	done

	/usr/bin/rm -rf /hal/temp
	/usr/bin/rm -rf /hal/list
	/usr/bin/rm -rf /hal/etc/rpm/hal-backend-list.ini
	echo "Finished to Create Backend Dependency List"
}

#Supported Target's list
TARGET=("RPI4" "VIM3" "C4" "GENERIC" "VISIONFIVE2" "BPIF3" "LPI4A" "RUBIKPI3" "ORINNANO");

PKGGROUP=`/usr/bin/rpm -qa | /bin/grep package-groups`
if [ $PKGGROUP ]; then
	for target in ${TARGET[@]}; do
		RET=`/usr/bin/rpm -qa | /usr/bin/grep $target`
		RET=$?
		if [ $RET -eq 0 ]; then
			break;
		fi
	done

	case $target in
	RPI4)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend RPI4"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	VIM3)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend VIM3"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	C4)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend C4"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	GENERIC)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend GENERIC"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	VISIONFIVE2)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend VISIONFIVE2"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	BPIF3)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend BPIF3"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	LPI4A)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend LPI4A"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	RUBIKPI3)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend RUBIKPI3"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	ORINNANO)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend ORINNANO"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	esac

	/usr/bin/mkdir -p /hal/list/

	#Get HAL Backend Package List#
	PKG=`/usr/bin/rpm -q $BACKEND`
	echo "Create Hal Backend Packages List"
	for packages in ${PKG}; do
		check_building_block $packages
	done

	create_backend_dependency_file

	#Create exportdb file to update a rpmdb of core image
	/usr/bin/rpmdb --dbpath=/hal/lib/rpm --exportdb > /hal/etc/hal-rpmdb.ini
fi

build_ts=$(/bin/date -u +%s)
build_date=$(/bin/date -u --date @$build_ts +%Y%m%d_%H%M%S)
build_time=$(/bin/date -u --date @$build_ts +%H:%M:%S)

/bin/sed -ri \
	-e 's|@BUILD_ID[@]|tizen-unified_20260429.102925|g' \
	-e "s|@BUILD_DATE[@]|$build_date|g" \
	-e "s|@BUILD_TIME[@]|$build_time|g" \
	-e "s|@BUILD_TS[@]|$build_ts|g" \
	/etc/tizen-build.conf

/etc/make_info_file.sh hal

#Generate hal ld.so.cache file
/bin/cat <<EOF > /tmp/dlconf.txt
/hal/lib
/hal/lib64
EOF

ldconfig_result=$(/usr/sbin/ldconfig -I -C /hal/etc/ld.so.cache -f /tmp/dlconf.txt 2>&1)
if [ $? != 0 ]; then
	if [[ "$ldconfig_result" == *"invalid option -- 'I'"* ]]; then
		echo "/hal/etc/ld.so.cache will not be generated - glibc was compiled without dlconf support"
	else
		echo "$ldconfig_result"
	fi
fi

# Generate Platform Extension related cache files
lscm_arch=$(uname -m)

if [ -d /hal/etc/platform-extension ]; then
	for lscm_list_file in /hal/etc/platform-extension/*.list; do
		if [ -f "${lscm_list_file}" ]; then
			# Get the base name of the list file
			lscm_base_name=${lscm_list_file##*/}
			lscm_base_name=${lscm_base_name%.list}
			lscm_cache_file="/hal/etc/${lscm_base_name}.cache"

			if ld_so_cache_maker -i --arch="${lscm_arch}" --output="${lscm_cache_file}" --config="${lscm_list_file}" >/dev/null 2>&1; then
				echo "Successfully created cache file: ${lscm_cache_file}"
			else
				echo "Failed to create cache file for: ${lscm_list_file}"
			fi
		fi
	done
fi

#!/bin/sh

echo "#################### common-hal-rule-directory-check.post ####################"
if [ -d /hal/lib64/udev/rules.d ]; then
	VALUE=`/usr/bin/ls -R /hal/lib64/udev/rules.d | /usr/bin/grep -v "hal\/\lib64\/udev\/rules.d\:"`
	if [ "$VALUE" ]; then
		echo "WARNING!! There are some files to install to wrong path (/hal/lib64/udev/rules.d)"
		echo "WARNING!! It has to be located under /hal/lib/ directory, not /hal/lib64/."
		FILES=`/usr/bin/ls -R /hal/lib64/udev/rules.d`
		for file in $FILES; do
			if [[ $file =~ ":" ]]; then
				echo $file
				DIR=`echo $file | /usr/bin/awk -F ":" '{print $1}'`
			fi
			if [ -f $DIR/$file ]; then
				echo $file
			fi
		done
	fi
fi


%end

%post --nochroot

%end





