2016-09-12 15:41:41 +02:00
|
|
|
#!/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
|
|
|
|
|
|
|
|
|
|
|
|
excluded :: [String]
|
|
|
|
excluded = intersperse "--exclude"
|
|
|
|
[ "/home/rnhmjoj/.cache/"
|
2017-04-08 23:04:56 +02:00
|
|
|
, "/home/rnhmjoj/game/"
|
|
|
|
, "/home/rnhmjoj/.config/mozilla/firefox/tay31tbe.default/lock"
|
2016-09-12 15:41:41 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = run (strings (bup "ls") >>= mapM_ backup)
|
|
|
|
|
|
|
|
|
|
|
|
findPath :: String -> Segment FilePath
|
|
|
|
findPath path = do
|
|
|
|
files <- strings (bup "ls" path)
|
|
|
|
if length files /= 1
|
|
|
|
then return ("/" </> final path)
|
|
|
|
else findPath (path </> head files)
|
|
|
|
where final = concat . drop 2 . splitPath
|
|
|
|
|
|
|
|
|
|
|
|
backup :: String -> Segment ()
|
|
|
|
backup name = do
|
|
|
|
path <- findPath (name </> "latest")
|
2017-04-08 23:04:56 +02:00
|
|
|
proc "bup" ("index" : path : "--exclude" : excluded)
|
2016-09-12 15:41:41 +02:00
|
|
|
bup "save" "-n" name path
|
|
|
|
|
|
|
|
|
|
|
|
bup :: ProcessType r => String -> r
|
|
|
|
bup = variadicProcess "bup"
|