|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: MickLesk (CanbiZ) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE |
| 6 | +# Source: https://github.com/icereed/paperless-gpt |
| 7 | + |
| 8 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +msg_info "Installing Dependencies" |
| 17 | +$STD apt-get install -y \ |
| 18 | + sudo \ |
| 19 | + curl \ |
| 20 | + mc \ |
| 21 | + gcc \ |
| 22 | + gnupg \ |
| 23 | + ca-certificates \ |
| 24 | + musl-dev \ |
| 25 | + mupdf \ |
| 26 | + libc6-dev \ |
| 27 | + musl-tools |
| 28 | +msg_ok "Installed Dependencies" |
| 29 | + |
| 30 | +msg_info "Setting up Node.js Repository" |
| 31 | +mkdir -p /etc/apt/keyrings |
| 32 | +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg |
| 33 | +echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >/etc/apt/sources.list.d/nodesource.list |
| 34 | +msg_ok "Set up Node.js Repository" |
| 35 | + |
| 36 | +msg_info "Installing Node.js" |
| 37 | +$STD apt-get update |
| 38 | +$STD apt-get install -y nodejs |
| 39 | +msg_ok "Installed Node.js" |
| 40 | + |
| 41 | +msg_info "Installing Golang" |
| 42 | +set +o pipefail |
| 43 | +temp_file=$(mktemp) |
| 44 | +golang_tarball=$(curl -s https://go.dev/dl/ | grep -oP 'go[\d\.]+\.linux-amd64\.tar\.gz' | head -n 1) |
| 45 | +wget -q https://golang.org/dl/"$golang_tarball" -O "$temp_file" |
| 46 | +tar -C /usr/local -xzf "$temp_file" |
| 47 | +ln -sf /usr/local/go/bin/go /usr/local/bin/go |
| 48 | +rm -f "$temp_file" |
| 49 | +set -o pipefail |
| 50 | +msg_ok "Installed Golang" |
| 51 | + |
| 52 | +msg_info "Setup Paperless-GPT" |
| 53 | +temp_file=$(mktemp) |
| 54 | +RELEASE=$(curl -s https://api.github.com/repos/icereed/paperless-gpt/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') |
| 55 | +wget -q "https://github.com/icereed/paperless-gpt/archive/refs/tags/v${RELEASE}.tar.gz" -O $temp_file |
| 56 | +tar zxf $temp_file |
| 57 | +mv paperless-gpt-${RELEASE} /opt/paperless-gpt |
| 58 | +cd /opt/paperless-gpt/web-app |
| 59 | +$STD npm install |
| 60 | +$STD npm run build |
| 61 | +cd /opt/paperless-gpt |
| 62 | +go mod download |
| 63 | +export CC=musl-gcc |
| 64 | +CGO_ENABLED=1 go build -tags musl -o /dev/null github.com/mattn/go-sqlite3 |
| 65 | +CGO_ENABLED=1 go build -tags musl -o paperless-gpt . |
| 66 | +echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" |
| 67 | +msg_ok "Setup Paperless-GPT" |
| 68 | + |
| 69 | +mkdir -p /opt/paperless-gpt-data |
| 70 | +read -p "Do you want to enter the Paperless local URL now? (y/n) " input_url |
| 71 | +if [[ "$input_url" =~ ^[Yy]$ ]]; then |
| 72 | + read -p "Enter your Paperless-NGX instance URL (e.g., http://192.168.1.100:8000): " PAPERLESS_BASE_URL |
| 73 | +else |
| 74 | + PAPERLESS_BASE_URL="http://your_paperless_ngx_url" |
| 75 | +fi |
| 76 | + |
| 77 | +read -p "Do you want to enter the Paperless API token now? (y/n) " input_token |
| 78 | +if [[ "$input_token" =~ ^[Yy]$ ]]; then |
| 79 | + read -p "Enter your Paperless API token: " PAPERLESS_API_TOKEN |
| 80 | +else |
| 81 | + PAPERLESS_API_TOKEN="your_paperless_api_token" |
| 82 | +fi |
| 83 | + |
| 84 | +msg_info "Setup Environment" |
| 85 | +cat <<EOF >/opt/paperless-gpt-data/.env |
| 86 | +PAPERLESS_BASE_URL=$PAPERLESS_BASE_URL |
| 87 | +PAPERLESS_API_TOKEN=$PAPERLESS_API_TOKEN |
| 88 | +
|
| 89 | +LLM_PROVIDER=openai |
| 90 | +LLM_MODEL=gpt-4o |
| 91 | +OPENAI_API_KEY=your_openai_api_key |
| 92 | +
|
| 93 | +#VISION_LLM_PROVIDER=ollama |
| 94 | +#VISION_LLM_MODEL=minicpm-v |
| 95 | +
|
| 96 | +LLM_LANGUAGE=English |
| 97 | +LOG_LEVEL=info |
| 98 | +
|
| 99 | +LISTEN_INTERFACE=:8080 |
| 100 | +
|
| 101 | +AUTO_TAG=paperless-gpt-auto |
| 102 | +MANUAL_TAG=paperless-gpt |
| 103 | +AUTO_OCR_TAG=paperless-gpt-ocr-auto |
| 104 | +
|
| 105 | +OCR_LIMIT_PAGES=5 |
| 106 | +EOF |
| 107 | +msg_ok "Setup Environment" |
| 108 | + |
| 109 | +msg_info "Creating Service" |
| 110 | +cat <<EOF >/etc/systemd/system/paperless-gpt.service |
| 111 | +[Unit] |
| 112 | +Description=Paperless-GPT |
| 113 | +After=network.target |
| 114 | +
|
| 115 | +[Service] |
| 116 | +Type=simple |
| 117 | +WorkingDirectory=/opt/paperless-gpt |
| 118 | +ExecStart=/opt/paperless-gpt/paperless-gpt |
| 119 | +Restart=always |
| 120 | +User=root |
| 121 | +EnvironmentFile=/opt/paperless-gpt-data/.env |
| 122 | +
|
| 123 | +[Install] |
| 124 | +WantedBy=multi-user.target |
| 125 | +EOF |
| 126 | +systemctl enable -q --now paperless-gpt |
| 127 | +msg_ok "Created Service" |
| 128 | + |
| 129 | +motd_ssh |
| 130 | +customize |
| 131 | + |
| 132 | +msg_info "Cleaning up" |
| 133 | +rm -f $temp_file |
| 134 | +$STD apt-get -y autoremove |
| 135 | +$STD apt-get -y autoclean |
| 136 | +msg_ok "Cleaned" |
0 commit comments