| 1 | #!/bin/bash |
| 2 | # Steven Shiau <[email protected]> |
| 3 | # License: GPL |
| 4 | # Script to setup DRBL server for the impatient. |
| 5 | |
| 6 | # Source function library. |
| 7 | [ -e /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions |
| 8 | |
| 9 | # |
| 10 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 11 | |
| 12 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 13 | |
| 14 | # Settings |
| 15 | accept_one_nic="no" |
| 16 | run_4impatient="" |
| 17 | limit_pxe_drbl_client="no" |
| 18 | |
| 19 | # |
| 20 | # usage |
| 21 | USAGE() { |
| 22 | echo "Usage:" |
| 23 | echo "$0 [Option]" |
| 24 | echo "Option:" |
| 25 | echo "-a, --unstable [y/n]: Use packages in unstable branch or not (Only works for RH-like distribution)." |
| 26 | echo "-b, --batch: Run $0 in batch mode (non-attended mode)." |
| 27 | echo "-e, --accept-one-nic Accept to run DRBL service in only one network card. ///NOTE/// This might mess up your network environment especially if there is an exi sting DHCP service in your network environment." |
| 28 | echo "-c, --live-client-branch [0|1|2|3] Assign the Clonezilla live release branch to be used, 0 is stable branch (Debian-based), 1 is testing branch (Debian-based), 2 is alternative stable branch (Ubuntu-based), 3 is alternative testing branch (Ubuntu-based). This option should be used when -z|--clonezilla-mode = 3" |
| 29 | echo "-p, --port-client-no NO The client number NO in each NIC port." |
| 30 | echo "-k, --client-archi [0/1/2]: Set the client's CPU arch, 0 for i386, 1 for i586, 2 for same level with DRBL server (for x86-64, use 2). This option is for the DRBL client is NFS based, i.e. all files are NFS mounted from server. It's different from the option '-u', which is only for clonezilla mode." |
| 31 | echo "-r, --drbl-mode [0|1|2] Assign DRBL mode (0: Full DRBL mode, 1: DRBL SSI mode, 2: Do NOT provide diskless Linux service to clients). Default value is 0.". |
| 32 | echo "-t, --testing [y/n]: Use packages in testing branch or not (Only works for RH-like distribution)." |
| 33 | echo "-u, --live-client-cpu-mode [0|1|2] Assign the CPU mode for client when doing Clonezilla job with Clonezilla live (0: i586, 1: i686, 2: amd64). This option should be used with -z|--clonezilla-mode = 3". |
| 34 | echo "-x, --limit-pxe-drbl-client Force the DHCP service managed by DRBL will only allow PXE or DRBL clients to lease IP address. By default all the clients can lease IP address. //NOTE// If you want to use Clonezilla live as the OS of clients when running Clonezilla job, do _NOT_ use this option. Otherwise your client won't be able to mount the root file system." |
| 35 | echo "-z, --clonezilla-mode [0|1|2|3] Assign Clonezilla mode (0: Full DRBL mode, 1: Clonezilla box mode, 2: Do NOT provide clonezilla service to clients, 3: Use Clonezilla live as the OS of clients). Default value is 0." |
| 36 | echo |
| 37 | echo "Example:" |
| 38 | echo " To create a Clonezilla server, using i686 Clonezilla live as the OS of clients, each network card will provide Clonezilla service to 40 clients:" |
| 39 | echo " $0 -p 40 -r 1 -z 3 -u 1" |
| 40 | } # end of USAGE |
| 41 | # |
| 42 | do_detail_mode_prompt() { |
| 43 | echo "$msg_delimiter_star_line" |
| 44 | echo "$msg_run_step_by_step: " |
| 45 | echo "(a):\"$DRBL_SCRIPT_PATH/sbin/drblsrv -i\" " |
| 46 | echo "(b):\"$DRBL_SCRIPT_PATH/sbin/drblpush -i\" " |
| 47 | } # end of do_detail_mode_prompt |
| 48 | # |
| 49 | do_imp_mode_prompt() { |
| 50 | if [ -z "$run_4impatient" ]; then |
| 51 | echo "$msg_delimiter_star_line" |
| 52 | echo "$msg_run_drbl4imp" |
| 53 | echo -n "$msg_press_enter_to_continue" |
| 54 | read |
| 55 | fi |
| 56 | [ -n "$verbose" ] && echo "Running drblsrv -i $client_archi_ans_opt $testing_opt $unstable_opt" |
| 57 | yes "" | drblsrv -i $client_archi_ans_opt $testing_opt $unstable_opt |
| 58 | RC=$? |
| 59 | if [ $RC -gt 0 ]; then |
| 60 | [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 61 | echo "Someting went wrong with drblsrv! Program terminted!!!" |
| 62 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 63 | exit 1 |
| 64 | fi |
| 65 | [ -n "$verbose" ] && echo "Running drblpush -i --not-add-start-drbl-srvi $accept_one_nic_opt $port_client_no_opt $drbl_mode_opt $clonezilla_mode_opt $live_client_branch_opt $live_client_cpu_mode_opt" |
| 66 | yes "" | drblpush -i --not-add-start-drbl-srvi $accept_one_nic_opt $port_client_no_opt $drbl_mode_opt $clonezilla_mode_opt $live_client_branch_opt $live_client_cpu_mode_opt |
| 67 | if [ "$limit_pxe_drbl_client" = "yes" ]; then |
| 68 | # modify dhcpd.conf, provide IP address to PXE/Etherboot/DRBL client only |
| 69 | echo "Modifying dhcpd.conf, now only PXE/Etherboot/DRBL client can lease IP address from this server..." |
| 70 | perl -pi -e 's/^([[:space:]]*)#[[:space:]]*(allow members of "DRBL-Client";)/$1$2/g' $DHCPDCONF_DIR/dhcpd.conf |
| 71 | else |
| 72 | echo "Modifying dhcpd.conf, now ANY client, not only PXE/Etherboot/DRBL client, can lease IP address from this server..." |
| 73 | perl -pi -e 's/^([[:space:]]*)#*[[:space:]]*(allow members of "DRBL-Client";)/$1#$2/g' $DHCPDCONF_DIR/dhcpd.conf |
| 74 | fi |
| 75 | echo "Start all DRBL related services by running 'drbl-all-service start'..." |
| 76 | drbl-all-service start |
| 77 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 78 | echo "$msg_all_set_you_can_turn_on_clients" |
| 79 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 80 | } # end of do_imp_mode_prompt |
| 81 | |
| 82 | # |
| 83 | check_if_root |
| 84 | |
| 85 | # main |
| 86 | while [ $# -gt 0 ]; do |
| 87 | case "$1" in |
| 88 | -a|--unstable) |
| 89 | shift |
| 90 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 91 | # skip the -xx option, in case |
| 92 | drbl_unstable_answer="$1" |
| 93 | shift |
| 94 | fi |
| 95 | [ -z "$drbl_unstable_answer" ] && USAGE && exit 1 |
| 96 | ;; |
| 97 | -l|--language) |
| 98 | shift |
| 99 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 100 | # skip the -xx option, in case |
| 101 | specified_lang="$1" |
| 102 | shift |
| 103 | fi |
| 104 | [ -z "$specified_lang" ] && USAGE && exit 1 |
| 105 | ;; |
| 106 | -b|--batch) |
| 107 | shift; run_4impatient="yes" ;; |
| 108 | -c|--live-client-branch) |
| 109 | shift |
| 110 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 111 | # skip the -xx option, in case |
| 112 | live_client_branch="$1" |
| 113 | shift |
| 114 | fi |
| 115 | [ -z "$live_client_branch" ] && USAGE && exit 1 |
| 116 | ;; |
| 117 | -e|--accept-one-nic) |
| 118 | shift; accept_one_nic="yes" ;; |
| 119 | -x|--limit-pxe-drbl-client) |
| 120 | shift; limit_pxe_drbl_client="yes" ;; |
| 121 | -k|--client-archi) |
| 122 | shift |
| 123 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 124 | # skip the -xx option, in case |
| 125 | client_archi_ans="$1" |
| 126 | shift |
| 127 | fi |
| 128 | [ -z "$client_archi_ans" ] && USAGE && exit 1 |
| 129 | ;; |
| 130 | -t|--testing) |
| 131 | shift |
| 132 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 133 | # skip the -xx option, in case |
| 134 | drbl_test_answer="$1" |
| 135 | shift |
| 136 | fi |
| 137 | [ -z "$drbl_test_answer" ] && USAGE && exit 1 |
| 138 | ;; |
| 139 | -r|--drbl-mode) |
| 140 | shift |
| 141 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 142 | # skip the -xx option, in case |
| 143 | drbl_mode="$1" |
| 144 | shift |
| 145 | fi |
| 146 | [ -z "$drbl_mode" ] && USAGE && exit 1 |
| 147 | ;; |
| 148 | -p|--port-client-no) |
| 149 | shift |
| 150 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 151 | # skip the -xx option, in case |
| 152 | assign_port_client_no="$1" |
| 153 | shift |
| 154 | fi |
| 155 | [ -z "$assign_port_client_no" ] && USAGE && exit 1 |
| 156 | ;; |
| 157 | -u|--live-client-cpu-mode) |
| 158 | shift |
| 159 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 160 | # skip the -xx option, in case |
| 161 | live_client_cpu_mode="$1" |
| 162 | shift |
| 163 | fi |
| 164 | [ -z "$live_client_cpu_mode" ] && USAGE && exit 1 |
| 165 | ;; |
| 166 | -z|--clonezilla-mode) |
| 167 | shift |
| 168 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 169 | # skip the -xx option, in case |
| 170 | clonezilla_mode="$1" |
| 171 | shift |
| 172 | fi |
| 173 | [ -z "$clonezilla_mode" ] && USAGE && exit 1 |
| 174 | ;; |
| 175 | -v|--verbose) shift; verbose="on" ;; |
| 176 | *) |
| 177 | USAGE |
| 178 | exit 1 |
| 179 | esac |
| 180 | done |
| 181 | |
| 182 | # |
| 183 | ask_and_load_lang_set $specified_lang |
| 184 | |
| 185 | # Put the options if assigned. |
| 186 | [ -n "$assign_port_client_no" ] && port_client_no_opt="-p $assign_port_client_no" |
| 187 | [ -n "$drbl_test_answer" ] && testing_opt="-t $drbl_test_answer" |
| 188 | [ -n "$drbl_unstable_answer" ] && unstable_opt="-a $drbl_unstable_answer" |
| 189 | [ -n "$drbl_mode" ] && drbl_mode_opt="-r $drbl_mode" |
| 190 | [ -n "$clonezilla_mode" ] && clonezilla_mode_opt="-z $clonezilla_mode" |
| 191 | [ -n "$client_archi_ans" ] && client_archi_ans_opt="-k $client_archi_ans" |
| 192 | [ -n "$accept_one_nic" ] && accept_one_nic_opt="--accept-one-nic" |
| 193 | [ -n "$live_client_cpu_mode" ] && live_client_cpu_mode_opt="-u $live_client_cpu_mode" |
| 194 | [ -n "$live_client_branch" ] && live_client_branch_opt="-t $live_client_branch" |
| 195 | |
| 196 | # |
| 197 | if [ -z "$run_4impatient" ]; then |
| 198 | echo "$msg_delimiter_star_line" |
| 199 | echo "$msg_are_you_sure_run_impatient" |
| 200 | echo -n "[Y/n] " |
| 201 | read run_4impatient |
| 202 | fi |
| 203 | |
| 204 | case "$run_4impatient" in |
| 205 | n|N|[nN][oO]) do_detail_mode_prompt ;; |
| 206 | *) do_imp_mode_prompt ;; |
| 207 | esac |