blob: f4bd6d14b1cebf98a64e2a535563b26b209b5b17 (
plain)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
#!/bin/bash
# import functions library
source rescue_common
tmpdir="/tmp/flash-rescue-root"
rootdir="$tmpdir/pen"
media_dir="/tmp/media"
upgrade_dir="$media_dir/upgrade"
config_files_network_scripts="etc/sysconfig/network-scripts/ifcfg-* \
etc/sysconfig/network-scripts/cellular.d \
etc/sysconfig/network-scripts/vpn.d \
etc/sysconfig/network-scripts/wireless.d"
config_files_users="etc/passwd etc/shadow etc/group etc/gshadow"
config_files_time="etc/localtime etc/ntp etc/ntp.conf"
config_files="etc/sysconfig/* $config_files_users $config_files_time \
etc/wpa_supplicant.conf etc/shorewall etc/kde \
etc/udev/rules.d/61-*_config.rules"
config_files_to_remove="etc/sysconfig/harddrake2"
function prepare() {
echo "Mounting Mandriva Flash key..."
echo
modprobe unionfs > /dev/null 2>&1
modprobe squashfs > /dev/null 2>&1
modprobe loop > /dev/null 2>&1
mkdir -p $rootdir
mkdir -p $tmpdir/squash
mkdir -p $tmpdir/user
mkdir -p $tmpdir/union
if ! mount_usbroot $rootdir; then
return 1
fi
mount -t ext2 -o loop $sys_loop $tmpdir/user > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error mounting system.loop"
return 1
fi
return 0
}
function get_existing_rpms() {
echo "Getting list of installed packages..."
echo
mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error mounting distrib.sqfs"
return 1
fi
mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \
none $tmpdir/union
if [ $? -ne 0 ]; then
echo "Error creating union of distrib.sqfs and system.loop"
return 1
fi
chroot $tmpdir/squash rpm -qa | sort > /tmp/previous_rpms.list
if [ $? -ne 0 ]; then
echo "Error getting list of vanilla rpms installed on previous key"
fi
chroot $tmpdir/union rpm -qa | sort > /tmp/existing_rpms.list
if [ $? -ne 0 ]; then
echo "Error getting list of rpms installed prior to upgrade"
fi
umount $tmpdir/union > /dev/null 2>&1
umount $tmpdir/squash > /dev/null 2>&1
mkdir -p $tmpdir/user/root
diff /tmp/previous_rpms.list /tmp/existing_rpms.list | sed -n 's/^> //p' > $tmpdir/user/root/new_existing_rpms.list
return 0
}
function move_files() {
for i in $*; do
if [ -e $i ]; then
dir=`dirname $i`
[ "$dir" = "." ] || mkdir -p ..keep/$dir
mv $i ..keep/$dir || { echo "Error moving $i"; return 1; }
fi
done
return 0
}
function remove_non_user_nor_config_files() {
echo "Filtering system configuration files and user accounts..."
echo
cd $tmpdir/user
rm -rf $config_files_to_remove
if [ -e ..keep ]; then
mv ..keep ..keep.bak
fi
if [ -e ..keep ]; then
echo "remove_non_user_nor_config_files can't work with existing temp dir"
return 1
fi
mkdir ..keep
move_files $config_files_network_scripts || return 1
rm -rf etc/sysconfig/network-scripts
move_files home root $config_files || return 1
rm -rf *
rm -rf .[^.]*
mv ..keep/* .
rmdir ..keep
cd - > /dev/null
return 0
}
function copy_new_version() {
echo "Copying new Mandriva Flash system..."
rm -rf $rootdir$boot_rel
rm -f $rootdir$loopbacks_rel/.*sqf
rm -f $rootdir$loopbacks_rel/.*sqfs
[ -d "$modules_dir" ] && rm -rf $modules_dir
tar c -C $upgrade_dir . | pv -s `du -sb $upgrade_dir | cut -f 1` | tar x -C $rootdir
echo
chmod -R u+w $rootdir
chmod -R u-w $rootdir$boot_rel $rootdir$loopbacks_rel
new_label=$(source_version_variables "2.0"; echo $label)
MTOOLS_SKIP_CHECK=1 mlabel -i $usbroot_device ::$new_label
return 0
}
function merge_config_files() {
echo "Merging user and group accounts in new system..."
echo
mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error mounting distrib.sqfs"
return 1
fi
upgrade.merge-users $tmpdir/user/etc $tmpdir/squash/etc
mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \
none $tmpdir/union
if [ $? -ne 0 ]; then
echo "Error creating union of distrib.sqfs and system.loop"
return 1
fi
#- reapply lang configuration, mostly to rewrite kdeglobals
chroot $tmpdir/union perl -I/usr/lib/libDrakX -Mlang -e "lang::write(lang::read())" &>/dev/null
return 0
}
function doit() {
if [ -d $tmpdir/user/var/lib/rpm/Packages ]; then
get_existing_rpms || return 1
fi
remove_non_user_nor_config_files || return 1
copy_new_version || return 1
merge_config_files || return 1
return 0
}
function cleanup() {
cd /
umount $tmpdir/union > /dev/null 2>&1
umount $tmpdir/user > /dev/null 2>&1
umount $tmpdir/squash > /dev/null 2>&1
umount $rootdir > /dev/null 2>&1
rmdir $tmpdir/union $tmpdir/user $tmpdir/squash 2> /dev/null
rmdir $rootdir $tmpdir 2> /dev/null
}
clear
trap cleanup SIGINT
version=""
if ! insert_pendrive; then
exit 1
fi
#- works only when upgrading versions with the same layout
sys_loop="$rootdir$loopbacks_rel/system.loop"
sfs_loop="$rootdir$loopbacks_rel/distrib.sqfs"
modules_dir="$rootdir$loopbacks_rel/modules"
echo
if ! prepare; then
cleanup
exit 1
fi
if ! doit; then
cleanup
exit 1
fi
cleanup
echo "Congratulations! Your Mandriva Flash system is now upgraded."
echo
exit 0
|