# cloud-config

name: "Default user, permissions and serial login"
stages:
  initramfs:
    - name: "Setup groups"
      ensure_entities:
      - entity: |
           kind: "group"
           group_name: "admin"
           password: "x"
           gid: 900
    - name: "Setup users"
      users:
        kairos:
          passwd: "!"
          shell: /bin/bash
          homedir: "/home/kairos"
          groups:
            - "admin"
    - name: "Set user password if running in live or uki"
      if: "[ -e /run/cos/live_mode ] || [ -e /run/cos/uki_install_mode ]"
      users:
        kairos:
          passwd: "kairos"
    - name: "Setup sudo"
      files:
      - path: "/etc/sudoers"
        owner: 0
        group: 0
        permsisions: 0600
        content: |
           Defaults always_set_home
           Defaults secure_path="/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin"
           Defaults env_reset
           Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_ATIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE"
           Defaults !insults
           root ALL=(ALL) ALL
           %admin ALL=(ALL) NOPASSWD: ALL
           #includedir /etc/sudoers.d
      commands:
        - passwd -l root
    - name: "Ensure runtime permission"
      if: '[ -e "/oem" ]'
      commands:
        - chown -R root:admin /oem
        - chmod 770 /oem
    - name: "Ensure runtime permission"
      if: '[ -e "/usr/local/cloud-config" ]'
      commands:
        - chown -R root:admin /usr/local/cloud-config
        - chmod 770 /usr/local/cloud-config
  initramfs.after:
    # Run this in the after stage so it doesnt collide with other initramfs changes to the /etc/inittab
    # Otherwise this can lead to 2 steps modifying the inittab at the same time and overriding or not cleaning it properly
    - name: "Enable serial login for alpine" # https://wiki.alpinelinux.org/wiki/Enable_Serial_Console_on_Boot
      if: '[ -e /sbin/openrc ]'
      commands:
        - sed -i -e 's/ttyS0.*//g' /etc/inittab
        - echo "ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100" >> /etc/inittab
