# -*-mic2-options-*- -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 Asia/Seoul
part / --fstype="ext4" --size=3500 --ondisk=mmcblk0 --label rootfs --fsoptions=defaults,noatime
part /opt --fstype="ext4" --size=512 --ondisk=mmcblk0 --label system-data --fsoptions=defaults,noatime
part /opt/usr --fstype="ext4" --size=3500 --ondisk=mmcblk0 --label user --fsoptions=defaults,noatime

rootpw tizen 
xconfig --startxonboot
bootloader  --timeout=3  --append="rw vga=current splash rootwait rootfstype=ext4 plymouth.enable=0"   --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=ivi-emulator --baseurl=http://download.tizen.org/snapshots/tizen/ivi/@BUILD_ID@/repos/emulator/packages/ --ssl_verify=no
repo --name=base_emulator32 --baseurl=http://download.tizen.org/snapshots/tizen/base/latest/repos/emulator32/packages/ --ssl_verify=no

%packages

# @ Generic Base
bash
connman
coreutils
default-ac-domains
e2fsprogs
filesystem
glibc-locale
gum-utils
kmod
kmod-compat
lrzsz
net-tools
pam
pam-locale
procps
psmisc
rfkill
rpm
rpm-security-plugin
setup
shadow-utils-adm
systemd
tizen-release
tlm
tzdata
util-linux
wpa_supplicant
# @ Generic Desktop Applications
emotion
# @ Generic Multimedia
alsa-utils
gst-plugins-bad
gst-plugins-base
gst-plugins-good
gstreamer
gstreamer-utils
pulseaudio
pulseaudio-module-bluetooth
pulseaudio-modules-tizen
pulseaudio-utils
# @ IVI Adaptation
# @ IVI Applications
app-installers
org.tizen.bootsplash
org.tizen.dpm-syspopup
org.tizen.dpm-toolkit
org.tizen.homescreen
org.tizen.screen-reader
org.tizen.stt-engine-default
org.tizen.tts-engine-default
smartdevicelink
tpk-backend
wgt-backend
# @ IVI Base
capi-base-utils
deviced
deviced-profile_common
deviced-tools
dlogutil
fsck-msdos
libstorage
lzo
newfs-msdos
tizen-locale
tizen-release-profile_ivi
tlm-config-common-singleseat
# @ IVI Bluetooth
bluetooth-agent
bluetooth-agent-profile_ivi
bluetooth-frwk-core
bluetooth-frwk-plugin-headed
bluetooth-frwk-profile_ivi
bluetooth-frwk-service
bluetooth-share
bluetooth-tools
bluetooth-tools-profile_ivi
bluez
bluez-profile_common
libbluetooth
obexd
org.tizen.bt-syspopup
org.tizen.bt-syspopup-profile_common
ug-bluetooth-efl
# @ IVI Connectivity Framework
capi-network-nfc
capi-network-smartcard
capi-network-tethering
connman-extension-ivi
libnl2
libtfeature
# @ IVI Console Tools
curl
findutils
grep
gzip
iptables
tar
unzip
xz
zip
# @ IVI Dali
dali
dali-adaptor
dali-adaptor-profile_ivi
dali-toolkit
# @ IVI EFL
at-spi2-core
capi-ui-efl-util
default-fonts-fc-sdk
default-fonts-sdk
efl-config-profile_ivi
efl-extension
efl-misc-profile_ivi
efl-modules-profile_ivi
elementary-locale
elementary-tools
libatk
libatk-bridge-2_0-0
libatspi0
typelib-1_0-Atspi-2_0
# @ IVI Enlightenment
e-mod-tizen-devicemgr
e-mod-tizen-eom
e-mod-tizen-keyrouter
e-mod-tizen-processmgr
e-mod-tizen-wl-textinput
e-mod-tizen-wm-policy
e-tizen-data-profile_ivi
enlightenment
# @ IVI Input Framework
anthy
capi-ui-inputmethod
capi-ui-inputmethod-manager
ise-default
ise-default-profile_ivi
ise-engine-anthy
ise-engine-default
ise-engine-hangul
ise-engine-sunpinyin
ise-engine-tables
ise-engine-tables-zh
isf
isf-config-ivi
isf-profile_wearable
libhangul
libscl-ui
org.tizen.inputmethod-setting
# @ IVI Middleware
SDL2
account-manager
account-parser
amd
app2sd
appcore-agent
appcore-widget
argos_watchdog
askuser
askuser-notification
askuser-plugins
askuser-test
auth-fw
automotive-message-broker
automotive-message-broker-libclient
automotive-message-broker-plugins
automotive-message-broker-plugins-common
automotive-message-broker-plugins-murphy
boost-date-time
boost-program-options
boost-regex
buxton2
cairo
calendar-service
capi-appfw-app-common
capi-appfw-app-control
capi-appfw-event
capi-appfw-package-manager
capi-appfw-preference
capi-geofence-manager
capi-maps-service
capi-messaging-messages
capi-network-softap
capi-system-device
capi-system-media-key
capi-system-runtime-info
capi-system-sensor
capi-vpnsvc
cert-svc
contacts-service2
context-service
crash-worker
cryptsetup
csr-framework
cyad
cynara
data-control
device-policy-manager
download-fonts-service
drm-service-core-tizen
email-service
esd
eventsystem
fido-client
geofence-server
gssdp
gupnp
gupnp-av
gupnp-dlna
iotcon
key-manager
key-manager-pam-plugin
krate
launchpad
launchpad-loader
lbs-server
lbs-server-plugin-replay
libaccount-service
libaskuser-common
libauth-fw-client
libauth-fw-client-admin
libcsr-framework-client
libcynara-creds-commons
libcynara-creds-dbus
libcynara-creds-gdbus
libcynara-creds-socket
libcynara-monitor
libdpm
libeom
libgeofence-dbus
libhyphen
libjson-glib
libkey-manager-client
libkey-manager-common
libkrate
libnss-security-manager
liboauth
libode
libpush
libpush-profile_common
libscl-core-profile_common
libsecurity-manager-client
libspeex
libwebappenc
location-geofence-server
location-lbs-server
maps-plugin-here
memps
mms-plugin
msg-service-tools
murphy
nghttp2
oauth2
ode
org.tizen.ode
org.tizen.secure-erase
phonenumber-utils
pkgmgr-server
pkgmgr-server
pkgmgr-tool
privilege-checker
privilege-info
pubkey-pinning
push-bin
push-bin-profile_common
push-tool-profile_common
resourced
rygel
sdbd
security-manager
security-privilege-manager
sensord-profile_ivi
session-utils
sms-plugin
stt
svi-data-profile_common
system-rw-update
tizen-debug
toybox
toybox-symlinks-dhcp
toybox-symlinks-dhcpd
ttrace
tzsh
ui-gadget-1
vc-engine-default
vconf-internal-keys
vconf-internal-keys-config-profile_ivi
voice-control
voice-control-elm
xdelta3
yaca
# @ IVI Multimedia
capi-content-media-content
capi-media-camera
capi-media-codec
capi-media-image-util
capi-media-metadata-editor
capi-media-metadata-extractor
capi-media-player
capi-media-recorder
capi-media-screen-mirroring
capi-media-sound-manager
capi-media-streamer
capi-media-streamrecorder
capi-media-thumbnail-util
capi-media-tone-player
capi-media-tool
capi-media-video-util
capi-media-vision
capi-media-wav-player
capi-mediademuxer
capi-mediamuxer
dcm-service
freealut
gst-libav
gst-plugins-tizen
gst-plugins-ugly
gst-rtsp-server
libbmp
libmedia-service
libmedia-thumbnail
libmedia-utils
libmm-camcorder
libmm-common
libmm-evas-renderer
libmm-fileinfo
libmm-imgp-gstcs
libmm-player
libmm-radio
libmm-session
libmm-sound
libmm-streamrecorder
libmm-transcode
libmm-wfd
libnsbmp
media-server
media-thumbnail-server
mediacontroller
mmsvc-camera
mmsvc-player
mmsvc-recorder
murphy-glib
mused
openal-soft
opencv
pulseaudio-modules-tizen
taglib
zbar
zint
# @ IVI Qt5
qt-tizen-demo
# @ IVI Telephony
call-manager
capi-telephony
libcall-manager
libtapi
libtcore
tel-plugin-database
tel-plugin-dbus_tapi
tel-plugin-indicator
tel-plugin-nitz
tel-plugin-packetservice
tel-plugin-packetservice-dbinit-profile_ivi
tel-plugin-vconf
telephony-daemon
telephony-daemon-profile_ivi
# @ IVI Wayland
libwayland-tbm-client
libwayland-tbm-server
# @ IVI Web Framework
browser-provider
chromium-efl
cordova-api
crosswalk-tizen
libwebsockets
webapi-plugins
# @ IVI Connectivity Framework Emualtor
capi-network-wifi-manager
mobileap-agent
net-config
# @ IVI Adaptation Emulator
capi-network-mtp
coregl
device-manager-plugin-emul
emulator-yagl
emuld
gst-plugins-emulator
libpciaccess
libtbm-vigs
libtdm-client
libtdm-drm
mmfw-sysconf-simulator
model-config-emulator-profile_common
system-plugin-emulator
system-plugin-profile_ivi
tel-plugin-atmodem
tel-plugin-vmodem
vmodemd-emul
# Others




