propellor spin
This commit is contained in:
parent
ad822196aa
commit
ef8c1d22cd
|
@ -57,8 +57,16 @@ testvm = host "testvm.kitenet.net"
|
||||||
& os (System (Debian Unstable) "amd64")
|
& os (System (Debian Unstable) "amd64")
|
||||||
& OS.cleanInstallOnce (OS.Confirmed "testvm.kitenet.net")
|
& OS.cleanInstallOnce (OS.Confirmed "testvm.kitenet.net")
|
||||||
`onChange` propertyList "fixing up after clean install"
|
`onChange` propertyList "fixing up after clean install"
|
||||||
[ OS.preserveRootSshAuthorized
|
[ User.shadowConfig True
|
||||||
|
, OS.preserveRootSshAuthorized
|
||||||
|
, OS.preserveResolvConf
|
||||||
|
, Grub.boots "/dev/sda"
|
||||||
|
`requires` Grub.installed Grub.PC
|
||||||
]
|
]
|
||||||
|
& Hostname.sane
|
||||||
|
& Hostname.searchDomain
|
||||||
|
& Apt.installed ["linux-image-amd64"]
|
||||||
|
& Apt.installed ["ssh"]
|
||||||
|
|
||||||
darkstar :: Host
|
darkstar :: Host
|
||||||
darkstar = host "darkstar.kitenet.net"
|
darkstar = host "darkstar.kitenet.net"
|
||||||
|
|
|
@ -17,6 +17,7 @@ propellor (1.1.0) UNRELEASED; urgency=medium
|
||||||
to do an in-place conversion from Fedora to Debian. Use with caution!
|
to do an in-place conversion from Fedora to Debian. Use with caution!
|
||||||
* Added group-related properties. Thanks, Félix Sipma.
|
* Added group-related properties. Thanks, Félix Sipma.
|
||||||
* Added Git.barerepo. Thanks, Félix Sipma.
|
* Added Git.barerepo. Thanks, Félix Sipma.
|
||||||
|
* Added Grub.installed and Grub.boots properties.
|
||||||
* hasSomePassword and hasPassword now default to using the name of the
|
* hasSomePassword and hasPassword now default to using the name of the
|
||||||
host as the Context for the password. To specify a different context,
|
host as the Context for the password. To specify a different context,
|
||||||
use hasSomePassword' and hasPassword' (API change)
|
use hasSomePassword' and hasPassword' (API change)
|
||||||
|
|
|
@ -7,8 +7,46 @@ import qualified Propellor.Property.Apt as Apt
|
||||||
-- | Eg, hd0,0 or xen/xvda1
|
-- | Eg, hd0,0 or xen/xvda1
|
||||||
type GrubDevice = String
|
type GrubDevice = String
|
||||||
|
|
||||||
|
-- | Eg, /dev/sda
|
||||||
|
type OSDevice = String
|
||||||
|
|
||||||
type TimeoutSecs = Int
|
type TimeoutSecs = Int
|
||||||
|
|
||||||
|
-- | Types of machines that grub can boot.
|
||||||
|
data BIOS = PC | EFI64 | EFI32 | Coreboot | Xen
|
||||||
|
|
||||||
|
-- | Installs the grub package. This does not make grub be used as the
|
||||||
|
-- bootloader.
|
||||||
|
--
|
||||||
|
-- This includes running update-grub, so that the grub boot menu is
|
||||||
|
-- created. It will be automatically updated when kernel packages are
|
||||||
|
-- installed.
|
||||||
|
installed :: BIOS -> Property
|
||||||
|
installed bios =
|
||||||
|
Apt.installed [pkg] `describe` "grub package installed"
|
||||||
|
`before`
|
||||||
|
cmdProperty "update-grub" []
|
||||||
|
where
|
||||||
|
pkg = case bios of
|
||||||
|
PC -> "grub-pc"
|
||||||
|
EFI64 -> "grub-efi-amd64"
|
||||||
|
EFI32 -> "grub-efi-ia32"
|
||||||
|
Coreboot -> "grub-coreboot"
|
||||||
|
Xen -> "grub-xen"
|
||||||
|
|
||||||
|
-- | Installs grub onto a device, so the system can boot from that device.
|
||||||
|
--
|
||||||
|
-- You may want to install grub to multiple devices; eg for a system
|
||||||
|
-- that uses software RAID.
|
||||||
|
--
|
||||||
|
-- Note that this property does not check if grub is already installed
|
||||||
|
-- on the device; it always does the work to reinstall it. It's a good idea
|
||||||
|
-- to arrange for this property to only run once, by eg making it be run
|
||||||
|
-- onChange after OS.cleanInstallOnce.
|
||||||
|
boots :: OSDevice -> Property
|
||||||
|
boots dev = cmdProperty "grub-install" [dev]
|
||||||
|
`describe` ("grub boots " ++ dev)
|
||||||
|
|
||||||
-- | Use PV-grub chaining to boot
|
-- | Use PV-grub chaining to boot
|
||||||
--
|
--
|
||||||
-- Useful when the VPS's pv-grub is too old to boot a modern kernel image.
|
-- Useful when the VPS's pv-grub is too old to boot a modern kernel image.
|
||||||
|
@ -31,8 +69,8 @@ chainPVGrub rootdev bootdev timeout = combineProperties desc
|
||||||
]
|
]
|
||||||
, "/boot/load.cf" `File.hasContent`
|
, "/boot/load.cf" `File.hasContent`
|
||||||
[ "configfile (" ++ bootdev ++ ")/boot/grub/grub.cfg" ]
|
[ "configfile (" ++ bootdev ++ ")/boot/grub/grub.cfg" ]
|
||||||
, Apt.installed ["grub-xen"]
|
, installed Xen
|
||||||
, flagFile (scriptProperty ["update-grub; grub-mkimage --prefix '(" ++ bootdev ++ ")/boot/grub' -c /boot/load.cf -O x86_64-xen /usr/lib/grub/x86_64-xen/*.mod > /boot/xen-shim"]) "/boot/xen-shim"
|
, flagFile (scriptProperty ["grub-mkimage --prefix '(" ++ bootdev ++ ")/boot/grub' -c /boot/load.cf -O x86_64-xen /usr/lib/grub/x86_64-xen/*.mod > /boot/xen-shim"]) "/boot/xen-shim"
|
||||||
`describe` "/boot-xen-shim"
|
`describe` "/boot-xen-shim"
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
|
|
|
@ -2,18 +2,16 @@ module Propellor.Property.OS (
|
||||||
cleanInstallOnce,
|
cleanInstallOnce,
|
||||||
Confirmation(..),
|
Confirmation(..),
|
||||||
preserveNetworkInterfaces,
|
preserveNetworkInterfaces,
|
||||||
|
preserveResolvConf,
|
||||||
preserveRootSshAuthorized,
|
preserveRootSshAuthorized,
|
||||||
grubBoots,
|
|
||||||
GrubDev,
|
|
||||||
rebootForced,
|
rebootForced,
|
||||||
kernelInstalled,
|
|
||||||
oldOSRemoved,
|
oldOSRemoved,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Propellor
|
import Propellor
|
||||||
import qualified Propellor.Property.Debootstrap as Debootstrap
|
import qualified Propellor.Property.Debootstrap as Debootstrap
|
||||||
import qualified Propellor.Property.Ssh as Ssh
|
import qualified Propellor.Property.Ssh as Ssh
|
||||||
import qualified Propellor.Property.User as User
|
import qualified Propellor.Property.File as File
|
||||||
import Propellor.Property.Mount
|
import Propellor.Property.Mount
|
||||||
import Propellor.Property.Chroot.Util (stdPATH)
|
import Propellor.Property.Chroot.Util (stdPATH)
|
||||||
import Utility.SafeCommand
|
import Utility.SafeCommand
|
||||||
|
@ -47,12 +45,17 @@ import Control.Exception (throw)
|
||||||
-- > & os (System (Debian Unstable) "amd64")
|
-- > & os (System (Debian Unstable) "amd64")
|
||||||
-- > & cleanInstallOnce (Confirmed "foo.example.com")
|
-- > & cleanInstallOnce (Confirmed "foo.example.com")
|
||||||
-- > `onChange` propertyList "fixing up after clean install"
|
-- > `onChange` propertyList "fixing up after clean install"
|
||||||
-- > [ preserveNetworkInterfaces
|
-- > [ User.shadowConfig True
|
||||||
|
-- > , preserveNetworkInterfaces
|
||||||
|
-- > , preserveResolvConf
|
||||||
-- > , preserverRootSshAuthorized
|
-- > , preserverRootSshAuthorized
|
||||||
-- > -- , kernelInstalled
|
-- > , Apt.update
|
||||||
-- > -- , grubBoots "hd0"
|
-- > -- , Grub.boots "/dev/sda"
|
||||||
|
-- > -- `requires` Grub.installed Grub.PC
|
||||||
-- > -- , oldOsRemoved (Confirmed "foo.example.com")
|
-- > -- , oldOsRemoved (Confirmed "foo.example.com")
|
||||||
-- > ]
|
-- > ]
|
||||||
|
-- > & Hostname.sane
|
||||||
|
-- > & Apt.installed ["linux-image-amd64"]
|
||||||
-- > & Apt.installed ["ssh"]
|
-- > & Apt.installed ["ssh"]
|
||||||
-- > & User.hasSomePassword "root"
|
-- > & User.hasSomePassword "root"
|
||||||
-- > & User.accountFor "joey"
|
-- > & User.accountFor "joey"
|
||||||
|
@ -67,8 +70,6 @@ cleanInstallOnce confirmation = check (not <$> doesFileExist flagfile) $
|
||||||
`requires`
|
`requires`
|
||||||
propellorbootstrapped
|
propellorbootstrapped
|
||||||
`requires`
|
`requires`
|
||||||
User.shadowConfig True
|
|
||||||
`requires`
|
|
||||||
flipped
|
flipped
|
||||||
`requires`
|
`requires`
|
||||||
osbootstrapped
|
osbootstrapped
|
||||||
|
@ -96,8 +97,10 @@ cleanInstallOnce confirmation = check (not <$> doesFileExist flagfile) $
|
||||||
massRename (renamesout ++ renamesin)
|
massRename (renamesout ++ renamesin)
|
||||||
removeDirectoryRecursive newOSDir
|
removeDirectoryRecursive newOSDir
|
||||||
|
|
||||||
-- Prepare environment for running additional properties.
|
-- Prepare environment for running additional properties,
|
||||||
|
-- overriding old OS's environment.
|
||||||
void $ setEnv "PATH" stdPATH True
|
void $ setEnv "PATH" stdPATH True
|
||||||
|
void $ unsetEnv "LANG"
|
||||||
|
|
||||||
-- Remount /dev, so that block devices etc are
|
-- Remount /dev, so that block devices etc are
|
||||||
-- available for other properties to use.
|
-- available for other properties to use.
|
||||||
|
@ -105,6 +108,14 @@ cleanInstallOnce confirmation = check (not <$> doesFileExist flagfile) $
|
||||||
warningMessage $ "failed mounting /dev using " ++ devfstype ++ "; falling back to MAKEDEV generic"
|
warningMessage $ "failed mounting /dev using " ++ devfstype ++ "; falling back to MAKEDEV generic"
|
||||||
void $ boolSystem "sh" [Param "-c", Param "cd /dev && /sbin/MAKEDEV generic"]
|
void $ boolSystem "sh" [Param "-c", Param "cd /dev && /sbin/MAKEDEV generic"]
|
||||||
|
|
||||||
|
-- Mount /sys too, needed by eg, grub-mkconfig.
|
||||||
|
unlessM (mount "sysfs" "sysfs" "/sys") $
|
||||||
|
warningMessage "failed mounting /sys"
|
||||||
|
|
||||||
|
-- And /dev/pts, used by apt.
|
||||||
|
unlessM (mount "devpts" "devpts" "/dev/pts") $
|
||||||
|
warningMessage "failed mounting /dev/pts"
|
||||||
|
|
||||||
liftIO $ writeFile flagfile ""
|
liftIO $ writeFile flagfile ""
|
||||||
return MadeChange
|
return MadeChange
|
||||||
|
|
||||||
|
@ -164,6 +175,16 @@ confirmed desc (Confirmed c) = property desc $ do
|
||||||
preserveNetworkInterfaces :: Property
|
preserveNetworkInterfaces :: Property
|
||||||
preserveNetworkInterfaces = undefined
|
preserveNetworkInterfaces = undefined
|
||||||
|
|
||||||
|
-- | /etc/resolv.conf is copied the from the old OS
|
||||||
|
preserveResolvConf :: Property
|
||||||
|
preserveResolvConf = check (fileExist oldloc) $
|
||||||
|
property (newloc ++ " copied from old OS") $ do
|
||||||
|
ls <- liftIO $ lines <$> readFile oldloc
|
||||||
|
ensureProperty $ newloc `File.hasContent` ls
|
||||||
|
where
|
||||||
|
newloc = "/etc/resolv.conf"
|
||||||
|
oldloc = oldOSDir ++ newloc
|
||||||
|
|
||||||
-- | Root's .ssh/authorized_keys has added to it any ssh keys that
|
-- | Root's .ssh/authorized_keys has added to it any ssh keys that
|
||||||
-- were authorized in the old OS. Any other contents of the file are
|
-- were authorized in the old OS. Any other contents of the file are
|
||||||
-- retained.
|
-- retained.
|
||||||
|
@ -176,19 +197,6 @@ preserveRootSshAuthorized = check (fileExist oldloc) $
|
||||||
newloc = "/root/.ssh/authorized_keys"
|
newloc = "/root/.ssh/authorized_keys"
|
||||||
oldloc = oldOSDir ++ newloc
|
oldloc = oldOSDir ++ newloc
|
||||||
|
|
||||||
-- | Installs an appropriate kernel from the OS distribution.
|
|
||||||
kernelInstalled :: Property
|
|
||||||
kernelInstalled = undefined
|
|
||||||
|
|
||||||
-- | Installs grub onto a device to boot the system.
|
|
||||||
--
|
|
||||||
-- You may want to install grub to multiple devices; eg for a system
|
|
||||||
-- that uses software RAID.
|
|
||||||
grubBoots :: GrubDev -> Property
|
|
||||||
grubBoots = undefined
|
|
||||||
|
|
||||||
type GrubDev = String
|
|
||||||
|
|
||||||
-- | Forces an immediate reboot, without contacting the init system.
|
-- | Forces an immediate reboot, without contacting the init system.
|
||||||
--
|
--
|
||||||
-- Can be used after cleanInstallOnce.
|
-- Can be used after cleanInstallOnce.
|
||||||
|
|
Loading…
Reference in New Issue