|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 3 | +# SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +# Only create a config file if HP_SHARED_KEY is set. |
| 8 | +if [ -n "$HP_SHARED_KEY" ]; then |
| 9 | + echo "HP_SHARED_KEY is set, creating /frpc.toml configuration file..." |
| 10 | + if [ -d "/certs/frp" ]; then |
| 11 | + echo "Found /certs/frp directory. Creating configuration with TLS certificates." |
| 12 | + cat <<EOF > /frpc.toml |
| 13 | +serverAddr = "$HP_FRP_ADDRESS" |
| 14 | +serverPort = $HP_FRP_PORT |
| 15 | +loginFailExit = false |
| 16 | +
|
| 17 | +transport.tls.enable = true |
| 18 | +transport.tls.certFile = "/certs/frp/client.crt" |
| 19 | +transport.tls.keyFile = "/certs/frp/client.key" |
| 20 | +transport.tls.trustedCaFile = "/certs/frp/ca.crt" |
| 21 | +transport.tls.serverName = "harp.nc" |
| 22 | +
|
| 23 | +metadatas.token = "$HP_SHARED_KEY" |
| 24 | +
|
| 25 | +[[proxies]] |
| 26 | +remotePort = $APP_PORT |
| 27 | +type = "tcp" |
| 28 | +name = "$APP_ID" |
| 29 | +[proxies.plugin] |
| 30 | +type = "unix_domain_socket" |
| 31 | +unixPath = "/tmp/exapp.sock" |
| 32 | +EOF |
| 33 | + else |
| 34 | + echo "Directory /certs/frp not found. Creating configuration without TLS certificates." |
| 35 | + cat <<EOF > /frpc.toml |
| 36 | +serverAddr = "$HP_FRP_ADDRESS" |
| 37 | +serverPort = $HP_FRP_PORT |
| 38 | +loginFailExit = false |
| 39 | +
|
| 40 | +transport.tls.enable = false |
| 41 | +
|
| 42 | +metadatas.token = "$HP_SHARED_KEY" |
| 43 | +
|
| 44 | +[[proxies]] |
| 45 | +remotePort = $APP_PORT |
| 46 | +type = "tcp" |
| 47 | +name = "$APP_ID" |
| 48 | +[proxies.plugin] |
| 49 | +type = "unix_domain_socket" |
| 50 | +unixPath = "/tmp/exapp.sock" |
| 51 | +EOF |
| 52 | + fi |
| 53 | +else |
| 54 | + echo "HP_SHARED_KEY is not set. Skipping FRP configuration." |
| 55 | +fi |
| 56 | + |
| 57 | +# If we have a configuration file and the shared key is present, start the FRP client |
| 58 | +if [ -f /frpc.toml ] && [ -n "$HP_SHARED_KEY" ]; then |
| 59 | + echo "Starting frpc in the background..." |
| 60 | + frpc -c /frpc.toml & |
| 61 | +fi |
| 62 | + |
| 63 | +# Start the main application (launch cmd for ExApp is an argument for this script) |
| 64 | +echo "Starting application: $@" |
| 65 | +exec "$@" |
0 commit comments