diff options
author | Andrew Cady <d@jerkface.net> | 2019-06-19 12:03:35 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2019-06-19 12:03:35 -0400 |
commit | 67553d3fb69b4af520a819ecf390dd943eb5880f (patch) | |
tree | 7e8cc4546550d3836e76f3a1938e8ddd69fdeba8 | |
parent | e5fc609586b56ab41c494d0c76757cc071c712a8 (diff) |
support for skel-files
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | fsmgr.hs | 19 | ||||
-rw-r--r-- | samizdat/samizdat-wip.yaml | 4 | ||||
-rw-r--r-- | samizdat/samizdat.yaml | 39 | ||||
-rw-r--r-- | src/ConfigFile.hs | 2 |
5 files changed, 59 insertions, 6 deletions
@@ -2,3 +2,4 @@ | |||
2 | /_build | 2 | /_build |
3 | *.btrfs | 3 | *.btrfs |
4 | *.btrfs~* | 4 | *.btrfs~* |
5 | _build/ | ||
@@ -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 | ||
25 | import ConfigFile | 25 | import ConfigFile |
26 | import System.Directory (createDirectoryIfMissing) | 26 | import System.Directory (getCurrentDirectory, createDirectoryIfMissing) |
27 | import System.Posix.Process (getProcessID) | 27 | import System.Posix.Process (getProcessID) |
28 | import System.Posix.Types (CUid (..)) | 28 | import System.Posix.Types (CUid (..)) |
29 | import System.Posix.User (getEffectiveUserID) | 29 | import 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 | ||
87 | absPath :: MonadIO m => FilePath -> m FilePath | ||
88 | absPath f@('/':_) = return f | ||
89 | absPath f = do | ||
90 | wd <- liftIO getCurrentDirectory | ||
91 | return $ wd </> f | ||
92 | |||
93 | getHomeDir :: Action FilePath | ||
94 | getHomeDir = do | ||
95 | Stdout homeDir <- cmd ["sh", "-c", "getent passwd \"$SUDO_USER\"|(IFS=: read _ _ _ _ _ d _; printf %s \"$d\")"] | ||
96 | return homeDir | ||
97 | |||
81 | buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () | 98 | buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () |
82 | buildInitialImage DiskImageConfig{..} mountpoint out = do | 99 | buildInitialImage 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 | ||
8 | binaries: | 10 | binaries: |
9 | - kiki | 11 | - kiki |
10 | - cokiki | 12 | - cokiki |
11 | - stack | 13 | - stack |
12 | - dhtd | 14 | - dhtd |
13 | - dht | 15 | - dht |
14 | chroot-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 @@ | |||
1 | parent: samizdat-wip | 1 | parent: samizdat-wip |
2 | packages: | 2 | packages: [] |
3 | - gpm | ||
4 | binaries: [] | 3 | binaries: [] |
5 | chroot-commands: [] | 4 | skel-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 | |||
37 | chroot-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 | ||
62 | parsePackageName :: Text -> Package | 63 | parsePackageName :: 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 | ||
75 | readCfg :: FilePath -> Action DiskImageConfig | 77 | readCfg :: FilePath -> Action DiskImageConfig |
76 | readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml | 78 | readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml |