Debian Codegraph @

scripts/sbin/check_drbl_setup_space

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Check if the harddrive space is enough for DRBL environment
5 # input: the client no
6 # output: $total_avail_space $drbl_need $common_root_space $per_node_space
7 # if space is enough, the return code is 0, if no, return code is 1
8
9 # Load DRBL setting and functions
10 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
11
12 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
13
14 check_if_root
15
16 #
17 usagescip-shell shell shell-project 0.0.0 usage().() {
18 echoscip-shell system . . echo. "Check if the space is enough to install DRBL"
19 echoscip-shell system . . echo. "Usage: `basenamescip-shell system . . basename. $0` [OPTION]"
20 echoscip-shell system . . echo. "Options:"
21 echoscip-shell system . . echo. "-v, --verbose: verbose mode."
22 echoscip-shell system . . echo. "-n, --client-no CLIENT_NO: The DRBL client number."
23 echoscip-shell system . . echo. "If space is enough for setup, nothing will be shown, and the return code is 0. If not enough space, return code is 1, and the output number are: total_avail_space drbl_need_space common_root_space per_node_space"
24 echoscip-shell system . . echo. "A estimation will be made by current necessary space multiplying ratio $buffer_ratio_for_client_space"
25 }
26 #
27 # main
28 while [scip-shell system . . `[`. $# -gt 0 ]; do
29 case "$1" in
30 -n|--client-no)
31 shift; client_no="$1"
32 shift
33 ;;
34 -v|--verbose)
35 shift; verbose="on"
36 ;;
37 -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2
38 usagescip-shell shell shell-project 0.0.0 usage(). >& 2
39 exit 2 ;;
40 *) break ;;
41 esac
42 done
43
44 [scip-shell system . . `[`. -z "$client_no" ] && usagescip-shell shell shell-project 0.0.0 usage(). && exit 1
45
46 # The extra space in front of /tftpboot is to exclude something like /mnt/tftpboot
47 tftpboot_space=$(LC_ALL=C dfscip-shell system . . df. --block-size 1M 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. -F" " '/ \/tftpboot/ {print $4}scip-shell filesystem . . `/ \/tftpboot/ {print $4}`.')
48 [scip-shell system . . `[`. -z "$tftpboot_space" ] && tftpboot_space=0
49 # we will overwrite the necessary directories in /tftpboot/, the space
50 # will be released, so add it to $total_avail_space
51 tftpboot_current_used=$(LC_ALL=C duscip-shell system . . du. -smc /tftpboot/scip-shell filesystem . . `/tftpboot/`. 2>/dev/nullscip-shell filesystem . . `/dev/null`. | cutscip-shell system . . cut. -f1 | tailscip-shell system . . tail. -n1)
52 [scip-shell system . . `[`. -z "$tftpboot_current_used" ] && tftpboot_current_used=0
53
54 # use $(NF-2) is safer than $4, because longer device name will use 2 lines like
55 # df -h /
56 # Filesystem Size Used Avail Use% Mounted on
57 # /dev/mapper/VolGroup00-LogVol00
58 # Then it's $3, not $3.
59 root_space=$(LC_ALL=C dfscip-shell system . . df. --block-size 1M /scip-shell filesystem . . `/`. 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. -F" " '/\/$/ { print $(NF-2)}scip-shell filesystem . . `/\/$/ { print $(NF-2)}`.')
60 [scip-shell system . . `[`. -z "$root_space" ] && root_space=0
61
62 total_avail_space=$(exprscip-shell system . . expr. $tftpboot_space + $root_space + $tftpboot_current_used)
63 common_root_space=$(duscip-shell system . . du. -smc $common_root_dir 2>/dev/nullscip-shell filesystem . . `/dev/null`. | cutscip-shell system . . cut. -f1 | tailscip-shell system . . tail. -n1)
64 [scip-shell system . . `[`. -z "$common_root_space" ] && common_root_space=0
65
66 # for /var/lib, we need to exclude the /var/lib/dpkg or /var/lib/rpm
67 per_node_space=$(duscip-shell system . . du. -smc /etcscip-shell filesystem . . `/etc`. /var/libscip-shell filesystem . . `/var/lib`. 2>/dev/nullscip-shell filesystem . . `/dev/null`. | cutscip-shell system . . cut. -f1 | tailscip-shell system . . tail. -n1)
68 # Exclude the dir assigned in varlib_NOT_2_be_copied_2_each_client
69 varlib_pkg_space_all=0
70 for iv in $varlib_NOT_2_be_copied_2_each_client; do
71 if [scip-shell system . . `[`. -d /var/lib/$iv ]; then
72 varlib_pkg_space=$(duscip-shell system . . du. -smc /var/lib/$iv 2>/dev/nullscip-shell filesystem . . `/dev/null`. | cutscip-shell system . . cut. -f1 | tailscip-shell system . . tail. -n1)
73 if [scip-shell system . . `[`. -n "$varlib_pkg_space" ]; then
74 varlib_pkg_space_all=$(( $varlib_pkg_space_all + $varlib_pkg_space))
75 fi
76 fi
77 done
78 per_node_space=$(($per_node_space - $varlib_pkg_space_all))
79 drbl_need=$(exprscip-shell system . . expr. $client_no "*" $per_node_space + $common_root_space)
80 drbl_need=$(echoscip-shell system . . echo. "scale=0; $drbl_need * $buffer_ratio_for_client_space" | bc -l)
81 # truncate the $drbl_need to be integer
82 drbl_need=$(echoscip-shell system . . echo. "$drbl_need / 1" | bc)
83 if [scip-shell system . . `[`. "$drbl_need" -gt "$total_avail_space" ]; then
84 if [scip-shell system . . `[`. "$verbose" = "on" ]; then
85 echoscip-shell system . . echo. "Warning!!! The system space maybe not enough for DRBL environment!!!"
86 echoscip-shell system . . echo. "Estimated necessary space for each DRBL client (MB): $DRBL_CLIENT_SPACE_PER_NODE"
87 echoscip-shell system . . echo. "Total DRBL clients: $client_no"
88 echoscip-shell system . . echo. "Available space (MB): $total_avail_space"
89 echoscip-shell system . . echo. "DRBL need space (MB): $drbl_need"
90 fi
91 echoscip-shell system . . echo. $total_avail_space $drbl_need $common_root_space $per_node_space
92 exit 1
93 fi
94 exit 0