about summary refs log tree commit diff stats
path: root/home-manager/config/firefox/scripts
diff options
context:
space:
mode:
authorene <ene@sils.li>2023-02-17 16:51:44 +0100
committerene <ene@sils.li>2023-02-17 16:51:44 +0100
commit32d4278611a8e9a88ca54a27a072985087015039 (patch)
tree3f3d73e246be7ba75d1b368e50dcbc37c8429609 /home-manager/config/firefox/scripts
parentFeat(impermanence): Add full stack tempfs (diff)
downloadnixos-config-32d4278611a8e9a88ca54a27a072985087015039.tar.gz
nixos-config-32d4278611a8e9a88ca54a27a072985087015039.zip
Feat(home-manager): Move configs in their own directory
Diffstat (limited to 'home-manager/config/firefox/scripts')
-rwxr-xr-xhome-manager/config/firefox/scripts/unzip_mozlz4.py43
-rwxr-xr-xhome-manager/config/firefox/scripts/update_extensions20
2 files changed, 63 insertions, 0 deletions
diff --git a/home-manager/config/firefox/scripts/unzip_mozlz4.py b/home-manager/config/firefox/scripts/unzip_mozlz4.py
new file mode 100755
index 00000000..311fd214
--- /dev/null
+++ b/home-manager/config/firefox/scripts/unzip_mozlz4.py
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+# source: https://unix.stackexchange.com/a/497861
+# Command-line tool to decompress mozLz4 files used for example by Firefox to store various kinds of session backup information.
+# Works in both Python 2.7.15 and 3.6.7, as of version 2.1.6 of the LZ4 Python bindings at pypi.org/project/lz4.
+# To use in another script, simply cut and paste the import statement and the mozlz4_to_text() function (lines 8 to 17).
+
+import lz4.block  # pip install lz4 --user
+
+
+def mozlz4_to_text(filepath):
+    # Given the path to a "mozlz4", "jsonlz4", "baklz4" etc. file,
+    # return the uncompressed text.
+    bytestream = open(filepath, "rb")
+    bytestream.read(8)  # skip past the b"mozLz40\0" header
+    valid_bytes = bytestream.read()
+    text = lz4.block.decompress(valid_bytes)
+    return text
+
+
+def main(args):
+  # Given command-line arguments of an input filepath for a ".mozlz4" file
+  # and optionally an output filepath, write the decompressed text to the
+  # output filepath.
+  # Default output filepath is the input filepath minus the last three characters
+  # (e.g. "foo.jsonlz4" becomes "foo.json")
+  filepath_in = args[0]
+  if len(args) < 2:
+    filepath_out = filepath_in[:-3]
+  else:
+    filepath_out = args[1]
+  text = mozlz4_to_text(filepath_in)
+  with open(filepath_out, "wb") as outfile:
+    outfile.write(text)
+  print("Wrote decompressed text to {}".format(filepath_out))
+
+
+if __name__ == "__main__":
+  import sys
+  args = sys.argv[1:]
+  if args and not args[0] in ("--help", "-h"):
+    main(args)
+  else:
+    print("Usage: mozlz4.py <mozlz4 file to read> <location to write>")
diff --git a/home-manager/config/firefox/scripts/update_extensions b/home-manager/config/firefox/scripts/update_extensions
new file mode 100755
index 00000000..97f7c0ba
--- /dev/null
+++ b/home-manager/config/firefox/scripts/update_extensions
@@ -0,0 +1,20 @@
+#!/bin/sh
+# shellcheck disable=SC2086
+# shellcheck source=/dev/null
+. ~/.local/lib/shell/lib
+
+tmp=$(mktmp)
+cat << EOF > $tmp
+    darkreader
+    firenvim
+    keepassxc-browser
+    simple-tab-groups
+    ublock-origin
+EOF
+
+
+nix shell git+https://codeberg.org/ene/generate_moz_extension.git -c generate_extensions $(cat $tmp) > "$(dirname $0)"/../settings/extensions.json
+
+
+
+if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi