From 069e402d7e91f8d6c4229f546cc218499b83dca1 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Mon, 9 Dec 2024 09:28:33 +0300 Subject: [PATCH] Bash: Add switch scripts. --- home/program/bash/module/Switch.nix | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 home/program/bash/module/Switch.nix diff --git a/home/program/bash/module/Switch.nix b/home/program/bash/module/Switch.nix new file mode 100644 index 00000000..a1dc41ce --- /dev/null +++ b/home/program/bash/module/Switch.nix @@ -0,0 +1,45 @@ +{ ... }: { + text = '' + # Install on a Nintendo Switch. + # Usage: switch_install + function switch_install() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=(*.ns[pz]) + + local id=$(_switch_id) + _switch_mount + + install() { + gio copy -p "''${target}" ''${id}5:\ SD\ Card\ install/ + } + + _iterate_targets install ''${targets[@]} + } + + # Backup a Nintendo Switch saves and album. + function switch_backup() { + local id=$(_switch_id) + _switch_mount + mkdir switch_backup || rm -r switch_backup/* + mkdir switch_backup/{save,album} + pushd switch_backup/save + cp -r /run/user/''${UID}/gvfs/mtp\:host\=-_DBI_*/7\:\ Saves/* . + popd + pushd switch_backup/album + cp -r /run/user/''${UID}/gvfs/mtp\:host\=-_DBI_*/8\:\ Album/* . + popd + pushd switch_backup + archive_fast album + archive save + } + + function _switch_id() { + gio mount -l -i | rg 'mtp://-_DBI_' | sed "s/^.*=//" | head -1 + } + + function _switch_mount() { + test -d /run/user/''${UID}/gvfs/mtp\:host\=-_DBI_* || gio mount "$(_switch_id)" + } + ''; +}