2023-05-05 16:43:21 +00:00
/ *
Copyright © 2022 SUSE LLC
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
package constants
import (
2024-03-13 08:54:12 +00:00
"errors"
2023-05-05 16:43:21 +00:00
"os"
2024-03-13 08:54:12 +00:00
"strings"
2024-09-19 14:04:02 +00:00
"github.com/gofrs/uuid"
2023-05-05 16:43:21 +00:00
)
const (
2024-08-21 07:25:10 +00:00
GrubConf = "/etc/cos/grub.cfg"
GrubOEMEnv = "grub_oem_env"
GrubDefEntry = "Kairos"
DefaultTty = "tty1"
BiosPartName = "bios"
EfiLabel = "COS_GRUB"
EfiPartName = "efi"
ActiveLabel = "COS_ACTIVE"
PassiveLabel = "COS_PASSIVE"
SystemLabel = "COS_SYSTEM"
RecoveryLabel = "COS_RECOVERY"
RecoveryPartName = "recovery"
StateLabel = "COS_STATE"
StatePartName = "state"
InstallStateFile = "state.yaml"
PersistentLabel = "COS_PERSISTENT"
PersistentPartName = "persistent"
OEMLabel = "COS_OEM"
OEMPartName = "oem"
MountBinary = "/usr/bin/mount"
EfiDevice = "/sys/firmware/efi"
LinuxFs = "ext4"
LinuxImgFs = "ext2"
SquashFs = "squashfs"
EfiFs = "vfat"
EfiSize = uint ( 64 )
OEMSize = uint ( 64 )
PersistentSize = uint ( 0 )
BiosSize = uint ( 1 )
ImgSize = uint ( 3072 )
HTTPTimeout = 60
LiveDir = "/run/initramfs/live"
RecoveryDir = "/run/cos/recovery"
StateDir = "/run/cos/state"
OEMDir = "/run/cos/oem"
PersistentDir = "/run/cos/persistent"
ActiveDir = "/run/cos/active"
TransitionDir = "/run/cos/transition"
EfiDir = "/run/cos/efi"
RecoverySquashFile = "recovery.squashfs"
IsoRootFile = "rootfs.squashfs"
ActiveImgFile = "active.img"
PassiveImgFile = "passive.img"
RecoveryImgFile = "recovery.img"
IsoBaseTree = "/run/rootfsbase"
AfterInstallChrootHook = "after-install-chroot"
AfterInstallHook = "after-install"
BeforeInstallHook = "before-install"
AfterResetChrootHook = "after-reset-chroot"
AfterResetHook = "after-reset"
BeforeResetHook = "before-reset"
AfterUpgradeChrootHook = "after-upgrade-chroot"
AfterUpgradeHook = "after-upgrade"
BeforeUpgradeHook = "before-upgrade"
TransitionImgFile = "transition.img"
RunningStateDir = "/run/initramfs/cos-state" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
RunningRecoveryStateDir = "/run/initramfs/isoscan" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
FailInstallationFileSentinel = "/run/cos/fail_installation"
ActiveImgName = "active"
PassiveImgName = "passive"
RecoveryImgName = "recovery"
StateResetImgName = "statereset"
GPT = "gpt"
UsrLocalPath = "/usr/local"
OEMPath = "/oem"
2024-08-13 09:12:20 +00:00
BootEntryRecovery = "recovery"
2023-05-05 16:43:21 +00:00
// SELinux targeted policy paths
SELinuxTargetedPath = "/etc/selinux/targeted"
SELinuxTargetedContextFile = SELinuxTargetedPath + "/contexts/files/file_contexts"
SELinuxTargetedPolicyPath = SELinuxTargetedPath + "/policy"
// Default directory and file fileModes
DirPerm = os . ModeDir | os . ModePerm
FilePerm = 0666
2023-12-06 13:37:20 +00:00
ConfigPerm = 0640 // Used for config files that contain secrets or other sensitive data
2023-05-05 16:43:21 +00:00
NoWriteDirPerm = 0555 | os . ModeDir
TempDirPerm = os . ModePerm | os . ModeSticky | os . ModeDir
// Eject script
EjectScript = "#!/bin/sh\n/usr/bin/eject -rmF"
ArchAmd64 = "amd64"
Archx86 = "x86_64"
ArchArm64 = "arm64"
SignedShim = "shim.efi"
2024-01-11 10:24:43 +00:00
SignedGrub = "grub.efi"
Rsync = "rsync"
2023-10-03 09:15:17 +00:00
2023-12-18 10:38:26 +00:00
UkiSource = "/run/install/uki"
2024-02-08 14:21:37 +00:00
UkiCdromSource = "/run/initramfs/live"
2023-12-18 10:38:26 +00:00
UkiEfiDir = "/efi"
UkiEfiDiskByLabel = ` /dev/disk/by-label/ ` + EfiLabel
2023-12-18 15:09:55 +00:00
UkiMaxEntries = 3
2024-03-13 08:54:12 +00:00
// Boot labeling
2024-03-29 11:49:07 +00:00
PassiveBootSuffix = " (fallback)"
RecoveryBootSuffix = " recovery"
StateResetBootSuffix = " state reset (auto)"
2024-04-15 13:24:10 +00:00
// Error
2024-11-27 10:16:56 +00:00
UpgradeNoSourceError = "Could not find a proper source for the upgrade.\nThis can be configured in the cloud config files under the 'upgrade.system.uri' key or via cmdline using the '--source' flag."
MultipleEntriesAssessmentError = "multiple boot entries found for %s"
NoBootAssessmentWarning = "No boot assessment found in current boot entry config file"
2023-05-05 16:43:21 +00:00
)
2024-03-29 11:49:07 +00:00
func UkiDefaultMenuEntries ( ) [ ] string {
return [ ] string { "cos" , "fallback" , "recovery" , "statereset" }
}
2024-01-26 16:41:23 +00:00
func UkiDefaultSkipEntries ( ) [ ] string {
2024-01-31 19:58:49 +00:00
return [ ] string { "interactive-install" , "install-mode-interactive" }
2024-01-26 16:41:23 +00:00
}
2023-05-05 16:43:21 +00:00
func GetCloudInitPaths ( ) [ ] string {
return [ ] string { "/system/oem" , "/oem/" , "/usr/local/cloud-config/" }
}
// GetDefaultSquashfsOptions returns the default options to use when creating a squashfs
func GetDefaultSquashfsOptions ( ) [ ] string {
return [ ] string { "-b" , "1024k" }
}
func GetDefaultSquashfsCompressionOptions ( ) [ ] string {
return [ ] string { "-comp" , "gzip" }
}
func GetFallBackEfi ( arch string ) string {
switch arch {
case ArchArm64 :
return "bootaa64.efi"
default :
return "bootx64.efi"
}
}
2023-09-13 09:07:28 +00:00
// GetGrubFonts returns the default font files for grub
func GetGrubFonts ( ) [ ] string {
return [ ] string { "ascii.pf2" , "euro.pf2" , "unicode.pf2" }
}
// GetGrubModules returns the default module files for grub
func GetGrubModules ( ) [ ] string {
2023-10-30 10:03:06 +00:00
return [ ] string { "loopback.mod" , "squash4.mod" , "xzio.mod" , "gzio.mod" , "regexp.mod" }
2023-09-13 09:07:28 +00:00
}
2024-02-21 09:44:32 +00:00
2024-09-26 11:31:19 +00:00
// GetYipConfigDirs returns all the directories where "yip" configuration might
// live. These include the directories were we store our system overlay files:
// https://github.com/kairos-io/packages/tree/main/packages/static/kairos-overlay-files/files/system/oem
func GetYipConfigDirs ( ) [ ] string {
return append ( GetUserConfigDirs ( ) , "/system/oem" )
}
2024-09-26 12:02:39 +00:00
// GetUserConfigDirs returns all the directories that might have configuration
// supplied by the user. They are in an order which allows the users to override
// baked-in configuration (e.g. in livecd, under /run/initramfs/live) with
// configuration coming from datasource (e.g. a datasource cdrom, written under /oem).
// That's why writable paths are last.
2024-09-26 11:31:19 +00:00
func GetUserConfigDirs ( ) [ ] string {
2024-02-21 09:44:32 +00:00
return [ ] string {
"/run/initramfs/live" ,
"/etc/kairos" , // Default system configuration file https://github.com/kairos-io/kairos/issues/2221
"/etc/elemental" , // for backwards compatibility
2024-09-26 11:59:16 +00:00
"/usr/local/cloud-config" ,
"/oem" ,
2024-02-21 09:44:32 +00:00
}
}
2024-03-13 08:54:12 +00:00
func BaseBootTitle ( title string ) string {
if strings . HasSuffix ( title , RecoveryBootSuffix ) {
return strings . TrimSuffix ( title , RecoveryBootSuffix )
} else if strings . HasSuffix ( title , PassiveBootSuffix ) {
return strings . TrimSuffix ( title , PassiveBootSuffix )
2024-03-29 11:49:07 +00:00
} else if strings . HasSuffix ( title , StateResetBootSuffix ) {
return strings . TrimSuffix ( title , StateResetBootSuffix )
2024-03-13 08:54:12 +00:00
}
return title
}
func BootTitleForRole ( role , title string ) ( string , error ) {
switch role {
case ActiveImgName :
return BaseBootTitle ( title ) , nil
case PassiveImgName :
return BaseBootTitle ( title ) + PassiveBootSuffix , nil
case RecoveryImgName :
return BaseBootTitle ( title ) + RecoveryBootSuffix , nil
2024-03-29 11:49:07 +00:00
case StateResetImgName :
return BaseBootTitle ( title ) + StateResetBootSuffix , nil
2024-03-13 08:54:12 +00:00
default :
return "" , errors . New ( "invalid role" )
}
}
2024-09-10 10:23:15 +00:00
// DiskUUID is the static UUID for main disk identification
var DiskUUID = uuid . NewV5 ( uuid . NamespaceURL , "KAIROS_DISK" ) . String ( )