2021-04-09 00:35:36 +02:00
|
|
|
final: prev:
|
|
|
|
{
|
2021-04-11 00:25:36 +02:00
|
|
|
magic_rb = prev.magic_rb or {} // {
|
2021-12-22 23:48:31 +01:00
|
|
|
gpg-key = final.writeSubstitutedShellScriptBin {
|
2021-04-11 00:25:36 +02:00
|
|
|
name = "gpg-key";
|
|
|
|
file = ./gpg-key;
|
|
|
|
substitutes = with prev; {
|
2022-01-26 20:38:46 +01:00
|
|
|
inherit cryptsetup busybox findutils gnupg sudo;
|
2021-04-11 00:25:36 +02:00
|
|
|
};
|
2021-04-09 00:35:36 +02:00
|
|
|
};
|
2021-04-18 01:23:47 +02:00
|
|
|
|
|
|
|
gpg-key-hs = with prev; writers.writeHaskellBin
|
|
|
|
"gpg-key"
|
|
|
|
{ libraries = [ haskellPackages.shh ]; }
|
|
|
|
''
|
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
import Shh
|
|
|
|
import System.Posix.User (getRealUserID)
|
|
|
|
import System.Environment (getArgs)
|
|
|
|
|
|
|
|
loadFromBins ["${findutils}", "${busybox}", "${cryptsetup}"]
|
|
|
|
|
|
|
|
main = do
|
|
|
|
userId <- getRealUserID
|
|
|
|
if userId /= 0 then do
|
|
|
|
putStrLn "You must run this script as root."
|
|
|
|
else do
|
|
|
|
cmdArgs <- getArgs
|
|
|
|
let
|
|
|
|
action = cmdArgs !! 0
|
|
|
|
case action of
|
|
|
|
"open" -> do
|
|
|
|
cryptsetup "open" "/dev/disk/by-label/secret" "secret"
|
|
|
|
mkdir "-p" "/mnt/key"
|
|
|
|
|
|
|
|
mount "/dev/mapper/secret" "/mnt/key"
|
|
|
|
"close" -> do
|
|
|
|
umount "/mnt/key"
|
|
|
|
cryptsetup "close" "secret"
|
|
|
|
|
|
|
|
rm "-r" "/mnt/key"
|
|
|
|
mntContains <- captureTrim <| find "/mnt" "-maxdepth" "0" "-empty"
|
2021-04-19 20:06:38 +02:00
|
|
|
when (show mntContains == "") (putStrLn "delete /mnt" -- rm "-r" "/mnt")
|
|
|
|
_ -> do
|
2021-04-18 01:23:47 +02:00
|
|
|
putStrLn "open - open key\nclose - close key"
|
|
|
|
'';
|
2021-04-09 00:35:36 +02:00
|
|
|
};
|
|
|
|
}
|