From f07266354e073fcb457c59c6a6523ea5fc880dfd Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 13 Apr 2025 12:09:39 -0400 Subject: chore: hoarder-linux.sh > karakeep-linux.sh v2.1 (#1219) * hoarder-linux.sh > karakeep-linux.sh v2.1 - Adds a migrate function so users can convert their Hoarder install to a Karakeep install - The function will also check for an update after finishing the migration - Various fixes and optimisations * Update docs with Debuntu migration path and replace Hoarder with Karakeep --- docs/docs/02-Installation/06-debuntu.md | 38 ++- .../14-Guides/04-hoarder-to-karakeep-migration.md | 10 + .../version-v0.23.1/02-Installation/06-debuntu.md | 38 ++- .../14-Guides/04-hoarder-to-karakeep-migration.md | 10 + hoarder-linux.sh | 310 ------------------ karakeep-linux.sh | 355 +++++++++++++++++++++ 6 files changed, 417 insertions(+), 344 deletions(-) delete mode 100644 hoarder-linux.sh create mode 100644 karakeep-linux.sh diff --git a/docs/docs/02-Installation/06-debuntu.md b/docs/docs/02-Installation/06-debuntu.md index 2c9c1901..2f3d1113 100644 --- a/docs/docs/02-Installation/06-debuntu.md +++ b/docs/docs/02-Installation/06-debuntu.md @@ -9,14 +9,14 @@ This script is a stripped-down version of those found in the [Proxmox Community - **Debian 12** (Buster) or - **Ubuntu 24.04** (Noble Numbat) -The script will download and install all dependencies (except for Ollama), install Hoarder, do a basic configuration of Hoarder and Meilisearch (the search app used by Hoarder), and create and enable the systemd service files needed to run Hoarder on startup. Hoarder and Meilisearch are run in the context of their low-privilege user environments for more security. +The script will download and install all dependencies (except for Ollama), install Karakeep, do a basic configuration of Karakeep and Meilisearch (the search app used by Karakeep), and create and enable the systemd service files needed to run Karakeep on startup. Karakeep and Meilisearch are run in the context of their low-privilege user environments for more security. The script functions as an update script in addition to an installer. See **[Updating](#updating)**. -### 1. Download the script from the [Hoarder repository](https://github.com/hoarder-app/hoarder/blob/main/hoarder-linux.sh). +### 1. Download the script from the [Karakeep repository](https://github.com/karakeep-app/karakeep/blob/main/karakeep-linux.sh) ``` -wget https://raw.githubusercontent.com/hoarder-app/hoarder/main/hoarder-linux.sh +wget https://raw.githubusercontent.com/karakeep-app/karakeep/main/karakeep-linux.sh ``` ### 2. Run the script @@ -26,10 +26,10 @@ wget https://raw.githubusercontent.com/hoarder-app/hoarder/main/hoarder-linux.sh If this is a fresh install, then run the installer by using the following command: ```shell - bash hoarder-linux.sh install + bash karakeep-linux.sh install ``` -### 3. Create an account/sign in! +### 3. Create an account/sign in Then visit `http://localhost:3000` and you should be greated with the Sign In page. @@ -37,34 +37,38 @@ wget https://raw.githubusercontent.com/hoarder-app/hoarder/main/hoarder-linux.sh > This script must be run as `root`, or as a user with `sudo` privileges. - If Hoarder has previously been installed using this script, then run the updater like so: + If Karakeep has previously been installed using this script, then run the updater like so: ```shell - bash hoarder-linux.sh update + bash karakeep-linux.sh update ``` ## Services and Ports -`hoarder.target` includes 4 services: `meilisearch.service`, `hoarder-web.service`, `hoarder-workers.service`, `hoarder-browser.service`. +`karakeep.target` includes 4 services: `meilisearch.service`, `karakeep-web.service`, `karakeep-workers.service`, `karakeep-browser.service`. -- `meilisearch.service`: Provides full-text search, Hoarder Workers service connects to it, uses port `7700` by default. +- `meilisearch.service`: Provides full-text search, Karakeep Workers service connects to it, uses port `7700` by default. -- `hoarder-web.service`: Provides the hoarder web service, uses `3000` port by default. +- `karakeep-web.service`: Provides the karakeep web service, uses `3000` port by default. -- `hoarder-workers.service`: Provides the hoarder workers service, no port. +- `karakeep-workers.service`: Provides the karakeep workers service, no port. -- `hoarder-browser.service`: Provides the headless browser service, uses `9222` port by default. +- `karakeep-browser.service`: Provides the headless browser service, uses `9222` port by default. ## Configuration, ENV file, database locations -During installation, the script created a configuration file for `meilisearch`, an `ENV` file for Hoarder, and located config paths and database paths separate from the installation path of Hoarder, so as to allow for easier updating. Their names/locations are as follows: +During installation, the script created a configuration file for `meilisearch`, an `ENV` file for Karakeep, and located config paths and database paths separate from the installation path of Karakeep, so as to allow for easier updating. Their names/locations are as follows: - `/etc/meilisearch.toml` - a basic configuration for meilisearch, that contains configs for the database location, disabling analytics, and using a master key, which prevents unauthorized connections. - `/var/lib/meilisearch` - Meilisearch DB location. -- `/etc/hoarder/hoarder.env` - The Hoarder `ENV` file. Edit this file to configure Hoarder beyond the default. The web service and the workers service need to be restarted after editing this file: - +- `/etc/karakeep/karakeep.env` - The Karakeep `ENV` file. Edit this file to configure Karakeep beyond the default. The web service and the workers service need to be restarted after editing this file: + ```shell - sudo systemctl restart hoarder-workers hoarder-web + sudo systemctl restart karakeep-workers karakeep-web ``` -- `/var/lib/hoarder` - The Hoarder database location. If you delete the contents of this folder you will lose all your data. +- `/var/lib/karakeep` - The Karakeep database location. If you delete the contents of this folder you will lose all your data. + +## Still Running Hoarder? + +There is a way to upgrade. Please see [Guides > Hoarder to Karakeep Migration](https://docs.karakeep.app/Guides/hoarder-to-karakeep-migration) diff --git a/docs/docs/14-Guides/04-hoarder-to-karakeep-migration.md b/docs/docs/14-Guides/04-hoarder-to-karakeep-migration.md index 1ac50c7c..289a091c 100644 --- a/docs/docs/14-Guides/04-hoarder-to-karakeep-migration.md +++ b/docs/docs/14-Guides/04-hoarder-to-karakeep-migration.md @@ -16,3 +16,13 @@ index cdfc908..6297563 100644 ``` You can also change the `HOARDER_VERSION` environment variable but if you do so remember to change it in the `.env` file as well. + +## Migrating a Baremetal Installation + +If you previously used the [Debian/Ubuntu install script](https://docs.karakeep.app/Installation/debuntu) to install Hoarder, there is an option to migrate your installation to Karakeep. + +```bash +bash karakeep-linux.sh migrate +``` + +This will migrate your installation with no user input required. After the migration, the script will also check for an update. diff --git a/docs/versioned_docs/version-v0.23.1/02-Installation/06-debuntu.md b/docs/versioned_docs/version-v0.23.1/02-Installation/06-debuntu.md index 2c9c1901..2f3d1113 100644 --- a/docs/versioned_docs/version-v0.23.1/02-Installation/06-debuntu.md +++ b/docs/versioned_docs/version-v0.23.1/02-Installation/06-debuntu.md @@ -9,14 +9,14 @@ This script is a stripped-down version of those found in the [Proxmox Community - **Debian 12** (Buster) or - **Ubuntu 24.04** (Noble Numbat) -The script will download and install all dependencies (except for Ollama), install Hoarder, do a basic configuration of Hoarder and Meilisearch (the search app used by Hoarder), and create and enable the systemd service files needed to run Hoarder on startup. Hoarder and Meilisearch are run in the context of their low-privilege user environments for more security. +The script will download and install all dependencies (except for Ollama), install Karakeep, do a basic configuration of Karakeep and Meilisearch (the search app used by Karakeep), and create and enable the systemd service files needed to run Karakeep on startup. Karakeep and Meilisearch are run in the context of their low-privilege user environments for more security. The script functions as an update script in addition to an installer. See **[Updating](#updating)**. -### 1. Download the script from the [Hoarder repository](https://github.com/hoarder-app/hoarder/blob/main/hoarder-linux.sh). +### 1. Download the script from the [Karakeep repository](https://github.com/karakeep-app/karakeep/blob/main/karakeep-linux.sh) ``` -wget https://raw.githubusercontent.com/hoarder-app/hoarder/main/hoarder-linux.sh +wget https://raw.githubusercontent.com/karakeep-app/karakeep/main/karakeep-linux.sh ``` ### 2. Run the script @@ -26,10 +26,10 @@ wget https://raw.githubusercontent.com/hoarder-app/hoarder/main/hoarder-linux.sh If this is a fresh install, then run the installer by using the following command: ```shell - bash hoarder-linux.sh install + bash karakeep-linux.sh install ``` -### 3. Create an account/sign in! +### 3. Create an account/sign in Then visit `http://localhost:3000` and you should be greated with the Sign In page. @@ -37,34 +37,38 @@ wget https://raw.githubusercontent.com/hoarder-app/hoarder/main/hoarder-linux.sh > This script must be run as `root`, or as a user with `sudo` privileges. - If Hoarder has previously been installed using this script, then run the updater like so: + If Karakeep has previously been installed using this script, then run the updater like so: ```shell - bash hoarder-linux.sh update + bash karakeep-linux.sh update ``` ## Services and Ports -`hoarder.target` includes 4 services: `meilisearch.service`, `hoarder-web.service`, `hoarder-workers.service`, `hoarder-browser.service`. +`karakeep.target` includes 4 services: `meilisearch.service`, `karakeep-web.service`, `karakeep-workers.service`, `karakeep-browser.service`. -- `meilisearch.service`: Provides full-text search, Hoarder Workers service connects to it, uses port `7700` by default. +- `meilisearch.service`: Provides full-text search, Karakeep Workers service connects to it, uses port `7700` by default. -- `hoarder-web.service`: Provides the hoarder web service, uses `3000` port by default. +- `karakeep-web.service`: Provides the karakeep web service, uses `3000` port by default. -- `hoarder-workers.service`: Provides the hoarder workers service, no port. +- `karakeep-workers.service`: Provides the karakeep workers service, no port. -- `hoarder-browser.service`: Provides the headless browser service, uses `9222` port by default. +- `karakeep-browser.service`: Provides the headless browser service, uses `9222` port by default. ## Configuration, ENV file, database locations -During installation, the script created a configuration file for `meilisearch`, an `ENV` file for Hoarder, and located config paths and database paths separate from the installation path of Hoarder, so as to allow for easier updating. Their names/locations are as follows: +During installation, the script created a configuration file for `meilisearch`, an `ENV` file for Karakeep, and located config paths and database paths separate from the installation path of Karakeep, so as to allow for easier updating. Their names/locations are as follows: - `/etc/meilisearch.toml` - a basic configuration for meilisearch, that contains configs for the database location, disabling analytics, and using a master key, which prevents unauthorized connections. - `/var/lib/meilisearch` - Meilisearch DB location. -- `/etc/hoarder/hoarder.env` - The Hoarder `ENV` file. Edit this file to configure Hoarder beyond the default. The web service and the workers service need to be restarted after editing this file: - +- `/etc/karakeep/karakeep.env` - The Karakeep `ENV` file. Edit this file to configure Karakeep beyond the default. The web service and the workers service need to be restarted after editing this file: + ```shell - sudo systemctl restart hoarder-workers hoarder-web + sudo systemctl restart karakeep-workers karakeep-web ``` -- `/var/lib/hoarder` - The Hoarder database location. If you delete the contents of this folder you will lose all your data. +- `/var/lib/karakeep` - The Karakeep database location. If you delete the contents of this folder you will lose all your data. + +## Still Running Hoarder? + +There is a way to upgrade. Please see [Guides > Hoarder to Karakeep Migration](https://docs.karakeep.app/Guides/hoarder-to-karakeep-migration) diff --git a/docs/versioned_docs/version-v0.23.1/14-Guides/04-hoarder-to-karakeep-migration.md b/docs/versioned_docs/version-v0.23.1/14-Guides/04-hoarder-to-karakeep-migration.md index 1ac50c7c..289a091c 100644 --- a/docs/versioned_docs/version-v0.23.1/14-Guides/04-hoarder-to-karakeep-migration.md +++ b/docs/versioned_docs/version-v0.23.1/14-Guides/04-hoarder-to-karakeep-migration.md @@ -16,3 +16,13 @@ index cdfc908..6297563 100644 ``` You can also change the `HOARDER_VERSION` environment variable but if you do so remember to change it in the `.env` file as well. + +## Migrating a Baremetal Installation + +If you previously used the [Debian/Ubuntu install script](https://docs.karakeep.app/Installation/debuntu) to install Hoarder, there is an option to migrate your installation to Karakeep. + +```bash +bash karakeep-linux.sh migrate +``` + +This will migrate your installation with no user input required. After the migration, the script will also check for an update. diff --git a/hoarder-linux.sh b/hoarder-linux.sh deleted file mode 100644 index 8a857091..00000000 --- a/hoarder-linux.sh +++ /dev/null @@ -1,310 +0,0 @@ -#!/usr/bin/env bash - -set -Eeuo pipefail - -# v2.0 -# Copyright 2024-2025 -# Author: vhsdream -# Adapted from: The Karakeep installation script from https://github.com/community-scripts/ProxmoxVE -# License: MIT - -# Basic error handling -trap 'catch $? $LINENO' ERR - -catch() { - if [ "$1" == 0 ]; then - return - fi - echo "Caught error $1 on line $2" -} - -OS="$( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release )" -INSTALL_DIR=/opt/hoarder -export DATA_DIR=/var/lib/hoarder -CONFIG_DIR=/etc/hoarder -LOG_DIR=/var/log/hoarder -ENV_FILE=${CONFIG_DIR}/hoarder.env - -install() { - echo "Karakeep installation for Debian 12/Ubuntu 24.04" && sleep 4 - echo "Installing Dependencies..." && sleep 1 - apt-get install --no-install-recommends -y \ - g++ \ - curl \ - build-essential \ - curl \ - sudo \ - unzip \ - gnupg \ - graphicsmagick \ - ghostscript \ - ca-certificates - if [[ "$OS" == "noble" ]]; then - apt-get install -y software-properties-common - add-apt-repository ppa:xtradeb/apps -y - apt-get install --no-install-recommends -y ungoogled-chromium yt-dlp - ln -s /usr/bin/ungoogled-chromium /usr/bin/chromium - else - apt-get install --no-install-recommends -y chromium - wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux -O /usr/bin/yt-dlp && chmod +x /usr/bin/yt-dlp - fi - - wget -q https://github.com/Y2Z/monolith/releases/latest/download/monolith-gnu-linux-x86_64 -O /usr/bin/monolith && chmod +x /usr/bin/monolith - wget -q https://github.com/meilisearch/meilisearch/releases/latest/download/meilisearch.deb && \ - DEBIAN_FRONTEND=noninteractive dpkg -i meilisearch.deb && rm meilisearch.deb - echo "Installed Dependencies" && sleep 1 - - echo "Installing Node.js..." - mkdir -p /etc/apt/keyrings - curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg - 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 - apt-get update - apt-get install -y nodejs - # https://github.com/hoarder-app/hoarder/issues/967 - npm install -g corepack@0.31.0 - echo "Installed Node.js" && sleep 1 - - echo "Installing Karakeep..." - mkdir -p $DATA_DIR - mkdir -p $CONFIG_DIR - mkdir -p $LOG_DIR - M_DATA_DIR=/var/lib/meilisearch - M_CONFIG_FILE=/etc/meilisearch.toml - RELEASE=$(curl -s https://api.github.com/repos/karakeep-app/karakeep/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') - cd /tmp - wget -q "https://github.com/karakeep-app/karakeep/archive/refs/tags/v${RELEASE}.zip" - unzip -q v${RELEASE}.zip - mv karakeep-${RELEASE} ${INSTALL_DIR} && cd ${INSTALL_DIR}/apps/web - corepack enable - export NEXT_TELEMETRY_DISABLED=1 - export PUPPETEER_SKIP_DOWNLOAD="true" - export CI="true" - pnpm i --frozen-lockfile - pnpm exec next build --experimental-build-mode compile - cd ${INSTALL_DIR}/apps/workers - pnpm i --frozen-lockfile - cd ${INSTALL_DIR}/apps/cli - pnpm i --frozen-lockfile - pnpm build - cd ${INSTALL_DIR}/packages/db - pnpm migrate - echo "Installed Karakeep" && sleep 1 - - echo "Creating configuration files..." - cd $INSTALL_DIR - MASTER_KEY="$(openssl rand -base64 12)" - cat <${M_CONFIG_FILE} -env = "production" -master_key = "$MASTER_KEY" -db_path = "${M_DATA_DIR}/data" -dump_dir = "${M_DATA_DIR}/dumps" -snapshot_dir = "${M_DATA_DIR}/snapshots" -no_analytics = true -EOF - chmod 600 $M_CONFIG_FILE - - KARAKEEP_SECRET="$(openssl rand -base64 36 | cut -c1-24)" - cat <${ENV_FILE} -NODE_ENV=production -SERVER_VERSION=${RELEASE} -NEXTAUTH_SECRET="${KARAKEEP_SECRET}" -NEXTAUTH_URL="http://localhost:3000" -DATA_DIR=${DATA_DIR} -MEILI_ADDR="http://127.0.0.1:7700" -MEILI_MASTER_KEY="${MASTER_KEY}" -BROWSER_WEB_URL="http://127.0.0.1:9222" -# CRAWLER_VIDEO_DOWNLOAD=true -# CRAWLER_VIDEO_DOWNLOAD_MAX_SIZE= -# OPENAI_API_KEY= -# OLLAMA_BASE_URL= -# INFERENCE_TEXT_MODEL= -# INFERENCE_IMAGE_MODEL= -EOF - chmod 600 $ENV_FILE - echo ${RELEASE} > ${INSTALL_DIR}/version.txt - echo "Configuration complete" && sleep 1 - - echo "Creating users and modifying permissions..." - useradd -U -s /usr/sbin/nologin -r -m -d "${M_DATA_DIR}" meilisearch - useradd -U -s /usr/sbin/nologin -r -M -d "${INSTALL_DIR}" hoarder - chown meilisearch:meilisearch "${M_CONFIG_FILE}" - chown -R hoarder:hoarder "${INSTALL_DIR}" "${CONFIG_DIR}" "${DATA_DIR}" "${LOG_DIR}" - echo "Users created, permissions modified" && sleep 1 - - echo "Creating service files..." - cat </etc/systemd/system/meilisearch.service -[Unit] -Description=MeiliSearch is a RESTful search API -Documentation=https://docs.meilisearch.com/ -After=network.target - -[Service] -User=meilisearch -Group=meilisearch -Restart=on-failure -WorkingDirectory=${M_DATA_DIR} -ExecStart=/usr/bin/meilisearch --config-file-path ${M_CONFIG_FILE} -NoNewPrivileges=true -ProtectHome=true -ReadWritePaths=${M_DATA_DIR} -ProtectSystem=full -ProtectHostname=true -ProtectControlGroups=true -ProtectKernelModules=true -ProtectKernelTunables=true -ProtectKernelLogs=true -ProtectClock=true -LockPersonality=true -RestrictRealtime=yes -RestrictNamespaces=yes -MemoryDenyWriteExecute=yes -PrivateDevices=yes -PrivateTmp=true -CapabilityBoundingSet= -RemoveIPC=true - -[Install] -WantedBy=multi-user.target -EOF - - cat </etc/systemd/system/hoarder-browser.service -[Unit] -Description=Hoarder headless browser -After=network.target - -[Service] -User=root -Restart=on-failure -ExecStart=/usr/bin/chromium --headless --no-sandbox --disable-gpu --disable-dev-shm-usage --remote-debugging-address=127.0.0.1 --remote-debugging-port=9222 --hide-scrollbars -TimeoutStopSec=5 -SyslogIdentifier=hoarder-browser - -[Install] -WantedBy=multi-user.target -EOF - - cat </etc/systemd/system/hoarder-workers.service -[Unit] -Description=Hoarder workers -Wants=network.target hoarder-browser.service meilisearch.service -After=network.target hoarder-browser.service meilisearch.service - -[Service] -User=hoarder -Group=hoarder -Restart=always -EnvironmentFile=${ENV_FILE} -WorkingDirectory=${INSTALL_DIR}/apps/workers -ExecStart=/usr/bin/pnpm run start:prod -StandardOutput=file:${LOG_DIR}/hoarder-workers.log -StandardError=file:${LOG_DIR}/hoarder-workers.log -TimeoutStopSec=5 -SyslogIdentifier=hoarder-workers - -[Install] -WantedBy=multi-user.target -EOF - - cat </etc/systemd/system/hoarder-web.service -[Unit] -Description=Hoarder web -Wants=network.target hoarder-workers.service -After=network.target hoarder-workers.service - -[Service] -User=hoarder -Group=hoarder -Restart=on-failure -EnvironmentFile=${ENV_FILE} -WorkingDirectory=${INSTALL_DIR}/apps/web -ExecStart=/usr/bin/pnpm start -StandardOutput=file:${LOG_DIR}/hoarder-web.log -StandardError=file:${LOG_DIR}/hoarder-web.log -TimeoutStopSec=5 -SyslogIdentifier=hoarder-web - -[Install] -WantedBy=multi-user.target -EOF - - cat </etc/systemd/system/hoarder.target -[Unit] -Description=Hoarder Services -After=network-online.target -Wants=meilisearch.service hoarder-browser.service hoarder-workers.service hoarder-web.service - -[Install] -WantedBy=multi-user.target -EOF - echo "Service files created" && sleep 1 - - echo "Enabling and starting services, please wait..." && sleep 3 - systemctl enable -q --now meilisearch.service hoarder.target - echo "Done" && sleep 1 - - echo "Cleaning up" && sleep 1 - rm /tmp/v${RELEASE}.zip - apt -y autoremove - apt -y autoclean - echo "Cleaned" && sleep 1 - - echo "OK, Karakeep should be accessible on port 3000 of this device's IP address!" && sleep 4 - exit 0 -} - -update() { - echo "Checking for an update..." && sleep 1 - if [[ ! -d ${INSTALL_DIR} ]]; then echo "Is Karakeep even installed?"; exit 1; fi - RELEASE=$(curl -s https://api.github.com/repos/karakeep-app/karakeep/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') - PREV_RELEASE=$(cat ${INSTALL_DIR}/version.txt) - if [[ "${RELEASE}" != "${PREV_RELEASE}" ]]; then - echo "Stopping affected services..." && sleep 1 - systemctl stop hoarder-web hoarder-workers - echo "Stopped services" && sleep 1 - - echo "Updating Karakeep to v${RELEASE}..." && sleep 1 - sed -i "s|SERVER_VERSION=${PREV_RELEASE}|SERVER_VERSION=${RELEASE}|" ${ENV_FILE} - rm -R ${INSTALL_DIR} - cd /tmp - wget -q "https://github.com/karakeep-app/karakeep/archive/refs/tags/v${RELEASE}.zip" - unzip -q v${RELEASE}.zip - mv karakeep-${RELEASE} ${INSTALL_DIR} - # https://github.com/hoarder-app/hoarder/issues/967 - if [[ $(corepack -v) < "0.31.0" ]]; then - npm install -g corepack@0.31.0 - fi - cd ${INSTALL_DIR}/apps/web && pnpm i --frozen-lockfile - pnpm exec next build --experimental-build-mode compile - cd ${INSTALL_DIR}/apps/workers && pnpm i --frozen-lockfile - cd ${INSTALL_DIR}/apps/cli && pnpm i --frozen-lockfile - pnpm build - cd ${INSTALL_DIR}/packages/db && pnpm migrate - echo "${RELEASE}" >${INSTALL_DIR}/version.txt - chown -R hoarder:hoarder ${INSTALL_DIR} ${DATA_DIR} - echo "Updated Karakeep to v${RELEASE}" && sleep 1 - echo "Restarting services and cleaning up..." && sleep 1 - systemctl start hoarder-workers hoarder-web - rm /tmp/v${RELEASE}.zip - echo "Ready!" - else - echo "No update required." - fi - exit 0 -} - -[ "$(id -u)" -ne 0 ] && echo "This script requires root privileges. Please run with sudo or as the root user." && exit 1 -command="${1:-}" -if [ -z "$command" ]; then - echo -e "Run script with 'install' to install Karakeep and 'update' to update Karakeep" && exit 1 -fi - -case "$command" in - install) - install - ;; - update) - update - ;; - *) - echo -e "Unknown command. Choose 'install' or 'update'" && exit 1 -esac diff --git a/karakeep-linux.sh b/karakeep-linux.sh new file mode 100644 index 00000000..4e7123df --- /dev/null +++ b/karakeep-linux.sh @@ -0,0 +1,355 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +# v2.1 +# Copyright 2024-2025 +# Author: vhsdream +# Adapted from: The Karakeep installation script from https://github.com/community-scripts/ProxmoxVE +# License: MIT + +# Basic error handling +trap 'catch $? $LINENO' ERR + +catch() { + if [ "$1" == 0 ]; then + return + fi + echo "Caught error $1 on line $2" +} + +OS="$(awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release)" +INSTALL_DIR=/opt/karakeep +export DATA_DIR=/var/lib/karakeep +CONFIG_DIR=/etc/karakeep +LOG_DIR=/var/log/karakeep +ENV_FILE=${CONFIG_DIR}/karakeep.env + +install() { + echo "Karakeep installation for Debian 12/Ubuntu 24.04" && sleep 4 + echo "Installing Dependencies..." && sleep 1 + apt-get install --no-install-recommends -y \ + g++ \ + curl \ + build-essential \ + sudo \ + unzip \ + gnupg \ + graphicsmagick \ + ghostscript \ + ca-certificates + if [[ "$OS" == "noble" ]]; then + apt-get install -y software-properties-common + add-apt-repository ppa:xtradeb/apps -y + apt-get install --no-install-recommends -y ungoogled-chromium yt-dlp + ln -s /usr/bin/ungoogled-chromium /usr/bin/chromium + else + apt-get install --no-install-recommends -y chromium + wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux -O /usr/bin/yt-dlp && chmod +x /usr/bin/yt-dlp + fi + + wget -q https://github.com/Y2Z/monolith/releases/latest/download/monolith-gnu-linux-x86_64 -O /usr/bin/monolith && chmod +x /usr/bin/monolith + wget -q https://github.com/meilisearch/meilisearch/releases/latest/download/meilisearch.deb && + DEBIAN_FRONTEND=noninteractive dpkg -i meilisearch.deb && rm meilisearch.deb + echo "Installed Dependencies" && sleep 1 + + echo "Installing Node.js..." + mkdir -p /etc/apt/keyrings + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg + 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 + apt-get update + apt-get install -y nodejs + # https://github.com/karakeep-app/karakeep/issues/967 + npm install -g corepack@0.31.0 + echo "Installed Node.js" && sleep 1 + + echo "Installing Karakeep..." + mkdir -p "$DATA_DIR" + mkdir -p "$CONFIG_DIR" + mkdir -p "$LOG_DIR" + M_DATA_DIR=/var/lib/meilisearch + M_CONFIG_FILE=/etc/meilisearch.toml + RELEASE=$(curl -s https://api.github.com/repos/karakeep-app/karakeep/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + cd /tmp + wget -q "https://github.com/karakeep-app/karakeep/archive/refs/tags/v${RELEASE}.zip" + unzip -q v"$RELEASE".zip + mv karakeep-"$RELEASE" "$INSTALL_DIR" && cd "$INSTALL_DIR"/apps/web + corepack enable + export NEXT_TELEMETRY_DISABLED=1 + export PUPPETEER_SKIP_DOWNLOAD="true" + export CI="true" + pnpm i --frozen-lockfile + pnpm exec next build --experimental-build-mode compile + cd "$INSTALL_DIR"/apps/workers + pnpm i --frozen-lockfile + cd "$INSTALL_DIR"/apps/cli + pnpm i --frozen-lockfile + pnpm build + cd "$INSTALL_DIR"/packages/db + pnpm migrate + echo "Installed Karakeep" && sleep 1 + + echo "Creating configuration files..." + cd "$INSTALL_DIR" + MASTER_KEY="$(openssl rand -base64 12)" + cat <${M_CONFIG_FILE} +env = "production" +master_key = "$MASTER_KEY" +db_path = "${M_DATA_DIR}/data" +dump_dir = "${M_DATA_DIR}/dumps" +snapshot_dir = "${M_DATA_DIR}/snapshots" +no_analytics = true +EOF + chmod 600 "$M_CONFIG_FILE" + + karakeep_SECRET="$(openssl rand -base64 36 | cut -c1-24)" + cat <${ENV_FILE} +NODE_ENV=production +SERVER_VERSION=${RELEASE} +NEXTAUTH_SECRET="${karakeep_SECRET}" +NEXTAUTH_URL="http://localhost:3000" +DATA_DIR=${DATA_DIR} +MEILI_ADDR="http://127.0.0.1:7700" +MEILI_MASTER_KEY="${MASTER_KEY}" +BROWSER_WEB_URL="http://127.0.0.1:9222" +# CRAWLER_VIDEO_DOWNLOAD=true +# CRAWLER_VIDEO_DOWNLOAD_MAX_SIZE= +# OPENAI_API_KEY= +# OLLAMA_BASE_URL= +# INFERENCE_TEXT_MODEL= +# INFERENCE_IMAGE_MODEL= +EOF + chmod 600 "$ENV_FILE" + echo "$RELEASE" >"$INSTALL_DIR"/version.txt + echo "Configuration complete" && sleep 1 + + echo "Creating users and modifying permissions..." + useradd -U -s /usr/sbin/nologin -r -m -d "$M_DATA_DIR" meilisearch + useradd -U -s /usr/sbin/nologin -r -M -d "$INSTALL_DIR" karakeep + chown meilisearch:meilisearch "$M_CONFIG_FILE" + chown -R karakeep:karakeep "$INSTALL_DIR" "$CONFIG_DIR" "$DATA_DIR" "$LOG_DIR" + echo "Users created, permissions modified" && sleep 1 + + echo "Creating service files..." + cat </etc/systemd/system/meilisearch.service +[Unit] +Description=MeiliSearch is a RESTful search API +Documentation=https://docs.meilisearch.com/ +After=network.target + +[Service] +User=meilisearch +Group=meilisearch +Restart=on-failure +WorkingDirectory=${M_DATA_DIR} +ExecStart=/usr/bin/meilisearch --config-file-path ${M_CONFIG_FILE} +NoNewPrivileges=true +ProtectHome=true +ReadWritePaths=${M_DATA_DIR} +ProtectSystem=full +ProtectHostname=true +ProtectControlGroups=true +ProtectKernelModules=true +ProtectKernelTunables=true +ProtectKernelLogs=true +ProtectClock=true +LockPersonality=true +RestrictRealtime=yes +RestrictNamespaces=yes +MemoryDenyWriteExecute=yes +PrivateDevices=yes +PrivateTmp=true +CapabilityBoundingSet= +RemoveIPC=true + +[Install] +WantedBy=multi-user.target +EOF + + cat </etc/systemd/system/karakeep-browser.service +[Unit] +Description=Karakeep headless browser +After=network.target + +[Service] +User=root +Restart=on-failure +ExecStart=/usr/bin/chromium --headless --no-sandbox --disable-gpu --disable-dev-shm-usage --remote-debugging-address=127.0.0.1 --remote-debugging-port=9222 --hide-scrollbars +TimeoutStopSec=5 +SyslogIdentifier=karakeep-browser + +[Install] +WantedBy=multi-user.target +EOF + + cat </etc/systemd/system/karakeep-workers.service +[Unit] +Description=Karakeep workers +Wants=network.target karakeep-browser.service meilisearch.service +After=network.target karakeep-browser.service meilisearch.service + +[Service] +User=karakeep +Group=karakeep +Restart=always +EnvironmentFile=${ENV_FILE} +WorkingDirectory=${INSTALL_DIR}/apps/workers +ExecStart=/usr/bin/pnpm run start:prod +StandardOutput=file:${LOG_DIR}/karakeep-workers.log +StandardError=file:${LOG_DIR}/karakeep-workers.log +TimeoutStopSec=5 +SyslogIdentifier=karakeep-workers + +[Install] +WantedBy=multi-user.target +EOF + + cat </etc/systemd/system/karakeep-web.service +[Unit] +Description=Karakeep web +Wants=network.target karakeep-workers.service +After=network.target karakeep-workers.service + +[Service] +User=karakeep +Group=karakeep +Restart=on-failure +EnvironmentFile=${ENV_FILE} +WorkingDirectory=${INSTALL_DIR}/apps/web +ExecStart=/usr/bin/pnpm start +StandardOutput=file:${LOG_DIR}/karakeep-web.log +StandardError=file:${LOG_DIR}/karakeep-web.log +TimeoutStopSec=5 +SyslogIdentifier=karakeep-web + +[Install] +WantedBy=multi-user.target +EOF + + cat </etc/systemd/system/karakeep.target +[Unit] +Description=Karakeep Services +After=network-online.target +Wants=meilisearch.service karakeep-browser.service karakeep-workers.service karakeep-web.service + +[Install] +WantedBy=multi-user.target +EOF + echo "Service files created" && sleep 1 + + echo "Enabling and starting services, please wait..." && sleep 3 + systemctl enable -q --now meilisearch.service karakeep.target + echo "Done" && sleep 1 + + echo "Cleaning up" && sleep 1 + rm /tmp/v"$RELEASE".zip + apt -y autoremove + apt -y autoclean + echo "Cleaned" && sleep 1 + + echo "OK, Karakeep should be accessible on port 3000 of this device's IP address!" && sleep 4 + exit 0 +} + +update() { + echo "Checking for an update..." && sleep 1 + if [[ ! -d ${INSTALL_DIR} ]]; then + echo "Is Karakeep even installed?" + exit 1 + fi + RELEASE=$(curl -s https://api.github.com/repos/karakeep-app/karakeep/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + PREV_RELEASE=$(cat "$INSTALL_DIR"/version.txt) + if [[ "$RELEASE" != "$PREV_RELEASE" ]]; then + if [[ "$(systemctl is-active karakeep-web)" == "active" ]]; then + echo "Stopping affected services..." && sleep 1 + systemctl stop karakeep-web karakeep-workers + echo "Stopped services" && sleep 1 + fi + echo "Updating Karakeep to v${RELEASE}..." && sleep 1 + sed -i "s|SERVER_VERSION=${PREV_RELEASE}|SERVER_VERSION=${RELEASE}|" "$ENV_FILE" + rm -R "$INSTALL_DIR" + cd /tmp + wget -q "https://github.com/karakeep-app/karakeep/archive/refs/tags/v${RELEASE}.zip" + unzip -q v"$RELEASE".zip + mv karakeep-"$RELEASE" "$INSTALL_DIR" + # https://github.com/karakeep-app/karakeep/issues/967 + if [[ $(corepack -v) < "0.31.0" ]]; then + npm install -g corepack@0.31.0 + fi + corepack enable + export NEXT_TELEMETRY_DISABLED=1 + export PUPPETEER_SKIP_DOWNLOAD="true" + export CI="true" + cd "$INSTALL_DIR"/apps/web && pnpm i --frozen-lockfile + pnpm exec next build --experimental-build-mode compile + cd "$INSTALL_DIR"/apps/workers && pnpm i --frozen-lockfile + cd "$INSTALL_DIR"/apps/cli && pnpm i --frozen-lockfile + pnpm build + cd "$INSTALL_DIR"/packages/db && pnpm migrate + echo "$RELEASE" >"$INSTALL_DIR"/version.txt + chown -R karakeep:karakeep "$INSTALL_DIR" "$DATA_DIR" + echo "Updated Karakeep to v${RELEASE}" && sleep 1 + echo "Restarting services and cleaning up..." && sleep 1 + systemctl start karakeep-workers karakeep-web + rm /tmp/v"$RELEASE".zip + echo "Ready!" + else + echo "No update required." + fi + exit 0 +} + +migrate() { + if [[ ! -d /opt/karakeep ]]; then + echo "Migrating your Hoarder installation to Karakeep, then checking for an update..." && sleep 3 + systemctl stop hoarder-browser hoarder-workers hoarder-web + sed -i -e "s|hoarder|karakeep|g" /etc/hoarder/hoarder.env /etc/systemd/system/hoarder-{browser,web,workers}.service /etc/systemd/system/hoarder.target \ + -e "s|Hoarder|Karakeep|g" /etc/systemd/system/hoarder-{browser,web,workers}.service /etc/systemd/system/hoarder.target + for path in /etc/systemd/system/hoarder*.service; do + new_path="${path//hoarder/karakeep}" + mv "$path" "$new_path" + done + mv /etc/systemd/system/hoarder.target /etc/systemd/system/karakeep.target + mv /opt/hoarder "$INSTALL_DIR" + mv /var/lib/hoarder "$DATA_DIR" + mv /etc/hoarder "$CONFIG_DIR" + mv /var/log/hoarder "$LOG_DIR" + mv "$CONFIG_DIR"/hoarder.env "$ENV_FILE" + mv "$LOG_DIR"/hoarder-web.log "$LOG_DIR"/karakeep-web.log + mv "$LOG_DIR"/hoarder-workers.log "$LOG_DIR"/karakeep-workers.log + usermod -l karakeep hoarder -d "$INSTALL_DIR" + groupmod -n karakeep hoarder + chown -R karakeep:karakeep "$INSTALL_DIR" "$CONFIG_DIR" "$DATA_DIR" "$LOG_DIR" + systemctl daemon-reload + systemctl -q enable --now karakeep.target + echo "Migration complete!" && sleep 2 + else + echo "There is no need for a migration: Karakeep is already installed." + exit 1 + fi +} + +[ "$(id -u)" -ne 0 ] && echo "This script requires root privileges. Please run with sudo or as the root user." && exit 1 +command="${1:-}" +if [ "$command" = "" ]; then + echo -e "\nRun script with:\r +parameter 'install' to install Karakeep\r +parameter 'update' to update Karakeep\r +parameter 'migrate' to migrate your Hoarder install to Karakeep\n +Note: 'migrate' will also update to the latest version if necessary" && exit 1 +fi + +case "$command" in +install) + install + ;; +update) + update + ;; +migrate) + migrate && update + ;; +*) + echo -e "Unknown command. Choose 'install', 'update' or 'migrate'." && exit 1 + ;; +esac -- cgit v1.2.3-70-g09d2