2014-11-23 19:42:22 +00:00
|
|
|
module Propellor.Property.OS (
|
|
|
|
cleanInstallOnce,
|
|
|
|
Confirmation
|
|
|
|
confirm,
|
|
|
|
fixupNetworkAddresses,
|
2014-11-23 23:49:53 +00:00
|
|
|
rootSshAuthorized,
|
|
|
|
grubBoots,
|
|
|
|
kernelInstalled,
|
2014-11-23 19:42:22 +00:00
|
|
|
oldOSRemoved,
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Propellor
|
|
|
|
import qualified Propellor.Property.Chroot as Chroot
|
|
|
|
import qualified Propellor.Property.Debootstrap as Debootstrap
|
|
|
|
|
|
|
|
-- | Replaces whatever OS was installed before with a clean installation
|
|
|
|
-- of the OS that the Host is configured to have.
|
|
|
|
--
|
|
|
|
-- This can replace one Linux distribution with different one.
|
|
|
|
-- But, it can also fail and leave the system in an unbootable state.
|
|
|
|
--
|
2014-11-23 20:39:49 +00:00
|
|
|
-- To avoid this property being accidentially used, you have to provide
|
|
|
|
-- a Context containing the name of the host that you intend to apply the
|
|
|
|
-- property to.
|
|
|
|
--
|
2014-11-23 19:42:22 +00:00
|
|
|
-- This property only runs once. The cleanly installed system will have
|
|
|
|
-- a file /etc/propellor-cleaninstall, which indicates it was cleanly
|
|
|
|
-- installed.
|
|
|
|
--
|
|
|
|
-- You will typically want to run some more properties after the clean
|
|
|
|
-- install, to bootstrap from the cleanly installed system to a fully
|
|
|
|
-- working system. For example:
|
|
|
|
--
|
|
|
|
-- > & os (System (Debian Unstable) "amd64")
|
2014-11-23 20:39:49 +00:00
|
|
|
-- > & cleanInstall (Context "foo.example.com") (BackupOldOS <> UseOldKernel)
|
2014-11-23 19:42:22 +00:00
|
|
|
-- > `onChange` propertyList "fixing up after clean install"
|
|
|
|
-- > [ fixupNetworkInterfaces
|
2014-11-23 23:49:53 +00:00
|
|
|
-- > , rootSshAuthorized
|
|
|
|
-- > -- , kernelInstalled
|
|
|
|
-- > -- , grubBoots "hd0"
|
2014-11-23 19:42:22 +00:00
|
|
|
-- > ]
|
|
|
|
-- > & Apt.installed ["ssh"]
|
2014-11-23 20:39:49 +00:00
|
|
|
-- > & User.hasSomePassword "root"
|
|
|
|
-- > & User.accountFor "joey"
|
|
|
|
-- > & User.hasSomePassword "joey"
|
2014-11-23 19:42:22 +00:00
|
|
|
-- > -- rest of system properties here
|
2014-11-23 20:39:49 +00:00
|
|
|
cleanInstallOnce :: Context -> Exceptions -> Property
|
|
|
|
cleanInstallOnce (Context c) = check (not <$> doesFileExist flagfile) $
|
2014-11-23 19:42:22 +00:00
|
|
|
Property "OS cleanly installed" $ do
|
2014-11-23 20:39:49 +00:00
|
|
|
hostname <- asks hostName
|
|
|
|
when (hostname /= c) $
|
|
|
|
error "Run with bad context, not matching hostname. Not running cleanInstalOnce!"
|
2014-11-23 19:42:22 +00:00
|
|
|
error "TODO"
|
2014-11-23 20:39:49 +00:00
|
|
|
-- debootstrap /new-os chroot, but don't run propellor
|
|
|
|
-- inside the chroot.
|
2014-11-23 19:42:22 +00:00
|
|
|
-- unmount all mounts
|
|
|
|
-- move all directories to /old-os,
|
|
|
|
-- except for /boot and /lib/modules
|
|
|
|
-- move /new-os to /
|
2014-11-23 20:39:49 +00:00
|
|
|
-- touch flagfile
|
2014-11-23 19:42:22 +00:00
|
|
|
-- re-bootstrap propellor in /usr/local/propellor,
|
|
|
|
-- (using git repo bundle, privdata file, and possibly
|
|
|
|
-- git repo url, which all need to be arranged to
|
|
|
|
-- be present in /old-os's /usr/local/propellor)
|
2014-11-23 20:39:49 +00:00
|
|
|
-- enable shadow passwords (to avoid foot-shooting)
|
2014-11-23 19:42:22 +00:00
|
|
|
-- return MadeChange
|
|
|
|
where
|
|
|
|
flagfile = "/etc/propellor-cleaninstall"
|
|
|
|
|
|
|
|
-- | Sometimes you want an almost clean install, but with some exceptions.
|
|
|
|
data Exceptions
|
|
|
|
= UseOldKernel -- ^ Leave /boot and /lib/modules from old OS, so the system can boot using them as before
|
|
|
|
| BackupOldOS -- ^ Back up old OS to /old-os, to avoid losing any important files
|
|
|
|
| NoExceptions
|
|
|
|
| CombinedExceptions Exceptions Exceptions
|
|
|
|
|
|
|
|
instance Monoid Exceptions where
|
|
|
|
mempty = NoExceptions
|
|
|
|
mappend = CombinedExceptions
|
|
|
|
|
|
|
|
-- /etc/network/interfaces is configured to bring up all interfaces that
|
|
|
|
-- are currently up, using the same IP addresses.
|
|
|
|
--
|
|
|
|
-- This property only does anything if it comes after cleanInstall,
|
|
|
|
-- in the same propellor run where cleanInstall has made a change.
|
|
|
|
fixupNetworkInterfaces :: Property
|
|
|
|
fixupNetworkInterfaces = undefined
|
|
|
|
|
|
|
|
-- /root/.ssh/authorized_keys is copied from the old os
|
2014-11-23 23:49:53 +00:00
|
|
|
rootSshAuthorized :: Property
|
|
|
|
rootSshAuthorized = undefined
|
2014-11-23 19:42:22 +00:00
|
|
|
|
|
|
|
-- Installs an appropriate kernel from the distribution.
|
2014-11-23 23:49:53 +00:00
|
|
|
kernelInstalled :: Property
|
|
|
|
kernelInstalled = undefined
|
2014-11-23 19:42:22 +00:00
|
|
|
|
|
|
|
-- Installs grub to boot the system.
|
2014-11-23 23:49:53 +00:00
|
|
|
grubBoots :: GrubDev -> Property
|
|
|
|
grubBoots = undefined
|
2014-11-23 19:42:22 +00:00
|
|
|
|
|
|
|
-- Removes the old OS's backup from /old-os
|
|
|
|
oldOSRemoved :: Property
|
|
|
|
oldOSRemoved = check (doesDirectoryExist oldOsDir) $
|
|
|
|
Property "old OS backup removed" $ liftIO $ do
|
|
|
|
removeDirectoryRecursive oldOsDir
|
|
|
|
return MadeChange
|
|
|
|
|
|
|
|
oldOsDir :: FilePath
|
|
|
|
oldOsDir = "/old-os"
|