|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2026 community-scripts ORG |
| 4 | +# Author: MickLesk (CanbiZ) |
| 5 | +# License: MIT | https://github.com/community-scripts/DevScripts/raw/main/LICENSE |
| 6 | +# Source: https://github.com/OpnForm/OpnForm |
| 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 install -y \ |
| 18 | + nginx \ |
| 19 | + redis-server |
| 20 | +msg_ok "Installed Dependencies" |
| 21 | + |
| 22 | +PG_VERSION="17" setup_postgresql |
| 23 | +PG_DB_NAME="opnform" PG_DB_USER="opnform" PG_DB_CREDS_FILE="/dev/null" setup_postgresql_db |
| 24 | +PHP_VERSION="8.3" PHP_FPM="YES" PHP_MEMORY_LIMIT="1G" PHP_UPLOAD_MAX_FILESIZE="64M" PHP_POST_MAX_SIZE="64M" PHP_MAX_EXECUTION_TIME="600" setup_php |
| 25 | +setup_composer |
| 26 | +NODE_VERSION="24" setup_nodejs |
| 27 | +fetch_and_deploy_gh_release "opnform" "OpnForm/OpnForm" "tarball" |
| 28 | + |
| 29 | +msg_info "Configuring OpnForm" |
| 30 | +FRONT_API_SECRET=$(random_password 40) |
| 31 | +mkdir -p /opt/opnform_data |
| 32 | +mv /opt/opnform/api/storage /opt/opnform_data/storage |
| 33 | +ln -s /opt/opnform_data/storage /opt/opnform/api/storage |
| 34 | +cat <<EOF >/opt/opnform_data/api.env |
| 35 | +APP_NAME="OpnForm" |
| 36 | +APP_ENV=production |
| 37 | +APP_KEY= |
| 38 | +APP_DEBUG=false |
| 39 | +APP_URL=http://${LOCAL_IP} |
| 40 | +FRONT_URL=http://${LOCAL_IP} |
| 41 | +FRONT_API_SECRET=${FRONT_API_SECRET} |
| 42 | +
|
| 43 | +LOG_CHANNEL=daily |
| 44 | +LOG_LEVEL=warning |
| 45 | +
|
| 46 | +DB_CONNECTION=pgsql |
| 47 | +DB_HOST=127.0.0.1 |
| 48 | +DB_PORT=5432 |
| 49 | +DB_DATABASE=opnform |
| 50 | +DB_USERNAME=opnform |
| 51 | +DB_PASSWORD=${PG_DB_PASS} |
| 52 | +
|
| 53 | +REDIS_HOST=127.0.0.1 |
| 54 | +REDIS_PORT=6379 |
| 55 | +CACHE_DRIVER=redis |
| 56 | +QUEUE_CONNECTION=redis |
| 57 | +SESSION_DRIVER=redis |
| 58 | +
|
| 59 | +FILESYSTEM_DRIVER=local |
| 60 | +LOCAL_FILESYSTEM_VISIBILITY=public |
| 61 | +
|
| 62 | +MAIL_MAILER=log |
| 63 | +MAIL_HOST= |
| 64 | +MAIL_PORT= |
| 65 | +MAIL_USERNAME= |
| 66 | +MAIL_PASSWORD= |
| 67 | +MAIL_ENCRYPTION= |
| 68 | +MAIL_FROM_ADDRESS=forms@example.com |
| 69 | +MAIL_FROM_NAME=OpnForm |
| 70 | +
|
| 71 | +JWT_TTL=1440 |
| 72 | +JWT_SECRET=$(random_password 40) |
| 73 | +JWT_SKIP_IP_UA_VALIDATION=false |
| 74 | +PUBLIC_UPLOADS_RATE_LIMIT_PER_MINUTE=30 |
| 75 | +PUBLIC_UPLOADS_RATE_LIMIT_PER_HOUR=300 |
| 76 | +
|
| 77 | +TRUSTED_PROXIES= |
| 78 | +SHOW_OFFICIAL_TEMPLATES=true |
| 79 | +EOF |
| 80 | +cat <<EOF >/opt/opnform_data/client.env |
| 81 | +NODE_ENV=production |
| 82 | +NITRO_HOST=127.0.0.1 |
| 83 | +NITRO_PORT=3000 |
| 84 | +NUXT_PUBLIC_APP_URL=/ |
| 85 | +NUXT_PUBLIC_API_BASE=/api |
| 86 | +NUXT_PRIVATE_API_BASE=http://127.0.0.1/api |
| 87 | +NUXT_PUBLIC_ENV=dev |
| 88 | +NUXT_API_SECRET=${FRONT_API_SECRET} |
| 89 | +NUXT_PUBLIC_H_CAPTCHA_SITE_KEY= |
| 90 | +NUXT_PUBLIC_RE_CAPTCHA_SITE_KEY= |
| 91 | +NUXT_PUBLIC_ROOT_REDIRECT_URL= |
| 92 | +EOF |
| 93 | +chmod 600 /opt/opnform_data/api.env /opt/opnform_data/client.env |
| 94 | +ln -sf /opt/opnform_data/api.env /opt/opnform/api/.env |
| 95 | +msg_ok "Configured OpnForm" |
| 96 | + |
| 97 | +msg_info "Building OpnForm API" |
| 98 | +cd /opt/opnform/api |
| 99 | +$STD composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader |
| 100 | +$STD php artisan key:generate --force |
| 101 | +$STD php artisan storage:link |
| 102 | +$STD php artisan migrate --force |
| 103 | +$STD php artisan passport:keys --force |
| 104 | +$STD php artisan telemetry:initialize-instance |
| 105 | +$STD php artisan optimize |
| 106 | +chown -R www-data:www-data /opt/opnform/api /opt/opnform_data/storage /opt/opnform_data/api.env |
| 107 | +chmod 600 /opt/opnform_data/storage/oauth-private.key |
| 108 | +msg_ok "Built OpnForm API" |
| 109 | + |
| 110 | +msg_info "Building OpnForm Client" |
| 111 | +cd /opt/opnform/client |
| 112 | +export NODE_OPTIONS="--max-old-space-size=4096" NUXT_TELEMETRY_DISABLED=1 |
| 113 | +$STD npm ci |
| 114 | +$STD npm run build |
| 115 | +rm -rf /opt/opnform/client/node_modules |
| 116 | +msg_ok "Built OpnForm Client" |
| 117 | + |
| 118 | +msg_info "Configuring Nginx" |
| 119 | +PHP_SOCK=$(get_php_fpm_socket) |
| 120 | +cat <<EOF >/etc/nginx/sites-available/opnform |
| 121 | +map \$request_uri \$opnform_api_uri { |
| 122 | + ~^/api(/.*\$) \$1; |
| 123 | + default \$request_uri; |
| 124 | +} |
| 125 | +
|
| 126 | +server { |
| 127 | + listen 80; |
| 128 | + listen [::]:80; |
| 129 | + server_name _; |
| 130 | + root /opt/opnform/api/public; |
| 131 | + index index.html index.htm index.php; |
| 132 | + client_max_body_size 64m; |
| 133 | +
|
| 134 | + location / { |
| 135 | + proxy_http_version 1.1; |
| 136 | + proxy_pass http://127.0.0.1:3000; |
| 137 | + proxy_set_header Host \$host; |
| 138 | + proxy_set_header X-Real-IP \$remote_addr; |
| 139 | + proxy_set_header X-Forwarded-Host \$host; |
| 140 | + proxy_set_header X-Forwarded-Port \$server_port; |
| 141 | + proxy_set_header Upgrade \$http_upgrade; |
| 142 | + proxy_set_header Connection "Upgrade"; |
| 143 | + } |
| 144 | +
|
| 145 | + location ^~ /api/_nuxt_icon/ { |
| 146 | + proxy_http_version 1.1; |
| 147 | + proxy_pass http://127.0.0.1:3000; |
| 148 | + proxy_set_header Host \$host; |
| 149 | + proxy_set_header X-Real-IP \$remote_addr; |
| 150 | + proxy_set_header X-Forwarded-Host \$host; |
| 151 | + proxy_set_header X-Forwarded-Port \$server_port; |
| 152 | + } |
| 153 | +
|
| 154 | + location ~/(api|open|local\/temp|forms\/assets)/ { |
| 155 | + try_files \$uri \$uri/ /index.php\$is_args\$args; |
| 156 | + } |
| 157 | +
|
| 158 | + location ~ \.php\$ { |
| 159 | + fastcgi_split_path_info ^(.+\.php)(/.+)\$; |
| 160 | + fastcgi_pass unix:${PHP_SOCK}; |
| 161 | + fastcgi_index index.php; |
| 162 | + include fastcgi_params; |
| 163 | + fastcgi_param SCRIPT_FILENAME \$document_root/index.php; |
| 164 | + fastcgi_param REQUEST_URI \$opnform_api_uri; |
| 165 | + } |
| 166 | +
|
| 167 | + location ~ /\. { |
| 168 | + deny all; |
| 169 | + } |
| 170 | +} |
| 171 | +EOF |
| 172 | +nginx_enable_site "opnform" |
| 173 | +msg_ok "Configured Nginx" |
| 174 | + |
| 175 | +msg_info "Creating Services" |
| 176 | +cat <<EOF >/etc/systemd/system/opnform-client.service |
| 177 | +[Unit] |
| 178 | +Description=OpnForm Client |
| 179 | +After=network.target |
| 180 | +
|
| 181 | +[Service] |
| 182 | +Type=simple |
| 183 | +WorkingDirectory=/opt/opnform/client |
| 184 | +EnvironmentFile=/opt/opnform_data/client.env |
| 185 | +ExecStart=/usr/bin/node .output/server/index.mjs |
| 186 | +Restart=on-failure |
| 187 | +RestartSec=5 |
| 188 | +
|
| 189 | +[Install] |
| 190 | +WantedBy=multi-user.target |
| 191 | +EOF |
| 192 | +cat <<EOF >/etc/systemd/system/opnform-worker.service |
| 193 | +[Unit] |
| 194 | +Description=OpnForm Queue Worker |
| 195 | +After=network.target postgresql.service redis-server.service |
| 196 | +
|
| 197 | +[Service] |
| 198 | +Type=simple |
| 199 | +User=www-data |
| 200 | +WorkingDirectory=/opt/opnform/api |
| 201 | +ExecStart=/usr/bin/php artisan queue:work |
| 202 | +Restart=always |
| 203 | +RestartSec=5 |
| 204 | +
|
| 205 | +[Install] |
| 206 | +WantedBy=multi-user.target |
| 207 | +EOF |
| 208 | +cat <<EOF >/etc/systemd/system/opnform-scheduler.service |
| 209 | +[Unit] |
| 210 | +Description=OpnForm Scheduler |
| 211 | +After=network.target postgresql.service redis-server.service |
| 212 | +
|
| 213 | +[Service] |
| 214 | +Type=simple |
| 215 | +User=www-data |
| 216 | +WorkingDirectory=/opt/opnform/api |
| 217 | +ExecStart=/usr/bin/php artisan schedule:work |
| 218 | +Restart=always |
| 219 | +RestartSec=5 |
| 220 | +
|
| 221 | +[Install] |
| 222 | +WantedBy=multi-user.target |
| 223 | +EOF |
| 224 | +systemctl enable -q --now redis-server opnform-client opnform-worker opnform-scheduler |
| 225 | +msg_ok "Created Services" |
| 226 | + |
| 227 | +motd_ssh |
| 228 | +customize |
| 229 | +cleanup_lxc |
0 commit comments