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
|
# General functions related to committing changes to devices
# Calling scripts must ensure /lib/partman/lib/base.sh is sourced as well!
# List the changes that are about to be committed and let the user confirm first
confirm_changes () {
local dev part partitions num id size type fs path name filesystem
local x template partdesc partitems items formatted_previously
local device dmtype
template="$1"
# Compute the changes we are going to do
partitems=''
items=''
formatted_previously=no
for dev in $DEVICES/*; do
[ -d "$dev" ] || continue
cd $dev
open_dialog IS_CHANGED
read_line x
close_dialog
if [ "$x" = yes ]; then
partitems="${partitems} $(humandev $(cat device))
"
fi
partitions=
open_dialog PARTITIONS
while { read_line num id size type fs path name; [ "$id" ]; }; do
[ "$fs" != free ] || continue
partitions="$partitions $id,$num"
done
close_dialog
for part in $partitions; do
id=${part%,*}
num=${part#*,}
[ -f $id/method -a -f $id/format \
-a -f $id/visual_filesystem ] || continue
# if no filesystem (e.g. swap) should either be not
# formatted or formatted before the method is specified
[ -f $id/filesystem -o ! -f $id/formatted \
-o $id/formatted -ot $id/method ] || continue
# if it is already formatted filesystem it must be formatted
# before the method or filesystem is specified
[ ! -f $id/filesystem -o ! -f $id/formatted \
-o $id/formatted -ot $id/method \
-o $id/formatted -ot $id/filesystem ] ||
{
formatted_previously=yes
continue
}
filesystem=$(cat $id/visual_filesystem)
partdesc=""
# Special case d-m devices to use a different description
if cat device | grep -q "/dev/mapper" ; then
device=$(cat device)
# dmraid and multipath devices are partitioned
if [ ! -f sataraid ] && \
! is_multipath_dev $device && \
! is_multipath_part $device; then
partdesc="partman/text/confirm_unpartitioned_item"
fi
fi
if [ -z "$partdesc" ]; then
partdesc="partman/text/confirm_item"
db_subst $partdesc PARTITION "$num"
fi
db_subst $partdesc TYPE "$filesystem"
db_subst $partdesc DEVICE $(humandev $(cat device))
db_metaget $partdesc description
items="${items} ${RET}
"
done
done
if [ "$items" ]; then
db_metaget partman/text/confirm_item_header description
items="$RET
$items"
fi
if [ "$partitems" ]; then
db_metaget partman/text/confirm_partitem_header description
partitems="$RET
$partitems"
fi
if [ "$partitems$items" ]; then
if [ -z "$items" ]; then
x="$partitems"
elif [ -z "$partitems" ]; then
x="$items"
else
x="$partitems
$items"
fi
maybe_escape "$x" db_subst $template/confirm ITEMS
db_input critical $template/confirm
db_go || true
db_get $template/confirm
if [ "$RET" = false ]; then
db_reset $template/confirm
return 1
else
db_reset $template/confirm
return 0
fi
else
if [ "$formatted_previously" = no ]; then
db_input critical $template/confirm_nochanges
db_go || true
if [ $template = partman-dmraid ]; then
# for dmraid, only a note is displayed
return 1
fi
db_get $template/confirm_nochanges
if [ "$RET" = false ]; then
db_reset $template/confirm_nochanges
return 1
else
db_reset $template/confirm_nochanges
return 0
fi
else
return 0
fi
fi
}
# Remove directories for partitions that no longer exist
# Device directory must be current
device_cleanup_partitions () {
local partitions pdirs pdir
partitions=
open_dialog PARTITIONS
while { read_line x1 id x; [ "$id" ]; }; do
partitions="${partitions:+$partitions$NL}$id"
done
close_dialog
pdirs="$(find . -type d | cut -d/ -f2 | sort -u |
grep "^[0-9]\+-[0-9]\+$")"
for pdir in $pdirs; do
if ! echo "$partitions" | grep -q "^$pdir$"; then
rm -rf $pdir
fi
done
}
commit_changes () {
local template
template=$1
for s in /lib/partman/commit.d/*; do
if [ -x $s ]; then
$s || {
db_input critical $template || true
db_go || true
for s in /lib/partman/init.d/*; do
if [ -x $s ]; then
$s || return 255
fi
done
return 1
}
fi
done
return 0
}
|