# -*-mic2-options-*- -A aarch64 -f loop --pack-to=@NAME@.tar.gz --record-pkgs=name,content,license -*-mic2-options-*-

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

lang C
keyboard us
timezone --utc America/Los_Angeles
part / --size=2048 --ondisk mmcblk0p --fstype=ext4 --label=rootfs --extoptions="-J size=16"
part /opt/ --size=512 --ondisk mmcblk0p --fstype=ext4 --label=system-data --extoptions="-m 0"
part /mnt/initrd --size=64 --ondisk mmcblk0p --fstype=cpio --label=ramdisk --cpiooptions="--format=newc"
part /mnt/initrd-recovery --size=128 --ondisk mmcblk0p --fstype=cpio --label=ramdisk-recovery --cpiooptions="--format=newc"


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=unified-standard --baseurl=http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Unified/@BUILD_ID@/repos/standard/packages/ --ssl_verify=no
repo --name=base-standard --baseurl=http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Base/latest/repos/standard/packages/ --ssl_verify=no


%packages

# @ IoT Headless Base
building-blocks-root-Preset_iot_core
# @ IoT Adaptation COMMON Headless
building-blocks-sub1-Preset_img_headless-common
# Others




%end



%post
#!/bin/sh
echo "#################### generic-adaptation.post ####################"

# fix TIVI-2291
sed -ri "s/(^blacklist i8042.*$)/#fix from base-general.post \1/" /etc/modprobe.d/blacklist.conf


#!/bin/sh
echo "#################### generic-base.post ####################"

