diff --git a/defaults/.bashrc b/defaults/.bashrc index 2fdfd55..b6c7e85 100644 --- a/defaults/.bashrc +++ b/defaults/.bashrc @@ -3,8 +3,25 @@ case $- in *) return ;; esac +computer_prompt_base_name() { + local name="" + if [ -n "${COMPUTER_NAME:-}" ]; then + name="${COMPUTER_NAME}" + elif [ -n "${COMPUTER_HANDLE:-}" ]; then + name="${COMPUTER_HANDLE}" + elif [ -r /etc/microagent/machine-name ]; then + IFS= read -r name /dev/null 2>&1; then + prompt_pure_context() { :; } zstyle ':prompt:pure:path' color blue pure_prompt="$PROMPT" PROMPT='%F{green}$(computer_prompt_name)%f '"$pure_prompt" diff --git a/microagent-init.sh b/microagent-init.sh index 799a148..284a43e 100644 --- a/microagent-init.sh +++ b/microagent-init.sh @@ -7,6 +7,18 @@ log() { printf '[microagent-init] %s\n' "$*" >&2 } +read_machine_name() { + if [ -r /etc/microagent/machine-name ]; then + tr -d '\r\n' /var/log/network.log 2>&1; then exit 1 fi +machine_name="$(read_machine_name)" +export COMPUTER_NAME="$machine_name" +printf '%s\n' "$machine_name" >/etc/hostname +cat >/etc/hosts </dev/null 2>&1 || true + if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then log "generating ssh host keys" ssh-keygen -A diff --git a/microagent-network-up.sh b/microagent-network-up.sh index 51b1952..d44eda1 100644 --- a/microagent-network-up.sh +++ b/microagent-network-up.sh @@ -40,9 +40,8 @@ ip link set dev "$primary_iface" up ip addr replace "${guest_ip}/30" dev "$primary_iface" ip route replace default via "$gateway_ip" dev "$primary_iface" -if [ -w /etc/resolv.conf ]; then - cat >/etc/resolv.conf <<'EOF' +mkdir -p /etc +cat >/etc/resolv.conf <<'EOF' nameserver 1.1.1.1 nameserver 8.8.8.8 EOF -fi