/usr/sbin/prep-ocsroot 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 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 | #!/bin/bash
# License: GPL
# Author: Steven Shiau <steven _at_ nchc org tw>
# Description: Program to prepare Clonezilla live image home dir.
#
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
# Default we will check if $ocsroot is a mountpoint after the mount action is done.
chk_ocsroot_mountpont="yes"
ntfs_mount_warning="no"
# Ref: https://sourceforge.net/tracker/?func=detail&atid=671653&aid=2949613&group_id=115473
# For cifs, noatime and nodiratime won't be honored, but cifs won't exit with error. It just ignores nodiratime.
# For sshfs, nodiratime is not honored, and sshfs will exit with error.
# For nfs, both noatime and nodiratime are honored.
# Therefore we put noatime only, and add "nodiratime" for nfs, hfsplus and other fs.
def_mount_opt="noatime"
# Extra option for df when outputing the disk usage. For local device mounting, we add '-a' so that the bind status can be shown. For others, no extra option.
df_extra_opt=""
# 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
#
check_if_root
# functions
USAGE() {
echo "Usage:"
echo "Prepare the clonezilla image dir"
echo "$0 [OPTION]"
language_help_prompt_by_idx_no
dialog_like_prog_help_prompt
echo "-s, --skip-ocsroot-mountpoint-chk Skip checking if Clonezilla image $ocsroot is a mountpoint."
echo "-t, --ocsroot-resource-type TYPE Assign the Clonezilla image home type, available TYPE: local_dev, ssh_server, samba_server, nfs_server, enter_shell, skip"
echo "Ex. $0 -l en_US.UTF-8"
}
prepare_mnt_point_ocsroot() {
if mountpoint $ocsroot &>/dev/null; then
echo "Umounting the existing $ocsroot..."
umount $ocsroot
fi
echo "Preparing the mount point $ocsroot..."
[ -L "$ocsroot" ] && rm -f $ocsroot
[ ! -d "$ocsroot" ] && mkdir -p $ocsroot
if [ ! -d "$ocsroot" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$ocsroot is NOT a directory! Failed to create directory $ocsroot! No mount point for $ocsroot!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
exit 1
fi
} # end of prepare_mnt_point_ocsroot
#
get_existing_dir() {
# show existing dir so that user can choose then return chosen to file ANS_TMP
local wk_dir="$1"
local ANS_TMP="$2"
local tgt_file= ans_=
local ASK_DIRNAME=1
local TMP=`mktemp /tmp/ocs.XXXXXX`
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
numfiles=`ls $wk_dir 2> /dev/null | wc -l`
numfiles=`expr $numfiles + 0`
# list the previous saved images
# the list of images can be put in one page
filelist="/ $(rep_whspc_w_udrsc "$msg_top_directory_in_local_dev")"
numfiles=1
echo -n "Scanning dir $wk_dir."
for file in $wk_dir/*; do
echo -n "."
# Only directory ..., not file
[ ! -d "$file" ] && continue
# Exclude those special name dir, e.g. with space, or beginning with "-"
[ -n "$(echo $file | grep -E "[[:space:]]")" ] && continue
[ -n "$(echo "$(basename "$file")" | grep -E "^-+")" ] && continue
# Skip Clonezilla image dir
[ -e "$file/disk" -a -n "$(ls $file/*-pt.sf 2>/dev/null)" ] && continue
[ -e "$file/parts" -a -n "$(ls $file/*-pt.sf 2>/dev/null)" ] && continue
fileinfo="$(unalias ls 2>/dev/null; ls -ldh "$file" 2>/dev/null| awk '{ print $6"_"$7; }')"
filelist="$filelist $(basename "$file") $fileinfo"
numfiles=`expr $numfiles + 1`
done
echo " done!"
if [ $numfiles -gt 0 ]; then
if [ $numfiles -lt $MAX_DIALOG_HEIGHT ]; then
height="$numfiles"
else
height="$MAX_DIALOG_HEIGHT"
fi
while [ "$ASK_DIRNAME" -ne 0 ]; do
$DIA \
--backtitle "$msg_nchc_free_software_labs" \
--title "$msg_nchc_clonezilla" \
--menu "$msg_which_dir_as_clonezilla_img_home:" 0 $RESTORE_DIA_WIDTH \
$height $filelist 2> $TMP
tgt_file="$(cat $TMP)"
if [ -z "$tgt_file" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_filename!\n$msg_do_u_want_to_do_it_again!" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ASK_DIRNAME=1;;
1) # no is chosen
echo "$msg_program_stop!"
[ -f "$TMP" ] && rm -f $TMP
if mountpoint $local_dev_mntpt &>/dev/null; then
umount $local_dev_mntpt
fi
exit 1;;
esac
else
ASK_DIRNAME=0
fi
done
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "No disk image is found in $wk_dir.. Make sure you already saved an image! $msg_program_stop!!!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
exit 1
fi
[ -f "$TMP" ] && rm -f $TMP
# return the valule
echo $tgt_file > $ANS_TMP
} # end of get_existing_dir
do_mount_local_dev() {
local target_part part_fs # target_part is like hda1, sda1...
local local_dev_mntpt sel_dir
df_extra_opt="-a"
prepare_mnt_point_ocsroot
if [ "$ocs_prompt_mode" = "tui" ]; then
$DIA --title "$msg_nchc_free_software_labs" --clear \
--msgbox "$msg_prompt_for_insert_USB_dev_if_necessary" 0 0
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo -e "$msg_prompt_for_insert_USB_dev_if_necessary"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
if type screen 2>&1 > /dev/null; then
screen watch -c -n 3 ocs-scan-disk
fi
fi
# Force kernel to re-read the partition table
echo "Informing the OS of partition table changes..."
partprobe 2>/dev/null
echo "Mounting local dev as $ocsroot..."
ANS_TMP=`mktemp /tmp/ocs_ans.XXXXXX`
trap "[ -f "$ANS_TMP" ] && rm -f $ANS_TMP" HUP INT QUIT TERM EXIT
get_input_dev_name $ANS_TMP partition menu yes "$msg_device_to_mount_as_ocsroot_do_not_mount_target_dev\n$msg_linux_parts_MS_mapping"
# we have to remove " (comes with checklist in dialog) so that for loop
# will work (Specially for FC3/4...)
target_part="$(cat $ANS_TMP | tr -d \")"
[ -f "$ANS_TMP" ] && rm -f $ANS_TMP
[ -z "$target_part" ] && exit 1
check_input_partition $target_part
# check if $target_part is ntfs or others
part_fs="$(LANG=C ocs-get-part-info /dev/$target_part filesystem)"
echo "/dev/$target_part filesystem: $part_fs"
# If ocs_prep_ocsroot_ask_dir is not "no", we just mount the partition as $ocsroot. Otherwise it's a little confusing.
if [ "$ocs_prep_ocsroot_ask_dir" != "no" ]; then
local_dev_mntpt="/tmp/local-dev"
else
local_dev_mntpt="$ocsroot"
fi
mkdir -p $local_dev_mntpt
case "$part_fs" in
ntfs)
if [ "$ntfs_mount_warning" = "yes" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_warning_mount_ntfs_writable"
echo "$msg_are_u_sure_u_want_to_continue ?"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "[y/N] "
read continue_mount_ntfs_3g
case "$continue_mount_ntfs_3g" in
y|Y|[yY][eE][sS])
echo "$msg_ok_let_do_it"
;;
*)
echo "$msg_program_stop"
exit 1
;;
esac
fi
echo ntfs-3g /dev/$target_part $local_dev_mntpt -o $def_mount_opt
ntfs-3g /dev/$target_part $local_dev_mntpt -o $def_mount_opt
if ! mountpoint $local_dev_mntpt &>/dev/null; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Looks like $local_dev_mntpt is not mounted normally! Maybe the NTFS file system in /dev/$target_part was not unmounted normally. Do you want to try to mount it with option "-o force" ? ///NOTE/// This is a little dangerous!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "[y/N] "
read mount_ntfs_with_force
case "$mount_ntfs_with_force" in
y|Y|[yY][eE][sS])
echo "$msg_ok_let_do_it"
echo "Run ntfsfix on /dev/$target_part first..."
ntfsfix /dev/$target_part
echo "Run ntfs-3g /dev/$target_part $local_dev_mntpt -o force..."
ntfs-3g /dev/$target_part $local_dev_mntpt -o force
;;
esac
fi
;;
hfsplus)
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_warning_mount_hfsplus_writable"
echo "$msg_are_u_sure_u_want_to_continue ?"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "[y/N] "
read continue_mount_hfsplus
case "$continue_mount_hfsplus" in
y|Y|[yY][eE][sS])
echo "$msg_ok_let_do_it"
;;
*)
echo "$msg_program_stop"
exit 1
;;
esac
echo mount -t hfsplus -o force,$def_mount_opt,nodiratime /dev/$target_part $local_dev_mntpt
LC_ALL=C mount -t hfsplus -o force,$def_mount_opt,nodiratime /dev/$target_part $local_dev_mntpt
;;
*) echo mount -t auto -o $def_mount_opt,nodiratime /dev/$target_part $local_dev_mntpt
LC_ALL=C mount -t auto -o $def_mount_opt,nodiratime /dev/$target_part $local_dev_mntpt
;;
esac
# If ocs_prep_ocsroot_ask_dir is not "no", we just mount the partition as $ocsroot. Therefore there is no need to ask dir here.
#[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
if [ "$ocs_prep_ocsroot_ask_dir" != "no" ]; then
sel_dir="$(mktemp /tmp/sel_dir.XXXXXX)"
get_existing_dir $local_dev_mntpt $sel_dir
real_ocsroot="$(cat $sel_dir)"
mount --bind -o $def_mount_opt,nodiratime $local_dev_mntpt/$real_ocsroot $ocsroot
[ -f "$sel_dir" -a -n "$sel_dir" ] && rm -f $sel_dir
fi
[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
} # end of do_mount_local_dev
#
do_mount_iscsi_server(){
# Now this function only supports iSCSI without authentication
local TMP srv_default iscsi_srv iscsi_target iscsi_account iscsi_password iscsi_port iscsi_port_def iscsi_extra_opt
# Default settings
iscsi_port_def="3260"
iscsi_extra_opt=""
network_config_if_necessary
prepare_mnt_point_ocsroot
echo "Mounting remote directory on iSCSI server as $ocsroot..."
TMP="$(mktemp /tmp/iscsi_tmp.XXXXXX)"
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
# (1) iSCSI server IP address or FQDN
srv_default="$(LC_ALL=C route -n | grep "^0.0.0.0" | awk -F" " '{print $2}')"
while [ -z "$iscsi_srv" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount iSCSI" --inputbox "$msg_ip_address_or_FQDN_of_server:" \
0 0 $srv_default $DIA_ESC \
2> $TMP
iscsi_srv="$(cat $TMP)"
done
echo "iSCSI server is: $iscsi_srv"
# clean tmp file
echo "" > $TMP
# (1b) iscsi port
while [ -z "$iscsi_port" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount iSCSI" --inputbox "$msg_iscsi_port_on_server:" \
0 0 $iscsi_port_def $DIA_ESC \
2> $TMP
iscsi_port="$(cat $TMP)"
done
echo "iSCSI port on server is: $iscsi_port"
# clean tmp file
echo "" > $TMP
# (2a) account
while [ -z "$iscsi_account" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount iSCSI" --inputbox "$msg_account_in_server, $msg_ex john:" \
0 0 your_username $DIA_ESC \
2> $TMP
iscsi_account="$(cat $TMP)"
done
echo "iSCSI account in $iscsi_srv is: $iscsi_account"
# clean tmp file
echo "" > $TMP
# (2b) password
while [ -z "$iscsi_password" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount iSCSI" --inputbox "$msg_account_in_server:" \
0 0 your_password $DIA_ESC \
2> $TMP
iscsi_password="$(cat $TMP)"
done
echo "iSCSI password in $iscsi_srv is: $iscsi_password"
# clean tmp file
echo "" > $TMP
# get iscsi disk
iscsiadm -m discovery -t sendtargets -p $iscsi_srv | awk '{print $2}' | head -n 1 > $TMP
#iscsiadm -m discovery -t sendtargets -p $iscsi_srv | awk '{print $2}' > $TMP
iscsi_target="$(cat $TMP)"
# show discoveried targets
$DIA --backtitle "$msg_nchc_free_software_labs" --title "Mount iSCSI" \
--msgbox "The discover target(s) as following: $(cat $TMP)" 0 0
# $DIA --backtitle "$msg_nchc_free_software_labs" --title "Mount sshfs" \
# --msgbox "$msg_now_you_have_to_enter_passwd: $ssh_account@$ssh_srv:$sshfs_dir ($msg_confirm_ssh_server_might_be_necessary)" 0 0
# get iscsi disk
iscsiadm -m node -T $iscsi_target -p $iscsi_srv -l
iscsi_dev=$(dmesg |grep -A 1 IET | tail -n 1 | awk -F"[" '{print $2}' | awk -F"]" '{print $1}')
if [ -z "$iscsi_dev" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "iSCSI device was not found!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
exit 1
fi
# delay 2 seconds to waiting iscsi device appear
sleep 2
[ -f "$TMP" ] && rm -f $TMP
if [ -e /dev/$iscsi_dev ]; then
echo "Mounting iSCSI device by:"
echo "mount /dev/$iscsi_dev $ocsroot"
LC_ALL=C mount /dev/$iscsi_dev $ocsroot
[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "iSCSI device /dev/$iscsi_dev was not found!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
exit 1
fi
} # end of do_mount_iscsi_server
#
do_mount_ssh_server(){
local TMP srv_default ssh_srv ssh_account sshfs_dir ssh_port ssh_port_def sshfs_extra_opt ask_ ans_
# Default settings
ssh_port_def="22"
sshfs_extra_opt="-o nonempty,$def_mount_opt"
network_config_if_necessary
prepare_mnt_point_ocsroot
echo "Mounting remote directory on ssh server as $ocsroot..."
# sshfs ACCOUNT@SSH_SERVER:/ABSOLUTE_PATH $ocsroot
TMP=$(mktemp /tmp/sshfs_tmp.XXXXXX)
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
# (1) ssh server IP address or FQDN
srv_default="$(LC_ALL=C route -n | grep "^0.0.0.0" | awk -F" " '{print $2}')"
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount sshfs" --inputbox "$msg_ip_address_or_FQDN_of_server:" \
0 0 $srv_default $DIA_ESC \
2> $TMP
ssh_srv="$(cat $TMP)"
if [ -z "$ssh_srv" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_a_server\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "SSH server is: $ssh_srv"
# clean tmp file
echo "" > $TMP
# (1b) ssh port
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount sshfs" --inputbox "$msg_ssh_port_on_server:" \
0 0 $ssh_port_def $DIA_ESC \
2> $TMP
ssh_port="$(cat $TMP)"
if [ -z "$ssh_port" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_the_ssh_port\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "SSH port on server is: $ssh_port"
# clean tmp file
echo "" > $TMP
# (2) account
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount sshfs" --inputbox "$msg_account_in_server, $msg_ex root:" \
0 0 root $DIA_ESC \
2> $TMP
ssh_account="$(cat $TMP)"
if [ -z "$ssh_account" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_an_account\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "SSH account in $ssh_srv is: $ssh_account"
# clean tmp file
echo "" > $TMP
# (3) absolute path
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount sshfs" --inputbox "$msg_sshfs_dir_path, $msg_ex $ocsroot" \
0 0 $ocsroot $DIA_ESC \
2> $TMP
sshfs_dir="$(cat $TMP)"
if [ -z "$sshfs_dir" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_the_path_to_image\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "sshfs dir in $sshfs_dir is: $sshfs_dir"
$DIA --backtitle "$msg_nchc_free_software_labs" --title "Mount sshfs" \
--msgbox "$msg_now_you_have_to_enter_passwd: $ssh_account@$ssh_srv:$sshfs_dir ($msg_confirm_ssh_server_might_be_necessary)" 0 0
[ -f "$TMP" ] && rm -f $TMP
echo "Mounting sshfs by:"
echo "sshfs \"$ssh_account\"@$ssh_srv:\"$sshfs_dir/\" $ocsroot -p $ssh_port $sshfs_extra_opt"
LC_ALL=C sshfs "$ssh_account"@$ssh_srv:"$sshfs_dir/" $ocsroot -p $ssh_port $sshfs_extra_opt
[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
} # end of do_mount_ssh_server
#
do_mount_samba_server(){
local TMP srv_default smb_srv smb_account smb_sec_opt smb_sec_mode ask_ ans_
network_config_if_necessary
prepare_mnt_point_ocsroot
echo "Mounting remote directory on Samba server as $ocsroot..."
# mount -t cifs -o username=your_user_name //192.168.200.254/images /home/partimag
TMP="$(mktemp /tmp/cifs_tmp.XXXXXX)"
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
# (1) samba server IP address or FQDN
srv_default="$(LC_ALL=C route -n | grep "^0.0.0.0" | awk -F" " '{print $2}')"
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount Samba server" --inputbox "$msg_ip_address_or_FQDN_of_server" \
0 0 $srv_default $DIA_ESC \
2> $TMP
smb_srv="$(cat $TMP)"
if [ -z "$smb_srv" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_a_server\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "Samba server is: $smb_srv"
# clean tmp file
echo "" > $TMP
# (2) Domain
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount Samba server" --inputbox "$msg_smb_domain_in_server, $msg_if_no_smb_domain_skip_this" \
0 0 "" $DIA_ESC \
2> $TMP
smb_domain="$(cat $TMP)"
echo "Domain in $smb_srv is: $smb_domain"
# clean tmp file
echo "" > $TMP
# (3) Account
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount Samba server" --inputbox "$msg_account_in_server, $msg_ex administrator" \
0 0 administrator $DIA_ESC \
2> $TMP
smb_account="$(cat $TMP)"
if [ -z "$smb_account" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_an_account\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "Account in $smb_srv is: $smb_account"
# clean tmp file
echo "" > $TMP
# (4) Absolute path
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount Samba server" --inputbox "$msg_ocs_img_dir_path, $msg_ex /images" \
0 0 /images $DIA_ESC \
2> $TMP
smbfs_dir="$(cat $TMP)"
if [ -z "$smbfs_dir" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_the_path_to_image\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "The path in samba server is: $smbfs_dir"
# (5) Security mode, e.g. sec=ntlm or sec=ntlmv2
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Security mode" --menu "$msg_ocs_live_mount_smb_security_mod" \
0 0 0 $DIA_ESC \
"auto" "$msg_ocs_use_system_default" \
"ntlm" "$msg_ocs_use_ntlm_mode" \
2> $TMP
smb_sec_mode="$(cat $TMP)"
if [ -z "$smb_sec_mode" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_select_a_mode\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the security mode
ask_="false"
fi
done
case "$smb_sec_mode" in
"ntlm") smb_sec_opt=",sec=ntlm";;
*) smb_sec_mode=""
esac
# clean tmp file
echo "" > $TMP
# (6) Password
$DIA --backtitle "$msg_nchc_free_software_labs" --title "Mount Samba server" \
--msgbox "$msg_now_you_have_to_enter_passwd \"$smb_account\"@$smb_srv:$smbfs_dir" 0 0
[ -f "$TMP" ] && rm -f $TMP
if [ -n "$smb_domain" ]; then
smb_domain_opt=",domain=$smb_domain"
fi
# Remove the / in the beging if it exists, since we will add it later
smbfs_dir="$(echo $smbfs_dir | sed -e "s|^/||g")"
if [ -z "$(LC_ALL=C lsmod | grep -Ew "^cifs")" ]; then
# In case cifs is not loaded
modprobe cifs
fi
echo "Mounting samba server by:"
echo "mount -t cifs \"//${smb_srv}/${smbfs_dir}\" $ocsroot -o user=\"${smb_account}${smb_domain_opt}\"${smb_sec_opt}"
LC_ALL=C mount -t cifs "//${smb_srv}/${smbfs_dir}" $ocsroot -o user="${smb_account}${smb_domain_opt}"${smb_sec_opt}
[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
} # end of do_mount_samba_server
#
check_portmap_nfs_common_daemon() {
# This function is only for Clonezilla live (client environment), i.e. Debian. Since in DRBL environment, portmap and nfs-common should be running in client.
local pid pid_portmap pid_rpcbind pid_rpc_statd
# If not debian, do nothing. Since we are focusing this on Clonezilla live.
if ! is_boot_from_live; then
return 1
fi
if [ -z "$(LC_ALL=C lsmod | grep -Ew "^nfs")" ]; then
# An insurance to force to load nfs module. On Ubuntu karmic when mounting nfs4 server, failed due to nfs module not loaded.
# http://sourceforge.net/tracker/?func=detail&atid=671650&aid=2936441&group_id=115473
modprobe nfs
fi
pid_portmap="$(LC_ALL=C pidof portmap)"
pid_rpcbind="$(LC_ALL=C pidof rpcbind)"
if [ -z "$pid_portmap" -a -z "$pid_rpcbind" ]; then
echo "Service portmap or rpcbind is necesary for NFS client. Start it now..."
if [ -e "/etc/init.d/portmap" ]; then
/etc/init.d/portmap start
else
/etc/init.d/rpcbind start
fi
fi
# We assume nfs-common only runs rpc.statd (for NFS3), no rpc.lockd. This is true for modern kernel (>=2.4).
pid_rpc_statd="$(LC_ALL=C pidof rpc.statd)"
if [ -z "$pid_rpc_statd" ]; then
if [ -e /etc/init.d/nfs-common ]; then
echo "nfs-common service is necesary for NFS client. Start it now..."
/etc/init.d/nfs-common start
fi
fi
} # end of check_portmap_nfs_common_daemon
#
do_mount_nfs_server(){
local TMP srv_default nfs_srv nfs_dir nfs_ver img_dir_eg nfsvers_opt ask_ ans_
network_config_if_necessary
prepare_mnt_point_ocsroot
echo "Mounting remote directory on NFS (Ver 3) server as $ocsroot..."
# mount -t nfs 192.168.200.254:/work/exp /home/partimag
TMP="$(mktemp /tmp/nfs.XXXXXX)"
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
# (1) NFS version
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"NFS version" --menu "$msg_ocs_live_mount_nfs_ser_ver" \
0 0 0 $DIA_ESC \
"nfs" "NFS v2, v3" \
"nfs4" "NFS v4" \
2> $TMP
nfs_ver="$(cat $TMP)"
if [ -z "$nfs_ver" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_select_a_mode\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
# Decide the prompt image path example and the "nfsvers" option
case "$nfs_ver" in
nfs) img_dir_eg="/home/partimag/"
nfsvers_opt="nfsvers=3"
;;
nfs4) img_dir_eg="/partimag/"
nfsvers_opt=""
;;
esac
# (2) Nfs server IP address or FQDN
srv_default="$(LC_ALL=C route -n | grep "^0.0.0.0" | awk -F" " '{print $2}')"
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount NFS server" --inputbox "$msg_ip_address_or_FQDN_of_server:" \
0 0 $srv_default $DIA_ESC \
2> $TMP
nfs_srv="$(cat $TMP)"
if [ -z "$nfs_srv" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_a_server\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "NFS server is: $nfs_srv"
# (3) Absolute path
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount NFS server" --inputbox "$msg_ocs_img_dir_path, $msg_ex $img_dir_eg:" \
0 0 $img_dir_eg $DIA_ESC \
2> $TMP
nfs_dir="$(cat $TMP)"
if [ -z "$nfs_dir" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_the_path_to_image\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "The path in nfs server is: $nfs_dir"
[ -f "$TMP" ] && rm -f $TMP
canonical_hostname_prep $nfs_srv
check_portmap_nfs_common_daemon
echo "Mounting NFS server by:"
echo "mount -t $nfs_ver $nfs_srv:$nfs_dir $ocsroot -o $def_mount_opt,nodiratime,$nfsvers_opt"
LC_ALL=C mount -t $nfs_ver $nfs_srv:$nfs_dir $ocsroot -o $def_mount_opt,nodiratime,$nfsvers_opt
[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
if LC_ALL=C dpkg -L unfs3 &>/dev/null; then
# A workaround to make unfs3 service work well. It seems that after nfs-common is started, the rpcbind does not work with unfs3 which will be started later, therefore here we force to restart rpcbind
if [ -e "/etc/init.d/portmap" ]; then
/etc/init.d/portmap stop
sleep 1
/etc/init.d/portmap start
else
/etc/init.d/rpcbind stop
sleep 1
/etc/init.d/rpcbind start
fi
fi
} # end of do_mount_nfs_server
do_mount_ftp_server(){
# Use curlftpfs to mount ftp server
local TMP srv_default ftp_srv ftp_account ftpfs_dir
network_config_if_necessary
prepare_mnt_point_ocsroot
echo "Mounting remote directory on ftp server as $ocsroot..."
# ftpfs ACCOUNT@FTP_SERVER:/ABSOLUTE_PATH $ocsroot
TMP="$(mktemp /tmp/ftpfs_tmp.XXXXXX)"
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
# (1) ftp server IP address or FQDN
srv_default="$(LC_ALL=C route -n | grep "^0.0.0.0" | awk -F" " '{print $2}')"
while [ -z "$ftp_srv" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount ftpfs" --inputbox "$msg_ip_address_or_FQDN_of_server:" \
0 0 $srv_default $DIA_ESC \
2> $TMP
ftp_srv="$(cat $TMP)"
done
echo "FTP server is: $ftp_srv"
# clean tmp file
echo "" > $TMP
# (2) account
while [ -z "$ftp_account" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount ftpfs" --inputbox "$msg_account_in_server, $msg_ex john:" \
0 0 $DIA_ESC \
2> $TMP
ftp_account="$(cat $TMP)"
done
echo "FTP account in $ftp_srv is: $ftp_account"
# clean tmp file
echo "" > $TMP
# (3) absolute path
while [ -z "$ftpfs_dir" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount ftpfs" --inputbox "$msg_ftpfs_dir_path, $msg_ex /images" \
0 0 $DIA_ESC \
2> $TMP
# remove leading / since something like
# curlftpfs ftp://192.168.120.254//images /home/partimag -o direct_io,kernel_cache,nonempty,user=account
# will be denied. The error is like:
# Error connecting to ftp: Server denied you to change to the given directory
ftpfs_dir="$(cat $TMP | sed -e "s|^/*||g")"
done
echo "ftpfs dir in $ftpfs_dir is: $ftpfs_dir"
[ -f "$TMP" ] && rm -f $TMP
$DIA --backtitle "$msg_nchc_free_software_labs" --title "Mount FTP server" \
--msgbox "$msg_now_you_have_to_enter_passwd for the account $ftp_account on ftp://$ftp_srv/$ftpfs_dir" 0 0
echo "Mounting ftpfs by:"
echo "curlftpfs -o direct_io,kernel_cache,nonempty,user=$ftp_account ftp://$ftp_srv/$ftpfs_dir $ocsroot ..."
LC_ALL=C curlftpfs -o direct_io,kernel_cache,nonempty,user=$ftp_account ftp://$ftp_srv/$ftpfs_dir $ocsroot
[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
} # end of do_mount_ftp_server
#
do_mount_webdav_server(){
# ///NOTE/// Although davfs2 is not suitable for larger file transfer. The cache mechanism is the key problem (ref: https://sourceforge.net/forum/forum.php?thread_id=2248597&forum_id=82589), yet we have use some workaround to make it work. The key is in ocs-tune-conf-for-webdav.
local TMP srv_default url_default davfs_url ask_
local default_dav_path_prompt="webdav"
local rc webdav_tmp
network_config_if_necessary
prepare_mnt_point_ocsroot
echo "Mounting remote directory on webdav server as $ocsroot..."
# mount -t davfs -o noexec $WEBDAV_SERVER:/$PATH $ocsroot
TMP="$(mktemp /tmp/davfs_tmp.XXXXXX)"
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
# (1) davfs server url
srv_default="$(LC_ALL=C route -n | grep "^0.0.0.0" | awk -F" " '{print $2}')"
url_default="http://$srv_default/$default_dav_path_prompt"
ask_="true"
while [ "$ask_" = "true" ]; do
$DIA --backtitle "$msg_nchc_free_software_labs" --title \
"Mount WebDAV fs" --inputbox "$msg_url_of_davfs_server" \
0 0 $url_default $DIA_ESC \
2> $TMP
davfs_url="$(cat $TMP)"
if [ -z "$davfs_url" ]; then
$DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
--yesno "$msg_you_must_input_the_path_to_image\n$msg_do_u_want_to_do_it_again" 0 0
ans_="$?"
case "$ans_" in
0) # yes is chosen
ask_="true";;
1) # no is chosen
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
[ -f "$TMP" ] && rm -f $TMP
exit 1;;
esac
else
# Got the one we want
ask_="false"
fi
done
echo "WebDAV URL is: $davfs_url"
# clean tmp file
echo "" > $TMP
$DIA --backtitle "$msg_nchc_free_software_labs" --title "Mount WebDAV server" \
--msgbox "$msg_now_you_have_to_enter_passwd: $davfs_url" 0 0
ocs-tune-conf-for-webdav
echo "Mounting davfs by:"
echo "mount -t davfs -o noexec $davfs_url $ocsroot ..."
LC_ALL=C mount -t davfs -o noexec $davfs_url $ocsroot
rc=$?
# For webdev_server we do not use check_if_ocsroot_a_mountpoint function because the mounting status might be weird:
# //NOTE// Even check_if_ocsroot_a_mountpoint passes, it still might be false:
# root@vivid:~# mount -t davfs -o noexec http://192.168.120.254/webdav /home/partimag
# Please enter the username to authenticate with server
# http://192.168.120.254/webdav or hit enter for none.
# Username: dlfkalf
# Please enter the password to authenticate user dlfkalf with server
# http://192.168.120.254/webdav or hit enter for none.
# Password:
# /sbin/mount.davfs: connection timed out two times;
# trying one last time
# /sbin/mount.davfs: server temporarily unreachable;
# mounting anyway
# root@vivid:~# echo $?
# 0
# Therefore we have to use mktemp to test it.
if [ "$rc" -eq 0 ]; then
if [ "$chk_ocsroot_mountpont" = "yes" ]; then
webdav_tmp="$(mktemp $ocsroot/webdav_tmp.XXXXXX 2>/dev/null)"
if [ ! -e "$webdav_tmp" ]; then
# Failed. i.e read-only. We have to check if any clonezilla image exists. If it is, this is still OK because it can be used for restoring.
if check_if_any_image_exists; then
# OK for restoring even it's read-only
true
else
# No image exists, and read-only. Then this is false mounting point for webdav server.
umount $ocsroot 2>/dev/null
ocs_fail_mountpoint
fi
else
# Writable, OK for saving and restoring.
rm -f $webdav_tmp
ocs_success_mountpoint
fi
fi
else
umount $ocsroot 2>/dev/null
ocs_fail_mountpoint
fi
} # end of do_mount_webdav_server
#
do_mount_s3_server(){
# ///NOTE/// Although AWS S3 is not suitable for larger file transfer. The cache mechanism is the key problem (ref: https://sourceforge.net/forum/forum.php?thread_id=2248597&forum_id=82589), yet we have use some workaround to make it work. The key is in ocs-tune-conf-for-s3-swift.
network_config_if_necessary
prepare_mnt_point_ocsroot
ocs-tune-conf-for-s3-swift
echo "Calibrating time..."
ntpdate-debian
echo $msg_delimiter_star_line
echo "To mount AWS S3 as image repository, you have to"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "(1) Prepare the password file as this format:"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "accessKeyId:secretAccessKey (use this format if you have only one set of credentials)"
echo "bucketName:accessKeyId:secretAccessKey (If you have more than one set of credentials)"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "(2) Save it as file /root/.passwd-s3fs"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "If it's ready on remote manchine, you can run something like to copy it:"
echo "scp myaccount@myserver:/root/.passwd-s3fs /root/.passwd-s3fs"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "(3) Run command: chmod 600 /root/.passwd-s3fs"
echo "(4) Run command: s3fs bucket[:/path] mountpoint [options]"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo " E.g. s3fs my-ocs-img $ocsroot"
echo $msg_enter_another_shell_hint_wo_netcfg_prompt
echo -n "$msg_press_enter_to_continue..."
read
/bin/bash
[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
} # end of do_mount_s3_server
#
do_mount_swift_server(){
# ///NOTE/// Although OpenStack S3 is not suitable for larger file transfer. The cache mechanism is the key problem (ref: https://sourceforge.net/forum/forum.php?thread_id=2248597&forum_id=82589), yet we have use some workaround to make it work. The key is in ocs-tune-conf-for-s3-swift.
network_config_if_necessary
prepare_mnt_point_ocsroot
ocs-tune-conf-for-s3-swift
echo "Calibrating time..."
ntpdate-debian
echo $msg_delimiter_star_line
echo "To mount OpenStack Swift as image repository, you have to"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "(1) Prepare the password file like this format:"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "username=demo"
echo "api_key=643afce8b5187d40ba15e4827384fc5b"
echo "(for use with Rackspace)"
echo "username=demo"
echo "tenant=demo"
echo "password=supersecret"
echo "authurl=http://10.10.0.1:5000/v2.0"
echo "(for use with OpenStack, noting that 'tenant' should be the tenant name, rather than the ID)"
echo "If it's ready on remote manchine, you can run something like to copy it:"
echo "scp myaccount@myserver:/root/.cloudfuse /root/.cloudfuse"
echo "For more info, run: zless /usr/share/doc/cloudfuse/README.gz"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "(2) Save it as file /root/.cloudfuse"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "(3) Run command: chmod 600 /root/.cloudfuse"
echo "(4) Run command: cloudfuse -o You_Options... mountpoint/"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo " E.g. cloudfuse $ocsroot"
echo $msg_enter_another_shell_hint_wo_netcfg_prompt
echo -n "$msg_press_enter_to_continue..."
read
/bin/bash
[ "$chk_ocsroot_mountpont" = "yes" ] && check_if_ocsroot_a_mountpoint
} # end of do_mount_swift_server
#
find_ocsroot_dev_description(){
local ocsroot_parent filesystem writable rw_test_file
filesystem="$(get_dir_filesystem $ocsroot)"
rw_test_file="$(mktemp $ocsroot/rw_test.XXXXXX)"
rc=$?
if [ "$rc" -eq 0 ]; then
writable="yes"
else
writable="no"
fi
[ -f "$rw_test_file" ] && rm -f $rw_test_file
case "$filesystem" in
tmpfs) livemedia_des="$msg_writable_dev_ramdisk" ;;
nfs|smbfs|cifs) livemedia_des="$msg_writable_fs_ex_nfs_smbfs" ;;
rootfs)
# This is special case in Debian Live.
# Check if / is using unionfs and tmpfs. In Debian Live, it's like:
# tmpfs /cow tmpfs rw 0 0
# unionfs / unionfs rw,dirs=/cow=rw:/filesystem.squashfs=ro,debug=4294967295,delete=whiteout 0 0
if [ -n "$(grep -E "^tmpfs /cow" /proc/mounts)" -a \
-n "$(grep -E "^unionfs / unionfs rw,dirs=/cow=rw:" /proc/mounts)" ]; then
livemedia_des="$msg_writable_dev_ramdisk"
fi
;;
aufs|overlayfs|overlay)
# This is special case in Ubuntu Live or Debian Lenny live.
# /proc/mounts is like:
# aufs on / type aufs (rw)
livemedia_des="$msg_writable_dev_ramdisk"
;;
fuse)
# Fuse... maybe sshfs or ftpfs (not on yet)
if [ "$writable" = "yes" ]; then
livemedia_des="$msg_writable_dev_fuse"
else
livemedia_des="$msg_readonly_dev_fuse"
fi
;;
*)
# not RAM disk,
if [ "$writable" = "yes" ]; then
livemedia_des="$msg_writable_dev_ex_usb_stick"
else
livemedia_des="$msg_readonly_dev_ex_CD"
fi
;;
esac
[ -z "$livemedia_des" ] && livemedia_des="$msg_unknown"
} # end of find_ocsroot_dev_description
#
webdav_ocsroot_dia_des() {
webdav_ocsroot_msg_1="webdav_server"
webdav_ocsroot_msg_2="$(rep_whspc_w_udrsc "$msg_mount_webdav_server")"
}
#
s3_ocsroot_dia_des() {
s3_ocsroot_msg_1="s3_server"
s3_ocsroot_msg_2="$(rep_whspc_w_udrsc "$msg_mount_S3_server")"
}
#
swift_ocsroot_dia_des() {
swift_ocsroot_msg_1="swift_server"
swift_ocsroot_msg_2="$(rep_whspc_w_udrsc "$msg_mount_swift_server")"
}
#
get_ocsroot_resource() {
local default_menu
find_ocsroot_dev_description
if is_drbl_clonezilla_live_env; then
webdav_ocsroot_dia_des
s3_ocsroot_dia_des
swift_ocsroot_dia_des
fi
local TMP
#
if [ -z "$ocsroot_src" ]; then
# If $ocsroot is a mount point, then default in "skip", otherwise default in "local_dev"
if mountpoint $ocsroot >/dev/null 2>&1; then
default_menu="skip"
else
default_menu="local_dev"
fi
TMP=$(mktemp /tmp/ocsrootmenu.XXXXXX)
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
$DIA --backtitle "$msg_nchc_free_software_labs" --default-item "$default_menu" --title \
"$msg_mount_ocsroot_img_hint_short_des" --menu "$msg_mount_ocsroo_img_hint_long_des\n$msg_choose_mode:" \
0 0 0 $DIA_ESC \
"local_dev" "$msg_mount_local_dev" \
"ssh_server" "$msg_mount_sshfs" \
"samba_server" "$msg_mount_smbfs" \
"nfs_server" "$msg_mount_nfs" \
$webdav_ocsroot_msg_1 $webdav_ocsroot_msg_2 \
$s3_ocsroot_msg_1 $s3_ocsroot_msg_2 \
$swift_ocsroot_msg_1 $swift_ocsroot_msg_2 \
"enter_shell" "$msg_enter_cml. $msg_do_it_manually" \
"skip" "$msg_skip_this_use_existing_ocsroot ($livemedia_des)" \
2> $TMP
# Since curlftpfs is not stable with partimage/ntfsclone, skip that now. We will turn it on when it's stable.
#"ftp_server" "$msg_mount_ftpfs ($msg_experimental, $msg_not_stable)" \
# Since iSCSI is not ready yet. comment this:
#"iscsi_server" "msg_mount_iscsi_server" \
ocsroot_src="$(cat $TMP)"
echo "ocsroot device is $ocsroot_src"
[ -f "$TMP" ] && rm -f $TMP
fi
case "$ocsroot_src" in
"local_dev"|"ssh_server"|"samba_server"|"nfs_server"|"webdav_server"|"s3_server"|"swift_server"|"enter_shell"|"skip")
true;;
*)
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "\"$ocsroot_src\" is an unknown or unsupported type! You have to specify a correct ocsroot_src (local_dev, ssh_server, samba_server, nfs_server, webdav_server, enter_shell, or skip)"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
exit 1
;;
esac
} # end of get_ocsroot_resource
#
while [ $# -gt 0 ]; do
case "$1" in
-l|--language)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
specified_lang="$1"
shift
fi
[ -z "$specified_lang" ] && USAGE && exit 1
;;
-t|--ocsroot-resource-type)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
ocsroot_src="$1"
shift
fi
[ -z "$ocsroot_src" ] && USAGE && exit 1
;;
-s|--skip-ocsroot-mountpoint-chk) chk_ocsroot_mountpont="no"; shift;;
-d0|--dialog) DIA="dialog"; shift;;
-d1|--Xdialog) DIA="Xdialog"; shift;;
-d2|--whiptail) DIA="whiptail"; shift;;
-d3|--gdialog) DIA="gdialog"; shift;;
-d4|--kdialog) DIA="kdialog"; shift;;
-*) echo "${0}: ${1}: invalid option" >&2
USAGE >& 2
exit 2 ;;
*) break ;;
esac
done
#
ask_and_load_lang_set $specified_lang
# check DIA
check_DIA_set_ESC $DIA
##############
#### main ####
##############
#
if [ -z "$ocsroot_src" ]; then
get_ocsroot_resource
fi
#
case "$ocsroot_src" in
local_dev) do_mount_local_dev;;
iscsi_server) do_mount_iscsi_server;;
ssh_server) do_mount_ssh_server;;
samba_server) do_mount_samba_server;;
nfs_server) do_mount_nfs_server;;
ftp_server) do_mount_ftp_server;;
webdav_server) do_mount_webdav_server;;
s3_server) do_mount_s3_server;;
swift_server) do_mount_swift_server;;
enter_shell)
echo $msg_enter_another_shell_hint_with_netcfg_prompt
echo -n "$msg_press_enter_to_continue..."
read
/bin/bash
;;
skip)
echo "$msg_existing_setting_is:"
echo $msg_delimiter_star_line
df -ah
echo $msg_delimiter_star_line
echo -n "$msg_press_enter_to_continue..."
read
;;
*)
echo "Unknown type of Clonezilla image home type!"
echo "$msg_program_stop!"
exit 1
;;
esac
echo "done!"
exit 0
|