~ubuntu-branches/ubuntu/lucid/migration-assistant/lucid-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/sh

# TODO: Incorporate capb backup.

set -e
. /usr/share/debconf/confmodule
. /usr/share/migration-assistant/ma-script-utils

if [ -z "$1" ]; then
    mapath="/usr/bin"
else
    mapath="$1"
fi

OLDIFS="$IFS"
NEWLINE='
'

IFS="$NEWLINE"
tmp=
for line in `os-prober`;
do
    dist=$(LC_ALL=C expr match "$line" '.*:\(.*\):.*:.*')
    location=${line%%:*}
    if [ -z "$tmp" ]; then
        tmp="$dist ($location)"
    else
        tmp="$tmp, $dist ($location)"
    fi
done
IFS="$OLDIFS"

db_subst migration-assistant/partitions choices "$tmp"
db_input high migration-assistant/partitions || true
db_go || exit 10

db_get migration-assistant/partitions || RET=
IFS="$NEWLINE"
selection=`echo "$RET" | sed -e 's/, /\n/g'`
for choice in $selection; do # Microsoft Windows XP Professional (/dev/hda1)
    IFS="$OLDIFS"
    location=$(LC_ALL=C expr "$choice" : '.*(\(.*\))$') # /dev/hda1
    IFS="$NEWLINE"
    for line in `os-prober`; do
        IFS="$OLDIFS"
        loc="${line%%:*}"
        if [ "$location" != "$loc" ]; then
            continue
        fi
        log "setting ostype from: '$line'"
        set_os_type "$line" || continue
        log "got ostype of: '$ostype', mountpoint is: '$mountpoint'"

        path="${loc#*/*/}" # hda1 or discs/disc0/part1
        mount_os "$ostype" "$loc" || continue
        db_register migration-assistant/users migration-assistant/$path/users
        db_subst migration-assistant/$path/users user-choices \
            "$($mapath/ma-search-users "$ostype" "$mountpoint" 2>>/var/log/syslog)"
        db_subst migration-assistant/$path/users os-type "$choice"

        db_input high migration-assistant/$path/users || true
        db_go || exit 10

        db_get migration-assistant/$path/users || RET=
        
        user_selection=`echo "$RET" | sed -e 's/, /\n/g'`
        IFS="$NEWLINE"
        for usr in $user_selection; do
            IFS="$OLDIFS"
            itemsret=$($mapath/ma-search-items --path="$mountpoint" --ostype="$ostype" --user="$usr" 2>>/var/log/syslog) || \
                (itemsret=; error "ma-search-items exited with an error for $usr.")
            # FIXME: We should figure out if there are any items for each user
            # before asking to import from the user.  Likewise, we should
            # figure out if there are any users to import before asking to
            # import from a partition.
            if [ -z "$itemsret" ]; then
                continue
            fi
            formatted_user=`echo "$usr" | sed -e 's/ /+/g'`
            db_register migration-assistant/items migration-assistant/$path/$formatted_user/items
            db_subst migration-assistant/$path/$formatted_user/items choices "$itemsret"
            db_subst migration-assistant/$path/$formatted_user/items user "$usr"

            # migration-assistant/discs/disc0/part1/Evan/items
            db_input high migration-assistant/$path/$formatted_user/items || true
            db_go || exit 10

            db_register migration-assistant/user migration-assistant/$path/$formatted_user/user
            # This prevents m-a from working right. change to choices
            #db_set migration-assistant/$path/$formatted_user/user "$(echo "$usr" | tr '[A-Z]' '[a-z]')"
            db_subst migration-assistant/$path/$formatted_user/user old-user "$usr"

            while :; do
                db_input high migration-assistant/$path/$formatted_user/user || true
                db_go || exit 10
                
                db_get migration-assistant/$path/$formatted_user/user || RET=
                new_user="$RET"
                
                if ! LC_ALL=C expr "$new_user" : '[a-z][-a-z0-9]*$' >/dev/null; then
                    db_fset migration-assistant/$path/$formatted_user/user seen false
                    db_fset migration-assistant/username-bad seen false
                    db_subst migration-assistant/username-bad user "$new_user"
                    db_input critical migration-assistant/username-bad
                    continue
                fi
                
                # TODO: Either copy this or depend on user-setup.
                if grep -v '^#' /usr/lib/user-setup/reserved-usernames | \
                   grep -q "^$new_user\$"; then
                    db_fset migration-assistant/$path/$formatted_user/user seen false
                    db_fset migration-assistant/username-reserved seen false
                    db_subst migration-assistant/username-reserved user "$new_user"
                    db_input critical migration-assistant/username-reserved
                    continue
                fi
                break
            done

            # Only ask if the user doesn't match the one seeded for user-setup.
            db_get passwd/username || RET=
            if [ "$new_user" = "$RET" ]; then
                continue
            fi

            # Password
            db_register migration-assistant/password migration-assistant/new-user/$new_user/password
            db_subst migration-assistant/new-user/$new_user/password user "$new_user"

            db_register migration-assistant/password-again migration-assistant/new-user/$new_user/password-again
            db_subst migration-assistant/new-user/$new_user/password-again user "$new_user"

            while :; do
                db_input high migration-assistant/new-user/$new_user/password || true
                db_go || exit 10
                db_get migration-assistant/new-user/$new_user/password || RET=
                pass=$RET

                db_input high migration-assistant/new-user/$new_user/password-again || true
                db_go || exit 10
                db_get migration-assistant/new-user/$new_user/password-again || RET=
                pass2=$RET
                
                if [ -z "$pass2" ] || [ -z "$pass" ]; then
                    db_set migration-assistant/new-user/$new_user/password ""
                    db_set migration-assistant/new-user/$new_user/password-again ""
                    db_fset migration-assistant/password-empty seen "false"
                    db_input high migration-assistant/password-empty || true
                    db_fset migration-assistant/new-user/$new_user/password seen "false"
                    db_fset migration-assistant/new-user/$new_user/password-again seen "false"
                    db_go || true
                    continue
                fi

                if [ "$pass2" = "$pass" ]; then
                    break
                else
                    db_set migration-assistant/new-user/$new_user/password ""
                    db_set migration-assistant/new-user/$new_user/password-again ""
                    db_fset migration-assistant/password-mismatch seen "false"
                    db_input high migration-assistant/password-mismatch || true
                    db_fset migration-assistant/new-user/$new_user/password seen "false"
                    db_fset migration-assistant/new-user/$new_user/password-again seen "false"
                    db_go || true
                fi
            done

            # Full Name
            db_register migration-assistant/fullname migration-assistant/new-user/$new_user/fullname
            db_subst migration-assistant/new-user/$new_user/fullname user "$new_user"
            db_input high migration-assistant/new-user/$new_user/fullname || true
            db_go || exit 10
        done
        IFS="$OLDIFS"
        unmount_os
    done
done
# vim:ai:et:sts=4:tw=80:sw=4: