commit b72326f0fbb7274e3c00cbd9a1c1c9e904c6af0a
parent dae0a9076acefe05777a41a67dbbef51b037ec7c
Author: breadcat <breadcat@users.noreply.github.com>
Date: Thu, 28 May 2026 13:13:38 +0100
Add pdfpassword variable and alter payslip script (again)
Diffstat:
6 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/common/home-manager.nix b/common/home-manager.nix
@@ -1,8 +1,8 @@
-{ machine, fullname, username, domain, email, sshkey, sshport, timezone, postcode, address, htpasswd, vpnusername, vpnpassword, todosecret, privatekey, matrixuser, matrixserver }:
+{ machine, fullname, username, domain, email, sshkey, sshport, timezone, postcode, address, htpasswd, vpnusername, vpnpassword, todosecret, pdfpassword, privatekey, matrixuser, matrixserver }:
let
home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-25.11.tar.gz";
- all-variables = { inherit machine fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret privatekey matrixuser matrixserver; };
+ all-variables = { inherit machine fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret pdfpassword privatekey matrixuser matrixserver; };
in
{
diff --git a/common/variables.nix b/common/variables.nix
@@ -1,7 +1,7 @@
-{ machine, fullname, username, domain, email, sshkey, sshport, timezone, postcode, address, htpasswd, vpnusername, vpnpassword, todosecret, privatekey, matrixuser, matrixserver }:
+{ machine, fullname, username, domain, email, sshkey, sshport, timezone, postcode, address, htpasswd, vpnusername, vpnpassword, todosecret, pdfpassword, privatekey, matrixuser, matrixserver }:
let
- all-variables = { inherit machine fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret privatekey matrixuser matrixserver; };
+ all-variables = { inherit machine fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret pdfpassword privatekey matrixuser matrixserver; };
in
{
diff --git a/entrypoint.nix b/entrypoint.nix
@@ -5,7 +5,7 @@
...
}: let
vars = import ./variables.nix { inherit lib; };
- inherit (vars) fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret privatekey matrixuser matrixserver;
+ inherit (vars) fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret pdfpassword privatekey matrixuser matrixserver;
hostname =
if builtins.pathExists "/etc/hostname"
@@ -16,6 +16,6 @@
osConfigPath = ./machines + "/${machine}.nix";
in {
imports = [
- (import osConfigPath { inherit config pkgs lib fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret privatekey matrixuser matrixserver ; })
+ (import osConfigPath { inherit config pkgs lib fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret pdfpassword privatekey matrixuser matrixserver ; })
];
}
\ No newline at end of file
diff --git a/machines/ilias.nix b/machines/ilias.nix
@@ -1,12 +1,12 @@
# NAS
-{ config, pkgs, lib, fullname, username, domain, email, sshkey, sshport, timezone, postcode, address, htpasswd, vpnusername, vpnpassword, todosecret, privatekey, matrixuser, matrixserver, ... }:
+{ config, pkgs, lib, fullname, username, domain, email, sshkey, sshport, timezone, postcode, address, htpasswd, vpnusername, vpnpassword, todosecret, pdfpassword, privatekey, matrixuser, matrixserver, ... }:
let machine = "ilias"; in {
imports = [
- (import ../common/variables.nix { inherit machine fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret privatekey matrixuser matrixserver; })
- (import ../common/home-manager.nix { inherit machine fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret privatekey matrixuser matrixserver; })
+ (import ../common/variables.nix { inherit machine fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret pdfpassword privatekey matrixuser matrixserver; })
+ (import ../common/home-manager.nix { inherit machine fullname username domain email sshkey sshport timezone postcode address htpasswd vpnusername vpnpassword todosecret pdfpassword privatekey matrixuser matrixserver; })
../common/boot-systemd.nix
../common/devel.nix
../common/flakes.nix
diff --git a/scripts/payslips.nix b/scripts/payslips.nix
@@ -1,33 +1,42 @@
-{ pkgs, ... }:
+{ pkgs, pdfpassword, ... }:
let
payslips = pkgs.writeShellScriptBin "payslips" ''
- # Default destination directory, or use argument
destination_default="/tank/paperwork/personal/workplace/wages"
destination_dir="''${1:-$destination_default}"
- pdftotext_bin="${pkgs.poppler-utils}/bin/pdftotext"
- # Process matching files
- for file in ./????????-????-????-????-????????????-result.pdf; do
- [[ -e "$file" ]] || continue # Skip if no match
+ mkdir -p "$destination_dir"
+
+ shopt -s nullglob
+
+ for file in ./*.PDF; do
filename=$(basename "$file")
- # Extract the date
- date=$("$pdftotext_bin" "$file" - | grep -oE '[0-9]{2}-[0-9]{2}-[0-9]{4}' | head -n1)
- if [[ "$date" =~ ^([0-9]{2})-([0-9]{2})-([0-9]{4})$ ]]; then
+
+ # Match: "10 - 31052026.PDF"
+ if [[ "$filename" =~ ^[0-9]+[[:space:]]-[[:space:]]([0-9]{2})([0-9]{2})([0-9]{4})\.PDF$ ]]; then
day="''${BASH_REMATCH[1]}"
month="''${BASH_REMATCH[2]}"
year="''${BASH_REMATCH[3]}"
+
new_filename="''${year}-''${month}-''${day}.pdf"
+ output_path="$destination_dir/$new_filename"
# Avoid overwriting existing files
- if [[ -e "$destination_dir/$new_filename" ]]; then
- new_filename="''${year}-''${month}-''${day}-$(date +%s).pdf"
+ if [[ -e "$output_path" ]]; then
+ output_path="$destination_dir/''${year}-''${month}-''${day}-$(date +%s).pdf"
fi
- mv "$file" "$destination_dir/$new_filename"
- echo "Moved: $file to $destination_dir/$new_filename"
+ # Remove PDF password protection
+ ${pkgs.qpdf}/bin/qpdf --password=${pdfpassword} --decrypt "$file" "$output_path"
+
+ if [[ $? -eq 0 ]]; then
+ rm "$file"
+ echo "Processed: $file -> $output_path"
+ else
+ echo "Failed to process: $file"
+ fi
else
- echo "Skipped (no valid date found in PDF): $filename"
+ echo "Skipped (filename did not match expected format): $filename"
fi
done
'';
diff --git a/variables.sample.nix b/variables.sample.nix
@@ -14,9 +14,10 @@ let
vpnusername = "";
vpnpassword = "";
todosecret = "JWTtoken";
+ pdfpassword = "";
privatekey = "path/to/private.key";
matrixuser = "";
matrixserver = "";
in {
- inherit fullname username domain email sshkey sshport timezone vpnusername vpnpassword todosecret privatekey matrixuser matrixserver;
+ inherit fullname username domain email sshkey sshport timezone vpnusername vpnpassword todosecret pdfpassword privatekey matrixuser matrixserver;
}
\ No newline at end of file