Revision bad5ca1f snf-image-helper/tasks/50AssignHostname.in
b/snf-image-helper/tasks/50AssignHostname.in | ||
---|---|---|
8 | 8 |
### END TAST INFO |
9 | 9 |
|
10 | 10 |
set -e |
11 |
. @commondir@/common.sh
|
|
11 |
. "@commondir@/common.sh"
|
|
12 | 12 |
|
13 | 13 |
windows_hostname() { |
14 |
local target=$1
|
|
15 |
local password=$2
|
|
14 |
local target="$1"
|
|
15 |
local password="$2"
|
|
16 | 16 |
|
17 | 17 |
local tmp_unattend=`mktemp` || exit 1 |
18 |
CLEANUP+=("rm $tmp_unattend")
|
|
18 |
add_cleanup rm "$tmp_unattend"
|
|
19 | 19 |
|
20 | 20 |
echo -n "Assigning new computer name..." |
21 | 21 |
|
22 | 22 |
local namespace="urn:schemas-microsoft-com:unattend" |
23 | 23 |
|
24 |
$XMLSTARLET ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:ComputerName" -v $password "$target/Unattend.xml" > $tmp_unattend
|
|
24 |
"$XMLSTARLET" ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:ComputerName" -v "$password" "$target/Unattend.xml" > "$tmp_unattend"
|
|
25 | 25 |
|
26 |
cat $tmp_unattend > "$target/Unattend.xml"
|
|
26 |
cat "$tmp_unattend" > "$target/Unattend.xml"
|
|
27 | 27 |
echo done |
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
linux_hostname() { |
31 |
local target=$1
|
|
32 |
local hostname=$2
|
|
31 |
local target="$1"
|
|
32 |
local hostname="$2"
|
|
33 | 33 |
|
34 |
local distro=$(get_base_distro $target)
|
|
34 |
local distro=$(get_base_distro "$target")
|
|
35 | 35 |
|
36 | 36 |
case "$distro" in |
37 | 37 |
debian) |
38 |
echo "$hostname" > $target/etc/hostname;;
|
|
38 |
echo "$hostname" > "$target/etc/hostname";;
|
|
39 | 39 |
redhat) |
40 |
sed -ie "s/HOSTNAME=.*$/HOSTNAME=$hostname/g" $target/etc/sysconfig/network;;
|
|
40 |
sed -ie "s/HOSTNAME=.*$/HOSTNAME=$hostname/g" "$target/etc/sysconfig/network";;
|
|
41 | 41 |
slackware|suse) |
42 | 42 |
#local domain=$(sed -e 's/^[^\.]*//g' < /etc/HOSTNAME) |
43 | 43 |
|
44 | 44 |
# In slackware hostname and domain name are joined together. For now I |
45 | 45 |
# will not retain the domain name. |
46 | 46 |
|
47 |
echo $hostname > ${target}/etc/HOSTNAME;;
|
|
47 |
echo "$hostname" > "${target}/etc/HOSTNAME";;
|
|
48 | 48 |
gentoo) |
49 |
sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"$hostname\"/" $target/etc/conf.d/hostname;;
|
|
49 |
sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"$hostname\"/" "$target/etc/conf.d/hostname";;
|
|
50 | 50 |
esac |
51 | 51 |
|
52 | 52 |
# Some Linux distributions assign the hostname to 127.0.1.1 in order to be |
53 | 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
|
|
54 |
sed -ie "s/^[[:blank:]]*127\.0\.1\.1[[:blank:]].\+$/127.0.1.1\t$hostname/" "$target/etc/hosts"
|
|
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
... | ... | |
63 | 63 |
fi |
64 | 64 |
|
65 | 65 |
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then |
66 |
windows_hostname $SNF_IMAGE_TARGET $SNF_IMAGE_HOSTNAME
|
|
66 |
windows_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
|
|
67 | 67 |
elif [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
68 |
linux_hostname $SNF_IMAGE_TARGET $SNF_IMAGE_HOSTNAME
|
|
68 |
linux_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
|
|
69 | 69 |
fi |
70 | 70 |
|
71 | 71 |
cleanup |
Also available in: Unified diff