Skip to content

Commit

Permalink
Add domain support via UTSNAME / -u (I probably shouldn't have hijacked
Browse files Browse the repository at this point in the history
UTSNAME like that but meh).
  • Loading branch information
specing committed Jul 24, 2014
1 parent f5d0a46 commit 4b60430
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions lxc-gentoo
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ WGET="wget --timeout=8 --read-timeout=15 -c -t10 -nd"

# Defaults only
NAME="${NAME:-gentoo}"
UTSNAME="${UTSNAME:-gentoo}"
UTSNAME="${UTSNAME:-gentoo.local}"
IPV4="${IPV4:-172.20.0.2/24}"
GATEWAY="${GATEWAY:-172.20.0.1}"
GUESTROOTPASS="$GUESTROOTPASS"
Expand Down Expand Up @@ -294,9 +294,36 @@ write_distro_network()
# custom hostname
write_distro_hostname()
{
echo -n " - setting hostname..."
printf "HOSTNAME=%s\n" "$UTSNAME" > "$ROOTFS/etc/conf.d/hostname"
echo "done."
# figure out the host parts
local hosts_entries="$UTSNAME"
local hosts_entry="$UTSNAME"

while [[ $hosts_entry = *.* ]]; do
hosts_entry="${hosts_entry%.*}"

hosts_entries="$hosts_entries $hosts_entry"
done

# actual hostname will is now in $hosts_entry
printf " - setting hostname..."
printf "hostname=\"%s\"\n" "$hosts_entry" > "$ROOTFS/etc/conf.d/hostname"


mapfile -t < "$ROOTFS/etc/hosts"
printf "" > "$ROOTFS/etc/hosts" # truncate

# potential problem: there are more 127... and ::1 entries. Not in stages for now.
for line in "${MAPFILE[@]}"; do
if [[ $line == 127.0.0.1* ]]; then
printf "%-20s %s %s\n" "127.0.0.1" "$hosts_entries" "localhost" >> "$ROOTFS/etc/hosts"
elif [[ $line == ::1* ]]; then
printf "%-20s %s %s %s\n" "::1" "$hosts_entries" "localhost" >> "$ROOTFS/etc/hosts"
else
printf "%s\n" "$line" >> "$ROOTFS/etc/hosts"
fi
done

printf "done.\n"
}

# fix init system
Expand Down Expand Up @@ -360,7 +387,7 @@ write_lxc_configuration()
$arch_line
# set the hostname
lxc.utsname = ${UTSNAME}
lxc.utsname = ${UTSNAME%%.*}
# network interface
lxc.network.type = veth
Expand Down Expand Up @@ -547,8 +574,11 @@ configure()


# choose a hostname, default is the container name
UTSNAME=${NAME}
read -p "What hostname do you wish for this container ? " -ei "$UTSNAME" UTSNAME
local domain=""
if [[ $UTSNAME = *.* ]]; then
domain=".${UTSNAME#*.}"
fi
read -p "What hostname[.domain] do you wish for this container ? " -ei "$NAME$domain" UTSNAME


# choose an ipv4 address, better to choose the same network than
Expand Down Expand Up @@ -776,7 +806,7 @@ help()
Current/Default: ${GATEWAY}
-n NAME : name of the container
Current/Default: ${NAME}
-u UTSNAME : hostname of the container
-u UTSNAME : hostname (+domain) of the container
Current/Default: ${UTSNAME}
-a ARCH : at the moment all but mips.
Current/Default: ${ARCH}
Expand Down

0 comments on commit 4b60430

Please sign in to comment.