#!/usr/bin/env bash
###############################################################################
#
# Copyright (C) 2009-2013 Nintendo. All rights reserved.
#
# These coded instructions, statements, and computer programs contain
# proprietary information of Nintendo of America Inc. and/or Nintendo
# Company Ltd., and are protected by Federal copyright law. They may
# not be disclosed to third parties or copied or duplicated in any form,
# in whole or in part, without the prior written consent of Nintendo.
#
###############################################################################
if [ "$USE_CAFEX" == "1" ]
then
# Set IFS to something that will not be in the args, so that BASH will pass the entire un-parsed string to CafeX
saveIFS="$IFS"
IFS=$'\n'
echo "Using CafeControl"
cafex.exe on $@
rval=$?
IFS="$saveIFS"
exit $rval
fi
###############################################################################
# cafeon simulates launching main startup application from power on
# assumes arguments are not options but command-line arguments for SysConfig
###############################################################################
###############################################################################
# create_directory_if_noexist
###############################################################################
create_directory_if_noexist()
{
if [ ! -d "$1" ]
then
echo "$(basename "$0"): Creating dir: $1"
mkdir -m 0777 -p "$1"
fi
}
################################################################################
# sed
#
# Wrapper function for /usr/bin/sed. Needed because of a sed bug: when using
# some non-UTF-8 encoding formats (ex: Shift-JIS), executing on a file with
# multibyte characters, sed can hang. This function forces sed to use the UTF-8
# encoding format, then restores to previous format.
################################################################################
sed()
{
local saved_lang=$LANG
LANG=C.UTF-8
/usr/bin/sed "$@"
LANG=$saved_lang
}
###############################################################################
# main
###############################################################################
CAFEON_DISABLE_BGD=0
CAFEON_MORE_OPTIONS=0
CAFEON_NOBGD_META=
BRIDGE_PARAMETERS_WITH_E=
CAFE_RUN_DEBUG=
echo `basename "$BASH_SOURCE"`: using sed workaround
CAFEON_OPTION_NO_DATA_SYNC=${CAFERUN_OPTION_NO_DATA_SYNC:-0}
export CAFE_RUN_RUNNING=${CAFE_RUN_RUNNING:-0}
if [ $CAFE_RUN_RUNNING -gt 0 ]
then
echo "****cafeon: RECURSIVE CALL TO cafeon EXITING****"
exit 1
fi
export CAFE_RUN_RUNNING=1
if [ $# -gt 0 ]
then
CAFEON_MORE_OPTIONS=1
while [ $CAFEON_MORE_OPTIONS -eq 1 ]
do
if [ "$1" = "-noprompt" ]
then
export CATTOUCAN_TERM="source -p -q /vol/content"
shift
elif [ "$1" = "-d" ]
then
CAFE_RUN_DEBUG="${CAFE_RUN_DEBUG} $1 $2"
shift
shift
elif [ "$1" = "-p" ]
then
CAFE_RUN_DEBUG="${CAFE_RUN_DEBUG} $1 $2"
shift
shift
elif [ "$1" = "-e" ]
then
BRIDGE_PARAMETERS_WITH_E="$BRIDGE_PARAMETERS_WITH_E $1 $2"
shift
shift
elif [ "$1" = "-nobgd" ]
then
CAFEON_DISABLE_BGD=1
shift
elif [ "$1" = "-nosync" ]
then
if [ ! -e "$CAFE_DATA_DIR" ]
then
echo "Session data directory is missing and needs to sync'd!"
echo " Please re-run without the '-nosync' option."
exit
fi
CAFEON_OPTION_NO_DATA_SYNC=1
shift
elif [ "$1" = "-recover" ]
then
export _CCRSYSCFG1=0x40000000
BOOTRUN_USE_RECOVERY_IMAGE=1
shift
else
CAFEON_MORE_OPTIONS=0
fi
done
fi
#Create a new version of $CAFE_META_DIR, this one with an edited meta.xml,
#which will force the disabling of background daemons
if [ $CAFEON_DISABLE_BGD -eq 1 ]
then
CAFEON_NOBGD_META=$CAFE_TEMP/${SESSION_PATH_PREFIX}tmp_meta
echo "Disabling background daemons in tmp dir $CAFEON_NOBGD_META"
create_directory_if_noexist $CAFEON_NOBGD_META
cp $CAFE_META_DIR/* $CAFEON_NOBGD_META
sed -i -e "s|\(\)\(.*\)\(\)|\10\3|" "$CAFEON_NOBGD_META/meta.xml"
export CAFE_META_DIR=$CAFEON_NOBGD_META
fi
# Pull out the low portion of the OS version number to determine if the
# SysConfig was built in debug or ndebug
OS_VERSION_LO=$(grep -s "os_version" \
"$CAFE_ROOT/data/mlc/sys/title/00050010/1f700500/code/app.xml" \
| cut -d ">" -f2 | cut -c 9-14 )
TOTAL_ARGLIST_WITH_QS=`echo $@ | sed -e "s/ /?/g" | sed -e "s/-c?/-c /g" | sed -e "s/?-c/ -c/g"`
if [ -z $OS_VERSION_LO ]
then
echo "error: unable to locate System Config Tool app.xml or file is corrupt"
else
# Synchronize the session data directory if multisession and not suppressed
if [ $CAFEON_OPTION_NO_DATA_SYNC -eq 0 ]
then
syncsession
fi
sed -i "s|\(\)\(.*\)\(\)|\1system_config_tool.rpx $TOTAL_ARGLIST_WITH_QS\3|" "$CAFE_DATA_DIR/mlc/sys/title/00050010/1f700500/code/cos.xml"
if [ $OS_VERSION_LO -eq "100040" ] # NDEBUG build
then
source caferun $CAFE_RUN_DEBUG $BRIDGE_PARAMETERS_WITH_E -e mcp:launch_hint:hfiomlc -z -t 0x000500101f700500 "$CAFE_ROOT/system/bin/ghs/cafe/app/system_config_tool/base/NDEBUG/system_config_tool.rpx" "$@"
elif [ $OS_VERSION_LO -eq "100080" ] # DEBUG build
then
source caferun $CAFE_RUN_DEBUG $BRIDGE_PARAMETERS_WITH_E -e mcp:launch_hint:hfiomlc -z -b -t 0x000500101f700500 "$CAFE_ROOT/system/bin/ghs/cafe/app/system_config_tool/base/DEBUG/system_config_tool.rpx" "$@"
fi
sed -i -e "s|\(\)\(.*\)\(\)|\1system_config_tool.rpx\3|" "$CAFE_DATA_DIR/mlc/sys/title/00050010/1f700500/code/cos.xml"
fi