4 # Provides: AssignHostname
5 # RunBefore: UmountImage
6 # RunAfter: InstallUnattend
7 # Short-Description: Assign Hostname/Computer Name to the instance
11 . "@commondir@/common.sh"
17 local tmp_unattend=`mktemp` || exit 1
18 add_cleanup rm "$tmp_unattend"
20 echo -n "Assigning new computer name..."
22 local namespace="urn:schemas-microsoft-com:unattend"
24 "$XMLSTARLET" ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:ComputerName" -v "$password" "$target/Unattend.xml" > "$tmp_unattend"
26 cat "$tmp_unattend" > "$target/Unattend.xml"
34 local distro=$(get_base_distro "$target")
38 echo "$hostname" > "$target/etc/hostname";;
40 sed -ie "s/HOSTNAME=.*$/HOSTNAME=$hostname/g" "$target/etc/sysconfig/network";;
42 #local domain=$(sed -e 's/^[^\.]*//g' < /etc/HOSTNAME)
44 # In slackware hostname and domain name are joined together. For now I
45 # will not retain the domain name.
47 echo "$hostname" > "${target}/etc/HOSTNAME";;
49 sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"$hostname\"/" "$target/etc/conf.d/hostname";;
52 # Some Linux distributions assign the hostname to 127.0.1.1 in order to be
53 # resolvable to an IP address. Lets replace this if found in /etc/hosts
54 sed -ie "s/^[[:blank:]]*127\.0\.1\.1[[:blank:]].\+$/127.0.1.1\t$hostname/" "$target/etc/hosts"
57 if [ ! -d "$SNF_IMAGE_TARGET" ]; then
58 log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
61 if [ -z "$SNF_IMAGE_HOSTNAME" ]; then
62 log_error "Hostname is missing"
65 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
66 windows_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
67 elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
68 linux_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
76 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :