From c1c997577102e6e331942523e439d6d0448f6278 Mon Sep 17 00:00:00 2001 From: MickLesk Date: Wed, 3 Jun 2026 09:13:16 +0200 Subject: [PATCH] Add Kiwix container installer and metadata Introduce a complete Kiwix LXC installer: ct/kiwix.sh (container template) and install/kiwix-install.sh (in-container install). The installer installs kiwix-tools from the Kiwix PPA, creates a systemd kiwix-serve service to serve /data/*.zim on port 8080, records the package version in /root/.kiwix, and includes an update_script to upgrade kiwix-tools. The container template validates a provided ZIM_DATA directory, configures a bind mount (using ID-mapped mounts if available), sets container options, and prints the service URL. Also add json/kiwix.json catalog metadata with usage notes (including ZIM_DATA usage and file permission guidance). --- ct/kiwix.sh | 100 +++++++++++++++++++++++++++++++++++++++ install/kiwix-install.sh | 52 ++++++++++++++++++++ json/kiwix.json | 44 +++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 ct/kiwix.sh create mode 100644 install/kiwix-install.sh create mode 100644 json/kiwix.json diff --git a/ct/kiwix.sh b/ct/kiwix.sh new file mode 100644 index 00000000..cd7d2006 --- /dev/null +++ b/ct/kiwix.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/build.func) +# Copyright (c) 2021-2026 community-scripts ORG +# Author: tewalds +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/kiwix/kiwix-tools + +APP="Kiwix" +var_tags="${var_tags:-documentation;offline}" +var_cpu="${var_cpu:-1}" +var_ram="${var_ram:-512}" +var_disk="${var_disk:-4}" +var_os="${var_os:-ubuntu}" +var_version="${var_version:-24.04}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + header_info + check_container_storage + check_container_resources + + if ! dpkg -s kiwix-tools &>/dev/null; then + msg_error "No ${APP} Installation Found!" + exit + fi + + CURRENT=$(cat /root/.kiwix 2>/dev/null || dpkg -s kiwix-tools 2>/dev/null | awk '/^Version:/{print $2}') + + msg_info "Stopping Service" + systemctl stop kiwix-serve + msg_ok "Stopped Service" + + msg_info "Updating Kiwix-Tools" + $STD apt update + $STD apt install -y --only-upgrade kiwix-tools + RELEASE=$(dpkg -s kiwix-tools 2>/dev/null | awk '/^Version:/{print $2}') + echo "${RELEASE}" >/root/.kiwix + msg_ok "Updated Kiwix-Tools" + + if [[ "$CURRENT" == "$RELEASE" ]]; then + msg_ok "Already on latest version: ${CURRENT}" + else + msg_ok "Updated successfully from ${CURRENT} to ${RELEASE}!" + fi + + msg_info "Starting Service" + systemctl start kiwix-serve + msg_ok "Started Service" + exit +} + +start +build_container + +msg_info "Validating ZIM directory." +if [[ -z "${ZIM_DATA:-}" ]]; then + msg_error "ZIM_DATA cannot be empty. Please run with ZIM_DATA=/path/to/zims" + exit 1 +fi +if [[ ! -d "$ZIM_DATA" ]]; then + msg_error "Directory '$ZIM_DATA' does not exist." + exit 1 +fi +if ! ls "${ZIM_DATA}"/*.zim >/dev/null 2>&1; then + msg_error "No .zim files found in '$ZIM_DATA'" + exit 1 +fi +msg_ok "Using ZIM directory: ${ZIM_DATA}" + +msg_info "Configuring Bind Mount" + +if pct set $CTID -features mountidmap=1 2>/dev/null; then + msg_info "Enabled ID-mapped mounts (ownership preserved)" + pct set $CTID -mp0 "$ZIM_DATA,mp=/data,ro=1" + msg_ok "Bind Mount Configured (read-only, ownership preserved)" +else + msg_info "ID-mapped mounts not available, using standard mount" + msg_info "Note: Files will appear as nobody:nogroup inside container" + msg_info "Ensure ZIM files are world-readable: chmod -R a+rX ${ZIM_DATA}" + pct set $CTID -mp0 "$ZIM_DATA,mp=/data" + msg_ok "Bind Mount Configured (read-write mount, read-only service)" +fi + +msg_info "Starting Service" +pct exec $CTID -- systemctl start kiwix-serve +msg_ok "Started Service" + +msg_info "Setting Container Options" +pct set $CTID --onboot 1 +msg_ok "Container Options Set" + +msg_ok "Completed Successfully!\n" +IP=$(pct exec $CTID -- hostname -I | awk '{print $1}') +echo -e "${TAB}${GATEWAY}${BGN}Web Interface:${CL} ${BL}http://${IP}:8080${CL}" +echo -e "${TAB}${INFO}${BGN}ZIM Directory:${CL} ${ZIM_DATA} ${DGN}→${CL} ${BGN}/data${CL}" diff --git a/install/kiwix-install.sh b/install/kiwix-install.sh new file mode 100644 index 00000000..3dcb66c0 --- /dev/null +++ b/install/kiwix-install.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# Copyright (c) 2021-2026 community-scripts ORG +# Author: tewalds +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/kiwix/kiwix-tools + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt install -y software-properties-common +msg_ok "Installed Dependencies" + +msg_info "Adding Kiwix PPA" +add-apt-repository -y ppa:kiwixteam/release >>"$(get_active_logfile)" 2>&1 +$STD apt update +msg_ok "Added Kiwix PPA" + +msg_info "Installing Kiwix-Tools" +$STD apt install -y kiwix-tools +RELEASE=$(dpkg -s kiwix-tools 2>/dev/null | awk '/^Version:/{print $2}') +echo "${RELEASE}" >/root/.kiwix +msg_ok "Installed Kiwix-Tools ${RELEASE}" + +mkdir -p /data + +msg_info "Creating Service" +cat <<'EOF' >/etc/systemd/system/kiwix-serve.service +[Unit] +Description=Kiwix ZIM Server +After=network.target + +[Service] +Type=simple +ExecStart=/bin/sh -c 'exec /usr/bin/kiwix-serve --port 8080 /data/*.zim' +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable kiwix-serve +msg_ok "Created Service" + +motd_ssh +customize +cleanup_lxc diff --git a/json/kiwix.json b/json/kiwix.json new file mode 100644 index 00000000..c1c697e5 --- /dev/null +++ b/json/kiwix.json @@ -0,0 +1,44 @@ +{ + "name": "Kiwix", + "slug": "kiwix", + "categories": [ + 0 + ], + "date_created": "2026-02-11", + "type": "ct", + "updateable": true, + "privileged": false, + "interface_port": 8080, + "documentation": "https://wiki.kiwix.org", + "website": "https://www.kiwix.org", + "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons@main/webp/kiwix.webp", + "description": "Offline content browser serving Wikipedia, Project Gutenberg, and more from ZIM archives", + "config_path": "", + "install_methods": [ + { + "type": "default", + "script": "ct/kiwix.sh", + "resources": { + "cpu": 1, + "ram": 512, + "hdd": 4, + "os": "Ubuntu", + "version": "24.04" + } + } + ], + "default_credentials": { + "username": null, + "password": null + }, + "notes": [ + { + "text": "Requires a bind-mounted directory with ZIM archives. Download some from https://library.kiwix.org to /your/zims. The installation command is then: `ZIM_DATA=/your/zims bash -c \"$(curl .../ct/kiwix.sh)\"`.", + "type": "info" + }, + { + "text": "Ensure ZIM files are world-readable: chmod -R a+rX /your/zims", + "type": "warning" + } + ] +} \ No newline at end of file