[hypnos] 重构 home 下 dotfiles 独立目录结构

This commit is contained in:
2026-01-23 01:20:06 +08:00
parent 2f31fbcd6e
commit 91a6a981c2
14 changed files with 47 additions and 12 deletions
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env zsh
sops-update-file() {
local src_file="$1"
local yaml_file="$2"
local age_key_file="$HOME/.config/sops/age/keys.txt"
if [[ -z "$src_file" || -z "$yaml_file" ]]; then
echo "用法: sops-update-file <原文件> <yaml文件>" >&2
return 1
fi
if [[ ! -f "$src_file" ]]; then
echo "找不到原文件: $src_file" >&2
return 1
fi
if [[ ! -f "$age_key_file" ]]; then
echo "找不到 age 私钥: $age_key_file" >&2
return 1
fi
local key_name="${yaml_file:t:r}"
local age_pub
age_pub="$(nix-shell -p age --run "age-keygen -y $age_key_file")" || return 1
local tmp
tmp="$(mktemp /tmp/sops-update.XXXXXX.yaml)" || return 1
{
echo "${key_name}: |"
sed 's/^/ /' "$src_file"
} > "$tmp"
nix-shell -p sops --run "sops --encrypt --input-type yaml --output-type yaml --age $age_pub --config /dev/null $tmp" > "$yaml_file"
local rc=$?
rm -f "$tmp"
return $rc
}