~ev/migration-assistant/trunk

« back to all changes in this revision

Viewing changes to ma-script-utils

  • Committer: Evan Dandrea
  • Date: 2010-04-23 14:24:34 UTC
  • Revision ID: evan.dandrea@canonical.com-20100423142434-2o9xpd7m662rt17j
* Catch empty arguments to unmount_os (LP 536673).
* Continue to the next operating system if mount_os fails.
* Clean up mount_os.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
unmount_os() {
54
54
    # If we didn't mount the device ourselves, don't unmount it.
55
55
    [ "$mountpoint" = "/mnt/migrationassistant" ] || return 0
 
56
    [ -z "$1" ] && return 0
56
57
    unmount_previously_run=
57
58
    device="$1"
58
59
 
110
111
    ostype="$1"
111
112
    device="$2"
112
113
 
113
 
 
114
114
    if [ "$1" = "linux" ]; then
115
115
        mkdir -p $mountpoint
116
116
        unmount_os $device
117
 
        mount $device $mountpoint || error "Failed to mount $device"
 
117
        if ! mount $device $mountpoint; then
 
118
            error "Failed to mount $device"
 
119
            exit 1
 
120
        fi
118
121
        if [ -f "$mountpoint/etc/fstab" ]; then
119
122
            while read uuid mp rest; do
120
123
                echo "$uuid" | grep -q '^#' && continue
121
124
                if [ "$mp" != "/home" ]; then
122
125
                    continue
123
126
                fi
124
 
 
125
 
                if [ "${uuid%=*}" = "UUID" ]; then
126
 
                    devname="/dev/disk/by-uuid/${uuid#*=}"
127
 
                    uuid=$(readlink -e "$devname") || \
128
 
                        error "$devname does not exist."
129
 
                elif [ "${uuid%=*}" = "LABEL" ]; then
130
 
                    devname="/dev/disk/by-label/${uuid#*=}"
131
 
                    uuid=$(readlink -e "$devname") || \
132
 
                        error "$devname does not exist."
133
 
                    elif [ ! -e "$uuid" ]; then
134
 
                        # This happens when the IDE driver in the old OS
135
 
                        # doesn't match the driver in the installer.  The old
136
 
                        # /home might be mounted on /dev/hda3 which could now
137
 
                        # be /dev/sda3 or something entirely different.  Since
138
 
                        # there's no way to determine what the device is
139
 
                        # without the old kernel loaded, we fail gracefully so
140
 
                        # that we can continue to the next OS.
141
 
                        log "$uuid does not exist, continuing."
142
 
                        break
143
 
                    fi
144
 
                    failed=
145
 
                    mount $uuid "$mountpoint/home" || failed="1"
146
 
                        if [ "$failed" ]; then
 
127
                devname=
 
128
                if [ -n "${uuid#*=}" ]; then
 
129
                    if [ "${uuid%=*}" = "UUID" ]; then
 
130
                        devname="/dev/disk/by-uuid/${uuid#*=}"
 
131
                    elif [ "${uuid%=*}" = "LABEL" ]; then
 
132
                        devname="/dev/disk/by-label/${uuid#*=}"
 
133
                    fi
 
134
                fi
 
135
                if [ -n "$devname" ]; then
 
136
                    uuid=$(readlink -e "$devname") || uuid=
 
137
                    if [ -z "$uuid"]; then
 
138
                        error "$devname does not exist."
 
139
                        return 1
 
140
                    fi
 
141
                else
 
142
                    error "couldn't understand $uuid."
 
143
                    return 1
 
144
                fi
 
145
                
 
146
                if [ ! -e "$uuid" ]; then
 
147
                    # This happens when the IDE driver in the old OS
 
148
                    # doesn't match the driver in the installer.  The old
 
149
                    # /home might be mounted on /dev/hda3 which could now
 
150
                    # be /dev/sda3 or something entirely different.  Since
 
151
                    # there's no way to determine what the device is
 
152
                    # without the old kernel loaded, we fail gracefully so
 
153
                    # that we can continue to the next OS.
 
154
                    error "$uuid does not exist."
 
155
                    return 1
 
156
                fi
 
157
                if ! mount $uuid "$mountpoint/home"; then
147
158
                    unmount_os "$uuid"
148
 
                    mount $uuid "$mountpoint/home" || \
 
159
                    if ! mount $uuid "$mountpoint/home"; then
149
160
                        error "failed to mount $uuid"
 
161
                        return 1
 
162
                    fi
150
163
                fi
151
164
                break
152
165
            done < "$mountpoint/etc/fstab"
162
175
 
163
176
        mkdir -p $mountpoint
164
177
        unmount_os $device
165
 
        mount -t ntfs $device $mountpoint -o umask=0022,nls=utf8 3>&- || \
166
 
        ( log "Mounting $device to $mountpoint with NTFS failed."
167
 
        mount -t vfat $device $mountpoint -o umask=0022,utf8 || \
168
 
        log "Mounting $device to $mountpoint with VFAT failed." )
 
178
        if ! mount -t ntfs $device $mountpoint -o umask=0022,nls=utf8 3>&-; then
 
179
            log "Mounting $device to $mountpoint with NTFS failed."
 
180
            if ! mount -t vfat $device $mountpoint -o umask=0022,utf8; then
 
181
                log "Mounting $device to $mountpoint with VFAT failed."
 
182
                return 1
 
183
            fi
 
184
        fi
169
185
    fi
170
 
 
171
186
}
172
187
 
173
188
ROOT=/target