From a07a40b018390b5832da6cf201c26ecfd4d1b7b3 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 17 Aug 2020 00:46:25 +0200 Subject: ma pkgs.nsrenamer: init --- makefu/5pkgs/nsrenamer/nsrenamer.sh | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 makefu/5pkgs/nsrenamer/nsrenamer.sh (limited to 'makefu/5pkgs/nsrenamer/nsrenamer.sh') diff --git a/makefu/5pkgs/nsrenamer/nsrenamer.sh b/makefu/5pkgs/nsrenamer/nsrenamer.sh new file mode 100755 index 000000000..3d60d1ae9 --- /dev/null +++ b/makefu/5pkgs/nsrenamer/nsrenamer.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +set -euf +indir=$(dirname "$1") +inname=$(basename "$1") +out=$(nxgameinfo_cli "$1") +ext=${1##*.} +id=$(awk -F: '/├ Title ID:/{print $2}' <<<$out |xargs) +baseid=$(awk -F: '/Base Title ID:/{print $2}' <<<$out |xargs) +version=$(awk -F: '/├ Display Version:/{print $2}' <<<$out |xargs) +name=$(awk -F: '/Title Name/{print $2}' <<<$out |xargs) +type=$(awk -F: '/Type:/{print $2}' <<<$out | xargs) + +! test -n "$id" && echo "Title ID cannot be empty!" && exit 1 +! test -n "$type" && echo "type cannot be empty!" && exit 1 + +if test "$type" == Base;then + ! test -n "$name" && echo "Title Name cannot be empty!" && exit 1 + NAME="[$id] $name Base Game.$ext" +elif test "$type" == Update;then + ! test -n "$name" && echo "Title Name cannot be empty!" && exit 1 + ! test -n "$version" && echo "Version cannot be empty!" && exit 1 + NAME="[$id] $name Update $version.$ext" +elif test "$type" == DLC;then + dlcname=$(jq -r --arg id "$id" '.[$id].name' < ~/.switch/titles.US.en.json) + if test -n "$dlcname" ;then + NAME="[$id] $dlcname DLC.$ext" + else + ! test -n "$name" && echo "dlcname cannot be found in titles.US.en.json and $name is empty!" && exit 1 + NAME="[$id] $name DLC.$ext" + fi +else + echo "unknown type '$type'" + exit 1 +fi +newname=$indir/$NAME + +if test "$NAME" == "${inname}";then + echo "name didn't change,doing nothing" + exit 0 +fi +if test -e "$newname" ;then + echo "'$NAME' already exists, will not override" + exit 1 +fi + +if test -n "${FORCE:-}" ;then + CONFIRM=y +else + read -p "rename '$inname' to '$NAME' - [y/N]" CONFIRM +fi + +if test -n "${FORCE:-}" -o "$CONFIRM" == "y" -o "$CONFIRM" == "Y";then + mv -nv "$1" "$newname" +else + echo "bailing out" + exit 1 +fi + -- cgit v1.2.3 From 9b30bf0814bd142052c30d0184d589fede04e1cf Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 18 Aug 2020 23:26:51 +0200 Subject: ma pkgs.nsrenamer: new naming scheme --- makefu/5pkgs/nsrenamer/nsrenamer.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'makefu/5pkgs/nsrenamer/nsrenamer.sh') diff --git a/makefu/5pkgs/nsrenamer/nsrenamer.sh b/makefu/5pkgs/nsrenamer/nsrenamer.sh index 3d60d1ae9..16aec3113 100755 --- a/makefu/5pkgs/nsrenamer/nsrenamer.sh +++ b/makefu/5pkgs/nsrenamer/nsrenamer.sh @@ -4,29 +4,29 @@ indir=$(dirname "$1") inname=$(basename "$1") out=$(nxgameinfo_cli "$1") ext=${1##*.} -id=$(awk -F: '/├ Title ID:/{print $2}' <<<$out |xargs) -baseid=$(awk -F: '/Base Title ID:/{print $2}' <<<$out |xargs) -version=$(awk -F: '/├ Display Version:/{print $2}' <<<$out |xargs) -name=$(awk -F: '/Title Name/{print $2}' <<<$out |xargs) -type=$(awk -F: '/Type:/{print $2}' <<<$out | xargs) +id=$(awk -F: '/├ Title ID:/{print $2}' <<<"$out" |xargs) +baseid=$(awk -F: '/Base Title ID:/{print $2}' <<<"$out" |xargs) +version=$(awk -F: '/├ Version:/{print $2}' <<<"$out" |xargs) +name=$(awk -F: '/Title Name/{print $2}' <<<"$out" | sed "s/[:']//g" | xargs ) +type=$(awk -F: '/Type:/{print $2}' <<<"$out" | xargs) ! test -n "$id" && echo "Title ID cannot be empty!" && exit 1 ! test -n "$type" && echo "type cannot be empty!" && exit 1 if test "$type" == Base;then ! test -n "$name" && echo "Title Name cannot be empty!" && exit 1 - NAME="[$id] $name Base Game.$ext" + NAME="$name [$id][v$version].$ext" elif test "$type" == Update;then ! test -n "$name" && echo "Title Name cannot be empty!" && exit 1 ! test -n "$version" && echo "Version cannot be empty!" && exit 1 - NAME="[$id] $name Update $version.$ext" + NAME="$name [UPD][$id][v$version].$ext" elif test "$type" == DLC;then - dlcname=$(jq -r --arg id "$id" '.[$id].name' < ~/.switch/titles.US.en.json) + dlcname=$(jq -r --arg id "$id" '.[$id].name' < ~/.switch/titles.US.en.json | sed "s/[:']//g") if test -n "$dlcname" ;then - NAME="[$id] $dlcname DLC.$ext" + NAME="$dlcname [DLC][$id][v$version].$ext" else ! test -n "$name" && echo "dlcname cannot be found in titles.US.en.json and $name is empty!" && exit 1 - NAME="[$id] $name DLC.$ext" + NAME="$dlcname [DLC][$id][v$version].$ext" fi else echo "unknown type '$type'" -- cgit v1.2.3