From f4ea4edb54ebd6848dbf0c222125c839991ebe19 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 20 Nov 2024 00:30:08 +0100 Subject: [PATCH] Replace `yq` with `go-yq` --- scripts/Arch/OS/install.fish | 2 +- scripts/Common/Software/aliae/Manage.ps1 | 6 ++--- .../docker/services/anki-sync/main.fish | 4 ++-- .../Software/docker/services/drone/main.fish | 19 +++++++-------- .../docker/services/forgejo/main.fish | 20 ++++++++-------- .../docker/services/jellyfin/main.fish | 5 ++-- .../docker/services/minecraft/main.fish | 3 +-- .../docker/services/nextcloud/main.fish | 23 ++++++++----------- .../Software/docker/services/ryot/main.fish | 6 ++--- .../Software/docker/services/service.fish | 6 ++--- .../docker/services/teamspeak/main.fish | 13 +++++------ .../docker/services/vaultwarden/main.fish | 10 ++++---- 12 files changed, 53 insertions(+), 64 deletions(-) diff --git a/scripts/Arch/OS/install.fish b/scripts/Arch/OS/install.fish index 727970c1..53c896cf 100755 --- a/scripts/Arch/OS/install.fish +++ b/scripts/Arch/OS/install.fish @@ -27,7 +27,7 @@ begin and yayinst \ linux-headers \ pacman-contrib \ - yq + go-yq end source "$dir/../../Common/OS/install.fish" diff --git a/scripts/Common/Software/aliae/Manage.ps1 b/scripts/Common/Software/aliae/Manage.ps1 index fbdef356..6fe58531 100644 --- a/scripts/Common/Software/aliae/Manage.ps1 +++ b/scripts/Common/Software/aliae/Manage.ps1 @@ -27,7 +27,7 @@ $null = New-Module { Value = "$Value"; } ` -User $User ` - ".alias |= [((. // [])[] | select(.name != env.Name))] + [{ name: env.Name, value: env.Value }]"; + ".alias |= [((. // [])[] | select(.name != env(Name)))] + [{ name: env(Name), value: env(Value) }]"; } <# @@ -53,7 +53,7 @@ $null = New-Module { Value = "$Value"; } ` -User $User ` - ".env |= [((. // [])[] | select(.name != env.Name))] + [{ name: env.Name, value: env.Value }]"; + ".env |= [((. // [])[] | select(.name != env(Name)))] + [{ name: env(Name), value: env(Value) }]"; } <# @@ -92,7 +92,7 @@ $null = New-Module { } sudo @using:flags pwsh -CommandWithArgs 'Get-Content -Raw $args[0]' $using:path | Set-Content $file; - yq -yi $using:Script $file; + yq -i $using:Script $file; sudo @using:flags pwsh -CommandWithArgs 'Set-Content $args[0] -Value $args[1]' $using:path (Get-Content -Raw $file); Remove-Item $file; } | Receive-Job -Wait; diff --git a/scripts/Common/Software/docker/services/anki-sync/main.fish b/scripts/Common/Software/docker/services/anki-sync/main.fish index ad9b82bd..212fd4f7 100644 --- a/scripts/Common/Software/docker/services/anki-sync/main.fish +++ b/scripts/Common/Software/docker/services/anki-sync/main.fish @@ -8,11 +8,11 @@ begin function installSW -V dir -V source set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l userKey ".services.anki.environment.SYNC_USER1" - set -l user (yq --raw-output "$userKey" "$source" | sed "s/:.*\$/:$pw/") + set -l user (yq "$userKey" "$source" | sed "s/:.*\$/:$pw/") initializeServiceInstallation $argv sudo cp "$dir/docker-compose.base.yml" (getServiceRoot $argv) - USER=$user yq "$userKey = env.USER" "$source" | \ + USER=$user yq "$userKey = env(USER)" "$source" | \ sudo tee (getServiceSecretsConfig $argv) >/dev/null installDockerService $argv diff --git a/scripts/Common/Software/docker/services/drone/main.fish b/scripts/Common/Software/docker/services/drone/main.fish index 50e49933..88efc6ca 100644 --- a/scripts/Common/Software/docker/services/drone/main.fish +++ b/scripts/Common/Software/docker/services/drone/main.fish @@ -63,30 +63,27 @@ begin echo "DRONE_RPC_SECRET=$secret" | sudo tee "$root/$SECRET_ENV" >/dev/null yq "$ciKey = $ciTemplate" "$tmpConfig" | \ - ENTRY="./data/$name:/data" yq "$ciKey.volumes = [ env.ENTRY ]" | \ - yq "$ciKey.env_file |= . + [ env.SECRET_ENV ]" | \ - PROTO=https yq "$ciEnv.DRONE_SERVER_PROTO = env.PROTO" | \ - HOST=(getServiceDomain "$subdomain" "$domain") yq "$ciEnv.DRONE_SERVER_HOST = env.HOST" | \ + ENTRY="./data/$name:/data" yq "$ciKey.volumes = [ env(ENTRY) ]" | \ + yq "$ciKey.env_file |= . + [ env(SECRET_ENV) ]" | \ + PROTO=https yq "$ciEnv.DRONE_SERVER_PROTO = env(PROTO)" | \ + HOST=(getServiceDomain "$subdomain" "$domain") yq "$ciEnv.DRONE_SERVER_HOST = env(HOST)" | \ yq "$dockerKey = $dockerTemplate" | \ yq "$sshKey = $sshTemplate" | \ - yq "$dockerKey.depends_on = [ env.CI_NAME ]" | \ - yq -y "." | \ + yq "$dockerKey.depends_on = [ env(CI_NAME) ]" | \ sudo tee "$config" >/dev/null for key in $dockerKey $sshKey set -l file (mktemp) - yq "$key.depends_on = [ env.CI_NAME ]" "$config" | \ - yq "$key.env_file |= . + [ env.RUNNER_ENV, env.SECRET_ENV ]" | \ - yq -y "." | \ + yq "$key.depends_on = [ env(CI_NAME) ]" "$config" | \ + yq "$key.env_file |= . + [ env(RUNNER_ENV), env(SECRET_ENV) ]" | \ tee "$file" >/dev/null sudo cp "$file" "$config" rm "$file" end - PORT="127.0.0.1:1337:80" yq "$ciKey.ports = [ env.PORT ]" "$tmpSecrets" | \ - yq -y "." | \ + PORT="127.0.0.1:1337:80" yq "$ciKey.ports = [ env(PORT) ]" "$tmpSecrets" | \ sudo tee "$secrets" >/dev/null end end diff --git a/scripts/Common/Software/docker/services/forgejo/main.fish b/scripts/Common/Software/docker/services/forgejo/main.fish index 313f590a..7d6d6a63 100644 --- a/scripts/Common/Software/docker/services/forgejo/main.fish +++ b/scripts/Common/Software/docker/services/forgejo/main.fish @@ -21,20 +21,19 @@ begin sudo cp "$dir/docker-compose.base.yml" "$root" installDockerService $argv - set port (yq (getSSHPortKey) "$source" --raw-output | mutatePort "$port") + set port (yq (getSSHPortKey) "$source" | mutatePort "$port") DOMAIN=(getServiceDomain $server) PW=$pw DB=Git USER=forgejo PW=$pw begin set -l gitEnv "$(getServiceKey "$service").environment" set -l dbEnv "$(getServiceKey "db").environment" - PORT=$port yq "$(getSSHPortKey) = env.PORT" "$source" | \ - yq "$gitEnv.FORGEJO__database__NAME = env.DB" | \ - yq "$gitEnv.FORGEJO__database__USER = env.USER" | \ - yq "$gitEnv.FORGEJO__database__PASSWD = env.PW" | \ - yq "$dbEnv.MARIADB_DATABASE = env.DB" | \ - yq "$dbEnv.MARIADB_USER = env.USER" | \ - yq "$dbEnv.MARIADB_PASSWORD = env.PW" | \ - yq -y . | \ + PORT=$port yq "$(getSSHPortKey) = env(PORT)" "$source" | \ + yq "$gitEnv.FORGEJO__database__NAME = env(DB)" | \ + yq "$gitEnv.FORGEJO__database__USER = env(USER)" | \ + yq "$gitEnv.FORGEJO__database__PASSWD = env(PW)" | \ + yq "$dbEnv.MARIADB_DATABASE = env(DB)" | \ + yq "$dbEnv.MARIADB_USER = env(USER)" | \ + yq "$dbEnv.MARIADB_PASSWORD = env(PW)" | \ sudo tee "$secrets" >/dev/null end end @@ -65,14 +64,13 @@ begin and yq "$envKey.USER_UID = $uid" "$file" | \ yq "$envKey.USER_GID = $gid" | \ - yq -y . | sudo tee "$config" >/dev/null mkdir -p "$dir" and chown -R $uid:$gid "$dir" rm "$file" - set port (yq (getSSHPortKey) "$secrets" --raw-output | extractPort) + set port (yq (getSSHPortKey) "$secrets" | extractPort) begin printf "%s\n" \ diff --git a/scripts/Common/Software/docker/services/jellyfin/main.fish b/scripts/Common/Software/docker/services/jellyfin/main.fish index 1232da56..4f484a53 100644 --- a/scripts/Common/Software/docker/services/jellyfin/main.fish +++ b/scripts/Common/Software/docker/services/jellyfin/main.fish @@ -50,7 +50,7 @@ begin for name in $service $flood set -l userKey "$(getServiceKey "$name").user" cp "$config" "$file" - USER=$uid:$gid yq -y "$userKey = env.USER" "$file" | sudo tee "$config" >/dev/null + USER=$uid:$gid yq "$userKey = env(USER)" "$file" | sudo tee "$config" >/dev/null end for name in $servarr rtorrent @@ -64,8 +64,7 @@ begin end cp "$config" "$file" - URL="https://$(getServiceDomain "$domain" "")/" yq "$(getServiceKey "$service").environment.JELLYFIN_PublishedServerUrl = env.URL" "$file" | \ - yq -y . | \ + URL="https://$(getServiceDomain "$domain" "")/" yq "$(getServiceKey "$service").environment.JELLYFIN_PublishedServerUrl = env(URL)" "$file" | \ sudo tee "$config" >/dev/null for dir in "$root"/{downloads,config/{,jellyfin,flood,rtorrent,radarr,sonarr,lidarr,prowlarr},media/{,movies,series,music}} diff --git a/scripts/Common/Software/docker/services/minecraft/main.fish b/scripts/Common/Software/docker/services/minecraft/main.fish index 1093ee14..39b8acf5 100644 --- a/scripts/Common/Software/docker/services/minecraft/main.fish +++ b/scripts/Common/Software/docker/services/minecraft/main.fish @@ -30,13 +30,12 @@ begin set uid (id -u $user) set gid (id -g $user) - for service in (yq --raw-output0 ".services | keys[]" "$config" | string split0) + for service in (yq -0 ".services | keys[]" "$config" | string split0) set -l envKey "$(getServiceKey "$service").environment" cp "$config" "$file" and yq "$envKey.UID = $uid" "$file" | \ yq "$envKey.GID = $gid" | \ - yq -y . | \ sudo tee "$config" >/dev/null end diff --git a/scripts/Common/Software/docker/services/nextcloud/main.fish b/scripts/Common/Software/docker/services/nextcloud/main.fish index 5cd65f05..e8501824 100644 --- a/scripts/Common/Software/docker/services/nextcloud/main.fish +++ b/scripts/Common/Software/docker/services/nextcloud/main.fish @@ -65,16 +65,14 @@ begin PROTO="https" DOMAIN="$domain" begin set -l envKey "$(getServiceKey "$service").environment" - yq "$envKey.NEXTCLOUD_TRUSTED_DOMAINS = env.DOMAIN" "$source" | \ - yq "$envKey.OVERWRITEPROTOCOL = env.PROTO" | \ - yq "$envKey.OVERWRITEHOST = env.DOMAIN" | \ - URL="$PROTO://$DOMAIN" yq "$envKey.OVERWRITECLIURL = env.URL" | \ - yq -y . | \ + yq "$envKey.NEXTCLOUD_TRUSTED_DOMAINS = env(DOMAIN)" "$source" | \ + yq "$envKey.OVERWRITEPROTOCOL = env(PROTO)" | \ + yq "$envKey.OVERWRITEHOST = env(DOMAIN)" | \ + URL="$PROTO://$DOMAIN" yq "$envKey.OVERWRITECLIURL = env(URL)" | \ sudo tee "$core" >/dev/null - DOMAIN=(getServiceDomain $officeDomain) yq "$officeEnv.server_name = env.DOMAIN" "$baseSource" | \ - URL="https://$(string escape --style regex "$DOMAIN"):443" yq "$officeEnv.aliasgroup1 = env.URL" | \ - yq -y . | \ + DOMAIN=(getServiceDomain $officeDomain) yq "$officeEnv.server_name = env(DOMAIN)" "$baseSource" | \ + URL="https://$(string escape --style regex "$DOMAIN"):443" yq "$officeEnv.aliasgroup1 = env(URL)" | \ sudo tee "$base" >/dev/null end @@ -83,17 +81,16 @@ begin PW="--static-auth-secret=$turnPW" \ DOMAIN="--realm=$domain" \ - yq "$key |= . + [env.PW, env.DOMAIN]" "$secretsSource" | \ - yq -y . | \ + yq "$key |= . + [env(PW), env(DOMAIN)]" "$secretsSource" | \ sudo tee "$secrets" >/dev/null end installDockerService $argv - set turnPort (yq --raw-output (getServicePortKey "$turn") "$secrets" | extractPort) - set turnPort (yq --raw-output "$portKey" "$secrets" | mutatePort "$turnPort") + set turnPort (yq (getServicePortKey "$turn") "$secrets" | extractPort) + set turnPort (yq "$portKey" "$secrets" | mutatePort "$turnPort") cp "$secrets" "$file" - PORT="$turnPort" yq -y "$portKey = env.PORT" "$file" | sudo tee "$secrets" >/dev/null + PORT="$turnPort" yq "$portKey = env(PORT)" "$file" | sudo tee "$secrets" >/dev/null rm "$file" end diff --git a/scripts/Common/Software/docker/services/ryot/main.fish b/scripts/Common/Software/docker/services/ryot/main.fish index 72a34b2b..6ed49537 100644 --- a/scripts/Common/Software/docker/services/ryot/main.fish +++ b/scripts/Common/Software/docker/services/ryot/main.fish @@ -13,12 +13,12 @@ begin set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l envKey ".services.$service.environment" set -l dbKey "$envKey.DATABASE_URL" - set -l dbUrl (yq --raw-output "$dbKey" "$source" | sed "s/^\(.*:\/\/.*:\).*\(@.*\/.*\)\$/\1$pw\2/") + set -l dbUrl ( "$dbKey" "$source" | sed "s/^\(.*:\/\/.*:\).*\(@.*\/.*\)\$/\1$pw\2/") initializeServiceInstallation $argv sudo cp "$file" "$root" - URL=$dbUrl yq "$dbKey = env.URL" "$source" | \ - PW=$pw yq ".services.db.environment.POSTGRES_PASSWORD = env.PW" | \ + URL=$dbUrl yq "$dbKey = env(URL)" "$source" | \ + PW=$pw yq ".services.db.environment.POSTGRES_PASSWORD = env(PW)" | \ sudo tee (getServiceSecretsConfig $argv) >/dev/null installDockerService $argv diff --git a/scripts/Common/Software/docker/services/service.fish b/scripts/Common/Software/docker/services/service.fish index 3fed9471..75302078 100644 --- a/scripts/Common/Software/docker/services/service.fish +++ b/scripts/Common/Software/docker/services/service.fish @@ -80,7 +80,7 @@ begin set -l url set -l config (getServiceSecretsConfig $argv) set -l portKey (getServicePortKey "$service") - set -l port (yq --raw-output "$portKey" "$config" | extractPort) + set -l port (yq "$portKey" "$config" | extractPort) if [ -n "$_flag_url" ] set url "$_flag_url" @@ -136,8 +136,8 @@ begin sudo mkdir -p "$nginxRoot" cp "$config" "$file" - set exposedPort (yq --raw-output "$portKey" "$file" | mutatePort $port) - PORT=$exposedPort yq -y "$portKey = env.PORT" "$file" | sudo tee "$config" >/dev/null + set exposedPort (yq "$portKey" "$file" | mutatePort $port) + PORT=$exposedPort yq "$portKey = env(PORT)" "$file" | sudo tee "$config" >/dev/null end end end diff --git a/scripts/Common/Software/docker/services/teamspeak/main.fish b/scripts/Common/Software/docker/services/teamspeak/main.fish index 13242b6e..ebdca876 100644 --- a/scripts/Common/Software/docker/services/teamspeak/main.fish +++ b/scripts/Common/Software/docker/services/teamspeak/main.fish @@ -14,18 +14,17 @@ begin cp "$dir/docker-compose.base.yml" (getServiceRoot $argv) USER="$service" begin - yq "$tsEnv.TS3SERVER_DB_USER = env.USER" "$source" | \ - yq "$dbEnv.MARIADB_USER = env.USER" + yq "$tsEnv.TS3SERVER_DB_USER = env(USER)" "$source" | \ + yq "$dbEnv.MARIADB_USER = env(USER)" end | \ PW="$pw" begin - yq "$tsEnv.TS3SERVER_DB_PASSWORD = env.PW" | \ - yq "$dbEnv.MARIADB_PASSWORD = env.PW" + yq "$tsEnv.TS3SERVER_DB_PASSWORD = env(PW)" | \ + yq "$dbEnv.MARIADB_PASSWORD = env(PW)" end | \ DB="$db" begin - yq "$tsEnv.TS3SERVER_DB_NAME = env.DB" | \ - yq "$dbEnv.MARIADB_DATABASE = env.DB" + yq "$tsEnv.TS3SERVER_DB_NAME = env(DB)" | \ + yq "$dbEnv.MARIADB_DATABASE = env(DB)" end | \ - yq . | \ sudo tee (getServiceSecretsConfig $argv) >/dev/null installDockerService $argv diff --git a/scripts/Common/Software/docker/services/vaultwarden/main.fish b/scripts/Common/Software/docker/services/vaultwarden/main.fish index 9156a4fe..fe78d37b 100644 --- a/scripts/Common/Software/docker/services/vaultwarden/main.fish +++ b/scripts/Common/Software/docker/services/vaultwarden/main.fish @@ -10,15 +10,15 @@ begin set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l envKey ".services.vaultwarden.environment" set -l dbKey "$envKey.DATABASE_URL" - set -l dbUrl (yq --raw-output "$dbKey" "$source" | sed "s/^\(.*:\/\/.*:\).*\(@.*\/.*\)\$/\1$pw\2/") + set -l dbUrl (yq "$dbKey" "$source" | sed "s/^\(.*:\/\/.*:\).*\(@.*\/.*\)\$/\1$pw\2/") initializeServiceInstallation $argv - URL="https://$domain.$(getMachineFQDN)" yq "$envKey.DOMAIN = env.URL" "$file" | \ - ADDRESS="noreply@$(getMachineFQDN)" yq -y "$envKey.SMTP_FROM = env.ADDRESS" | \ + URL="https://$domain.$(getMachineFQDN)" yq "$envKey.DOMAIN = env(URL)" "$file" | \ + ADDRESS="noreply@$(getMachineFQDN)" yq "$envKey.SMTP_FROM = env(ADDRESS)" | \ sudo tee "$(getServiceRoot $argv)/$(basename "$file")" >/dev/null - URL=$dbUrl yq "$dbKey = env.URL" "$source" | \ - PW=$pw yq ".services.db.environment.MARIADB_PASSWORD = env.PW" | \ + URL=$dbUrl yq "$dbKey = env(URL)" "$source" | \ + PW=$pw yq ".services.db.environment.MARIADB_PASSWORD = env(PW)" | \ sudo tee (getServiceSecretsConfig $argv) >/dev/null installDockerService $argv