#!/bin/bash

PATH=/bin:/usr/bin:/sbin:/usr/sbin
ONLYCAP_LIST="/etc/smack/onlycap"

# check initial boot
function check_init_boot
{
	if [ ! -e /opt/share/security-config/.smack_pre_labeling ]
	then
		touch /opt/share/security-config/.smack_pre_labeling
		return 1
	fi
	return 0
}

# Set default smack label for the specific file or folder
function set_smack_label
{
	if [ -e /csa ]
	then
		chsmack -r -a "_" /csa
		if [ -e /csa/nv ]
		then
			chown -R telephony:telephony /csa/nv
			chsmack -r -a "System" /csa/nv
		fi
	fi

	# onlycap feautre
	chsmack -e "User" /usr/bin/launchpad-loader
	chsmack -e "User" /usr/bin/wrt-loader
}

check_init_boot

if [ "$?" == 1 ] # Init boot case
then
	set_smack_label
fi

echo $(cat $ONLYCAP_LIST) > /sys/fs/smackfs/onlycap
