summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2019-06-19 12:03:35 -0400
committerAndrew Cady <d@jerkface.net>2019-06-19 12:03:35 -0400
commit67553d3fb69b4af520a819ecf390dd943eb5880f (patch)
tree7e8cc4546550d3836e76f3a1938e8ddd69fdeba8
parente5fc609586b56ab41c494d0c76757cc071c712a8 (diff)
support for skel-files
-rw-r--r--.gitignore1
-rw-r--r--fsmgr.hs19
-rw-r--r--samizdat/samizdat-wip.yaml4
-rw-r--r--samizdat/samizdat.yaml39
-rw-r--r--src/ConfigFile.hs2
5 files changed, 59 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 1f1fb01..4e096f0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
2/_build 2/_build
3*.btrfs 3*.btrfs
4*.btrfs~* 4*.btrfs~*
5_build/
diff --git a/fsmgr.hs b/fsmgr.hs
index 0dc1790..429b0a1 100644
--- a/fsmgr.hs
+++ b/fsmgr.hs
@@ -23,7 +23,7 @@ import qualified Options.Applicative as Opt
23 ;import Options.Applicative hiding (action, command) 23 ;import Options.Applicative hiding (action, command)
24 24
25import ConfigFile 25import ConfigFile
26import System.Directory (createDirectoryIfMissing) 26import System.Directory (getCurrentDirectory, createDirectoryIfMissing)
27import System.Posix.Process (getProcessID) 27import System.Posix.Process (getProcessID)
28import System.Posix.Types (CUid (..)) 28import System.Posix.Types (CUid (..))
29import System.Posix.User (getEffectiveUserID) 29import System.Posix.User (getEffectiveUserID)
@@ -63,6 +63,12 @@ buildRoot config@DiskImageConfig{..} finalOut = do
63 forM_ (unpack <$> binaries) $ \b -> do 63 forM_ (unpack <$> binaries) $ \b -> do
64 p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b) 64 p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b)
65 cmd_ "cp -L" [p] [mountpoint </> "usr/local/bin" </> b] 65 cmd_ "cp -L" [p] [mountpoint </> "usr/local/bin" </> b]
66 {- 3.5 skel -}
67 forM_ (unpack <$> skelFiles) $ \f -> do
68 homeDir <- getHomeDir
69 target <- absPath mountpoint <&> (</> "etc/skel")
70 cmd_ "mkdir -p" [target]
71 cmd_ (Cwd homeDir) "cp -r --preserve=mode,timestamps -L --parents -t" [target] [f]
66 {- 4. custom setup commands -} 72 {- 4. custom setup commands -}
67 forM_ chrootCommands $ \c -> do 73 forM_ chrootCommands $ \c -> do
68 cmd_ "chroot" [mountpoint] "/bin/sh -c" [unpack c] 74 cmd_ "chroot" [mountpoint] "/bin/sh -c" [unpack c]
@@ -78,6 +84,17 @@ buildRoot config@DiskImageConfig{..} finalOut = do
78 cmd_ "btrfstune -S1" [out] 84 cmd_ "btrfstune -S1" [out]
79 cmd_ "mv" [out, finalOut] 85 cmd_ "mv" [out, finalOut]
80 86
87absPath :: MonadIO m => FilePath -> m FilePath
88absPath f@('/':_) = return f
89absPath f = do
90 wd <- liftIO getCurrentDirectory
91 return $ wd </> f
92
93getHomeDir :: Action FilePath
94getHomeDir = do
95 Stdout homeDir <- cmd ["sh", "-c", "getent passwd \"$SUDO_USER\"|(IFS=: read _ _ _ _ _ d _; printf %s \"$d\")"]
96 return homeDir
97
81buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () 98buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action ()
82buildInitialImage DiskImageConfig{..} mountpoint out = do 99buildInitialImage DiskImageConfig{..} mountpoint out = do
83 case initialImage of 100 case initialImage of
diff --git a/samizdat/samizdat-wip.yaml b/samizdat/samizdat-wip.yaml
index 0e506c8..f331a7f 100644
--- a/samizdat/samizdat-wip.yaml
+++ b/samizdat/samizdat-wip.yaml
@@ -5,11 +5,11 @@ packages:
5- cron 5- cron
6- sshfs 6- sshfs
7- emacs25 7- emacs25
8- gpm
9- parted
8binaries: 10binaries:
9- kiki 11- kiki
10- cokiki 12- cokiki
11- stack 13- stack
12- dhtd 14- dhtd
13- dht 15- dht
14chroot-commands:
15- "useradd u -G sudo -m -p '' -s /bin/bash"
diff --git a/samizdat/samizdat.yaml b/samizdat/samizdat.yaml
index dae433a..14fc9d8 100644
--- a/samizdat/samizdat.yaml
+++ b/samizdat/samizdat.yaml
@@ -1,5 +1,38 @@
1parent: samizdat-wip 1parent: samizdat-wip
2packages: 2packages: []
3- gpm
4binaries: [] 3binaries: []
5chroot-commands: [] 4skel-files:
5- '.bashrc'
6- '.config/git/ignore'
7- '.gitconfig' # This embeds my email address so not really suitable
8 # permanently.
9- '.spacemacs'
10- '.tmux.conf'
11- '.tmux.stage2.conf'
12- '.vimrc'
13- '.xbindkeysrc'
14- '.xinitrc'
15- '.Xresources'
16
17# dev tools
18- '.local/bin/stack'
19- '.local/bin/rustup'
20
21# keymap control/recue
22- '.local/bin/asdf'
23- '.local/bin/aoeu'
24- '.local/bin/ASDF'
25- '.local/bin/dvorak'
26- '.local/bin/qwer'
27- '.local/bin/асдф'
28
29# misc. programs/scripts I wrote
30- '.local/bin/google'
31- '.local/bin/jack-plumbing'
32- '.local/bin/musopen'
33- '.local/bin/record'
34- '.local/bin/sliceweasel'
35- '.local/bin/axis'
36
37chroot-commands:
38- "useradd u -G sudo -m -p '' -s /bin/bash"
diff --git a/src/ConfigFile.hs b/src/ConfigFile.hs
index 8b23582..a1d3662 100644
--- a/src/ConfigFile.hs
+++ b/src/ConfigFile.hs
@@ -57,6 +57,7 @@ data DiskImageConfig = DiskImageConfig {
57, unpackOnly :: Bool 57, unpackOnly :: Bool
58, binaries :: Vector Text 58, binaries :: Vector Text
59, chrootCommands :: Vector Text 59, chrootCommands :: Vector Text
60, skelFiles :: Vector Text
60} deriving (Show, Read) 61} deriving (Show, Read)
61 62
62parsePackageName :: Text -> Package 63parsePackageName :: Text -> Package
@@ -71,6 +72,7 @@ diskImageConfigParser = object $
71 <*> defaultField "unpack-only" False bool 72 <*> defaultField "unpack-only" False bool
72 <*> defaultField "binaries" Vector.empty (array string) 73 <*> defaultField "binaries" Vector.empty (array string)
73 <*> defaultField "chroot-commands" Vector.empty (array string) 74 <*> defaultField "chroot-commands" Vector.empty (array string)
75 <*> defaultField "skel-files" Vector.empty (array string)
74 76
75readCfg :: FilePath -> Action DiskImageConfig 77readCfg :: FilePath -> Action DiskImageConfig
76readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml 78readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml