|
| 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/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://github.com/documenso/documenso |
| 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 "Setup Functions" |
| 17 | +setup_local_ip_helper |
| 18 | +import_local_ip |
| 19 | +msg_ok "Setup Functions" |
| 20 | + |
| 21 | +msg_info "Installing Dependencies" |
| 22 | +$STD apt-get install -y \ |
| 23 | + gpg \ |
| 24 | + libc6 \ |
| 25 | + make \ |
| 26 | + cmake \ |
| 27 | + jq \ |
| 28 | + postgresql \ |
| 29 | + python3 \ |
| 30 | + python3-bcrypt |
| 31 | +msg_ok "Installed Dependencies" |
| 32 | + |
| 33 | +msg_info "Setting up Node.js Repository" |
| 34 | +mkdir -p /etc/apt/keyrings |
| 35 | +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg |
| 36 | +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 |
| 37 | +msg_ok "Set up Node.js Repository" |
| 38 | + |
| 39 | +msg_info "Installing Node.js" |
| 40 | +$STD apt-get update |
| 41 | +$STD apt-get install -y nodejs |
| 42 | +$STD npm install -g [email protected] |
| 43 | +msg_ok "Installed Node.js" |
| 44 | + |
| 45 | +msg_info "Setting up PostgreSQL" |
| 46 | +DB_NAME="documenso_db" |
| 47 | +DB_USER="documenso_user" |
| 48 | +DB_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)" |
| 49 | +$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" |
| 50 | +$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;" |
| 51 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';" |
| 52 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';" |
| 53 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC'" |
| 54 | +{ |
| 55 | + echo "Documenso-Credentials" |
| 56 | + echo "Database Name: $DB_NAME" |
| 57 | + echo "Database User: $DB_USER" |
| 58 | + echo "Database Password: $DB_PASS" |
| 59 | +} >>~/documenso.creds |
| 60 | +msg_ok "Set up PostgreSQL" |
| 61 | + |
| 62 | +msg_info "Installing Documenso (Patience)" |
| 63 | +cd /opt |
| 64 | +RELEASE=$(curl -fsSL https://api.github.com/repos/documenso/documenso/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') |
| 65 | +curl -fsSL "https://github.com/documenso/documenso/archive/refs/tags/v${RELEASE}.zip" -o v${RELEASE}.zip |
| 66 | +unzip -q v${RELEASE}.zip |
| 67 | +mv documenso-${RELEASE} /opt/documenso |
| 68 | +cd /opt/documenso |
| 69 | +mv .env.example /opt/documenso/.env |
| 70 | +sed -i \ |
| 71 | + -e "s|^NEXTAUTH_SECRET=.*|NEXTAUTH_SECRET='$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)'|" \ |
| 72 | + -e "s|^NEXT_PRIVATE_ENCRYPTION_KEY=.*|NEXT_PRIVATE_ENCRYPTION_KEY='$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)'|" \ |
| 73 | + -e "s|^NEXT_PRIVATE_ENCRYPTION_SECONDARY_KEY=.*|NEXT_PRIVATE_ENCRYPTION_SECONDARY_KEY='$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)'|" \ |
| 74 | + -e "s|^DOCUMENSO_ENCRYPTION_KEY=.*|DOCUMENSO_ENCRYPTION_KEY='$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)'|" \ |
| 75 | + -e "s|^DOCUMENSO_ENCRYPTION_SECONDARY_KEY=.*|DOCUMENSO_ENCRYPTION_SECONDARY_KEY='$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)'|" \ |
| 76 | + -e "s|^NEXTAUTH_URL=.*|NEXTAUTH_URL=\"http://${LOCAL_IP}:3000\"|" \ |
| 77 | + -e "s|^NEXT_PUBLIC_WEBAPP_URL=.*|NEXT_PUBLIC_WEBAPP_URL='http://${LOCAL_IP}:9000'|" \ |
| 78 | + -e "s|^NEXT_PUBLIC_MARKETING_URL=.*|NEXT_PUBLIC_MARKETING_URL=\"http://${LOCAL_IP}:3001\"|" \ |
| 79 | + -e "s|^NEXT_PRIVATE_INTERNAL_WEBAPP_URL=.*|NEXT_PRIVATE_INTERNAL_WEBAPP_URL=\"http://${LOCAL_IP}:3000\"|" \ |
| 80 | + -e "s|^NEXT_PRIVATE_DATABASE_URL=.*|NEXT_PRIVATE_DATABASE_URL=\"postgres://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME\"|" \ |
| 81 | + -e "s|^NEXT_PRIVATE_DIRECT_DATABASE_URL=.*|NEXT_PRIVATE_DIRECT_DATABASE_URL=\"postgres://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME\"|" \ |
| 82 | + /opt/documenso/.env |
| 83 | +export TURBO_CACHE=1 |
| 84 | +export NEXT_TELEMETRY_DISABLED=1 |
| 85 | +export CYPRESS_INSTALL_BINARY=0 |
| 86 | +export NODE_OPTIONS="--max-old-space-size=4096" |
| 87 | +$STD npm ci |
| 88 | +$STD npm run build:web |
| 89 | +$STD npm run prisma:migrate-deploy |
| 90 | +echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" |
| 91 | +msg_ok "Installed Documenso" |
| 92 | + |
| 93 | +msg_info "Create User" |
| 94 | +PASSWORD_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b'helper-scripts', bcrypt.gensalt(rounds=12)).decode())") |
| 95 | +sudo -u postgres psql -d documenso_db -c "INSERT INTO \"User\" (name, email, \"emailVerified\", password, \"identityProvider\", roles, \"createdAt\", \"lastSignedIn\", \"updatedAt\", \"customerId\") VALUES ('helper-scripts', '[email protected]', '2025-01-20 17:14:45.058', '$PASSWORD_HASH', 'DOCUMENSO', ARRAY['USER', 'ADMIN']::\"Role\"[], '2025-01-20 16:04:05.543', '2025-01-20 16:14:55.249', '2025-01-20 16:14:55.25', NULL) RETURNING id;" |
| 96 | +$STD npm run prisma:migrate-deploy |
| 97 | +msg_ok "User created" |
| 98 | + |
| 99 | +msg_info "Creating Service" |
| 100 | +cat <<EOF >/etc/systemd/system/documenso.service |
| 101 | +[Unit] |
| 102 | +Description=Documenso Service |
| 103 | +After=network.target postgresql.service |
| 104 | +
|
| 105 | +[Service] |
| 106 | +WorkingDirectory=/opt/documenso/apps/web |
| 107 | +ExecStart=/usr/bin/npm start |
| 108 | +Restart=always |
| 109 | +EnvironmentFile=/opt/documenso/.env |
| 110 | +
|
| 111 | +[Install] |
| 112 | +WantedBy=multi-user.target |
| 113 | +EOF |
| 114 | +systemctl enable -q --now documenso |
| 115 | +msg_ok "Created Service" |
| 116 | + |
| 117 | +motd_ssh |
| 118 | +customize |
| 119 | + |
| 120 | +msg_info "Cleaning up" |
| 121 | +$STD apt-get -y autoremove |
| 122 | +$STD apt-get -y autoclean |
| 123 | +msg_ok "Cleaned" |
0 commit comments