Replace yq with go-yq

This commit is contained in:
Manuel Thalmann 2024-11-20 00:30:08 +01:00
parent e9a57fafad
commit 766b0504cf
12 changed files with 53 additions and 64 deletions

View file

@ -27,7 +27,7 @@ begin
and yayinst \ and yayinst \
linux-headers \ linux-headers \
pacman-contrib \ pacman-contrib \
yq go-yq
end end
source "$dir/../../Common/OS/install.fish" source "$dir/../../Common/OS/install.fish"

View file

@ -27,7 +27,7 @@ $null = New-Module {
Value = "$Value"; Value = "$Value";
} ` } `
-User $User ` -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"; Value = "$Value";
} ` } `
-User $User ` -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; 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); sudo @using:flags pwsh -CommandWithArgs 'Set-Content $args[0] -Value $args[1]' $using:path (Get-Content -Raw $file);
Remove-Item $file; Remove-Item $file;
} | Receive-Job -Wait; } | Receive-Job -Wait;

View file

@ -8,11 +8,11 @@ begin
function installSW -V dir -V source function installSW -V dir -V source
set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32")
set -l userKey ".services.anki.environment.SYNC_USER1" 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 initializeServiceInstallation $argv
sudo cp "$dir/docker-compose.base.yml" (getServiceRoot $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 sudo tee (getServiceSecretsConfig $argv) >/dev/null
installDockerService $argv installDockerService $argv

View file

@ -63,30 +63,27 @@ begin
echo "DRONE_RPC_SECRET=$secret" | sudo tee "$root/$SECRET_ENV" >/dev/null echo "DRONE_RPC_SECRET=$secret" | sudo tee "$root/$SECRET_ENV" >/dev/null
yq "$ciKey = $ciTemplate" "$tmpConfig" | \ yq "$ciKey = $ciTemplate" "$tmpConfig" | \
ENTRY="./data/$name:/data" yq "$ciKey.volumes = [ env.ENTRY ]" | \ ENTRY="./data/$name:/data" yq "$ciKey.volumes = [ env(ENTRY) ]" | \
yq "$ciKey.env_file |= . + [ env.SECRET_ENV ]" | \ yq "$ciKey.env_file |= . + [ env(SECRET_ENV) ]" | \
PROTO=https yq "$ciEnv.DRONE_SERVER_PROTO = env.PROTO" | \ PROTO=https yq "$ciEnv.DRONE_SERVER_PROTO = env(PROTO)" | \
HOST=(getServiceDomain "$subdomain" "$domain") yq "$ciEnv.DRONE_SERVER_HOST = env.HOST" | \ HOST=(getServiceDomain "$subdomain" "$domain") yq "$ciEnv.DRONE_SERVER_HOST = env(HOST)" | \
yq "$dockerKey = $dockerTemplate" | \ yq "$dockerKey = $dockerTemplate" | \
yq "$sshKey = $sshTemplate" | \ yq "$sshKey = $sshTemplate" | \
yq "$dockerKey.depends_on = [ env.CI_NAME ]" | \ yq "$dockerKey.depends_on = [ env(CI_NAME) ]" | \
yq -y "." | \
sudo tee "$config" >/dev/null sudo tee "$config" >/dev/null
for key in $dockerKey $sshKey for key in $dockerKey $sshKey
set -l file (mktemp) set -l file (mktemp)
yq "$key.depends_on = [ env.CI_NAME ]" "$config" | \ yq "$key.depends_on = [ env(CI_NAME) ]" "$config" | \
yq "$key.env_file |= . + [ env.RUNNER_ENV, env.SECRET_ENV ]" | \ yq "$key.env_file |= . + [ env(RUNNER_ENV), env(SECRET_ENV) ]" | \
yq -y "." | \
tee "$file" >/dev/null tee "$file" >/dev/null
sudo cp "$file" "$config" sudo cp "$file" "$config"
rm "$file" rm "$file"
end end
PORT="127.0.0.1:1337:80" yq "$ciKey.ports = [ env.PORT ]" "$tmpSecrets" | \ PORT="127.0.0.1:1337:80" yq "$ciKey.ports = [ env(PORT) ]" "$tmpSecrets" | \
yq -y "." | \
sudo tee "$secrets" >/dev/null sudo tee "$secrets" >/dev/null
end end
end end

View file

@ -21,20 +21,19 @@ begin
sudo cp "$dir/docker-compose.base.yml" "$root" sudo cp "$dir/docker-compose.base.yml" "$root"
installDockerService $argv 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 DOMAIN=(getServiceDomain $server) PW=$pw DB=Git USER=forgejo PW=$pw begin
set -l gitEnv "$(getServiceKey "$service").environment" set -l gitEnv "$(getServiceKey "$service").environment"
set -l dbEnv "$(getServiceKey "db").environment" set -l dbEnv "$(getServiceKey "db").environment"
PORT=$port yq "$(getSSHPortKey) = env.PORT" "$source" | \ PORT=$port yq "$(getSSHPortKey) = env(PORT)" "$source" | \
yq "$gitEnv.FORGEJO__database__NAME = env.DB" | \ yq "$gitEnv.FORGEJO__database__NAME = env(DB)" | \
yq "$gitEnv.FORGEJO__database__USER = env.USER" | \ yq "$gitEnv.FORGEJO__database__USER = env(USER)" | \
yq "$gitEnv.FORGEJO__database__PASSWD = env.PW" | \ yq "$gitEnv.FORGEJO__database__PASSWD = env(PW)" | \
yq "$dbEnv.MARIADB_DATABASE = env.DB" | \ yq "$dbEnv.MARIADB_DATABASE = env(DB)" | \
yq "$dbEnv.MARIADB_USER = env.USER" | \ yq "$dbEnv.MARIADB_USER = env(USER)" | \
yq "$dbEnv.MARIADB_PASSWORD = env.PW" | \ yq "$dbEnv.MARIADB_PASSWORD = env(PW)" | \
yq -y . | \
sudo tee "$secrets" >/dev/null sudo tee "$secrets" >/dev/null
end end
end end
@ -65,14 +64,13 @@ begin
and yq "$envKey.USER_UID = $uid" "$file" | \ and yq "$envKey.USER_UID = $uid" "$file" | \
yq "$envKey.USER_GID = $gid" | \ yq "$envKey.USER_GID = $gid" | \
yq -y . |
sudo tee "$config" >/dev/null sudo tee "$config" >/dev/null
mkdir -p "$dir" mkdir -p "$dir"
and chown -R $uid:$gid "$dir" and chown -R $uid:$gid "$dir"
rm "$file" rm "$file"
set port (yq (getSSHPortKey) "$secrets" --raw-output | extractPort) set port (yq (getSSHPortKey) "$secrets" | extractPort)
begin begin
printf "%s\n" \ printf "%s\n" \

View file

@ -50,7 +50,7 @@ begin
for name in $service $flood for name in $service $flood
set -l userKey "$(getServiceKey "$name").user" set -l userKey "$(getServiceKey "$name").user"
cp "$config" "$file" 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 end
for name in $servarr rtorrent for name in $servarr rtorrent
@ -64,8 +64,7 @@ begin
end end
cp "$config" "$file" cp "$config" "$file"
URL="https://$(getServiceDomain "$domain" "")/" yq "$(getServiceKey "$service").environment.JELLYFIN_PublishedServerUrl = env.URL" "$file" | \ URL="https://$(getServiceDomain "$domain" "")/" yq "$(getServiceKey "$service").environment.JELLYFIN_PublishedServerUrl = env(URL)" "$file" | \
yq -y . | \
sudo tee "$config" >/dev/null sudo tee "$config" >/dev/null
for dir in "$root"/{downloads,config/{,jellyfin,flood,rtorrent,radarr,sonarr,lidarr,prowlarr},media/{,movies,series,music}} for dir in "$root"/{downloads,config/{,jellyfin,flood,rtorrent,radarr,sonarr,lidarr,prowlarr},media/{,movies,series,music}}

View file

@ -30,13 +30,12 @@ begin
set uid (id -u $user) set uid (id -u $user)
set gid (id -g $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" set -l envKey "$(getServiceKey "$service").environment"
cp "$config" "$file" cp "$config" "$file"
and yq "$envKey.UID = $uid" "$file" | \ and yq "$envKey.UID = $uid" "$file" | \
yq "$envKey.GID = $gid" | \ yq "$envKey.GID = $gid" | \
yq -y . | \
sudo tee "$config" >/dev/null sudo tee "$config" >/dev/null
end end

View file

@ -65,16 +65,14 @@ begin
PROTO="https" DOMAIN="$domain" begin PROTO="https" DOMAIN="$domain" begin
set -l envKey "$(getServiceKey "$service").environment" set -l envKey "$(getServiceKey "$service").environment"
yq "$envKey.NEXTCLOUD_TRUSTED_DOMAINS = env.DOMAIN" "$source" | \ yq "$envKey.NEXTCLOUD_TRUSTED_DOMAINS = env(DOMAIN)" "$source" | \
yq "$envKey.OVERWRITEPROTOCOL = env.PROTO" | \ yq "$envKey.OVERWRITEPROTOCOL = env(PROTO)" | \
yq "$envKey.OVERWRITEHOST = env.DOMAIN" | \ yq "$envKey.OVERWRITEHOST = env(DOMAIN)" | \
URL="$PROTO://$DOMAIN" yq "$envKey.OVERWRITECLIURL = env.URL" | \ URL="$PROTO://$DOMAIN" yq "$envKey.OVERWRITECLIURL = env(URL)" | \
yq -y . | \
sudo tee "$core" >/dev/null sudo tee "$core" >/dev/null
DOMAIN=(getServiceDomain $officeDomain) yq "$officeEnv.server_name = env.DOMAIN" "$baseSource" | \ DOMAIN=(getServiceDomain $officeDomain) yq "$officeEnv.server_name = env(DOMAIN)" "$baseSource" | \
URL="https://$(string escape --style regex "$DOMAIN"):443" yq "$officeEnv.aliasgroup1 = env.URL" | \ URL="https://$(string escape --style regex "$DOMAIN"):443" yq "$officeEnv.aliasgroup1 = env(URL)" | \
yq -y . | \
sudo tee "$base" >/dev/null sudo tee "$base" >/dev/null
end end
@ -83,17 +81,16 @@ begin
PW="--static-auth-secret=$turnPW" \ PW="--static-auth-secret=$turnPW" \
DOMAIN="--realm=$domain" \ DOMAIN="--realm=$domain" \
yq "$key |= . + [env.PW, env.DOMAIN]" "$secretsSource" | \ yq "$key |= . + [env(PW), env(DOMAIN)]" "$secretsSource" | \
yq -y . | \
sudo tee "$secrets" >/dev/null sudo tee "$secrets" >/dev/null
end end
installDockerService $argv installDockerService $argv
set turnPort (yq --raw-output (getServicePortKey "$turn") "$secrets" | extractPort) set turnPort (yq (getServicePortKey "$turn") "$secrets" | extractPort)
set turnPort (yq --raw-output "$portKey" "$secrets" | mutatePort "$turnPort") set turnPort (yq "$portKey" "$secrets" | mutatePort "$turnPort")
cp "$secrets" "$file" 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" rm "$file"
end end

View file

@ -13,12 +13,12 @@ begin
set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32")
set -l envKey ".services.$service.environment" set -l envKey ".services.$service.environment"
set -l dbKey "$envKey.DATABASE_URL" 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 initializeServiceInstallation $argv
sudo cp "$file" "$root" sudo cp "$file" "$root"
URL=$dbUrl yq "$dbKey = env.URL" "$source" | \ URL=$dbUrl yq "$dbKey = env(URL)" "$source" | \
PW=$pw yq ".services.db.environment.POSTGRES_PASSWORD = env.PW" | \ PW=$pw yq ".services.db.environment.POSTGRES_PASSWORD = env(PW)" | \
sudo tee (getServiceSecretsConfig $argv) >/dev/null sudo tee (getServiceSecretsConfig $argv) >/dev/null
installDockerService $argv installDockerService $argv

View file

@ -80,7 +80,7 @@ begin
set -l url set -l url
set -l config (getServiceSecretsConfig $argv) set -l config (getServiceSecretsConfig $argv)
set -l portKey (getServicePortKey "$service") 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" ] if [ -n "$_flag_url" ]
set url "$_flag_url" set url "$_flag_url"
@ -136,8 +136,8 @@ begin
sudo mkdir -p "$nginxRoot" sudo mkdir -p "$nginxRoot"
cp "$config" "$file" cp "$config" "$file"
set exposedPort (yq --raw-output "$portKey" "$file" | mutatePort $port) set exposedPort (yq "$portKey" "$file" | mutatePort $port)
PORT=$exposedPort yq -y "$portKey = env.PORT" "$file" | sudo tee "$config" >/dev/null PORT=$exposedPort yq "$portKey = env(PORT)" "$file" | sudo tee "$config" >/dev/null
end end
end end
end end

View file

@ -14,18 +14,17 @@ begin
cp "$dir/docker-compose.base.yml" (getServiceRoot $argv) cp "$dir/docker-compose.base.yml" (getServiceRoot $argv)
USER="$service" begin USER="$service" begin
yq "$tsEnv.TS3SERVER_DB_USER = env.USER" "$source" | \ yq "$tsEnv.TS3SERVER_DB_USER = env(USER)" "$source" | \
yq "$dbEnv.MARIADB_USER = env.USER" yq "$dbEnv.MARIADB_USER = env(USER)"
end | \ end | \
PW="$pw" begin PW="$pw" begin
yq "$tsEnv.TS3SERVER_DB_PASSWORD = env.PW" | \ yq "$tsEnv.TS3SERVER_DB_PASSWORD = env(PW)" | \
yq "$dbEnv.MARIADB_PASSWORD = env.PW" yq "$dbEnv.MARIADB_PASSWORD = env(PW)"
end | \ end | \
DB="$db" begin DB="$db" begin
yq "$tsEnv.TS3SERVER_DB_NAME = env.DB" | \ yq "$tsEnv.TS3SERVER_DB_NAME = env(DB)" | \
yq "$dbEnv.MARIADB_DATABASE = env.DB" yq "$dbEnv.MARIADB_DATABASE = env(DB)"
end | \ end | \
yq . | \
sudo tee (getServiceSecretsConfig $argv) >/dev/null sudo tee (getServiceSecretsConfig $argv) >/dev/null
installDockerService $argv installDockerService $argv

View file

@ -10,15 +10,15 @@ begin
set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32")
set -l envKey ".services.vaultwarden.environment" set -l envKey ".services.vaultwarden.environment"
set -l dbKey "$envKey.DATABASE_URL" 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 initializeServiceInstallation $argv
URL="https://$domain.$(getMachineFQDN)" yq "$envKey.DOMAIN = env.URL" "$file" | \ URL="https://$domain.$(getMachineFQDN)" yq "$envKey.DOMAIN = env(URL)" "$file" | \
ADDRESS="noreply@$(getMachineFQDN)" yq -y "$envKey.SMTP_FROM = env.ADDRESS" | \ ADDRESS="noreply@$(getMachineFQDN)" yq "$envKey.SMTP_FROM = env(ADDRESS)" | \
sudo tee "$(getServiceRoot $argv)/$(basename "$file")" >/dev/null sudo tee "$(getServiceRoot $argv)/$(basename "$file")" >/dev/null
URL=$dbUrl yq "$dbKey = env.URL" "$source" | \ URL=$dbUrl yq "$dbKey = env(URL)" "$source" | \
PW=$pw yq ".services.db.environment.MARIADB_PASSWORD = env.PW" | \ PW=$pw yq ".services.db.environment.MARIADB_PASSWORD = env(PW)" | \
sudo tee (getServiceSecretsConfig $argv) >/dev/null sudo tee (getServiceSecretsConfig $argv) >/dev/null
installDockerService $argv installDockerService $argv