#!/usr/bin/env nix-script #!>haskell #! shell | bup git #! env | BUP_DIR #! haskell | shell-conduit filepath import Data.List (intersperse) import Data.Conduit.Shell import Data.Conduit.Shell.Segments (strings) import Data.Conduit.Shell.Variadic (variadicProcess) import System.FilePath -- | regexs for excluded files excluded :: [String] excluded = intersperse "--exclude-rx" [ "/rnhmjoj/game/" , "/rnhmjoj/\\.cache/" , "/unity3d/.+/.+/Unity/" ] main :: IO () main = run $ mapM_ backup =<< strings (bup "ls") -- | Finds the path of a backup findPath :: String -> Segment FilePath findPath path = do files <- strings (bup "ls" "-A" path) if length files == 1 then findPath (path head files) else return $ "/" final path where final = concat . drop 2 . splitPath -- | Runs the backup backup :: String -> Segment () backup name = do path <- findPath (name "latest") proc "bup" ("index" : path : "--exclude-rx" : excluded) bup "save" "-n" name path -- | Fix for missing execs on NixOS bup :: ProcessType r => String -> r bup = variadicProcess "bup"