/usr/sbin/ocs-cvtimg-comp is in clonezilla 3.21.13-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 | #!/bin/bash
# License: GPL
# Author: Steven Shiau <steven _at_ nchc org tw>
# Description: To convert the image of Clonezilla from
# existing compression format to another one.
#
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. /etc/drbl/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions
# Load the config in ocs-live.conf. This is specially for Clonezilla live. It will overwrite some settings of /etc/drbl/drbl-ocs.conf, such as $DIA...
[ -e "/etc/ocs/ocs-live.conf" ] && . /etc/ocs/ocs-live.conf
# Settings
verbose="no"
chk_img_restoreable_def="yes"
#
USAGE() {
echo "$ocs - To convert the image of Clonezilla from existing compression format to another one"
echo "Usage:"
echo "To run $ocs:"
echo "$ocs [OPTION] SRC_IMAGE_NAME DEST_IMAGE_NAME"
echo "Options:"
echo "-b, --batch-mode Run image checking in batch mode"
echo "-i, --image-size SIZE Set the split image file volume size SIZE (MB). When $ocs is run with -x, the default SIZE is set as $VOL_LIMIT_IN_INTERACTIVE, if without -x, we will not split it."
echo "-or, --ocsroot DIR Specify DIR (absolute path) as directory ocsroot (i.e. overwrite the ocsroot assigned in drbl.conf)"
echo "-nogui, --nogui Do not show GUI (TUI) of Partclone when checking, use text only"
echo "-sc, --skip-check-restorable Skip checking the image if restorable after it is converted."
echo "-v, --verbose Prints verbose information"
echo "-z0, --no-compress Convert to uncompression format"
echo "-z1, --gzip-compress Convert to gzip format"
echo "-z2, --bz2-compress Convert to bzip2 format"
echo "-z3, --lzo-compress Convert to lzop format"
echo "-z4, --lzma-compress Convert to lzma format"
echo "-z5, --xz-compress Convert to xz format"
echo "-z6, --lzip-compress Convert to lzip format"
echo "-z7, --lrzip-compress Convert to lrzip format"
echo "SRC_IMAGE_NAME and DEST_IMAGE_NAME are the image dir name, not absolute path"
echo "If the destination compression format is not assigned, XZ format will be used"
echo "If \"ask_user\" is used as SRC_IMAGE_NAME or DEST_IMAGE_NAME, a dialog menu will be shown to allow selection or inputing."
echo "If no SRC_IMAGE_NAME or DEST_IMAGE_NAME is specified, a dialog menu will be shown."
echo "Ex:"
echo "To convert the image \"my-image\", which is located in $ocsroot/my-image to \"my-image-xz\" with xz format, run"
echo " $ocs -z5 my-image my-image-pixz"
echo
} # end of USAGE
#
choose_compress_format() {
local TMP=`mktemp /tmp/ocs_comp.XXXXXX`
local z_opt default_comp
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
show_z4_or_above_menu_or_not
if [ -n "$ocs_z5_option_1" ]; then
default_comp_opt="--default-item $ocs_z5_option_1"
fi
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"$msg_nchc_clonezilla" --menu "$msg_choose_one_compression_param_to_save" \
$default_comp_opt \
0 0 0 $DIA_ESC \
"-z1" "$msg_ocs_param_z1" \
"-z2" "$msg_ocs_param_z2" \
"-z3" "$msg_ocs_param_z3" \
$ocs_z4_option_1 $ocs_z4_option_2 \
$ocs_z5_option_1 $ocs_z5_option_2 \
$ocs_z6_option_1 $ocs_z6_option_2 \
$ocs_z7_option_1 $ocs_z7_option_2 \
"-z0" "$msg_ocs_param_z0" \
2> $TMP
z_opt="$(cat $TMP)"
case "$z_opt" in
-z0) IMG_CLONE_CMP="cat";;
-z1)
if type pigz &>/dev/null; then
IMG_CLONE_CMP="pigz -c $extra_pigz_opt"
else
IMG_CLONE_CMP="gzip -c $extra_gzip_opt"
fi
shift;;
-z2)
if [ "$parallel_bzip2_prog" = "pbzip2" ] && type pbzip2 &>/dev/null; then
IMG_CLONE_CMP="pbzip2 -c $extra_pbzip2_opt"
elif [ "$parallel_bzip2_prog" = "lbzip2" ] && type lbzip2 &>/dev/null; then
IMG_CLONE_CMP="lbzip2 -c $extra_lbzip2_opt"
else
IMG_CLONE_CMP="bzip2 -c $extra_bzip2_opt"
fi
shift;;
-z3) IMG_CLONE_CMP="lzop -c $extra_lzop_opt";;
-z4) IMG_CLONE_CMP="lzma -c $extra_lzma_opt";;
-z6)
if type plzip &>/dev/null; then
IMG_CLONE_CMP="plzip -c $extra_plzip_opt"
else
IMG_CLONE_CMP="lzip -c $extra_lzip_opt"
fi
shift;;
-z7) IMG_CLONE_CMP="lrzip -q - $extra_lrzip_opt";;
*)
if type pixz &>/dev/null; then
IMG_CLONE_CMP="pixz $extra_pixz_opt"
else
IMG_CLONE_CMP="xz -c $extra_xz_opt"
fi
shift;;
esac
[ -f "$TMP" ] && rm -f $TMP
} # end of choose_compress_format
#
ask_if_check_converted_img() {
local TMP=`mktemp /tmp/ocs_chk.XXXXXX`
local sc_opt
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
# Question about checking the image after conversion
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"$msg_nchc_clonezilla" --menu "$msg_choose_if_checking_image_restorable" \
0 0 0 $DIA_ESC \
" " "$msg_check_converted_img_restorable" \
"-sc" "$msg_skip_check_converted_img_restorable" \
2> $TMP
sc_opt="$(cat $TMP)"
case "$sc_opt" in
-sc) chk_img_restoreable="no";;
*) chk_img_restoreable="yes";;
esac
[ -f "$TMP" ] && rm -f $TMP
} # ask_if_check_converted_img
#
ask_image_volume_size() {
local vol_size_tmp
local ASK_VOL_SIZE=1
# VOL_LIMIT and VOL_LIMIT_prompt are global variables.
vol_size_tmp="$(mktemp /tmp/vol_size_tmp.XXXXXX)"
trap "[ -f "$vol_size_tmp" ] && rm -f $vol_size_tmp" HUP INT QUIT TERM EXIT
while [ "$ASK_VOL_SIZE" -ne 0 ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"$msg_nchc_clonezilla" --inputbox "$msg_set_image_volume_size" \
0 0 $VOL_LIMIT_prompt \
2> $vol_size_tmp
if [ -n "$(cat $vol_size_tmp | grep -iE "[^[:digit:]]")" ]; then
ASK_VOL_SIZE=1
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" \
--msgbox "$msg_enter_digits_only\n$msg_please_do_it_again!!!" 0 0
else
ASK_VOL_SIZE=0
fi
done
VOL_LIMIT="$(cat $vol_size_tmp)"
[ -f "$vol_size_tmp" ] && rm -f $vol_size_tmp
} # ask_image_volume_size
#
img_covert_to_diff_compression() {
local file_ fs_ partclone_img_info_tmp file_basename rc img_info
local used_size block_size used_size_byte rmopt_v
# First, we find the filesystem
file_="$(unalias ls &>/dev/null; ls $target_d/$img_file.*-img* 2>/dev/null | sort | head -n 1)"
file_basename="$(basename ${file_})"
if [ -n "${file_}" ]; then
if [ -n "$(echo $file_basename | grep -Eo -- "-ptcl-img")" ]; then
# new format, image file is like: sda1.ext4-ptcl-img.gz, sda1.ext4-ptcl-img.gz.aa
fs_="$(echo $file_basename | sed -e "s/^$img_file\.//g" -e "s/-ptcl-img.*//g")"
else
# old format, image file is like: sda2.hfsp-img.aa sda2.hfsp-img.ab sda2.hfsp-img.ac
fs_="$(echo $file_basename | sed -e "s/^$img_file\.//g" -e "s/-img.*//g")"
fi
fi
if [ -z "${fs_}" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "The file system can not be decided in function img_covert_to_diff_compression!!!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
my_ocs_exit 1
fi
if [ -n "$(echo "$file_basename" | grep -Eo -- "-ptcl-img")" ]; then
# New format
if [ -n "$(echo "$file_basename" | grep -Eo -- "-ptcl-img.*.aa")" ]; then
# New format with image split, e.g. sda1.ext4-ptcl-img.gz.aa
get_image_cat_zip_cmd ${file_basename}
# e.g. sda1.ext4-ptcl-img.gz.aa -> sda1.ext4-ptcl-img.gz.*
img_file_prefix="$(echo ${file_basename} | sed -r -e "s/\.aa*$//").*"
else
# New format with image not split, e.g. sda1.ext4-ptcl-img.gz
get_image_cat_zip_cmd ${file_basename}
# The file is NOT split, so the file name is just like "sda1.ext4-ptcl-img.gz" only, no "."
img_file_prefix="${file_basename}"
fi
else
# Old format
# The split suffix length for old format is only 2, so we do not have to consider >=3 (*.aaa or more).
if [ -f "$target_d/$img_file.${fs_}-img.aa" ]; then
# Old format with image split
get_image_cat_zip_cmd $target_d/$img_file.${fs_}-img.aa
# The files are split, like hda1.00, hda1.01, so we have to add "."
img_file_prefix="$img_file.${fs_}-img.*"
else
# Old format with image not split
get_image_cat_zip_cmd $target_d/$img_file.${fs_}-img
# The file is NOT split, so the file name is just like "hda1" only, no "."
img_file_prefix="$img_file.${fs_}-img"
fi
fi
echo $msg_delimiter_star_line
s_comp_suf="$(ocs-get-comp-suffix $unzip_stdin_cmd)"
if [ -z "$s_comp_suf" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "Failed to find the compression format of source image!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
my_ocs_exit 1
fi
# E.g.
# (1) New format without split, e.g.
# sda1.ext4-ptcl-img.gz.aa -> sda1.ext4-ptcl-img.gz.* (now) -> sda1.ext4-ptcl-img
# (2) New format with image not split, e.g.
# sda1.ext4-ptcl-img.gz (now) -> sda1.ext4-ptcl-img
#t_img_file_prefix="$(echo $img_file_prefix | sed -r -e "s|\.\*$||g" \
# -e "s|\.$s_comp_suf\..*$||g" -e "s|\.$s_comp_suf$||g")"
t_img_file_prefix="$(echo $img_file_prefix | sed -r -e "s|\.\*$||g" -e "s|\.${s_comp_suf}$||g")"
# //NOTE// Here we force to use LC_ALL=C for partclone since we need to use get_partclone_image_info to parse the log file to get the rate. Only the keyword in English is supported in get_partclone_image_info.
split_error="$(mktemp /tmp/split_error.XXXXXX)"
trap "[ -f "$TMP" ] && rm -f $split_error" HUP INT QUIT TERM EXIT
compress_prog_opt="$IMG_CLONE_CMP"
cmd_compress="$compress_prog_opt"
t_comp_suf="$(ocs-get-comp-suffix $compress_prog_opt)"
if [ -z "$t_comp_suf" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "Failed to decide the compression format of destination image!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
my_ocs_exit 1
fi
# Check if source and destination compression program is the same format. If it's the same, we can not go on, otherwise the source file will be overwritten, and it will be broken due to source and destination are the same one.
if [ "$img_comp_format" = "$t_comp_suf" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "Source compression format and destination format are the same: $img_comp_format"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
my_ocs_exit 1
else
echo "Now process the image file of partition: $img_file_prefix"
echo "Converting compression format: $img_comp_format -> $t_comp_suf by \"$compress_prog_opt\""
fi
img_info="$(mktemp /tmp/ocs_img_info.XXXXXXX)"
trap "[ -f "$img_info" ] && rm -f $img_info" HUP INT QUIT TERM EXIT
# Find the used space from partclone.info. Because for pv, -s option only accepts integer
# So we can not use 1.5 GB for example, instead we have to use 356732*4096=1461174272
# Partclone v0.2.68 http://partclone.org
# Unknown mode
# File system: EXTFS
# Device size: 5.0 GB = 1220352 Blocks
# Space in use: 1.5 GB = 356732 Blocks
# Free Space: 3.5 GB = 863620 Blocks
# Block size: 4096 Byte
( for img in $target_d/$img_file_prefix; do
cat $img
done
) | \
$unzip_stdin_cmd | partclone.info -s - &> $img_info
used_size="$(LC_ALL=C awk -F":" '/^Space in use/ {print $2}' $img_info | sed -r -e "s/^.*[[:space:]]=//g" -e "s/^[[:space:]]*//g" -e "s/[[:space:]]*Blocks//g")"
block_size="$(LC_ALL=C awk -F":" '/^Block size/ {print $2}' $img_info | sed -r -e "s/^[[:space:]]*//g" -e "s/Byte$//g")"
used_size_byte="$(LC_ALL=C echo "scale=0; $used_size * $block_size / 1" | bc -l)"
if [ -n "$used_size_byte" ]; then
# Option for pv. The -s option only accepts integer
used_size_opt="-s $used_size_byte"
fi
rm -f $img_info
#
( for img in $target_d/$img_file_prefix; do
cat $img
done
) | \
$unzip_stdin_cmd | \
(
case "$VOL_LIMIT" in
[1-9]*)
# $target_dir_fullpath/$t_img_file_prefix.${t_comp_suf}. is prefix, the last "." is necessary make the output file is like sda1.${fs_pre}-img.aa, sda1.${fs_pre}-img.ab. We do not add -d to make it like sda1.${fs_pre}-img.00, sda1.${fs_pre}-img.01, since it will confuse people that it looks like created by partimage (sda1.${fs_pre}-img.000, sda1.${fs_pre}-img.001)
pv -paet $used_size_opt | ${cmd_compress} | split -a $split_suf_len -b ${VOL_LIMIT}MB - $target_dir_fullpath/$t_img_file_prefix.${t_comp_suf}. 2> $split_error
;;
*)
pv -paet $used_size_opt | ${cmd_compress} | cat - > $target_dir_fullpath/$t_img_file_prefix.${t_comp_suf} 2> $split_error
;;
esac
)
rc="$?"
if [ "$rc" -eq 0 ]; then
# Change the partition or LV permission. For better security.
chmod 600 $target_dir_fullpath/$t_img_file_prefix.${t_comp_suf}* 2>/dev/null
for ifile in $target_d/$img_file_prefix; do
if [ -L "$ifile" ]; then
if [ "$verbose" = "yes" ]; then
echo "Remove the temp link image file(s) $ifile"
rmopt_v="-v"
fi
rm -f $rmopt_v $ifile
fi
done
fi
if [ -s "$split_error" ]; then
cat $split_error
fi
rm -f $split_error
return $rc
} # end of img_covert_to_diff_compression
#
do_partition_or_lv_img_convert() {
# part is like: /dev/hda1
local target_d="$1"
local img_file="$(to_filename $2)"
local rc hdtmp partition
image_name_="$(basename $target_d)"
# get the cat program: cat, zcat or bzcat
if is_partclone_image $target_d $img_file; then
# The saved image is from partclone
img_covert_to_diff_compression
rc=$?
if [ "$rc" -gt 0 -a "$ocs_batch_mode" != "on" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "This image conversion failed: $img_file" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "This image conversion is finished: $img_file" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
elif [ -f "$target_d/$img_file.dd-img" -o \
-n "$(ls $target_d/$img_file.dd-img.aa* 2>/dev/null)" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Image was saved by dd. No converting it. Copy the file later: $img_file" | tee --append ${OCS_LOGFILE}
sleep 1
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
rc=0
fi
echo $msg_delimiter_star_line
return $rc
} # end of do_partition_or_lv_img_convert
#
task_logv_convert() {
# mode is unicast or multicast
local tgt_parts="$1" # tgt_parts is like: hda1 hda2 hda5
local volg is_in_chosen_partition lvm_tmp rc rctlv
PV_PARSE_CONF="$target_dir_fullpath/lvm_vg_dev.list"
LOGV_PARSE_CONF="$target_dir_fullpath/lvm_logv.list"
if [ ! -f "$PV_PARSE_CONF" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "This LVM PV file NOT found: $PV_PARSE_CONF"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
fi
if [ ! -f "$LOGV_PARSE_CONF" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "This LVM LV file NOT found: $LOGV_PARSE_CONF"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
fi
#
while read lv fs; do
# Then we process the real data partition, only those in the chosen partitions
# Ex:
# /dev/vg3/lvol0 Linux rev 1.0 ext3 filesystem data (large files)
# Then lvol0 is belong to VG vg3
volg="$(echo "$lv" | awk -F"/" '{print $3}')"
# Find if the LV is in the chosen partition (via VG, we can determine that)
# EX: tgt_parts: hda1, hda3, hda5...
# vg3 /dev/hda3 nPMQQ0-D2yN-YRHL-9fBM-0cUm-vgcw-DCUTri
is_in_chosen_partition="no"
for ipt in $tgt_parts; do
if [ -n "$(grep -E "[[:space:]]+/dev/$ipt[[:space:]]+" $PV_PARSE_CONF | grep -E "\<$volg\>")" ]; then
# Found the chosen partitions is in the VG
is_in_chosen_partition="yes"
break
fi
done
# If not in the chosen partition, skip this, continue with the next.
[ "$is_in_chosen_partition" = "no" ] && continue
fn="$(echo $lv | sed -e "s|^/dev/||" -e "s|/|-|g")"
# create the swap if it's swap partition
case "$fs" in
*[Ss][Ww][Aa][Pp]*)
echo $msg_delimiter_star_line
echo "Found the swap partition $lv info:"
# read LABEL, UUID info for $partition if swappt-$(to_filename ${fn}).info exists
uuid_opt=""
label_opt=""
if [ -e "$target_dir_fullpath/swappt-$(to_filename ${fn}).info" ]; then
cat "$target_dir_fullpath/swappt-$(to_filename ${fn}).info"
echo "Swap partition info file found!"
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_this_swap_part_info_not_found: ${fn}"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
fi
echo $msg_delimiter_star_line
# then skip the rest.
continue;;
esac
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Checking the device LV $fn in the image \"$(basename $target_dir_fullpath)\"..."
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
do_partition_or_lv_img_convert $target_dir_fullpath $fn $lv
rc=$?
rctlv="$(($rctlv + $rc))"
done < $LOGV_PARSE_CONF
return $rctlv
} # end of task_logv_convert
#
task_convertimage() {
local target_dir="$1"
local parts_included target_dir_fullpath
local ptype rc rct part_is_lvm
local f_parent
#
target_parts="$(get_parts_list_from_img $ocsroot/$target_dir)"
# target_hd will be extract from $target_parts, maybe we will have one more
# find the target hd
# maybe we will have one more hd (like hda1, hda2, hdb1, hdb3 -> hda, hdb)
for ipart in $target_parts; do
thd_tmp="$(get_diskname $ipart)"
if [ -z "$target_hd" ]; then
target_hd="$thd_tmp"
elif [ -z "$(echo $target_hd | grep -Ew "$thd_tmp" 2>/dev/null)" ]; then
target_hd="$target_hd $thd_tmp"
fi
done
#
if [ -e "$ocsroot/$target_dir/disk" ]; then
image_type="disk"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_a_disk_image_saved_from_hd: $(get_disk_list_from_img $ocsroot/$target_dir)"
echo "$msg_the_part_image_to_be_convert: $target_parts"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
elif [ -e "$ocsroot/$target_dir/parts" ]; then
image_type="partition"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_a_part_image_saved_from_partitions: $(get_parts_list_from_img $ocsroot/$target_dir)"
echo "$msg_the_part_image_to_be_cheked: $target_parts"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_broken_image_dir"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
# Use $target_dir_fullpath as the absolute path, i.e. put leading $ocsroot, since from now on we need the full path dir to access them.
target_dir_fullpath="$ocsroot/$target_dir"
check_input_target_image "$target_dir_fullpath"
screen_not_blank
# if $create_part (global variable) is no, only some preparations
# in create_partition, it won't run sfdisk in fact.
# strip the leading spaces
target_parts="$(echo $target_parts | sed -e "s/^[[:space:]]*//g")"
echo $msg_delimiter_star_line
PV_PARSE_CONF="$target_dir_fullpath/lvm_vg_dev.list"
do_LVM_restore="no"
rct=0
for partition in $target_parts; do
# hda1 -> hda
hd_tmp="$(get_diskname $partition)"
part_is_lvm="no"
# If we partition is listed in lvm_vg_dev.list, process LVM later. //NOTE// LVM might use Id=83 instead of 8e, so we can not parse it based on Id.
if [ -e $PV_PARSE_CONF ]; then
for i in $(sed -e 's!^.*/dev/\([^[:space:]]\{3,\}\)[[:space:]]*.*$!\1!g' $PV_PARSE_CONF); do
if [ "$partition" = "$(get_master_dev_of_multipath $i)" ]; then
part_is_lvm="yes"
break
fi
done
fi
# If part_is_lvm is yes, we should skip the rest...
if [ "$part_is_lvm" = "yes" ]; then
do_LVM_restore="yes"
# This continue is to skip the rest of this partition do loop
continue
fi
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Converting the image of partition $partition in the image \"$target_dir\"..."
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
do_partition_or_lv_img_convert $target_dir_fullpath $partition
rc=$?
rct="$(($rct + $rc))"
done
# Check LVM
if [ "$do_LVM_restore" = "yes" ]; then
# LVM exists, check PV/VG/LV.
task_logv_convert "$target_parts"
rc=$?
rct="$(($rct + $rc))"
echo $msg_delimiter_star_line
fi
# If the above conversion run smoothly, then we can scan the symbolic link files, and copy them. This is especially for those dd-img and its related files.
if [ "$rct" -eq 0 ]; then
for i in $target_dir_fullpath/*; do
if [ -h "$i" ]; then
f_parent="$(LC_ALL=C stat -c "%N" $i | awk -F"->" '{print $2}' |\
sed -r -e "s/^[[:space:]]*//g" -e "s/\`//g" -e "s/'//g")"
rm -f $i
( cd $target_dir_fullpath
echo "Copying $f_parent..."
rsync -avP -L $f_parent .
)
rc=$?
rct="$(($rct + $rc))"
fi
done
# Since the converted image is not encrypted, we should remove ecryptfs.info
rm -f $target_dir_fullpath/ecryptfs.info
fi
if [ "$rct" -gt 0 ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_failed_to_convert_the_img_compression: $target_dir" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_this_incomplete_image_will_be_removed: $target_dir_fullpath"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
if [ "$ocs_batch_mode" != "on" ]; then
echo -n "$msg_press_enter_to_continue..."
read
fi
# Careful... Do not remove all the images...
if [ -n "$target_dir_fullpath" ]; then
if [ "$target_dir_fullpath" != "$ocsroot" ]; then
rm -fv $target_dir_fullpath/*
rmdir -v $target_dir_fullpath
fi
fi
echo "$msg_program_stop!"
my_ocs_exit 1
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_succeeded_convert_the_img_compression: $target_dir" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
} # end of task_convertimage
#
check_if_old_format_img() {
local target_dir="$1"
local parts_included target_dir_fullpath
local ptype rc rct
local img_f
target_dir_fullpath="$ocsroot/$target_dir"
target_parts="$(get_parts_list_from_img $ocsroot/$target_dir)"
# strip the leading spaces
target_parts="$(echo $target_parts | sed -e "s/^[[:space:]]*//g")"
echo $msg_delimiter_star_line
for partition in $target_parts; do
img_f="$(to_filename $partition)"
if [ -f "$target_dir_fullpath/$img_f.000" -o \
-n "$(ls $target_dir_fullpath/$img_f.aa* 2>/dev/null)" -o \
-f "$target_dir_fullpath/$img_f" ]; then
# The saved image is from partimage
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "This partition image was saved by partimage." | tee --append ${OCS_LOGFILE}
echo "This program does not support converting that format!" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
rc=1
if [ "$ocs_batch_mode" != "on" ]; then
echo -n "$msg_press_enter_to_continue..."
read
fi
echo "$msg_program_stop!"
my_ocs_exit 1
elif [ -f "$target_dir_fullpath/$img_f.ntfs-img" -o \
-n "$(ls $target_dir_fullpath/$img_f.ntfs-img.aa* 2>/dev/null)" ]; then
# The saved image is from ntfsclone
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "This partition image was saved by ntfsclone." | tee --append ${OCS_LOGFILE}
echo "This program does not support converting that format!" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
if [ "$ocs_batch_mode" != "on" ]; then
echo -n "$msg_press_enter_to_continue..."
read
fi
echo "$msg_program_stop!"
my_ocs_exit 1
fi
done
} # end of check_if_old_format_img
####################
### Main program ###
####################
ocs_file="$0"
ocs=`basename $ocs_file`
#
while [ $# -gt 0 ]; do
case "$1" in
-b|--batch) ocs_batch_mode="on"; shift;;
-or|--ocsroot)
# overwrite the ocsroot in drbl.conf
shift;
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
ocsroot="$1"
shift;
fi
[ -z "$ocsroot" ] && USAGE && exit 1
;;
-nogui|--nogui)
# -nogui is for backward compatable, better to use --nogui
nogui="on"
shift;;
-sc|--skip-check-restorable)
# Flag to check if the image is restorable
chk_img_restoreable="no"
shift;;
-v|--verbose) verbose="yes"; shift;;
-i|--image-size)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
VOL_LIMIT=$1
shift
fi
[ -z "$VOL_LIMIT" ] && USAGE && exit 1
;;
-z0|--no-compress) IMG_CLONE_CMP="cat"; shift;;
-z1|--gzip-compress)
if type pigz &>/dev/null; then
IMG_CLONE_CMP="pigz -c $extra_pigz_opt"
else
IMG_CLONE_CMP="gzip -c $extra_gzip_opt"
fi
shift;;
-z2|--bz2-compress)
if [ "$parallel_bzip2_prog" = "pbzip2" ] && type pbzip2 &>/dev/null; then
IMG_CLONE_CMP="pbzip2 -c $extra_pbzip2_opt"
elif [ "$parallel_bzip2_prog" = "lbzip2" ] && type lbzip2 &>/dev/null; then
IMG_CLONE_CMP="lbzip2 -c $extra_lbzip2_opt"
else
IMG_CLONE_CMP="bzip2 -c $extra_bzip2_opt"
fi
shift;;
-z3|--lzo-compress) IMG_CLONE_CMP="lzop -c $extra_lzop_opt"; shift;;
-z4|--lzma-compress) IMG_CLONE_CMP="lzma -c $extra_lzma_opt"; shift;;
-z5|--xz-compress)
if type pixz &>/dev/null; then
IMG_CLONE_CMP="pixz $extra_pixz_opt"
else
IMG_CLONE_CMP="xz -c $extra_xz_opt"
fi
shift;;
-z6|--lzip-compress)
if type plzip &>/dev/null; then
IMG_CLONE_CMP="plzip -c $extra_plzip_opt"
else
IMG_CLONE_CMP="lzip -c $extra_lzip_opt"
fi
shift;;
-z7|--lrzip-compress) IMG_CLONE_CMP="lrzip -q - $extra_lrzip_opt"; shift;;
-*) echo "${0}: ${1}: invalid option" >&2
USAGE >& 2
exit 2 ;;
*) break ;;
esac
done
#
if [ -z "$*" ]; then
mode="interactive"
else
ocs_src_img_name="$1"
shift
ocs_dest_img_name="$1"
fi
# Fedora Core 1 seems to use dumb for rc1, we have to force it use linux.
# otherwise setterm will complain.
[ -z "$TERM" -o "$TERM" = "dumb" ] && TERM="linux"
echo "Setting the TERM as $TERM"
export TERM="$TERM"
#
check_if_root
ask_and_load_lang_set
# check DIA
check_DIA_set_ESC $DIA
#
[ -z "$IMG_CLONE_CMP" ] && IMG_CLONE_CMP="$IMG_CLONE_CMP_def"
# imagedir is a variable which ask_user related function need
imagedir="$ocsroot"
[ -z "$ocs_src_img_name" ] && ocs_src_img_name="ask_user"
[ -z "$ocs_dest_img_name" ] && ocs_dest_img_name="ask_user"
# If it's interactive mode, use the interactive value.
# The VOL_LIMIT_prompt is preparted here, later we will use.
if [ "$ocs_src_img_name" = "ask_user" -o \
"$ocs_dest_img_name" = "ask_user" ]; then
VOL_LIMIT_prompt="$VOL_LIMIT_IN_INTERACTIVE"
else
VOL_LIMIT_prompt=$VOL_LIMIT_DEFAULT
fi
# Prepare the image to be converted
# 1st, check if "$ocs_dest_img_name" exist
if [ "$ocs_src_img_name" = "ask_user" ]; then
get_target_dir_name_when_converting_img
ocs_src_img_name="$target_dir"
fi
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_the_image_to_be_convert: $ocs_src_img_name"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
if [ -z "$IMG_CLONE_CMP" ]; then
choose_compress_format
fi
append_name="$(ocs-get-comp-suffix $IMG_CLONE_CMP)"
if [ "$ocs_dest_img_name" = "ask_user" ]; then
get_target_dir_name_when_saving ${ocs_src_img_name}-${append_name} # get $target_dir
ocs_dest_img_name="$target_dir"
fi
#
if [ -z "$VOL_LIMIT" ]; then
ask_image_volume_size
fi
# If VOL_LIMIT is too large, split won't work. Check and fix it if required.
check_and_fix_vol_limit_if_required
if [ "$mode" = "interactive" ]; then
ask_if_check_converted_img
else
if [ -z "$chk_img_restoreable" ]; then
chk_img_restoreable="$chk_img_restoreable_def"
fi
fi
ecryptfs_rc="1"
if is_ecryptfs_img $ocsroot/$ocs_src_img_name; then
# If it's encrypted image, we have to decrypt it.
ocs_sr_type="restore"
target_dir="$ocs_src_img_name"
# //NOTE// If encrypt_ocs_img="yes", after this step, ocsroot and target_dir will be changed
# The original ones will be kept as ocsroot_orig and target_dir_orig.
prepare_ecryptfs_mount_point_if_necessary
ecryptfs_rc="$?"
if [ "$ecryptfs_rc" -eq 0 ]; then
ocs_src_img_name="$target_dir"
ocs_tmp_img_opt="-or $ocsroot"
else
echo "$msg_program_stop"
my_ocs_exit 1
fi
fi
#
check_if_old_format_img "$ocs_src_img_name"
# Before creating the destination image, we have to set the correct ocsroot otherwise it's reset by prepare_ecryptfs_mount_point_if_necessary.
if [ "$ecryptfs_rc" -eq 0 ]; then
# The image to be processed is encrypted, and we have to let create-ocs-tmp-img create the image in the original image repository
ocsroot="$ocsroot_orig"
fi
# Use create-ocs-tmp-img to create a temp dir in image repository, then we will convert all link files to regular files.
create-ocs-tmp-img $ocs_tmp_img_opt -n -t $ocsroot "$ocs_src_img_name" "$ocs_dest_img_name"
task_convertimage "$ocs_dest_img_name"
#
if [ "$chk_img_restoreable" = "yes" ]; then
if [ "$nogui" = "on" ]; then
nogui_opt="-nogui"
fi
echo $msg_delimiter_star_line
echo "Checking the converted image..."
ocs-chkimg -b $nogui_opt $ocs_dest_img_name
rc_ocs="$?"
if [ "$rc_ocs" -eq 0 ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
echo "$msg_new_compression_format_image_created_successfully: $ocs_dest_img_name"
if [ "$ecryptfs_rc" -eq 0 ]; then
echo "$msg_converted_img_is_not_encrypted"
fi
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_failed_to_convert_new_compression_as_another_image: $ocs_dest_img_name"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
fi
my_ocs_exit $rc_ocs
|