-
-
Couldn't load subscription status.
- Fork 127
Add Helper Scripts for traefik #869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dellthePROgrammer
wants to merge
15
commits into
community-scripts:main
Choose a base branch
from
dellthePROgrammer:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ddfc9ab
Update Traefik install to show available commands
dellthePROgrammer c7a7df5
Add 4 helper scripts and defaults for cloudflare
dellthePROgrammer 3999c05
change source build func to dev branch
dellthePROgrammer 655637a
switch back to VE build
dellthePROgrammer d26afc5
ensure you run the install script
dellthePROgrammer aba1417
Correctly make the files for traefik-install
dellthePROgrammer b245c3f
ensure install script is run
dellthePROgrammer 25dd721
make the build func use my repo temporarily
dellthePROgrammer 38abba6
change url to match file location
dellthePROgrammer 96df5bf
correct link again...
dellthePROgrammer 3259a0e
look for logs
dellthePROgrammer d9838af
fix URL
dellthePROgrammer 74a4d39
update escape values
dellthePROgrammer 967033a
set permissions for helper scripts
dellthePROgrammer 35e078b
fix scripts to work in VED Repo
dellthePROgrammer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env bash | ||
| source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/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" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,267 @@ | ||
| #!/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: "[email protected]" | ||
| 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 traefik.service | ||
| 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 | ||
| chmod +x /usr/bin/addsite | ||
| chmod +x /usr/bin/ensite | ||
| chmod +x /usr/bin/dissite | ||
| chmod +x /usr/bin/editsite | ||
| 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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to base the script on version 13 right away.