|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: cobalt (cobaltgit) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://caddyserver.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 Caddy" |
| 17 | +$STD apk add --no-cache caddy caddy-openrc |
| 18 | +cat <<EOF >/etc/caddy/Caddyfile |
| 19 | +:80 { |
| 20 | + # Set this path to your site's directory. |
| 21 | + root * /var/www/html |
| 22 | +
|
| 23 | + # Enable the static file server. |
| 24 | + file_server |
| 25 | +
|
| 26 | + # Another common task is to set up a reverse proxy: |
| 27 | + # reverse_proxy localhost:8080 |
| 28 | +
|
| 29 | + # Or serve a PHP site through php-fpm: |
| 30 | + # php_fastcgi localhost:9000 |
| 31 | +} |
| 32 | +EOF |
| 33 | +mkdir -p /var/www/html |
| 34 | +cat <<EOF >/var/www/html/index.html |
| 35 | +<!DOCTYPE html> |
| 36 | +<html> |
| 37 | + <head> |
| 38 | + <title>Caddy works!</title> |
| 39 | + </head> |
| 40 | + <body> |
| 41 | + <h1>Hello Caddy!</h1> |
| 42 | + <p>For more information, refer to the Caddy <a href="https://caddyserver.com/docs/">documentation</a><p> |
| 43 | + </body> |
| 44 | +</html> |
| 45 | +EOF |
| 46 | +msg_ok "Installed Caddy" |
| 47 | + |
| 48 | +read -r -p "${TAB3}Would you like to install xCaddy Addon? <y/N> " prompt |
| 49 | +if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then |
| 50 | + GO_VERSION="$(curl -fsSL https://go.dev/VERSION?m=text | head -1 | cut -c3-)" setup_go |
| 51 | + msg_info "Setup xCaddy" |
| 52 | + cd /opt |
| 53 | + RELEASE=$(curl -fsSL https://api.github.com/repos/caddyserver/xcaddy/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') |
| 54 | + curl -fsSL "https://github.com/caddyserver/xcaddy/releases/download/${RELEASE}/xcaddy_${RELEASE:1}_linux_amd64.tar.gz" -o "xcaddy_${RELEASE:1}_linux_amd64.tar.gz" |
| 55 | + $STD tar xzf xcaddy_"${RELEASE:1}"_linux_amd64.tar.gz -C /usr/local/bin xcaddy |
| 56 | + rm -rf /opt/xcaddy* |
| 57 | + $STD xcaddy build |
| 58 | + msg_ok "Setup xCaddy" |
| 59 | +fi |
| 60 | + |
| 61 | +msg_info "Enabling Caddy Service" |
| 62 | +$STD rc-update add caddy default |
| 63 | +msg_ok "Enabled Caddy Service" |
| 64 | + |
| 65 | +msg_info "Starting Caddy" |
| 66 | +$STD service caddy start |
| 67 | +msg_ok "Started Caddy" |
| 68 | + |
| 69 | +motd_ssh |
| 70 | +customize |
0 commit comments