<commit_before>#!/bin/bash

# reference: https://gist.github.com/bloodearnest/ebf044476e70c4baee59c5000a10f4c8

# To launch a container using this profile:
#   $ lxc launch ubuntu: -p default -p $PROFILE_NAME

set -eu

PROFILE_NAME="centos.cloud-init.config"

PUBKEY=${HOME}/.ssh/id_rsa.pub
if [ ! -f "${PUBKEY}" ]
then
    # Check for existence of a pubkey, or else exit with message
    echo "[$(date +%r)]----> [ERROR] Please generate an SSH keypair using 'ssh-keygen -t rsa'. This key will be authorized to login as the CentOS 7 centos cloud image user."
    exit 3
else
    # Place contents of $PUBKEY into $KEY
    KEY=$(<${PUBKEY})
fi

SUDOGROUP="wheel"
TIMEZONE=America/Sao_Paulo

# create a profile to control this, name it after $USER
lxc profile create $PROFILE_NAME &> /dev/null || true

# configure profile
# this will rewrite the whole profile
cat << EOF | lxc profile edit $PROFILE_NAME
name: $PROFILE_NAME
description: setup cloud-init for a centos 7 container
config:
  # note: user.user-data is still available
  user.vendor-data: |
    #cloud-config

    # Users
    users:
        - name: centos
          groups: ['${SUDOGROUP}']
          shell: /bin/bash
          sudo: ALL=(ALL) NOPASSWD:ALL
          ssh_authorized_keys:
            - ${KEY}
        - name: ops
          groups: ['${SUDOGROUP}']
          shell: /bin/bash
          sudo: ALL=(ALL) NOPASSWD:ALL
          ssh_authorized_keys:
            - ${KEY}

    # Remove cloud-init when finished with it
    runcmd:
        - [ yum, -y, remove, cloud-init ]

    # Configure where output will go
    output:
        all: ">> /var/log/cloud-init.log"

    # configure interaction with ssh server
    ssh_genkeytypes: ['ed25519', 'rsa']

    # Install my public ssh key to the first user-defined user configured
    # in cloud.cfg in the template (which is centos for CentOS cloud images)
    ssh_authorized_keys:
        - ${KEY}

    timezone: ${TIMEZONE}
EOF
<commit_msg>Adding a message on starting up<commit_after>#!/bin/bash

# reference: https://gist.github.com/bloodearnest/ebf044476e70c4baee59c5000a10f4c8

# To launch a container using this profile:
#   $ lxc launch ubuntu: -p default -p $PROFILE_NAME

set -eu

PROFILE_NAME="centos.cloud-init.config"

PUBKEY=${HOME}/.ssh/id_rsa.pub
if [ ! -f "${PUBKEY}" ]
then
    # Check for existence of a pubkey, or else exit with message
    echo "[$(date +%r)]----> [ERROR] Please generate an SSH keypair using 'ssh-keygen -t rsa'. This key will be authorized to login as the CentOS 7 centos cloud image user."
    exit 3
else
    # Place contents of $PUBKEY into $KEY
    KEY=$(<${PUBKEY})
fi

SUDOGROUP="wheel"
TIMEZONE=America/Sao_Paulo

# create a profile to control this, name it after $USER
lxc profile create $PROFILE_NAME &> /dev/null || true

# configure profile
# this will rewrite the whole profile
cat << EOF | lxc profile edit $PROFILE_NAME
name: $PROFILE_NAME
description: setup cloud-init for a centos 7 container
config:
  # note: user.user-data is still available
  user.vendor-data: |
    #cloud-config

    # Users
    users:
        - name: centos
          groups: ['${SUDOGROUP}']
          shell: /bin/bash
          sudo: ALL=(ALL) NOPASSWD:ALL
          ssh_authorized_keys:
            - ${KEY}
        - name: ops
          groups: ['${SUDOGROUP}']
          shell: /bin/bash
          sudo: ALL=(ALL) NOPASSWD:ALL
          ssh_authorized_keys:
            - ${KEY}

    bootcmd:
        - echo 'Starting cloud-init for hostname '$(hostname)

    # Remove cloud-init when finished with it
    runcmd:
        - [ yum, -y, remove, cloud-init ]

    # Configure where output will go
    output:
        all: ">> /var/log/cloud-init.log"

    # configure interaction with ssh server
    ssh_genkeytypes: ['ed25519', 'rsa']

    # Install my public ssh key to the first user-defined user configured
    # in cloud.cfg in the template (which is centos for CentOS cloud images)
    ssh_authorized_keys:
        - ${KEY}

    timezone: ${TIMEZONE}
EOF

{'fraction_non_alphanumeric': 0.10878243512974052, 'fraction_numerical': 0.01347305389221557, 'mean_word_length': 2.688132474701012, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1082140', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1283, 'n_words': 420}