feat: Added age support.

This commit is contained in:
2025-10-28 13:33:52 -04:00
parent ba46ba6a6c
commit 847ca621ad

38
envr
View File

@@ -34,29 +34,51 @@ def "main import" [
$"file '($file)' imported successfull!" $"file '($file)' imported successfull!"
} }
const db_path = '/home/spencer/.envr/data.db' const db_path = '/home/spencer/.envr/data.age'
# Create or load the database # Create or load the database
def "open db" [] { def "open db" [] {
if (not ($db_path | path exists)) { if (not ($db_path | path exists)) {
init-db create-db
} } else {
stor import -f $db_path # Open the db
let dec = mktemp -p ~/.envr;
age -d -i ((main config show).priv_key | path expand) $db_path | save -f $dec
stor import -f $dec
rm $dec
} }
def "init-db" []: nothing -> table { stor open
sqlite3 $db_path 'create table envr_env_files ( }
def "create-db" []: nothing -> any {
let dec = mktemp -p ~/.envr;
sqlite3 $dec 'create table envr_env_files (
path text primary key not null path text primary key not null
, dir text not null , dir text not null
, remotes text -- JSON , remotes text -- JSON
, sha256 text not null , sha256 text not null
, contents text not null , contents text not null
);' );'
let pub_key = ((main config show).pub_key | path expand);
age -R $pub_key $dec | save -f $db_path
stor import -f $dec
rm $dec;
} }
def "close db" [] { def "close db" [] {
stor export --file-name $'($db_path).new' let dec = mktemp -p ~/.envr;
mv $'($db_path).new' $db_path
stor export --file-name $dec;
# Encrypt the file
let pub_key = ((main config show).pub_key | path expand);
age -R $pub_key $dec | save -f $db_path
rm $dec
} }
# Supported config formats # Supported config formats