image:
  distribution: plamolinux

source:
  downloader: plamolinux-http
  url: https://repository.plamolinux.org/pub/linux/Plamo/

targets:
  lxc:
    create_message: |
      You just created an {{ image.description }} container.
    config:
    - type: all
      before: 5
      content: |-
        lxc.include = LXC_TEMPLATE_CONFIG/plamo.common.conf

    - type: user
      before: 5
      content: |-
        lxc.include = LXC_TEMPLATE_CONFIG/plamo.userns.conf

    - type: all
      after: 4
      content: |-
        lxc.include = LXC_TEMPLATE_CONFIG/common.conf

    - type: user
      after: 4
      content: |-
        lxc.include = LXC_TEMPLATE_CONFIG/userns.conf

    - type: all
      content: |-
        lxc.arch = {{ image.architecture_kernel }}

files:
- name: hostname
  path: /etc/hostname
  generator: hostname

- name: hostname
  path: /etc/HOSTNAME
  generator: hostname

- name: hosts
  path: /etc/hosts
  generator: hosts

- name: inittab
  path: /etc/inittab
  generator: dump
  content: |-
    # /etc/inittab derived from LFS 20170713
    # Begin /etc/inittab

    id:3:initdefault:

    si::sysinit:/etc/rc.d/init.d/rc S

    l0:0:wait:/etc/rc.d/init.d/rc 0
    l1:S1:wait:/etc/rc.d/init.d/rc 1
    l2:2:wait:/etc/rc.d/init.d/rc 2
    l3:3:wait:/etc/rc.d/init.d/rc 3
    l4:4:wait:/etc/rc.d/init.d/rc 4
    l5:5:wait:/etc/rc.d/init.d/rc 5
    l6:6:wait:/etc/rc.d/init.d/rc 6

    ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
    pf::powerfail:/sbin/shutdown -h +0 "THE POWER IS FAILING"

    su:S016:once:/sbin/sulogin

    c:1235:respawn:/sbin/agetty console 38400
    1:2345:respawn:/sbin/agetty --noclear tty1 9600
    2:2345:respawn:/sbin/agetty tty2 9600
    3:2345:respawn:/sbin/agetty tty3 9600

    # End /etc/inittab

- name: fstab
  path: /etc/fstab
  generator: dump
  content: |-
    proc            /proc           proc    defaults        0 0
    tmpfs           /run            tmpfs   defaults        0 0
    sysfs           /sys            sysfs   defaults        0 0
    tmpfs           /tmp            tmpfs   defaults        0 0
    devpts          /dev/pts        devpts  gid=5,mode=620  0 0
    usbfs           /proc/bus/usb   usbfs   noauto          0 0

- name: eth0
  path: /etc/sysconfig/ifconfig.eth0
  generator: dump
  content: |-
    ONBOOT="yes"
    IFACE="eth0"
    SERVICE="dhclient"

packages:
  custom_manager:
    install:
      cmd: installpkg
    remove:
      cmd: removepkg
    update:
      cmd: updatepkg
    clean:
      cmd: true
    refresh:
      cmd: true
  sets:
  - packages:
    - sudo
    action: install

actions:
- trigger: post-unpack
  action: |
    #!/bin/sh
    set -eux

    # Configure timezone
    ln -s ../usr/share/zoneinfo/Asia/Tokyo /etc/localtime

    # Disable pam_loginuid.so in /etc/pam.d/login
    sed -i '/pam_loginuid/s/^/#/' /etc/pam.d/login

- trigger: post-unpack
  action: |
    #!/bin/sh
    set -eux

    # Inittab
    sed -i -e '/^1:2345/i c:1235:respawn:/sbin/agetty console 38400'\
      -e '/^ca:/a pf::powerfail:/sbin/shutdown -h +0 "THE POWER IS FAILING"' \
      -e '/^4:2345/d' \
      -e '/^5:2345/d' \
      -e '/^6:2345/d' /etc/inittab

    # Tweak init script on startup
    for script in S05modules S10eudev S20swap S30checkfs S35setclock S50eudev_retry S70console; do
      rm -f "/etc/rc.d/rcS.d/${script}"
    done

    # Remove init script in runlevel3
    for script in rc3.d/S30sshd rc6.d/K30sshd rc6.d/K35setclock rc6.d/S65swap rc6.d/S70mountfs \
                  rc0.d/K30sshd rc0.d/K35setclock rc0.d/S65swap rc0.d/S70mountfs; do
      rm -f "/etc/rc.d/${script}"
    done

    # Tweak rc script
    if [ -e /etc/rc.d/init.d/rc ]; then
      sed -i -e '/wait_for_user/d' -e '/Press Enter to/d' /etc/rc.d/init.d/rc
    fi

    # remove initpkg that do not execute on containers
    for pkg in shadow netconfig7 eudev openssh; do
      rm -f "/var/log/initpkg/${pkg}"
    done

mappings:
  architecture_map: plamolinux
