# bootcd2disk.conf.src - source for bootcd2disk.conf
### conf.src conf.start
# vim: set filetype=sh :
#        file: bootcd2disk.conf
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2001-2020)
#     license: GNU General Public License, version 3
# description: bootcd2disk.conf - default config for bootcd2disk
#              It is installed in /etc/bootcd/ and
#              can be restored from /usr/share/doc/examples/
#
### conf.src bootcd_mount()
define_bootcd_mount() {
  needs "EFIBOOT" || return $?
  if [ "$EFIBOOT" = "bios" ]; then
    bootcd_mount()
    {
      bootcd_global DISK0P1 DISK0P3
      mount $DISK0P3 $1
      mkdir -p $1/boot; mount $DISK0P1 $1/boot
    }
  else  # efi or bios+efi
    bootcd_mount()
    {
      bootcd_global DISK0P1 DISK0P2 DISK0P4
      mount $DISK0P4 $1
      mkdir -p $1/boot; mount $DISK0P2 $1/boot
      mkdir -p $1/boot/efi; fsck -y $DISK0P1; mount $DISK0P1 $1/boot/efi
    }
  fi
}
### conf.src bootcd_umount()
define_bootcd_umount() {
  needs "EFIBOOT" || return $?
  if [ "$EFIBOOT" = "bios" ]; then
    bootcd_umount()
    {
      umount $1/boot
      umount $1
    }
  else # efi or bios+efi
    bootcd_umount()
    {
      umount $1/boot/efi
      umount $1/boot
      umount $1
    }
  fi
}
### conf.src EXT2FS
define_EXT2FS() {
  needs "EFIBOOT LINUXFS" || return $?
  if [ "$LINUXFS" = "ext2" ]; then
    if [ "$EFIBOOT" = "bios" ]; then
      EXT2FS="DISK0P1 DISK0P3"
    else # efi or bios+efi
      EXT2FS="DISK0P2 DISK0P4"
    fi
  else
    EXT2FS=""
  fi
}
### conf.src EXT3FS
define_EXT3FS() {
  needs "EFIBOOT LINUXFS" || return $?
  if [ "$LINUXFS" = "ext3" ]; then
    if [ "$EFIBOOT" = "bios" ]; then
      EXT3FS="DISK0P1 DISK0P3"
    else # efi or bios+efi
      EXT3FS="DISK0P2 DISK0P4"
    fi
  else
    EXT3FS=""
  fi
}
### conf.src EXT4FS
define_EXT4FS() {
  needs "EFIBOOT LINUXFS" || return $?
  if [ "$LINUXFS" = "ext4" ]; then
    if [ "$EFIBOOT" = "bios" ]; then
      EXT4FS="DISK0P1 DISK0P3"
    else # efi or bios+efi
      EXT4FS="DISK0P2 DISK0P4"
    fi
  else
    EXT4FS=""
  fi
}
### conf.src FSTAB
define_FSTAB() {
  needs "EFIBOOT" || return $?

  if [ "$EFIBOOT" = "bios" ]; then
    FSTAB="\
DISK0P3 /     $LINUXFS defaults,errors=remount-ro 0 1
DISK0P1 /boot $LINUXFS defaults 0 1
DISK0P2 none  swap sw 0 0
proc      /proc proc defaults 0 0"
  else # $EFIBOOT = efi or bios+efi
    FSTAB="\
DISK0P4 /         $LINUXFS defaults,errors=remount-ro 0 1
DISK0P2 /boot     $LINUXFS defaults 0 1
DISK0P1 /boot/efi vfat defaults 0 1
DISK0P3 none      swap sw 0 0
proc      /proc proc defaults 0 0"
  fi
}
### conf.src RESUME
define_RESUME() {
  needs "EFIBOOT" || return $?
  if [ "$EFIBOOT" = "bios" ]; then
    RESUME="DISK0P2"
  else # efi or bios+efi
    RESUME="DISK0P3"
  fi
}
### conf.src SFDISK#
define_SFDISK() {
  needs "EFIBOOT" || return $?
  START=2048                  # Sectors = 1 MB
  BOOTS="$(expr 200 \* 2048)" # Sectors = 200 MB
  EFIS="$(expr 512 \* 2048)"  # Sectors = 512 MB
  MEMS="$(free | grep Mem | gawk '{print $2}')" # KB
  SWAPS="$(expr 4 \* $MEMS)"  # Sectors = Double MEMS
  if [ "$EFIBOOT" = "bios" ]; then
    SFDISK0="unit: sectors
$START,$BOOTS,L
,$SWAPS,S
,+,L;"
  else # efi or bios+efi
    SFDISK0="unit: sectors
$START,$EFIS,U
,$BOOTS,L
,$SWAPS,S
,+,L;"
  fi
}
### conf.src SWAP
define_SWAP() {
  needs "EFIBOOT" || return $?
  if [ "$EFIBOOT" = "bios" ]; then
    SWAP="DISK0P2"
  else # efi or bios+efi
    SWAP="DISK0P3"
  fi
}
### conf.src VFAT
define_VFAT() {
  needs "EFIBOOT" || return $?
  if [ "$EFIBOOT" = "bios" ]; then
    VFAT=""
  else # efi or bios+efi
    VFAT="DISK0P1"
  fi
}
### conf.src conf.end
