# -*-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=vfat --label boot --active --align 1024 --part-type C12A7328-F81F-11D2-BA4B-00A0C93EC93B
part / --size 3500 --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=guest  
user --name guest  --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.3/@BUILD_ID@/repos/atom/packages/ 

%packages

@IVI Adaptation
@Generic Base
@IVI Base
@Generic Packaging
@Generic Middleware
@Generic Wayland
@Generic Crosswalk
@Generic Multimedia
@Generic Multimedia Intel
@Generic Bluetooth
@Generic Console Tools
@Generic Desktop Applications
@IVI UX Weston
@IVI Middleware
@IVI Middleware Intel
@IVI Applications
@Generic Setup Boot

kernel-profile-ivi

ivi-repos
%end



%post
#!/bin/sh
echo "#################### ivi-adaptations.post ####################"

#replace "Tizen Next" with real release number.
sed -i 's/(\(.*\))/(@BUILD_ID@)/' /etc/os-release

# create user 'app' and group 'app', dropped from platfrom/upstream/setup
groupadd -g 5000 app 
useradd -c "System based user" -d /home/app -g users -G app -m -u 5000 -s /bin/sh app

# adjust TZ_SYS_DEFAULT_USER to 'app'
sed -ri 's|^(TZ_SYS_DEFAULT_USER=).*$|\1app|' /etc/tizen-platform.conf


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

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

# start dbus session
ln -s ../dbus.service /lib/systemd/user/default.target.wants/

# Run prelink to speed up dynamic binary/library loading
/usr/sbin/prelink --all

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

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

# workaround for bug PTREL-763
patch -b -p1 -d/ <<'EOF'
--- 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
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

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

# create appfw dirs for users 'app' and 'guest'
for user in app guest; do
	generic_base_fix_user_homedir $user
done


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

rm -rf /root/.zypp

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


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


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


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


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


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


#!/bin/sh
echo "#################### generic-console-tools.post ####################"

# customize bash prompt
cat >/etc/profile.d/bash_prompt_custom.sh <<'EOF'
if [ "$PS1" ]; then

	function proml {
		# set a fancy prompt (overwrite the one in /etc/profile)
		local default="\[\e[0m\]"
		local usercol='\[\e[1;34m\]' # blue
		local hostcol='\[\e[1;32m\]' # green
		local pathcol='\[\e[1;33m\]' # yellow
		local gitcol='\[\e[1;31m\]' # light red
		local termcmd=''
		local _p="$";

		if [ "`id -u`" -eq 0 ]; then
			usercol='\[\e[1;31m\]'
			_p="#"
		fi

		PS1="${usercol}\u${default}@${hostcol}\h${default}:${pathcol}\w${default}${gitcol}${default}${_p} ${termcmd}"
	}

	proml

	function rcd () {
      [ "${1:0:1}" == "/" ] && { cd $1; } || { cd $(pwd -P)/$1; }
   }

	alias ll="ls -lZ"
	alias lr="ls -ltrZ"
	alias la="ls -alZ"

	function get_manifest () {
		rpm -qa --queryformat="%{name} %{Version} %{Release} %{VCS}\n" | sort
	}
fi
EOF


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

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

# 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
[ "${TZ_BUILD_WITH_EMULATOR}" == "1" ] && generic_desktop_applications_fix_userhome developer


#!/bin/sh
echo "#################### ivi-ux-weston.post ####################"

usermod -G 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

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

# fix users homedirs
for user in app guest; do
	generic_desktop_applications_fix_userhome $user
done

#!/bin/sh
echo "#################### generic-setup-boot.post ##################"

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


%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
