Replace yq with go-yq

This commit is contained in:
Manuel Thalmann 2024-11-20 00:30:08 +01:00
parent 502db25da2
commit 7a0c771365
12 changed files with 53 additions and 64 deletions

View file

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

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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" \

View file

@ -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}}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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