%end


%attachment
/boot/kernel/dzImage
%end

%post
#!/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=$(date -u --date @$build_ts +%Y%m%d_%H%M%S)
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 "#################### ivi-base.post ####################"

######### multiuser mode: create additional users and fix their homedirs

if ! generic_base_user_exists owner; then
	gum-utils --offline --add-user --username=owner --usertype=admin --usecret=tizen
fi

#!/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 "############### ivi-packaging.post ################"

# generate repo files for zypper
function genrepo() {
	local url=$1
	local reponame=$2
	local filename=${3:-$2}
	local enabled=${4:-0}

	local prefix=${TZ_BUILD_VENDOR}-${TZ_BUILD_PROFILE}-${TZ_BUILD_REPO}

	# remove double slashes if any
	url=$(sed -e  's|/\+|/|g' -e 's|:/|://|' <<<$url)

	cat >> /etc/zypp/repos.d/$prefix-${filename}.repo << EOF
[$prefix-${reponame}]
name=$prefix-${reponame}
enabled=$enabled
autorefresh=0
baseurl=${url}?ssl_verify=no
type=rpm-md
gpgcheck=0
 
EOF
}

# source /etc/tizen-build.conf to get more infos about project, repos etc.
. /etc/tizen-build.conf 

# adjust build_id if this scripts executes before the replacement in /etc/tizen-build.conf
TZ_BUILD_ID=$(echo $TZ_BUILD_ID | sed 's|@BUILD_ID[@]|@BUILD_ID@|')

