|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: Slaviša Arežina (tremor021) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://openarchiver.com/ |
| 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 dependendencies" |
| 17 | +$STD apt install -y valkey |
| 18 | +msg_ok "Installed dependendencies" |
| 19 | + |
| 20 | +NODE_VERSION="22" NODE_MODULE="pnpm" setup_nodejs |
| 21 | +PG_VERSION="17" setup_postgresql |
| 22 | +fetch_and_deploy_gh_release "meilisearch" "meilisearch/meilisearch" "binary" |
| 23 | +fetch_and_deploy_gh_release "openarchiver" "LogicLabs-OU/OpenArchiver" "tarball" |
| 24 | +JWT_KEY="$(openssl rand -hex 32)" |
| 25 | +SECRET_KEY="$(openssl rand -hex 32)" |
| 26 | +IP_ADDR=$(hostname -I | awk '{print $1}') |
| 27 | + |
| 28 | +msg_info "Setting up PostgreSQL" |
| 29 | +DB_NAME="openarchiver_db" |
| 30 | +DB_USER="openarchiver" |
| 31 | +DB_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-18)" |
| 32 | +$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" |
| 33 | +$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;" |
| 34 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';" |
| 35 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';" |
| 36 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC';" |
| 37 | +{ |
| 38 | + echo "Open Archiver DB Credentials" |
| 39 | + echo "Database Name: $DB_NAME" |
| 40 | + echo "Database User: $DB_USER" |
| 41 | + echo "Database Password: $DB_PASS" |
| 42 | +} >>~/openarchiver.creds |
| 43 | +msg_ok "Set up PostgreSQL" |
| 44 | + |
| 45 | +msg_info "Configuring MeiliSearch" |
| 46 | +curl -fsSL https://raw.githubusercontent.com/meilisearch/meilisearch/latest/config.toml -o /etc/meilisearch.toml |
| 47 | +MASTER_KEY=$(openssl rand -base64 12) |
| 48 | +sed -i \ |
| 49 | + -e 's|^env =.*|env = "production"|' \ |
| 50 | + -e "s|^# master_key =.*|master_key = \"$MASTER_KEY\"|" \ |
| 51 | + -e 's|^db_path =.*|db_path = "/var/lib/meilisearch/data"|' \ |
| 52 | + -e 's|^dump_dir =.*|dump_dir = "/var/lib/meilisearch/dumps"|' \ |
| 53 | + -e 's|^snapshot_dir =.*|snapshot_dir = "/var/lib/meilisearch/snapshots"|' \ |
| 54 | + -e 's|^# no_analytics = true|no_analytics = true|' \ |
| 55 | + -e 's|^http_addr =.*|http_addr = "127.0.0.1:7700"|' \ |
| 56 | + /etc/meilisearch.toml |
| 57 | + |
| 58 | +cat <<EOF >/etc/systemd/system/meilisearch.service |
| 59 | +[Unit] |
| 60 | +Description=Meilisearch |
| 61 | +After=network.target |
| 62 | +
|
| 63 | +[Service] |
| 64 | +ExecStart=/usr/bin/meilisearch --config-file-path /etc/meilisearch.toml |
| 65 | +Restart=always |
| 66 | +
|
| 67 | +[Install] |
| 68 | +WantedBy=multi-user.target |
| 69 | +EOF |
| 70 | +systemctl enable -q --now meilisearch |
| 71 | +sleep 5 |
| 72 | +msg_ok "Configured MeiliSearch" |
| 73 | + |
| 74 | +msg_info "Setting up Open Archiver" |
| 75 | +mkdir -p /opt/openarchiver-data |
| 76 | +cd /opt/openarchiver |
| 77 | +cp .env.example .env |
| 78 | +sed -i "s|^NODE_ENV=.*|NODE_ENV=production|g" /opt/openarchiver/.env |
| 79 | +sed -i "s|^POSTGRES_DB=.*|POSTGRES_DB=openarchiver_db|g" /opt/openarchiver/.env |
| 80 | +sed -i "s|^POSTGRES_USER=.*|POSTGRES_USER=openarchiver|g" /opt/openarchiver/.env |
| 81 | +sed -i "s|^POSTGRES_PASSWORD=.*|POSTGRES_PASSWORD=$DB_PASS|g" /opt/openarchiver/.env |
| 82 | +sed -i "s|^DATABASE_URL=.*|DATABASE_URL=\"postgresql://openarchiver:$DB_PASS@localhost:5432/openarchiver_db\"|g" /opt/openarchiver/.env |
| 83 | +sed -i "s|^MEILI_HOST=.*|MEILI_HOST=http://localhost:7700|g" /opt/openarchiver/.env |
| 84 | +sed -i "s|^MEILI_MASTER_KEY=.*|MEILI_MASTER_KEY=$MASTER_KEY|g" /opt/openarchiver/.env |
| 85 | +sed -i "s|^REDIS_HOST=.*|REDIS_HOST=localhost|g" /opt/openarchiver/.env |
| 86 | +sed -i "s|^REDIS_PASSWORD=.*|REDIS_PASSWORD=|g" /opt/openarchiver/.env |
| 87 | +sed -i "s|^STORAGE_LOCAL_ROOT_PATH=.*|STORAGE_LOCAL_ROOT_PATH=/opt/openarchiver-data|g" /opt/openarchiver/.env |
| 88 | +sed -i "s|^JWT_SECRET=.*|JWT_SECRET=$JWT_KEY|g" /opt/openarchiver/.env |
| 89 | +sed -i "s|^ENCRYPTION_KEY=.*|ENCRYPTION_KEY=$SECRET_KEY|g" /opt/openarchiver/.env |
| 90 | +sed -i "s|^TIKA_URL=.*|TIKA_URL=|g" /opt/openarchiver/.env |
| 91 | +echo "ORIGIN=http://$IP_ADDR:3000" >> /opt/openarchiver/.env |
| 92 | +$STD pnpm install --shamefully-hoist --frozen-lockfile --prod=false |
| 93 | +$STD pnpm build |
| 94 | +$STD pnpm db:migrate |
| 95 | +msg_ok "Setup Open Archiver" |
| 96 | + |
| 97 | +msg_info "Creating Service" |
| 98 | +cat <<EOF >/etc/systemd/system/openarchiver.service |
| 99 | +[Unit] |
| 100 | +Description=Open Archiver Service |
| 101 | +After=network-online.target |
| 102 | +
|
| 103 | +[Service] |
| 104 | +Type=simple |
| 105 | +User=root |
| 106 | +EnvironmentFile=/opt/openarchiver/.env |
| 107 | +WorkingDirectory=/opt/openarchiver |
| 108 | +ExecStart=/usr/bin/pnpm docker-start |
| 109 | +Restart=on-failure |
| 110 | +
|
| 111 | +[Install] |
| 112 | +WantedBy=multi-user.target |
| 113 | +EOF |
| 114 | +systemctl enable -q --now openarchiver |
| 115 | +msg_ok "Created Service" |
| 116 | + |
| 117 | +motd_ssh |
| 118 | +customize |
| 119 | + |
| 120 | +msg_info "Cleaning up" |
| 121 | +$STD apt -y autoremove |
| 122 | +$STD apt -y autoclean |
| 123 | +$STD apt -y clean |
| 124 | +msg_ok "Cleaned" |
0 commit comments