File: ocs-gen-bt-slices

package info (click to toggle)
clonezilla 5.13.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,176 kB
  • sloc: sh: 41,198; perl: 193; python: 59; makefile: 26
file content (98 lines) | stat: -rwxr-xr-x 3,183 bytes parent folder | download | duplicates (4)
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
#!/bin/bash
# License: GPL 
# Author: Steven Shiau <steven _at_ clonezilla org>
# Description: Program to create the Clonezilla bittorrent slices files from existing Clonezilla image

#
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
#
USAGE() {
    echo "$ocs - To create the Clonezilla bittorrent slices files from existing Clonezilla image"
    echo "Usage:"
    echo "To run $ocs:"
    echo "$ocs [OPTION] IMAGE DEVICE"
    echo "IMAGE is the image dir name, not absolute path"
    echo "DEVICE is the device name, can be with or without /dev/, e.g, /dev/sda1 or sda1."
    echo "If \"DEVICE\" is not assigned, all the devices in the image will be processed."
    echo 
    echo "OPTION:"
    echo "-or, --ocsroot DIR Specify DIR (absolute path) as directory ocsroot (i.e. overwrite the ocsroot assigned in drbl.conf)"
    echo "If \"ask_user\" is used as IMAGE_NAME or no IMAGE_NAME is specified, a dialog menu will be shown."
    echo "Ex:"
    echo "To create the Clonezilla bittorrent slices files of sda1 and sda2 from the image \"my-image\", which is located in $ocsroot/my-image, run"
    echo "   $ocs my-image sda1 sda2"
    echo
} # end of USAGE

####################
### Main program ###
####################

ocs_file="$0"
ocs=`basename $ocs_file`
#
while [ $# -gt 0 ]; do
 case "$1" in
   -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
           ;;
   -*)     echo "${0}: ${1}: invalid option" >&2
           USAGE >& 2
           exit 2 ;;
   *)      break ;;
 esac
done

target_dir="$1"
shift
target_parts="$(strip_leading_dev $*)" # No matter the input is like /dev/sda or sda, format it as sda

force_TERM_as_linux_if_necessary

#
check_if_root
ask_and_load_lang_set
# check DIA
check_DIA_set_ESC $DIA

# imagedir is a variable which ask_user related function need
imagedir="$ocsroot"
[ -z "$ocs_chk_img_name" ] && ocs_chk_img_name="ask_user"

if [ -z "$target_dir" -o  "$target_dir" = "ask_user" ]; then
  get_target_dir_name_when_checking_img_restorable # output: target_dir
fi
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_the_image_to_be_convert: $target_dir"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
if [ -z "$target_parts" ]; then
  target_parts="$(get_parts_list_from_img $ocsroot/$target_dir)"
fi
check_input_target_image "$ocsroot/$target_dir"

if is_ecryptfs_img $ocsroot/$target_dir; then
  [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
  echo "$msg_convert_encrypted_img_not_supported"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "$msg_program_stop!"
  my_ocs_exit 1
fi

create_bittorrent_slices "$target_dir" "$target_parts"
rc=$?
my_ocs_exit $rc