summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Schroot.hs
blob: bb20f6e63eff3f48208a2dff5b7ab44218f09444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- | Maintainer: Sean Whitton <spwhitton@spwhitton.name>

{-# LANGUAGE DeriveDataTypeable #-}

module Propellor.Property.Schroot where

import Propellor.Base
import Propellor.Types.Info
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt

import Utility.FileMode

data UseOverlays = UseOverlays deriving (Eq, Show, Typeable)

-- | Indicate that a schroots on a host should use @union-type=overlay@
--
-- Setting this property does not actually ensure that the line
-- @union-type=overlay@ is present in any schroot config files.  See
-- 'Propellor.Property.Sbuild.built' for example usage.
useOverlays :: Property (HasInfo + UnixLike)
useOverlays = pureInfoProperty "use schroot overlays" (InfoVal UseOverlays)

-- | Gets whether a host uses overlays.
usesOverlays :: Propellor Bool
usesOverlays = isJust . fromInfoVal
	<$> (askInfo :: Propellor (InfoVal UseOverlays))

-- | Configure schroot such that all schroots with @union-type=overlay@ in their
-- configuration will run their overlays in a tmpfs.
--
-- Implicitly sets 'useOverlays' info property.
--
-- Shell script from <https://wiki.debian.org/sbuild>.
overlaysInTmpfs :: Property (HasInfo + DebianLike)
overlaysInTmpfs = go `requires` installed
  where
	f = "/etc/schroot/setup.d/04tmpfs"
	go :: Property (HasInfo + UnixLike)
	go = combineProperties "schroot overlays in tmpfs" $ props
		& useOverlays
		& f `File.hasContent`
			[ "#!/bin/sh"
			, ""
			, "set -e"
			, ""
			, ". \"$SETUP_DATA_DIR/common-data\""
			, ". \"$SETUP_DATA_DIR/common-functions\""
			, ". \"$SETUP_DATA_DIR/common-config\""
			, ""
			, ""
			, "if [ $STAGE = \"setup-start\" ]; then"
			, "  mount -t tmpfs overlay /var/lib/schroot/union/overlay"
			, "elif [ $STAGE = \"setup-recover\" ]; then"
			, "  mount -t tmpfs overlay /var/lib/schroot/union/overlay"
			, "elif [ $STAGE = \"setup-stop\" ]; then"
			, "  umount -f /var/lib/schroot/union/overlay"
			, "fi"
			]
		`onChange` (f `File.mode` combineModes (readModes ++ executeModes))

installed :: Property DebianLike
installed = Apt.installed ["schroot"]