#!/usr/bin/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. # ############################################################################### source $(dirname "$0")/xmain.sh #============================== #MAKE IMAGE #This script masters, images, #and installs a specified RPX #onto the console. # #VERSION 1.12 #============================== displayHelp(){ FIL=$(basename "$0") echo "Master, Image, Install, Launch script Options (optional): -t : Replaces low digits of the current title ID in the app.xml file -b : RPX is a debug version (default: NDEBUG) -s : Install from an SD card (default: PCFS) -n : Install to NAND (default: USB) -x : Skip running the RPX for mastering/imaging -m : Launch title from sysconfig rather than debugger -o : Specify an image output directory (default: MLC/install) -i : Specify the image filename (default: RPX file name) -NM : Do not master/image title -NI : Do not install title -NL : Do not launch title -r : location of RPX (not including .rpx) --help -h --h -help : Display help Options (last optional): -a: : arguments to run the RPX with Usage: $FIL [optionals] [-a ...] Example: #Using first RPX in current working directory (NDEBUG) $FIL #---or--- #Specify parameters (args = anything past -a) $FIL -a -x 30 -y 20 #---or--- #Specify a path to a DEBUG RPX $FIL -b -r \"\$CAFE_ROOT/system/bin/\$TOOLCHAIN/\$PLATFORM\"/demo/helloworld/DEBUG/helloworld" exit $1 } initFlags #LAUNCH_DBG=0 #launch in debug mode (default) LAUNCH_DEVM=16 #launch from sysconfig NO_IMG=32 #do not master/image NO_INSTALL=64 #do not install the title NO_LAUNCH=128 #do not launch the title NO_RUN=256 #do not run initially (mastering) INSTALL_SD=512 #install from the SD card LAUNCH_FLAG=$((NO_LAUNCH|LAUNCH_DEVM)) #============================== # PARSE INPUT #============================== ARG=("$@") for((i=0;i<$#;++i));do case "${ARG[i]}" in #set title ID -t)if [ $((++i)) -ge $# ];then break fi TID="${ARG[i]}" verifyTID;; #debug build of RPX -b)FLG=$((FLG|DBG_BUILD));; #install to NAND -n)FLG=$((FLG|TITLE_MLC));; #install from SD card -s)FLG=$((FLG|INSTALL_SD));; #launch from sysconfig -m)FLG=$((FLG|LAUNCH_DEVM));; #do not run the RPX before mastering -x)FLG=$((FLG|NO_RUN));; #do not master/img -NM)FLG=$((FLG|NO_IMG));; #do not launch -NL)FLG=$((FLG|NO_LAUNCH));; #do not install title -NI)FLG=$((FLG|NO_INSTALL));; #path to RPX -r)if [ $((++i)) -ge $# ];then break fi FIL="${ARG[i]}";; #RPX arguments -a)ARG="${ARG[@]:$((++i))}" break;; #image output path -o)if [ $((++i)) -ge $# ];then break fi OUT="${ARG[i]}";; #image filename -i)if [ $((++i)) -ge $# ];then break fi APP="${ARG[i]}";; #display help and exit -h|--h|-help|--help) displayHelp 0;; esac done if [ $i -ge $# ];then unset ARG fi i= #============================== # VERIFY INPUT #============================== #cannot do an imaging and launch without installing if [ $((FLG&(NO_IMG|NO_INSTALL|NO_LAUNCH))) == $NO_INSTALL ];then die Cannot specify only option '-NI' fi #cannot specify parameters when not launching if [[ $((FLG&NO_LAUNCH)) != 0 && ! -z "$ARG" ]];then unset ARG echo Ignoring arguments '(-a)' with option '-NL' fi #check image variable specification if [ $((FLG&NO_IMG)) != 0 ];then if [ ! -z "$OUT" ];then unset OUT echo Ignoring output directory '(-o)' with option '-NM' fi if [ ! -z "$TID" ];then unset TID echo Ignoring Title ID '(-t)' with option '-NM' fi fi getRPX #default to RPX name? if [ -z "$APP" ];then APP=$(basename "$FIL") APP="${APP:0:$((${#APP}-4))}" fi # # For right now, we are only installing from MLC/install directory # if [[ ! -z "$OUT" && $((FLG&NO_INSTALL)) != 0 ]];then if [ $(toLower $(realpath "$OUT")) != $(toLower $(realpath "$CAFE_MLC_DIR"/install)) ];then die You cannot install a title from anywhere but the default directory fi unset OUT fi #default to USB if not specified if [ $((FLG&TITLE_HINT)) == 0 ];then FLG=$((FLG|TITLE_USB)) fi #auto kill inconsistant launch if [ $((FLG&LAUNCH_FLAG)) == $LAUNCH_FLAG ];then FLG=$((FLG&(~LAUNCH_DEVM))) echo No Launch and sysconfig launch specified, ignoring sysconfig launch fi #============================== # OBTAIN TITLE ID (app.xml) #============================== #sync session doSync if [ $((FLG&(NO_IMG|NO_RUN))) == 0 ];then # #REALLY SHOTTY WAY OF GETTING #ALL THE REQUIRED FILES TO MASTER # - Rethink later? # i= if [ $((FLG&DBG_BUILD)) != 0 ];then i='-b' fi echo -ne Running the RPX... #run the rpx on a new thread FLG=$((FLG|1)) bash caferun &>/dev/null -z $i "$FIL" $ARG & #sleep for 30 and stop the execution i= sleep 30 cafestop FLG=$((FLG&(~1))) echo done! fi #make sure app.xml was copied over if [ "$SESSION_MANAGER" == 1 ];then tmp=$(basename "$FIL") tmp="$CAFE_DATA_TMP"/${tmp:0:$((${#tmp}-4))} else tmp=$(dirname "$FIL") fi tmp="$tmp"/app.xml if [ ! -e "$tmp" ];then echo "$tmp" die app.xml is not present in the RPX directory fi echo -ne Reading the app.xml... #obtain app.xml data arr=$(cat "$tmp") if [ $? != 0 ];then die ' 'Failed to read the app.xml contents fi var=${#arr} arr=$(echo "$arr" | awk '{gsub(/\\/,"\\\\");print}') beg=0 #locates a string in the data (sequential searching) strFind(){ let x=var-beg l=${#1} #length of str < data? if [ $l -le $x ];then #gets a 1 based index from the data, 0 if not found i=`awk -v a="${arr:beg}" -v b="$1" 'BEGIN{printf index(a,b)}'` if [ $i != 0 ];then let i=i-1+beg; return fi fi l=0 } #sets the new beginning point setBeg(){ let beg=i+l } #app.xml error badApp(){ die ' 'Corrupted app.xml } #check if the last search was successful resCheck(){ if [ $l == 0 ];then badApp fi } #find title id tag strFind '' resCheck setBeg #find tag closing strFind '<' resCheck #free data x= var= #set TID length l=${#TID} #obtain the ID with the replaced characters TID="${arr:beg:i-beg-l}$TID" #make sure we have something... if [ -z "$((0x$TID))" ];then badApp fi #are we replacing the title ID? if [ $l != 0 ];then #write new data echo "${arr:0:beg}$TID${arr:i}" > "$tmp" #check if write was successful if [ $? != 0 ];then die ' 'Failed to rewrite app.xml fi fi #free data i= l= tmp= unset arr beg var echo done! #============================== # MASTER/IMAGE DATA #============================== if [ $((FLG&NO_IMG)) == 0 ];then echo Mastering the RPX... #make directory to hold mastered title x="$CAFE_ROOT/mstr" if [ ! -d "$x" ];then mkdir "$x" if [ $? != 0 ];then die Failed to create mastering directory fi fi x="$x/$APP" #master the title makecfmaster.sh -r "$FIL" -o "$x" if [ $? != 0 ];then die Mastering returned error fi echo done! #check if successful x="$x".wumad if [ ! -f "$x" ];then die Mastering failed fi echo Creating download image... #get custom output directory if [ ! -z "$OUT" ];then OUT="-o $OUT" fi #image the title makecfdownloadimage.sh -i "$x" $OUT if [ $? != 0 ];then die Imaging returned error fi x= #free memory if [ ! -z "$OUT" ];then unset OUT fi echo done! fi #============================== # INSTALL/SYSCONFIG LAUNCH IMAGE #============================== #are we doing anything with this? if [ $((FLG&(LAUNCH_DEVM|NO_INSTALL))) != $NO_INSTALL ];then #if we are installing, check if image is there i=$((FLG&NO_INSTALL)) if [ $i == 0 ];then APP="$APP"_p01 if [ ! -d "$CAFE_MLC_DIR/install/$APP" ];then die This title is not imaged fi fi echo -ne Writing the custom sysconfig scripts... #make a custom script openSCP #modify data for installing l=$((FLG&TITLE_MLC)) if [ $i == 0 ];then if [ $l == 0 ];then tmp=usb else tmp=mlc fi writeSCP "set_install_dev $tmp" #where are we installing this from? tmp=storage_hfiomlc01/install if [ $((FLG&INSTALL_SD)) != 0 ];then tmp=app_sd i=2 fi writeSCP "install /vol/$tmp/$APP" fi #are we launching it from sysconfig (without debug)? if [ $((FLG&LAUNCH_DEVM)) != 0 ];then if [ ! -z "$ARG" ];then #add a space ARG=" $ARG" fi #bug work-around writeSCPDelay writeSCP "launch $TID$ARG" fi echo done! #make sure they copy the image to the SD Card if [[ $i == 2 && $((FLG&NO_IMG)) == 0 ]];then echo ' Please copy the image to an SD Card and insert it into the CAT-DEV... Press enter to continue...' read i unset i fi echo Running custom sysconfig scripts... #run the script runSCP echo ' 'done! fi unset tmp i l x #============================== # LAUNCH DEBUG #============================== if [ $((FLG&LAUNCH_FLAG)) == 0 ];then echo Launching game with debugger... #launch game via debug trap runTrap INT runDBG echo ' 'done! fi exit 0