<commit_before>#!/bin/bash

script_cmdline ()
{
    local param
    for param in $(< /proc/cmdline); do
        case "${param}" in
            script=*) echo "${param#*=}" ; return 0 ;;
        esac
    done
}

automated_script ()
{
    local script rt
    script="$(script_cmdline)"
    if [[ -n "${script}" && ! -x /tmp/startup_script ]]; then
        if [[ "${script}" =~ ^http:// || "${script}" =~ ^ftp:// ]]; then
            wget "${script}" --retry-connrefused -q -O /tmp/startup_script >/dev/null
            rt=$?
        else
            cp "${script}" /tmp/startup_script
            rt=$?
        fi
        if [[ ${rt} -eq 0 ]]; then
            chmod +x /tmp/startup_script
            /tmp/startup_script
        fi
    fi
}

get_mac ()
{
  awk 'BEGIN {FS="="; RS=" ";} { if ($1 ~ /BOOTIF/) {gsub(/^[^-]+-/, "", $2); gsub(/-/, ":", $2); print tolower($2)}}' /proc/cmdline
}

get_interface_we_booted_from ()
{
  awk '/'"$1"'/ {sub(/:/, "", $2); print $2}' <<< "$(ip -oneline link show up)"
}

setup_ipv6 ()
{
  if [ -n "$IP6ADDR" ] && [ -n "$IP6GW" ] && [ -n "$IP6PRE" ]; then
    local mac=""
    local interface=""
    mac="$(get_mac)"
    interface="$(get_interface_we_booted_from "$mac")"
    ip -6 addr add "${IP6ADDR}/${IP6PRE}" dev "$interface"
    ip -6 route delete default
    ip -6 route add default via "$IP6GW" dev "$interface"
  fi
}

if [[ $(tty) == "/dev/tty1" ]]; then
  cmdline="$(cat /proc/cmdline)"
  # shellcheck disable=SC2163
  for i in $cmdline; do
    case "$i" in
      HASH=*) export "$i";;
      IP6ADDR=*) export "$i";;
      IP6GW=*) export "$i";;
      IP6PRE=*) export "$i";;
    esac;
  done

  setup_ipv6

  if [ -n "$HASH" ]; then
    grep -v "^root" /etc/shadow > /tmp/shadow.tmp
    GECOS="$(awk -F: '/^root/ {print $3":"$4":"$5":"$6":"$7":"$8":"}' /etc/shadow)"
    echo "root:${HASH}:${GECOS}" > /etc/shadow
    cat /tmp/shadow.tmp >> /etc/shadow
    rm /tmp/shadow.tmp
  fi
  automated_script
fi
<commit_msg>setup proper systemd-networkd<commit_after>#!/bin/bash

script_cmdline ()
{
    local param
    for param in $(< /proc/cmdline); do
        case "${param}" in
            script=*) echo "${param#*=}" ; return 0 ;;
        esac
    done
}

automated_script ()
{
    local script rt
    script="$(script_cmdline)"
    if [[ -n "${script}" && ! -x /tmp/startup_script ]]; then
        if [[ "${script}" =~ ^http:// || "${script}" =~ ^ftp:// ]]; then
            wget "${script}" --retry-connrefused -q -O /tmp/startup_script >/dev/null
            rt=$?
        else
            cp "${script}" /tmp/startup_script
            rt=$?
        fi
        if [[ ${rt} -eq 0 ]]; then
            chmod +x /tmp/startup_script
            /tmp/startup_script
        fi
    fi
}

get_mac ()
{
  awk 'BEGIN {FS="="; RS=" ";} { if ($1 ~ /BOOTIF/) {gsub(/^[^-]+-/, "", $2); gsub(/-/, ":", $2); print tolower($2)}}' /proc/cmdline
}

get_interface_we_booted_from ()
{
  awk '/'"$1"'/ {sub(/:/, "", $2); print $2}' <<< "$(ip -oneline link show up)"
}

setup_ipv6 ()
{
  if [ -n "$IP6ADDR" ] && [ -n "$IP6GW" ] && [ -n "$IP6PRE" ]; then
    local mac=""
    local interface=""
    mac="$(get_mac)"
    interface="$(get_interface_we_booted_from "$mac")"
    ip -6 addr add "${IP6ADDR}/${IP6PRE}" dev "$interface"
    ip -6 route delete default
    ip -6 route add default via "$IP6GW" dev "$interface"
  fi
}
systemctl start systemd-resolved
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
if [[ $(tty) == "/dev/tty1" ]]; then
  cmdline="$(cat /proc/cmdline)"
  # shellcheck disable=SC2163
  for i in $cmdline; do
    case "$i" in
      HASH=*) export "$i";;
      IP6ADDR=*) export "$i";;
      IP6GW=*) export "$i";;
      IP6PRE=*) export "$i";;
    esac;
  done

  setup_ipv6

  if [ -n "$HASH" ]; then
    grep -v "^root" /etc/shadow > /tmp/shadow.tmp
    GECOS="$(awk -F: '/^root/ {print $3":"$4":"$5":"$6":"$7":"$8":"}' /etc/shadow)"
    echo "root:${HASH}:${GECOS}" > /etc/shadow
    cat /tmp/shadow.tmp >> /etc/shadow
    rm /tmp/shadow.tmp
  fi
  automated_script
fi

{'fraction_non_alphanumeric': 0.22313229089103995, 'fraction_numerical': 0.016877637130801686, 'mean_word_length': 2.341625207296849, 'pattern_counts': {'":': 14, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '3203184', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1518, 'n_words': 375}