Skip to content

Instantly share code, notes, and snippets.

@dkosmari
Last active October 10, 2024 05:57
Show Gist options
  • Select an option

  • Save dkosmari/22f91053921c305111083e914feb4fbf to your computer and use it in GitHub Desktop.

Select an option

Save dkosmari/22f91053921c305111083e914feb4fbf to your computer and use it in GitHub Desktop.
A shell script to fetch Wii U crash logs through ftpiiu plugin. Can use lftp, curl, wget to retrieve the files.
#!/bin/sh -e
# This script copies crash logs from a Wii U running Aroma with FTPiiU plugin.
WIIU_ADDRESS=${1:-wiiu}
# Note: choose your favorite command to do FTP downloads
function download {
URL="$1"
# lftp -c get "$URL"
wget --no-verbose "$URL"
# curl --progress-bar --remote-name "$URL"
}
TEMP_PATH=$(mktemp -d)
if [[ -z "$TEMP_PATH" ]]
then
echo "failed to create temporary directory"
exit 1
fi
function cleanup {
rm -rf "$TEMP_PATH"
echo "Deleted temp directory ${TEMP_PATH}"
}
trap cleanup EXIT
REMOTE_SYS="storage_slc/sys"
# obtain the console serial id
(cd "$TEMP_PATH" && \
download "ftp://${WIIU_ADDRESS}/${REMOTE_SYS}/config/sys_prod.xml")
SYS_PROD_PATH="${TEMP_PATH}/sys_prod.xml"
# To avoid depending on a XML parser, we use sed instead.
CODE_ID=$(sed -rn \
's|[[:space:]]*<code_id[^>]*>([[:alpha:]]+)</code_id>|\1|p' \
"$SYS_PROD_PATH")
SERIAL_ID=$(sed -rn \
's|[[:space:]]*<serial_id[^>]*>([[:digit:]]+)</serial_id>|\1|p' \
"$SYS_PROD_PATH")
# Download each log file individually; it's slow, but reliable.
for ((i=0; i<100; ++i))
do
(cd "$TEMP_PATH" && \
download "ftp://${WIIU_ADDRESS}/${REMOTE_SYS}/logs/${i}.log")
done
# dump logs into <SERIAL>/<DATETIME>
SERIAL="${CODE_ID}${SERIAL_ID}"
DATETIME=$(date "+%F_%H-%M-%S")
DEST_PATH="${SERIAL}/${DATETIME}"
mkdir -v -p "$DEST_PATH"
echo "Copying logs to $DEST_PATH"
# rename all log files to match their timestamps (first line in the log)
for f in $(ls --sort=time --time=birth $TEMP_PATH/*.log)
do
FILE_TIME=$(head -n 1 < "$f")
FILE_NAME="${FILE_TIME//:/-}"
FILE_NAME="${FILE_TIME// /_}"
cat "$f" >> "${DEST_PATH}/${FILE_NAME}.log"
done
# finishing touch: use mac2unix if available
if command -v mac2unix >/dev/null 2>&1
then
mac2unix --keepdate --force --quiet -- "$DEST_PATH/"/*.log
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment