From 62a0b3bf1961f0568af619f1d18b25e1a26a7498 Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Fri, 4 Dec 2020 01:49:17 -0600
Subject: [PATCH] Prompt for hostname, better logging

---
 gentoostrap.sh | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/gentoostrap.sh b/gentoostrap.sh
index bc09f0c..eda50ed 100755
--- a/gentoostrap.sh
+++ b/gentoostrap.sh
@@ -129,6 +129,7 @@ build-gentoo() {
 	pushd "$_optdest" > /dev/null 2>&1
 	# These is a very generic make.conf to get the system up and running
 	# We use march of x86-64 to ensure compatibility if we're bootstrapping on a host other than the target
+	log "Building make.conf"
 	cat <<-EOF > "$_optdest/etc/portage/make.conf"
 	# ABI_X86 is used to control multilib support
 	ABI_X86="64 32"
@@ -143,6 +144,7 @@ build-gentoo() {
 	USE="networkmanager systemd -elogind -test"
 	EOF
 	# This is required on >=17.1 to unroll some circular dependencies
+	log "Setting package.use settings for gentoostrap"
 	cat <<-EOF > "$_optdest/etc/portage/package.use/gentoostrap"
 	# These solve circular dependency issues
 	dev-lang/python -bluetooth -sqlite
@@ -150,26 +152,36 @@ build-gentoo() {
 	sys-libs/ncurses -gpm
 	EOF
 	# Configure default ebuild repositories
+	log "Syncing ebuild repos"
 	mkdir -p "$_optdest/etc/portage/repos.conf"
 	cp "$_optdest/usr/share/portage/config/repos.conf" \
 		"$_optdest/etc/portage/repos.conf/gentoo.conf"
 	# DNS
+	log "Configuring DNS"
 	cat <<-EOF > "$_optdest/etc/resolv.conf"
 	nameserver 8.8.8.8
 	nameserver 8.8.4.4
 	EOF
 	# Hostname
-	echo "$(hostname -s)" > "$_optdest/etc/conf.d/hostname"
+	read -p "Enter system hostname: " hostname
+	echo "$hostname" > "$_optdest/etc/conf.d/hostname"
 	# hosts
-	echo "127.0.0.1 $(hostname -s)" > "$_optdest/etc/hosts"
+	log "Configuring hosts"
+	cat <<-EOF > "$_optdest/etc/hosts"
+	127.0.0.1 $hostname
+	::1 $hostname
+	EOF
 	# Timezone
+	log "Configuring timezone"
 	cp /etc/timezone "$_optdest/etc/timezone"
 	# Locale
+	log "Configuring locale"
 	cat <<-EOF > "$_optdest/etc/locale.gen"
 	en_US ISO-8859-1
 	en_US.UTF-8 UTF-8
 	EOF
 	# fstab
+	log "Dropping to editor to configure fstab"
 	cat <<-EOF > "$_optdest/etc/fstab"
 	# fstab - Filesystem table
 	# See fstab(5) for syntax and configuration information
@@ -181,6 +193,7 @@ build-gentoo() {
 	# Now we need to pivot into a chroot and finish configuration natively
 	# Buuuut... since we're using systemd, we get to just spawn a systemd-nspawn container
 	popd
+	log "Pivoting to container for more setup"
 	cp "$0" "$_optdest/gentoostrap.sh"
 	sudo systemd-nspawn --directory="$_optdest" /gentoostrap.sh -c
 
@@ -256,9 +269,6 @@ build-gentoo-chroot() {
 	* Install and configure grub
 	* Reboot and pray
 
-	Other things you may want to do:
-	* Change the system hostname
-
 	Dumping to a shell now. Have fun!
 	EOF
 	exec bash