Merge pull request #746 from dellthePROgrammer/main
Created Helper Scripts to add, edit, disable, and enable sites for Traefik
This commit is contained in:
commit
16682f6cf3
58
ct/traefik.sh
Normal file
58
ct/traefik.sh
Normal file
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
|
||||
# Copyright (c) 2021-2025 tteck
|
||||
# Author: tteck (tteckster)
|
||||
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
||||
# Source: https://traefik.io/
|
||||
|
||||
APP="Traefik"
|
||||
var_tags="${var_tags:-proxy}"
|
||||
var_cpu="${var_cpu:-1}"
|
||||
var_ram="${var_ram:-512}"
|
||||
var_disk="${var_disk:-2}"
|
||||
var_os="${var_os:-debian}"
|
||||
var_version="${var_version:-12}"
|
||||
var_unprivileged="${var_unprivileged:-1}"
|
||||
|
||||
header_info "$APP"
|
||||
variables
|
||||
color
|
||||
catch_errors
|
||||
|
||||
function update_script() {
|
||||
header_info
|
||||
check_container_storage
|
||||
check_container_resources
|
||||
if [[ ! -f /etc/systemd/system/traefik.service ]]; then
|
||||
msg_error "No ${APP} Installation Found!"
|
||||
exit
|
||||
fi
|
||||
RELEASE=$(curl -fsSL https://api.github.com/repos/traefik/traefik/releases | grep -oP '"tag_name":\s*"v\K[\d.]+?(?=")' | sort -V | tail -n 1)
|
||||
msg_info "Updating $APP LXC"
|
||||
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
|
||||
curl -fsSL "https://github.com/traefik/traefik/releases/download/v${RELEASE}/traefik_v${RELEASE}_linux_amd64.tar.gz" -o $(basename "https://github.com/traefik/traefik/releases/download/v${RELEASE}/traefik_v${RELEASE}_linux_amd64.tar.gz")
|
||||
tar -C /tmp -xzf traefik*.tar.gz
|
||||
mv /tmp/traefik /usr/bin/
|
||||
rm -rf traefik*.tar.gz
|
||||
systemctl restart traefik.service
|
||||
echo "${RELEASE}" >/opt/${APP}_version.txt
|
||||
msg_ok "Updated $APP LXC"
|
||||
else
|
||||
msg_ok "No update required. ${APP} is already at ${RELEASE}"
|
||||
fi
|
||||
exit
|
||||
}
|
||||
|
||||
start
|
||||
build_container
|
||||
description
|
||||
|
||||
msg_ok "Completed Successfully!\n"
|
||||
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
|
||||
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
|
||||
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8080${CL}"
|
||||
echo -e "Commands available are as below:"
|
||||
echo -e "addsite - creating a config"
|
||||
echo -e "ensite - enables a config"
|
||||
echo -e "dissite - disables a config"
|
||||
echo -e "editsite - edits a config"
|
263
install/traefik-install.sh
Normal file
263
install/traefik-install.sh
Normal file
@ -0,0 +1,263 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright (c) 2021-2025 tteck
|
||||
# Author: tteck (tteckster)
|
||||
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
||||
# Source: https://traefik.io/
|
||||
|
||||
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
|
||||
color
|
||||
verb_ip6
|
||||
catch_errors
|
||||
setting_up_container
|
||||
network_check
|
||||
update_os
|
||||
|
||||
msg_info "Installing Dependencies"
|
||||
$STD apt-get install -y apt-transport-https
|
||||
msg_ok "Installed Dependencies"
|
||||
|
||||
RELEASE=$(curl -fsSL https://api.github.com/repos/traefik/traefik/releases | grep -oP '"tag_name":\s*"v\K[\d.]+?(?=")' | sort -V | tail -n 1)
|
||||
msg_info "Installing Traefik v${RELEASE}"
|
||||
mkdir -p /etc/traefik/{conf.d,ssl,sites-available}
|
||||
curl -fsSL "https://github.com/traefik/traefik/releases/download/v${RELEASE}/traefik_v${RELEASE}_linux_amd64.tar.gz" -o "traefik_v${RELEASE}_linux_amd64.tar.gz"
|
||||
tar -C /tmp -xzf traefik*.tar.gz
|
||||
mv /tmp/traefik /usr/bin/
|
||||
rm -rf traefik*.tar.gz
|
||||
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
|
||||
msg_ok "Installed Traefik v${RELEASE}"
|
||||
|
||||
msg_info "Creating Traefik configuration"
|
||||
cat <<EOF >/etc/traefik/traefik.yaml
|
||||
providers:
|
||||
file:
|
||||
directory: /etc/traefik/conf.d/
|
||||
watch: true
|
||||
|
||||
entryPoints:
|
||||
web:
|
||||
address: ':80'
|
||||
http:
|
||||
redirections:
|
||||
entryPoint:
|
||||
to: websecure
|
||||
scheme: https
|
||||
websecure:
|
||||
address: ':443'
|
||||
http:
|
||||
tls:
|
||||
certResolver: letsencrypt
|
||||
# Uncomment below if using cloudflare
|
||||
/*
|
||||
forwardedHeaders:
|
||||
trustedIPs:
|
||||
- 173.245.48.0/20
|
||||
- 103.21.244.0/22
|
||||
- 103.22.200.0/22
|
||||
- 103.31.101.64/22
|
||||
- 141.101.64.0/18
|
||||
- 108.162.192.0/18
|
||||
- 190.93.240.0/20
|
||||
- 188.114.96.0/20
|
||||
- 197.234.240.0/22
|
||||
- 198.41.128.0/17
|
||||
- 162.158.0.0/15
|
||||
- 104.16.0.0/13
|
||||
- 104.16.0.0/13
|
||||
- 172.64.0.0/13
|
||||
- 131.0.72.0/22
|
||||
*/
|
||||
asDefault: true
|
||||
traefik:
|
||||
address: ':8080'
|
||||
|
||||
certificatesResolvers:
|
||||
letsencrypt:
|
||||
acme:
|
||||
email: "foo@bar.com"
|
||||
storage: /etc/traefik/ssl/acme.json
|
||||
tlsChallenge: {}
|
||||
|
||||
# Uncomment below if you are using self signed or no certificate
|
||||
#serversTransport:
|
||||
# insecureSkipVerify: true
|
||||
|
||||
api:
|
||||
dashboard: true
|
||||
insecure: true
|
||||
|
||||
log:
|
||||
filePath: /var/log/traefik/traefik.log
|
||||
format: json
|
||||
level: INFO
|
||||
|
||||
accessLog:
|
||||
filePath: /var/log/traefik/traefik-access.log
|
||||
format: json
|
||||
filters:
|
||||
statusCodes:
|
||||
- "200"
|
||||
- "400-599"
|
||||
retryAttempts: true
|
||||
minDuration: "10ms"
|
||||
bufferingSize: 0
|
||||
fields:
|
||||
headers:
|
||||
defaultMode: drop
|
||||
names:
|
||||
User-Agent: keep
|
||||
EOF
|
||||
msg_ok "Created Traefik configuration"
|
||||
|
||||
msg_info "Creating Service"
|
||||
cat <<EOF >/etc/systemd/system/traefik.service
|
||||
[Unit]
|
||||
Description=Traefik is an open-source Edge Router that makes publishing your services a fun and easy experience
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=/usr/bin/traefik --configFile=/etc/traefik/traefik.yaml
|
||||
Restart=on-failure
|
||||
ExecReload=/bin/kill -USR1 \$MAINPID
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl enable -q --now traefik
|
||||
msg_ok "Created Service"
|
||||
|
||||
msg_info "Creating site templates"
|
||||
cat <<EOF >/etc/traefik/template.yaml.tpl
|
||||
http:
|
||||
routers:
|
||||
${hostname}:
|
||||
rule: Host(`${FQDN}`)
|
||||
service: ${hostname}
|
||||
tls:
|
||||
certResolver: letsencrypt
|
||||
services:
|
||||
${hostname}:
|
||||
loadbalancer:
|
||||
servers:
|
||||
- url: "${URL}"
|
||||
EOF
|
||||
msg_ok: "Template Created"
|
||||
msg_info: "Creating Helper Scripts"
|
||||
cat <<EOF >/usr/bin/addsite
|
||||
#!/bin/bash
|
||||
|
||||
function setup_site() {
|
||||
hostname="$(whiptail --inputbox "Enter the hostname of the Site" 8 78 --title "Hostname" 3>&1 1>&2 2>&3)"
|
||||
exitstatus=$?
|
||||
[[ "$exitstatus" = 1 ]] && return;
|
||||
FQDN="$(whiptail --inputbox "Enter the FQDN of the Site" 8 78 --title "FQDN" 3>&1 1>&2 2>&3)"
|
||||
exitstatus=$?
|
||||
[[ "$exitstatus" = 1 ]] && return;
|
||||
URL="$(whiptail --inputbox "Enter the URL of the Site (For example http://192.168.x.x:8080)" 8 78 --title "URL" 3>&1 1>&2 2>&3)"
|
||||
exitstatus=$?
|
||||
[[ "$exitstatus" = 1 ]] && return;
|
||||
filename="/etc/traefik/sites-available/${hostname}.yaml"
|
||||
export hostname FQDN URL
|
||||
envsubst '${hostname} ${FQDN} ${URL}' < /etc/traefik/template.yaml.tpl > ${filename}
|
||||
}
|
||||
|
||||
setup_site
|
||||
EOF
|
||||
cat <<EOF >/usr/bin/ensite
|
||||
#!/bin/bash
|
||||
|
||||
function ensite() {
|
||||
DIR="/etc/traefik/sites-available"
|
||||
files=( "$DIR"/* )
|
||||
|
||||
opts=()
|
||||
for f in "${files[@]}"; do
|
||||
name="${f##*/}"
|
||||
opts+=( "$name" "" )
|
||||
done
|
||||
|
||||
choice=$(whiptail \
|
||||
--title "Select an entry" \
|
||||
--menu "Choose a site" \
|
||||
20 60 12 \
|
||||
"${opts[@]}" \
|
||||
3>&1 1>&2 2>&3)
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
ln -s $DIR/$choice /etc/traefik/conf.d
|
||||
else
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
ensite
|
||||
EOF
|
||||
cat <<EOF >/usr/bin/dissite
|
||||
#!/bin/bash
|
||||
|
||||
function dissite() {
|
||||
DIR="/etc/traefik/conf.d"
|
||||
files=( "$DIR"/* )
|
||||
|
||||
opts=()
|
||||
for f in "${files[@]}"; do
|
||||
name="${f##*/}"
|
||||
opts+=( "$name" "" )
|
||||
done
|
||||
|
||||
choice=$(whiptail \
|
||||
--title "Select an entry" \
|
||||
--menu "Choose a site" \
|
||||
20 60 12 \
|
||||
"${opts[@]}" \
|
||||
3>&1 1>&2 2>&3)
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
rm $DIR/$choice
|
||||
else
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
dissite
|
||||
EOF
|
||||
|
||||
cat <<EOF >/usr/bin/editsite
|
||||
#!/bin/bash
|
||||
|
||||
function edit_site() {
|
||||
DIR="/etc/traefik/sites-available"
|
||||
files=( "$DIR"/* )
|
||||
|
||||
opts=()
|
||||
for f in "${files[@]}"; do
|
||||
name="${f##*/}"
|
||||
opts+=( "$name" "" )
|
||||
done
|
||||
|
||||
choice=$(whiptail \
|
||||
--title "Select an entry" \
|
||||
--menu "Choose a site" \
|
||||
20 60 12 \
|
||||
"${opts[@]}" \
|
||||
3>&1 1>&2 2>&3)
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
nano $DIR/$choice
|
||||
else
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
edit_site
|
||||
EOF
|
||||
msg_ok "Helper Scripts Created"
|
||||
|
||||
motd_ssh
|
||||
customize
|
||||
|
||||
msg_info "Cleaning up"
|
||||
$STD apt-get -y autoremove
|
||||
$STD apt-get -y autoclean
|
||||
msg_ok "Cleaned"
|
Loading…
x
Reference in New Issue
Block a user