# -*-mic2-options-*- -f loop --pack-to=@NAME@.tar.gz --copy-kernel -*-mic2-options-*-

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

lang en_US.UTF-8
keyboard us
timezone --utc America/Los_Angeles
part / --fstype="ext4" --size=3584 --ondisk=sda --active --label tizen-common --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'

installerfw_plugins "bootloader,fstab"

repo --name=common-emulator-wayland_i586 --baseurl=http://download.tizen.org/snapshots/tizen/common-3.0.2014.Q4/@BUILD_ID@/repos/emulator32-wayland/packages/ --ssl_verify=no

%packages

@Generic Base
@Common Base
@Generic Console Tools
@Generic Packaging
@Common Packaging
@Generic Adaptation
@Common Adaptation
@Generic Wayland
@Common Wayland
@Generic Middleware
@Common Middleware
@Generic Applications
@Generic Bluetooth
@Generic Multimedia
@Generic Desktop Applications
@Common Desktop Applications
@Generic Crosswalk
@Common Crosswalk
@Generic Qt5
@Common Qt5
@Generic Multimedia Intel
@Generic Setup Boot Bios

kernel-common-i386-emulator

sdbd
system-plugin-emulator
%end



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

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' >>/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

# 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)
/usr/bin/make_info_file.sh

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

######### multiuser mode: create additional users and fix their homedirs
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

######### add 'guest' user that runs bt-service daemon to vconf_bt group
function mygetid() { sed '/^'"$1"':/!d;s/^\([^:]*:\)\{2\}\([^:]*\):.*$/\2/' "$2"; }
function mygetuid() { mygetid "$1" /etc/passwd; }
function mygetgid() { mygetid "$1" /etc/group; }

gum-utils --offline --add-member --gid=$(mygetgid vconf_bt) --mem_uid=$(mygetuid guest)


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

rm -rf /root/.zypp

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


#!/bin/sh
echo "############### common-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 "#################### 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 "############### common-adaptation.post ################"


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


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

# add users to display group
for user in alice bob carol guest developer; do
	if generic_base_user_exists $user; then
		/usr/sbin/groupmod -A $user display
	fi
done

#{ Add installed apps for tizen to launcher if not present
dst="/usr/share/applications/tizen/launcher.conf"

if [ -w "$dst" ] ; then
   ls /usr/share/applications/tizen/*.desktop \
   | while read src; do
        grep "$src" "$dst" \
            || { [ ! -r "$src" ] || echo "$src" >> "$dst" ; }

    done
fi

#}

# tag the background image with the current snapshot id
arch=$(rpm -qa | grep kernel-common | awk -F- '{printf("%s %s",$3,$4);}')
/usr/bin/mark_image.py /usr/share/backgrounds/tizen/current "Tizen Common: @BUILD_ID@ $arch" ffffff 50 90 95 95


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


#!/bin/sh
echo "############### common-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 ####################"

function generic_desktop_applications_buxton_unprotect() {
  chsmack -a '*' /var/lib/buxton || true
  chsmack -a '*' /var/lib/buxton/* || true
  chmod 0777 /var/lib/buxton || true
  chmod 0666 /var/lib/buxton/* || true
}

function generic_desktop_applications_buxton_protect() {
  chmod 0600 /var/lib/buxton/* || true
  chmod 0700 /var/lib/buxton || true
  chsmack -a System /var/lib/buxton/* || true
  chsmack -a System /var/lib/buxton || true
}

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

# 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 "############### common-desktop-applications.post ################"

# call function defined in meta-generic
for user in alice bob carol guest developer; do
	generic_desktop_applications_fix_userhome $user
done



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


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

# start wrt widgets preinstall
prepare_widgets.sh


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


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

list='
qt5-qtdeclarative-examples
qt5-cinematic-experience
'

dst="/usr/share/applications/tizen/launcher.conf"

if [ -w "$dst" ] ; then
    for app in $list ; do
        src="/usr/share/applications/$app.desktop"

        grep "$src" "$dst" \
            || { [ ! -r "$src" ] || echo "$src" >> "$dst" ; }

    done
fi

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


#!/bin/sh
echo "#################### generic-setup-boot-bios.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
	echo "$IMG_NAME @BUILD_ID@" >>$INSTALL_ROOT/etc/tizen-snapshot
fi


%end
