From d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 24 Jan 2024 14:56:56 -0600 Subject: Getting a whole kobo distribution together! --- pkgs/install.nix | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ pkgs/plato.nix | 46 +++++++++++++++++++++++ pkgs/source.nix | 21 +++++++++++ 3 files changed, 177 insertions(+) create mode 100644 pkgs/install.nix create mode 100644 pkgs/plato.nix create mode 100644 pkgs/source.nix (limited to 'pkgs') diff --git a/pkgs/install.nix b/pkgs/install.nix new file mode 100644 index 0000000..e25108d --- /dev/null +++ b/pkgs/install.nix @@ -0,0 +1,110 @@ +{ writeShellApplication +, coreutils +, gnugrep +, rsync +, util-linux +, koboLabel ? "KOBOeReader" +, ... }: writeShellApplication { + name = "KoboInstaller"; + runtimeInputs = [ + coreutils + gnugrep + rsync + util-linux + ]; + text = '' + INPUT=${1-} + + if [[ -z "$INPUT" ]]; then + echo "Must provide an input directory" + exit 255 + fi + + if [[ ! -d "$INPUT/.kobo" ]] || [[ ! -d "$INPUT/.adds" ]]; then + echo "Missing one of $INPUT/.kobo or $INPUT/.adds. Are you sure your input directory is correct?" + exit 255 + fi + + KOBO_MOUNTPOINT="$(findmnt -nlo TARGET LABEL="${koboLabel}")" + if [[ -z "$KOBO_MOUNTPOINT" ]]; then + echo "Couldn't find a Kobo eReader volume! Is one actually mounted?" + exit 255 + fi + + KOBO_DIR="$KOBO_MOUNTPOINT/.kobo" + if [[ ! -d "$KOBO_DIR" ]]; then + echo "It doesn't seem like $KOBO_MOUNTPOINT actually points to a Kobo eReader since it doesn't contain a .kobo directory..." + exit 255 + fi + + # Tiny DRY helper for the failure message... + recap_failure() { + echo "* As a result, the device may have been left in an inconsistent state!" + echo "* Please note that NO automatic cleanup will be done!" + echo "* As such, before unplugging your device, consider removing:" + echo "* The following folders:" + for kfm_folder in .adds/kfmon .adds/koreader .adds/plato ; do + local current_folder="$KOBO_MOUNTPOINT/$kfm_folder" + if [[ -d "$current_folder" ]] ; then + printf "\t%s\n" "$current_folder" + else + printf "\t%-96s%32s\n" "$current_folder" "[OK: Already gone]" + fi + done + echo "* As well as the following files:" + for kfm_file in .kobo/KoboRoot.tgz kfmon.png koreader.png icons/plato.png ; do + local current_file="$KOBO_MOUNTPOINT/$kfm_file" + if [[ -f "$current_file" ]] ; then + printf "\t%s\n" "$current_file" + else + printf "\t%-96s%32s\n" "$current_file" "[OK: Already gone]" + fi + done + } + + KOBO_CONFIG="$KOBO_DIR/Kobo/Kobo eReader.conf" + echo "* Preventing Nickel from scanning hidden directories . . ." + cat >> "${KOBO_CONFIG}" <<-\EoM + + [FeatureSettings] + ExcludeSyncFolders=(\\.(?!kobo|adobe).+|([^.][^/]*/)+\\..+) + EoM + + # Check for a cat failure, as unlikely as it might be (permissions?)... + ret=$? + if [[ $ret -ne 0 ]] ; then + echo "* Installation FAILED: Failed to update Nickel config!" + echo "* No permanent changes have been made." + exit $ret + fi + + # Double-check that it was updated, in case of gremlins attack... + if ! grep -Fq 'ExcludeSyncFolders=(\\.(?!kobo|adobe).+|([^.][^/]*/)+\\..+)' "${KOBO_CONFIG}" ; then + echo "* Installation FAILED: Nickel config update was ineffective o_O !" + echo "* No permanent changes have been made." + exit 255 + fi + + echo "* Installing Kobo package" + rsync -vr "$INPUT/" "$KOBO_MOUNTPOINT" + + ret=$? + if [[ $ret -ne 0 ]]; then + echo "* Installation FAILED: Failed to copy archive!" + recap_failure + exit $ret + fi + + echo "* Sanity check . . ." + if [[ ! "$KOBO_DIR/KoboRoot.tgz" ]]; then + echo "* Installation FAILED: Copying was ineffective (no KoboRoot tarball) o_O !" + recap_failure + exit 255 + fi + + echo "* Installation successful!" + echo "* Please make sure to eject & unplug your device safely!" + + exit 0 + ''; +} diff --git a/pkgs/plato.nix b/pkgs/plato.nix new file mode 100644 index 0000000..815ac76 --- /dev/null +++ b/pkgs/plato.nix @@ -0,0 +1,46 @@ +{ stdenvNoCC +, formats +, runCommand +, writeScript +, lib + +, platoSrc +, platoSettings ? {} +, platoCfg ? "" +, dictionaries ? [] +, fonts ? [] +, ... }: +with builtins // lib; +stdenvNoCC.mkDerivation (finalAttrs: { + name = "plato"; + + src = platoSrc; + + dontFix = true; + dontPatch = true; + dontConfigure = true; + dontBuild = true; + + installPhase = '' + mkdir -p $out + cp -rv . $out + + # mkdir -p $out/.adds/plato/dictionaries + for d in ${concatMapStringsSep " " toString dictionaries}; do + find $d/share/dictd/ -type f -regex '.*\.\(dict\(\.dz\)?\|index\)' -exec cp -v {} $out/.adds/plato/dictionaries/ \; + done + + for d in ${concatMapStringsSep " " toString fonts}; do + find $d/share/fonts/truetype/ -type f -regex '.*\.\(ttf\|otf\)' -exec cp -v {} $out/.adds/plato/fonts/ \; + done + + ${optionalString (platoSettings != {}) '' + cp -v ${(formats.toml {}).generate "Settings.toml" platoSettings} $out/.adds/plato/Settings.toml + ''} + ${optionalString (platoCfg != "") '' + cp -v ${writeScript "config.sh" platoCfg} $out/.adds/plato/config.sh + ''} + '' + ; + +}) diff --git a/pkgs/source.nix b/pkgs/source.nix new file mode 100644 index 0000000..dcf40fe --- /dev/null +++ b/pkgs/source.nix @@ -0,0 +1,21 @@ +{ fetchzip, ... }: +{ + KOReader = fetchzip { + stripRoot = false; + url = "https://storage.gra.cloud.ovh.net/v1/AUTH_2ac4bfee353948ec8ea7fd1710574097/kfmon-pub/OCP-KOReader-v2024.01.zip"; + }; + Plato = fetchzip { + stripRoot = false; + url = "https://storage.gra.cloud.ovh.net/v1/AUTH_2ac4bfee353948ec8ea7fd1710574097/kfmon-pub/OCP-Plato-0.9.40.zip"; + sha256 = "sha256-jOCC3p9Q/DNtSADgMgmCwPvoZ4XA4ka1zH7dfg8r/kg="; + }; + KOReader-Plato = fetchzip { + stripRoot = false; + url = "https://storage.gra.cloud.ovh.net/v1/AUTH_2ac4bfee353948ec8ea7fd1710574097/kfmon-pub/OCP-Plato-0.9.40_KOReader-v2024.01.zip"; + sha256 = "sha256-A0ImPLQ+5/MLg5Iw3U3WnoKc2Cd/g6lSiSzAiBnrfZM="; + }; + KFMon = fetchzip { + stripRoot = false; + url = "https://storage.gra.cloud.ovh.net/v1/AUTH_2ac4bfee353948ec8ea7fd1710574097/kfmon-pub/OCP-KFMon-1.4.6-43-g2c54087.zip"; + }; +} -- cgit v1.2.3