# -*-mic2-options-*- -f raw --fstab=uuid --copy-kernel --compress-disk-image=bz2 --generate-bmap -*-mic2-options-*-

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

lang en_US.utf8
keyboard us
timezone --utc America/Los_Angeles
part /boot --size 64 --ondisk sdb --fstype=ext4 --label boot --active --align 1024 --fsoptions=noatime
part / --size 3748 --ondisk sdb --fstype=ext4 --label platform --align 1024 --fsoptions=noatime

rootpw tizen 
xconfig --startxonboot
bootloader  --timeout=0  --append="rootwait rootfstype=ext4 quiet"   --ptable=gpt

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

installerfw_plugins "bootloader,fstab"

repo --name=ivi --baseurl=https://download.tizen.org/snapshots/tizen/ivi-3.0.m14.2/@BUILD_ID@/repos/atom/packages/ 

%packages

@Base System
@IVI Adaptation
@IVI Packaging
@IVI Middleware
@Wayland
@IVI UX Weston
@Console Tools
@IVI Applications

kernel-x86-ivi

ivi-repos
setup-extlinux
setup-ivi-clone
%end



%post
# base-general.post

ln -sf /proc/self/mounts /etc/mtab

rm -rf /root/.zypp

# workaround for bug PTREL-763
patch -p1 -d/ <<'EOF'
diff -urN bad/etc/pam.d/systemd-user good/etc/pam.d/systemd-user
--- bad/etc/pam.d/systemd-user 2014-03-20 10:01:36.657843073 +0100
+++ good/etc/pam.d/systemd-user 2014-03-20 10:06:51.586121696 +0100
@@ -4,5 +4,6 @@
 
 account include system-auth
 session include system-auth
+session required pam_systemd.so
 auth required pam_deny.so
 password required pam_deny.so
EOF

# create appfw dirs inside homes
for user in app; do
	for appdir in desktop manifest dbspace; do
		mkdir -p /home/$user/.applications/$appdir
	done
	find /home/$user/ -type d -exec chsmack -a User {} \;
	chown -R $user:users /home/$user/
done

#Hack to temporarily disable net-config, which collides with settingsd. Related to TIVI-2569

rm /usr/lib/systemd/system/multi-user.target.wants/net-config.service 

# rpm.post
rm -f /var/lib/rpm/__db*
rpmdb --rebuilddb

# Initialize the native application database
pkg_initdb

# adjust app group: main group 'users', extra group 'app', 'weston-launch'
/usr/sbin/usermod -g users app
/usr/sbin/usermod -G app,weston-launch app

# Enable a logind session for 'app' user on seat0 (the default seat for
# graphical sessions)
mkdir -p /usr/lib/systemd/system/graphical.target.wants
ln -s ../user-session-launch@.service /usr/lib/systemd/system/graphical.target.wants/user-session-launch@seat0-5000.service
ln -sf weston.target  /usr/lib/systemd/user/default.target

# Add over-riding environment to enable the web runtime to
# run on an IVI image as a different user then the tizen user
# Some notes on some of the variables:
#  - ELM_THEME is needed in order for the wrt to have visible content
#  - WRT_PROCESS_POOL_DISABLE is a work around for TIVI-2062
cat > /etc/sysconfig/wrt <<EOF
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/5000/dbus/user_bus_socket
XDG_RUNTIME_DIR=/run/user/5000
ELM_ENGINE=wayland_egl
ECORE_EVAS_ENGINE=wayland_egl
ELM_THEME=tizen-HD-light
WRT_PROCESS_POOL_DISABLE=1
EOF

# Use the same over-rides for the native prelaunch daemon
cp /etc/sysconfig/wrt /etc/sysconfig/launchpad

# Add a rule to ensure the app user has permissions to
# open the graphics device
cat > /etc/udev/rules.d/99-dri.rules <<EOF
SUBSYSTEM=="drm", MODE="0666"
EOF

############### desktop-applications.post ################

# temp workaround to fill each user app_info database with global db infos
. /etc/tizen-platform.conf
ail_initdb
pkg_initdb

echo "Fixing multiuser app_info dbs"
chsmack -a "_" $TZ_SYS_DB/.app_info.db*
chmod 764 $TZ_SYS_DB/.app_info.db*

for user in app; do
	[ ! -d /home/$user ] && continue
	echo "Fix app_info.db of $user"

	if [ -f /home/$user/.applications/dbspace/.app_info.db ]; then
		sqlite3 /home/$user/.applications/dbspace/.app_info.db <<EOF
attach database '$TZ_SYS_DB/.app_info.db' as common;
insert into app_info select * from common.app_info;
EOF
	else
		cp $TZ_SYS_DB/.app_info.db /home/$user/.applications/dbspace/.app_info.db
	fi

	chown -R $user:users /home/$user/.applications/dbspace/
	chsmack -a User /home/$user/.applications/dbspace/.app_info.db*
done

# Install and configure the boot-loader, /etc/fstab, and so on
/usr/sbin/setup-ivi-boot


# Migrate /etc/sysconfig/i18n until MIC is fixed to handle locale.conf
#
if [ -e /etc/sysconfig/i18n -a ! -e /etc/locale.conf ]; then
        unset LANG
        unset LC_CTYPE
        unset LC_NUMERIC
        unset LC_TIME
        unset LC_COLLATE
        unset LC_MONETARY
        unset LC_MESSAGES
        unset LC_PAPER
        unset LC_NAME
        unset LC_ADDRESS
        unset LC_TELEPHONE
        unset LC_MEASUREMENT
        unset LC_IDENTIFICATION
        . /etc/sysconfig/i18n >/dev/null 2>&1 || :
        [ -n "$LANG" ] && echo LANG=$LANG > /etc/locale.conf 2>&1 || :
        [ -n "$LC_CTYPE" ] && echo LC_CTYPE=$LC_CTYPE >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_NUMERIC" ] && echo LC_NUMERIC=$LC_NUMERIC >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_TIME" ] && echo LC_TIME=$LC_TIME >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_COLLATE" ] && echo LC_COLLATE=$LC_COLLATE >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_MONETARY" ] && echo LC_MONETARY=$LC_MONETARY >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_MESSAGES" ] && echo LC_MESSAGES=$LC_MESSAGES >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_PAPER" ] && echo LC_PAPER=$LC_PAPER >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_NAME" ] && echo LC_NAME=$LC_NAME >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_ADDRESS" ] && echo LC_ADDRESS=$LC_ADDRESS >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_TELEPHONE" ] && echo LC_TELEPHONE=$LC_TELEPHONE >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_MEASUREMENT" ] && echo LC_MEASUREMENT=$LC_MEASUREMENT >> /etc/locale.conf 2>&1 || :
        [ -n "$LC_IDENTIFICATION" ] && echo LC_IDENTIFICATION=$LC_IDENTIFICATION >> /etc/locale.conf 2>&1 || :
fi
rm -f /etc/sysconfig/i18n >/dev/null 2>&1 || :

chsmack -a System::Shared /etc/locale.conf


%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
fi


%end
