aboutsummaryrefslogtreecommitdiff
path: root/pkgs
diff options
context:
space:
mode:
authorChris Wells <chris@mathematicaster.org>2024-09-10 14:51:28 -0500
committerChris Wells <chris@mathematicaster.org>2024-09-10 14:51:28 -0500
commit4f471484b3a1e16230979a8406503a220b9101f4 (patch)
treedc3f5256f275f34d3bcc9573462ed34c7fd97f77 /pkgs
parent5cb16c34a8c5b803ec723934c1dc828c0e8e3bad (diff)
downloadkobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar
kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.gz
kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.bz2
kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.lz
kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.xz
kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.zst
kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.zip
I think this is almost working!
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/firmware/default.nix8
-rw-r--r--pkgs/install.nix110
-rw-r--r--pkgs/misc/create-koboroot.nix5
-rw-r--r--pkgs/misc/deploy.nix65
-rw-r--r--pkgs/misc/merge.nix10
-rw-r--r--pkgs/plato.nix46
-rw-r--r--pkgs/source.nix21
7 files changed, 79 insertions, 186 deletions
diff --git a/pkgs/firmware/default.nix b/pkgs/firmware/default.nix
index 8403abb..e33cf4a 100644
--- a/pkgs/firmware/default.nix
+++ b/pkgs/firmware/default.nix
@@ -1,4 +1,4 @@
-{ stdenvNoCC, fetchzip, lib, kobo-utils, gawk, ... }:
+{ stdenvNoCC, fetchzip, lib, rsync, kobo-utils, gawk, ... }:
{ hardware, date, version, hash ? "", ... }:
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "kobo-firmware";
@@ -13,6 +13,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
nativeBuildInputs = [
kobo-utils
gawk
+ rsync
];
outputs = [
@@ -39,10 +40,9 @@ stdenvNoCC.mkDerivation (finalAttrs: {
installPhase = ''
runHook preInstall
- cp -r $src $out
- rm $out/KoboRoot.tgz
+ rsync -av --links --exclude="KoboRoot.tgz" $src/ $out
- mkdir $KoboROot
+ mkdir $KoboRoot
tar xvzf $src/KoboRoot.tgz --directory=$KoboRoot
runHook postInstall
diff --git a/pkgs/install.nix b/pkgs/install.nix
deleted file mode 100644
index e25108d..0000000
--- a/pkgs/install.nix
+++ /dev/null
@@ -1,110 +0,0 @@
-{ 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/misc/create-koboroot.nix b/pkgs/misc/create-koboroot.nix
new file mode 100644
index 0000000..7cf1bff
--- /dev/null
+++ b/pkgs/misc/create-koboroot.nix
@@ -0,0 +1,5 @@
+{ runCommandLocal, ... }: p:
+runCommand "mk-koboroot" {} ''
+ mkdir -p $out
+ tar czvf --mode=u+w $out/KoboRoot.tgz "${p}"
+''
diff --git a/pkgs/misc/deploy.nix b/pkgs/misc/deploy.nix
new file mode 100644
index 0000000..23973e9
--- /dev/null
+++ b/pkgs/misc/deploy.nix
@@ -0,0 +1,65 @@
+{ stdenvNoCC, writeShellApplication, makeWrapper, rsync, kobo-utils, lib, ... }:
+src:
+let
+ deployScript = writeShellApplication {
+ name = "deploy";
+ runtimeInputs = [
+ rsync
+ kobo-utils
+ ];
+ text = ''
+ PAYLOAD="./payload"
+
+ if [[ ! -d "$PAYLOAD" ]]; then
+ >&2 echo "./payload is not a directory I can copy..."
+ exit 1
+ fi
+
+ KOBOMNT="$(kobo-find -f -w)"
+ KOBODIR="$KOBOMNT/.kobo"
+
+ if [[ -z "$KOBOMNT" ]]; then
+ >&2 echo "Cannot find mounted kobo"
+ exit 1
+ elif [[ ! -d "$KOBODIR" ]]; then
+ >&2 echo "$KOBODIR does not appear to exist. Is this really a kobo?"
+ exit 1
+ fi
+
+ echo "Deploying payload"
+
+ rsync -rv --executability --chmod=u+w "$PAYLOAD/" "$KOBODIR"
+ '';
+ };
+in stdenvNoCC.mkDerivation (finalAttrs: {
+ name = "deploy-kobo";
+
+ inherit src;
+
+ nativeBuildInputs = [
+ makeWrapper
+ ];
+
+ buildInputs = [
+ kobo-utils
+ rsync
+ ];
+
+ phases = "installPhase";
+
+ installPhase = ''
+ runHook preInstall
+
+ mkdir -p $out
+ cp -r $src $out/payload
+
+ mkdir -p $out/bin
+ makeWrapper "${lib.getExe deployScript}" $out/bin/deploy --chdir "$out"
+
+ runHook postInstall
+ '';
+
+ meta = {
+ mainProgram = "deploy";
+ };
+})
diff --git a/pkgs/misc/merge.nix b/pkgs/misc/merge.nix
index 9d6eabb..b4b4892 100644
--- a/pkgs/misc/merge.nix
+++ b/pkgs/misc/merge.nix
@@ -1,7 +1,7 @@
{ runCommand, writeShellApplication, rsync, lib, ... }:
args@{ name, paths, preferLocalBuild ? true, allowSubstitutes ? false, postBuild ? "" }:
let
- env = builtins.removeAttrs args [ "name" "postBuild" ]] // {
+ env = builtins.removeAttrs args [ "name" "postBuild" ] // {
inherit preferLocalBuild allowSubstitutes;
nativeBuildInputs = (args.nativeBuildInputs or []) ++ [
rsync
@@ -28,8 +28,7 @@ let
case "$REALPATH" in
"/nix/store/"* )
- echo "Replacing $FILE by $REALPATH"
- cp -v --remove-destination "$REALPATH" "$FILE"
+ cp -vf --remove-destination "$REALPATH" "$FILE"
;;
esac
'';
@@ -39,10 +38,11 @@ in runCommand name env ''
mkdir -p $out
for i in $(cat $pathsPath); do
- rsync -rv --copy-dirlinks --links --executability "$i/" "$out"
+ rsync -rv --copy-dirlinks --links --executability --chmod=u+w "$i/" "$out"
done
- find $out -type l -exec "replaceBadSymlink {}" \;
+ find $out/ -type l -exec replaceBadSymlink {} \;
+
${postBuild}
''
diff --git a/pkgs/plato.nix b/pkgs/plato.nix
deleted file mode 100644
index 815ac76..0000000
--- a/pkgs/plato.nix
+++ /dev/null
@@ -1,46 +0,0 @@
-{ 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
deleted file mode 100644
index dcf40fe..0000000
--- a/pkgs/source.nix
+++ /dev/null
@@ -1,21 +0,0 @@
-{ 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";
- };
-}