root / rename @ e34560c8
History | View | Annotate | Download (3 kB)
1 | 79224631 | Lance Albertson | #!/bin/bash |
---|---|---|---|
2 | 79224631 | Lance Albertson | |
3 | 39855ac4 | Lance Albertson | # Copyright (C) 2010 Oregon State University |
4 | 79224631 | Lance Albertson | # |
5 | 79224631 | Lance Albertson | # This program is free software; you can redistribute it and/or modify |
6 | 79224631 | Lance Albertson | # it under the terms of the GNU General Public License as published by |
7 | 79224631 | Lance Albertson | # the Free Software Foundation; either version 2 of the License, or |
8 | 79224631 | Lance Albertson | # (at your option) any later version. |
9 | 79224631 | Lance Albertson | # |
10 | 79224631 | Lance Albertson | # This program is distributed in the hope that it will be useful, but |
11 | 79224631 | Lance Albertson | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 79224631 | Lance Albertson | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | 79224631 | Lance Albertson | # General Public License for more details. |
14 | 79224631 | Lance Albertson | # |
15 | 79224631 | Lance Albertson | # You should have received a copy of the GNU General Public License |
16 | 79224631 | Lance Albertson | # along with this program; if not, write to the Free Software |
17 | 79224631 | Lance Albertson | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 79224631 | Lance Albertson | # 02110-1301, USA. |
19 | 79224631 | Lance Albertson | |
20 | 79224631 | Lance Albertson | set -e |
21 | 79224631 | Lance Albertson | |
22 | 79224631 | Lance Albertson | . common.sh |
23 | 79224631 | Lance Albertson | |
24 | e7a2d1ad | Lance Albertson | debug set -x |
25 | e7a2d1ad | Lance Albertson | |
26 | 8727c57d | Lance Albertson | if [ "${NOMOUNT}" = "yes" ] ; then |
27 | 8727c57d | Lance Albertson | # do nothing if NOMOUNT is enabled |
28 | 8727c57d | Lance Albertson | exit 0 |
29 | 8727c57d | Lance Albertson | fi |
30 | 8727c57d | Lance Albertson | |
31 | 39855ac4 | Lance Albertson | TARGET=`mktemp -d` || exit 1 |
32 | 39855ac4 | Lance Albertson | CLEANUP+=("rmdir $TARGET") |
33 | 79224631 | Lance Albertson | |
34 | 79224631 | Lance Albertson | # If the target device is not a real block device we'll first losetup it. |
35 | 79224631 | Lance Albertson | # This is needed for file disks. |
36 | 79224631 | Lance Albertson | if [ ! -b $blockdev ]; then |
37 | 79224631 | Lance Albertson | ORIGINAL_BLOCKDEV=$blockdev |
38 | 8d0132dc | Lance Albertson | blockdev=$($LOSETUP -sf $blockdev) |
39 | 8d0132dc | Lance Albertson | CLEANUP+=("$LOSETUP -d $blockdev") |
40 | 79224631 | Lance Albertson | fi |
41 | 79224631 | Lance Albertson | |
42 | 494927a8 | Lance Albertson | filesystem_dev=$(map_disk0 $blockdev) |
43 | 39855ac4 | Lance Albertson | CLEANUP+=("unmap_disk0 $blockdev") |
44 | 494927a8 | Lance Albertson | root_dev=$(map_partition $filesystem_dev root) |
45 | 494927a8 | Lance Albertson | boot_dev=$(map_partition $filesystem_dev boot) |
46 | 79224631 | Lance Albertson | |
47 | 77449e7c | Lance Albertson | mount_disk0 $TARGET |
48 | abade4ea | Lance Albertson | get_os_type $TARGET |
49 | 6161ab06 | Lance Albertson | |
50 | 6161ab06 | Lance Albertson | case "${OS_TYPE}" in |
51 | 6161ab06 | Lance Albertson | debian) |
52 | 6161ab06 | Lance Albertson | HNAME="${TARGET}/etc/hostname" |
53 | 6161ab06 | Lance Albertson | OLD_HNAME="$(cat $HNAME)" |
54 | 6161ab06 | Lance Albertson | ;; |
55 | 6161ab06 | Lance Albertson | redhat) |
56 | 6161ab06 | Lance Albertson | HNAME="${TARGET}/etc/sysconfig/network" |
57 | 6161ab06 | Lance Albertson | OLD_HNAME="$(grep HOSTNAME ${HNAME} | \ |
58 | 7e603c5d | Lance Albertson | sed -e 's/HOSTNAME=//' | \ |
59 | 7e603c5d | Lance Albertson | sed -e s/\"//g)" |
60 | 6161ab06 | Lance Albertson | ;; |
61 | 6161ab06 | Lance Albertson | gentoo) |
62 | 6161ab06 | Lance Albertson | HNAME="${TARGET}/etc/conf.d/hostname" |
63 | 0747d6ac | Lance Albertson | # baselayout-2.x support |
64 | 0747d6ac | Lance Albertson | if [ -d ${TARGET}/usr/share/openrc ] ; then |
65 | 0747d6ac | Lance Albertson | OLD_HNAME="$(grep hostname ${HNAME} | \ |
66 | 0747d6ac | Lance Albertson | sed -e 's/hostname=//' | \ |
67 | 0747d6ac | Lance Albertson | sed -e s/\"//g)" |
68 | 0747d6ac | Lance Albertson | else |
69 | 0747d6ac | Lance Albertson | OLD_HNAME="$(grep HOSTNAME ${HNAME} | \ |
70 | 0747d6ac | Lance Albertson | sed -e 's/HOSTNAME=//' | \ |
71 | 0747d6ac | Lance Albertson | sed -e s/\"//g)" |
72 | 0747d6ac | Lance Albertson | fi |
73 | 6161ab06 | Lance Albertson | ;; |
74 | 6161ab06 | Lance Albertson | suse) |
75 | 6161ab06 | Lance Albertson | HNAME="${TARGET}/etc/HOSTNAME" |
76 | 6161ab06 | Lance Albertson | OLD_HNAME="$(cat $HNAME)" |
77 | 6161ab06 | Lance Albertson | ;; |
78 | 6161ab06 | Lance Albertson | esac |
79 | 79224631 | Lance Albertson | |
80 | 314b080b | Lance Albertson | if [ "$OLD_HNAME" = "$old_name" \ |
81 | 314b080b | Lance Albertson | -o "${OLD_HNAME}.$(echo $old_name | cut -d . -f 2,3)" \ |
82 | c6d45f5f | Lance Albertson | = "$old_name" ] ; then |
83 | 6161ab06 | Lance Albertson | case "${OS_TYPE}" in |
84 | 6161ab06 | Lance Albertson | debian|suse) |
85 | 6161ab06 | Lance Albertson | echo $instance > $HNAME |
86 | 6161ab06 | Lance Albertson | ;; |
87 | 314b080b | Lance Albertson | redhat) |
88 | 7e603c5d | Lance Albertson | sed -ie "s/HOSTNAME=${OLD_HNAME}/HOSTNAME=${instance}/" $HNAME |
89 | 6161ab06 | Lance Albertson | ;; |
90 | 314b080b | Lance Albertson | gentoo) |
91 | 0747d6ac | Lance Albertson | if [ -d ${TARGET}/usr/share/openrc ] ; then |
92 | 0747d6ac | Lance Albertson | sed -ie "s/hostname.*/hostname=\"${instance}\"/" $HNAME |
93 | 0747d6ac | Lance Albertson | else |
94 | 0747d6ac | Lance Albertson | sed -ie "s/HOSTNAME.*/HOSTNAME=\"${instance}\"/" $HNAME |
95 | 0747d6ac | Lance Albertson | fi |
96 | 314b080b | Lance Albertson | ;; |
97 | 6161ab06 | Lance Albertson | esac |
98 | 79224631 | Lance Albertson | else |
99 | 6161ab06 | Lance Albertson | log_error "Cannot rename from $old_name to $instance:" |
100 | 6161ab06 | Lance Albertson | log_error "Instance has a different hostname ($OLD_HNAME)" |
101 | 6161ab06 | Lance Albertson | exit 1 |
102 | 79224631 | Lance Albertson | fi |
103 | 79224631 | Lance Albertson | |
104 | 79224631 | Lance Albertson | # execute cleanups |
105 | 79224631 | Lance Albertson | cleanup |
106 | 79224631 | Lance Albertson | trap - EXIT |
107 | 79224631 | Lance Albertson | |
108 | 79224631 | Lance Albertson | exit 0 |