From 8d8837927ea94b7650e52e35e79ba97567cd96cb Mon Sep 17 00:00:00 2001 From: Emily Frost Date: Tue, 16 Jun 2020 12:04:32 -0500 Subject: [PATCH] Added ftp-sync, nkit, sfo-read, and vita-sync. --- fix-fileshare-permissions | 13 +++--- ftp-sync | 20 +++++++++ nkit | 16 +++++++ ps2-sync | 82 ------------------------------------ sfo-read | 88 +++++++++++++++++++++++++++++++++++++++ vita-sync | 11 +++++ 6 files changed, 142 insertions(+), 88 deletions(-) create mode 100755 ftp-sync create mode 100755 nkit delete mode 100755 ps2-sync create mode 100755 sfo-read create mode 100755 vita-sync diff --git a/fix-fileshare-permissions b/fix-fileshare-permissions index 993e9b9..f81a0d3 100755 --- a/fix-fileshare-permissions +++ b/fix-fileshare-permissions @@ -1,8 +1,9 @@ -#!/usr/bash +#!/bin/bash -test_dir='/media/hoard-disk/ebooks' +dir='/media/hoard/hoard/' +fileshare_group='library-users' +fileshare_owner='emily' -sudo chown root:root "$test_dir" -sudo chmod 600 "$test_dir" -sudo setfacl -Rm 'group:fileshare:r-x' "$test_dir" -sudo setfacl -Rm 'group:fileshare-admin:rwx' "$test_dir" +chown -R $fileshare_owner:$fileshare_group "$dir" +find "$dir" -type d -exec chmod 755 {} \; +find "$dir" -type f -exec chmod 644 {} \; diff --git a/ftp-sync b/ftp-sync new file mode 100755 index 0000000..7b7602f --- /dev/null +++ b/ftp-sync @@ -0,0 +1,20 @@ +#!/usr/bin/bash + +FTP_DIR=~/.local/var/ftp-mount/ +host="$1" +local_dir="$2" + +curlftpfs "$host" "$FTP_DIR" || exit 1 + +# TODO: Copying to FTP produces "ftruncate failed" errors. Not sure how to convince rsync to not use +# that. +# TODO: Rsync is probably not the best tool for the job here. It has *no* conflict handling. +echo "Copying new data to FTP server." +rsync -rtu --progress --inplace "$local_dir/" "$FTP_DIR" + +echo "Copying new data from FTP server." +rsync -rtu --progress "$FTP_DIR" "$local_dir" + +# TODO: This should probably be in a trap function. +fusermount -u "$FTP_DIR" +echo "Done." diff --git a/nkit b/nkit new file mode 100755 index 0000000..ee291c7 --- /dev/null +++ b/nkit @@ -0,0 +1,16 @@ +#!/usr/bin/bash + +# rebuild-iso +# compress + +case $1 in + 'compress') + mono /usr/lib/nkit/ConvertToNKit.exe "${@:2}" + ;; + 'rebuild-iso') + mono /usr/lib/nkit/ConvertToISO.exe "${@:2}" + ;; + *) + echo 'Missing action.' + ;; +esac diff --git a/ps2-sync b/ps2-sync deleted file mode 100755 index 6cd70b0..0000000 --- a/ps2-sync +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/python3 -""" -### ps2-sync -This tool makes links to ISO files in the way that Open PS2 Loader expects. It should work for both -Samba and USB loading, but has only been tested with Samba. - -This depends on hdl-dump. -""" - -import os -import subprocess - -# TODO: Replace these with user input and/or config files. -ROOT_PATH = '.' - -def get_disc_info(disc_image_path): - this_disc_info = { - 'gameid': None, - 'disc_type': None, - 'filename': None - } - - # TODO: Figure out how to do hdl-dump's work in this script. - # I tried this with isoparser, but the parsing took far too long. - hdl_dump_args = ['hdl-dump', 'cdvd_info2', disc_image_path] - # hdl-dump has a weird output format, quoting items inconsistently. Fortunately, it isn't - # likely to change anytime soon. - hdl_dump_result = subprocess.run(hdl_dump_args, capture_output=True) - if hdl_dump_result.returncode == 0: - hdl_dump_output = hdl_dump_result.stdout.decode('utf-8').split(' ') - - # hdl-dump prepends "dual-layer" to the disc type field instead of using DVD5/DVD9. - if hdl_dump_output[0] == 'dual-layer': - this_disc_info['gameid'] = hdl_dump_output[4][1:-1] - this_disc_info['disc_type'] = hdl_dump_output[1] - - else: - this_disc_info['gameid'] = hdl_dump_output[3][1:-1] - this_disc_info['disc_type'] = hdl_dump_output[0] - - this_disc_info['filename'] = os.path.basename(disc_image_path) - else: - print('File %s is not a Playstation 2 disc image.' % os.path.basename(disc_image_path)) - - return this_disc_info - -def remove_dead_links(directory): - for link_name in os.listdir(directory): - link_path = os.path.abspath(os.path.join(directory, link_name)) - if os.path.islink(link_path): - link_target = os.path.join(directory, os.readlink(link_path)) - if not os.path.exists(link_target): - print('Removing dead link %s.' % link_path) - os.remove(link_path) - -root_path = os.path.abspath(ROOT_PATH) -source_path = os.path.join(root_path, 'iso') -disc_repo = os.path.join(root_path, '.opl-srv') - -os.makedirs(os.path.join(disc_repo, 'DVD'), exist_ok=True) -os.makedirs(os.path.join(disc_repo, 'CD'), exist_ok=True) -remove_dead_links(os.path.join(disc_repo, 'DVD')) -remove_dead_links(os.path.join(disc_repo, 'CD')) - -for filename in os.listdir(source_path): - disc_path = os.path.join(source_path, filename) - disc_info = get_disc_info(disc_path) - - if not disc_info['disc_type'] or not disc_info['gameid']: - print("Disc type could not be determined for %s" % disc_info['filename']) - - else: - disc_link_filename = '%s.%s' % (disc_info['gameid'], disc_info['filename']) - disc_link_path = os.path.join(disc_repo, disc_info['disc_type'], disc_link_filename) - disc_rel_path = os.path.relpath(disc_path, start=os.path.dirname(disc_link_path)) - - if not os.path.exists(disc_link_path): - print('Adding disc %s.' % disc_info['filename']) - print('Linking to %s.' % disc_rel_path) - os.symlink(disc_rel_path, disc_link_path) - else: - print('Disc %s already linked.' % disc_info['filename']) diff --git a/sfo-read b/sfo-read new file mode 100755 index 0000000..c509be2 --- /dev/null +++ b/sfo-read @@ -0,0 +1,88 @@ +#!/usr/bin/python3 + +import struct +import sys + +SFO_MAGIC = b'\x00PSF' +SFO_HEADER_FORMAT = '