|
| 1 | +#!/usr/bin/env bash |
| 2 | +source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/build.func) |
| 3 | +# Copyright (c) 2021-2026 community-scripts ORG |
| 4 | +# Author: tewalds |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://github.com/kiwix/kiwix-tools |
| 7 | + |
| 8 | +APP="Kiwix" |
| 9 | +var_tags="${var_tags:-documentation;offline}" |
| 10 | +var_cpu="${var_cpu:-1}" |
| 11 | +var_ram="${var_ram:-512}" |
| 12 | +var_disk="${var_disk:-4}" |
| 13 | +var_os="${var_os:-debian}" |
| 14 | +var_version="${var_version:-13}" |
| 15 | +var_unprivileged="${var_unprivileged:-1}" |
| 16 | + |
| 17 | +header_info "$APP" |
| 18 | +variables |
| 19 | +color |
| 20 | +catch_errors |
| 21 | + |
| 22 | +function update_script() { |
| 23 | + header_info |
| 24 | + check_container_storage |
| 25 | + check_container_resources |
| 26 | + |
| 27 | + CURRENT_VER=$(/usr/local/bin/kiwix-serve --version 2>&1 | grep -oP '\d+\.\d+\.\d+' | head -1) |
| 28 | + |
| 29 | + fetch_and_deploy_archive "https://download.kiwix.org/release/kiwix-tools/kiwix-tools_linux-x86_64.tar.gz" /usr/local/bin/ |
| 30 | + |
| 31 | + NEW_VER=$(/usr/local/bin/kiwix-serve --version 2>&1 | grep -oP '\d+\.\d+\.\d+' | head -1) |
| 32 | + |
| 33 | + if [[ "$CURRENT_VER" == "$NEW_VER" ]]; then |
| 34 | + msg_ok "Already on latest version: $CURRENT_VER" |
| 35 | + exit |
| 36 | + fi |
| 37 | + |
| 38 | + systemctl restart kiwix-serve |
| 39 | + msg_ok "Updated from $CURRENT_VER to $NEW_VER!" |
| 40 | + exit |
| 41 | +} |
| 42 | + |
| 43 | +start |
| 44 | +build_container |
| 45 | + |
| 46 | +msg_info "Validating ZIM directory." |
| 47 | +if [[ -z "${ZIM_DIR:-}" ]]; then |
| 48 | + msg_error "ZIM_DIR cannot be empty. Please run with ZIM_DIR=/path/to/zims" |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | +if [[ ! -d "$ZIM_DIR" ]]; then |
| 52 | + msg_error "Directory '$ZIM_DIR' does not exist." |
| 53 | + exit 1 |
| 54 | +fi |
| 55 | +if ! ls "${ZIM_DIR}"/*.zim >/dev/null 2>&1; then |
| 56 | + msg_error "No .zim files found in '$ZIM_DIR'" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | +msg_ok "Using ZIM directory: ${ZIM_DIR}" |
| 60 | + |
| 61 | +msg_info "Configuring Bind Mount" |
| 62 | + |
| 63 | +if pct set $CTID -features mountidmap=1 2>/dev/null; then |
| 64 | + msg_info "Enabled ID-mapped mounts (ownership preserved)" |
| 65 | + pct set $CTID -mp0 "$ZIM_DIR,mp=/data,ro=1" |
| 66 | + msg_ok "Bind Mount Configured (read-only, ownership preserved)" |
| 67 | +else |
| 68 | + msg_info "ID-mapped mounts not available, using standard mount" |
| 69 | + msg_info "Note: Files will appear as nobody:nogroup inside container" |
| 70 | + msg_info "Ensure ZIM files are world-readable: chmod -R a+rX ${ZIM_DIR}" |
| 71 | + pct set $CTID -mp0 "$ZIM_DIR,mp=/data" |
| 72 | + msg_ok "Bind Mount Configured (read-write mount, read-only service)" |
| 73 | +fi |
| 74 | + |
| 75 | +msg_info "Setting Container Options" |
| 76 | +pct set $CTID --onboot 1 |
| 77 | +msg_ok "Container Options Set" |
| 78 | + |
| 79 | +msg_ok "Completed Successfully!\n" |
| 80 | +IP=$(pct exec $CTID -- hostname -I | awk '{print $1}') |
| 81 | +echo -e "${TAB}${GATEWAY}${BGN}Web Interface:${CL} ${BL}http://${IP}:8080${CL}" |
| 82 | +echo -e "${TAB}${INFO}${BGN}ZIM Directory:${CL} ${ZIM_DIR} ${DGN}→${CL} ${BGN}/data${CL}" |
0 commit comments