feat: initial
This commit is contained in:
commit
bba9ceff39
18 changed files with 750 additions and 0 deletions
87
services/kiwix-updater.nix
Normal file
87
services/kiwix-updater.nix
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
# Import service data (make sure this path is correct)
|
||||
service_data = import ../data/services.nix;
|
||||
kiwix = service_data.kiwix;
|
||||
zimUrls = kiwix.urls;
|
||||
updater = pkgs.writeShellScriptBin "kiwix-updater" ''
|
||||
set -e
|
||||
|
||||
URLS=(
|
||||
${builtins.concatStringsSep " " zimUrls}
|
||||
)
|
||||
|
||||
download() {
|
||||
local url=''$1
|
||||
local filename=''$(basename "''$url")
|
||||
local filepath="${kiwix.root_dir}"/''$filename
|
||||
|
||||
if [ -f "''$filepath" ]; then
|
||||
echo "''$filepath exists!"
|
||||
return 0
|
||||
fi
|
||||
cd ${kiwix.root_dir}
|
||||
${pkgs.wget}/bin/wget --continue --quiet "''$url" -O "''$filename.tmp"
|
||||
mv ''$filename.tmp ''$filename
|
||||
}
|
||||
|
||||
build_lib() {
|
||||
{
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>'
|
||||
echo '<library>'
|
||||
for zim in "${kiwix.root_dir}"/*.zim; do
|
||||
if [ -f "''$zim" ]; then
|
||||
filename=''$(basename "''$zim")
|
||||
size=''$(stat -c%s "''$zim")
|
||||
case "''$filename" in
|
||||
*_en_*)
|
||||
title="English Wikipedia (Text Only)"
|
||||
lang="eng"
|
||||
;;
|
||||
*_de_*)
|
||||
title="German Wikipedia (Text Only)"
|
||||
lang="deu"
|
||||
;;
|
||||
*)
|
||||
title="''$filename"
|
||||
lang="unknown"
|
||||
;;
|
||||
esac
|
||||
cat << EOF
|
||||
<book id="''$filename" path="/data/''$filename" title="''$title" language="''$lang">
|
||||
<title>''$title</title>
|
||||
<language>''$lang</language>
|
||||
<path>/data/''$filename</path>
|
||||
<size>''$size</size>
|
||||
</book>
|
||||
EOF
|
||||
fi
|
||||
done
|
||||
echo '</library>'
|
||||
} > "${kiwix.root_dir}/library.xml.tmp"
|
||||
mv "${kiwix.root_dir}/library.xml.tmp" "${kiwix.root_dir}/library.xml"
|
||||
}
|
||||
|
||||
for url in "''${URLS[@]}"; do
|
||||
download "''$url"
|
||||
done
|
||||
|
||||
build_lib
|
||||
|
||||
${pkgs.systemd}/bin/systemctl restart podman-kiwix-serve.service
|
||||
'';
|
||||
in {
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
wget
|
||||
curl
|
||||
];
|
||||
|
||||
services.cron = {
|
||||
enable = true;
|
||||
systemCronJobs = [
|
||||
"0 3 * * * root ${updater}/bin/kiwix-updater >/dev/null 2>&1"
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue