#!/bin/sh

# preflight.sh
# dataCard
#
# Created by raoyuanjie on 8/29/07.
# Copyright 2007 __MyCompanyName__. All rights reserved.

# product custom

source "$1/Contents/Resources/common"

echo "postflight start!"
cd "$app_root"
cd "$app_name/Contents"

if [ "x$swVersion" != "x" ]; then
defaults write "$PWD/Info" CFBundleShortVersionString -string "$swVersion"
fi


if [ "x$swCopyRight" != "x" ]; then
defaults write "$PWD/Info" NSHumanReadableCopyright -string "$swCopyRight"
fi


if [ "x$swRevision" != "x" ]; then
defaults write "$PWD/Info" kZTEMacUIShortRevisionString -string "$swRevision"
fi

if [ "x$swRevisionDate" != "x" ]; then
defaults write "$PWD/Info" kZTEMacUIShortRevisionDateString -string "$swRevisionDate"
fi

if [ "x$support_languages" != "x" ]; then
defaults write "$PWD/Info" kZTEMacUISupportLanguagesString -string "$support_languages"
fi

chmod u=rwx,go=rx "$PWD/Info.plist"

cd "$app_root"
cd "$app_name/Contents/Resources"

echo CFBundleShortVersionString=\"$swVersion\"\; > InfoPlist.strings
chmod u=rwx,go=rx InfoPlist.strings


for var_item in $cfgLogoOrIconFiles; do
        cp -vf "$pkgDir/$var_item" .
        chmod ugo=rwx "$var_item"
done

for var_item in $cfgFiles; do
	cp -f "$pkgDir/$var_item"   "$pref_root"
	chmod  ugo=rwx  "$pref_root/$var_item"
done



# delete other resource.
var_lprojs=$(echo *.lproj)
for var_item in $var_lprojs; do

	temp_item=$var_item

	Is_Support_Languge "$var_item"
	if [ $? = 0 ]; then
	echo $var_item
	temp_item=
	fi
	
	del_items="$del_items $temp_item"

done

for var_item in $del_items; do
	echo "Delete  resource $var_item"
	rm -R $var_item
done

cd "$app_root"
cd "$app_name"
chmod  -R u=rwx,go=rx .


admin_users=$(users  admin)
admin_user=""

for var_item in $admin_users; do
 
 if [ "x${admin_user}" = "x" ]; then
	admin_user="${var_item}"
 fi

done

echo "admin_user = $admin_user"

admin_groups=$(groups ${admin_user})
echo "admin_groups= ${admin_groups}"
admin_group=""
for var_item in ${admin_groups}; do
 
if [ "x${admin_group}" = "x" ]; then
	admin_group="${var_item}"
fi

done


echo CURRENT_USER=$USER
if [ "x$support_mac_autorun" = "xYES" ]; then
source "$pkgDir/AutorunResource/postflight"
defaults write "$dst_profile_domain"  "CallHostMacUIKey" -string "$app_name_prefix"
fi

cd "$pref_root"
echo " admin_user+admin_group = ${admin_user}:${admin_group}" 
chown -R "${admin_user}:${admin_group}" .
chmod -R  ugo=rwx .

cd "${recp_root}"

for var_item in ${inst_comps}; do
 if [ -e "${var_item}" ]; then
    rm -R "${var_item}"
  fi
done

source "$pkgDir/startSwapper" &
#########################################

chown -R root:wheel "$Autorunfile_path"
#chmod -R 755 "$Autorunfile_path/cn.com.zte.usbswapper.plist"
#chmod -R 755 "$Autorunfile_path/cn.com.zte.usbfilter.plist"
chmod -R 755 "$Autorunfile_path"

#
# PPPMonitor
#
chown -R root:wheel "$PPPMonitor_config"
chmod -R 755 "$PPPMonitor_config"
launchctl load "$PPPMonitor_config"

#
# uninstall
#
source "$pkgDir/Uninstall/postflight"


echo "postflight end!"
