summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/SiteSpecific/JoeySites.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor/Property/SiteSpecific/JoeySites.hs')
-rw-r--r--src/Propellor/Property/SiteSpecific/JoeySites.hs96
1 files changed, 64 insertions, 32 deletions
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