Skip to content

Instantly share code, notes, and snippets.

@stefan-matic
Last active December 17, 2023 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefan-matic/8ca5351d4662a7ab619c481bfd53b722 to your computer and use it in GitHub Desktop.
Save stefan-matic/8ca5351d4662a7ab619c481bfd53b722 to your computer and use it in GitHub Desktop.
Automate adding Traefik labels to containers
#!/bin/bash
############################################################################################
# Run the script as ./unraid-traefik-labels.sh main_clicks <APP_NAME> <APP_PORT> #
# Example: ./unraid-traefik-labels.sh main_clicks my-app 5554 #
# #
# To get coordinates for click options place your mouse on the desired location and use: #
# eval $(xdotool getmouselocation --shell) #
# echo $X #
# echo $Y #
############################################################################################
# Ensure the browser window is in focus
# Ensure that the name matches your tab
# If you are updating an existing container it should be
# UNRAID/UpdateContainer
xdotool search --name "UNRAID/AddContainer" windowactivate --sync
# Set delay for all subsequent xdotool commands
delay="--delay 35"
new() {
xdotool key $delay Return
sleep 0.5
xdotool key $delay Down
xdotool key $delay Down
xdotool key $delay Down
xdotool key $delay Tab
}
new_click() {
xdotool key $delay Return
sleep 0.5
xdotool mousemove 2788 642 click 1
sleep 0.5
xdotool mousemove 2741 716 click 1
xdotool key $delay Tab
}
save() {
xdotool key $delay Tab
xdotool key $delay Tab
xdotool key $delay Return
}
enable() {
xdotool type $delay "Enable Traefik"
xdotool key $delay Tab
xdotool type $delay "traefik.enable"
xdotool key $delay Tab
xdotool type $delay "true"
xdotool key $delay Tab
xdotool type $delay "true"
}
rule() {
xdotool type $delay "Traefik Rule"
xdotool key $delay Tab
xdotool type $delay "traefik.http.routers.$1.rule"
xdotool key $delay Tab
xdotool type $delay "Host(\`$1.$3\`)"
xdotool key $delay Tab
xdotool type $delay "Host(\`$1.$3\`)"
}
entrypoints() {
xdotool type $delay "Traefik EntryPoints"
xdotool key $delay Tab
xdotool type $delay "traefik.http.routers.$1.entryPoints"
xdotool key $delay Tab
xdotool type $delay "web,websecure"
xdotool key $delay Tab
xdotool type $delay "web,websecure"
}
port() {
xdotool type $delay "Traefik Port"
xdotool key $delay Tab
xdotool type $delay "traefik.http.services.$1.loadbalancer.server.port"
xdotool key $delay Tab
xdotool type $delay "$2"
xdotool key $delay Tab
xdotool type $delay "$2"
}
tls() {
xdotool type $delay "Traefik TLS"
xdotool key $delay Tab
xdotool type $delay "traefik.http.routers.$1.tls"
xdotool key $delay Tab
xdotool type $delay "true"
xdotool key $delay Tab
xdotool type $delay "true"
}
middleware() {
xdotool type $delay "Authentik Middleware"
xdotool key $delay Tab
xdotool type $delay "traefik.http.routers.$1.middlewares"
xdotool key $delay Tab
xdotool type $delay "authentik@file"
xdotool key $delay Tab
xdotool type $delay "authentik@file"
}
# Doesn't work because of bug
# https://forums.unraid.net/bug-reports/stable-releases/6126-docker-add-configuration-menu-breaks-when-selecting-config-type-with-keyboard-arrows-r2773/
main() {
local container_name=$1
local port_number=$2
new
enable
save
new
rule "$container_name"
save
new
entrypoints "$container_name"
save
new
port "$container_name" "$port_number"
save
new
tls "$container_name"
save
}
main_clicks() {
local container_name=$1
local port_number=$2
new_click
enable
save
new_click
rule "$container_name"
save
new_click
entrypoints "$container_name"
save
new_click
port "$container_name" "$port_number"
save
new_click
tls "$container_name"
save
}
$@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment