2023-03-20 02:32:51 -07:00
|
|
|
{{- if and (or (and (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "CLOUDFLARE_R2_ID"))) (env "CLOUDFLARE_R2_ID")) (or (and (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "CLOUDFLARE_R2_SECRET"))) (env "CLOUDFLARE_R2_SECRET")) (ne .user.cloudflare.r2 "") -}}
|
2023-01-29 20:44:55 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
CONFIG_FILE="$HOME/.config/rclone/rclone.conf"
|
|
|
|
if cat "$CONFIG_FILE" | grep '# MEGABYTE LABS MANAGED S3'; then
|
|
|
|
# TODO: Remove old block
|
2023-04-19 05:13:42 -07:00
|
|
|
START_LINE="$(echo `grep -n -m 1 "# MEGABYTE LABS MANAGED S3" "$CONFIG_FILE" | cut -f1 -d ":"`)"
|
|
|
|
END_LINE="$(echo `grep -n -m 1 "# MEGABYTE LABS MANAGED S3" "$CONFIG_FILE" | cut -f1 -d ":"`)"
|
2023-01-29 20:44:55 -08:00
|
|
|
if command -v gsed > /dev/null; then
|
|
|
|
gsed -i "$START_LINE,$END_LINEd" "$CONFIG_FILE"
|
|
|
|
else
|
|
|
|
sed -i "$START_LINE,$END_LINEd" "$CONFIG_FILE"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
tee -a "$CONFIG_FILE" > /dev/null <<EOT
|
|
|
|
# MEGABYTE LABS MANAGED S3
|
|
|
|
[{{ .user.username}}-s3]
|
2023-06-18 20:30:41 -07:00
|
|
|
access_key_id = {{ if (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "CLOUDFLARE_R2_ID")) }}{{- includeTemplate "secrets/CLOUDFLARE_R2_ID" | decrypt | trim -}}{{ else }}{{- env "CLOUDFLARE_R2_ID" -}}{{ end }}
|
2023-04-18 22:15:21 -07:00
|
|
|
acl = private
|
|
|
|
endpoint = {{ .user.cloudflare.r2 }}.r2.cloudflarestorage.com/user
|
2023-01-29 20:44:55 -08:00
|
|
|
provider = Cloudflare
|
|
|
|
region = auto
|
2023-06-18 20:30:41 -07:00
|
|
|
secret_access_key = {{ if (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "CLOUDFLARE_R2_SECRET")) }}{{- includeTemplate "secrets/CLOUDFLARE_R2_SECRET" | decrypt | trim -}}{{ else }}{{- env "CLOUDFLARE_R2_SECRET" -}}{{ end }}
|
2023-04-18 22:15:21 -07:00
|
|
|
type = s3
|
2023-01-29 20:44:55 -08:00
|
|
|
# MEGABYTE LABS MANAGED S3
|
|
|
|
EOT
|
2023-02-04 00:19:52 -08:00
|
|
|
{{- end -}}
|