summaryrefslogtreecommitdiff
path: root/src/Propellor
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor')
-rw-r--r--src/Propellor/Property/Apt.hs16
-rw-r--r--src/Propellor/Property/SiteSpecific/JoeySites.hs96
2 files changed, 78 insertions, 34 deletions
diff --git a/src/Propellor/Property/Apt.hs b/src/Propellor/Property/Apt.hs
index 4faf0984..2e7ccb04 100644
--- a/src/Propellor/Property/Apt.hs
+++ b/src/Propellor/Property/Apt.hs
@@ -16,6 +16,7 @@ import qualified Propellor.Property.File as File
import qualified Propellor.Property.Service as Service
import Propellor.Property.File (Line)
import Propellor.Types.Info
+import Utility.SafeCommand
data HostMirror = HostMirror Url
deriving (Eq, Show, Typeable)
@@ -308,11 +309,22 @@ buildDep ps = robustly $ go
-- in the specifed directory, with a dummy package also
-- installed so that autoRemove won't remove them.
buildDepIn :: FilePath -> Property DebianLike
-buildDepIn dir = cmdPropertyEnv "sh" ["-c", cmd] noninteractiveEnv
+buildDepIn dir = go
`changesFile` dpkgStatus
`requires` installedMin ["devscripts", "equivs"]
where
- cmd = "cd '" ++ dir ++ "' && mk-build-deps debian/control --install --tool 'apt-get -y --no-install-recommends' --remove"
+ -- mk-build-deps may leave files behind sometimes, eg on failure,
+ -- so run it in a temp directory, passing the path to the control
+ -- file
+ go :: UncheckedProperty DebianLike
+ go = unchecked $ property ("build-dep in " ++ dir) $ liftIO $
+ withTmpDir "build-dep" $ \tmpdir -> do
+ cmdResult <$> boolSystem' "mk-build-deps"
+ [ File $ dir </> "debian" </> "control"
+ , Param "--install"
+ , Param "--tool"
+ , Param "apt-get -y --no-install-recommends"
+ ] (\p -> p { cwd = Just tmpdir })
-- | The name of a package, a glob to match the names of packages, or a regexp
-- surrounded by slashes to match the names of packages. See
diff --git a/src/Propellor/Property/SiteSpecific/JoeySites.hs b/src/Propellor/Property/SiteSpecific/JoeySites.hs
index d6043517..9b8a7e70 100644
--- a/src/Propellor/Property/SiteSpecific/JoeySites.hs
+++ b/src/Propellor/Property/SiteSpecific/JoeySites.hs
@@ -1238,53 +1238,42 @@ homeNAS = propertyList "home NAS" $ props
[ "# let users power control startech hub with uhubctl"
, "ATTR{idVendor}==\"" ++ hubvendor ++ "\", ATTR{idProduct}==\"005a\", MODE=\"0666\""
]
- & autoMountDrive "archive-10" (USBHubPort hubvendor 1) (Just "archive-oldest")
- & autoMountDrive "archive-11" (USBHubPort hubvendor 2) (Just "archive-older")
- & autoMountDrive "archive-12" (USBHubPort hubvendor 3) (Just "archive-old")
- & autoMountDrive "archive-13" (USBHubPort hubvendor 4) (Just "archive")
+ & autoMountDrivePort "archive-10" (USBHubPort hubvendor hubloc 1)
+ (Just "archive-oldest")
+ & autoMountDrivePort "archive-11" (USBHubPort hubvendor hubloc 2)
+ (Just "archive-older")
+ & autoMountDrivePort "archive-12" (USBHubPort hubvendor hubloc 3)
+ (Just "archive-old")
+ & autoMountDrivePort "archive-13" (USBHubPort hubvendor hubloc 4)
+ (Just "archive")
+ & autoMountDrive "passport" Nothing
& Apt.installed ["git-annex", "borgbackup"]
where
hubvendor = "0409"
+ hubloc = "4-1.6"
-data USBHubPort = USBHubPort String Int
+data USBHubPort = USBHubPort
+ { hubVendor :: String
+ , hubLocation :: String
+ , hubPort :: Int
+ }
-- Makes a USB drive with the given label automount, and unmount after idle
-- for a while.
--
-- The hub port is turned on and off automatically as needed, using
-- uhubctl.
-autoMountDrive :: Mount.Label -> USBHubPort -> Maybe FilePath -> Property DebianLike
-autoMountDrive label (USBHubPort hubvendor port) malias = propertyList desc $ props
- & File.ownerGroup mountpoint (User "joey") (Group "joey")
- `requires` File.dirExists mountpoint
- & case malias of
- Just t -> ("/media/joey/" ++ t) `File.isSymlinkedTo`
- File.LinkTarget mountpoint
- Nothing -> doNothing <!> doNothing
- & File.hasContent ("/etc/systemd/system/" ++ mount)
- [ "[Unit]"
- , "Description=" ++ label
- , "Requires=" ++ hub
- , "After=" ++ hub
- , "[Mount]"
- -- avoid mounting whenever the block device is available,
- -- only want to automount on demand
- , "Options=noauto"
- , "What=" ++ devfile
- , "Where=" ++ mountpoint
- , "[Install]"
- , "WantedBy="
- ]
- `onChange` Systemd.daemonReloaded
+autoMountDrivePort :: Mount.Label -> USBHubPort -> Maybe FilePath -> Property DebianLike
+autoMountDrivePort label hp malias = propertyList desc $ props
& File.hasContent ("/etc/systemd/system/" ++ hub)
[ "[Unit]"
- , "Description=Startech usb hub port " ++ show port
+ , "Description=Startech usb hub port " ++ show (hubPort hp)
, "PartOf=" ++ mount
, "[Service]"
, "Type=oneshot"
, "RemainAfterExit=true"
- , "ExecStart=/usr/sbin/uhubctl -a on -p " ++ show port ++ " --vendor " ++ hubvendor
- , "ExecStop=/bin/sh -c 'uhubctl -a off -p " ++ show port ++ " --vendor " ++ hubvendor
+ , "ExecStart=/usr/sbin/uhubctl -a on " ++ selecthubport
+ , "ExecStop=/bin/sh -c 'uhubctl -a off " ++ selecthubport
-- Powering off the port does not remove device
-- files, so ask udev to remove the devfile; it will
-- be added back after the drive next spins up
@@ -1297,6 +1286,50 @@ autoMountDrive label (USBHubPort hubvendor port) malias = propertyList desc $ pr
, "WantedBy="
]
`onChange` Systemd.daemonReloaded
+ & autoMountDrive'
+ [ "Requires=" ++ hub
+ , "After=" ++ hub
+ ] label malias
+ where
+ devfile = "/dev/disk/by-label/" ++ label
+ mountpoint = "/media/joey/" ++ label
+ desc = "auto mount with hub port power control " ++ mountpoint
+ hub = "startech-hub-port-" ++ show (hubPort hp) ++ ".service"
+ mount = svcbase ++ ".mount"
+ svcbase = Systemd.escapePath mountpoint
+ selecthubport = unwords
+ [ "-p", show (hubPort hp)
+ , "-n", hubVendor hp
+ , "-l", hubLocation hp
+ ]
+
+-- Makes a USB drive with the given label automount, and unmount after idle
+-- for a while.
+autoMountDrive :: Mount.Label -> Maybe FilePath -> Property DebianLike
+autoMountDrive = autoMountDrive' []
+
+autoMountDrive' :: [String] -> Mount.Label -> Maybe FilePath -> Property DebianLike
+autoMountDrive' mountunitadd label malias = propertyList desc $ props
+ & File.ownerGroup mountpoint (User "joey") (Group "joey")
+ `requires` File.dirExists mountpoint
+ & case malias of
+ Just t -> ("/media/joey/" ++ t) `File.isSymlinkedTo`
+ File.LinkTarget mountpoint
+ Nothing -> doNothing <!> doNothing
+ & File.hasContent ("/etc/systemd/system/" ++ mount)
+ ([ "[Unit]"
+ , "Description=" ++ label
+ ] ++ mountunitadd ++
+ [ "[Mount]"
+ -- avoid mounting whenever the block device is available,
+ -- only want to automount on demand
+ , "Options=noauto"
+ , "What=" ++ devfile
+ , "Where=" ++ mountpoint
+ , "[Install]"
+ , "WantedBy="
+ ])
+ `onChange` Systemd.daemonReloaded
& File.hasContent ("/etc/systemd/system/" ++ automount)
[ "[Unit]"
, "Description=Automount " ++ label
@@ -1316,7 +1349,6 @@ autoMountDrive label (USBHubPort hubvendor port) malias = propertyList desc $ pr
devfile = "/dev/disk/by-label/" ++ label
mountpoint = "/media/joey/" ++ label
desc = "auto mount " ++ mountpoint
- hub = "startech-hub-port-" ++ show port ++ ".service"
automount = svcbase ++ ".automount"
mount = svcbase ++ ".mount"
svcbase = Systemd.escapePath mountpoint