treefmt-check
checks.x86_64-linux.treefmt
· build #924
· raw
1treefmt v2.6.0traversed 442 files2emitted 408 files for processing3formatted 408 files (10 changed) in 1.363s4 M docs/gen-ssh-config.sh5 M docs/generate-host-info.sh6 M docs/generate-lldp-graph.sh7 M docs/get-lldp-neighbors.sh8 M modules/db-sync/scripts/db-freeze.sh9 M modules/db-sync/scripts/db-sync-all.sh10 M modules/db-sync/scripts/db-sync-status.sh11 M modules/db-sync/scripts/db-sync-stop.sh12 M modules/db-sync/scripts/db-thaw.sh13 M terraform/authentik/import-existing.sh14diff --git a/docs/gen-ssh-config.sh b/docs/gen-ssh-config.sh15index 575c5a6..63a3489 10075516--- a/docs/gen-ssh-config.sh17+++ b/docs/gen-ssh-config.sh18@@ -4,9 +4,9 @@ set -euo pipefail19 user=${1:-}20 21 if [[ -z $user ]]; then22- echo "Missing username"23- echo "Usage: $(basename "$0") username"24- exit 125+ echo "Missing username"26+ echo "Usage: $(basename "$0") username"27+ exit 128 fi29 30 # GitHub directory pages change independently of this script; use the stable API.31@@ -28,20 +28,20 @@ Host eta32 EOF33 34 curl -fsSL \35- -H 'Accept: application/vnd.github+json' \36- -H 'X-GitHub-Api-Version: 2022-11-28' \37- 'https://api.github.com/repos/SBEE-Lab/infra/contents/hosts?ref=main' \38- >"$tempfile"39+ -H 'Accept: application/vnd.github+json' \40+ -H 'X-GitHub-Api-Version: 2022-11-28' \41+ 'https://api.github.com/repos/SBEE-Lab/infra/contents/hosts?ref=main' \42+ >"$tempfile"43 machines=$(grep -oE '"name"[[:space:]]*:[[:space:]]*"[^"]+\.nix"' "$tempfile" |44- sed -E 's/.*"([^"]+)\.nix"/\1/' |45- sort -u)46+ sed -E 's/.*"([^"]+)\.nix"/\1/' |47+ sort -u)48 49 while read -r machine; do50- if [[ -z $machine || $machine == "eta" ]]; then51- continue52- fi53+ if [[ -z $machine || $machine == "eta" ]]; then54+ continue55+ fi56 57- cat <<EOF58+ cat <<EOF59 Host $machine60 HostName $machine.sjanglab.org61 User $user62diff --git a/docs/generate-host-info.sh b/docs/generate-host-info.sh63index 92a5380..87ddb19 10075564--- a/docs/generate-host-info.sh65+++ b/docs/generate-host-info.sh66@@ -2,8 +2,8 @@67 set -euo pipefail68 69 if [[ -z ${1:-} ]]; then70- echo "Usage: $(basename "$0") host" >&271- exit 172+ echo "Usage: $(basename "$0") host" >&273+ exit 174 fi75 76 target=$177diff --git a/docs/generate-lldp-graph.sh b/docs/generate-lldp-graph.sh78index 7fbaa06..0a099a6 10075579--- a/docs/generate-lldp-graph.sh80+++ b/docs/generate-lldp-graph.sh81@@ -2,8 +2,8 @@82 set -euo pipefail83 84 if ((BASH_VERSINFO[0] < 4)); then85- echo "$(basename "$0") requires Bash 4 or newer" >&286- exit 187+ echo "$(basename "$0") requires Bash 4 or newer" >&288+ exit 189 fi90 91 report="../graph.md"92@@ -11,60 +11,60 @@ url="https://github.com/SBEE-Lab/infra/blob/main/docs/hosts"93 declare -A interfaces94 95 {96- echo '```mermaid'97- echo ' graph TD'98+ echo '```mermaid'99+ echo ' graph TD'100 101- for host_file in *; do102- [[ -f $host_file ]] || continue103- while read -r neighbor; do104- [[ -z $neighbor ]] && continue105- host_interface=$(echo "$neighbor" | cut -d' ' -f1)106- link_speed=$(echo "$neighbor" | cut -d' ' -f2)107- neighbor_interface=$(echo "$neighbor" | cut -d' ' -f3 | tr -cd '[:alnum:]._-')108- neighbor_name=$(echo "$neighbor" | cut -d' ' -f4 | tr -cd '[:alnum:]._-')109+ for host_file in *; do110+ [[ -f $host_file ]] || continue111+ while read -r neighbor; do112+ [[ -z $neighbor ]] && continue113+ host_interface=$(echo "$neighbor" | cut -d' ' -f1)114+ link_speed=$(echo "$neighbor" | cut -d' ' -f2)115+ neighbor_interface=$(echo "$neighbor" | cut -d' ' -f3 | tr -cd '[:alnum:]._-')116+ neighbor_name=$(echo "$neighbor" | cut -d' ' -f4 | tr -cd '[:alnum:]._-')117 118- interfaces[$host_file]+=" $host_interface"119- interfaces[$neighbor_name]+=" $neighbor_interface"120+ interfaces[$host_file]+=" $host_interface"121+ interfaces[$neighbor_name]+=" $neighbor_interface"122 123- echo " ${host_file}.${host_interface}[\"$host_interface\"]-- $link_speed ---${neighbor_name}.${neighbor_interface}[\"$neighbor_interface\"]"124- done <"$host_file"125- done126+ echo " ${host_file}.${host_interface}[\"$host_interface\"]-- $link_speed ---${neighbor_name}.${neighbor_interface}[\"$neighbor_interface\"]"127+ done <"$host_file"128+ done129 130- for host in "${!interfaces[@]}"; do131- interfaces[$host]=$(xargs -n 1 <<<"${interfaces[$host]}" | sort -u | xargs)132- echo " subgraph $host"133- for interface in ${interfaces[$host]}; do134- echo " ${host}.${interface}[\"$interface\"]"135- done136- echo " end"137- done138+ for host in "${!interfaces[@]}"; do139+ interfaces[$host]=$(xargs -n 1 <<<"${interfaces[$host]}" | sort -u | xargs)140+ echo " subgraph $host"141+ for interface in ${interfaces[$host]}; do142+ echo " ${host}.${interface}[\"$interface\"]"143+ done144+ echo " end"145+ done146 147- for host in "${!interfaces[@]}"; do148- [[ -f "../$host.md" ]] || continue149- for interface in ${interfaces[$host]}; do150- echo " click ${host}.${interface} \"$url/$host.md\" \"$host\""151- done152- done153+ for host in "${!interfaces[@]}"; do154+ [[ -f "../$host.md" ]] || continue155+ for interface in ${interfaces[$host]}; do156+ echo " click ${host}.${interface} \"$url/$host.md\" \"$host\""157+ done158+ done159 160- echo '```'161+ echo '```'162 } >"$report"163 164 # Remove inverse duplicate links.165 while true; do166- duplicate=""167- while read -r link; do168- interface_1=$(awk '{print $1}' <<<"$link" | rev | cut -c 3- | rev)169- link_speed=$(awk '{print $2}' <<<"$link")170- interface_2=$(awk '{print $3}' <<<"$link" | cut -c 4-)171- candidate="$interface_2-- $link_speed ---$interface_1"172- if grep -q -F "$candidate" "$report"; then173- duplicate=$candidate174- break175- fi176- done < <(grep -E -- '-- [[:digit:]]+[GM] ---' "$report")177+ duplicate=""178+ while read -r link; do179+ interface_1=$(awk '{print $1}' <<<"$link" | rev | cut -c 3- | rev)180+ link_speed=$(awk '{print $2}' <<<"$link")181+ interface_2=$(awk '{print $3}' <<<"$link" | cut -c 4-)182+ candidate="$interface_2-- $link_speed ---$interface_1"183+ if grep -q -F "$candidate" "$report"; then184+ duplicate=$candidate185+ break186+ fi187+ done < <(grep -E -- '-- [[:digit:]]+[GM] ---' "$report")188 189- [[ -n $duplicate ]] || break190- tempfile=$(mktemp -t sbee-lldp-graph.XXXXXX)191- awk -v pattern="$duplicate" 'index($0, pattern) == 0' "$report" >"$tempfile"192- mv "$tempfile" "$report"193+ [[ -n $duplicate ]] || break194+ tempfile=$(mktemp -t sbee-lldp-graph.XXXXXX)195+ awk -v pattern="$duplicate" 'index($0, pattern) == 0' "$report" >"$tempfile"196+ mv "$tempfile" "$report"197 done198diff --git a/docs/get-lldp-neighbors.sh b/docs/get-lldp-neighbors.sh199index 1396412..dd84cfb 100755200--- a/docs/get-lldp-neighbors.sh201+++ b/docs/get-lldp-neighbors.sh202@@ -2,8 +2,8 @@203 set -euo pipefail204 205 if [[ -z ${1:-} ]]; then206- echo "Usage: $(basename "$0") host" >&2207- exit 1208+ echo "Usage: $(basename "$0") host" >&2209+ exit 1210 fi211 212 target=$1213@@ -12,17 +12,17 @@ report="$hostname"214 lldp=$(ssh "$target" -- networkctl lldp --json=short)215 216 while IFS=$' ' read -r interface neighbor_interface neighbor_name; do217- [[ -z $interface ]] && continue218- link_speed=$(ssh "$target" -- cat "/sys/class/net/$interface/speed" </dev/null)219+ [[ -z $interface ]] && continue220+ link_speed=$(ssh "$target" -- cat "/sys/class/net/$interface/speed" </dev/null)221 222- if ((link_speed >= 1000)); then223- speed="$((link_speed / 1000))G"224- else225- speed="${link_speed}M"226- fi227- echo "$interface $speed $neighbor_interface $neighbor_name"228+ if ((link_speed >= 1000)); then229+ speed="$((link_speed / 1000))G"230+ else231+ speed="${link_speed}M"232+ fi233+ echo "$interface $speed $neighbor_interface $neighbor_name"234 done < <(235- python3 -c '236+ python3 -c '237 import json238 import sys239 240diff --git a/modules/db-sync/scripts/db-freeze.sh b/modules/db-sync/scripts/db-freeze.sh241index 6c31d2c..b709211 100644242--- a/modules/db-sync/scripts/db-freeze.sh243+++ b/modules/db-sync/scripts/db-freeze.sh244@@ -1,24 +1,24 @@245 #!/usr/bin/env bash246 set -euo pipefail247 if [[ $# -ne 2 ]]; then248- echo "Usage: db-freeze <database> <tag>" >&2249- exit 1250+ echo "Usage: db-freeze <database> <tag>" >&2251+ exit 1252 fi253 db="$1"254 tag="$2"255 src="@dbRoot@/$db"256 dst="@dbRoot@/$db.frozen.$tag"257 [[ -d $src ]] || {258- echo "Not found: $db" >&2259- exit 1260+ echo "Not found: $db" >&2261+ exit 1262 }263 [[ ! -e $dst ]] || {264- echo "Already exists: $dst" >&2265- exit 1266+ echo "Already exists: $dst" >&2267+ exit 1268 }269 if systemctl is-active --quiet "db-sync-$db.service" 2>/dev/null; then270- echo "Sync in progress for $db, abort" >&2271- exit 1272+ echo "Sync in progress for $db, abort" >&2273+ exit 1274 fi275 cp --reflink=auto -a "$src" "$dst"276 echo "Frozen: $dst"277diff --git a/modules/db-sync/scripts/db-sync-all.sh b/modules/db-sync/scripts/db-sync-all.sh278index 442bc74..9d558f0 100644279--- a/modules/db-sync/scripts/db-sync-all.sh280+++ b/modules/db-sync/scripts/db-sync-all.sh281@@ -1,8 +1,8 @@282 #!/usr/bin/env bash283 set -euo pipefail284 for timer in $(systemctl list-units 'db-sync-*.timer' --plain --no-legend | awk '{print $1}'); do285- svc="${timer%.timer}.service"286- echo "Starting $svc ..."287- systemctl start --no-block "$svc"288+ svc="${timer%.timer}.service"289+ echo "Starting $svc ..."290+ systemctl start --no-block "$svc"291 done292 echo "All sync services triggered (running in background)"293diff --git a/modules/db-sync/scripts/db-sync-status.sh b/modules/db-sync/scripts/db-sync-status.sh294index d901078..13ece0c 100644295--- a/modules/db-sync/scripts/db-sync-status.sh296+++ b/modules/db-sync/scripts/db-sync-status.sh297@@ -5,14 +5,14 @@ echo ""298 printf "%-40s %-10s %-10s %s\n" "SERVICE" "STATE" "RESULT" "LAST RUN"299 printf "%-40s %-10s %-10s %s\n" "-------" "-----" "------" "--------"300 for svc in $(systemctl list-units 'db-sync-*.service' --plain --no-legend --all | awk '{print $1}' | grep -v notify); do301- result=$(systemctl show "$svc" -p Result --value)302- active=$(systemctl show "$svc" -p ActiveState --value)303- started=$(systemctl show "$svc" -p ExecMainStartTimestamp --value)304- if [[ -z $started ]]; then305- started="never"306- result="-"307- fi308- printf "%-40s %-10s %-10s %s\n" "$svc" "$active" "$result" "$started"309+ result=$(systemctl show "$svc" -p Result --value)310+ active=$(systemctl show "$svc" -p ActiveState --value)311+ started=$(systemctl show "$svc" -p ExecMainStartTimestamp --value)312+ if [[ -z $started ]]; then313+ started="never"314+ result="-"315+ fi316+ printf "%-40s %-10s %-10s %s\n" "$svc" "$active" "$result" "$started"317 done318 echo ""319 echo "Disk usage:"320diff --git a/modules/db-sync/scripts/db-sync-stop.sh b/modules/db-sync/scripts/db-sync-stop.sh321index 5fe0b69..c2035a8 100644322--- a/modules/db-sync/scripts/db-sync-stop.sh323+++ b/modules/db-sync/scripts/db-sync-stop.sh324@@ -1,17 +1,17 @@325 #!/usr/bin/env bash326 set -euo pipefail327 if [[ $# -eq 0 ]]; then328- # Stop all running sync services329- for svc in $(systemctl list-units 'db-sync-*.service' --plain --no-legend --state=activating,running | awk '{print $1}'); do330- echo "Stopping $svc ..."331- systemctl stop "$svc"332- done333- echo "All sync services stopped"334+ # Stop all running sync services335+ for svc in $(systemctl list-units 'db-sync-*.service' --plain --no-legend --state=activating,running | awk '{print $1}'); do336+ echo "Stopping $svc ..."337+ systemctl stop "$svc"338+ done339+ echo "All sync services stopped"340 else341- # Stop specific database(s)342- for db in "$@"; do343- svc="db-sync-${db}.service"344- echo "Stopping $svc ..."345- systemctl stop "$svc"346- done347+ # Stop specific database(s)348+ for db in "$@"; do349+ svc="db-sync-${db}.service"350+ echo "Stopping $svc ..."351+ systemctl stop "$svc"352+ done353 fi354diff --git a/modules/db-sync/scripts/db-thaw.sh b/modules/db-sync/scripts/db-thaw.sh355index bf0ab2f..f7a388b 100644356--- a/modules/db-sync/scripts/db-thaw.sh357+++ b/modules/db-sync/scripts/db-thaw.sh358@@ -1,15 +1,15 @@359 #!/usr/bin/env bash360 set -euo pipefail361 if [[ $# -ne 2 ]]; then362- echo "Usage: db-thaw <database> <tag>" >&2363- exit 1364+ echo "Usage: db-thaw <database> <tag>" >&2365+ exit 1366 fi367 db="$1"368 tag="$2"369 target="@dbRoot@/$db.frozen.$tag"370 [[ -d $target ]] || {371- echo "Not found: $target" >&2372- exit 1373+ echo "Not found: $target" >&2374+ exit 1375 }376 rm -rf "$target"377 echo "Thawed: $db.frozen.$tag"378diff --git a/terraform/authentik/import-existing.sh b/terraform/authentik/import-existing.sh379index 0b6c4d5..fa14c4d 100755380--- a/terraform/authentik/import-existing.sh381+++ b/terraform/authentik/import-existing.sh382@@ -6,83 +6,83 @@ AK_TOKEN=${AK_TOKEN:-$(sops -d --extract '["AUTHENTIK_TOKEN"]' secrets.yaml)}383 TG=${TG:-terragrunt}384 385 api() {386- curl -sSf -H "Authorization: Bearer ${AK_TOKEN}" "$AK/api/v3/$1"387+ curl -sSf -H "Authorization: Bearer ${AK_TOKEN}" "$AK/api/v3/$1"388 }389 390 state_has() {391- $TG state show "$1" >/dev/null 2>&1392+ $TG state show "$1" >/dev/null 2>&1393 }394 395 import_if_missing() {396- local address=$1397- local id=$2398+ local address=$1399+ local id=$2400 401- if [ -z "$id" ] || [ "$id" = "null" ]; then402- echo "skip $address: no remote object"403- return 0404- fi405+ if [ -z "$id" ] || [ "$id" = "null" ]; then406+ echo "skip $address: no remote object"407+ return 0408+ fi409 410- if state_has "$address"; then411- echo "ok $address already imported"412- return 0413- fi414+ if state_has "$address"; then415+ echo "ok $address already imported"416+ return 0417+ fi418 419- echo "import $address <- $id"420- $TG import "$address" "$id"421+ echo "import $address <- $id"422+ $TG import "$address" "$id"423 }424 425 json_quote() {426- jq -Rn --arg v "$1" '$v'427+ jq -Rn --arg v "$1" '$v'428 }429 430 group_id_by_name() {431- local name=$1432- api "core/groups/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" |433- jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' |434- head -n1435+ local name=$1436+ api "core/groups/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" |437+ jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' |438+ head -n1439 }440 441 user_id_by_username() {442- local username=$1443- api "core/users/?search=$(jq -rn --arg v "$username" '$v|@uri')&page_size=100" |444- jq -r --arg username "$username" '.results[] | select(.username == $username) | .pk' |445- head -n1446+ local username=$1447+ api "core/users/?search=$(jq -rn --arg v "$username" '$v|@uri')&page_size=100" |448+ jq -r --arg username "$username" '.results[] | select(.username == $username) | .pk' |449+ head -n1450 }451 452 proxy_id_by_external_host() {453- local external_host=$1454- api "providers/proxy/?page_size=100" |455- jq -r --arg external_host "$external_host" '.results[] | select(.external_host == $external_host) | .pk' |456- head -n1457+ local external_host=$1458+ api "providers/proxy/?page_size=100" |459+ jq -r --arg external_host "$external_host" '.results[] | select(.external_host == $external_host) | .pk' |460+ head -n1461 }462 463 app_uuid_by_slug() {464- local slug=$1465- curl -sS -H "Authorization: Bearer ${AK_TOKEN}" "$AK/api/v3/core/applications/${slug}/" 2>/dev/null |466- jq -r '.pk // empty' 2>/dev/null || true467+ local slug=$1468+ curl -sS -H "Authorization: Bearer ${AK_TOKEN}" "$AK/api/v3/core/applications/${slug}/" 2>/dev/null |469+ jq -r '.pk // empty' 2>/dev/null || true470 }471 472 oauth2_id_by_name() {473- local name=$1474- api "providers/oauth2/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" |475- jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' |476- head -n1477+ local name=$1478+ api "providers/oauth2/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" |479+ jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' |480+ head -n1481 }482 483 scope_mapping_id_by_name() {484- local name=$1485- api "propertymappings/provider/scope/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" |486- jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' |487- head -n1488+ local name=$1489+ api "propertymappings/provider/scope/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" |490+ jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' |491+ head -n1492 }493 494 outpost_id=$(api 'outposts/instances/?search=authentik%20Embedded%20Outpost&page_size=100' |495- jq -r '.results[] | select(.name == "authentik Embedded Outpost") | .pk' |496- head -n1)497+ jq -r '.results[] | select(.name == "authentik Embedded Outpost") | .pk' |498+ head -n1)499 500 # Keep keys in sync with local.groups in groups.tf.501 while IFS='|' read -r key name; do502- import_if_missing "authentik_group.group[$(json_quote "$key")]" "$(group_id_by_name "$name")"503+ import_if_missing "authentik_group.group[$(json_quote "$key")]" "$(group_id_by_name "$name")"504 done <<'EOF'505 authentik_admins|authentik Admins506 sjanglab_admins|sjanglab-admins507@@ -93,45 +93,45 @@ sjanglab_pending|sjanglab-pending508 EOF509 510 for username in akadmin terraform; do511- import_if_missing "authentik_user.service[$(json_quote "$username")]" "$(user_id_by_username "$username")"512+ import_if_missing "authentik_user.service[$(json_quote "$username")]" "$(user_id_by_username "$username")"513 done514 515 while IFS='|' read -r app external_host; do516- provider_id=$(proxy_id_by_external_host "$external_host")517- app_id=$(app_uuid_by_slug "$app")518-519- import_if_missing "authentik_provider_proxy.app[$(json_quote "$app")]" "$provider_id"520- if [ -n "$app_id" ]; then521- import_if_missing "authentik_application.app[$(json_quote "$app")]" "$app"522- else523- echo "skip application for $app: no remote object"524- fi525-526- if [ -n "$outpost_id" ] && [ -n "$provider_id" ]; then527- import_if_missing "authentik_outpost_provider_attachment.embedded[$(json_quote "$app")]" "${outpost_id}:${provider_id}"528- else529- echo "skip outpost attachment for $app: no outpost/provider"530- fi531+ provider_id=$(proxy_id_by_external_host "$external_host")532+ app_id=$(app_uuid_by_slug "$app")533+534+ import_if_missing "authentik_provider_proxy.app[$(json_quote "$app")]" "$provider_id"535+ if [ -n "$app_id" ]; then536+ import_if_missing "authentik_application.app[$(json_quote "$app")]" "$app"537+ else538+ echo "skip application for $app: no remote object"539+ fi540+541+ if [ -n "$outpost_id" ] && [ -n "$provider_id" ]; then542+ import_if_missing "authentik_outpost_provider_attachment.embedded[$(json_quote "$app")]" "${outpost_id}:${provider_id}"543+ else544+ echo "skip outpost attachment for $app: no outpost/provider"545+ fi546 done <<'EOF'547 n8n|https://n8n.sjanglab.org548 logging|https://logging.sjanglab.org549 EOF550 551 while IFS='|' read -r key name; do552- import_if_missing "authentik_property_mapping_provider_scope.oidc_group[$(json_quote "$key")]" "$(scope_mapping_id_by_name "$name")"553+ import_if_missing "authentik_property_mapping_provider_scope.oidc_group[$(json_quote "$key")]" "$(scope_mapping_id_by_name "$name")"554 done <<'EOF'555 headscale|headscale-groups556 nextcloud|nextcloud-groups557 EOF558 559 while IFS='|' read -r key name slug; do560- import_if_missing "authentik_provider_oauth2.oidc[$(json_quote "$key")]" "$(oauth2_id_by_name "$name")"561- app_id=$(app_uuid_by_slug "$slug")562- if [ -n "$app_id" ]; then563- import_if_missing "authentik_application.oidc[$(json_quote "$key")]" "$slug"564- else565- echo "skip application for $slug: no remote object"566- fi567+ import_if_missing "authentik_provider_oauth2.oidc[$(json_quote "$key")]" "$(oauth2_id_by_name "$name")"568+ app_id=$(app_uuid_by_slug "$slug")569+ if [ -n "$app_id" ]; then570+ import_if_missing "authentik_application.oidc[$(json_quote "$key")]" "$slug"571+ else572+ echo "skip application for $slug: no remote object"573+ fi574 done <<'EOF'575 headscale|Headscale|headscale576 nextcloud|Nextcloud|nextcloud