# snapshot repo
genrepo ${TZ_BUILD_SNAPSHOT_URL}/${TZ_BUILD_ID}/repos/${TZ_BUILD_REPO}/packages snapshot snapshot 1
genrepo ${TZ_BUILD_SNAPSHOT_URL}/${TZ_BUILD_ID}/repos/${TZ_BUILD_REPO}/debug snapshot-debug snapshot 1

# latest repo
genrepo ${TZ_BUILD_SNAPSHOT_URL}/latest/repos/${TZ_BUILD_REPO}/packages update update 0
genrepo ${TZ_BUILD_SNAPSHOT_URL}/latest/repos/${TZ_BUILD_REPO}/debug update-debug update 0

# daily repo
genrepo ${TZ_BUILD_DAILY_URL}/latest/repos/${TZ_BUILD_REPO}/packages daily daily 0
genrepo ${TZ_BUILD_DAILY_URL}/latest/repos/${TZ_BUILD_REPO}/debug daily-debug daily 0

# weekly repo
genrepo ${TZ_BUILD_WEEKLY_URL}/latest/repos/${TZ_BUILD_REPO}/packages weekly weekly 0
genrepo ${TZ_BUILD_WEEKLY_URL}/latest/repos/${TZ_BUILD_REPO}/debug weekly-debug weekly 0


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


#!/bin/sh
echo "############### ivi-middleware.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
[ "${TZ_BUILD_WITH_EMULATOR}" == "1" ] && generic_desktop_applications_fix_userhome developer


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


#!/bin/sh
echo "############### ivi-web-framework.post ################"

# start wrt widgets preinstall
prepare_widgets.sh


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


#!/bin/sh
echo "############### ivi-mbr-3parts.post ################"


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

#for user in alice bob carol guest; do
# if ! generic_base_user_exists $user; then
#  gum-utils --offline --add-user --username="$user" --usertype=normal --usecret=tizen
# fi
#done


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

LICENSE_DIR=/usr/share/licenses
LICENSE_FILE=/usr/share/license.html
MD5_TEMP_FILE=/usr/share/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 "<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 "</body>" >> $LICENSE_FILE
echo "</html>" >> $LICENSE_FILE

rm -rf $LICENSE_DIR/* $MD5_TEMP_FILE

#!/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 


%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
