3 # Copyright (C) 2011 GRNET S.A.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # Provides: AssignHostname
22 # RunBefore: UmountImage
23 # RunAfter: InstallUnattend
24 # Short-Description: Assign Hostname/Computer Name to the instance
28 . "@commondir@/common.sh"
34 local tmp_unattend=`mktemp` || exit 1
35 add_cleanup rm "$tmp_unattend"
37 echo -n "Assigning new computer name..."
39 local namespace="urn:schemas-microsoft-com:unattend"
41 "$XMLSTARLET" ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:ComputerName" -v "$password" "$target/Unattend.xml" > "$tmp_unattend"
43 cat "$tmp_unattend" > "$target/Unattend.xml"
51 local distro=$(get_base_distro "$target")
55 echo "$hostname" > "$target/etc/hostname";;
57 sed -ie "s/HOSTNAME=.*$/HOSTNAME=$hostname/g" "$target/etc/sysconfig/network";;
59 #local domain=$(sed -e 's/^[^\.]*//g' < /etc/HOSTNAME)
61 # In slackware hostname and domain name are joined together. For now
62 # I will not retain the domain name.
63 echo "$hostname" > "${target}/etc/HOSTNAME";;
65 sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"$hostname\"/" "$target/etc/conf.d/hostname";;
68 # Some Linux distributions assign the hostname to 127.0.1.1 in order to be
69 # resolvable to an IP address. Lets replace this if found in /etc/hosts
70 sed -ie "s/^[[:blank:]]*127\.0\.1\.1[[:blank:]].\+$/127.0.1.1\t$hostname/" "$target/etc/hosts"
73 if [ ! -d "$SNF_IMAGE_TARGET" ]; then
74 log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
77 if [ -z "$SNF_IMAGE_HOSTNAME" ]; then
78 log_error "Hostname is missing"
81 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
82 windows_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
83 elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
84 linux_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
89 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :