-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_option
executable file
·99 lines (84 loc) · 1.89 KB
/
do_option
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
#!/bin/sh
set -e
. /lib/partman/lib/base.sh
dev=${1%//*}
id=${1#*//}
cd $dev
setup_reuse_partition () {
echo keep > $1/method
if [ -f $1/detected_filesystem ]; then
cp $1/detected_filesystem $1/filesystem
fi
mkdir -p $1/options
rm -f $1/format
>$1/use_filesystem
>$1/reuse
}
path=
cleanup_ro_partitions=
mountpoint="$(mktemp -d)"
cleanup () {
[ -e $mountpoint ] && umount -l $mountpoint && rmdir $mountpoint || true
for p in $cleanup_ro_partitions; do
blockdev --setrw $p || true
done
}
trap cleanup EXIT HUP INT QUIT TERM
setup_reuse_partition $id
echo / > $id/mountpoint
update_partition $dev $id
open_dialog PARTITION_INFO $id
read_line num i size type fs path name
close_dialog
mounted=
if type grub-mount >/dev/null 2>&1 && \
grub-mount "$path" "$mountpoint" 2>/dev/null 3>&- 6>&- 7<&-; then
mounted=1
else
blockdev --setro "$path" || continue
cleanup_ro_partitions="$cleanup_ro_partitions $path"
if mount -o ro "$path" "$mountpoint" 3>&- 6>&- 7<&-; then
mounted=1
fi
fi
if [ ! "$mounted" ] || [ ! -f "$mountpoint/etc/fstab" ]; then
exit 100
fi
fstab=
while read uuid mp rest; do
if [ "${uuid%=*}" != "UUID" ]; then
continue
fi
uuid="${uuid#*=}"
if [ ! -e "/dev/disk/by-uuid/$uuid" ]; then
continue
fi
fstab="$fstab $uuid,$mp"
done < "$mountpoint/etc/fstab"
for dev in $DEVICES/*; do
cd $dev
partitions=
open_dialog PARTITIONS
while { read_line num i size type fs p name; [ "$i" ]; }; do
if [ "$(cat $i/detected_filesystem)" = "linux-swap" ]; then
# Swap will be automatically used.
continue
fi
u="$(blkid -o value -s UUID $p)" || true
for line in $fstab; do
uuid="${line%,*}"
mp="${line#*,}"
if [ "$uuid" = "$u" ]; then
echo "$mp" > $i/mountpoint
partitions="$partitions $i"
break
fi
done
done
close_dialog
for part in $partitions; do
setup_reuse_partition $part
update_partition $dev $part
done
done
exit 100