test ! -e /opt/var && mkdir -p /opt/var
test -d /var && cp -arf /var/* /opt/var/
rm -rf /var
ln -snf opt/var /var

test ! -e /opt/usr/home && mkdir -p /opt/usr/home
test -d /home && cp -arf /home/* /opt/usr/home/
rm -rf /home
ln -snf opt/usr/home /home

build_ts=$(date -u +%s)
build_date_local=$(date -u --date @$build_ts +%Y%m%d_%H%M%S)
build_date=$(echo @BUILD_DATE@ | sed -r -e "s/@BUILD_DATE[@]/$build_date_local/g")
build_time=$(date -u --date @$build_ts +%H:%M:%S)

sed -ri \
	-e 's|@BUILD_ID[@]|@BUILD_ID@|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

# setup systemd default target for user session
cat <<'EOF' >>/usr/lib/systemd/user/default.target
[Unit]
Description=User session default target
EOF
mkdir -p /usr/lib/systemd/user/default.target.wants

# sdx: fix smack labels on /var/log
chsmack -a '*' /var/log

# create appfw dirs inside homes
function generic_base_user_exists() {
	user=$1
	getent passwd | grep -q ^${user}:
}

function generic_base_user_home() {
	user=$1
	getent passwd | grep ^${user}: | cut -f6 -d':'
}

function generic_base_fix_user_homedir() {
	user=$1
	generic_base_user_exists $user || return 1

	homedir=$(generic_base_user_home $user)
	mkdir -p $homedir/apps_rw
	for appdir in desktop manifest dbspace; do
		mkdir -p $homedir/.applications/$appdir
	done
	find $homedir -type d -exec chsmack -a User {} \;
	chown -R $user:users $homedir
	return 0
}

# fix TC-320 for SDK
. /etc/tizen-build.conf
[ "${TZ_BUILD_WITH_EMULATOR}" == "1" ] && generic_base_fix_user_homedir developer

# Add info.ini for system-info CAPI (TC-2047)
/etc/make_info_file.sh

#!/bin/sh
echo "#################### generic-users.post ####################"

if ! generic_base_user_exists owner; then
        # By default GUM will create users in /opt/etc/passwd, which is
        # additional users database suitable for end-user created accounts.
        # However, the 'owner' user is shipped by Tizen system itself and
        # it's its default user.  Consequently, it should always be available
        # and thus, it should be added to /etc/passwd.
        conf=/etc/gumd/gumd.conf
        origf=${conf}.orig
        mv -v $conf $origf
        sed -e 's,^\(PASSWD_FILE\).*,\1=/etc/passwd,' -e 's,^\(SHADOW_FILE\).*,\1=/etc/shadow,' <$origf >$conf
        gum-utils --offline --add-user --username=owner --usertype=admin --usecret=""
        mv -v $origf $conf
fi



#!/bin/sh

echo "############### iot-headless-base.post ################"

######### Execute pkg_initdb if there is no pkgmgr-tool pacakge
rpm -qa | grep pkgmgr-tool
if [ $? != 0 ]
then
pkg_initdb --ro
fi


#!/bin/sh
echo "#################### generic-wayland.post ####################"


#!/bin/sh
echo "#################### generic-middleware.post ####################"


#!/bin/sh
echo "#################### generic-applications.post ####################"


#!/bin/sh
echo "#################### generic-bluetooth.post ####################"


#!/bin/sh
echo "#################### generic-multimedia.post ####################"


#!/bin/sh
echo "#################### generic-desktop-applications.post ####################"

# depends on generic-base functions
function generic_desktop_applications_fix_userhome() {
	user=$1

	generic_base_user_exists $user || return 1
	homedir=$(generic_base_user_home $user)

	echo "Fix app_info.db of $user"
	chown -R $user:users $homedir/.applications/dbspace/
}

# fix TC-320 for SDK
. /etc/tizen-build.conf
# Disable to run below line because this results in always failure, so it can be regarded as useless.
#[ "${TZ_BUILD_WITH_EMULATOR}" == "1" ] && generic_desktop_applications_fix_userhome developer


#!/bin/sh
echo "#################### generic-crosswalk.post ####################"


#!/bin/sh
echo "############### common-crosswalk.post ################"

# start wrt widgets preinstall
rpm -qa | grep wrt-widget
if [ $? = 0 ]
then
prepare_widgets.sh
fi


#!/bin/sh
echo "############### common-license.post ################"

LICENSE_BASE=/usr/share

LICENSE_DIR=$LICENSE_BASE/licenses
LICENSE_FILE=$LICENSE_BASE/license.html
MD5_TEMP_FILE=$LICENSE_BASE/temp_license_md5

if [[ -f $LICENSE_FILE ]]; then
        rm -f $LICENSE_FILE
fi


if [[ -f $MD5_TEMP_FILE ]]; then
        rm -f $MD5_TEMP_FILE
fi


cd $LICENSE_DIR
LICENSE_LIST=`ls */*`

for INPUT in $LICENSE_LIST; do
        if [[ -f $INPUT ]]; then
                PKG_NAME=`echo $INPUT|cut -d'/' -f1`
                echo `md5sum $INPUT` $PKG_NAME >> $MD5_TEMP_FILE
        fi
done

MD5_LIST=`cat $MD5_TEMP_FILE|awk '{print $1}'|sort -u`

echo "<html>" >> $LICENSE_FILE
echo "<head>" >> $LICENSE_FILE
echo "<meta name=\"viewport\" content=\"initial-scale=1.0\">" >> $LICENSE_FILE
echo "</head>" >> $LICENSE_FILE
echo "<body>" >> $LICENSE_FILE
echo "<font size=6>" >> $LICENSE_FILE
echo "<xmp>" >> $LICENSE_FILE

for INPUT in $MD5_LIST; do
        PKG_LIST=`cat $MD5_TEMP_FILE|grep $INPUT|awk '{print $3}'`
        FILE_LIST=`cat $MD5_TEMP_FILE|grep $INPUT|awk '{print $2}'`
        PKG_FILE=`echo $FILE_LIST |awk '{print $1}'`

        echo "$PKG_LIST :" >> $LICENSE_FILE
        cat $PKG_FILE >> $LICENSE_FILE
        echo  >> $LICENSE_FILE
        echo  >> $LICENSE_FILE
        echo  >> $LICENSE_FILE
done

echo "</xmp>" >> $LICENSE_FILE
echo "</font>" >> $LICENSE_FILE
echo "</body>" >> $LICENSE_FILE
echo "</html>" >> $LICENSE_FILE

rm -rf $LICENSE_DIR/* $MD5_TEMP_FILE

#!/bin/sh
echo "#################### generic-dbus-policychecker.post ####################"
if [ -x /usr/bin/dbuspolicy-checker ] ; then
	fail_cnt=0
	for f in /etc/dbus-1/system.d/*.conf /usr/share/dbus-1/system.d/*.conf; do
		echo
		echo "$0: Checking D-Bus policy file: $f"
		result=$(/usr/bin/dbuspolicy-checker "$f")
		fail=$(echo "$result" | grep FAILED | wc -l)
		echo "$result"
		if [ $fail -gt 0 ]; then
			echo "Found $fail Fails"
			echo "Remove conf file : mv $f $f.fail"
			mv "$f" "${f}.fail"
			fail_cnt=$(( ${fail_cnt} + 1 ))
		fi
	done
	if [ $fail_cnt -gt 0 ]; then
		echo "Error: MIC build exits due to failed cases on dbus policy checker.(${fail_cnt} errors)"
		exit 1
	fi

fi

#!/bin/sh
echo "#################### generic-security.post ####################"

if [ -e /usr/share/security-config/set_capability ]; then
	echo 'Give capabilities to daemons via set_capability from security-config package'
	/usr/share/security-config/set_capability
fi
if [ -e /opt/share/security-config/test/image_test.sh ]; then
	echo 'Run security-test'
	/opt/share/security-config/test/image_test.sh
fi

# 04-15-2019 : This is to create security-manager DB backup file.
security-manager-cmd -b
 

#!/bin/sh

echo "############### iot-making-ABB-tag.post ################"

if [ -f  /opt/share/bb/make_ABB_tag.sh ]
then
    /opt/share/bb/make_ABB_tag.sh /opt/share/bb/mapping-bb-rs.xml > /etc/config/tizen_abb_tag.cfg
else
    echo "There is no script file - /opt/share/bb/make_ABB_bb.sh"
fi


#!/bin/sh

echo "############### iot-making-building-blocks-dll.post ################"

export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
export MIC_CROSSGEN2_ENABLED=1

DOTNET_MIC_DIR=/opt/usr/dotnet/mic

if [ -f  /opt/share/bb/make_tizenfx_from_bb.sh ]
then
	/opt/share/bb/make_tizenfx_from_bb.sh
	if [ -f /usr/bin/dotnettool ]
	then
		# remove previous native image
		dotnettool --ni-reset-system

		chmod 755 /usr/bin/patchelf
		chmod 755 $DOTNET_MIC_DIR/*

		# set the patchelf
		/usr/bin/patchelf --set-interpreter $DOTNET_MIC_DIR/ld-linux-x86-64.so.2 $DOTNET_MIC_DIR/crossgen2
		/usr/bin/patchelf --set-rpath $DOTNET_MIC_DIR $DOTNET_MIC_DIR/crossgen2

		for file in $( find $DOTNET_MIC_DIR -type f \( -name "*.so" -or -name "*.so.*" \) -not -name "*.dbg" -not -name "ld-*.so*" )
		do
		    /usr/bin/patchelf --set-rpath $DOTNET_MIC_DIR ${file}
		done

		# generate native image for system
		dotnettool --ni-system --inputbubble --print-cmd

		# generate native image for all app
		dotnettool --ni-regen-all-app --print-cmd
		dotnettool --tac-regen-all --print-cmd
	else
		echo "There is no execute file - /usr/bin/dotnettool"
	fi
else
	echo "There is no script file - /opt/share/bb/make_tizenfx_from_bb.sh"
fi

# remove files and package related to dotnet used only in MIC
rm -rf $DOTNET_MIC_DIR
rpm -e patchelf --nodeps
rpm -e crossgen2-mic --nodeps

#!/bin/sh
echo "############### common-cleanup-directory.post ################"

# remove manuals, docs and headers
rm -rf /usr/include
rm -rf /usr/share/man
rm -rf /usr/share/doc

# remove libzypp history
rm -rf /var/log/zypp

#!/bin/sh

echo "#################### common-hal-directory-check.post ####################"
if [ -d /hal ]; then
	VALUE=`/usr/bin/ls -R /hal | /usr/bin/grep -v "hal\:"`
	if [ "$VALUE" ]; then
		echo "WARNING!! There are some files to install to wrong path (/hal)"
		echo "WARNING!! It has to be nothing under hal directory."
		FILES=`/usr/bin/ls -R /hal`
		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
####################### buildname.nochroot #######################
if [ -n "$IMG_NAME" ]; then
	echo "BUILD_ID=$IMG_NAME" >> $INSTALL_ROOT/etc/tizen-release
	echo "BUILD_ID=$IMG_NAME" >> $INSTALL_ROOT/etc/os-release
	echo "$IMG_NAME @BUILD_ID@" >>$INSTALL_ROOT/etc/tizen-snapshot
fi

echo "############### backup-data.nochroot ################"

date +'[%m/%d %H:%M:%S %Z] backup-data.nochroot nochroot post script - start'

if [ -e $INSTALL_ROOT/usr/bin/build-backup-data.sh ]; then
    $INSTALL_ROOT/usr/bin/build-backup-data.sh
fi

date +'[%m/%d %H:%M:%S %Z] backup-data.nochroot nochroot post script - end'


%end




