HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //snap/core24/1243/usr/share/subiquity/console-conf-write-login-details
#!/bin/bash

pretty_name="$( awk -F "=" '$1 = /PRETTY_NAME/ {print $2;}' /usr/lib/os-release | sed 's/"//g')"
tty_name=$(tty | cut -c 6-)

get_first_ip() {
  local ip_address
  for iface in $(ip -br address | awk '{print $1}')
  do
    if [ -n "${iface}" ] && [ "${iface}" != "lo" ] && ip addr show dev "${iface}" >/dev/null 2>&1; then
        ip_address="$(ip -4 -br addr show dev "${iface}" | awk '{print$3}' | sed 's|\(.*\)/.*|\1|')"
        if [ -n "${ip_address}" ]; then
          echo "${ip_address}"
          return 0
        fi
    fi
  done
  echo "<no ip address>"
  return 2
}

print_ssh_commands() {
  local user_name
  # take any user with non zero authorized keys file
  for h in $(getent passwd | grep -v -e /nologin -e /false | cut -d: -f6 | grep -e /home -e /root)
  do
    if [ ! -s "${h}/.ssh/authorized_keys" ]; then
      continue
    fi
    user_name="$(basename "${h}")"
    for iface in $(ip -br address | awk '$2 == "UP" {print $1}')
    do
      if [ -n "${iface}" ] && [ "${iface}" != "lo" ] && ip addr show dev "${iface}" >/dev/null 2>&1; then
        ip4_address="$(ip -4 -br addr show dev "${iface}" | awk '{print$3}' | sed 's|\(.*\)/.*|\1|')"
        ip6_address="$(ip -6 -br addr show dev "${iface}" | awk '{print$3}' | sed 's|\(.*\)/.*|\1|')"
        if [ -n "${ip4_address}" ]; then
          printf "\tssh %s@%s\n" "${user_name}" "${ip4_address}"
          printf "\tssh %s@%s\n" "${user_name}" "${ip6_address}"
        fi
      fi
    done
    echo ""
  done
}

print_sshd_finger_prints() {
  (
    shopt -s nullglob
    for key in /etc/ssh/*.pub; do
        ssh-keygen -lf "${key}" | awk '{print "\t"substr($4,2,length($4)-2)"\t"$2}'
    done
  )
  return 0
}

write_login_details() {
  ip=$(get_first_ip)
  local ret=${?}
  echo "${pretty_name} on ${ip} (${tty_name})"
  echo ""
  print_sshd_finger_prints
  echo ""
  echo "To login:"
  echo ""
  print_ssh_commands
  echo "Personalize your account at https://login.ubuntu.com."
  return ${ret}
}


write_login() {
  # handle unmanaged devices
  local ret=0
  # fish for non-root users
  # shellcheck disable=SC2143
  if [ -z "$(getent passwd | grep -v -e /nologin -e /false | grep /home)" ]; then
    ip=$(get_first_ip)
    if [ -n "${ip}" ]; then
      echo "device managed without user @ ${ip}"
    else
      echo "device managed without user"
    fi
  else
    write_login_details
    ret=${?}
  fi
  return ${ret}
}

case ${1} in
  --host-fingerprints)
    print_sshd_finger_prints
    ;;
  *)
    write_login
    ;;
esac

# pass on return code
exit ${?}