shithub: bin.rc

ref: 4e18dc77f2ab9257b363ccb480a69cb9def901ba
dir: /bin/secretz/

View raw version
#!/bin/rc
# secretz - a local replacement for secstore
rfork en
enc=$home/lib/factotum
fn usage {
	>[1=2] echo 'secretz [-c | -e | -l]'
	exit usage
}
ramfs -p
fn secretz {@{
	echo -n 'secret: '
	</dev/cons >/dev/consctl {
		echo rawon
		read >/tmp/secret
	}
	echo
	switch($1){
	case -c
		sam /tmp/factotum
		</tmp/factotum >$enc <[3]/tmp/secret auth/aescbc -i -e || exit auth
	case -e
		<$enc >/tmp/factotum <[3]/tmp/secret auth/aescbc -i -d || exit auth
		sam /tmp/factotum
		</tmp/factotum >$enc <[3]/tmp/secret auth/aescbc -i -e
		echo -n 'load? '
		if(~ `{read} y yes)
			read -m /tmp/factotum >/mnt/factotum/ctl
	case -l *
		<$enc >/tmp/factotum <[3]/tmp/secret auth/aescbc -i -d || exit auth
		read -m /tmp/factotum >/mnt/factotum/ctl
	}
	exit ''
}}
while(! secretz $1)
	;