Debian Codegraph @

sbin/drblpush

raw
1 #!/usr/bin/perl -X
2 #
3 # Copyright (C) 2002-2012 by NCHC, Steven Shiau, K. L. Huang, and Ceasar Sun
4 # (steven _at nchc org tw, klhaung _at_ gmail com, ceasar _at_ nchc org tw)
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #
20 # Version 0.1, by K. L. Huang, klhaung _at_ gmail com, especially for Debian
21 # Modified by Steven Shiau, steven _at_ clonezilla org DRBL for Redhat
22
23 # setting
24 # timed login to GDM default time (seconds)
25 our $TIMED_GDM_TIME_DEFAULT="30";
26
27 # Swap size for client to open
28 our $MAXSWAPSIZE_DEFAULT="128";
29
30 # default autologin or timed login account password length
31 our $ACCOUNT_PASSWD_LENGTH_DEFAULT="8";
32
33 # default client no connected to some ethernet port
34 our $DEFAULT_CLIENT_NO_EACH_PORT="12";
35 # $assign_client_no_each_port is assign by -p or --port_client_no
36 our $assign_client_no_each_port;
37
38 # default boot prompt timeout for PXE client
39 our $DEFAULT_CLIENT_SYSTEM_BOOT_TIMEOUT="70";
40
41 #
42 our $DEFAULT_NISDOMAINNAME="penguinzilla";
43 our $DEFAULT_DOMAINNAME="drbl.org";
44
45 # flag to turn on/off NAT service in drbl server
46 our $drbl_server_as_NAT_server;
47
48 # This parameters are defined in drbl.conf or environment variables (e.g. DRBL_SCRIPT_PATH).
49 our $DRBL_SCRIPT_PATH;
50 our $drbl_setup_path;
51 our $drbl_syscfg;
52 # file name to record the auto login ID and passwd
53 our $AUTO_LOGIN_ID_PASSWD;
54 # file to record the IP and hostname for clients
55 our $IP_HOST_TABLE;
56 our $CLIENT_IP_HOSTNAME_LIST;
57 our $drblroot;
58 our $drbl_common_root;
59 our $query_pkglist_cmd;
60 our $DHCPD_DEFAULT_LEASE_TIME;
61 our $DHCPD_MAX_LEASE_TIME;
62 our $pxecfg_pd;
63
64 # First we need to get DRBL_SCRIPT_PATH.
65 chomp($DRBL_SCRIPT_PATH=`LC_ALL=C get-drbl-conf-param DRBL_SCRIPT_PATH`);
66 $ENV{'PATH'} = "$ENV{'PATH'}:$DRBL_SCRIPT_PATH/sbin:$DRBL_SCRIPT_PATH/bin:";
67
68 # Get them from drbl.conf
69 chomp($drbl_setup_path=`LC_ALL=C get-drbl-conf-param drbl_setup_path`);
70 chomp($drbl_syscfg=`LC_ALL=C get-drbl-conf-param drbl_syscfg`);
71 chomp($AUTO_LOGIN_ID_PASSWD=`LC_ALL=C get-drbl-conf-param AUTO_LOGIN_ID_PASSWD`);
72 # We use $CLIENT_IP_HOSTNAME_LIST (IP_HOST_TABLE) as the temp file in drblpush working dir.
73 chomp($IP_HOST_TABLE=`LC_ALL=C get-drbl-conf-param IP_HOST_TABLE`);
74 chomp($CLIENT_IP_HOSTNAME_LIST=`LC_ALL=C basename $IP_HOST_TABLE`);
75 chomp($drblroot=`LC_ALL=C get-drbl-conf-param drblroot`);
76 chomp($drbl_common_root=`LC_ALL=C get-drbl-conf-param drbl_common_root`);
77 chomp($query_pkglist_cmd=`LC_ALL=C get-drbl-conf-param query_pkglist_cmd`);
78 chomp($DHCPD_DEFAULT_LEASE_TIME=`LC_ALL=C get-drbl-conf-param DHCPD_DEFAULT_LEASE_TIME`);
79 chomp($DHCPD_MAX_LEASE_TIME=`LC_ALL=C get-drbl-conf-param DHCPD_MAX_LEASE_TIME`);
80 chomp($pxecfg_pd=`LC_ALL=C get-drbl-conf-param pxecfg_pd`);
81 chomp($ocs_img_repo_dir_default=`LC_ALL=C get-drbl-conf-param ocsroot`);
82
83 # the created config filename
84 our $DRBLPUSH_CONF="drblpush.conf";
85 # file to record the hosts
86 our $hosts_list="hosts_list.drbl";
87 # file to record the public IP for clients
88 our $public_ip_list="public_ip.drbl";
89 our @ip_sys_prefix;
90 our @ip_sys;
91 our $public_ip_port;
92 our $public_ip_addr;
93 # $pub_port_NAT is when there is no public IP in this drbl server, one of those
94 # private IPs which is connected to NAT server.
95 our $pub_port_NAT;
96
97 our $purge_client;
98 our $keep_client;
99 our $client_startup_mode;
100 # DRBL SSI (Single System Image) MODE: clients use the tarball template in $drbl_common_root/drbl_ssi for etc, var. There is a program "drbl-ssi-client-prepare" will be run in init.drbl to modify the necessary config of etc when client boots.
101 # Clonezilla box mode = DRBL SSI mode + runlevel 1 in client
102 our $drbl_mode;
103 our $drbl_ssi_mode;
104 our $clonezilla_mode;
105 our $clonezilla_box_mode;
106 our $run_drbl_ocs_live_prep="yes";
107 our $drbl_ocs_live_server;
108 our $live_client_cpu_mode;
109 our $ocs_img_repo_dir;
110 our $ocs_img_repo_dir_default;
111 # switch for local swap in client
112 our $swap_create;
113 our $client_exist_flag;
114 # default color for warning and error
115 #our $color_warn="yellow";
116 our $color_warn="Bold Yellow";
117 our $color_fail="red";
118 our $add_start_drbl_services_after_cfg="yes";
119 our $continue_with_one_port;
120
121 # use some perl modules
122 use Term::ANSIColor;
123 use File::Path;
124 # Import locale-handling tool set from POSIX module.
125 use POSIX qw(locale_h);
126 # set the locale to C
127 setlocale(LC_ALL, "C");
128
129 #
130 # ------------------------------------------------------------------------
131 # Begin of the program
132 # subroutines
133 require "$DRBL_SCRIPT_PATH/sbin/drbl-perl-functions";
134
135 chomp($orig_wd=`LC_ALL=C pwd`);
136 chomp($drblpush_wd=`LC_ALL=C mktemp -d /tmp/drblpush_wd.tmp.XXXXXX`);
137 # before changing to working directory, we copy the macadr-* into working dir
138 system("cp -f macadr-*.txt $drblpush_wd > /dev/null 2>&1");
139 chdir ($drblpush_wd) || die ("Could not change to new working directory!!!");
140
141 sub netmask_to_cidr {
142 my $mask = shift;
143 my $cidr = 0;
144 foreach my $octet (split(/\./, $mask)) {
145 my $bin = sprintf("%08b", $octet);
146 $cidr += ($bin =~ tr/1/1/);
147 }
148 return $cidr;
149 }
150
151 sub set_client_public_ip {
152 # $_[0]: file to input containing client IPs (input)
153 # $_[1]: file to output containing client public IPs parameters (return)
154 my @drbl_ip=`cat $_[0]`;
155 my $public_ip_file="$_[1]";
156
157 my $saved_ip="";
158 my $saved_gw="";
159 my $saved_netmask="255.255.255.0";
160 my $public_ip;
161 my $public_gw;
162 my $public_netmask;
163 my @public_network_param;
164 my $first_saved_ip;
165
166 sub check_net_digit {
167 my $check_ip="$_[0]";
168 my $check_type="$_[1]"; # 2 values: IP or NETMASK
169 my @check_ip_each=split(/\./,$check_ip);
170 if (@check_ip_each != "4") { return "failed"; }
171 if ($check_type eq "IP") {
172 # check the first and last digit, it can not be 255 or 0.
173 if ($check_ip_each[$#$check_ip_each] eq "0" || $check_ip_each[$#$check_ip_each] eq "255" ) {
174 print "$check_ip_each[$#$check_ip_each] $lang_deploy{\"can_not_be_the_last_IP\"}!!!\n";
175 return "failed";
176 }
177 if ($check_ip_each[0] eq "0" || $check_ip_each[0] eq "255" ) {
178 print "$check_ip_each[0] $lang_deploy{\"can_not_be_the_first_IP\"}!!!\n";
179 return "failed";
180 }
181 }
182
183 foreach $DIG (@check_ip_each) {
184 if ($check_type eq "IP") {
185 if ($DIG > "255" || $DIG < "0") {
186 return "failed";
187 }
188 }elsif ($check_type eq "NETMASK"){
189 if ($DIG >= "256") {
190 return "failed";
191 }
192 }
193 }
194 } # end of sub check_net_digit
195
196 sub get_network_param {
197 $IP="$_[0]";
198 $saved_ip="$_[1]";
199 $saved_gw="$_[2]";
200 $saved_netmask="$_[3]";
201 print "$lang_deploy{\"enter_public_IP_for_the_client\"} ($lang_deploy{\"its_IP_in_DRBL_is\"} $IP)\n[$saved_ip] ";
202 chomp($public_ip=<STDIN>);
203 if ($public_ip eq ""){
204 $public_ip=$saved_ip;
205 }
206 my $chk_rlt=check_net_digit($public_ip,"IP");
207 while ($chk_rlt eq "failed") {
208 print "$lang_deploy{\"wrong_entered_IP\"}\n";
209 chomp($public_ip=<STDIN>);
210 $chk_rlt=check_net_digit($public_ip,"IP");
211 }
212 print "public_ip $public_ip\n" if $verbosity >=2;
213
214 @networkIp=split(/\./,$public_ip);
215 my $IP_PREFIX=$networkIp[0].".".$networkIp[1].".".$networkIp[2];
216 $saved_ip=$IP_PREFIX.".".++$networkIp[3];
217 print "network $IP_PREFIX.0\n" if $verbosity >=2;
218 print "saved_ip $saved_ip\n" if $verbosity >=2;
219 $saved_gw=$IP_PREFIX.".".254;
220
221 # public ip gateway
222 print "$lang_deploy{\"enter_gateway_for_client\"} ($lang_deploy{\"its_IP_in_DRBL_is\"} $IP) \n[$saved_gw] ";
223 chomp($public_gw=<STDIN>);
224 if ($public_gw eq "") { $public_gw=$saved_gw; }
225 my $chk_rlt=check_net_digit($public_gw,"IP");
226 while ($chk_rlt eq "failed") {
227 print "$lang_deploy{\"wrong_entered_IP\"}\n";
228 chomp($public_gw=<STDIN>);
229 $chk_rlt=check_net_digit($public_gw,"IP");
230 }
231 $saved_gw=$public_gw;
232 print "public_gw is $public_gw\n" if $verbosity >=2;
233 print "saved_gw is $saved_gw\n" if $verbosity >=2;
234
235
236 # public ip netmask
237 print "$lang_deploy{\"enter_netmask_for_client\"} ($lang_deploy{\"its_IP_in_DRBL_is\"} $IP) \n[$saved_netmask] ";
238 chomp($public_netmask=<STDIN>);
239 if ($public_netmask eq "") { $public_netmask="$saved_netmask" }
240 my $chk_rlt=check_net_digit($public_netmask,"NETMASK");
241 while ($chk_rlt eq "failed") {
242 print "$lang_deploy{\"wrong_entered_netmask\"}\n";
243 chomp($public_netmask=<STDIN>);
244 $chk_rlt=check_net_digit($public_netmask,"NETMASK");
245 }
246 $saved_netmask=$public_netmask;
247 print "public_netmask is $public_netmask\n" if $verbosity >=2;
248 print "saved_netmask is $saved_netmask\n" if $verbosity >=2;
249
250 return $saved_ip, $saved_gw, $saved_netmask, $public_ip, $public_gw, $public_netmask;
251 } # end of sub get_network_param
252
253 chomp($public_ip_tmp=`LC_ALL=C mktemp /tmp/public_ip_tmp.XXXXXX`);
254 chomp($public_ip_guess=`LC_ALL=C mktemp /tmp/public_ip_guess.XXXXXX`);
255 open(PUBLIC_IP_FILE,">$public_ip_tmp") or die "$lang_deploy{\"failed_to_open_file\"} \"$public_ip_tmp\"\n";
256 open(PUBLIC_IP_GUESS_FILE,">$public_ip_guess") or die "$lang_deploy{\"failed_to_open_file\"} \"$public_ip_guess\"\n";
257 print "Clients' IPs: @drbl_ip\n" if $verbosity >=2;
258
259 # prepare the public ip file, one for guessed from first input, the other for
260 # entering one by one.
261 print PUBLIC_IP_FILE <<END_PUBLIC_IP;
262 # The private IP is for the client connected to DRBL server.
263 # The public IP is for the client connected to WAN.
264 #------------------------------------------------------------
265 #private IP \t public IP \t netmask \t gateway
266 END_PUBLIC_IP
267
268 print PUBLIC_IP_GUESS_FILE <<END_PUBLIC_IP_GUESS;
269 # The private IP is for the client connected to DRBL server.
270 # The public IP is for the client connected to WAN.
271 #------------------------------------------------------------
272 #private IP \t public IP \t netmask \t gateway
273 END_PUBLIC_IP_GUESS
274
275 chomp($IP=@drbl_ip[0]);
276 # get first public ip for client
277 get_network_param($IP, $saved_ip, $saved_gw, $saved_netmask);
278 $first_saved_ip=$saved_ip;
279
280 print PUBLIC_IP_FILE <<END_PUBLIC_IP;
281 $IP \t $public_ip \t $public_netmask \t $public_gw
282 END_PUBLIC_IP
283
284 print PUBLIC_IP_GUESS_FILE <<END_PUBLIC_IP_GUESS;
285 $IP \t $public_ip \t $public_netmask \t $public_gw
286 END_PUBLIC_IP_GUESS
287
288 foreach $IP (@drbl_ip[1..$#drbl_ip]) {
289 chomp($IP);
290 $public_ip=$saved_ip;
291 @networkIp=split(/\./,$public_ip);
292 my $IP_PREFIX=$networkIp[0].".".$networkIp[1].".".$networkIp[2];
293 $saved_ip=$IP_PREFIX.".".++$networkIp[3];
294
295 $public_netmask=$saved_netmask;
296 $public_gw=$saved_gw;
297 print PUBLIC_IP_GUESS_FILE <<END_PUBLIC_IP_GUESS;
298 $IP \t $public_ip \t $public_netmask \t $public_gw
299 END_PUBLIC_IP_GUESS
300 }
301
302 print "#$delimiter{\"dash_line\"}\n";
303 print "$lang_deploy{\"set_client_public_IP_as\"}\n";
304 print "#$delimiter{\"dash_line\"}\n";
305 system("LC_ALL=C cat $public_ip_guess");
306 print "#$delimiter{\"dash_line\"}\n";
307 print "$lang_text{\"Accept\"} ? [Y/n] ";
308 chomp($value=<STDIN>);
309 SWITCH: for ($value) {
310 /^n$|^no$/i && do {
311 # Enter each one by one
312 foreach $IP (@drbl_ip[1..$#drbl_ip]) {
313 chomp($IP);
314 # use the first one saved for initial prompt value to user
315 $saved_ip=$first_saved_ip;
316 get_network_param($IP, $saved_ip, $saved_gw, $saved_netmask);
317 print PUBLIC_IP_FILE <<END_PUBLIC_IP;
318 $IP \t $public_ip \t $public_netmask \t $public_gw
319 END_PUBLIC_IP
320 }
321 close(PUBLIC_IP_FILE);
322 # put the result file to working directory
323 system("LC_ALL=C cp -f $public_ip_tmp $public_ip_file");
324 last SWITCH;
325 };
326 /.*/ && do {
327 # accept the guess one, output the result
328 close(PUBLIC_IP_GUESS_FILE);
329 # put the result file to working directory
330 system("LC_ALL=C cp -f $public_ip_guess $public_ip_file");
331 last SWITCH;
332 };
333 }
334
335 unlink ($public_ip_tmp) if -f $public_ip_tmp;
336 unlink ($public_ip_guess) if -f $public_ip_guess;
337 } # end of sub set_client_public_ip
338 #
339 sub set_autologin_passwd{
340 print "$lang_deploy{\"use_random_password\"}\n".
341 "[Y/n] ";
342 chomp($auto_login_random_passwd=<STDIN>);
343 if ($auto_login_random_passwd eq "n" || $auto_login_random_passwd eq "N" || $auto_login_random_passwd eq "no" || $auto_login_random_passwd eq "NO") {
344 # input password for client auto-login account
345 print "$lang_deploy{\"enter_password_for_autologin_accounts\"}\n";
346 # we set 2 different passwords to make while loop works.
347 $client_autologin_passwd1="init1";
348 $client_autologin_passwd2="init2";
349 while ($client_autologin_passwd1 ne $client_autologin_passwd2 || ($client_autologin_passwd1 eq "" && $client_autologin_passwd2 eq "" )) {
350 print "$lang_deploy{\"whats_client_autologin_passwd\"}\n";
351 # turn off echo
352 system "LC_ALL=C stty -echo";
353 chomp($client_autologin_passwd1=<STDIN>);
354 # turn on echo
355 system "LC_ALL=C stty echo";
356 print "$lang_deploy{\"retype_autologin_passwd\"}\n";
357 system "LC_ALL=C stty -echo";
358 chomp($client_autologin_passwd2=<STDIN>);
359 system "LC_ALL=C stty echo";
360 if ($client_autologin_passwd1 ne $client_autologin_passwd2) {
361 print colored ("$lang_deploy{\"sorry_passwd_not_match\"}\n", "$color_warn");
362 }elsif ($client_autologin_passwd1 eq "" && $client_autologin_passwd2 eq "" ){
363 print colored ("$lang_deploy{\"sorry_passwd_can_not_empty\"}\n", "$color_warn");
364 }
365 }
366 $client_autologin_passwd=$client_autologin_passwd1;
367 }else{
368 # Random password for client auto-login account
369 $client_autologin_passwd="$ACCOUNT_PASSWD_LENGTH_DEFAULT";
370 print "$lang_deploy{\"ok_let_continue\"}\n";
371 }
372 } # end of set_autologin_passwd
373
374 #
375 sub interactive_mode {
376 my $dnsdomain_sys, $nisdomain_sys, $hostname_sys;
377 #we will scan the ethernet from $ethernet_list[0]...
378 #use public IP in alias interface, private IP in real interface,
379 #Ex: eth0: 192.168.0.254, eth0:1 61.216.116.23
380
381 my $ethernet_list_;
382 print "Finding the available ethernet ports...\n" if $verbosity >=2;
383 chomp($ethernet_list_=`get-all-nic-ip -d`);
384 my @ethernet_list=split(/ /,$ethernet_list_);
385 my @ethernet_sys; # the private ethernet we found and useful, ex:"eth1"
386 my @range_start;
387 my @range_end;
388 my @MAC_file;
389 my $one_ethernet_port_server="no";
390 my $use_proxy_dhcp="no";
391 my $DHCPOFFER_siaddr="";
392 my $DHCPOFFER_yiaddr="";
393 my $DHCPOFFER_prefix="";
394 my $DHCPOFFER_eth="";
395
396 # Try to get setting from system
397 chomp($dnsdomain_sys=`dnsdomainname`);
398 chomp($nisdomain_sys=`nisdomainname`);
399 chomp($hostname_sys=`hostname`);
400 my @client_hostname_prefix_default=split(/\./,$hostname_sys);
401 # Append "-" so that the hostname for client is like: prefix-192-168-1-1
402 $client_hostname_prefix_default[0]="$client_hostname_prefix_default[0]"."-";
403 print "DNSDOMAIN in system is $dnsdomain_sys\n" if $verbosity >= 2;
404 print "NISDOMAIN in system is $nisdomain_sys\n" if $verbosity >= 2;
405 print "Client hostname prefix default is $client_hostname_prefix_default[0]\n" if $verbosity >= 2;
406
407 unlink ($DRBLPUSH_CONF) if -f $DRBLPUSH_CONF;
408 open(CONFIG_FILE,">$DRBLPUSH_CONF") or die "$lang_deploy{\"failed_to_open_file\"} \"$DRBLPUSH_CONF\"\n";
409
410 # get domain name
411 # If we can find the one in system, use it as the default one
412 if ( $dnsdomain_sys && "$dnsdomain_sys" ne "localdomain" ) {
413 $DEFAULT_DOMAINNAME="$dnsdomain_sys";
414 }
415 print "$delimiter{\"dash_line\"}\n".
416 "$lang_deploy{\"domain_prompt\"}\n".
417 "[$DEFAULT_DOMAINNAME] ";
418 while (<STDIN>) {
419 chomp;
420 $dnsdomain_sys=$_;
421 if ( "$dnsdomain_sys" =~ / |\/|\\/ ) {
422 print "\" \" ($lang_text{\"space\"}), \"/\", $lang_text{\"or\"} \"\\\" $lang_deploy{\"not_allowed_domainname\"} $lang_deploy{\"enter_it_again\"}!\n".
423 "[$DEFAULT_DOMAINNAME] ";
424 } else {
425 # if empty, use default name
426 if ($dnsdomain_sys eq "") { $dnsdomain_sys="$DEFAULT_DOMAINNAME"; }
427 print "$lang_deploy{\"set_domain_as\"} $dnsdomain_sys\n";
428 last;
429 }
430 }
431
432 # get nis domain name
433 # If we can find the one in system, use it as the default one.
434 # We will not use "localdomain" "nisdomainname: Local domain name not set" (on Fedora 13, when nisdomainname is not set, it is shown as that) and "(none)"
435 if ( $nisdomain_sys && "$nisdomain_sys" !~ /^(localdomain|nisdomainname: Local domain name not set|\(none\))$/i ) {
436 $DEFAULT_NISDOMAINNAME="$nisdomain_sys";
437 }
438 print "$delimiter{\"dash_line\"}\n".
439 "$lang_deploy{\"nisdomain_prompt\"}\n".
440 "[$DEFAULT_NISDOMAINNAME] ";
441 while (<STDIN>) {
442 chomp;
443 $nisdomain_sys=$_;
444 if ( "$nisdomain_sys" =~ / |\/|\\|\.|^[0-9]/ ) {
445 print "\" \" ($lang_text{\"space\"}), \"/\", \".\", \"\\\" $lang_text{\"or\"} \"$lang_word{\"initial_digit\"}\" $lang_deploy{\"not_allowed_nisdomain_sys\"} $lang_deploy{\"enter_it_again\"}!\n".
446 "[$DEFAULT_NISDOMAINNAME] ";
447 } else {
448 # if empty, use default name
449 if ($nisdomain_sys eq "") { $nisdomain_sys="$DEFAULT_NISDOMAINNAME"; }
450 print "$lang_deploy{\"set_domain_as\"} $nisdomain_sys\n";
451 last;
452 }
453 }
454
455 # get client hostname prefix
456 print "$delimiter{\"dash_line\"}\n".
457 "$lang_deploy{\"enter_client_hostname_prefix\"}\n".
458 "[$client_hostname_prefix_default[0]] ";
459 while (<STDIN>) {
460 chomp;
461 $client_hostname_prefix=$_;
462 if ( "$client_hostname_prefix" =~ / |\/|\\|\./ ) {
463 # "-" should be ok, but we need to parse the /etc/dhcpd.conf
464 # then if make it like fc1-1=00:2A:00:AB:CD:EF, run
465 # fc1-1=00:2A:00:AB:CD:EF in shell will fail. So we skip
466 # "-"
467 print "\" \" ($lang_text{\"space\"}), \"/\", \".\", \"\\\" $lang_text{\"or\"} \"$lang_word{\"initial_digit\"}\" $lang_deploy{\"not_allowed_hostname\"} $lang_deploy{\"enter_it_again\"}!\n".
468 "[$client_hostname_prefix_default[0]] ";
469 } else {
470 # if empty, use default name
471 if ($client_hostname_prefix eq "") {
472 $client_hostname_prefix="$client_hostname_prefix_default[0]";
473 }
474 print "$lang_deploy{\"set_client_hostname_prefix\"} $client_hostname_prefix\n".
475 "$delimiter{\"dash_line\"}\n";
476 last;
477 }
478 }
479 # try to find all the NIC for clients, i.e. eth1, eth2...
480 foreach my $ethx (@ethernet_list) {
481 print "Finding the IP address for $ethx...\n" if $verbosity >=2;
482 chomp($nic_ethx_ip=`drbl-get-ipadd $ethx`);
483 chomp($nic_ethx_netmask=`drbl-get-netmask $ethx`);
484 if ( $nic_ethx_ip ) {
485 # Specially, we do not want the alias interface, such as:eth0:1
486 my $IP=`drbl-get-ipadd $ethx`;
487 chomp($IP);
488 if ( ! $IP ) {
489 print "The IP address of $ethx was not found!\n".
490 "$lang_deploy{\"we_will_skip\"} $ethx!\n";
491 } else {
492 print "$ethx: IP address $IP, netmask $nic_ethx_netmask\n";
493 push @ethernet_sys, $ethx;
494 }
495
496 }
497 }
498 if ( @ethernet_sys <= 0 ) {
499 print "$lang_deploy{\"no_NIC_setup\"}\n".
500 "$lang_deploy{\"we_can_NOT_continue\"}\n";
501 exit;
502 } else {
503 print "$lang_deploy{\"configured_nic\"} ".
504 colored ("@ethernet_sys \n", "$color_warn");
505 print "$delimiter{\"dash_line\"}\n";
506
507 # Find the ethernet port connected to WAN.
508 print "Finding the available public IP address...\n" if $verbosity >=2;
509 chomp($public_ip_addr=`get-all-nic-ip -a`);
510 chomp($public_ip_port=`get-all-nic-ip -p`);
511 if ($public_ip_port) {
512 print "$lang_deploy{\"ethernet_port_for_internet\"} $public_ip_port\n";
513 @ethernet_sys = grep { $_ ne "$public_ip_port" } @ethernet_sys;
514 print "$lang_deploy{\"ethernet_port_for_DRBL\"} ".
515 colored ("@ethernet_sys \n", "$color_warn");
516
517 }else{
518 my $private_eth_ports_;
519 chomp($private_eth_ports_=`get-all-nic-ip -t`);
520 my @private_eth_ports=split(/ /,$private_eth_ports_);
521 my $guess_uplink_port;
522 # we just want one port, so use "head -n 1" to get the 1st one.
523 chomp($guess_uplink_port=`PATH=$PATH:/sbin/:/usr/sbin route -n | awk '/^0.0.0.0/ {print \$8}' | sort | head -n 1`);
524 print "$lang_deploy{\"unable_to_find_public_IP\"}\n".
525 "$lang_deploy{\"for_internet_access_prompt\"}\n".
526 "$lang_deploy{\"available_eth_ports\"}:\n";
527 foreach my $ethx (@private_eth_ports){
528 my $IP=`drbl-get-ipadd $ethx`;
529 chomp($IP);
530 print "$ethx ($IP), ";
531 }
532 print "\n";
533 print "[$guess_uplink_port] ";
534 while (<STDIN>) {
535 chomp;
536 $pub_ans=$_;
537 if ($pub_ans eq "") { $pub_ans="$guess_uplink_port"; }
538 foreach my $k (@private_eth_ports) {
539 if ( "$pub_ans" eq "$k" ) {
540 # if empty, use default name
541 $pub_port_NAT=$pub_ans;
542 last;
543 }
544 }
545 if ( $pub_port_NAT ) {
546 last;
547 }else{
548 print "\"$pub_ans\" $lang_deploy{\"is_not_in_the_lists\"} (@private_eth_ports). $lang_deploy{\"enter_it_again\"}!\n";
549 }
550 }
551 print "$lang_deploy{\"the_eth_port_you_choose_for_wan\"}: ".
552 colored ("$pub_port_NAT\n", "$color_warn");
553 # Exclude uplink port, so @ethernet_sys will contain only ports connected to DRBL clients.
554 @ethernet_sys = grep { $_ ne "$pub_port_NAT" } @ethernet_sys;
555 if (@ethernet_sys) {
556 print "$lang_deploy{\"ethernet_port_for_DRBL\"} ".
557 colored ("@ethernet_sys \n", "$color_warn");
558 }
559 }
560 # if not ethernet port is available for DRBL, use $pub_port_NAT.
561 if ( @ethernet_sys <= 0 ) {
562 # Since only one port is available, we will use this only one to provide services for client. Give WARNING!
563 if (!$continue_with_one_port) {
564 print colored ("$lang_deploy{\"only_one_network_card_in_system\"}\n", "$color_warn").
565 colored ("$lang_deploy{\"are_you_sure_you_want_to_continue\"}\n", "$color_warn").
566 "[y/N] ";
567 chomp($continue_with_one_port=<STDIN>);
568 }
569 SWITCH: for ($continue_with_one_port) {
570 /^y$|^yes$/i && do {
571 # 2 cases: (1) only one public IP address port (public_ip_port) (2) only one private IP address port connected to WAN via NAT (pub_port_NAT)
572 if ($pub_port_NAT) {
573 @ethernet_sys = ("$pub_port_NAT");
574 } elsif ($public_ip_port) {
575 @ethernet_sys = ("$public_ip_port");
576 }
577 $one_ethernet_port_server="yes";
578 last SWITCH;
579 };
580 /.*/ && do {
581 print "$lang_deploy{\"program_stop\"}\n";
582 exit (1);
583 last SWITCH;
584 };
585 }
586 }
587 # Final check before using ethernet port
588 if ( @ethernet_sys <= 0 ) {
589 print "$lang_deploy{\"no_NIC_setup\"}\n".
590 "$lang_deploy{\"we_can_NOT_continue\"}\n";
591 exit;
592 }
593 # Checking if class A/B private IP ? If so, set warning about multicast clonezilla
594 # for($i=0;$i<=$#ethernet_sys;$i++) {
595 # my $ethx="$ethernet_sys[$i]";
596 # my $IP=`drbl-get-ipadd $ethx`;
597 # chomp($IP);
598 # if ( "$IP" =~ /^(172\.(1[6-9]|2[0-9]|3[01])\..*|10\..*)/ ) {
599 # # Class A: 10.0.0.0 - 10.255.255.255
600 # # Class B: 172.16.0.0 - 172.31.255.255
601 # print "$delimiter{\"star_line\"}\n";
602 # #print "Found class A or B private IP \"$IP\" in $ethx for your DRBL system! ".
603 # #colored ("$lang_deploy{\"class_c_IP_for_multicast_clonezilla\"}\n", "$color_warn");
604 # #print "$delimiter{\"star_line\"}\n".
605 # # "$lang_deploy{\"press_enter_to_continue\"}";
606 # # chomp($line=<STDIN>);
607 # }
608 #};
609 #print "$delimiter{\"star_line\"}\n";
610 }
611 if ($one_ethernet_port_server eq "yes") {
612 # Ask if proxy DHCP when there is existing DHCP
613 # Detect DHCP service first
614 my $detect_dhcp_rlt1=256;
615 while ($detect_dhcp_rlt1 == 256) {
616 $detect_dhcp_rlt1=system("drbl-find-dhcp-srv -i $ethernet_sys[0] $drblpush_wd/dhcp-detect.tmp");
617 if ($detect_dhcp_rlt1 == 256) {
618 print "\n$delimiter{\"star_line\"}\n";
619 print colored ("$lang_deploy{\"failed_to_detect_dhcp_service\"}\n", "$color_warn").
620 "$lang_deploy{\"do_you_want_to_try_it_again\"}\n".
621 "[Y/n] ";
622 chomp(my $try_again=<STDIN>);
623 if ($try_again eq "n" || $try_again eq "N" || $try_again eq "no" || $try_again eq "NO") {
624 $detect_dhcp_rlt1=0;
625 }
626 }
627 }
628 # Only when $drblpush_wd/dhcp-detect.tmp exists we will continue this
629 chomp($DHCPOFFER_eth=`. $drblpush_wd/dhcp-detect.tmp; echo \$DHCPOFFER_eth`);
630 chomp($DHCPOFFER_siaddr=`. $drblpush_wd/dhcp-detect.tmp; echo \$DHCPOFFER_siaddr`);
631 chomp($DHCPOFFER_yiaddr=`. $drblpush_wd/dhcp-detect.tmp; echo \$DHCPOFFER_yiaddr`);
632 if ($DHCPOFFER_siaddr) {
633 print "$delimiter{\"star_line\"}\n";
634 print colored ("$lang_deploy{\"found_dhcp_service_on_nic\"}: $DHCPOFFER_eth\n", "$color_warn").
635 colored ("$lang_deploy{\"do_you_want_to_lease_ip_addr_from_existing_dhcp_srv\"}: $DHCPOFFER_siaddr\n", "$color_warn").
636 colored ("$lang_deploy{\"will_use_available_ip_addr_from_dhcp_srv\"}\n", "$color_warn").
637 colored ("$lang_deploy{\"note_you_have_to_make_sure_enough_no_of_ip_addr\"}\n", "$color_warn").
638 "[Y/n] ";
639 chomp($use_proxy_dhcp=<STDIN>);
640 }
641 SWITCH: for ($use_proxy_dhcp) {
642 /^n$|^no$/i && do {
643 # Format the variable use_proxy_dhcp
644 $use_proxy_dhcp="no";
645 print colored ("Do not use proxy DHCP.\n","$color_warn");
646 last SWITCH;
647 };
648 /.*/ && do {
649 # Format the variable use_proxy_dhcp
650 $use_proxy_dhcp="yes";
651 print colored ("Use proxy DHCP. Adding virtual network drbl0...\n","$color_warn");
652 system("drbl-add-vir-netdev $ethernet_sys[0] drbl0");
653 my $detect_dhcp_rlt2=256;
654 while ($detect_dhcp_rlt2 == 256) {
655 $detect_dhcp_rlt2=system("drbl-find-dhcp-srv -i drbl0 $drblpush_wd/dhcp-detect-vir0.txt");
656 if ($detect_dhcp_rlt2 == 256) {
657 print "\n$delimiter{\"star_line\"}\n";
658 print colored ("$lang_deploy{\"failed_to_detect_dhcp_service\"}\n", "$color_warn").
659 "$lang_deploy{\"do_you_want_to_try_it_again\"}\n".
660 "[Y/n] ";
661 chomp(my $try_again=<STDIN>);
662 if ($try_again eq "n" || $try_again eq "N" || $try_again eq "no" || $try_again eq "NO") {
663 $detect_dhcp_rlt2=0;
664 }
665 }
666 }
667 # Reset variables before loading them.
668 $DHCPOFFER_eth="";
669 $DHCPOFFER_siaddr="";
670 $DHCPOFFER_yiaddr="";
671 $DHCPOFFER_prefix="";
672 chomp($DHCPOFFER_eth=`. $drblpush_wd/dhcp-detect-vir0.txt; echo \$DHCPOFFER_eth`);
673 chomp($DHCPOFFER_siaddr=`. $drblpush_wd/dhcp-detect-vir0.txt; echo \$DHCPOFFER_siaddr`);
674 chomp($DHCPOFFER_yiaddr=`. $drblpush_wd/dhcp-detect-vir0.txt; echo \$DHCPOFFER_yiaddr`);
675 chomp($DHCPOFFER_prefix=`. $drblpush_wd/dhcp-detect-vir0.txt; echo \$DHCPOFFER_prefix`);
676 if ($DHCPOFFER_yiaddr) {
677 if (!$DHCPOFFER_prefix) {
678 chomp($DHCPOFFER_prefix=`LC_ALL=C ip -o -f inet addr show $ethernet_sys[0] | awk -F" " '{print \$4}' | awk -F"/" '{print \$2}' | head -n 1`);
679 }
680 system("ip addr add $DHCPOFFER_yiaddr/$DHCPOFFER_prefix dev drbl0");
681 # TODO: check if new dirvir0 exists.
682 # TODO: Write system config file for virtual network card (Debian/Ubuntu, Fedora...)
683 system("perl -p -i -e \"s/^use_existing_dhcp_srv=.*/use_existing_dhcp_srv=yes/g\" $drbl_syscfg/drbl.conf");
684 # Put new virtual network card in $ethernet_sys
685 push @ethernet_sys, drbl0;
686 # Since virtual network card is pushed, now we should remove $pub_port_NAT or $public_ip_port
687 if ($pub_port_NAT) {
688 @ethernet_sys = grep { $_ ne "$pub_port_NAT" } @ethernet_sys;
689 } elsif ($public_ip_port) {
690 @ethernet_sys = grep { $_ ne "$public_ip_port" } @ethernet_sys;
691 }
692 }
693 last SWITCH;
694 };
695 }
696 }
697
698 # detect the mac address
699 # Only when there are two or more ethernet ports we should collect MAC.
700 if ( $one_ethernet_port_server eq "no" ) {
701 print "$delimiter{\"star_line\"}\n".
702 "$lang_deploy{\"collect_MAC_prompt\"}\n".
703 "[y/N] ";
704 chomp($line=<STDIN>);
705 SWITCH: for ($line) {
706 /^y$|^yes$/i && do {
707 $collect_mac="yes";
708 print "$delimiter{\"star_line\"}\n".
709 "$lang_deploy{\"ok_let_do_it\"}\n";
710 my $whoiam = `LC_ALL=C id -nu`;
711 chomp($whoiam);
712 if ("$whoiam" eq "root") {
713 system("LC_ALL=C drbl-collect-mac -n -l $language @ethernet_sys");
714 print colored ("$lang_deploy{\"saved_mac_address_files_in_etc\"}\n", "$color_warn");
715 }else{
716 print "$lang_deploy{\"you_are_not_root\"},\n".
717 "$lang_word{\"please_enter\"} ". colored("$lang_word{\"root_passwd\"} ","$color_warn"). "to collect those MAC addresses...\n";
718 my $su_rlt=system("LC_ALL=C su -c \"drbl-collect-mac @ethernet_sys\" root");
719 while ($su_rlt == 256) {
720 $su_rlt=system("LC_ALL=C su -c \"drbl-collect-mac @ethernet_sys\" root");
721 }
722 }
723 last SWITCH;
724 };
725 /.*/ && do {
726 $collect_mac="no";
727 last SWITCH;
728 };
729 }
730 }
731
732 print "$delimiter{\"star_line\"}\n".
733 "$lang_deploy{\"ok_let_continue\"}\n".
734 "$delimiter{\"star_line\"}\n";
735
736 # ask user to input client no.
737 my @ip_sys_start;
738 my @ip_sys_end;
739 my @total_client_no;
740 for($i=0;$i<=$#ethernet_sys;$i++) {
741 $ethx="$ethernet_sys[$i]";
742 # Try to get setting from system also
743 # get the ipaddress of NIC "eth1, eth2..."
744 my $ip_sys_tmp;
745 my $netmask_sys_tmp;
746 chomp($ip_sys_tmp=`drbl-get-ipadd $ethx`);
747 chomp($netmask_sys_tmp=`drbl-get-netmask $ethx`);
748 # We must get the static IP for this NIC, NO DHCP...
749 if ( "$ip_sys_tmp" eq "" ) {
750 print "$delimiter{\"star_line\"}\n".
751 "$lang_deploy{\"unable_to_get_ethx_IP\"} ".
752 colored("$ethx \n","$color_fail").
753 "$lang_deploy{\"program_stop\"}\n";
754 exit (1);
755 };
756
757 # Find the available start IP which will not conflict with the server
758 my $ip_hostmin = `drbl-ipcalc $ip_sys_tmp $netmask_sys_tmp | awk -F' ' '/^HostMin:/ {print \$2}'`;
759 chomp($ip_hostmin);
760 print "Hostmin: $ip_hostmin\n";
761 # Find the max number of the class
762 my $hostmax_no = `drbl-ipcalc $ip_sys_tmp $netmask_sys_tmp | grep -Ew "^Hosts/Net:" | awk -F":" '{print \$2}' | awk -F" " '{print \$1}'`;
763 chomp($hostmax_no);
764 my @ip_sys_sp=split(/\./,$ip_hostmin);
765 $ip_sys_prefix[$i]="$ip_sys_sp[0].$ip_sys_sp[1].$ip_sys_sp[2]";
766 $ip_sys[$i]=$ip_sys_tmp;
767
768 if ( $use_proxy_dhcp eq "no" ) {
769 # Only when it's not proxy mode we will ask about using fixed IP address
770 print "$lang_deploy{\"fix_eth_IP_prompt\"} ".
771 colored("$ethx","$color_warn").
772 " ?\n".
773 "[y/N] ";
774 chomp($MAC=<STDIN>);
775 } else {
776 $MAC="no";
777 }
778 my $mac_f_tmp="";
779 if ($MAC eq "y" || $MAC eq "Y" || $MAC eq "yes" || $MAC eq "YES") {
780 # User wants to fix the IP addresses for DRBL clients
781 print "$delimiter{\"star_line\"}\n".
782 "$lang_deploy{\"MAC_file_prompt\"} $ethx.\n".
783 "[macadr-$ethx.txt] ";
784 while (<STDIN>) {
785 chomp;
786 if ( $_ eq "" ) {
787 $mac_f_tmp="macadr-$ethx.txt";
788 }else{
789 $mac_f_tmp=$_;
790 }
791
792 # 2 cases filename user entered (1) without path (2) with path
793 # we will try both cases, and copy the file to working dir.
794 $MAC_file[$i]=`basename $mac_f_tmp 2>/dev/null`;
795 chomp($MAC_file[$i]);
796 my $mac_dir=`dirname $mac_f_tmp 2>/dev/null`;
797 chomp($mac_dir);
798 # if user does not specify the path, then it is the original wd
799 if ( $mac_dir eq "." ) { $mac_dir="$orig_wd"; }
800 print "MAC_file[$i], mac_dir: $MAC_file[$i], $mac_dir\n" if $verbosity >= 2;
801
802 # (1) w/o path: copy the entered file from orig_wd if they exist
803 # this is the case if user specified file like "mac1.txt"
804 # (2) whith path: copy the entered file if they exist
805 # this is the case if user specified file like "/root/mac1.txt"
806 system("[ -f $mac_dir/$MAC_file[$i] ] && cp -f $mac_dir/$MAC_file[$i] ./");
807
808 # check MAC address files
809 check_MAC_file(".","$MAC_file[$i]");
810
811 my $range_start_default = `echo $ip_hostmin | awk -F"." '{print \$4}'`;
812 chomp($range_start_default);
813
814 # get the client no from user input
815 # 1st, get the initial value of the last set of digits in the IP address in this subnet
816 print "$delimiter{\"star_line\"}\n".
817 "$lang_deploy{\"IP_start_prompt\"} $ethx.\n",
818 "[$range_start_default] ";
819
820 unless ( $range_start[$i] ) {
821 while (<STDIN>) {
822 chomp;
823 my $start_input=$_;
824 if ($start_input eq "") {
825 $range_start[$i]=$range_start_default;
826 last;
827 } elsif ( $start_input =~ /[^0-9]/ ) {
828 print "$lang_deploy{\"not_initial_value\"}\n";
829 } else {
830 $range_start[$i]=$start_input;
831 last;
832 }
833 }
834 }
835 # use wc -l to count the lines of file user input
836 # we use the MAC file in working dir ($MAC_file[$i]) so it been
837 # processed by check_MAC_file. Ex. the space line is stripped.
838 chomp($line=`LC_ALL=C cat $MAC_file[$i] 2>/dev/null | wc -l |tr -d \" \" `);
839 $range_end[$i]=$range_start[$i] + $line - 1;
840 if ($line >= $hostmax_no) {
841 print colored ("The file \"$mac_dir/$MAC_file[$i]\" you set for the clients connected to $ethx is empty or invalid.\nTotal number of clients in file: $line.\nMax number in this subnet: $hostmax_no.\nPlease enter the filename again, or press \"ctrl-c\" to quit!\n", "$color_warn");
842 } else {
843 $range_end[$i]=$range_start[$i] + $line - 1;
844 last;
845 }
846 }
847 } else {
848 # User wants to use floating IP addresses for DRBL clients
849 print "$delimiter{\"star_line\"}\n".
850 "$lang_deploy{\"range_prompt\"}\n";
851 my $range_start_default = `echo $ip_hostmin | awk -F"." '{print \$4}'`;
852 chomp($range_start_default);
853
854 # user does NOT want to fix the IP address for DRBL client
855 # get the client no from user input
856 print "$delimiter{\"star_line\"}\n".
857 "$lang_deploy{\"IP_start_prompt\"} $ethx.\n",
858 "[$range_start_default] ";
859 unless ( $range_start[$i] ) {
860 while (<STDIN>) {
861 chomp;
862 my $start_input=$_;
863 if ($start_input eq "") {
864 $range_start[$i]=$range_start_default;
865 last;
866 } elsif ( $start_input =~ /[^0-9]/ ) {
867 print "$lang_deploy{\"not_initial_value\"}\n";
868 } else {
869 $range_start[$i]=$start_input;
870 last;
871 }
872 }
873 }
874 # count the clients no which already exist to prompt user
875 my $client_no;
876 if ( ! $assign_client_no_each_port ) {
877 $client_no=`LC_ALL=C unalias ls 2> /dev/null; ls -d /tftpboot/nodes/$ip_sys_prefix[$i].* 2>/dev/null |wc -w|sed -e "s/ //g"`;
878 chomp($client_no);
879 # if 0, set the default no for user
880 if ($client_no eq "0") { $client_no="$DEFAULT_CLIENT_NO_EACH_PORT";}
881 } else {
882 $client_no=$assign_client_no_each_port;
883 }
884 print "client_no:$client_no\n" if $verbosity >=2;
885 print "$delimiter{\"star_line\"}\n".
886 "$lang_deploy{\"client_number_connected_to_eth\"} $ethx ?\n".
887 "$lang_deploy{\"enter_the_no\"}: \n".
888 "[$client_no] ";
889 while (<STDIN>) {
890 chomp;
891 my $line=$_;
892 if ($line eq "") { $line=$client_no;}
893 if ($line >= $hostmax_no) {
894 print colored ("Total number of clients in file: $line.\nMax number in this subnet: $hostmax_no.\nPlease enter the client number again, or press \"ctrl-c\" to quit!\n", "$color_warn");
895 } else {
896 $range_end[$i]=$range_start[$i] + $line - 1;
897 last;
898 }
899 }
900 }
901 # List all the IP address, and get the last one.
902 $total_client[$i]=$range_end[$i]-$range_start[$i]+1;
903 $ip_sys_start[$i]=$ip_sys_prefix[$i].".".$range_start[$i];
904 chomp($ip_sys_end[$i]=`drbl-ipcalc-list -c $total_client[$i] $ip_sys_start[$i] $netmask_sys_tmp | head -n $total_client[$i] | tail -n 1`);
905
906 if ( ! $MAC_file[$i] ){
907 # use the range for clients.
908 print "$delimiter{\"star_line\"}\n".
909 "$lang_deploy{\"set_the_IP_connected_to_eth\"} ".
910 colored ("$ethx $lang_text{\"as\"}: $ip_sys_start[$i] - $ip_sys_end[$i]\n","$color_warn").
911 "$lang_text{\"Accept\"} ? [Y/n] ";
912 }else{
913 # use the fixed IP address for clients.
914 print "$delimiter{\"star_line\"}\n".
915 "$lang_deploy{\"filename_you_set\"} \"$MAC_file[$i]\".\n".
916 "$lang_deploy{\"client_no_in_MAC_file\"} $line.\n".
917 "$lang_deploy{\"set_the_IP_connected_to_eth\"} $ethx $lang_deploy{\"by_MAC_file\"} ".
918 colored ("$ethx $lang_text{\"as\"}: $ip_sys_start[$i] - $ip_sys_end[$i]\n","$color_warn").
919 "$lang_text{\"Accept\"} ? [Y/n] ";
920 }
921
922 chomp($line=<STDIN>);
923 if ($line eq "n" || $line eq "N" || $line eq "no" || $line eq "NO") {
924 print "$delimiter{\"exclamation_line\"}\n".
925 "$lang_deploy{\"let_restart_it_again\"}\n";
926 redo;
927 }
928 else {
929 print "$delimiter{\"star_line\"}\n".
930 "$lang_deploy{\"ok_let_continue\"}\n";
931 }
932 }
933
934 # print the schematic network
935 my $PUB_NIC;
936 my $IP_PUB_NIC;
937 if ( $public_ip_port ) {
938 $PUB_NIC=$public_ip_port;
939 $IP_PUB_NIC=$public_ip_addr;
940 }else{
941 $PUB_NIC=$pub_port_NAT;
942 chomp($IP_PUB_NIC=`drbl-get-ipadd $pub_port_NAT`);
943 }
944 print "$delimiter{\"star_line\"}\n".
945 "$lang_deploy{\"layout_for_DRBL\"} \n".
946 "$delimiter{\"star_line\"}\n";
947 print color "$color_warn";
948 print
949 " NIC NIC IP Clients\n".
950 "+-----------------------------+\n".
951 "| DRBL SERVER |\n".
952 "| |\n".
953 "| +-- [$PUB_NIC] $IP_PUB_NIC +- to WAN\n".
954 "| |\n";
955 for($i=0;$i<=$#ethernet_sys;$i++) {
956 $ethx="$ethernet_sys[$i]";
957 my $grp=$ethx;
958 # extract group for ethx, i.e. group 1 for eth1, group 3 for eth3...
959 # For interface like vmnet1, we will not extract that so that the
960 # hostname will not conflict.
961 $grp=~ s/eth//;
962 # get the total client number. total_client[$i] is only for those connecting to ethx
963 $total_client_no += $total_client[$i];
964 #
965 print
966 "| +-- [$ethx] $ip_sys[$i] +- to clients group $grp [ $total_client[$i] clients, their IP \n".
967 "| | from $ip_sys_start[$i] - $ip_sys_end[$i]]\n";
968 }
969
970 print
971 "+-----------------------------+\n";
972 print color 'reset';
973 print
974 "$delimiter{\"star_line\"}\n";
975
976 print "Total clients: ".
977 colored ("$total_client_no\n", "$color_warn").
978 "$delimiter{\"star_line\"}\n".
979 "$lang_deploy{\"press_enter_to_continue\"}";
980 chomp($line=<STDIN>);
981
982 # Ask user if DRBL SSI mode ?
983 print "$delimiter{\"star_line\"}\n";
984 if ( ! $drbl_mode ) {
985 print "$delimiter{\"dash_line\"}\n".
986 "$lang_deploy{\"which_drbl_mode_for_client\"}\n".
987 "[0] ";
988 chomp($drbl_mode=<STDIN>);
989 }
990 SWITCH: for ($drbl_mode) {
991 /^[[:space:]]*1[[:space:]]*$/ && do {
992 $drbl_mode="drbl_ssi_mode";
993 print "$lang_deploy{\"drbl_ssi_mode_is_set\"}\n".
994 "$delimiter{\"star_line\"}\n";
995 last SWITCH;
996 };
997 /^[[:space:]]*2[[:space:]]*$/ && do {
998 $drbl_mode="none";
999 # since no diskless service for client in the system,
1000 # set some default value to avoid asking laster.
1001 $swap_create="no";
1002 $client_startup_mode="2"; # text mode
1003 $set_client_root_passwd="no";
1004 $set_DBN_client_audio_plugdev="no";
1005 $set_client_alias_IP="no";
1006 $open_thin_client_option="no";
1007 print colored ("$lang_deploy{\"no_drbl_mode_in_system\"}\n", "$color_warn").
1008 "$delimiter{\"star_line\"}\n";
1009 last SWITCH;
1010 };
1011 /.*/ && do {
1012 $drbl_mode="full_drbl_mode";
1013 print "$lang_deploy{\"full_drbl_mode_is_set\"}\n".
1014 "$delimiter{\"star_line\"}\n";
1015 last SWITCH;
1016 };
1017 }
1018 # Ask user if clonezilla box mode ?
1019 if ( ! $clonezilla_mode ) {
1020 print "$delimiter{\"dash_line\"}\n".
1021 "$lang_deploy{\"which_clonezilla_mode_for_client\"}\n".
1022 "[0] ";
1023 chomp($clonezilla_mode=<STDIN>);
1024 }
1025 SWITCH: for ($clonezilla_mode) {
1026 /^[[:space:]]*1[[:space:]]*$/ && do {
1027 $clonezilla_mode="clonezilla_box_mode";
1028 print "$lang_deploy{\"clonezilla_box_mode_is_set\"}\n".
1029 "$delimiter{\"star_line\"}\n";
1030 last SWITCH;
1031 };
1032 /^[[:space:]]*2[[:space:]]*$/ && do {
1033 $clonezilla_mode="none";
1034 # since no clonezilla in the system,
1035 # set some default value to avoid asking laster.
1036 $ocs_img_repo_dir="$ocs_img_repo_dir_default";
1037 print colored ("$lang_deploy{\"no_clonezilla_in_system\"}\n", "$color_warn").
1038 "$delimiter{\"star_line\"}\n";
1039 last SWITCH;
1040 };
1041 /^[[:space:]]*3[[:space:]]*$/ && do {
1042 $clonezilla_mode="clonezilla_live_mode";
1043 print "$lang_deploy{\"clonezilla_live_mode_is_set\"}\n".
1044 "$delimiter{\"star_line\"}\n";
1045 last SWITCH;
1046 };
1047 /.*/ && do {
1048 $clonezilla_mode="full_clonezilla_mode";
1049 print "$lang_deploy{\"full_clonezilla_mode_is_set\"}\n".
1050 "$delimiter{\"star_line\"}\n";
1051 last SWITCH;
1052 };
1053 }
1054 # Ask client's CPU arch when running Clonezilla job with Clonezilla live
1055 if ( "$run_drbl_ocs_live_prep" eq "yes" ) {
1056 if ( "$clonezilla_mode" eq "clonezilla_live_mode" ) {
1057 if ( ! "$live_client_branch" ) {
1058 print "$delimiter{\"star_line\"}\n".
1059 "$lang_deploy{\"which_clonezilla_live_branch\"}\n".
1060 "[2] ";
1061 chomp($live_client_branch=<STDIN>);
1062 }
1063 if ( ! "$live_client_cpu_mode" ) {
1064 if ( "$live_client_branch" eq "0" || "$live_client_branch" eq "1" ) {
1065 print "$delimiter{\"star_line\"}\n".
1066 "$lang_deploy{\"which_live_client_cpu_mode\"}\n".
1067 "[2] ";
1068 chomp($live_client_cpu_mode=<STDIN>);
1069 }else{
1070 # For Ubuntu-based Clonezilla live, different arch is not available.
1071 # Only amd64 is available in Ubuntu >= 19.10
1072 print "$lang_deploy{\"from_ubuntu_1910_only_amd64_is_available\"}\n";
1073 }
1074 }
1075 }
1076 # Format the input number as text
1077 SWITCH: for ($live_client_branch) {
1078 /^[[:space:]]*0[[:space:]]*$/ && do {
1079 $live_client_branch="stable";
1080 last SWITCH;
1081 };
1082 /^[[:space:]]*1[[:space:]]*$/ && do {
1083 $live_client_branch="testing";
1084 last SWITCH;
1085 };
1086 /^[[:space:]]*3[[:space:]]*$/ && do {
1087 $live_client_branch="alternative_testing";
1088 last SWITCH;
1089 };
1090 /.*/ && do {
1091 $live_client_branch="alternative";
1092 last SWITCH;
1093 };
1094 }
1095 if ( $live_client_cpu_mode ) {
1096 print "$delimiter{\"star_line\"}\n";
1097 print "$lang_deploy{\"live_client_branch_set\"}: $live_client_branch\n";
1098 }
1099 # Format the input number as text
1100 if ( "$live_client_branch" eq "stable" || "$live_client_branch" eq "testing" ) {
1101 # Normal Clonezilla live, i686, i686-pae and amd64 exist
1102 SWITCH: for ($live_client_cpu_mode) {
1103 /^[[:space:]]*0[[:space:]]*$/ && do {
1104 $live_client_cpu_mode="i686";
1105 last SWITCH;
1106 };
1107 /^[[:space:]]*1[[:space:]]*$/ && do {
1108 $live_client_cpu_mode="i686-pae";
1109 last SWITCH;
1110 };
1111 /^[[:space:]]*2[[:space:]]*$/ && do {
1112 $live_client_cpu_mode="amd64";
1113 last SWITCH;
1114 };
1115 /.*/ && do {
1116 $live_client_cpu_mode="amd64";
1117 last SWITCH;
1118 };
1119 }
1120 }else{
1121 # Alternative Clonezilla live, only amd64 exists from Ubuntu >= 19.10
1122 $live_client_cpu_mode="amd64";
1123 }
1124 if ( $live_client_cpu_mode ) {
1125 print "$delimiter{\"star_line\"}\n";
1126 print "$lang_deploy{\"live_client_cpu_arch_is_set\"}: $live_client_cpu_mode\n";
1127 }
1128 }
1129
1130 if ( "$drbl_mode" eq "none" && "$clonezilla_mode" eq "none" ) {
1131 print colored ("$lang_deploy{\"both_drbl_clonezilla_are_none\"}\n", "$color_warn");}
1132 # Ask user what's clonezilla image's repository ?
1133 #
1134 if ( ! $ocs_img_repo_dir ) {
1135 print "$delimiter{\"dash_line\"}\n".
1136 "$lang_deploy{\"where_is_ocs_img_repo_dir\"}\n".
1137 "[$ocs_img_repo_dir_default] ";
1138 while (<STDIN>) {
1139 chomp;
1140 $ocs_img_repo_dir=$_;
1141 if ( "$ocs_img_repo_dir" =~ /\/mnt$|\/media$|\/tmp$/ ) {
1142 print "$ocs_img_repo_dir $lang_deploy{\"not_allowed_ocs_img_repo_dir\"} $lang_deploy{\"enter_it_again\"}!\n".
1143 "[$ocs_img_repo_dir_default] ";
1144 } else {
1145 # if empty, use default name
1146 if ($ocs_img_repo_dir eq "") { $ocs_img_repo_dir="$ocs_img_repo_dir_default"; }
1147 print colored ("Directory for Clonezilla saved images: $ocs_img_repo_dir\n", "$color_warn");
1148 last;
1149 }
1150 }
1151 }
1152
1153 # ask if use need local HD space as swap file ?
1154 if ( ! $swap_create ) {
1155 print "$delimiter{\"dash_line\"}\n".
1156 "$lang_deploy{\"swap_prompt\"}\n".
1157 "[Y/n] ";
1158 chomp($swap_create=<STDIN>);
1159 }
1160 SWITCH: for ($swap_create) {
1161 /^n$|^no$/i && do {
1162 $localswapfile="no";
1163 last SWITCH;
1164 };
1165 /.*/ && do {
1166 $localswapfile="yes";
1167 print "$delimiter{\"star_line\"}\n".
1168 "$lang_deploy{\"try_to_create_swap\"}\n".
1169 "$delimiter{\"dash_line\"}\n".
1170 "$lang_deploy{\"max_swap_size\"}\n".
1171 "[$MAXSWAPSIZE_DEFAULT] ";
1172 chomp($maxswapsize=<STDIN>);
1173 if ( "$maxswapsize" eq "" ) {
1174 $maxswapsize="$MAXSWAPSIZE_DEFAULT";
1175 print colored ("maxswapsize=$maxswapsize\n", "$color_warn");
1176 }
1177 last SWITCH;
1178 };
1179 }
1180
1181 # Ask which mode is preferred for clients
1182 print "$delimiter{\"star_line\"}\n";
1183 if ( ! $client_startup_mode ) {
1184 print "$delimiter{\"dash_line\"}\n".
1185 "$lang_deploy{\"mode_for_client_init\"}\n".
1186 "[1] ";
1187 chomp($client_startup_mode=<STDIN>);
1188 }
1189 if ($client_startup_mode eq "2") {
1190 $CLIENT_INIT="text";
1191 print "$lang_deploy{\"client_text_mode\"}\n".
1192 "$delimiter{\"star_line\"}\n";
1193 }else{
1194 $CLIENT_INIT="graphic";
1195 print "$lang_deploy{\"client_graphic_mode\"}\n".
1196 "$delimiter{\"star_line\"}\n";
1197 print "$delimiter{\"dash_line\"}\n".
1198 "$lang_deploy{\"login_mode_for_client\"}\n".
1199 "[0] ";
1200 chomp($login_gdm_opt=<STDIN>);
1201 if ($login_gdm_opt eq "1") {
1202 $LOGIN_GDM_OPT="auto_login";
1203 set_autologin_passwd;
1204 print "$lang_deploy{\"auto_login\"}\n".
1205 "$delimiter{\"star_line\"}\n";
1206 print "[$total_client_no] $lang_deploy{\"created_account_for_auto_login\"}".
1207 " \"$AUTO_LOGIN_ID_PASSWD\"\n";
1208 } elsif ($login_gdm_opt eq "2") {
1209 $LOGIN_GDM_OPT="timed_login";
1210 print "$delimiter{\"dash_line\"}\n".
1211 "$lang_deploy{\"time_for_countdown\"}\n".
1212 "[$TIMED_GDM_TIME_DEFAULT] ";
1213 chomp($timed_time=<STDIN>);
1214 if ($timed_time eq "") {
1215 $TIMED_LOGIN_TIME = "$TIMED_GDM_TIME_DEFAULT";
1216 }else{
1217 $TIMED_LOGIN_TIME = $timed_time;
1218 }
1219 print "$lang_deploy{\"timed_login_prompt\"} $TIMED_LOGIN_TIME $lang_text{\"seconds\"}.\n".
1220 "$delimiter{\"star_line\"}\n";
1221 print "[$total_client_no] $lang_deploy{\"created_account_for_auto_login\"}".
1222 " \"$AUTO_LOGIN_ID_PASSWD\"\n";
1223 } else {
1224 $LOGIN_GDM_OPT="login";
1225 print "$lang_deploy{\"normal_login_prompt\"}\n".
1226 "$delimiter{\"star_line\"}\n";
1227 }
1228 }
1229 # Ask if user want to set the root password of clients
1230 if ( ! $set_client_root_passwd ){
1231 print "$delimiter{\"dash_line\"}\n".
1232 "$lang_deploy{\"set_client_root_passwd\"}\n".
1233 "[y/N] ";
1234 chomp($set_client_root_passwd=<STDIN>);
1235 }
1236 SWITCH: for ($set_client_root_passwd) {
1237 /^y$|^yes$/i && do {
1238 $set_client_root_passwd="yes";
1239 # we set 2 different passwords to make while loop works.
1240 $client_root_passwd_1="init1";
1241 $client_root_passwd_2="init2";
1242 while ($client_root_passwd_1 ne $client_root_passwd_2 || ($client_root_passwd_1 eq "" && $client_root_passwd_2 eq "" )) {
1243 print "$lang_deploy{\"whats_client_root_passwd\"}\n";
1244 # turn off echo
1245 system "LC_ALL=C stty -echo";
1246 chomp($client_root_passwd_1=<STDIN>);
1247 # turn on echo
1248 system "LC_ALL=C stty echo";
1249 print "$lang_deploy{\"retype_root_passwd\"}\n";
1250 system "LC_ALL=C stty -echo";
1251 chomp($client_root_passwd_2=<STDIN>);
1252 system "LC_ALL=C stty echo";
1253 if ($client_root_passwd_1 ne $client_root_passwd_2) {
1254 print colored ("$lang_deploy{\"sorry_passwd_not_match\"}\n", "$color_warn");
1255 }elsif ($client_root_passwd_1 eq "" && $client_root_passwd_2 eq "" ){
1256 print colored ("$lang_deploy{\"sorry_passwd_can_not_empty\"}\n", "$color_warn");
1257 }
1258 }
1259 $client_root_passwd=$client_root_passwd_1;
1260 last SWITCH;
1261 };
1262 /.*/ && do {
1263 $set_client_root_passwd="no";
1264 print "$lang_deploy{\"ok_let_continue\"}\n";
1265 last SWITCH;
1266 };
1267 }
1268
1269 # Ask if user want to set the pxelinux password of clients
1270 print "$delimiter{\"dash_line\"}\n".
1271 "$lang_deploy{\"set_client_pxelinux_passwd\"}\n".
1272 "[y/N] ";
1273 chomp($set_client_pxelinux_passwd=<STDIN>);
1274 SWITCH: for ($set_client_pxelinux_passwd) {
1275 /^y$|^yes$/i && do {
1276 $set_client_pxelinux_passwd="yes";
1277 # we set 2 different passwords to make while loop works.
1278 $client_pxelinux_passwd_1="pxeinit1";
1279 $client_pxelinux_passwd_2="pxeinit2";
1280 while ($client_pxelinux_passwd_1 ne $client_pxelinux_passwd_2 || ($client_pxelinux_passwd_1 eq "" && $client_pxelinux_passwd_2 eq "" )) {
1281 print "$lang_deploy{\"whats_client_pxelinux_passwd\"}\n";
1282 # turn off echo
1283 system "LC_ALL=C stty -echo";
1284 chomp($client_pxelinux_passwd_1=<STDIN>);
1285 # turn on echo
1286 system "LC_ALL=C stty echo";
1287 print "$lang_deploy{\"retype_root_passwd\"}\n";
1288 system "LC_ALL=C stty -echo";
1289 chomp($client_pxelinux_passwd_2=<STDIN>);
1290 system "LC_ALL=C stty echo";
1291 if ($client_pxelinux_passwd_1 ne $client_pxelinux_passwd_2) {
1292 print colored ("$lang_deploy{\"sorry_passwd_not_match\"}\n", "$color_warn");
1293 }elsif ($client_pxelinux_passwd_1 eq "" && $client_pxelinux_passwd_2 eq "" ){
1294 print colored ("$lang_deploy{\"sorry_passwd_can_not_empty\"}\n", "$color_warn");
1295 }
1296 }
1297 $client_pxelinux_passwd=$client_pxelinux_passwd_1;
1298 last SWITCH;
1299 };
1300 /.*/ && do {
1301 $set_client_pxelinux_passwd="no";
1302 print "$lang_deploy{\"ok_let_continue\"}\n";
1303 last SWITCH;
1304 };
1305 }
1306
1307 # Ask if user want to set the boot prompt for clients
1308 if ( $set_client_pxelinux_passwd eq "no" ) {
1309 print "$delimiter{\"dash_line\"}\n".
1310 "$lang_deploy{\"set_client_system_select\"}\n".
1311 "[Y/n] ";
1312 chomp($set_client_system_select=<STDIN>);
1313 SWITCH: for ($set_client_system_select) {
1314 /^n$|^no$/i && do {
1315 $set_client_system_select="no";
1316 last SWITCH;
1317 };
1318 /.*/ && do {
1319 $set_client_system_select="yes";
1320 while ($client_system_boot_timeout eq "") {
1321 print "$lang_deploy{\"whats_client_system_boot_timeout\"}\n".
1322 "[$DEFAULT_CLIENT_SYSTEM_BOOT_TIMEOUT] ";
1323 chomp($client_system_boot_timeout_=<STDIN>);
1324 if ( "$client_system_boot_timeout_" =~ /[^0-9]/ ) {
1325 print colored ("$lang_deploy{\"sorry_timeout_must_be_number\"}\n", "$color_warn");
1326 } else {
1327 # if empty, use default timeout
1328 if ($client_system_boot_timeout_ eq "") {
1329 $client_system_boot_timeout_="$DEFAULT_CLIENT_SYSTEM_BOOT_TIMEOUT";
1330 }
1331 $client_system_boot_timeout="$client_system_boot_timeout_";
1332 }
1333 }
1334 print "$lang_deploy{\"ok_let_continue\"}\n";
1335 print "$delimiter{\"dash_line\"}\n";
1336 last SWITCH;
1337 };
1338 }
1339 }
1340
1341 # Ask if user want to use graphic pxe boot menu for clients
1342 # When serial console is found in pxelinux config file, force to set
1343 # $use_graphic_pxelinux_menu=no
1344 # When CLIENT_INIT is chosen as text mode, default to use txt PXE menu
1345 my $SERIAL_CONSOLE=`LC_ALL=C grep -Ewi "^serial" $pxecfg_pd/pxelinux.cfg/default 2>/dev/null`;
1346 if ( $SERIAL_CONSOLE ){
1347 print "Serial console parameters are found in $pxecfg_pd/pxelinux.cfg/default. Force to use text PXELINUX menu, no graphic background.\n";
1348 $use_graphic_pxelinux_menu="no"
1349 }
1350 if ( "$CLIENT_INIT" eq "text"){
1351 $graphic_pxelinux_menu_default="no";
1352 $graphic_pxelinux_menu_prompt="y/N";
1353 }else{
1354 $graphic_pxelinux_menu_default="yes";
1355 $graphic_pxelinux_menu_prompt="Y/n";
1356 }
1357 if ( ! $use_graphic_pxelinux_menu ) {
1358 print "$delimiter{\"dash_line\"}\n".
1359 "$lang_deploy{\"use_graphic_pxelinux_menu\"}\n".
1360 colored ("$lang_deploy{\"note_for_use_graphic_pxelinux_menu\"}\n", "$color_warn").
1361 "[$graphic_pxelinux_menu_prompt] ";
1362 chomp($use_graphic_pxelinux_menu=<STDIN>);
1363 if ( ! $use_graphic_pxelinux_menu ) { $use_graphic_pxelinux_menu=$graphic_pxelinux_menu_default }
1364 SWITCH: for ($use_graphic_pxelinux_menu) {
1365 /^n$|^no$/i && do {
1366 print "Use text PXE Linux menu for the client.\n";
1367 $use_graphic_pxelinux_menu="no";
1368 last SWITCH;
1369 };
1370 /.*/ && do {
1371 print "Use graphic PXE Linux menu for the client.\n";
1372 $use_graphic_pxelinux_menu="yes";
1373 last SWITCH;
1374 };
1375 }
1376 }
1377 print "$delimiter{\"dash_line\"}\n";
1378
1379 # If Debian, ask if user want to set group plugdev and audio open
1380 # to all users
1381 if (-f "/etc/debian_version") {
1382 if ( ! $set_DBN_client_audio_plugdev ) {
1383 print "$delimiter{\"dash_line\"}\n".
1384 "$lang_deploy{\"set_DBN_client_audio_plugdev_etc_open_to_all\"}\n".
1385 "[Y/n] ";
1386 chomp($set_DBN_client_audio_plugdev=<STDIN>);
1387 }
1388 SWITCH: for ($set_DBN_client_audio_plugdev) {
1389 /^n$|^no$/i && do {
1390 $set_DBN_client_audio_plugdev="no";
1391 last SWITCH;
1392 };
1393 /.*/ && do {
1394 $set_DBN_client_audio_plugdev="yes";
1395 print "$lang_deploy{\"ok_let_continue\"}\n";
1396 print "$delimiter{\"dash_line\"}\n";
1397 last SWITCH;
1398 };
1399 }
1400 }
1401
1402 # Ask if user want to set the public IP for clients
1403 if ( ! $set_client_alias_IP ) {
1404 print "$delimiter{\"dash_line\"}\n".
1405 "$lang_deploy{\"set_client_alias_IP\"}\n".
1406 "[y/N] ";
1407 chomp($set_client_alias_IP=<STDIN>);
1408 }
1409 SWITCH: for ($set_client_alias_IP) {
1410 /^y$|^yes$/i && do {
1411 $set_client_public_ip_opt="yes";
1412 last SWITCH;
1413 };
1414 /.*/ && do {
1415 $set_client_public_ip_opt="no";
1416 last SWITCH;
1417 };
1418 }
1419
1420 # Ask if user want to open the thin-client mode
1421 if ( ! $open_thin_client_option ) {
1422 print "$delimiter{\"dash_line\"}\n".
1423 "$lang_deploy{\"open_thin_client_option\"}\n".
1424 "[y/N] ";
1425 chomp($open_thin_client_option=<STDIN>);
1426 }
1427 SWITCH: for ($open_thin_client_option) {
1428 /^y$|^yes$/i && do {
1429 $open_thin_client_option="yes";
1430 last SWITCH;
1431 };
1432 /.*/ && do {
1433 $open_thin_client_option="no";
1434 print "$lang_deploy{\"ok_let_continue\"}\n";
1435 print "$delimiter{\"dash_line\"}\n";
1436 last SWITCH;
1437 };
1438 }
1439
1440 # Ask if user want to turn DRBL server as a NAT server
1441 if ( ! $drbl_server_as_NAT_server ) {
1442 print "$delimiter{\"dash_line\"}\n".
1443 "$lang_deploy{\"drbl_server_as_NAT_server\"}\n".
1444 "[Y/n] ";
1445 chomp($drbl_server_as_NAT_server=<STDIN>);
1446 }
1447 SWITCH: for ($drbl_server_as_NAT_server) {
1448 /^n$|^no$/i && do {
1449 $drbl_server_as_NAT_server="no";
1450 print colored ("$lang_deploy{\"drbl_server_is_NOT_NAT_server\"}\n", "$color_warn");
1451 last SWITCH;
1452 };
1453 /.*/ && do {
1454 $drbl_server_as_NAT_server="yes";
1455 print "$lang_deploy{\"ok_let_continue\"}\n";
1456 print "$delimiter{\"dash_line\"}\n";
1457 last SWITCH;
1458 };
1459 }
1460
1461 # Ask if user want to purge client files if they exist
1462 $client_exist_flag=system("LC_ALL=C ls -d /tftpboot/nodes/* >/dev/null 2>&1") / 256;
1463 if ($client_exist_flag eq 0) {
1464 # old clients exist
1465 if ( ! $keep_client ) {
1466 print "$delimiter{\"dash_line\"}\n".
1467 "$lang_deploy{\"keep_client_setting_question\"}\n".
1468 "[Y/n] ";
1469 chomp($keep_client=<STDIN>);
1470 }
1471 SWITCH: for ($keep_client) {
1472 /^n$|^no$/i && do {
1473 $purge_client="yes";
1474 print "$lang_deploy{\"remove_client_setting\"}\n".
1475 "$delimiter{\"star_line\"}\n";
1476 last SWITCH;
1477 };
1478 /.*/ && do {
1479 $purge_client="no";
1480 print "$lang_deploy{\"keep_client_setting\"}\n".
1481 "$delimiter{\"star_line\"}\n";
1482 last SWITCH;
1483 };
1484 }
1485 }else{
1486 # old clients do NOT exist, so it's not necessary to clean old files
1487 $purge_client="no";
1488 }
1489
1490 #
1491 print "$delimiter{\"star_line\"}\n";
1492
1493 # output the config file
1494 print CONFIG_FILE <<END_CFG;
1495 #Setup for general
1496 [general]
1497 domain=$dnsdomain_sys
1498 nisdomain=$nisdomain_sys
1499 localswapfile=$localswapfile
1500 client_init=$CLIENT_INIT
1501 login_gdm_opt=$LOGIN_GDM_OPT
1502 timed_login_time=$TIMED_LOGIN_TIME
1503 maxswapsize=$maxswapsize
1504 ocs_img_repo_dir=$ocs_img_repo_dir
1505 total_client_no=$total_client_no
1506 create_account=$create_account
1507 account_passwd_length=$ACCOUNT_PASSWD_LENGTH_DEFAULT
1508 hostname=$client_hostname_prefix
1509 purge_client=$purge_client
1510 client_autologin_passwd=$client_autologin_passwd
1511 client_root_passwd=$client_root_passwd
1512 client_pxelinux_passwd=$client_pxelinux_passwd
1513 set_client_system_select=$set_client_system_select
1514 use_graphic_pxelinux_menu=$use_graphic_pxelinux_menu
1515 set_DBN_client_audio_plugdev=$set_DBN_client_audio_plugdev
1516 open_thin_client_option=$open_thin_client_option
1517 client_system_boot_timeout=$client_system_boot_timeout
1518 language=$language
1519 set_client_public_ip_opt=$set_client_public_ip_opt
1520 config_file=$DRBLPUSH_CONF
1521 collect_mac=$collect_mac
1522 run_drbl_ocs_live_prep=$run_drbl_ocs_live_prep
1523 drbl_ocs_live_server=$drbl_ocs_live_server
1524 clonezilla_mode=$clonezilla_mode
1525 live_client_branch=$live_client_branch
1526 live_client_cpu_mode=$live_client_cpu_mode
1527 drbl_mode=$drbl_mode
1528 drbl_server_as_NAT_server=$drbl_server_as_NAT_server
1529 add_start_drbl_services_after_cfg=$add_start_drbl_services_after_cfg
1530 continue_with_one_port=$continue_with_one_port
1531
1532 END_CFG
1533
1534
1535 for($i=0;$i<=$#ethernet_sys;$i++) {
1536 my $ethx=$ethernet_sys[$i];
1537 if ( ! $MAC_file[$i] ){
1538 # output the range format
1539 print CONFIG_FILE <<END_CFG;
1540 #Setup for $ethx
1541 [$ethx]
1542 interface=$ethx
1543 range=$range_start[$i]-$range_end[$i]
1544 END_CFG
1545 }else{
1546 # output the MAC format
1547 print CONFIG_FILE <<END_CFG;
1548 #Setup for $ethx
1549 [$ethx]
1550 interface=$ethx
1551 mac=$MAC_file[$i]
1552 ip_start=$range_start[$i]
1553 END_CFG
1554 }
1555 # Put gateway if only one ethernet port is available, i.e. No NAT on this server.
1556 if ( $#ethernet_list == 0 ) { # Only one port
1557 my $gateway;
1558 chomp($gateway=`LANG=C PATH=$PATH:/sbin/:/usr/sbin route -n | awk '/^0.0.0.0/ {print \$2}'`);
1559 print CONFIG_FILE <<END_CFG;
1560 gateway=$gateway
1561 END_CFG
1562 }
1563 # Append a space line
1564 print CONFIG_FILE <<END_CFG;
1565
1566 END_CFG
1567 }
1568
1569 close(CONFIG_FILE);
1570 # set mode for more secure
1571 system("LC_ALL=C chmod 600 $DRBLPUSH_CONF");
1572
1573 }#end of interactive_mode
1574
1575 # subroutine to read file, parse them as parameters
1576 # in: config_file
1577 # out: hash of hash reference
1578 sub read_config {
1579
1580 my %HoH = ();
1581 my $KoH="general";
1582 my $key="",$value="";
1583
1584 open(CONFIG,$_[0]) or die "Can NOT find file \"$_[0]\"! \nPlease check your config file!\n";
1585 while(<CONFIG>) {
1586 if($_=~/^#.*/) {
1587 # ignore comment
1588 #print "ignore $_\n";
1589 }
1590 elsif($_=~/\[.*\]/) {
1591 # has key
1592 chop;
1593 my $key_ = $_;
1594 # skip the comments
1595 $key_ =~ s/#.*//;
1596 # delete the spaces
1597 $key_ =~ s/ //g;
1598 $KoH=substr($key_,1,length($key_)-2);
1599 }
1600 else {
1601 # hash value
1602 chop;
1603 if( 0 == length($_) ) { next; }
1604 ($key,$value)=split(/=/);
1605 # Turn all the key to uppercase
1606 $key=uc($key);
1607 # skip the comments
1608 $value =~ s/#.*//;
1609 # delete the spaces
1610 $value =~ s/ //g;
1611 #print "KoH=$KoH, key=$key, value=$value\n";
1612 $HoH{ $KoH }{ $key }= $value;
1613 }
1614 }
1615 close(CONFIG);
1616
1617 return( \%HoH );
1618 }
1619
1620 sub drbl_server_parse {
1621 # Part 1,
1622 # get enough information, setup the DRBL server
1623 #
1624 my $DNS_sys="/etc/resolv.conf";
1625 my $rHoH = read_config($_[0]);
1626
1627 my $nameserver=$rHoH->{"general"}{"NAMESERVER"};
1628 my $domain=$rHoH->{"general"}{"DOMAIN"};
1629 my $nisdomain=$rHoH->{"general"}{"NISDOMAIN"};
1630 my $nfsserver_default=$rHoH->{"general"}{"NFSSERVER_DEFAULT"};
1631 my $localswapfile=$rHoH->{"general"}{"LOCALSWAPFILE"};
1632 my $CLIENT_INIT=$rHoH->{"general"}{"CLIENT_INIT"};
1633 my $maxswapsize=$rHoH->{"general"}{"MAXSWAPSIZE"};
1634 my $ocs_img_repo_dir=$rHoH->{"general"}{"OCS_IMG_REPO_DIR"};
1635 my $purge_client=$rHoH->{"general"}{"PURGE_CLIENT"};
1636 my $language=$rHoH->{"general"}{"LANGUAGE"};
1637 my $set_client_system_select=$rHoH->{"general"}{"SET_CLIENT_SYSTEM_SELECT"};
1638 my $use_graphic_pxelinux_menu=$rHoH->{"general"}{"USE_GRAPHIC_PXELINUX_MENU"};
1639 my $set_DBN_client_audio_plugdev=$rHoH->{"general"}{"SET_DBN_CLIENT_AUDIO_PLUGDEV"};
1640 my $open_thin_client_option=$rHoH->{"general"}{"OPEN_THIN_CLIENT_OPTION"};
1641 my $client_system_boot_timeout=$rHoH->{"general"}{"CLIENT_SYSTEM_BOOT_TIMEOUT"};
1642 my $set_client_public_ip_opt=$rHoH->{"general"}{"SET_CLIENT_PUBLIC_IP_OPT"};
1643 my $config_file=$rHoH->{"general"}{"CONFIG_FILE"};
1644 my $collect_mac=$rHoH->{"general"}{"COLLECT_MAC"};
1645 my $client_root_passwd=$rHoH->{"general"}{"CLIENT_ROOT_PASSWD"};
1646 my $client_pxelinux_passwd=$rHoH->{"general"}{"CLIENT_PXELINUX_PASSWD"};
1647 my $clonezilla_mode=$rHoH->{"general"}{"CLONEZILLA_MODE"};
1648 my $run_drbl_ocs_live_prep=$rHoH->{"general"}{"RUN_DRBL_OCS_LIVE_PREP"};
1649 my $drbl_ocs_live_server=$rHoH->{"general"}{"DRBL_OCS_LIVE_SERVER"};
1650 my $live_client_branch=$rHoH->{"general"}{"LIVE_CLIENT_BRANCH"};
1651 my $live_client_cpu_mode=$rHoH->{"general"}{"LIVE_CLIENT_CPU_MODE"};
1652 my $drbl_mode=$rHoH->{"general"}{"DRBL_MODE"};
1653 my $drbl_server_as_NAT_server=$rHoH->{"general"}{"DRBL_SERVER_AS_NAT_SERVER"};
1654 # Note! We do not write and read $sh_debug and $verbose_opt to and from config file, since they are runtime parameter
1655
1656 # for login GDM
1657 my $login_gdm_opt=$rHoH->{"general"}{"LOGIN_GDM_OPT"};
1658 my $timed_login_time=$rHoH->{"general"}{"TIMED_LOGIN_TIME"};
1659
1660 # for auto login or timed login account
1661 my $create_account=$rHoH->{"general"}{"CREATE_ACCOUNT"};
1662 my $account_prefix=$rHoH->{"general"}{"ACCOUNT_PREFIX"};
1663 my $account_passwd_length=$rHoH->{"general"}{"ACCOUNT_PASSWD_LENGTH"};
1664 my $total_client_no=$rHoH->{"general"}{"TOTAL_CLIENT_NO"};
1665 my $passwd_length=$rHoH->{"general"}{"ACCOUNT_PASSWD_LENGTH"};
1666 my $hostname_prefix=$rHoH->{"general"}{"HOSTNAME"};
1667 my $client_autologin_passwd=$rHoH->{"general"}{"CLIENT_AUTOLOGIN_PASSWD"};
1668 my $add_start_drbl_services_after_cfg=$rHoH->{"general"}{"ADD_START_DRBL_SERVICES_AFTER_CFG"};
1669 my $continue_with_one_port=$rHoH->{"general"}{"CONTINUE_WITH_ONE_PORT"};
1670
1671 print "The GDM login option: $login_gdm_opt\n" if $verbosity >=2;
1672 print "timed_login_time: $timed_login_time\n" if $verbosity >=2;
1673 print "account_prefix: $account_prefix\n" if $verbosity >=2;
1674 print "total_client_no: $total_client_no\n" if $verbosity >=2;
1675 print "passwd_length: $passwd_length\n" if $verbosity >=2;
1676 print "maxswapsize in system is $maxswapsize\n" if $verbosity >= 2;
1677 print "ocs_img_repo_dir in system is $ocs_img_repo_dir\n" if $verbosity >= 2;
1678 print "Hostname_prefix from config file: \"$hostname_prefix\".\n" if $verbosity >= 2;
1679
1680 # Try to get setting from system also
1681 chomp(my $nameserver_sys=`drbl-get-dnsserver`);
1682 print "nameserver in system is $nameserver_sys\n" if $verbosity >= 2;
1683
1684 # get some setting in this server so that if some parameters are not set,
1685 # we can use the one in this system.
1686 chomp($dnsdomain_sys=`dnsdomainname`);
1687 chomp($nisdomain_sys=`nisdomainname`);
1688 print "DNSDOMAIN in system is $dnsdomain_sys\n" if $verbosity >= 2;
1689 print "NISDOMAIN in system is $nisdomain_sys\n" if $verbosity >= 2;
1690
1691 # set nameserver, domain, nisdomain, the priority: use the config file first, if unset, then use the value in system
1692 if ( ! $nameserver ) {
1693 $nameserver = $nameserver_sys;
1694 print "* nameserver is not set in config file, \nthe one \"$nameserver\" got from system will be used.\n" if $verbosity >= 2;
1695 }
1696 if ( ! $nisdomain ) {
1697 $nisdomain = $nisdomain_sys;
1698 print "* nisdomain is not set in config file, \nthe one \"$nisdomain\" got from system will be used.\n" if $verbosity >= 2;
1699 }
1700 if ( ! $domain ) {
1701 $domain = $dnsdomain_sys;
1702 print "* dnsdomain is not set in config file, \nthe one got \"$domain\" from system will be used.\n" if $verbosity >= 2;
1703 }
1704
1705 # check if the values are set in config file or system, just in case
1706 if ( ! $nameserver ) {
1707 print "Error! NAMESERVER is unset!\n";
1708 print "Please set it in config file \"$_[0]\" or $DNS_sys.\n";
1709 exit;
1710 }
1711
1712 if ( ! $nisdomain ) {
1713 print "Error! NISDOMAIN is unset!\n";
1714 print "Please set it in config file \"$_[0]\" or system config file.\n";
1715 exit;
1716 }
1717 if ( ! $domain ) {
1718 print "Error! DOMAIN unset!\n";
1719 print "Please set it in config file \"$_[0]\" or system config file.\n";
1720 exit;
1721 }
1722
1723 if ("$mode" eq "load_config_file") {
1724 # check public IP setting
1725 if ("$set_client_public_ip_opt" eq "yes" && ! -f "$drbl_syscfg/$public_ip_list") {
1726 print "$delimiter{\"star_line\"}\n".
1727 colored ("Unable to find the $drbl_syscfg/$public_ip_list; If you want to create the $drbl_syscfg/$public_ip_list, you must run \"drblpush\" in interactive mode (with -i option)!\n", "$color_warn").
1728 "$lang_deploy{\"press_enter_to_continue\"}";
1729 chomp($line=<STDIN>);
1730 print "$delimiter{\"dash_line\"}\n";
1731 }
1732 # check MAC address files
1733 if ("$collect_mac" eq "yes" ){ check_MAC_file("$drbl_syscfg","macadr-"); }
1734 }
1735
1736 #
1737 if ($localswapfile eq "y" || $localswapfile eq "Y" || $localswapfile eq "yes" || $localswapfile eq "YES") {
1738 $mkswapfile="mkswapfile";
1739 }else{
1740 $mkswapfile="";
1741 }
1742
1743 if ( "$login_gdm_opt" eq "timed_login" && ! $timed_login_time ) {
1744 print "You set config to timed login GDM, but there is no set time!\n".
1745 "We will set the time as $TIMED_GDM_TIME_DEFAULT seconds.\n";
1746 }
1747
1748 # detect kernel in server support udp over NFS or tcp over NFS (tcp is the default seting one for DRBL environment)
1749 # try to get if the kernel running the server supports NFS over TCP, if not, ust NFS over UDP
1750 $nfsd_tcp_rlt=system("#!/bin/bash; . $DRBL_SCRIPT_PATH/sbin/drbl-functions; check_kernel_nfsd_tcp_config");
1751 if ($nfsd_tcp_rlt == 256) {
1752 # set the protocol as udp
1753 $nfs_protocol="udp";
1754 }else{
1755 # set the protocol as tcp
1756 $nfs_protocol="tcp";
1757 }
1758 $nfs_protocol_uc=uc $nfs_protocol;
1759 print "$lang_deploy{\"server_kernel_nfsd_support\"} ".
1760 colored ("NFS over $nfs_protocol_uc", "$color_warn").
1761 "!\n".
1762 colored ("$lang_deploy{\"change_kernel_notes\"}\n", "$color_warn").
1763 "$lang_deploy{\"press_enter_to_continue\"}";
1764 chomp($line=<STDIN>);
1765 print "$delimiter{\"dash_line\"}\n";
1766
1767 #
1768 my $nameserver_=$nameserver;
1769 $nameserver_=~ s/\,/ /g;
1770
1771 # generate dhcpd.conf, hosts, $main_sh...
1772
1773 $main_sh="drbl_deploy.sh";
1774 # delete the old files
1775 unlink ($main_sh) if -f $main_sh;
1776 unlink (dhcpd.conf) if -f dhcpd.conf;
1777 unlink (nfsserver_all) if -f nfsserver_all;
1778 unlink (yp.conf) if -f yp.conf;
1779 unlink ($hosts_list) if -f $hosts_list;
1780 unlink ($CLIENT_IP_HOSTNAME_LIST) if -f $CLIENT_IP_HOSTNAME_LIST;
1781 unlink ($public_ip_list) if -f $public_ip_list;
1782 unlink ("kea-dhcp4.conf") if -f "kea-dhcp4.conf";
1783
1784 my @kea_subnets = ();
1785 my $primary_bootserver;
1786
1787 # open the config files for DRBL server
1788 open(DHCPD_OUT,">dhcpd.conf") or die "Can NOT write file \"dhcpd.conf\" \n";
1789 open(KEA_OUT,">kea-dhcp4.conf") or die "Can NOT write file \"kea-dhcp4.conf\" \n";
1790 open(NETGROUP_OUT,">netgroup") or die "Can NOT write file \"netgroup\"! \n";
1791 open(DISKLESS_OUT,">$main_sh") or die "Can NOT write file \"$main_sh\" \n";
1792 open(NFSSERVER_OUT,">nfsserver_all") or die "Can NOT write file \"nfsserver_all\" \n";
1793 open(YPCONF_SERVER,">yp.conf") or die "Can NOT write file \"yp.conf\" \n";
1794 open(HOSTS_LIST_OUT,">$hosts_list") or die "Can NOT write file \"$hosts_list\" \n";
1795 open(CLIENT_HOST_IP_LIST_OUT,">$CLIENT_IP_HOSTNAME_LIST") or die "Can NOT write file \"$CLIENT_IP_HOSTNAME_LIST\" \n";
1796 open(SWAPCONF_OUT,">mkswapfile") or die "Can NOT write file \"mkswapfile\" \n";
1797 open(GLOBAL_SETTING,">drbl_deploy.conf") or die "Can NOT write file \"drbl_deploy.conf\" \n";
1798
1799 ## get the etherboot zpxe filenames
1800 #print "Searching installed Etherboot files for dhcpd.conf... ";
1801 #chomp(my $etherboot_zpxe=`$query_pkglist_cmd drbl-etherboot | grep -E "eb-.*-etherboot-pci.zpxe\$" | xargs basename`);
1802 #chomp(my $sis900_zpxe=`$query_pkglist_cmd drbl-etherboot | grep -E "sis900.zpxe\$" | xargs basename`);
1803 #print "done! \n";
1804 my $pxe_file;
1805 if (-e "$pxecfg_pd/lpxelinux.0"){
1806 $pxe_file="lpxelinux.0";
1807 }else{
1808 $pxe_file="pxelinux.0";
1809 }
1810
1811 print "$delimiter{\"star_line\"}\n";
1812
1813 # some general option in dhcpd.conf, hosts, $main_sh
1814 print DHCPD_OUT <<EOF;
1815 # Generated by DRBL.
1816 # Do NOT modify this file unless you know what you are doing!
1817
1818 default-lease-time $DHCPD_DEFAULT_LEASE_TIME;
1819 max-lease-time $DHCPD_MAX_LEASE_TIME;
1820 option subnet-mask 255.255.255.0;
1821 option domain-name-servers $nameserver;
1822 option domain-name "$domain";
1823 ddns-update-style none;
1824 server-name drbl;
1825
1826 allow booting;
1827 allow bootp;
1828
1829 # For Raspberry Pi
1830 # Ref: https://www.raspberrypi.org/forums/viewtopic.php?t=209247
1831 # https://tools.ietf.org/html/rfc2132
1832 option vendor-specific-info code 43 = string; # Server - RFC 2132, 8.4
1833 option param-request-list code 55 = string; # Client - RFC 2132, 9.8
1834 option vendor-class-identifier code 60 = string; # Client - RFC 2132, 9.13
1835 option rpi-tftp-server code 66 = text; # Server - RFC 2132, 9.4
1836
1837 # Ref: Dynamic Host Configuration Protocol (DHCP) Options for the
1838 # Intel Preboot eXecution Environment (PXE)
1839 # https://tools.ietf.org/html/rfc4578
1840 # https://tools.ietf.org/html/rfc5071
1841 option arch code 93 = unsigned integer 16; # Client - RFC 4578, 2.1
1842 option space pxelinux;
1843 #option pxelinux.magic code 208 = string; # Server - RFC 5071, 3.2
1844 #option pxelinux.configfile code 209 = text; # Server - RFC 5071, 4.2
1845 #option pxelinux.pathprefix code 210 = text; # Server - RFC 5071, 5.2
1846 #option pxelinux.reboottime code 211 = unsigned integer 32; # Server - RFC 5071, 6.2
1847
1848 site-option-space "pxelinux";
1849
1850 if exists dhcp-parameter-request-list {
1851 # Always send the PXELINUX options (specified in hexadecimal, i.e.: 208=0xd0, 209=0xd1, etc.)
1852 option dhcp-parameter-request-list = concat(option dhcp-parameter-request-list,d0,d1,d2,d3);
1853 }
1854 # Ref:
1855 # http://www.syslinux.org/wiki/index.php/PXELINUX
1856 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=720589
1857 # //NOTE// From DRBL 2.15, bootia32.efi and bootx64.efi could be the one from
1858 # (1) syslinux (scripts/sbin/prepare-files-for-PXE-client)
1859 # or
1860 # (2) grub (drbl-gen-grub-efi-nb)
1861 # Ref: http://ipxe.org/cfg/platform. Thanks to Danny Russ for providing this.
1862 if option arch = 00:00 {
1863 # Intel x86PC or
1864 # Raspberry Pi, which should not declare itself as an Intel x86PC.
1865 # Ref: https://kiljan.org/2019/11/16/arch-linux-arm-network-boot-on-raspberry-pi-4/
1866 # We will overwrite it later in the class "raspberrypi".
1867 filename "lpxelinux.0";
1868 } else if option arch = 00:06 {
1869 # EFI IA32
1870 filename "bootia32.efi";
1871 } else if option arch = 00:07 or
1872 option arch = 00:09 {
1873 # EFI BC or EFI x86-64
1874 filename "bootx64.efi";
1875 } else if option arch = 00:0a {
1876 # armv7 (arm 32 bit)
1877 filename "bootarm.efi";
1878 } else if option arch = 00:0b or
1879 option arch = 00:16 {
1880 # aarch64 (arm 64 bit)
1881 # Rockpro64 (https://www.pine64.org/rockpro64) uses 00:16
1882 filename "bootaa64.efi";
1883 } else {
1884 # Default to Intel x86PC
1885 filename "lpxelinux.0";
1886 }
1887
1888 class "raspberrypi" {
1889 # Raspberry Pi, which should not declare itself as an Intel x86PC.
1890 # However, we still can identify it by some methods.
1891 # Ref: https://kiljan.org/2019/11/16/arch-linux-arm-network-boot-on-raspberry-pi-4/
1892 match if (
1893 (
1894 # Parameter list from Pi 3B ROM and old bootcode.bin
1895 binary-to-ascii(10,8,",",option param-request-list) =
1896 "43,60,67,128,129,130,131,132,133,134,135,66"
1897 # Parameter list from Pi 3B+ ROM and newer bootcode.bin
1898 or binary-to-ascii(10,8,",",option param-request-list) =
1899 "43,60,67,128,129,130,131,132,133,134,135,66,1,3"
1900 # Parameter list from Pi 4B EEPROM boot code (2019-10-16)
1901 or binary-to-ascii(10,8,",",option param-request-list) =
1902 "1,3,43,60,66,67,128,129,130,131,132,133,134,135"
1903 )
1904 and option vendor-class-identifier = "PXEClient:Arch:00000:UNDI:002001"
1905 and option arch = 00:00 # Architecture: Intel x86PC
1906 and (
1907 substring(hardware,1,3) = b8:27:eb # Pi Foundation OUI listing
1908 or substring(hardware,1,3) = dc:a6:32 # Raspberry Pi Trading Ltd OUI listing
1909 )
1910 );
1911 # There are extra 3 spaces in the end for vendor-specific-info, due to a bug in bootrom for Raspberry Pi <= 3
1912 # No need for Raspberry Pi 4, but it is OK to have that.
1913 # Ref: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/net.md
1914 option vendor-specific-info "Raspberry Pi Boot ";
1915 # bootcode.bin is not used on the Raspberry Pi 4, because it has been replaced by boot code in the onboard EEPROM.
1916 # Older model needs that.
1917 # Ref: https://www.raspberrypi.org/documentation/configuration/boot_folder.md
1918 filename "bootcode.bin";
1919 }
1920
1921 ## Uncomment the following "if block" when you have some buggy PXE NIC card (such as annoying sis900 NIC). Remember to modify the MAC vendor prefix and restart dhcpd service!!!
1922 ## This is a workround for some network card with BAD PXE code in firmware.
1923 ## It will only affect those clients with MAC vendor prefix you assigned.
1924 ## Ref: http://syslinux.zytor.com/archives/2005-August/005640.html
1925
1926 #if substring (option vendor-class-identifier, 0, 3) = "PXE" {
1927 # # **************************************************************
1928 # # ***MODIFY*** the MAC vendor prefix of client network card here.
1929 # # **************************************************************
1930 # # For annoying sis900 network card, maybe it is 00:07:95, 00:0C:6E...
1931 # if substring (hardware, 1, 3) = 00:0C:6E {
1932 # # sis900.zpxe is specially for sis900 NIC, you can download it from
1933 # # http://rom-o-matic.net/etherboot/etherboot-5.4.4/contrib/rom-o-matic
1934 # filename = "sis900.zpxe";
1935 # }
1936 #}
1937
1938 # Uncomment the following to get the debug/verbose messages in system log. The messages like the following will be shown:
1939 # PXEClient:Arch:00009:UNDI:003016
1940 # Begin of log command
1941 #log ( info, vendor-class-identifier ) ;
1942 # End of log command
1943
1944 # Uncomment the following to get the debug/verbose messages in system log. The messages like the following will be shown:
1945 # Client 0:c:29:1d:9a:d1 with arch 0:7 requests 1:2:3:4:5:6:c:d:f:11:12:16:17:1c:28:29:2a:2b:32:33:36:3a:3b:3c:42:43:61:80:81:82:83:84:85:86:87 - PXEClient:Arch:00007:UNDI:003016 - no dhcp-client-id
1946 # Client 0:c:29:e5:a4:2 with arch 0:0 requests 1:2:3:5:6:b:c:d:f:10:11:12:2b:36:3c:43:80:81:82:83:84:85:86:87 - PXEClient:Arch:00000:UNDI:002001 - no dhcp-client-id
1947 # Client 0:c:29:3b:34:fb with arch 0:0 requests 1:3:6:c:f:1c:28:29:2a - DRBLClient - no dhcp-client-id
1948 # Begin of log command
1949 #log(info, concat("Client ",
1950 # binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
1951 # " with arch ",
1952 # binary-to-ascii(16, 8, ":", option arch),
1953 # " requests ",
1954 # binary-to-ascii(16, 8, ":", option dhcp-parameter-request-list),
1955 # " - ",
1956 # pick-first-value(option vendor-class-identifier, "no vendor-id"),
1957 # " - ",
1958 # pick-first-value(option dhcp-client-identifier, "no dhcp-client-id"))
1959 # );
1960 # End of log command
1961
1962 # This class 'DRBL-Client' defines 3 kind of clients: PXE, Etherboot (1st stage) or DRBL client (2nd stage, i.e. in network initrd/initramfs (mkpxeinitrd-net)) to lease IP address. This will only affect 'range' statement only, not the 'host' statement.
1963 # Note! The following line(s) in the pool statement: 'allow members of "DRBL-Client";' is/are commented to disable this mechanism by default.
1964 # If you do want to use this mechanism, uncomment all 'allow members of "DRBL-Client";', then only PXE, etherboot and DRBL client can lease IP address from this DHCP service.
1965 # ///NOTE/// In summary, two cases you can turn on this mechanism:
1966 # (1) This DRBL server is not used as a clonezilla server.
1967 # (2) This DRBL server is used as a Clonezilla server, with the following conditions:
1968 # (a) 'range' statement is used in this DRBL service.
1969 # (b) There is an existing DHCP service which can provide IP address leases to the restored OS (either GNU/inux or MS Windows) in the client. Otherwise if you uncomment 'allow members of "DRBL-Client";', restored OS won't be able to lease IP address.
1970
1971 # The DRBL client class: PXE, Etherboot or DRBL client
1972 class "DRBL-Client" {
1973 match if
1974 (substring(option vendor-class-identifier, 0, 9) = "PXEClient") or
1975 (substring(option vendor-class-identifier, 0, 9) = "Etherboot") or
1976 (substring(option vendor-class-identifier, 0, 10) = "DRBLClient") ;
1977 }
1978
1979 # If you want to use special port for DHCP service, edit here:
1980 # For more info, ref: http://drbl.sourceforge.net/faq/index.php#path=./2_System&entry=37_coexist_with_existing_dhcp.faq
1981 # local-port 1067;
1982 # remote-port 1068;
1983
1984 EOF
1985
1986 # set the config file for mkswapfile
1987 print SWAPCONF_OUT "maxswapsize=$maxswapsize\n";
1988
1989 print CLIENT_HOST_IP_LIST_OUT "# Created by DRBL (drblpush), begin\n";
1990
1991 print NETGROUP_OUT "# Added by DRBL, begin\n";
1992 print NETGROUP_OUT "nodes ";
1993
1994 # write the nis client config file for server, i.e. ypbind will also run in
1995 # DRBL server, so that user can use yppasswd to change his passwd in server.
1996 # The yp server is the DRBL server, too, so we use localhost.
1997 print YPCONF_SERVER <<YPCONF_SERVER_EOF;
1998 domain $nisdomain server localhost
1999 YPCONF_SERVER_EOF
2000
2001 # output the global setting for drbl_deploy
2002 print GLOBAL_SETTING <<GLOBAL_EOF;
2003 ##################################
2004 # drbl_deploy global setting
2005 # File automatically created by drblpush.
2006 # It is better not to manually modify this file.
2007 ##################################
2008 config_file="$config_file"
2009 purge_client="$purge_client"
2010 client_root_passwd="$client_root_passwd"
2011 client_pxelinux_passwd="$client_pxelinux_passwd"
2012 language="$language"
2013 set_client_system_select="$set_client_system_select"
2014 use_graphic_pxelinux_menu="$use_graphic_pxelinux_menu"
2015 set_DBN_client_audio_plugdev="$set_DBN_client_audio_plugdev"
2016 open_thin_client_option="$open_thin_client_option"
2017 client_system_boot_timeout="$client_system_boot_timeout"
2018 collect_mac=$collect_mac
2019 total_client_no=$total_client_no
2020 nfs_protocol="$nfs_protocol"
2021 client_init="$CLIENT_INIT"
2022 mkswapfile="$mkswapfile"
2023 ocs_img_repo_dir="$ocs_img_repo_dir"
2024 nfsserver_default="$nfsserver_default"
2025 nameserver="$nameserver"
2026 nameserver_="$nameserver_"
2027 domain="$domain"
2028 nisdomain="$nisdomain"
2029 public_ip_list="$public_ip_list"
2030 login_gdm_opt="$login_gdm_opt"
2031 client_autologin_passwd="$client_autologin_passwd"
2032 timed_login_time="$TIMED_LOGIN_TIME"
2033 run_drbl_ocs_live_prep="$run_drbl_ocs_live_prep"
2034 drbl_ocs_live_server="$drbl_ocs_live_server"
2035 clonezilla_mode="$clonezilla_mode"
2036 live_client_branch="$live_client_branch"
2037 live_client_cpu_mode="$live_client_cpu_mode"
2038 drbl_mode="$drbl_mode"
2039 sh_debug="$sh_debug"
2040 verbose_opt="$verbose_opt"
2041 CLIENT_IP_HOSTNAME_LIST="$CLIENT_IP_HOSTNAME_LIST"
2042 drbl_server_as_NAT_server="$drbl_server_as_NAT_server"
2043 add_start_drbl_services_after_cfg="$add_start_drbl_services_after_cfg"
2044 continue_with_one_port="$continue_with_one_port"
2045 use_proxy_dhcp="$use_proxy_dhcp"
2046 ##################################
2047 # End of global setting
2048 ##################################
2049
2050 GLOBAL_EOF
2051
2052 close(GLOBAL_EOF);
2053 system("chmod 600 drbl_deploy.conf");
2054 system("mkdir -p $drbl_syscfg; cp -f drbl_deploy.conf $drbl_syscfg/");
2055
2056 print DISKLESS_OUT <<EOF;
2057 #!/bin/bash $sh_debug
2058 # **********************************************************************
2059 # File automatically created by drblpush,
2060 # better not to modify this file manually.
2061 # "drblpush" is written by K. L. Huang, klhaung _at_ gmail com,
2062 # especially for Debian, then modified to use with Redhat by
2063 # Steven Shiau, steven _at_ clonezilla org.
2064 # Ceasar Sun, ceasar _at_ nchc org tw
2065 # **********************************************************************
2066
2067 # Load DRBL setting and functions
2068 DRBL_SCRIPT_PATH="\${DRBL_SCRIPT_PATH:-/usr/share/drbl/}"
2069
2070 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
2071 . /etc/drbl/drbl_deploy.conf
2072
2073 # Get distribution ID and release number.
2074 [ -e /etc/lsb-release ] && . /etc/lsb-release
2075
2076 # get the l10n message
2077 if [ -f "$DRBL_SCRIPT_PATH/lang/bash/$language" ] ; then
2078 . $DRBL_SCRIPT_PATH/lang/bash/$language
2079 else
2080 echo "Not such language option!!!"
2081 exit 1
2082 fi
2083
2084 # store the orig LC_ALL, then set it as C
2085 LC_ALL_org=\$LC_ALL
2086 export LC_ALL=C
2087
2088 EOF
2089
2090 print DISKLESS_OUT q{
2091 # Decide the sysv init service control program is update-rc.d or insserv in Debian or Ubuntu. The output variable is "$dbn_ubn_serv_control_prog".
2092 if [ -e /etc/debian_version ]; then
2093 get_debian_ubuntu_init_serv_control_prog
2094
2095 # Jul/30/2015 Besides, due to this issue on Debian/Ubuntu:
2096 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=793760
2097 # we disabled efi_netboot_1st_in_nvram
2098 # otherwise for Clonezilla SE the uEFI clients will always enter Clonezilla
2099 # mode after finishing the previous Clonezilla job. One day when Debian/Ubuntu
2100 # applies the patch, we will enable it.
2101 # //NOTE// Sep/19/2015 We have used grub embedded preconfig way in drbl-gen-grub-efi-nb
2102 # to solve this issue:
2103 # http://lists.gnu.org/archive/html/help-grub/2015-09/msg00035.html
2104 # Therefore disable this.
2105 # LC_ALL=C perl -pi -e 's/^efi_netboot_1st_in_nvram=.*/efi_netboot_1st_in_nvram="no" # Disabled when running drblpush/g' /etc/drbl/drbl-ocs.conf
2106 fi
2107
2108 # Create the prerun/postrun dirs if they do not exist
2109 mkdir -p $DRBLPUSH_PRERUN_DIR $DRBLPUSH_POSTRUN_DIR
2110 # pre run
2111 if [ -n "$(unalias ls 2>/dev/null; ls $DRBLPUSH_PRERUN_DIR/ 2>/dev/null)" ]; then
2112 echo "Some files are found in $DRBLPUSH_PRERUN_DIR. Run them first..."
2113 drbl-run-parts $DRBLPUSH_PRERUN_DIR
2114 fi
2115 # check if the space is enough to setup DRBL
2116 echo -n "Checking the necessary disk space... "
2117 # When none full drbl mode AND none full clonezilla mode, only 1 client. Otherwise we will generate all the clients.
2118 if [ "$clonezilla_mode" != "full_clonezilla_mode" -a \
2119 "$drbl_mode" != "full_drbl_mode" ]; then
2120 total_client_no_for_checking="1"
2121 else
2122 total_client_no_for_checking="$total_client_no"
2123 fi
2124 space_check=$(check_drbl_setup_space -n $total_client_no_for_checking)
2125 rc=$?
2126 if [ "$rc" -gt 0 ]; then
2127 total_avail_space=$(echo $space_check | awk '{print $1}')
2128 drbl_need_space=$(echo $space_check | awk '{print $2}')
2129 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
2130 echo "$msg_total_avail_space: $total_avail_space (MB)"
2131 echo "$msg_necessary_space_setup_drbl: $drbl_need_space (MB)"
2132 echo "$msg_total_client_no: $total_client_no"
2133 echo "$msg_system_maybe_not_enough_space"
2134 echo "$msg_press_ctrl_c_stop!"
2135 echo "$msg_press_enter_to_continue"
2136 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
2137 read
2138 fi
2139 echo "done!"
2140
2141 # copy the config files to $drbl_syscfg...
2142 echo -n "Copying the config file to $drbl_syscfg... "
2143 mkdir -m 700 -p $drbl_syscfg
2144 cp -f $config_file $drbl_syscfg/
2145 [ -f $public_ip_list ] && cp -f $public_ip_list $drbl_syscfg/
2146 echo "done!"
2147
2148 # Do some checks...
2149 if [ "$(dirname $drbl_common_root)" = "/" ]; then
2150 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
2151 echo "You can NOT assign the drbl_common_root as / in drbl.conf!!!"
2152 echo "Program terminated!!!"
2153 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
2154 exit 1
2155 fi
2156
2157 # varlib_NOT_2_be_copied_2_each_client and varcache_2_be_copied_2_common_root are loaded from drbl.conf
2158 # varlib_NOT_2_be_copied_2_each_client -> varlib_opts_common_to_each is processed in
2159 # sbin/drbl-gen-client-files
2160
2161 # "$DISTRIB_ID" is from /etc/lsb-release
2162 if [ "$DISTRIB_ID" = "Ubuntu" ]; then
2163 case "$DISTRIB_RELEASE" in
2164 "10.10")
2165 # Weird Buggy Ubuntu 10.10 (Maverick)... The /var/lib/nfs/{sm,sm.bak} are not owned by statd in 1:1.2.2-1ubuntu1. It's owned by root. No idea how it happens, it's not always. Anyway force to add this for Ubuntu 10.10.
2166 if [ "$(LC_ALL=C stat -c %U /var/lib/nfs/sm)" != "statd" ]; then
2167 chown -R statd /var/lib/nfs/{sm,sm.bak}
2168 fi
2169 ;;
2170 "18.04")
2171 # systemd-logind's IP sandbox breaks nss-nis and suchlike #7074
2172 # Thanks to Robert Arkiletian for reporting this in drbl mailing list.
2173 # Ref: https://sourceforge.net/p/drbl/mailman/message/36319119/
2174 # https://github.com/systemd/systemd/issues/7074
2175 perl -pi -e "s/^IPAddressDeny=any/#IPAddressDeny=any # commented by DRBL/g" /lib/systemd/system/systemd-logind.service
2176 perl -pi -e "s/^IPAddressDeny=any/#IPAddressDeny=any # commented by DRBL/g" /lib/systemd/system/systemd-udevd.service
2177 ;;
2178 esac
2179 fi
2180 # Ubuntu >= 20.10 has a hook file zz-dhclient causing server booting to lease IP address. We do not need that.
2181 if grep -Ewq "^cp -a /usr/lib/initramfs-tools/etc/dhcp/.*" /usr/share/initramfs-tools/hooks/zz-dhclient 2>/dev/null; then
2182 echo "Found /usr/share/initramfs-tools/hooks/zz-dhclient. Comment it to avoid running dhclient in initramfs."
2183 perl -pi -e "s|^(cp -a /usr/lib/initramfs-tools/etc/dhcp/.*)|# \$1 # commented by DRBL|" /usr/share/initramfs-tools/hooks/zz-dhclient
2184 update-initramfs -u
2185 fi
2186
2187 # If purge_client = no, which means we will NOT overwrite the old files.
2188 # we had better to add "-u" for rsync, and we assign keep_old_files_flag=yes
2189 if [ "$purge_client" = "no" ]; then
2190 RSYNC_OPT_EXTRA="-u"
2191 keep_old_files_flag="yes"
2192 else
2193 RSYNC_OPT_EXTRA=""
2194 keep_old_files_flag="no"
2195 fi
2196
2197 # check if drbl is installed or not, which is necessary
2198 if ! rpm -q --quiet drbl &>/dev/null && ! chk_deb_installed drbl &>/dev/null; then
2199 echo "You did NOT install drbl!!! Program terminated!"
2200 exit 1
2201 fi
2202
2203 # backup the original setting files in DRBL server
2204 [ -f $DHCPDCONF_DIR/dhcpd.conf ] && mv -f $DHCPDCONF_DIR/dhcpd.conf $DHCPDCONF_DIR/dhcpd.conf.orig
2205 [ -f /etc/netgroup ] && mv -f /etc/netgroup /etc/netgroup.drblsave
2206 [ -f /var/yp/securenets ] && mv -f /var/yp/securenets /var/yp/securenets.drblsave
2207 [ -f /etc/ypserv.securenets ] && mv -f /etc/ypserv.securenets /etc/ypserv.securenets.drblsave
2208 # We do not want the old ethers, this will cause lag in network. Thanks to Dave Haakenhout <Dave.Haakenhout _at_ nccw nl>
2209 [ -e /etc/ethers ] && mv -f /etc/ethers /etc/ethers.orig
2210
2211 # Backup the old clients-of-$nfsserver.txt
2212 for i in $drbl_syscfg/clients-of-*.txt; do
2213 if [ -f "$i" ]; then
2214 mv -f $i ${i}.drblsave
2215 fi
2216 done
2217
2218 # copy some config files (dhcpd.conf, yp.conf...) created
2219 # in the drblpush DRBL server.
2220
2221 cp -f dhcpd.conf $DHCPDCONF_DIR/
2222 [ -d /etc/kea ] || mkdir -p /etc/kea
2223 cp -f kea-dhcp4.conf /etc/kea/
2224 if systemctl list-unit-files | grep -q kea-dhcp4-server; then
2225 echo "Restarting Kea DHCPv4 Server..."
2226 systemctl enable kea-dhcp4-server >/dev/null 2>&1
2227 systemctl restart kea-dhcp4-server
2228 fi
2229
2230 # Create symbolic links for any existing web server document roots for HTTPBoot
2231 for docroot in /var/www/html /var/www /usr/share/nginx/html; do
2232 if [ -d "$docroot" ]; then
2233 echo "Configuring HTTPBoot symlinks in document root: $docroot"
2234 if [ ! -e "$docroot"/tftpboot ] && [ ! -L "$docroot"/tftpboot ]; then
2235 ln -sf /tftpboot "$docroot"/tftpboot
2236 fi
2237 if [ ! -e "$docroot"/grub ] && [ ! -L "$docroot"/grub ]; then
2238 ln -sf /tftpboot/nbi_img/grub "$docroot"/grub
2239 fi
2240 fi
2241 done
2242
2243 # Enable and restart the active web server service
2244 for ws in lighttpd apache2 httpd nginx; do
2245 if systemctl list-unit-files "$ws.service" &>/dev/null; then
2246 echo "Enabling and restarting $ws service..."
2247 systemctl enable "$ws" >/dev/null 2>&1
2248 systemctl restart "$ws" >/dev/null 2>&1
2249 fi
2250 done
2251 # Generate the dnsmasq config file
2252 if [ "$use_proxy_dhcp" = "yes" ]; then
2253 # Only create dnsmasq.conf when use_proxy_dhcp is set as yes.
2254 gen_dnsmasq_cfg $dnsmasq_cfg
2255 fi
2256
2257 cp -f mkswapfile $SYSCONF_PATH/mkswapfile
2258
2259 for icfg in yp.conf netgroup; do
2260 cp -f $icfg /etc/
2261 done
2262
2263 # put the temp hostname to /etc/drbl
2264 cp -f $CLIENT_IP_HOSTNAME_LIST $IP_HOST_TABLE
2265
2266 # put clients-of-*.txt to /etc/drbl/
2267 cp -f clients-of-*.txt $drbl_syscfg/
2268
2269 # create /etc/hosts based on drblpush.conf and dhcpd.conf, so must be after dhcpd.conf is copied to system.
2270 drbl-etc-hosts
2271
2272 echo -n "Cleaning the stale files of the diskless nodes if they exist... "
2273 # clean the config or setting files in $drbl_common_root/etc/diskless-image
2274 # and /tftpboot/nodes/*/etc/diskless-image.
2275 # This action is important, otherwise the stalled files will always exist.
2276 find $drbl_common_root/etc/diskless-image $drblroot/*/etc/diskless-image -name "config" -exec rm -f {} \; &> /dev/null
2277 find $drbl_common_root $drblroot -name "$public_ip_list" -exec rm -f {} \; &> /dev/null
2278 echo "done!"
2279
2280 #
2281 # backup the old MAC address files if the collect MAC is on
2282 if [ "$collect_mac" = "yes" ]; then
2283 echo -n "Backuping the old MAC address files... "
2284 now=$(date +%F-%k-%M)
2285 find $drbl_syscfg -name "macadr-*.txt" -exec mv {} {}.saved_$now \;
2286 echo "done!"
2287 fi
2288
2289 # Part 2,
2290 # generate file system for clients, like what is done in Debian diskless-newimage
2291 #
2292
2293 # Setting
2294 echo "$msg_delimiter_star_line"
2295 # get the distribution name and type: OS_Version and OS_type
2296 check_distribution_name
2297 echo "$msg_delimiter_star_line"
2298 if [ -z "$OS_Version" ]; then
2299 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
2300 echo "$msg_not_determine_OS"
2301 echo "$msg_is_not_supported"
2302 echo "$msg_press_ctrl_c_stop!"
2303 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
2304 read
2305 exit 1
2306 fi
2307 echo "The version number for your GNU/Linux: $OS_Version"
2308
2309 # First, common root files
2310 [ ! -d /tftpboot ] && mkdir /tftpboot
2311
2312 # When user changes ocsroot, we need to modify drbl.conf (note: This must be after $drbl_common_root//$ocsroot is created)
2313 # If this script is rerun, maybe clonezilla.lock exists.
2314 if [ -f "$ocs_lock_dir/clonezilla.lock" ]; then
2315 echo "Your system is already in clonezilla mode... we will stop it when running drblpush so it will not in a mess."
2316 drbl-ocs -l 0 stop
2317 else
2318 # prepare a dir for ocs lock file
2319 mkdir -p $ocs_lock_dir
2320 fi
2321 # We need the clonezilla image dir ($ocs_img_repo_dir for sever, and $drbl_common_root/$ocs_img_repo_dir for client to use it as a mount point) if it does not exist, and we will write it into drbl.conf so that the later script will read that.
2322 mkdir -p $ocs_img_repo_dir $drbl_common_root/$ocs_img_repo_dir
2323 # Create Clonezilla log dir
2324 mkdir -p $ocs_log_dir
2325
2326 # ocsroot is supposed to be /home/partimag if untouched, if it is assigned to different one, we have to modify drbl.conf
2327 # strip the last / if it exists ( avoid this does not match "/home/partimag" <-> "/home/partimag/" , actually they are same)
2328 ocsroot="$(LC_ALL=C echo $ocsroot | sed -e "s|/[[:space:]]*$||g")"
2329 ocs_img_repo_dir="$(LC_ALL=C echo $ocs_img_repo_dir | sed -e "s|/[[:space:]]*$||g")"
2330 if [ "$ocs_img_repo_dir" != "$ocsroot" ]; then
2331 sub_cmd="s|^[[:space:]]*ocsroot=.*|ocsroot=\"$ocs_img_repo_dir\" # Modified by drblpush|g"
2332 perl -pi -e "$sub_cmd" /etc/drbl/drbl.conf
2333 fi
2334
2335 case "$purge_client" in
2336 [yY][eE][sS])
2337 echo -n "Completely cleaning old common root files if they exist... "
2338 # Clean the stalled files...
2339 [ -d $drbl_common_root/etc ] && rm -rf $drbl_common_root/etc
2340 [ -d $drbl_common_root/var ] && rm -rf $drbl_common_root/var
2341 echo "done !"
2342
2343 echo -n "Completely cleaning old nodes if they exist... "
2344 # Clean old node files
2345 for iclient in $drblroot/[0-9]*; do
2346 [ -d "$iclient" -a -n "$(echo "$iclient" | grep -E "[0-9]")" ] && rm -rf $iclient
2347 done
2348
2349 echo "done !"
2350 ;;
2351 *)
2352 echo "Keeping the old common root files if they exist... "
2353 echo "Keeping old nodes if they exist... "
2354 ;;
2355 esac
2356
2357 echo -n "Creating common root files... This might take several minutes..."
2358 echo -n "."
2359 # diskless_root_dir_1 are those necessary dir for mount point (from drbl.conf).
2360 # From Debian Sid 201108, the /run (tmpfs) is required. Therefore if it can be found on server, append it. Ref: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620157
2361 [ -d "/run" ] && diskless_root_dir_1="$diskless_root_dir_1 run"
2362 # $diskless_root_dir_ro_user_add $diskless_root_dir_rw_user_add are user assigned dirs in drbl.conf
2363 for d in $diskless_root_dir_1 $diskless_root_dir_ro_user_add $diskless_root_dir_rw_user_add; do
2364 mkdir -p $drbl_common_root/$d
2365 done
2366 # diskless_root_dir_2 are those necessary dir for mount point (from drbl.conf), too. These dirs depend on distribution, so we will test it before create it.
2367 for d in $diskless_root_dir_2; do
2368 [ -d "/$d" ] && mkdir -p $drbl_common_root/$d
2369 done
2370
2371 # locale en_US.UTF-8 will be the default locale for clonezilla dialog in console. Therefore we have to create that.
2372 gen_locale_if_not_found en_US en_US.UTF-8
2373
2374 # 1/7/2006, since B2D does not have /media, but it will create and use that
2375 # once you plug the usb devices, so now we mkdir media for DRBL B2D client
2376 echo -n "."
2377 if [ -e /etc/b2d-release ]; then
2378 mkdir -p $drbl_common_root/media
2379 fi
2380
2381 echo -n "."
2382 # copy some rc files to root home directory
2383 for ir in .bashrc .bash_profile .profile .viminfo; do
2384 [ -f /root/$ir ] && rsync -a $RSYNC_OPT_EXTRA /root/$ir $drbl_common_root/root/
2385 done
2386
2387 # create the console so that client can output message when entering init. This is especially for Debian.
2388 echo -n "."
2389 # force to clean the old ones
2390 for i in console null; do
2391 [ -c $drbl_common_root/dev/$i ] && rm -f $drbl_common_root/dev/$i
2392 done
2393 mknod -m 600 $drbl_common_root/dev/console c 5 1
2394 mknod -m 666 $drbl_common_root/dev/null c 1 3
2395
2396 #
2397 echo -n "."
2398 # copy /sbin, /bin to node_root
2399 # For FC17, since /sbin is linked to /usr/sbin, we have to create /sbin, /bin first
2400 mkdir -p $drbl_common_root/usr/{sbin,bin}
2401
2402 # Note!!! For rsync, do NOT to append "/" in the /sbin, .i.e. NO /sbin/
2403 rsync -a $RSYNC_OPT_EXTRA /usr/sbin/* $drbl_common_root/usr/sbin/
2404 # Because Ubuntu 15.04 hides insserv in /usr/lib/insserv/insserv due to switch
2405 # to systemd. However, it's important for us to enable sysvinit service (some
2406 # services are not systemdlized yet, e.g. nis in Ubuntu 15.04). Therefore force
2407 # to put it in $drbl_common_root/sbin/
2408 # Variable DESTDIR is required for copy_exec_drbl use
2409 export DESTDIR="$drbl_common_root"
2410 [ -e "/usr/lib/insserv/insserv" ] && copy_exec_drbl /usr/lib/insserv/insserv /sbin/
2411
2412 #
2413 echo -n "."
2414 rsync -a $RSYNC_OPT_EXTRA /usr/bin/* $drbl_common_root/usr/bin/
2415 # We need awk and cut in init.drbl.
2416 # For RH-like, awk and cut are in /bin, however, in Debian, they are in /usr/bin, which is not mounted when trying to get IP address of NFS server in running init.drbl. So we have to copy them.
2417 # Note!!! In Debian, we need the gawk, not awk, so we already installed gawk
2418 # in drblsrv, and it will replace awk as /etc/alternatives/awk -> /usr/bin/gawk
2419 # But maybe it is better to cp gawk -> awk ?
2420 must_prog_for_init_drbl="cut gawk"
2421 for imust in $must_prog_for_init_drbl; do
2422 [ -e "$drbl_common_root/bin/$imust" ] && rm -f $drbl_common_root/bin/$imust
2423 if [ -e "/usr/bin/$imust" ]; then
2424 #echo "Copying $imust from /usr/bin/ to $drbl_common_root/bin/..."
2425 cp -af --dereference /usr/bin/$imust $drbl_common_root/bin/
2426 else
2427 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
2428 echo "FATAL error!!! $imust is not found in /usr/bin!!! Client will NOT be able to boot or run correctly!!!"
2429 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
2430 fi
2431 done
2432 # link gawk as awk for clients.
2433 (cd $drbl_common_root/usr/bin/; ln -fs gawk awk)
2434 # For gawk_3.1.8+dfsg-0.1 on Debian sid (2011/07/30), it requires /usr/lib/*.so*# $ ldd /usr/bin/gawk
2435 # linux-gate.so.1 => (0xb76eb000)
2436 # libsigsegv.so.2 => /usr/lib/libsigsegv.so.2 (0xb76d7000)
2437 # libdl.so.2 => /lib/i386-linux-gnu/i686/cmov/libdl.so.2 (0xb76d3000)
2438 # libm.so.6 => /lib/i386-linux-gnu/i686/cmov/libm.so.6 (0xb76ac000)
2439 # libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xb7552000)
2440 # /lib/ld-linux.so.2 (0xb76ec000)
2441 #
2442 export DESTDIR="$drbl_common_root"
2443 [ -e "$(LC_ALL=C command -v gawk)" ] && copy_exec_drbl "$(LC_ALL=C command -v gawk)" /usr/bin/
2444
2445 echo -n "."
2446 # Creat a file $drbl_common_root/usr/sbin/fsck.nfs to let rc.sysinit use
2447 # "fsck.nfs" always successfully
2448 echo "#!/bin/bash
2449 # dummy fsck.nfs file that always returns success.
2450 # Created by drblpush to let rc.sysinit use fsck.nfs always successfully
2451 exit 0" > $drbl_common_root/usr/sbin/fsck.nfs
2452 chmod 755 $drbl_common_root/usr/sbin/fsck.nfs
2453
2454 echo -n "."
2455
2456 for id in lib lib64 bin sbin; do
2457 mkdir -p $drbl_common_root/usr/$id
2458 if [ -L "/$id" ]; then
2459 if [ ! -L "$drbl_common_root/$id" ]; then
2460 (cd $drbl_common_root; ln -fs usr/$id $id)
2461 fi
2462 fi
2463 done
2464 # Steven todo, make sure it is right ?
2465 # $drbl_common_root/lib/security is important for PAM, if we remove/update it,
2466 # clients have to reboot, otherwise user can not login in the client.
2467 # So it is better to keep $drbl_common_root/lib/security/ without updating.
2468 # if [ -d $drbl_common_root/lib/security ]; then
2469 # rsync -a $RSYNC_OPT_EXTRA --exclude=modules/ --exclude=security/ /lib $drbl_common_root/
2470 # else
2471 # rsync -a $RSYNC_OPT_EXTRA --exclude=modules/ /lib $drbl_common_root/
2472 # fi
2473 # 2006/6/1 Just sync it, otherwise /lib/security will not be updated, some files will be missing.
2474 # 2012/9/26 For FC17 since /lib is linked as /usr/lib, we have to copy files, not the linked dir.
2475 lib_opts_common_to_common=""
2476 for iv in $lib_NOT_2_be_copied_2_common_root; do
2477 lib_opts_common_to_common="$lib_opts_common_to_common --exclude=$iv/ "
2478 done
2479 rsync -a $lib_opts_common_to_common /usr/lib/* $drbl_common_root/usr/lib/
2480
2481 # For x86_64
2482 # For FC3 or later: /lib64 is a directory, not /lib32, only dir /lib
2483 # For Ubuntu breezy amd64: /lib64 is a symbolic to /lib, /lib32 is a directory
2484 for d in lib lib32 libx32 lib64; do
2485 if [ -L "/$d" ]; then
2486 rsync -a /$d/* $drbl_common_root/usr/$d/
2487 fi
2488 done
2489
2490 echo " done!"
2491
2492 # Copy or update the kernel for client if necessary...
2493 echo "Update the kernel for client if necessary... "
2494 update-drbl-client-kernel-from-server $verbose_opt $RSYNC_OPT_EXTRA
2495
2496 # copy /etc to template node
2497 # etc_exclude_dirs is loaded from drbl.conf
2498 etc_rsync_opt=""
2499 for ietc in $etc_exclude_dirs; do
2500 etc_rsync_opt="$etc_rsync_opt --exclude=$ietc"
2501 done
2502 echo "Copying the directory /etc/ to clients common root $drbl_common_root..."
2503 rsync -a $etc_rsync_opt $RSYNC_OPT_EXTRA /etc $drbl_common_root
2504
2505 # For Ubuntu 6.10 (edgy), there is no /etc/inittab, but upstart still respect
2506 # inittab. We will create one for client, but for edgy+1 or later, maybe not respect /etc/inittab, then we have to follow upstart in the future.
2507 #if [ ! -f /etc/inittab ]; then
2508 # cat <<-INIT_END > $drbl_common_root/etc/inittab
2509 ## inittab created by DRBL.
2510 ## This file is created to be backward compatible with Ubuntu Dapper/Breezy and Debian Sarge/Etch. Although Ubuntu Edgy now uses upstart instead of sysvinit, it still respect /etc/inittab, but in Edgy+1 or later, maybe it will not respect.
2511 #
2512 ## The default runlevel.
2513 #id:2:initdefault:
2514 #INIT_END
2515 #fi
2516 #
2517
2518 # clean the ssh key, so that client will create its own.
2519 key_file="ssh_host_dsa_key ssh_host_dsa_key.pub ssh_host_key ssh_host_key.pub ssh_host_rsa_key ssh_host_rsa_key.pub"
2520 for ik in $key_file; do
2521 if diff /etc/ssh/$ik $drbl_common_root/etc/ssh/$ik &>/dev/null; then
2522 echo -n "Cleaning the ssh key file $ik copied from server... "
2523 rm -f $drbl_common_root/etc/ssh/$ik
2524 echo "done!"
2525 fi
2526 done
2527
2528 # comment /etc/hosts.allow and /etc/hosts.deny in drbl client
2529 for ik in hosts.deny hosts.allow; do
2530 echo -n "Commenting the TCPwrapper related file $drbl_common_root/etc/$ik copied from server... "
2531 perl -pi -e 's/^([^#][[:print:]]+)$/# $1 # commented by DRBL/g' $drbl_common_root/etc/$ik
2532 echo "done!"
2533 done
2534
2535 # clean the mtab in $drbl_common_root copied from server
2536 rm -f $drbl_common_root/etc/mtab*
2537
2538 # clean the netplan file copied from server
2539 rm -f $drbl_common_root/etc/netplan/*.yaml
2540
2541 # For Debian udev, if $drbl_common_root/etc/udev/rules.d/z25_persistent-net.rules exists, remove it. Since it contains the network MAC address from drbl server, and we should let client automatically create that.
2542 if [ -n "$(unalias ls 2>/dev/null; ls $drbl_common_root/etc/udev/rules.d/*persistent-net.rules 2>/dev/null)" ]; then
2543 rm -f $drbl_common_root/etc/udev/rules.d/*persistent-net.rules
2544 fi
2545
2546 # make sure the hostname of server in 127.0.0.1 in /etc/hosts
2547 # is not copied to clients.
2548 # like
2549 #-----------------------------------------------------------
2550 #127.0.0.1 rh9 localhost.localdomain localhost
2551 #-----------------------------------------------------------
2552 # if it is copied to client, client will have some problem to connect to server
2553 # such as yppasswd will complain the yppasswdd is NOT running on "rh9".
2554 HOSTNAME_SRV=`/usr/bin/hostname`
2555 if [ -n "$(grep $HOSTNAME_SRV $drbl_common_root/etc/hosts |grep 127.0.0.1)" ]; then
2556 perl -p -i -e "s/127.0.0.1.*/127.0.0.1 localhost.localdomain localhost/g" $drbl_common_root/etc/hosts
2557 fi
2558
2559 # create mkswapfile to $drbl_common_root/etc/init.d/
2560 # This must before service to add
2561 cp -f $drbl_setup_path/files/misc/{mkswapfile,drblthincli,arm-wol} $drbl_common_root/etc/init.d/
2562 # ocs-run is a script to start clone for clonezilla, it only will be put in
2563 # client's rc1.d when clonezilla save/restart start.
2564 cp -f $drbl_setup_path/files/ocs/ocs-run $drbl_common_root/etc/init.d/
2565 # For Debian, there is no gdm-safe-restart script, we just copy it from drbl
2566 # package. We need gdm-safe-restart for terminal mode setup.
2567 [ ! -x /usr/sbin/gdm-safe-restart ] && cp -f $drbl_setup_path/files/misc/gdm-safe-restart /usr/sbin/gdm-safe-restart
2568 chown root:root $drbl_common_root/etc/init.d/{mkswapfile,drblthincli,arm-wol}
2569 # Put systemd services for {mkswapfile,drblthincli,arm-wol}
2570 if is_systemd_init; then
2571 cp -f $drbl_setup_path/files/misc/systemd/{mkswapfile.service,drblthincli.service,arm-wol.service} $drbl_common_root/lib/systemd/system/
2572 if [ -e /etc/debian_version ]; then
2573 # Write the override file for remote-fs-pre of systemd due to nfs-utils
2574 # in Debian does not ship native systemd unit files.
2575 # Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=768006
2576 mkdir -p $drbl_common_root/lib/systemd/system/nfs-common.service.d/
2577 cp -f $drbl_setup_path/files/misc/systemd/remote-fs-pre.conf $drbl_common_root/lib/systemd/system/nfs-common.service.d/
2578 if [ ! -e /etc/systemd/system/tmp.mount -a \
2579 ! -e /lib/systemd/system/tmp.mount -a \
2580 -e /usr/share/systemd/tmp.mount ]; then
2581 # Debian systemd 220 disabled tmp.mount, and it might cause our diskless client umount /tmp in amd64. We have to enable it.
2582 # Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779902
2583 if [ -e "$drbl_common_root/etc/default/tmpfs" ]; then
2584 perl -pi -e "s/[#]RAMTMP=.*/RAMTMP=yes/g" $drbl_common_root/etc/default/tmpfs
2585 fi
2586 cp -a /usr/share/systemd/tmp.mount $drbl_common_root/lib/systemd/system/tmp.mount
2587 # Manuall link the tmp.mount since systemctl fails to run in chroot.
2588 mkdir -p $drbl_common_root/etc/systemd/system/local-fs.target.wants/
2589 ln -fs /lib/systemd/system/tmp.mount $drbl_common_root/etc/systemd/system/local-fs.target.wants/tmp.mount
2590 fi
2591 fi
2592 fi
2593
2594 # For MDK/Debian/SuSE, we put the one we wrote "firstboot.XXX.drbl" to
2595 # common root /etc/init.d as firstboot.
2596 # There is already firstboot comes with RH/FC/CentOS.
2597 # We do NOT use the firstboot comes with yast2-firstboot in SuSE.
2598 if [ "$OS_type" != "RH" ]; then
2599 if [ -f "$drbl_setup_path/files/${OS_type}/${OS_Version}/firstboot.${OS_Version}.drbl" ]; then
2600 cp -f $drbl_setup_path/files/${OS_type}/${OS_Version}/firstboot.${OS_Version}.drbl $drbl_common_root/etc/init.d/firstboot
2601 else
2602 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
2603 echo "Warning! The fine-tune file ${drbl_setup_path}/files/${OS_type}/${OS_Version}/firstboot.${OS_Version}.drbl was not found. Using ${drbl_setup_path}/files/${OS_type}/firstboot.default-${OS_type}.drbl as /etc/init.d/firstboot for DRBL clients!"
2604 echo "This may cause some problems to DRBL clients!"
2605 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
2606 cp -f $drbl_setup_path/files/${OS_type}/firstboot.default-${OS_type}.drbl $drbl_common_root/etc/init.d/firstboot
2607 fi
2608 fi
2609
2610 # modify some bootup script or setting (System V is easier to do here.. all scripts are separated.)
2611 if [ -e /etc/debian_version ]; then
2612 # Debian
2613 # For genuine Debian Sarge
2614 if [ -e $drbl_common_root/etc/init.d/umountfs ]; then
2615 perl -pi -e 's/(^[[:space:]]*umount -ttmpfs.*)/#$1 # Modified by DRBL/g' $drbl_common_root/etc/init.d/umountfs
2616 perl -pi -e 's/(^[[:space:]]*umount -tnoproc)(,noprocfs.*)/$1,nonfs,notmpfs$2 # Modified by DRBL/g' $drbl_common_root/etc/init.d/umountfs
2617 # For genuine Debian Etch
2618 perl -pi -e 's/(^[[:space:]]*)(proc|procfs|linprocfs|devfs|sysfs|usbfs.*)/$1nfs|tmpfs|none|$2/g' $drbl_common_root/etc/init.d/umountfs
2619 # for B2D
2620 perl -pi -e 's/^[[:space:]]*umount \$FORCE -a -r.*/umount \$FORCE -tnoproc,nonfs,notmpfs,noprocfs,nodevfs,nosysfs,nousbfs,nousbdevfs,nodevpts -d -a -r # Modified by DRBL/g' $drbl_common_root/etc/init.d/umountfs
2621 # for Ubuntu Dapper
2622 # To avoid $DIR is noting.
2623 # Ref: https://lists.ubuntu.com/archives/ubuntu-users/2006-May/079378.html
2624 perl -pi -e 's|^([[:space:]]*)(umount -r -d \$DIRS*)|$1 [ -n "\$DIRS" ] && $2 # Modified by DRBL|g' $drbl_common_root/etc/init.d/umountfs
2625 # For Debian Squeeze, by default it uses parallel start service "startpar" (i.e. CONCURRENCY=makefile). We disable it in the client so that we won't have to modify the services. E.g. /etc/rc1.d/*ssh when running clonezilla SE job.
2626 fi
2627 if [ -e $drbl_common_root/etc/init.d/rc ]; then
2628 LC_ALL=C perl -pi -e "s|^CONCURRENCY=.*|CONCURRENCY=none # Mofified by DRBL|g" $drbl_common_root/etc/init.d/rc
2629 # Disable the lvm udevd, otherwise this rule file will be read-only in the client, and it will be auto-run during booting. Then the disk will be always busy. Clonezilla will fail to create partition table.
2630 fi
2631 disable_lvm2_udevd_rules $drbl_common_root
2632
2633 elif [ -e /etc/SuSE-release ]; then
2634 # For SuSE
2635 # SuSE is unique here, it uses parallel start service "startpar", we do not
2636 # want that, otherwise some services might fail due to NFS client does not
2637 # finish yet.
2638 echo -n "Turn off runlevel scripts in parallel in clients... "
2639 perl -pi -e "s/^[[:space:]]*[#]*[[:space:]]*RUN_PARALLEL=.*/RUN_PARALLEL=no/g" $drbl_common_root/etc/sysconfig/boot
2640 echo "done!"
2641 # modify some services
2642 # 1. etc/init.d/boot, use -o remount so it will not complain when booting.
2643 perl -pi -e 's/^([[:space:]]*mount -n -t proc)(.*)/$1 -o remount $2 # Modified by DRBL/g' $drbl_common_root/etc/init.d/boot
2644 perl -pi -e 's/^([[:space:]]*mount -n -t sysfs)(.*)/$1 -o remount $2 # Modified by DRBL/g' $drbl_common_root/etc/init.d/boot
2645 # 2. boot.udev, we have to turn on runlevel 1 so that clonezilla will be ok.
2646 perl -pi -e 's/^[[:space:]]*#+[[:space:]]*Default-Start:.*/# Default-Start: B 1/g' $drbl_common_root/etc/init.d/boot.udev
2647 # 3. boot.localfs, we add -l when umount in "boot.udev stop" (called by reboot/halt)
2648 perl -pi -e 's/^([[:space:]]*umount) -avt (noproc,nonfs.*)/$1 -avtl nosysfs,$2 # Modified by DRBL/g' $drbl_common_root/etc/init.d/boot.localfs
2649 # 3. nfs client,
2650 # (a) For OpenSuSE 11.1, it seems if we do not restart dbus after NFS is run, something weird. E.g. When xdm start, an error:
2651 # Starting service gdm ** (gdm:2916): WARNING **: Couldn't connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: Connection refused startproc: exit status of parent of /usr/sbin/gdm: 1 failed
2652 # Therefore we force to restart dbus after nfs dirs are mounted:
2653 perl -pi -e 's|^([[:space:]]*mount -at nfs.*)|$1; /etc/init.d/dbus restart # Modified by DRBL|g' $drbl_common_root/etc/init.d/nfs
2654 # (b) We do not want to recreate ld.so.cache, it is only provided
2655 # by DRBL server.
2656 # Note! recreate here will take a long time.
2657 # Note2: boot.ldconfig is run before nfs.
2658 # It will not include some remote NFS directory
2659 # (like /opt/kde/lib... /opt/gnome/lib...
2660 # we have to turn off boot.ldconfig in /etc/init.d/boot.d also.
2661 # Here we put "true" so that if there is only one command in the if/else block, the nfs start script won't fail.
2662 perl -pi -e 's|^([[:space:]]*#+)[[:space:]]*check if ld.so.cache needs to be refreshed.*|$1 DRBL comment this, we will not let boot.ldconfig run in DRBL client.|g' $drbl_common_root/etc/init.d/nfs
2663 perl -pi -e 's|/etc/init.d/(boot.ldconfig start.*)|true #$1|g' $drbl_common_root/etc/init.d/nfs
2664 rm -f $drbl_common_root/etc/init.d/boot.d/[SK][0-9][0-9]boot.ldconfig
2665 fi
2666
2667 # Remove the unnecessary service,
2668 # First, remove all the service
2669 # Prepare the necessary env for chkconfig, update-rc.d or insserv
2670 if [ -e /etc/debian_version ]; then
2671 # For Debian
2672 prepare_update_rc_d_env $drbl_common_root/
2673 elif [ -e /etc/SuSE-release ]; then
2674 # For SuSE
2675 create_insserv_env $drbl_common_root/
2676 else
2677 # For RH-like
2678 create_chkconfig_env $drbl_common_root/
2679 fi
2680 # Skip those do not support chkconfig, or actually, they are not services.
2681 # reboot/halt are necessary for all dists.
2682 # For FC17, getty@ is required.
2683 service_to_be_kept="dualconf functions reboot halt killall single mandrake_consmap mandrake_everytime mandrake_firstime usb getty@"
2684
2685 # For normal service in init.d
2686 isrv_list="$(cd $drbl_common_root/etc/init.d; ls *)"
2687 # For systemd-like , E.g. FC17
2688 if is_systemd_init; then
2689 isrv_list="$isrv_list $(find $drbl_common_root/lib/systemd/system -name "*.service" -type f -exec basename {} \;| sed -e "s/\.service$//g")"
2690 fi
2691
2692 for isrv in $isrv_list ; do
2693 # Skip directory
2694 [ -d "$drbl_common_root/etc/init.d/$isrv" -o -d "$drbl_common_root/lib/systemd/system/$isrv.service" ] && continue
2695 # keep some services.
2696 [ -n "$(echo $service_to_be_kept | grep -w $isrv)" ] && continue
2697 if is_systemd_init; then
2698 # For systemd-like, E.g. FC17, Debian Jessie, Ubuntu 15.04
2699 echo "Deleting '$isrv' service in systemd-like environment ..."
2700 if [ -e "$drbl_common_root/etc/init.d/$isrv" ]; then
2701 if [ -x "$drbl_common_root/sbin/chkconfig" ]; then
2702 chroot $drbl_common_root/ /sbin/chkconfig --del $isrv
2703 elif [ -x "$drbl_common_root/sbin/insserv" ]; then
2704 chroot $drbl_common_root/ insserv -f -r $isrv &> /dev/null
2705 fi
2706 find $drbl_common_root/etc/rc*.d -regex ".*[SK][-0-9][0-9]$isrv" -exec rm -f {} \;
2707 fi
2708 if [ -e "$drbl_common_root/lib/systemd/system/${isrv}.service" ]; then
2709 find $drbl_common_root/etc/systemd/ -name "${isrv}.service" -exec rm -f {} \;
2710 fi
2711 elif [ -e /etc/debian_version ]; then
2712 # For Debian
2713 # We should keep the services in rcS.d, but "update-rc.d remove" does
2714 # not support this. It will also clean all the services in rcS.d.
2715 # So we will copy those services of rcS.d to client's common root
2716 # after this. NOTE! This can only be done after all updata-rc.d
2717 # finished. Otherwise it will affect the update-rc.d
2718 if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
2719 chroot $drbl_common_root/ insserv -f -r $isrv &> /dev/null
2720 else
2721 chroot $drbl_common_root/ /usr/sbin/update-rc.d -f $isrv remove &> /dev/null
2722 fi
2723 elif [ -e /etc/SuSE-release ]; then
2724 # For SuSE
2725 # There are a lot of boot.* services, we must exclude them also.
2726 # Special case: boot.udev, which only starts in boot, 2, 3, 5, but we need
2727 # it to start in 1 also. So we remove boot.udev here, then modify it, then
2728 # add it later.
2729 [ "$isrv" = "boot.udev" ] && chroot $drbl_common_root/ /sbin/insserv -f -r $isrv
2730 [ -n "$(echo $isrv | grep "^boot.*")" ] && continue
2731
2732 [ "$isrv" = "Makefile" ] && continue
2733 [ "$isrv" = "README" ] && continue
2734 [ "$isrv" = "rc" ] && continue
2735 chroot $drbl_common_root/ /sbin/insserv -f -r $isrv
2736 else
2737 # For RH-like
2738 chroot $drbl_common_root/ /sbin/chkconfig --del $isrv
2739 # Maybe it will fail to delete the service, so try to delete brutely.
2740 # This happens in Mandriva 2007.0. Bugs report:
2741 # http://qa.mandriva.com/show_bug.cgi?id=24409
2742 # http://qa.mandriva.com/show_bug.cgi?id=23104
2743 # In Mandriva 2008.0, there is some special service start name "S-1", like:
2744 # ./rc.d/rc3.d/S-1nfs-common, ./rc.d/rc3.d/S-1nfs-server
2745 # Therefore it's not "[SK][0-9][0-9]$i", it's "[SK][-0-9][0-9]$i" here.
2746 ( cd $drbl_common_root/etc
2747 find ./rc*.d -regex ".*[SK][-0-9][0-9]$isrv" -exec rm -f {} \;
2748 )
2749 fi
2750 done
2751
2752 # Set journal.conf for FC 21 to solve bootup hanging, by Ceasar
2753 # Ref: http://forums.gentoo.org/viewtopic-t-806432-view-previous.html?sid=206e0c04aa942972883135971a18c6ae
2754 # Add into clients' /etc/systemd/journald.conf
2755 # Storage=volatile
2756 # SystemMaxUse=20M
2757 # SystemMaxFileSize=20M
2758
2759 if [ -e "$drbl_common_root/etc/systemd/journald.conf" ]; then
2760 sed -i -e "/SystemMaxUse\=/d" -e "/SystemMaxFileSize\=/d" -e "/Storage\=/d" $drbl_common_root/etc/systemd/journald.conf
2761 echo "Storage=volatile" >> $drbl_common_root/etc/systemd/journald.conf
2762 echo "SystemMaxUse=20M" >> $drbl_common_root/etc/systemd/journald.conf
2763 echo "SystemMaxFileSize=20M" >> $drbl_common_root/etc/systemd/journald.conf
2764 fi
2765
2766 # Get the gdm or kdm config filename
2767 # get_gdm_kdm_conf_filename will also process lightdm/mdm. For Ubuntu 14.04, /etc/lightdm/lightdm.conf does not exist, and get_gdm_kdm_conf_filename will unzip the one "/usr/share/doc/lightdm/lightdm.conf.gz" and put it in /etc/lightdm/
2768 get_gdm_kdm_conf_filename
2769
2770 if [ -z "$GDM_CFG" ]; then
2771 prepare_gdm_custom_conf
2772 fi
2773
2774 # set gdm.conf for DRBL clients
2775 if [ -f "$drbl_common_root/$GDM_CFG" -a "$set_drbl_gdmgreeter" = "yes" ]; then
2776 # force to use graphic greeting (gdmgreeter is available in sarge, not in woody. In woody, it is gdmlogin)
2777 # gdmgreeter: /usr/bin/gdmgreeter (sarge) or /usr/lib/gdm/gdmgreeter (breezy)
2778 # gnome 2.14: /usr/libexec/gdmgreeter
2779 GDM_GREETER="$($query_pkglist_cmd gdm 2>/dev/null | grep -E "\/gdmgreeter$")"
2780 if [ -n "$GDM_GREETER" ]; then
2781 # Set Greeter=$GDM_GREETER
2782 lines="$(get_block_line_in_gdm_kdm daemon $drbl_common_root/$GDM_CFG)"
2783 begin_line=$(echo $lines | awk -F" " '{print $1}')
2784 end_line=$(echo $lines | awk -F" " '{print $2}')
2785 chk_cmd="if ($begin_line..$end_line) {print}"
2786 if [ -n "$(perl -n -e "$chk_cmd" $drbl_common_root/$GDM_CFG | grep -i "^Greeter=")" ]; then
2787 sub_cmd="if ($begin_line..$end_line) {s|^Greeter=.*|Greeter=$GDM_GREETER|}"
2788 perl -pi -e "$sub_cmd" $drbl_common_root/$GDM_CFG
2789 else
2790 # insert 1 blank line
2791 sub_cmd="if ($((end_line))..$((end_line))) {s|^(.*)$|\$1\n|gi}"
2792 perl -pi -e "$sub_cmd" $drbl_common_root/$GDM_CFG
2793 # replace the one we want in the added blank line
2794 sub_cmd="if ($((end_line+1))..$((end_line+1))) {s|^$|Greeter=$GDM_GREETER|gi}"
2795 perl -pi -e "$sub_cmd" $drbl_common_root/$GDM_CFG
2796 fi
2797 # Set GraphicalTheme=drbl-gdm
2798 lines="$(get_block_line_in_gdm_kdm greeter $drbl_common_root/$GDM_CFG)"
2799 begin_line=$(echo $lines | awk -F" " '{print $1}')
2800 end_line=$(echo $lines | awk -F" " '{print $2}')
2801 chk_cmd="if ($begin_line..$end_line) {print}"
2802 if [ -n "$(perl -n -e "$chk_cmd" $drbl_common_root/$GDM_CFG | grep -i "^GraphicalTheme=")" ]; then
2803 sub_cmd="if ($begin_line..$end_line) {s|^GraphicalTheme=.*|GraphicalTheme=drbl-gdm|}"
2804 perl -pi -e "$sub_cmd" $drbl_common_root/$GDM_CFG
2805 else
2806 # insert 1 blank line
2807 sub_cmd="if ($((end_line))..$((end_line))) {s|^(.*)$|\$1\n|gi}"
2808 perl -pi -e "$sub_cmd" $drbl_common_root/$GDM_CFG
2809 # replace the one we want in the added blank line
2810 sub_cmd="if ($((end_line+1))..$((end_line+1))) {s|^$|GraphicalTheme=drbl-gdm|gi}"
2811 perl -pi -e "$sub_cmd" $drbl_common_root/$GDM_CFG
2812 fi
2813 fi
2814 fi
2815
2816 # 2nd, add the service which DRBL client need
2817 client_services=""
2818 # Add the necessary services:
2819 # firstboot is always necessary. Even for MDK, there is no firstboot in /etc/init.d, we will add it which is provided by DRBL. It will control the run level
2820 # via chkconfig (i.e. for rc3, although the service is added, but it will
2821 # not run.
2822 # Note by Steven Shiau on 2006/09/26, we put firstboot in the beginning
2823 # (hence it's in front of the dm service of Mandriva), since in LSB based
2824 # service, we need to put firstboot before dm, otherwise dm might run
2825 # before firstboot.
2826 client_services="$client_services firstboot"
2827
2828 # client_services_chklist is loaded in drbl.conf.
2829
2830 # check if the service listed exists
2831 for iser in $client_services_chklist; do
2832 # For systemd, chcek /lib/systemd/system/*.service
2833 [ -e "/etc/init.d/$iser" -o -f "/lib/systemd/system/${iser}.service" ] && client_services="$client_services $iser"
2834 done
2835
2836 # add the services only exist in DRBL client.
2837 client_services="$client_services drblthincli $mkswapfile arm-wol"
2838
2839 # For some distribution, add special service if DRBL is configured to run
2840 # some desktop application, such as iiimf, cups.
2841
2842 # add some special services for specific distribution
2843 if [ -e /etc/debian_version ]; then
2844 # For Debian
2845 # The umountfs is already modified by drblpush
2846 client_services="$client_services sendsigs umountfs"
2847 elif [ -e /etc/SuSE-release ]; then
2848 # For SuSE
2849 # Suse uses xdm to start kdm/gdm/xdm, they are all in the same service name.
2850 # We foced to use the modified boot.udev (it's on in runlevel 1,2,3,4,5
2851 # Note: "nfs" is server in RH, but it's client in SuSE. So we have to add it
2852 # separately for SuSE.
2853 client_services="$client_services nfs xdm boot.udev"
2854 else
2855 # For RH-like
2856 # IIim in FC2, iiim in FC3, scim for MDK 10.1 (scim is not a service, so skip this). Try to find which one...
2857 for iinput in IIim iiim; do
2858 if [ -n "$(LC_ALL=C [ -x /sbin/chkconfig ] && chkconfig --list $iinput 2>/dev/null | awk '/5:on/ {print $7}')" -o -n "$(LC_ALL=C [ -x /sbin/chkconfig ] && chkconfig --list $iinput 2>/dev/null | awk '/3:on/ {print $5}')" ]; then
2859 client_services="$client_services $iinput"
2860 fi
2861 done
2862 # Due to this bug, we force to turn on gpm in FC4.
2863 # https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=158620
2864 case "$OS_Version" in
2865 FC[4-9]|FC1[01234])
2866 # To avoid this bug, shit!
2867 # https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=158620
2868 if [ -e "$drbl_common_root/etc/init.d/gpm" ]; then
2869 client_services="$client_services gpm"
2870 # modify the gpm so that it will start in rc1, clonezilla is run in rc1.d
2871 perl -pi -e "s/^# chkconfig: 2345 85 15/# chkconfig: 12345 17 83/g" $drbl_common_root/etc/init.d/gpm
2872 fi
2873 ;;
2874 esac
2875 fi
2876
2877 # add the services specified by user
2878 if [ -e "$drbl_syscfg/client-extra-service" ]; then
2879 . $drbl_syscfg/client-extra-service
2880 client_services="$client_services $service_extra_added"
2881 fi
2882
2883 echo "The startup services for DRBL client are:"
2884 # strip the leading space
2885 [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
2886 echo $(echo $client_services | sed -e "s/^ //g")
2887 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
2888
2889 # prepare the necessary env for chkconfig, update-rc.d or insserv
2890 if [ -e /etc/debian_version ]; then
2891 # For Debian
2892 prepare_update_rc_d_env $drbl_common_root/
2893 elif [ -e /etc/SuSE-release ]; then
2894 # For SuSE
2895 create_insserv_env $drbl_common_root/
2896 else
2897 # For RH-like
2898 create_chkconfig_env $drbl_common_root/
2899 fi
2900 for i in $client_services; do
2901 if is_systemd_init; then
2902 # Systemd system
2903 echo "Enabling service $i..."
2904 case "$i" in
2905 ypbind)
2906 # remove ypserv
2907 sed -i -e "s/[[:space:]]*ypserv.service//" $drbl_common_root/lib/systemd/system/$i.service
2908 ;;
2909 dm)
2910 # TODO: start drblthincli before dm.
2911 true
2912 ;;
2913 netfs)
2914 # TODO
2915 true
2916 ;;
2917 esac
2918 if [ -e "$drbl_common_root/lib/systemd/system/$i.service" ]; then
2919 # systemctl can't work in chroot environment :`chroot $drbl_common_root/ /sbin/chkconfig --add $i`
2920 # Therefore manually link it:
2921 _systemctl_target=$(grep -e "^WantedBy=" $drbl_common_root/lib/systemd/system/$i.service | sed -e "s/WantedBy=//")
2922 if [ ! -z "$_systemctl_target" ]; then
2923 echo "to target: '$_systemctl_target'";
2924 for ti in $_systemctl_target; do
2925 ln -s -v /lib/systemd/system/$i.service $drbl_common_root/etc/systemd/system/$ti.wants/$i.service
2926 done
2927 else
2928 echo "Skip ...";
2929 fi
2930 fi
2931 # 2024/9/14 Comment this backup plan, since systemd service is enabled.
2932 # if [ -e "$drbl_common_root/etc/init.d/$i" ]; then
2933 # if [ -x "$drbl_common_root/sbin/chkconfig" ]; then
2934 # echo "Running: chroot $drbl_common_root/ /sbin/chkconfig --add $i"
2935 # chroot $drbl_common_root/ /sbin/chkconfig --add $i
2936 # elif [ -x "$drbl_common_root/usr/sbin/update-rc.d" ]; then
2937 # echo "Running: chroot $drbl_common_root /usr/sbin/update-rc.d $i defaults"
2938 # chroot $drbl_common_root /usr/sbin/update-rc.d $i defaults
2939 # echo "Running: chroot $drbl_common_root /usr/sbin/update-rc.d $i enable"
2940 # chroot $drbl_common_root /usr/sbin/update-rc.d $i enable
2941 # elif [ -x "$drbl_common_root/sbin/insserv" ]; then
2942 # # Use insserv for debian/ubuntu
2943 # # Ubuntu >= 16.10, there is no insserv at all.
2944 # # Add '-f' to fix adding nis service error in Xenial, by Ceasar
2945 # echo "Running: chroot $drbl_common_root/ insserv -f $i &> /dev/null"
2946 # chroot $drbl_common_root/ insserv -f $i &> /dev/null
2947 # fi
2948 # fi
2949 elif [ -e /etc/debian_version ]; then
2950 if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
2951 # Use insserv
2952 chroot $drbl_common_root/ insserv $i &> /dev/null
2953 else
2954 # Use update-rc.d
2955 case "$i" in
2956 portmap)
2957 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 18 2 3 4 5 . start 32 0 6 . stop 32 1 . &> /dev/null
2958 ;;
2959 rpcbind)
2960 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 18 2 3 4 5 . start 32 0 6 . stop 32 1 . &> /dev/null
2961 ;;
2962 nis)
2963 # nis should be earlier than gdm (S13)
2964 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 12 2 3 4 5 . stop 12 0 1 6 . &> /dev/null
2965 ;;
2966 sendsigs)
2967 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 20 0 6 . &> /dev/null
2968 ;;
2969 umountfs)
2970 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 40 0 6 . &> /dev/null
2971 ;;
2972 mkswapfile)
2973 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 35 2 3 4 5 . stop 65 0 1 6 . &> /dev/null
2974 ;;
2975 firstboot)
2976 # chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 95 2 3 4 5 . stop 05 0 1 6 . &> /dev/null
2977 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 95 S . &> /dev/null
2978 ;;
2979 drblthincli)
2980 # drblthincli must be before gdm/kdm
2981 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 12 2 3 4 5 . stop 88 0 1 6 . &> /dev/null
2982 ;;
2983 nfs-common)
2984 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 21 2 3 4 5 . stop 79 0 1 6 . &> /dev/null
2985 ;;
2986 acpid)
2987 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 10 2 3 4 5 . stop 21 0 1 6 . &> /dev/null
2988 ;;
2989 acpi-support)
2990 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 99 2 3 4 5 . stop 20 0 1 6 . &> /dev/null
2991 ;;
2992 usplash)
2993 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 98 2 3 4 5 . stop 01 0 1 6 . &> /dev/null
2994 ;;
2995 arm-wol)
2996 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 99 2 3 4 5 . &> /dev/null
2997 ;;
2998 dbus)
2999 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 12 2 3 4 5 . &> /dev/null
3000 ;;
3001 hal)
3002 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i start 24 2 3 4 5 . &> /dev/null
3003 ;;
3004 *)
3005 chroot $drbl_common_root/ /usr/sbin/update-rc.d $i defaults &> /dev/null
3006 ;;
3007 esac
3008 fi
3009 elif [ -e /etc/SuSE-release ]; then
3010 # SuSE
3011 chroot $drbl_common_root/ /sbin/insserv -f $i
3012 else
3013 # RH-like
3014 # Note by Steven Shiau on 2006/9/26
3015 # Mandriva 2007 uses LSB service config and parallel init.
3016 # We have to modify some services
3017 case "$i" in
3018 ypbind)
3019 # remove ypserv
3020 perl -pi -e 's/^(#[[:space:]]*Should-Start: )(ypserv)(.*)/$1 $3/g' $drbl_common_root/etc/init.d/$i
3021 perl -pi -e 's/^(#[[:space:]]*Should-Stop: )(ypserv)(.*)/$1 $3/g' $drbl_common_root/etc/init.d/$i
3022 ;;
3023 dm)
3024 # We need drblthincli to run before dm, so when drblthincli is on, it
3025 # will start before dm.
3026 perl -pi -e 's/^#[[:space:]]*Required-Start:.*/# Required-Start: xfs firstboot netfs drblthincli/g' $drbl_common_root/etc/init.d/$i
3027 ;;
3028 netfs)
3029 # Mandriva 2009.0 or newer netfs will exit if /var/lock/subsys/network not existing.
3030 # It's: [ ! -f /var/lock/subsys/network -a ! -f /var/lock/subsys/NetworkManager ] && exit 0
3031 perl -pi -e 's|(^[[:space:]]*)(.*/var/lock/subsys/network.*)|$1#$2 # Modified by DRBL|g' $drbl_common_root/etc/init.d/$i
3032 ;;
3033 esac
3034 chroot $drbl_common_root/ /sbin/chkconfig --add $i
3035 # case "$i" in
3036 # ypbind)
3037 # # When using chkconfig --add ypbind, client do not put in rcx.d, since on
3038 # # RH/FC it is:
3039 # # chkconfig: - 27 73
3040 # # Hence we use chkconfig ypbind to turn on it.
3041 # # For Mandriva 2010.0, "chkconfig ypbind on" will also make ypbind on in rc7.d (although it's "# chkconfig: 345 17 83" in mandriva's /etc/init.d/ypbind, but since mandriva 2007 it has used LSB service config instead of honor the chkconfig tag), but it will fail when running graphic mode since rpcbind is not on in rc7.d. Here we can not force to turn on it.
3042 # if [ -n "$(grep -E "^# chkconfig: - " $drbl_common_root/etc/init.d/$i)" ]; then
3043 # # For RH/FC case
3044 # chroot $drbl_common_root/ /sbin/chkconfig $i on
3045 # fi
3046 # esac
3047 # 10/27/2012 Force to turn on the service. If only using "chkconfig --add", the service might not be in the "on" status. It will only make those services "on" on the server to be "on" on the client. Thanks to Odin Nøsen for reporting this.
3048 # Ref: http://sourceforge.net/mailarchive/forum.php?thread_name=CANCtYmUJYn5XNx6RS-sP9xVWqctjHYahn0egWY_Bxc-%2BTGnMiA%40mail.gmail.com&forum_name=drbl-user
3049 chroot $drbl_common_root/ /sbin/chkconfig $i on
3050 fi
3051 done
3052 # Deal with ocs-run service in systemd environment
3053 # 1. create rescue.target and services files
3054 # 2. make a link of rescue.service to ocsd-rescue.service
3055 # 3. remove /etc/rc*.d/S*ocs-run to avoid ocs-run service competition
3056 if is_systemd_init; then
3057 [ -e /etc/lsb-release ] && . /etc/lsb-release
3058 [ ! -d "$drbl_common_root/etc/systemd/system/rescue.target.wants" ] && mkdir "$drbl_common_root/etc/systemd/system/rescue.target.wants"
3059 cp -P $drbl_common_root/etc/systemd/system/multi-user.target.wants/* $drbl_common_root/etc/systemd/system/rescue.target.wants/
3060 if [ -d $drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/systemd/system ]; then
3061 # For Ubuntu, first find its own one.
3062 cp $drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/systemd/system/ocsd-*.service $drbl_common_root/etc/systemd/system/
3063 elif [ -d $drbl_setup_path/files/${OS_type}/${OS_Version}/systemd/system ]; then
3064 cp $drbl_setup_path/files/${OS_type}/${OS_Version}/systemd/system/ocsd-*.service $drbl_common_root/etc/systemd/system/
3065 else
3066 # Can not find fine-tune file, show warning, and use the most related one.
3067 OS_Version_Major="${OS_Version:0:3}" # E.g. CO7.1.1503 -> CO7; DBN9.2 -> DBN9
3068 most_related_ver_d="$(LC_ALL=C find $drbl_setup_path/files/$OS_type/${OS_Version_Major}* -maxdepth 1 -type d -exec dirname {} \; 2>/dev/null | sort -V | uniq | tail -n 1)"
3069 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3070 echo "Warning! The fine-tune files in dir ${drbl_setup_path}/files/${OS_type}/${OS_Version}/systemd/system/ were not found. Using ocs-related systemd files in ${most_related_ver_d}/ for client's systemd service."
3071 echo "This may cause some problems to DRBL clients!"
3072 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3073 sleep 7
3074 cp ${most_related_ver_d}/systemd/system/ocsd-*.service $drbl_common_root/etc/systemd/system/
3075 fi
3076 ln -sf ocsd-rescue.service $drbl_common_root/etc/systemd/system/rescue.service
3077 rm -rf $drbl_common_root/etc/rc*.d/S*ocs-run
3078 fi
3079
3080 # copy those rcS.d services for Debian, this can only be done after all updata-rc.d finished. Otherwise it will affect the update-rc.d
3081 if [ -e /etc/debian_version ]; then
3082 # Exclude those not necessary.
3083 # Put the service to be removed in $unnecessary_rcsd_srv if you have.
3084 RCS_D_EXCLUDE=""
3085 unnecessary_rcsd_srv=""
3086 for isv in $unnecessary_rcsd_srv; do
3087 RCS_D_EXCLUDE="$RCS_D_EXCLUDE --exclude=S*${isv} "
3088 done
3089 rsync -a $RCS_D_EXCLUDE /etc/rcS.d/* $drbl_common_root/etc/rcS.d/
3090 # Force to overwrite the modified networking service. We should not overwrite the symbolic link file for Ubuntu's client. It's linked to /lib/init/upstart-job
3091 if [ ! -L $drbl_common_root/etc/init.d/networking ]; then
3092 cp -af $drbl_setup_path/files/misc/networking $drbl_common_root/etc/init.d/
3093 fi
3094 # force to link some necessary services, since Knoppix or B2D won't have
3095 # them, but in DRBL, it's a must!!!
3096 (
3097 cd $drbl_common_root/etc/rcS.d/
3098 [ -f ../init.d/mountvirtfsn ] && ln -fs ../init.d/mountvirtfsn S02mountvirtfsn
3099 [ -f ../init.d/discover ] && ln -fs ../init.d/discover S36discover
3100 # B2D pureGnome 20051212 does not have hotplug* in rcS.d, but pureKDE has.
3101 # Anyway, for to link them.
3102 [ -f ../init.d/hotplug ] && ln -fs ../init.d/hotplug S40hotplug
3103 [ -f ../init.d/hotplug-net ] && ln -fs ../init.d/hotplug-net S41hotplug-net
3104 # change the hdparm from S07 to S60 (which is far after S41force-load-ide so we can access IDE device after IDE-related modules are loaded and ready).
3105 if [ -f ../init.d/hdparm ]; then
3106 [ -e "S07hdparm" ] && rm -f S07hdparm
3107 ln -fs ../init.d/hdparm S60hdparm
3108 fi
3109 [ -f ../init.d/portmap ] && ln -fs ../init.d/portmap S43portmap
3110 [ -f ../init.d/rpcbind ] && ln -fs ../init.d/rpcbind S43rpcbind
3111 [ -f ../init.d/mountnfs.sh ] && ln -fs ../init.d/mountnfs.sh S45mountnfs.sh
3112 )
3113 # modify some services which maybe not fit the requirement.
3114 # a. module-init-tools, since the method it detects rw is not quite well.
3115 if [ -e $drbl_common_root/etc/init.d/module-init-tools ]; then
3116 perl -pi -e 's|if \[ -w /lib/modules/\$KVER.*|if touch /lib/modules/\$KVER/modules.dep 2>/dev/null; then|g' $drbl_common_root/etc/init.d/module-init-tools
3117 fi
3118 fi
3119
3120 vmware_as_server="$(grep "VMWare Inc" /proc/pci 2>/dev/null)"
3121 # for VMWare, you have better to install the VMWare tools,
3122 if [ -n "$vmware_as_server" ]; then
3123 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3124 echo "It is VMWare as DRBL server ..., If you want to use X Window, make sure you already installed VMWare tools."
3125 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3126 fi
3127 # First, clean the XF86Config,
3128 # let configure (like redhat-cfg-xfree86) in /etc/init.d/firstboot
3129 # to create the first one.
3130 # Remove XF86Config and xorg.conf (Both for RH/MDK) in common root
3131 # NOTE! We can NOT remove XF86Config-4/xorg.conf for Debian... it is a template, just rename it.
3132 if [ -e /etc/debian_version ]; then
3133 # Debian
3134 for ix in XF86Config-4 xorg.conf; do
3135 [ -e "$drbl_common_root/etc/X11/$ix" ] && mv -f $drbl_common_root/etc/X11/${ix} $drbl_common_root/etc/X11/${ix}.drbl.template
3136 done
3137 # Debian Sarge does not sync the locale setting of gdm with system. do it
3138 if [ -f /etc/default/gdm ]; then
3139 # use subshell to avoid the running shell
3140 (
3141 # For B2D, it uses /etc/sysconfig/i18n...
3142 [ -e /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
3143 # the environment priority is higher then /etc/sysconfig/i18n
3144 [ -e /etc/environment ] && . /etc/environment
3145 if [ -n "$LANG" ]; then
3146 if grep -q "^[[:space:]]*#*[[:space:]]*LANG=.*" $drbl_common_root/etc/default/gdm 2>/dev/null; then
3147 perl -pi -e "s/^[[:space:]]*#*[[:space:]]*LANG=.*/LANG=$LANG/g" $drbl_common_root/etc/default/gdm
3148 else
3149 echo "LANG=$LANG" >> $drbl_common_root/etc/default/gdm
3150 fi
3151 fi
3152 )
3153 fi
3154 else
3155 # RH-like
3156 for ix in XF86Config xorg.conf; do
3157 [ -e "$drbl_common_root/etc/X11/$ix" ] && rm -f $drbl_common_root/etc/X11/${ix}*
3158 done
3159 fi
3160
3161 # Remove the firstboot setting to aviod it says NO
3162 [ -f $drbl_common_root/etc/sysconfig/firstboot ] && rm -f $drbl_common_root/etc/sysconfig/firstboot
3163 # Remove the /etc/reconfigSys to avoid firstboot run reconfig
3164 [ -f $drbl_common_root/etc/reconfigSys ] && rm -f $drbl_common_root/etc/reconfigSys
3165 # Disable the /usr/sbin/firstboot in the firstboot service, we should not reconfig ntp, user accounts for clients... This is for Redhat, Fedora...
3166 if [ -e $drbl_common_root/etc/init.d/firstboot ]; then
3167 perl -p -i -e 's|^(\s*)(/usr/sbin/firstboot.*)$|$1true # $2 # Modified by DRBL|g' $drbl_common_root/etc/init.d/firstboot
3168 fi
3169
3170 # Take care the hardware config files, clean old, make them be detected at boot.
3171 if [ -e /etc/debian_version ]; then
3172 # Debian
3173 # In Debian, we need to keep the modules.conf* so that discover will work.
3174 # We can not force to put ide-cd ide-disk ide-generic modules in /etc/modules (they are loaded by /etc/rcS.d/S20modutils), this will result chip driver (like piix and ide_core) is loaded afther them (by /etc/rcS.d/S40hotplut). This will cause a problem: unable to turn on IDE HD DMA ("HDIO_SET-DMA failed: Operation not permitted")
3175 # So we create a startup script after hotplug.
3176 if [ -f $drbl_common_root/etc/modules ]; then
3177 rm -f $drbl_common_root/etc/modules
3178 cat <<-MOD_END > $drbl_common_root/etc/modules
3179 # /etc/modules: kernel modules to load at boot time.
3180 #
3181 # This file should contain the names of kernel modules that are
3182 # to be loaded at boot time, one per line. Comments begin with
3183 # a "#", and everything on the line after them are ignored.
3184
3185 # Note from DRBL:
3186 # These modules are cleaned by DRBL drblpush so that we have a clean file.
3187 # You can add any module you need here. But do not force to put ide-cd ide-disk ide-generic modules here, this will result chip driver (like piix and ide_core) is loaded afther them (by /etc/rcS.d/S40hotplut). This will cause a problem: unable to turn on IDE HD DMA ("HDIO_SET-DMA failed: Operation not permitted")
3188 # DRBL will load ide-* in /etc/rcS.d/S41force-load-ide
3189
3190 MOD_END
3191 fi
3192 cp -f $drbl_setup_path/files/misc/force-load-ide $drbl_common_root/etc/init.d/force-load-ide
3193 prepare_update_rc_d_env $drbl_common_root/
3194 if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
3195 chroot $drbl_common_root/ insserv force-load-ide &> /dev/null
3196 else
3197 chroot $drbl_common_root/ /usr/sbin/update-rc.d force-load-ide start 41 S . &> /dev/null
3198 fi
3199 elif [ -e /etc/SuSE-release ]; then
3200 # SuSE
3201 # No more force to put some almost-must modules (ide-disk...) in /etc/sysconfig/kernel, same reason with the Debian one.
3202 # Here we modify hwscan to let it run in boot.d and add a service "force-load-ide" in boot.d
3203 # hwscan only exists in SuSE 9.3, in 10.0 or later it's gone!
3204 create_insserv_env $drbl_common_root/
3205 for i in parse-load-mod-suse force-load-ide; do
3206 cp -f $drbl_setup_path/files/misc/$i $drbl_common_root/etc/init.d/
3207 chroot $drbl_common_root/ /sbin/insserv -f $i
3208 done
3209 # modify boot.idedma service to make it after force-load-ide
3210 if [ -e "$drbl_common_root/etc/init.d/boot.idedma" ]; then
3211 chroot $drbl_common_root/ /sbin/insserv -f -r boot.idedma
3212 perl -pi -e 's/^#[[:space:]]*Required-Start:.*/# Required-Start: boot.loadmodules force-load-ide/g' $drbl_common_root/etc/init.d/boot.idedma
3213 chroot $drbl_common_root/ /sbin/insserv -f boot.idedma
3214 fi
3215 # process the hwscan for SuSE 9.3
3216 if [ -e "$drbl_common_root/etc/init.d/hwscan" ]; then
3217 perl -pi -e 's/^#[[:space:]]*Default-Start:.*/# Default-Start: B/g' $drbl_common_root/etc/init.d/hwscan
3218 chroot $drbl_common_root/ /sbin/insserv -f hwscan
3219 fi
3220 # xfs need account nobody, which only exists in YP, so we have to make xfs runs after ypbind.
3221 if [ -e "$drbl_common_root/etc/init.d/xfs" ]; then
3222 if ! grep -Eq "^#[[:space:]]*Required-Start:.* ypbind" $drbl_common_root/etc/init.d/xfs; then
3223 perl -pi -e 's/(^#[[:space:]]*Required-Start:.*)/$1 ypbind/g' $drbl_common_root/etc/init.d/xfs
3224 fi
3225 chroot $drbl_common_root/ /sbin/insserv -f xfs
3226 fi
3227 # To avoid the loop error (i.e. haldaemon need nfs, nfs need network, network need haldaemon, we remove haldaemon in network. Then we can make haldaemon after nfs. (Although network service is not enabled in client, but we still have to do this modification.) without "chroot $drbl_common_root/ /sbin/insserv -f network" it.
3228 if [ -e "$drbl_common_root/etc/init.d/network" ]; then
3229 chroot $drbl_common_root/ /sbin/insserv -f -r network
3230 perl -pi -e 's/(^#[[:space:]]*Required-Start:.*)haldaemon/$1/g' $drbl_common_root/etc/init.d/network
3231 chroot $drbl_common_root/ /sbin/insserv -f network
3232 fi
3233 # modify haldaemon service to make it after nfs, since
3234 # ldd /usr/sbin/hald:
3235 # ...
3236 # libgobject-2.0.so.0 => /opt/gnome/lib/libgobject-2.0.so.0 (0xb7ec9000)
3237 # libglib-2.0.so.0 => /opt/gnome/lib/libglib-2.0.so.0 (0xb7e43000)
3238 # libdbus-1.so.2 => /usr/lib/
3239 # ...
3240 # so we need to make it after NFS directories (/usr/, /opt) are mounted.
3241 if [ -e "$drbl_common_root/etc/init.d/haldaemon" ]; then
3242 chroot $drbl_common_root/ /sbin/insserv -f -r haldaemon
3243 perl -pi -e 's/^#[[:space:]]*Required-Start:.*/# Required-Start: boot.localnet dbus nfs/g' $drbl_common_root/etc/init.d/haldaemon
3244 chroot $drbl_common_root/ /sbin/insserv -f haldaemon
3245 fi
3246 #
3247 else
3248 # RH-like
3249 # Only for RH-like distribution, we can remove the modules.conf*
3250 # remove the etc/modules.conf in template so that the kudzu in the client can create their own hardware config file.
3251 # In Debian, we need to keep the modules.conf* so that discover will work.
3252 find $drbl_common_root/etc/ -name "modules.conf*" -exec rm -f {} \;
3253 fi
3254
3255 # remove the script in rc[0,6].d to let the client can halt and reboot
3256 if [ -e /etc/debian_version ]; then
3257 # Debian
3258 # For Debian, we use update-rc.d to assign which level run which program, so
3259 # no networking & umountnfs.sh
3260 true
3261 elif [ -e /etc/SuSE-release ]; then
3262 # SuSE
3263 client_halt_reboot_runlevel_must_remove_srv="nfs network"
3264 for i in $client_halt_reboot_runlevel_must_remove_srv; do
3265 # Note! Only for K[0-9][0-9]*, since nfs is nfs client in SuSE, we need it
3266 # to start, but do not want it to be killed when change runlevel, reboot
3267 # or halt.
3268 rm -f $drbl_common_root/etc/init.d/rc[123456].d/K[0-9][0-9]$i
3269 done
3270 else
3271 # RH-like
3272 client_halt_reboot_runlevel_must_remove_srv="netfs network killall"
3273 for i in $client_halt_reboot_runlevel_must_remove_srv; do
3274 rm -f $drbl_common_root/etc/rc[06].d/[SK][0-9][0-9]$i
3275 done
3276 fi
3277
3278 # force to disable selinux in the client.
3279 for ise in /etc/selinux/config /etc/sysconfig/selinux; do
3280 if [ -f $drbl_common_root/$ise ]; then
3281 perl -pi -e "s/^SELINUX=.*/SELINUX=disabled/g" $drbl_common_root/$ise
3282 fi
3283 done
3284
3285 # remove the template's etc/sysconfig/hwconf which kudzu will log
3286 [ -f $drbl_common_root/etc/sysconfig/hwconf ] && rm -f $drbl_common_root/etc/sysconfig/hwconf
3287
3288 # Prepare the critical program mount.nfs, since some lib could be in /usr/lib/ (e.g. Fedora 12 or Mandriva 2010.0).
3289 # Variable DESTDIR is required for copy_exec_drbl use
3290 export DESTDIR="$drbl_common_root"
3291 [ -e "/sbin/mount.nfs" ] && copy_exec_drbl /sbin/mount.nfs /sbin/
3292
3293 # The root over NFS mount is done in sbin/init which Steven modified,
3294 # $nfsserver:$drbl_common_root
3295 # so remove this file
3296 [ -f $drbl_common_root/etc/fstab ] && rm -f $drbl_common_root/etc/fstab
3297
3298 # clean the rhn config, client should not do that.
3299 [ -d $drbl_common_root/etc/sysconfig/rhn ] && rm -rf $drbl_common_root/etc/sysconfig/rhn 2> /dev/null
3300
3301 # Before copying init.drbl as $drbl_common_root/sbin/init (copyied in the
3302 # revious rsync command), we'd better to remove $drbl_common_root/sbin/init
3303 # therwise if it's a symbolic file, which might cause the server /sbin/init
3304 # o fail. This is the case in systemd:
3305 # lrwxrwxrwx 1 root root 20 Apr 17 09:37 /sbin/init -> /lib/systemd/systemd*
3306 rm -f $drbl_common_root/sbin/init
3307 cp -f $drbl_setup_path/files/misc/init.drbl $drbl_common_root/sbin/init
3308 # Find if the dir /run is mounted as tmpfs. If not, disable that for client.
3309 run_fs="$(LC_ALL=C df -T /run 2>/dev/null |grep -Ew "/run" | awk -F" " '{print $1}')"
3310 if [ "$run_fs" != "tmpfs" ]; then
3311 perl -pi -e "s/^TMPFS_RUN=.*/TMPFS_RUN=\"false\" # Enabled by drblpush./g" $drbl_common_root/sbin/init
3312 fi
3313 chown root:root $drbl_common_root/sbin/init
3314 chmod 755 $drbl_common_root/sbin/init
3315
3316 # mkdir special directory etc/diskless-image for each diskless host to mount its fstab
3317 #
3318 mkdir -p $drbl_common_root/etc/diskless-image
3319
3320 # copy dev tarball to $drbl_common_root/etc/diskless-image
3321 # For older version of udev, we test udevd, for newer one, we test udevadm
3322 if [ -x "$drbl_common_root/usr/sbin/udevadm" -o \
3323 -x "$drbl_common_root/usr/bin/udevadm" -o \
3324 -x "$drbl_common_root/usr/sbin/udevd" ]; then
3325 echo -n "Using udev for clients... "
3326 elif [ -f "$drbl_pkgdir/dev.tgz" ]; then
3327 echo -n "Using old-style dev for clients... "
3328 cp -f $drbl_pkgdir/dev.tgz $drbl_common_root/etc/diskless-image
3329 else
3330 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
3331 echo "Can NOT find udev or the dev.tgz, did you already setup the DRBL server ?"
3332 echo "Please press Ctrl-C to stop the program!"
3333 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3334 read
3335 exit 1
3336 fi
3337
3338 # Switch client graphic/text mode
3339 case "$OS_type" in
3340 RH|MDK|SUSE)
3341 # set the init to user specifies
3342 case "$client_init" in
3343 "text")
3344 CLIENT_INIT_RL=3
3345 ;;
3346 "graphic")
3347 CLIENT_INIT_RL=5
3348 ;;
3349 esac
3350 # systemd-liked use /etc/systemd/system/default.target link to default runlevel
3351 [ -L "$drbl_common_root/etc/systemd/system/default.target" ] && ln -fsv /lib/systemd/system/runlevel${CLIENT_INIT_RL}.target $drbl_common_root/etc/systemd/system/default.target || perl -p -i -e "s/^id:[1-5]:initdefault:/id:$CLIENT_INIT_RL:initdefault:/g" $drbl_common_root/etc/inittab
3352 ;;
3353 DBN)
3354 default_dm="$(drbl-check-dm 2> /dev/null)"
3355 if [ -n "$default_dm" ]; then
3356 case "$client_init" in
3357 "text")
3358 echo "Set text mode for Debian DRBL client..."
3359 prepare_update_rc_d_env $drbl_common_root/
3360 if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
3361 chroot $drbl_common_root/ insserv -f -r $default_dm &> /dev/null
3362 else
3363 chroot $drbl_common_root/ /usr/sbin/update-rc.d -f $default_dm remove &> /dev/null
3364 fi
3365 #clean_update_rc_d_env $drbl_common_root/
3366 # For upstart 0.6.3 (Ubuntu 9.10) or later it uses /etc/init/*.conf
3367 if [ -e "$drbl_common_root/etc/init/${default_dm}.conf" ]; then
3368 switch_upstart_service $drbl_common_root/etc/init/${default_dm}.conf off
3369 fi
3370 ;;
3371 "graphic")
3372 if [ -n "$default_dm" ]; then
3373 echo "Set graphic mode for Debian DRBL client..."
3374 prepare_update_rc_d_env $drbl_common_root/
3375 # gdm should be later than nis (S12), and should be later than hal (S24)
3376 if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
3377 chroot $drbl_common_root/ insserv $default_dm &> /dev/null
3378 else
3379 chroot $drbl_common_root/ /usr/sbin/update-rc.d $default_dm start 30 2 3 4 5 . stop 01 0 1 6 . &> /dev/null
3380 fi
3381 #clean_update_rc_d_env $drbl_common_root/
3382 # For upstart 0.6.3 (Ubuntu 9.10) or later it uses /etc/init/*.conf
3383 if [ -e "$drbl_common_root/etc/init/${default_dm}.conf" ]; then
3384 switch_upstart_service $drbl_common_root/etc/init/${default_dm}.conf on
3385 fi
3386 fi
3387 ;;
3388 esac
3389 else
3390 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3391 echo "The default display manager is NOT found! We can NOT set text or graphic mode for Debian DRBL client."
3392 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3393 fi
3394 ;;
3395 esac
3396
3397 # Turn off all the xinted/inted services in clients.
3398 # Set the tftpd to on when xinetd/inted starts in server.
3399 # (1) for client:
3400 if [ -e /etc/debian_version ]; then
3401 # Debian
3402 if grep -q "^tftp[[:space:]]+" $drbl_common_root/etc/inetd.conf 2>/dev/null; then
3403 # Note: /usr/sbin/update-inetd is perl, and require some perl modules.
3404 # It need /usr/share/perl5/DebianNet.pm, but it depends on perl version.
3405 #chroot $drbl_common_root /usr/sbin/update-inetd --remove tftp
3406 # Here we use easier method, just delete the tftp in /etc/inetd.conf
3407 # It looks like:
3408 # tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot
3409 perl -pi -e "s/^tftp[[:space:]]+.*//g" $drbl_common_root/etc/inetd.conf
3410 fi
3411 if [ -e $drbl_common_root/etc/init.d/tftpd-hpa ]; then
3412 # it's a standalone daemon
3413 prepare_update_rc_d_env $drbl_common_root/
3414 if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
3415 chroot $drbl_common_root/ insserv -f -r tftpd-hpa &> /dev/null
3416 else
3417 chroot $drbl_common_root/ /usr/sbin/update-rc.d -f tftpd-hpa remove &> /dev/null
3418 fi
3419 fi
3420 else
3421 # RH-like & SuSE
3422 perl -p -i -e "s/disable.*=.*/disable = yes/g" $drbl_common_root/etc/xinetd.d/tftp
3423 fi
3424
3425 # (2) for server
3426 if [ -n "$(getenforce 2>/dev/null)" -a "$(getenforce 2>/dev/null)" = "Enforcing" ]; then
3427 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3428 echo "SELinux is 'Enabled' !! Please disable it or make it to work with DRBL relative service "
3429 sleep 10
3430 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3431 fi
3432 # Disable FirewallD
3433 if [ "$(LC_ALL=C firewall-cmd --state 2>/dev/null)" = "running" ]; then
3434 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3435 echo "'Firewlld' would be DISABLED and stop , then replace with iptables service !!!"
3436 systemctl stop firewalld.service
3437 systemctl disable firewalld.service
3438 sleep 10
3439 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3440 fi
3441
3442 # set the tftp to on when xinetd/inted starts and portmap or rpcbind settings in server.
3443 if [ -e /etc/debian_version ]; then
3444 # Debian
3445 # (1) tftpd
3446 # Force to remove tftpd in inetd if it's set, and we will add it later
3447 # and put our arguments "-s /tftpboot/nbi_img"
3448 if grep -q "^tftp" /etc/inetd.conf 2>/dev/null; then
3449 /usr/sbin/update-inetd --remove tftp
3450 fi
3451 if [ -e /etc/init.d/tftpd-hpa ]; then
3452 # Patch the /etc/init.d/tftp-hpa, the "set -e" should not be put otherwise
3453 # if tftpd-hpa is not started, "/etc/init.d/tftpd-hpa restart" (insted of
3454 # "/etc/init.d/tftpd-hpa start") will just stop and fail, will not start it.
3455 perl -p -i -e "s/^[[:space:]]*set -e.*/#set -e/g" /etc/init.d/tftpd-hpa
3456
3457 # From tftpd-hpa 5.0, the config file is different
3458 # /etc/init.d/tftpd-hpa is for Debian, while /etc/init/tftpd-hpa.conf is for Ubuntu's upstart
3459 if [ -n "$(grep -E TFTP_DIRECTORY /etc/init.d/tftpd-hpa 2>/dev/null)" -a \
3460 -n "$(grep -E TFTP_USERNAME /etc/init.d/tftpd-hpa 2>/dev/null)" ] || \
3461 [ -n "$(grep -E TFTP_DIRECTORY /etc/init/tftpd-hpa.conf 2>/dev/null)" -a \
3462 -n "$(grep -E TFTP_USERNAME /etc/init/tftpd-hpa.conf 2>/dev/null)" ]; then
3463 # Version 5.0 or later.
3464 cat <<-TFTP_END > /etc/default/tftpd-hpa
3465 TFTP_USERNAME="tftp"
3466 TFTP_DIRECTORY="/tftpboot/nbi_img"
3467 TFTP_ADDRESS="0.0.0.0:69"
3468 TFTP_OPTIONS="--secure --ipv4"
3469 TFTP_END
3470 else
3471 # Version 0.49 or before.
3472 # it's a standalone daemon
3473 cat <<-TFTP_END > /etc/default/tftpd-hpa
3474 RUN_DAEMON="yes"
3475 OPTIONS="-l -s /tftpboot/nbi_img"
3476 TFTP_END
3477 fi
3478 # (2) Portmap. From portmap (6.0-11), when new installation, default the question whether to bind to the loopback interface only. We have to open it.
3479 if [ -e /etc/default/portmap ]; then
3480 perl -pi -e 's/^(OPTIONS=.*)/#$1 # Commented by DRBL/g' /etc/default/portmap
3481 fi
3482 else
3483 # it's a daemon in inetd, set it in inetd.conf
3484 /usr/sbin/update-inetd --group BOOT --add 'tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /tftpboot/nbi_img'
3485 fi
3486 else
3487 # RH-like & SuSE
3488 if [ -e /etc/xinetd.d/tftp ]; then
3489 # set the tftp working directory to be /tftpboot/nbi_img
3490 # to have higher security.
3491 perl -p -i -e "s/disable.*=.*/disable = no/g" /etc/xinetd.d/tftp
3492 perl -p -i -e "s/server_arg.*=.*/server_args = -s \/tftpboot\/nbi_img/g" /etc/xinetd.d/tftp
3493 fi
3494 # For systemd distr. , ex: Fedora 21
3495 if [ -e /usr/lib/systemd/system/tftp.service ]; then
3496 perl -p -i -e "s/^(ExecStart=\S*)[[:space:]]+.*$/\$1 -s \/tftpboot\/nbi_img/g" /usr/lib/systemd/system/tftp.service
3497 fi
3498 fi
3499
3500 # create a config file for each diskless host to mount its fstab
3501 # Steven to do, what's master ?
3502 cat <<-CONFIG_END > $drbl_common_root/etc/diskless-image/config
3503
3504 nfsserver_default=$nfsserver_default
3505 nfsimagedir=$drbl_common_root
3506 nfshostsdir=$drblroot
3507 nameserver="$nameserver"
3508
3509 CONFIG_END
3510
3511 # for clients' public IP
3512 # if the file $public_ip_list is created, copy it
3513 [ -f "$public_ip_list" ] && cp -f $public_ip_list $drbl_common_root/etc/diskless-image/
3514
3515 # copy the collected MAC addresses to drbl sysconfig
3516 if [ "$collect_mac" = "yes" ]; then
3517 cp -f macadr-*.txt $drbl_syscfg/ &> /dev/null
3518 fi
3519
3520 # write the resolv.conf
3521 # //NOTE// For resolvconf on Ubuntu 12.04, the /etc/resolv.conf is linked to /run/resolvconf/resolv.conf, which is a tmpfs file system. Here just remove it.
3522 rm -f $drbl_common_root/etc/resolv.conf
3523
3524 for nameserver in $nameserver_; do
3525 echo "nameserver $nameserver" >> $drbl_common_root/etc/resolv.conf
3526 done
3527
3528 # rc.sysinit only in RH-like (BSD), no rc.sysinit in Debian/SuSE
3529 case "$OS_type" in
3530 RH|MDK)
3531 # For distribution RH/FC/CO/MDK/MDV
3532 if [ -f "${drbl_setup_path}/files/${OS_type}/${OS_Version}/rc.sysinit.${OS_Version}.drbl" ]; then
3533 cp -f ${drbl_setup_path}/files/${OS_type}/${OS_Version}/rc.sysinit.${OS_Version}.drbl $drbl_common_root/etc/rc.d/rc.sysinit
3534 else
3535 # Can not find fine-tune file, show warning. This is only necessary for CentOS <= 6, since for Fedora, when >= version 17, no required. //NOTE// From drbl 2.x, only CentOS and Fedora are supported.
3536 OS_Version_Major="${OS_Version:0:3}" # E.g. CO5.8 -> CO5
3537 case "$OS_Version" in
3538 CO*)
3539 if ! is_systemd_init; then
3540 most_related_ver="$(LC_ALL=C find $drbl_setup_path/files/$OS_type/${OS_Version_Major}* -type d -exec basename {} \; 2>/dev/null | sort | uniq | tail -n 1)"
3541 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3542 echo "Warning! The fine-tune file ${drbl_setup_path}/files/${OS_type}/${OS_Version}/rc.sysinit.${OS_Version}.drbl was not found. Using ${drbl_setup_path}/files/${OS_type}/${most_related_ver}/rc.sysinit.${most_related_ver}.drbl as /etc/rc.d/rc.sysinit for DRBL clients!"
3543 echo "This may cause some problems to DRBL clients!"
3544 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3545 [ -n "$most_related_ver" ] && cp -f ${drbl_setup_path}/files/${OS_type}/${most_related_ver}/rc.sysinit.${most_related_ver}.drbl $drbl_common_root/etc/rc.d/rc.sysinit
3546 fi
3547 ;;
3548 esac
3549 fi
3550 ;;
3551 esac
3552
3553 # "ln -fs tmp/boot/ boot" in template
3554 # insert "mkdir tmp/boot" in rc.sysinit of other clients, because it's tmpfs
3555 # so that /sbin/mkkerneldoth in rc.sysinit can creat file "/boot/boot.h"
3556 if [ ! -L "$drbl_common_root/boot" ]; then
3557 (cd $drbl_common_root; ln -fs tmp/boot boot)
3558 fi
3559
3560 # create the CLEAN rc.boot/boot.local/rc.local to avoid some commands copied from server
3561 if [ -e /etc/debian_version ]; then
3562 # Debian
3563 [ -d "$drbl_common_root/etc/rc.boot" ] && rm -f $drbl_common_root/etc/rc.boot/*
3564 elif [ -e /etc/SuSE-release ]; then
3565 # SuSE
3566 if [ -f "$drbl_common_root/etc/init.d/boot.local" ]; then
3567 perl -pi -e "s/^[[:space:]]*[^#]+//g" $drbl_common_root/etc/init.d/boot.local
3568 fi
3569 else
3570 # RH-like
3571 # 1st, clean rc.local
3572 [ -f $drbl_common_root/etc/rc.d/rc.local ] && rm -f $drbl_common_root/etc/rc.d/rc.local
3573
3574 # 2nd, create a clean rc.local
3575 cat <<-RC_LOCAL > $drbl_common_root/etc/rc.d/rc.local
3576 #!/bin/bash
3577 #
3578 # This script will be executed *after* all the other init scripts.
3579 # You can put your own initialization stuff in here if you don't
3580 # want to do the full Sys V style init stuff.
3581 export PATH=\$PATH:$DRBL_SCRIPT_PATH/sbin:$DRBL_SCRIPT_PATH/bin
3582
3583 touch /var/lock/subsys/local
3584
3585 # For Mandrake, harddrake will not create cdrom link automatically... so
3586 # detect it and create it.
3587 # While for Redhat, kudzu will do that. Anyway, we just do it.
3588 if [ ! -e "/dev/cdrom" ]; then
3589 cddev="\$(drbl-detect-cdrom)"
3590 [ -n "\$cddev" ] && ln -fs /dev/\$cddev /dev/cdrom
3591 fi
3592
3593 # For Mandrake, it use /mnt (tmpfs) instead of /media for cdrom, floppy, create the mount point in tmpfs, since mandrake does not create them automatically.
3594 # Although the problem is only in mandrake, but we still create them for all RH-like dists, since user maybe want to use these mount points.
3595 for d in floppy cdrom loop disk usb; do
3596 [ ! -d "/mnt/\$d" ] && mkdir -p /mnt/\$d
3597 done
3598
3599 RC_LOCAL
3600
3601 #change its mode
3602 chown root:root $drbl_common_root/etc/rc.d/rc.local
3603 chmod 775 $drbl_common_root/etc/rc.d/rc.local
3604 fi
3605
3606 # Modify some rc programs.
3607 # For RH-like, use the modified template etc/init.d/halt, which remove all the umount command
3608 # For Debian and SuSE, just use perl to modify them.
3609 if [ -e /etc/debian_version ]; then
3610 # Debian
3611 # For genuine Debian
3612 # remove -i in "reboot -d -f -i" so it won't stop network before reboot
3613 # remove -i in "halt -d -f -i -p" so it won't stop network before halt
3614 if [ -e $drbl_common_root/etc/init.d/reboot ]; then
3615 perl -pi -e 's/^([[:space:]]*reboot .*)-i(.*)/$1 $2 # Modified by DRBL/' $drbl_common_root/etc/init.d/reboot
3616 fi
3617 if [ -e $drbl_common_root/etc/init.d/halt ]; then
3618 perl -pi -e 's/^([[:space:]]*halt .*)-i(.*)/$1 $2 # Modified by DRBL/' $drbl_common_root/etc/init.d/halt
3619 fi
3620 # For B2D, the reboot and halt is a little different, except the above,
3621 # we have to comment umount -a
3622 if [ -e $drbl_common_root/etc/init.d/reboot ]; then
3623 perl -pi -e 's/^([[:space:]]*umount -a.*)/#$1 # Modified by DRBL/' $drbl_common_root/etc/init.d/reboot
3624 fi
3625 if [ -e $drbl_common_root/etc/init.d/halt ]; then
3626 perl -pi -e 's/^([[:space:]]*umount -a.*)/#$1 # Modified by DRBL/' $drbl_common_root/etc/init.d/halt
3627 fi
3628 # To force do not turn off network when rebooting/halting.
3629 if grep -Eq "^NETDOWN=" $drbl_common_root/etc/init.d/halt 2>/dev/null; then
3630 # If we found "NETDOWN=..." in /etc/init.d/halt, force to write NETDOWN=no in client's /etc/default/halt
3631 if ! grep -Eq "^NETDOWN=" $drbl_common_root/etc/default/halt 2>/dev/null; then
3632 echo "NETDOWN=no # Modified by DRBL" >> $drbl_common_root/etc/default/halt
3633 else
3634 if [ -e $drbl_common_root/etc/default/halt ]; then
3635 perl -pi -e 's/^NETDOWN=.*/NETDOWN=no # Modified by DRBL/' $drbl_common_root/etc/default/halt
3636 fi
3637 fi
3638 fi
3639 # Disable the /lib/init/rw removinig. Otherwise harmless errors will be shown during clents booting.
3640 if [ -e /lib/init/bootclean.sh ]; then
3641 LC_ALL=C perl -pi -e 's|(^[[:space:]]*)(clean /lib/init/rw "! -type d".*$)|$1#$2 # Modified by DRBL|g' $drbl_common_root/lib/init/bootclean.sh
3642 fi
3643
3644 # Do not clean or remove etc/mtab when boots, and force not to update etc/mtab
3645 if [ -e $drbl_common_root/etc/init.d/checkroot.sh ]; then
3646 perl -pi -e 's|^([[:space:]]*:> $MTAB_PATH.*)|#$1 # Modified by DRBL|' $drbl_common_root/etc/init.d/checkroot.sh
3647 perl -pi -e 's|^([[:space:]]*rm -f \$\{MTAB_PATH\}~.*)|#$1 # Modified by DRBL|' $drbl_common_root/etc/init.d/checkroot.sh
3648 perl -pi -e 's|^([[:space:]]*)INIT_MTAB_FILE=yes|$1 INIT_MTAB_FILE=no # Modified by DRBL|' $drbl_common_root/etc/init.d/checkroot.sh
3649 fi
3650 if [ -e $drbl_common_root/etc/init.d/checkfs.sh ]; then
3651 # Do not remove /fastboot, DRBL client is always fastboot
3652 perl -pi -e 's|^([[:space:]]*rm -f )(/fastboot)(.*)|$1 $3 # modified by DRBL|' $drbl_common_root/etc/init.d/checkfs.sh
3653 fi
3654 # bootmisc.sh will prevent client to login by showning
3655 # "System bootup in progress - please wait" > /etc/nologin
3656 # We must avoid /etc/nologin to be created by set DELAYLOGIN=no in client's /etc/default/rcS
3657 if [ -e $drbl_common_root/etc/default/rcS ]; then
3658 perl -pi -e 's|^[[:space:]]*DELAYLOGIN=.*|DELAYLOGIN=no # modified by DRBL|' $drbl_common_root/etc/default/rcS
3659 fi
3660
3661 if [ -x "$drbl_common_root/etc/init.d/linux-restricted-modules-common" ]; then
3662 # $drbl_common_root/lib/modules/$KERNEL_VER/volatile is already created in drblsrv-offline for Ubuntu. Here we have to modify linux-restricted-modules-common service so that it can write in /lib/modules/$KERNEL_VER/volatile, otherwise it is Read-Only NFS filesystem.
3663 # /sbin/lrm-manager --quick ->
3664 # mount -n -t tmpfs tmpfs /lib/modules/`uname -r`/volatile; /sbin/lrm-manager --quick # Modified by DRBL
3665 perl -pi -e 's|^([[:space:]]*)(/sbin/lrm-manager --quick.*)|$1mount -n -t tmpfs tmpfs /lib/modules/`uname -r`/volatile; $2 # Modified by DRBL|g' $drbl_common_root/etc/init.d/linux-restricted-modules-common
3666 fi
3667
3668 # Debian Etch has NetworkManager/NetworkManagerDispatcher under dbus, we can not let it start in client. Otherwise the network in client will be reset.
3669 rm -f $drbl_common_root/etc/dbus-1/event.d/[0-9][0-9]NetworkManager*
3670
3671 # Making mountkernfs.sh and mountdevsubfs.sh start with updating /etc/mtab, otherwise when it's run 2nd time with reload (mountkernfs.sh reload), it will complain that
3672 # mount: can't find /run/lock in /etc/fstab or /etc/mtab
3673 # mount: can't find /run/shm in /etc/fstab or /etc/mtab
3674 # This is for Debian Jessie because mountkernfs.sh and mountdevsubfs.sh use different flag than that in Wheezy and Squeeze.
3675 # start)
3676 # mount_filesystems mount_noupdate -> mount_filesystems mount
3677 # ;;
3678 for i in mountkernfs.sh mountdevsubfs.sh; do
3679 if [ -e $drbl_common_root/etc/init.d/$i ]; then
3680 perl -pi -e 's|^([[:space:]]*)mount_filesystems mount_noupdate|$1mount_filesystems mount # modified by DRBL|' $drbl_common_root/etc/init.d/$i
3681 fi
3682 done
3683 # For Ubuntu dapper, /etc/init.d/mountnfs.sh is no more, and moved to /etc/network/if-up.d/mountnfs.sh. It will be run when ifup starts successfully in networking service. However, in DRBL client, network is actually started in initrd.
3684 # For Debian testing (on 2006/09/15), the mountnfs.sh from initscripts 2.86.ds1-19 or later use the same skill with waitnfs.sh, but it's name is mountnfs.sh. Hence we have to use the keyword "Wait for network file systems" to judge that, since in the mountnfs.sh, there is:
3685 # Short-Description: Wait for network file systems to be mounted
3686 # Ugly! This is a workaround, it's better to make the ifup command work in /etc/init.d/networking, then the /etc/network/if-up.d/mountnfs.sh can be run in client.
3687 use_start_srv_after_ifup="no"
3688 if grep -q -E "Wait for network file systems" $drbl_common_root/etc/init.d/mountnfs.sh 2>/dev/null; then
3689 use_start_srv_after_ifup="yes"
3690 elif [ -e $drbl_common_root/etc/init.d/waitnfs.sh ]; then
3691 use_start_srv_after_ifup="yes"
3692 fi
3693 if [ "$use_start_srv_after_ifup" = "yes" ]; then
3694 # mountnfs.sh is called in start-srv-after-ifup
3695 cp -af $drbl_setup_path/files/misc/start-srv-after-ifup $drbl_common_root/etc/init.d/
3696 for infsf in waitnfs.sh mountnfs.sh; do
3697 if [ -e $drbl_common_root/etc/init.d/$infsf ]; then
3698 # Here we also insert a line to create a dir /tmp/boot (/tmp is tmpfs so we have to use a service to do that everytime client boots) so the /boot link to /tmp/boot/ will work.
3699 # case (1): The function name is do_start (dapper)
3700 perl -pi -e 's|(^[[:space:]]*)do_start([[:space:]]*$)|$1/etc/init.d/start-srv-after-ifup; mkdir -p /tmp/boot; do_start # Modified by DRBL $2|' $drbl_common_root/etc/init.d/$infsf
3701 # case (2): The function name is do_wait_async_mount (etch), in this case
3702 # We'd better to force ASYNCMOUNTNFS=yes in /etc/default/rcS
3703 perl -pi -e 's|(^[[:space:]]*)do_wait_async_mount([[:space:]]*$)|$1/etc/init.d/start-srv-after-ifup; mkdir -p /tmp/boot; do_wait_async_mount # Modified by DRBL $2|' $drbl_common_root/etc/init.d/$infsf
3704 # mountnfs.sh is buggy, too. Actually it's mountpoint bug, which failed to identify some mount point as mount point, e.g. /usr/ and /var (mounted in init.drbl)
3705 # https://bugs.launchpad.net/ubuntu/+source/sysvinit/+bug/93634
3706 # A workaround is (1) not to put "/usr/" and "/var" in the list and (2) shorten the TIMEOUT.
3707 # Code for (1) to be commented in mountnfs.sh from Debian Lenny/Squeeze:
3708 # case "$MTPT" in
3709 # /usr/local|/usr/local/*)
3710 # ;;
3711 # /usr|/usr/*)
3712 # waitnfs="$waitnfs $MTPT"
3713 # ;;
3714 # /var|/var/*)
3715 # waitnfs="$waitnfs $MTPT"
3716 # ;;
3717 # esac
3718 # (1)
3719 mountnfs_file="$drbl_common_root/etc/init.d/$infsf"
3720 case_to_be_commented="usr var"
3721 for i in $case_to_be_commented; do
3722 chk_line_no="$(LC_ALL=C grep -n -F -- "/$i|/$i/*)" $mountnfs_file | cut -d":" -f1)"
3723 [ -z "$chk_line_no" ] && continue
3724 chk_next_line="$((chk_line_no + 1))"
3725 perl -pi -e "if (${chk_next_line}..${chk_next_line}) {s/^([[:space:]]+)(waitnfs=.*)/\$1#\$2 # Modified by DRBL/g}" $mountnfs_file
3726 done
3727 # (2)
3728 perl -pi -e 's/^([[:space:]]+)TIMEOUT=[[:digit:]]+/$1TIMEOUT=30 # Modified by DRBL/g' $drbl_common_root/etc/init.d/$infsf
3729 perl -pi -e 's|^[[:space:]]*ASYNCMOUNTNFS=.*|ASYNCMOUNTNFS=yes # Modified by DRBL|g' $drbl_common_root/etc/default/rcS
3730 fi
3731 done
3732 fi
3733 # UGLY!
3734 # The upstart (/etc/event.d/rc-default) in Ubuntu 6.10 to 9.04 is buggy, it does not honor the [013456] in /proc/cmdline
3735 # Ref: https://launchpad.net/ubuntu/+source/upstart/+bug/85014
3736 # It's fixed in Ubuntu 9.10 or later.
3737 [ -e /etc/lsb-release ] && . /etc/lsb-release
3738 if [ "$DISTRIB_ID" = "Ubuntu" ]; then
3739 case "$DISTRIB_RELEASE" in
3740 "6.10")
3741 cp -f $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/rc-default $drbl_common_root/etc/event.d/rc-default
3742 # For ubuntu 6.10-7.10 upstart problem.
3743 # Ref: https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/65230
3744 # Change the contents of /etc/event.d/tty[1-6]:
3745 # start on runlevel 2 -> start on stopped rc2
3746 for i in $drbl_common_root/etc/event.d/tty[0-9]; do
3747 perl -pi -e "s/^start on runlevel /start on stopped rc/g" $i
3748 done
3749 ;;
3750 "7.04"|"7.10"|"8.04"|"8.10"|"9.04")
3751 cp -f $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/rc-default $drbl_common_root/etc/event.d/rc-default
3752 # For ubuntu 6.10-7.10 upstart problem.
3753 # Ref: https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/65230
3754 # Change the contents of /etc/event.d/tty[1-6]:
3755 # start on runlevel 2 -> start on stopped rc2
3756 for i in $drbl_common_root/etc/event.d/tty[0-9]; do
3757 perl -pi -e "s/^start on runlevel /start on stopped rc/g" $i
3758 done
3759 # Disable the recovery-menu, use sulogin, otherwise the error messages of Clonezilla will be overwritten.
3760 if [ -e "$drbl_common_root/etc/event.d/rcS-sulogin" ]; then
3761 perl -pi -e "s|(^[[:space:]]*) /usr/share/recovery-mode/recovery-menu.*|\$1 /sbin/sulogin # Modified by DRBL. Force to use sulogin!|g" $drbl_common_root/etc/event.d/rcS-sulogin
3762 fi
3763 ;;
3764 "9.10")
3765 # The released rc-sysinit.conf is buggy. We use the one we patched.
3766 cp -af $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/rc-sysinit.conf $drbl_common_root/etc/init/rc-sysinit.conf
3767 cp -af $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/drbl-client-boot.conf $drbl_common_root/etc/init/drbl-client-boot.conf
3768 ;;
3769 *)
3770 # For Ubuntu 10.04 or later.
3771 if [ -e "$drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/drbl-client-boot.conf" ]; then
3772 cp -af $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/drbl-client-boot.conf $drbl_common_root/etc/init/drbl-client-boot.conf
3773 else
3774 if ! is_systemd_init; then
3775 # Only show this for upstart
3776 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3777 echo "Warning! Unable to find the fine-tune file $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/drbl-client-boot.conf, use $drbl_setup_path/files/Ubuntu/drbl-client-boot-default.conf for DRBL clients!"
3778 echo "This may cause some problems to DRBL clients!"
3779 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3780 cp -af $drbl_setup_path/files/Ubuntu/drbl-client-boot-default.conf $drbl_common_root/etc/init/drbl-client-boot.conf
3781 fi
3782 fi
3783 if [ -e "$drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/S00wait-drbl" ]; then
3784 cp -af $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/S00wait-drbl $drbl_common_root/etc/rcS.d/
3785 else
3786 if ! is_systemd_init; then
3787 # Only show this for upstart
3788 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3789 echo "Warning! Unable to find the fine-tune file $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/S00wait-drbl, use $drbl_setup_path/files/Ubuntu/S00wait-drbl-default for DRBL clients!"
3790 echo "This may cause some problems to DRBL clients!"
3791 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3792 cp -af $drbl_setup_path/files/Ubuntu/S00wait-drbl-default $drbl_common_root/etc/init/S00wait-drbl
3793 fi
3794 fi
3795 # For plymouth.conf, we won't let plymouthd to run in rc=1, even with --mode=shutdown, otherwise when running clonezilla job in the client, the initial screen might be in vt 7, and the clonezilla job is run at vt 1.
3796 if [ -e "$drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/plymouth.conf" ]; then
3797 # Use the customized plymouth.conf.
3798 cp -af $drbl_setup_path/files/Ubuntu/$DISTRIB_RELEASE/plymouth.conf $drbl_common_root/etc/init/plymouth.conf
3799 else
3800 if [ "$DISTRIB_RELEASE" \< 13.10 ]; then
3801 # Here if we use the override file like the following for
3802 # Ubuntu 13.10,
3803 # the client won't be able to enter lightdm, only stay in text mode.
3804 # This is OK for Clonezilla mode, but not for DRBL mode. This issue
3805 # is fixed on Ubuntu 13.10.
3806 # //NOTE// Here we can not use function switch_upstart_service because it will stop all, howerver, we only want to disable part of its action for Ubuntu < 13.10 otherwise it won't be able to enter lightdm.
3807 perl -pi -e 's|^([[:space:]]*)(exec /sbin/plymouthd --mode=shutdown)|$1true #$2 # Commented by DRBL to avoid no Clonezilla SE output messages on console 1|g' $drbl_common_root/etc/init/plymouth.conf
3808 #perl -pi -e 's|^([[:space:]]*)(exec /sbin/plymouthd --mode=boot --attach-to-session)|$1true #$2 # Commented by DRBL to avoid no Clonezilla SE output messages on console 1|g' $drbl_common_root/etc/init/plymouth.conf
3809 #perl -pi -e 's|^([[:space:]]*)(exec /bin/plymouth show-splash)|$1true #$2 # Commented by DRBL to avoid no Clonezilla SE output messages on console 1|g' $drbl_common_root/etc/init/plymouth.conf
3810 elif [ "$DISTRIB_RELEASE" \< 14.10 ]; then
3811 # 2018/02/09 Comment all. It seems for Ubuntu 14.04 the default behavior is OK now.
3812 # Ubuntu 13.10 - 14.04.
3813 # For upstart (>1.3) service, we can use override file (Ref: http://upstart.ubuntu.com/cookbook/#override-files)
3814 # echo "manual" > $drbl_common_root/etc/init/plymouth.override
3815 # For Ubuntu 14.04 or later, a command about plymouth was added in /etc/init/rc.conf. We have to disable it otherwise it will switch to vt7 but rc1 (where S19ocs-run is, especially for select-in-client mode of clonezilla) is still in vt1.
3816 # perl -pi -e 's|^([[:space:]]*)(status plymouth-shutdown.*start wait-for-state WAITER=rc WAIT_FOR=plymouth-shutdown.*)|$1true #$2 # Commented by DRBL to keep the services in rc in same console|g' $drbl_common_root/etc/init/rc.conf
3817 true
3818 else
3819 # Ubuntu 14.10 or later.
3820 # For Ubuntu 14.10 plymouth service is a must for client to start all required service,
3821 # Therefore we can not disable it.
3822 # For Ubuntu 14.04 or later, a command about plymouth was added in /etc/init/rc.conf. We have to disable it otherwise it will switch to vt7 but rc1 (where S19ocs-run is, especially for select-in-client mode of clonezilla) is still in vt1.
3823 perl -pi -e 's|^([[:space:]]*)(status plymouth-shutdown.*start wait-for-state WAITER=rc WAIT_FOR=plymouth-shutdown.*)|$1true #$2 # Commented by DRBL to keep the services in rc in same console|g' $drbl_common_root/etc/init/rc.conf
3824 # Somehow the unnecessary services in client's /etc/rcS.d/ cause the console behaves weird... like:
3825 # (1) The TUI output of partclone is distored
3826 # (2) Keyboard does not work well in the mode "select-in-client"
3827 # Therefore we just remove all of them except S00wait-drbl. It's OK to do so because all the required services are actually started by upstart already.
3828 # //NOTE// This workaround does not work well. It will cause client fails to reboot/shtudown. Therefore we can not use it.
3829 # if [ "$DISTRIB_RELEASE" = "14.10" ]; then
3830 # for isr in $drbl_common_root/etc/rcS.d/*; do
3831 # [ "$isr" = "$drbl_common_root/etc/rcS.d/S00wait-drbl" ] && continue
3832 # rm -f $isr
3833 # done
3834 # fi
3835 fi
3836 fi
3837 ;;
3838 esac
3839 fi
3840
3841 # Start for Linux Mint , by Ceasar
3842 if [ "$DISTRIB_ID" = "LinuxMint" -a -z "$(echo "$DISTRIB_DESCRIPTION" | grep -iE '^LMDE' )" ]; then
3843 case "$DISTRIB_RELEASE" in
3844 *)
3845 # LinuxMint "17"|"17.1"|"17.2") or later
3846 if [ -e "$drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/drbl-client-boot.conf" ]; then
3847 cp -af $drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/drbl-client-boot.conf $drbl_common_root/etc/init/drbl-client-boot.conf
3848 else
3849 if ! is_systemd_init; then
3850 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3851 echo "Warning! Unable to find the fine-tune file $drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/drbl-client-boot.conf, use $drbl_setup_path/files/${DISTRIB_ID}/drbl-client-boot-default.conf for DRBL clients!"
3852 echo "This may cause some problems to DRBL clients!"
3853 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3854 cp -af $drbl_setup_path/files/${DISTRIB_ID}/drbl-client-boot-default.conf $drbl_common_root/etc/init/drbl-client-boot.conf
3855 fi
3856 fi
3857
3858 if [ -e "$drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/S00wait-drbl" ]; then
3859 cp -af $drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/S00wait-drbl $drbl_common_root/etc/rcS.d/
3860 else
3861 if ! is_systemd_init; then
3862 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3863 echo "Warning! Unable to find the fine-tune file $drbl_setup_path/files/${DISTRIB_ID}/$DISTRIB_RELEASE/S00wait-drbl, use $drbl_setup_path/files/${DISTRIB_ID}/S00wait-drbl-default for DRBL clients!"
3864 echo "This may cause some problems to DRBL clients!"
3865 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3866 cp -af $drbl_setup_path/files/${DISTRIB_ID}/S00wait-drbl-default $drbl_common_root/etc/init/S00wait-drbl
3867 fi
3868 fi
3869 # deal with plymouth.conf
3870 if [ -e "$drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/plymouth.conf" ]; then
3871 # Use the customized plymouth.conf.
3872 cp -af $drbl_setup_path/files/${DISTRIB_ID}/${DISTRIB_RELEASE}/plymouth.conf $drbl_common_root/etc/init/plymouth.conf
3873 else
3874 if [ "$DISTRIB_RELEASE" \< 17 ]; then
3875 echo "Not supported version: DISTRIB_ID='$DISTRIB_ID' ; DISTRIB_RELEASE='$DISTRIB_RELEASE'";
3876 elif [ "$DISTRIB_RELEASE" \< 18 ]; then
3877 # For : LinuxMint 17.x
3878 echo "manual" > $drbl_common_root/etc/init/plymouth.override
3879 perl -pi -e 's|^([[:space:]]*)(status plymouth-shutdown.*start wait-for-state WAITER=rc WAIT_FOR=plymouth-shutdown.*)|$1true #$2 # Commented by DRBL to keep the services in rc in same console|g' $drbl_common_root/etc/init/rc.conf
3880 else
3881 # For : LinuxMint 18 or later (pre-expected)
3882 perl -pi -e 's|^([[:space:]]*)(status plymouth-shutdown.*start wait-for-state WAITER=rc WAIT_FOR=plymouth-shutdown.*)|$1true #$2 # Commented by DRBL to keep the services in rc in same console|g' $drbl_common_root/etc/init/rc.conf
3883 fi
3884 fi
3885 ;;
3886 *)
3887 echo "Not supported version :$DISTRIB_ID <$DISTRIB_RELEASE>";
3888 ;;
3889 esac
3890 fi
3891 # End for LinuxMint
3892
3893 # Modify upstart 0.6.3 /etc/init.d/*.conf.
3894 if [ -d "$drbl_common_root/etc/init" ]; then
3895 # For Ubuntu 9.10 upstart problem.
3896 # Ref: https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/405847
3897 # Change the contents of /etc/init/rc-sysinit.conf, since this rc-sysinit.conf file will be used for Clonezilla live and DRBL, in Clonezilla live we do not change the "start", but in DRBL we do. If we do not change it to be "drbl-client-boot", which is after "startup", the /sbin/init.orig will do nothing since in DRBL client, it's diskless, so no "filesystem".
3898 # start on .* -> start on startup.
3899 # For portmap.conf, one more extra line, i.e.:
3900 #start on (local-filesystems
3901 # and net-device-up IFACE=lo)
3902 # upstart_conf_2_be_startup is for those conf will be "start on startup"
3903 # So the sequence:
3904 # 1st group: startup -> udev.conf and portmap.conf
3905 # 2nd group: drbl-client-boot (which contains virtual fs, dubs, hal, nfs...)
3906 # 3rd group: after drbl-client-boot -> rc-sysinit.conf
3907 # For Ubuntu 11.10, (1) Make mounted-var.conf start on startup since /var/run need to be linked to /run so it's writable for other daemons. (2) Commented dbus.conf since it will be started in drbl-client-boot.conf. Otherwise drbl-client-boot.conf will exit with error code.
3908 upstart_conf_2_be_startup="udev.conf rpcbind-boot.conf mounted-var.conf"
3909 upstart_conf_2_be_after_drbl_client_boot="rc-sysinit.conf"
3910 upstart_conf_2_be_manual="dbus.conf mountall.conf mountall-net.conf resolvconf.conf network-manager.conf isc-dhcp-server6.conf isc-dhcp-server.conf tftpd-hpa.conf"
3911 for i in $upstart_conf_2_be_startup; do
3912 if [ -e "$drbl_common_root/etc/init/$i" ]; then
3913 perl -pi -e "s/^start on.*/start on startup # Modified by DRBL/g" $drbl_common_root/etc/init/$i
3914 fi
3915 done
3916 for i in $upstart_conf_2_be_after_drbl_client_boot; do
3917 if [ -e "$drbl_common_root/etc/init/$i" ]; then
3918 perl -pi -e "s/^start on.*/start on startup and started drbl-client-boot # Modified by DRBL/g" $drbl_common_root/etc/init/$i
3919 fi
3920 done
3921 # Remove the extra one line "and net-device-up IFACE=lo)"
3922 if [ -e "$drbl_common_root/etc/init/portmap.conf" ]; then
3923 perl -pi -e "s/^[[:space:]]*and net-device-up IFACE=lo.*//g" $drbl_common_root/etc/init/portmap.conf
3924 fi
3925 for i in $upstart_conf_2_be_manual; do
3926 # Force to disable client's some services
3927 if [ -e "$drbl_common_root/etc/init/$i" ]; then
3928 switch_upstart_service "$drbl_common_root/etc/init/$i" off
3929 fi
3930 done
3931 # Disable the recovery-menu, use sulogin, otherwise the error messages of Clonezilla will be overwritten.
3932 if [ -e "$drbl_common_root/etc/init/rcS.conf" ]; then
3933 perl -pi -e "s|(^[[:space:]]*exec) /usr/share/recovery-mode/recovery-menu.*|\$1 /sbin/sulogin # Modified by DRBL. Force to use sulogin!|g" $drbl_common_root/etc/init/rcS.conf
3934 # We have to force to enter different runlevel, not in runlevel 1 , otherwise the Clonezilla job (/etc/rc1.d/S19ocs-run) will be run again.
3935 perl -pi -e "s|(^[[:space:]]*) start --no-wait rc-sysinit.*|\$1 telinit 2 # Modified by DRBL. Force to enter runlevel 2 to avoid clonezilla job is run again!|g" $drbl_common_root/etc/init/rcS.conf
3936 fi
3937 fi
3938
3939 elif [ -e /etc/SuSE-release ]; then
3940 # SuSE
3941 # 1. In SuSE, /etc/init.d/reboot is link to halt, so we just have to modify
3942 # halt.
3943 perl -pi -e 's|^(> /success.*)|#$1 # Modified by DRBL|' $drbl_common_root/etc/init.d/halt
3944 perl -pi -e 's|^(umount -anvt proc.*)|#$1 # Modified by DRBL|' $drbl_common_root/etc/init.d/halt
3945 perl -pi -e 's|^(test -z.*fuser -sk -HUP $hupon)|#$1 # Modified by DRBL|' $drbl_common_root/etc/init.d/halt
3946 # 2. Do not clean or remove etc/mtab when boots
3947 perl -pi -e 's|^([[:space:]]*)(rm -f /etc/mtab.*)|$1# $2 # Modified by DRBL|' $drbl_common_root/etc/init.d/boot.rootfsck
3948 # 3. For OpenSuSE 10.0, clean /fastboot in boot.localfs is:
3949 # rm -f /etc/mtab* /etc/nologin /nologin /fastboot /forcefsck /success
3950 # Not only etc/mtab, do not remove /fastboot, either, keep it, since DRBL client is always fastboot
3951 perl -pi -e 's|^([[:space:]]*rm -f )/etc/mtab\* (.*)/fastboot(.*)|$1 $2 $3 # Modified by DRBL|' $drbl_common_root/etc/init.d/boot.localfs
3952 # It's not easy to write in one command, so for OpenSuSE 10.1, we add another line to clean /fastboot in /etc/init.d/boot.localfs:
3953 # rm -f /etc/nologin /nologin /fastboot /forcefsck /success
3954 # Do not remove /fastboot, keep it, since DRBL client is always fastboot
3955 perl -pi -e 's|^([[:space:]]*rm -f .*)/fastboot(.*)|$1 $2 # Modified by DRBL|' $drbl_common_root/etc/init.d/boot.localfs
3956 # Do not umount -t tmpfs.
3957 perl -pi -e 's|umount -t tmpfs.*;;|continue ;; # Modified by DRBL|' $drbl_common_root/etc/init.d/boot.localfs
3958 # For OpenSuSE 11.3, the unmounting tmpfs part has changed. Modify here:
3959 perl -pi -e 's|^(typeset -r nomnt=autofs,.*)|$1,tmpfs # Modified by DRBL|' $drbl_common_root/etc/init.d/boot.localfs
3960
3961 # 4. boot.rootfsck, we comment the mount -f / to avoid / be mounted twice.
3962 perl -pi -e 's|^([[:space:]]*)(mount -f /)|$1# $2 # Modified by DRBL|g' $drbl_common_root/etc/init.d/boot.rootfsck
3963
3964 # 5. Force /etc/init.d/rc1.d/S*single to be at S90, not too early. In OpenSuSE 11.1, it's S10single, while ocs-run is S19.
3965 (
3966 if ls $drbl_common_root/etc/init.d/rc1.d/S*single >/dev/null 2>&1; then
3967 cd $drbl_common_root/etc/init.d/rc1.d/
3968 mv S*single S90single
3969 fi
3970 )
3971 else
3972 # RH-like
3973 if [ -f "$drbl_setup_path/files/${OS_type}/${OS_Version}/halt.$OS_Version.drbl" ]; then
3974 cp -f $drbl_setup_path/files/${OS_type}/${OS_Version}/halt.$OS_Version.drbl $drbl_common_root/etc/init.d/halt
3975 else
3976 # not Debian, it's RH-like (BSD style), so show warning. This is only necessary for CentOS <= 6, since for Fedora, when >= version 17, no required. //NOTE// From drbl 2.x, only CentOS and Fedora are supported.
3977 OS_Version_Major="${OS_Version:0:3}" # E.g. CO5.8 -> CO5
3978 case "$OS_Version" in
3979 CO*)
3980 if ! is_systemd_init; then
3981 most_related_ver="$(LC_ALL=C find $drbl_setup_path/files/$OS_type/${OS_Version_Major}* -type d -exec basename {} \; 2>/dev/null | sort | uniq | tail -n 1)"
3982 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
3983 echo "Warning! The fine-tune file ${drbl_setup_path}/files/${OS_type}/${OS_Version}/halt.${OS_Version}.drbl was not found. Using $drbl_setup_path/files/${OS_type}/${most_related_ver}/halt.${most_related_ver}.drbl as /etc/init.d/halt for DRBL clients!"
3984 echo "This may cause some problems to DRBL clients!"
3985 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
3986 [ -n "$most_related_ver" ] && cp -f $drbl_setup_path/files/${OS_type}/${most_related_ver}/halt.${most_related_ver}.drbl $drbl_common_root/etc/init.d/halt
3987 fi
3988 ;;
3989 esac
3990 fi
3991 # From Fedora 9, upstart is used, and the post script of rc1 will force to terminate all programs after S19ocs-run is run in the end of rc1. i.e. when client finishes cloning in Clonezilla SE, a reboot or shutdown command (e.g. ocs-sr -p reboot...) will be killed by the post-stop script of rc1. Therefore we comment it.
3992 # The post script in /etc/event.d/rc1 is:
3993 #post-stop script
3994 # clear
3995 # TEXTDOMAIN=initscripts
3996 # . /etc/profile.d/lang.sh
3997 # echo $"Telling INIT to go to single user mode."
3998 # exec telinit S
3999 #end script
4000 if [ -e "$drbl_common_root/etc/event.d/rc1" ]; then
4001 perl -pi -e 's|(^[[:space:]]*)(clear)|$1# $2 # Modified by DRBL|' $drbl_common_root/etc/event.d/rc1
4002 perl -pi -e 's|(^[[:space:]]*)(.*Telling INIT to go to single user mode.*)|$1# $2 # Modified by DRBL|' $drbl_common_root/etc/event.d/rc1
4003 perl -pi -e 's|(^[[:space:]]*)(exec telinit S)|$1# $2 # Modified by DRBL|' $drbl_common_root/etc/event.d/rc1
4004 # Instead, we put a modified single to be run after S19ocs-run
4005 cp -af $drbl_setup_path/files/RH/single.drbl $drbl_common_root/etc/rc1.d/S99single
4006 fi
4007 fi
4008
4009 # delete the users in template, i.e. we will use the YP, not local account
4010 # in clients
4011 echo -n "Deleting the accounts (except root) in the clients common root template... "
4012 usrdel_file_need="/usr/sbin/userdel"
4013 cp --parents -d $usrdel_file_need $drbl_common_root
4014 if ldd $usrdel_file_need &>/dev/null; then
4015 usrdel_lib_need=$(LC_ALL=C ldd /usr/sbin/userdel | sed -e "s/.*=> //g" -e "s/(0x.*)//g" | awk '{print $1}')
4016 for imod in $usrdel_lib_need; do
4017 # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/
4018 [ "$imod" = "linux-vdso.so.1" ] && continue
4019 [ "$imod" = "linux-gate.so.1" ] && continue
4020 cp --parents -d $imod $drbl_common_root
4021 done
4022 fi
4023 # UGLY... For SuSE, we need to copy /usr/lib/pwdutils/ to $drbl_common_root,
4024 # but why ? Here it's just a lots of try-and-errors...
4025 [ -d /usr/lib/pwdutils/ ] && cp --parents -d -r /usr/lib/pwdutils $drbl_common_root
4026 [ -x /usr/sbin/userdel-pre.local ] && cp --parents -d /usr/sbin/userdel-pre.local $drbl_common_root
4027 [ -x /usr/sbin/userdel-post.local ] && cp --parents -d /usr/sbin/userdel-post.local $drbl_common_root
4028 # /usr/bin/crontab exists in /usr/sbin/userdel-pre.local in SuSE
4029 [ -x /usr/bin/crontab ] && cp --parents -d /usr/bin/crontab $drbl_common_root
4030
4031 user_to_del="$(drbl-get-common-username 2>/dev/null)"
4032 for u in $user_to_del; do
4033 if grep -q "^$u:" $drbl_common_root/etc/passwd; then
4034 chroot $drbl_common_root /usr/sbin/userdel $u 2>/dev/null
4035 fi
4036 done
4037 # We need nobody user. However, since some services are started before yp/nis, we will let nobody as local account. Comment this one.
4038 #echo "Exporting nfsnobody in NIS/YP...".
4039 #perl -pi -e "s/^.*NFSNOBODYUID=.*/NFSNOBODYUID=0/g" /var/yp/Makefile
4040 #perl -pi -e "s/^.*NFSNOBODYGID=.*/NFSNOBODYGID=0/g" /var/yp/Makefile
4041 # Oct/25/2011, for better security, do not show the hashed yp passwd. Thanks to Robert Arkiletian <robark _at_ gmail com> for reporting this issue.
4042 perl -pi -e "s/^MERGE_PASSWD=.*/MERGE_PASSWD=false/g" /var/yp/Makefile
4043 perl -pi -e "s/^MERGE_GROUP=.*/MERGE_GROUP=false/g" /var/yp/Makefile
4044 # Enable "shadow" in "all line" in /var/yp/Makefile.
4045 # For Fedora/CentOS, the "all line" is like:
4046 # all: passwd group hosts rpc services netid protocols mail \
4047 # # netgrp shadow publickey networks ethers bootparams printcap \
4048 # # amd.home auto.master auto.home auto.local passwd.adjunct \
4049 # # timezone locale netmasks
4050 # For Debian/Ubuntu, it is like:
4051 # ALL = passwd group hosts rpc services netid protocols netgrp
4052 # #ALL += publickey mail ethers bootparams printcap
4053 # ##ALL += amd.home auto.master auto.home auto.local
4054 # ##ALL += timezone locale networks netmasks
4055 # #
4056 # ## Autodetect /etc/shadow if it's there
4057 # #ifneq ($(wildcard $(SHADOW)),)
4058 # #ALL += shadow
4059 # #endif
4060 # #
4061 # ## Autodetect /etc/passwd.adjunct if it's there
4062 # #ifneq ($(wildcard $(ADJUNCT)),)
4063 # #ALL += passwd.adjunct
4064 # #endif
4065 # #
4066 # #all: $(ALL)
4067 if [ -z "$(LC_ALL=C grep -Ew "^all:.*shadow.*" /var/yp/Makefile)" ]; then
4068 perl -pi -e 's|(^all:)(.*)|$1 shadow $2|g' /var/yp/Makefile
4069 fi
4070 echo "done!"
4071
4072 # Enable the NIS client for this template
4073 # For Mandrake/Debian, there is no authconfig,
4074 # Mandrake use drakauth, but not interactive ?
4075 echo -n "Enabling the NIS client in the common root template... "
4076 # For RH-like, used to use /usr/sbin/authconfig, but in FC5, it's python... not easy to create the "create_authconfig_env $drbl_common_root/"
4077 # turn on the nis in common root's /etc/nsswitch.conf, this is necessary for MDK/DBN since MDK/DBN does NOT have /usr/sbin/authconfig
4078 perl -pi -e "s/^passwd:.*/passwd: files nis/" $drbl_common_root/etc/nsswitch.conf
4079 perl -pi -e "s/^shadow:.*/shadow: files nis/" $drbl_common_root/etc/nsswitch.conf
4080 perl -pi -e "s/^group:.*/group: files nis/" $drbl_common_root/etc/nsswitch.conf
4081 perl -pi -e "s/^hosts:.*/hosts: files nis dns/" $drbl_common_root/etc/nsswitch.conf
4082
4083 # Patch for mandriva, e.g. 2009 or 2010, the /etc/init.d/sound is using /root/tmp/ as the temp dir. This will make /etc/init.d/sound not work in client because it's early before NFS /root is mounted. We have filed a bug report in https://qa.mandriva.com/show_bug.cgi?id=55929 to suggest to use /tmp/ instead of /root/tmp/.
4084 if [ -e "$drbl_common_root/etc/init.d/sound" ]; then
4085 perl -pi -e 's|^([[:space:]]*)MIXER_SETTINGS=/root/tmp/asound.state_tmp|$1MIXER_SETTINGS=/tmp/asound.state_tmp|g' $drbl_common_root/etc/init.d/sound
4086 fi
4087
4088 # For Debian
4089 if [ -e /etc/debian_version ]; then
4090 if [ -f $drbl_common_root/etc/default/nis ]; then
4091 perl -p -i -e "s/^NISSERVER=.*/NISSERVER=false/" $drbl_common_root/etc/default/nis
4092 perl -p -i -e "s/^NISCLIENT=.*/NISCLIENT=true/" $drbl_common_root/etc/default/nis
4093 fi
4094 fi
4095 # Turn off wicd autostart, otherwise user need to enter password when entering XFCE in drbl client. It's not required because the network configuration on drbl client is done during booting. This is especially for DRBL live.
4096 if [ -e $drbl_common_root/etc/xdg/autostart/wicd-tray.desktop ]; then
4097 cat <<-WICD_END > $drbl_common_root/etc/xdg/autostart/wicd-tray.desktop
4098 [Desktop Entry]
4099 # Disabled by DRBL.
4100 Hidden=true
4101 WICD_END
4102 fi
4103 echo "done!"
4104
4105 echo -n "Creating some necessary files in the clients common root template..."
4106 # set the arguments "-q" in kudzu to let system do configuration that
4107 # doesn't require user input
4108 if [ -d "$drbl_common_root/etc/sysconfig" -a "$drbl_common_root/etc/sysconfig/kudzu" ]; then
4109 if ! grep -qE "^KUDZU_ARGS=-q" $drbl_common_root/etc/sysconfig/kudzu 2>/dev/null; then
4110 echo "KUDZU_ARGS=-q" >> $drbl_common_root/etc/sysconfig/kudzu
4111 fi
4112 fi
4113
4114 #echo -n "."
4115 # write the ntp server setting
4116 #if ! grep -q "^server pool.ntp.org" /etc/ntp.conf 2>/dev/null; then
4117 # echo "server pool.ntp.org" >> /etc/ntp.conf
4118 #fi
4119
4120 # set the restrict for ntp clients
4121 #if ! grep -q "^restrict default ignore" /etc/ntp.conf 2>/dev/null; then
4122 # echo "restrict default ignore" >> /etc/ntp.conf
4123 #fi
4124
4125 #if ! grep -q "^restrict 127.0.0.1" /etc/ntp.conf 2>/dev/null; then
4126 # echo "restrict 127.0.0.1" >> /etc/ntp.conf
4127 #fi
4128
4129 echo -n "."
4130 # Create the /var in template, only directory
4131 # Other directories in /var/lib/ are important for some applications.
4132 # /var/lib/rpm/* is necessary for rpm database,
4133 # /var/spool/mail is necessary for each user.
4134 # It's better to export /var/lib all.
4135
4136 # Use rsync will be easier....Thanks to Wayne Davison [email protected]
4137 rsync -a $RSYNC_OPT_EXTRA --include="*/" --exclude="*" /var $drbl_common_root/
4138
4139 # symbolic_files_in_var_chklist is loaded in drbl.conf.
4140 # On Ubuntu 11.10, FC17, /var/run is linked to /run, and /var/lock is linked to /run/lock.
4141 # On Fedora 17, /var/run and /var/lock have to create as a link to "/run" and "/run/lock" before client booting. Have to use absolute not relative path
4142
4143 for i in $symbolic_files_in_var_chklist; do
4144 if [ -L /var/$i ]; then
4145 _tmp_absolute="$(readlink -f /var/$i)"
4146 rm -f $drbl_common_root/var/$i
4147 ln -s $_tmp_absolute $drbl_common_root/var/$i
4148 fi
4149 done
4150
4151 echo -n "."
4152
4153 # For SuSE, we need to copy /var/X11R6 to clients also. How about /var/adm ?
4154 [ -n "$(unalias ls 2>/dev/null; ls /var/X11R6/* 2>/dev/null)" ] && rsync -a $RSYNC_OPT_EXTRA /var/X11R6/* $drbl_common_root/var/X11R6/
4155 # UGLY!
4156 # /var/yp/nicknames is importand in clients, otherwise "ypcat passwd" won't work.
4157 [ -e /var/yp/nicknames ] && cp -a /var/yp/nicknames $drbl_common_root/var/yp/
4158
4159 # Copy all /var/lib/* to the common root
4160 # For /var/lib/, we can not use $RSYNC_OPT_EXTRA, since if we just run drblsrv
4161 # some files, like in /var/lib/rpm/, it's newer than those in the system.
4162 # We force to sync that in the server to client.
4163 # varlib_NOT_2_be_copied_2_common_root is loaded from drbl.conf
4164 # prepare the options for rsync to exclude when copy files in
4165 # /var/lib/* to /tftpboot/node_root/var/lib/
4166 varlib_opts_common_to_common=""
4167 for iv in $varlib_NOT_2_be_copied_2_common_root; do
4168 varlib_opts_common_to_common="$varlib_opts_common_to_common --exclude=$iv/ "
4169 done
4170 [ -d /var/lib ] && rsync -a $varlib_opts_common_to_common /var/lib/* $drbl_common_root/var/lib/
4171
4172 # Copy selected /var/cache/* to the common root
4173 for icache in $varcache_2_be_copied_2_common_root; do
4174 [ -d "/var/cache/$icache" ] && rsync -a $RSYNC_OPT_EXTRA /var/cache/$icache $drbl_common_root/var/cache/
4175 done
4176
4177 # In OpenSUSE 10.1, if "/var/log/lastlog" does NOT exist in client, pam_lastlog will refuse to run, and user or root won't be able to login in client's console.
4178 # The error in client will be like:
4179 # May 20 06:40:48 opensuse101102 login[2996]: pam_lastlog(login:session): unable to open /var/log/lastlog: No such file or directory
4180 touch $drbl_common_root/var/log/lastlog
4181 # For OpenSuSE 10.1, if /var/lib/nfs/state does not exist, it will show err.
4182 touch $drbl_common_root/var/lib/nfs/state
4183 # For Debian 4.0, if /var/log/dmesg does not exist, it will complain when first boot.
4184 touch $drbl_common_root/var/log/dmesg
4185
4186 };
4187
4188 # print all the nfsserver to $drbl_common_root/etc/diskless-image/config
4189 print NFSSERVER_OUT "NFSSERVER_LIST=\"";
4190 foreach my $k1 ( sort(keys %$rHoH) ) {
4191 if( $k1=~/general/ ) { next; } # skip general block
4192 my $nfsserver=$rHoH->{$k1}{"NFSSERVER"};
4193 #---------------
4194 my $interface=$rHoH->{$k1}{"INTERFACE"};
4195 # Try to get setting from system also
4196 # use the NIC "eth1, eth2..." of DRBL server as default nfsserver_sys...
4197 my $nfsserver_sys;
4198 chomp($nfsserver_sys=`drbl-get-ipadd $interface`);
4199 # set nfsserver, the priority: use the config file first, if unset, then use the value in system
4200 if ( ! $nfsserver ) {
4201 $nfsserver = $nfsserver_sys;
4202 print "* nfsserver is not set in config file, \nthe one \"$nfsserver\" got from system will be used.\n" if $verbosity >= 2;
4203 }
4204
4205 # check if the values are set in config file or system
4206 unless ( $nfsserver ) {
4207 print "Error! NFSSERVER is unset!\n";
4208 print "Please set nfsserver in config file \"$_[0]\" or IPADDR in system config file.\n";
4209 exit;
4210 }
4211 #---------------
4212 #print "nfsserver: $nfsserver\n";
4213 print NFSSERVER_OUT "$nfsserver ";
4214
4215 # next one
4216 $i++;
4217 };
4218 print NFSSERVER_OUT "\"\n";
4219
4220 print DISKLESS_OUT q{
4221 echo -n ". "
4222 # append all the nfsserver to $drbl_common_root/etc/diskless-image/config
4223 cat nfsserver_all >> $drbl_common_root/etc/diskless-image/config
4224
4225 echo "done!"
4226 };
4227
4228 # Part 3,
4229 # create every client node, like Debian's diskless-newhost
4230 #
4231 print DISKLESS_OUT q{
4232 # create every client node, like Debian's diskless-newhost
4233 };
4234
4235 foreach my $k1 ( sort(keys %$rHoH) ) {
4236 if( $k1=~/general/ ) { next; } # skip general block
4237 my @kea_reservations = ();
4238 my $kea_pool_start = "";
4239 my $kea_pool_end = "";
4240
4241 my $interface=$rHoH->{$k1}{"INTERFACE"};
4242 my $network=$rHoH->{$k1}{"NETWORK"};
4243 my $nfsserver=$rHoH->{$k1}{"NFSSERVER"};
4244 my $bootserver=$rHoH->{$k1}{"BOOTSERVER"};
4245 my $nisserver=$rHoH->{$k1}{"NISSERVER"};
4246 my $gateway=$rHoH->{$k1}{"GATEWAY"};
4247 my $nbi=$rHoH->{$k1}{"NBI"};
4248 my $mac=$rHoH->{$k1}{"MAC"};
4249 my $ip_start=$rHoH->{$k1}{"IP_START"};
4250 my $range=$rHoH->{$k1}{"RANGE"};
4251
4252 if( length($bootserver)==0 ) { $bootserver=$nfsserver; }
4253 if( length($nisserver)==0 ) { $nisserver=$nfsserver; }
4254 if( length($gateway)==0 ) { $gateway=$nfsserver; }
4255 if( length($nbi)==0 ) { $nbi=$rHoH->{"general"}{"NBI"}; }
4256 # Try to get setting from system also
4257 # use the NIC "eth1, eth2..." of DRBL server as default nfsserver_sys...
4258 chomp($hostname_sys=`hostname`);
4259 chomp($netmask_sys=`drbl-get-netmask $interface`);
4260 chomp($ipaddr_sys=`drbl-get-ipadd $interface`);
4261 # the IP address for server is the NFS server for client
4262 my $nfsserver_sys=$ipaddr_sys;
4263 my $bootserver_sys=$nfsserver_sys;
4264 my $nisserver_sys=$nfsserver_sys;
4265 # set nfsserver, bootserver, nisserver address, the priority: use the config file first, if unset, then use the value in system
4266
4267 # If hostname_prefix unset, try to set it as that of server
4268 if ( ! $hostname_prefix ) {
4269 @hostname_sp_sys=split(/\./,$hostname_sys);
4270 $hostname_prefix="$hostname_sp_sys[0]";
4271 }
4272
4273 unless ( $netmask_sys ) {
4274 print "Error! NETMASK is unset!\n";
4275 print "Please set NETMASK in system config file.\n";
4276 exit;
4277 }
4278
4279 if ( ! $network ) {
4280 # Since there are two versions of ipcalc, we use the perl one, which is
4281 # from http://jodies.de/ipcalc
4282 $network = `drbl-ipcalc $ipaddr_sys $netmask_sys | awk -F' ' '/Network:/ {print \$2}' | sed -e "s|/.*||g"`;
4283 chomp($network);
4284 print colored ("The calculated NETWORK for $interface is $network.\n", "$color_warn");
4285 }
4286
4287 if ( ! $hostname ) {
4288 $hostname = $hostname_sys;
4289 print "* hostname is not set in config file, \nthe one \"$hostname\" got from system will be used.\n" if $verbosity >= 2;
4290 }
4291
4292 if ( ! $nfsserver ) {
4293 $nfsserver = $nfsserver_sys;
4294 print "* nfsserver is not set in config file, \nthe one \"$nfsserver\" got from system will be used.\n" if $verbosity >= 2;
4295 }
4296 if ( ! $bootserver ) {
4297 $bootserver = $bootserver_sys;
4298 print "* bootserver is not set in config file, \nthe one \"$bootserver\" got from system will be used.\n" if $verbosity >= 2;
4299 }
4300 if ( ! $nisserver ) {
4301 $nisserver = $nisserver_sys;
4302 print "* nisserver is not set in config file, \nthe one \"$nisserver\" got from system will be used.\n" if $verbosity >= 2;
4303 }
4304 if ( ! $gateway ) {
4305 $gateway = $bootserver;
4306 print "* gateway is not set in config file, \nUse bootserver as gateway.\n" if $verbosity >= 2;
4307 }
4308
4309 # Last check if the values are set in config file or system
4310 unless ( $hostname ) {
4311 print "Error! HOSTNAME is unset!\n";
4312 print "Please set hostname in config file \"$_[0]\" or HOSTNAME in system config file.\n";
4313 exit;
4314 }
4315 unless ( $nfsserver ) {
4316 print "Error! NFSSERVER is unset!\n";
4317 print "Please set nfsserver in config file \"$_[0]\"\n";
4318 exit;
4319 }
4320 unless ( $bootserver ) {
4321 print "Error! BOOTSERVER is unset!\n";
4322 print "Please set bootserver in config file \"$_[0]\"\n";
4323 exit;
4324 }
4325 unless ( $nisserver ) {
4326 print "Error! NISSERVER is unset!\n";
4327 print "Please set nisserver in config file \"$_[0]\"\n";
4328 exit;
4329 }
4330 unless ( $gateway ) {
4331 print "Error! GATEWAY is unset!\n";
4332 print "Please set gateway in config file \"$_[0]\"\n";
4333 exit;
4334 }
4335
4336 if (! defined $primary_bootserver) {
4337 $primary_bootserver = $bootserver;
4338 }
4339
4340 # go
4341 @nfsserverIp=split(/\./,$nfsserver);
4342 @networkIp=split(/\./,$network);
4343
4344 # For alias IP address, we need something like:
4345 # Ref: https://lists.isc.org/pipermail/dhcp-users/2010-September/012053.html
4346 #shared-network "some-identifier" {
4347 # subnet 192.168.100.0 netmask 255.255.255.0 {
4348 # option subnet-mask 255.255.255.0;
4349 # option routers 192.168.100.254;
4350 # next-server 192.168.100.254;
4351 #
4352 # pool {
4353 # range 192.168.100.1 192.168.100.3;
4354 # }
4355 # }
4356 # subnet 192.168.120.0 netmask 255.255.255.0 {
4357 # }
4358 #}
4359 if ( $interface =~ /eth[0-9]+:[0-9]+/ ) {
4360 print DHCPD_OUT <<EOF;
4361 shared-network "alias-interface-identifier" {
4362 EOF
4363 }
4364
4365 print DHCPD_OUT <<EOF;
4366 subnet $network netmask $netmask_sys {
4367 option subnet-mask $netmask_sys;
4368 option routers $gateway;
4369 option rpi-tftp-server "$bootserver";
4370 next-server $bootserver;
4371
4372 EOF
4373
4374 # range option, we have to create the IP table file
4375 chomp ( $iplist_tmp = `LC_ALL=C mktemp /tmp/drbl_iprange.XXXXXX` );
4376 print "interface: $interface\n" if $verbosity >= 2;
4377 if( length($mac)==0 && length($range)!=0 ) {
4378 # range case. The config shown in drblpush.conf:
4379 # range=1-15
4380 # so $rs=1, $re=15
4381 ($rs,$re)=split(/-/,$range,2);
4382 $total_count=$re-$rs+1;
4383 # get the initial value in the last set of digits in the IP address
4384 # from range starting no.
4385 $ip_start=$rs;
4386 } else {
4387 # MAC case. The config shown in drblpush.conf:
4388 # [eth1]
4389 # interface=eth1
4390 # mac=macadr-eth1.txt
4391 # ip_start=1
4392 chomp($total_count=`LC_ALL=C cat $mac | wc -l`);
4393 }
4394 chomp ($ip_hostmin=`LC_ALL=C drbl-ipcalc $ipaddr_sys $netmask_sys | awk -F' ' '/^HostMin:/ {print \$2}'`);
4395 # Here we add one more client, in case the IP address is used by server
4396 my $total_count_request=$total_count+1;
4397 # Todo: What if user assigns a wrong initial number (ip_start)?
4398 my @ip_tmp_sp=split(/\./,$ip_hostmin);
4399 my $ip_tmp_prefix="$ip_tmp_sp[0].$ip_tmp_sp[1].$ip_tmp_sp[2]";
4400 my $ip_tmp_start=$ip_tmp_prefix.".".$ip_start;
4401
4402 # We should not let drbl-ipcalc-list to list 3 more IP addresses in case some of them are used, like in the server's ethernet port. Otherwise for class C, if user assigns total clients as 253, drbl-ipcalc-list won't be able to list 256 clients for class C (e.g. 192.168.1.0/24).
4403 system("drbl-ipcalc-list -c $total_count_request $ip_tmp_start $netmask_sys > $iplist_tmp");
4404 # Check if any IP address in the output file.
4405 my $ip_tmp_no="";
4406 chomp($ip_tmp_no=`LC_ALL=C wc -l $iplist_tmp | awk -F" " '{print \$1}'`);
4407 if ($ip_tmp_no eq "0" ) {
4408 print "Wrong configuration for this network card: $interface\n";
4409 print "$lang_deploy{\"program_stop\"}\n";
4410 exit (1);
4411 }
4412
4413 # Remove the nfsserver IP address.
4414 system("perl -pi -e \"s/\\b$nfsserver\\b\\n//g\" $iplist_tmp");
4415 # Keep exact lines because drbl-ipcalc-list will output extra 3 lines
4416 system("LC_ALL=C head -n \"$total_count\" $iplist_tmp > $iplist_tmp.swap");
4417 system("cp -a $iplist_tmp.swap $iplist_tmp");
4418 unlink ("$iplist_tmp.swap") if -f "$iplist_tmp.swap";
4419
4420 # Write the output shell script drbl_deploy.sh
4421 # Start with index = 1
4422 $i=1;
4423 while($i <= $total_count) {
4424 chomp ($ip=`perl -ne "$i..$i and print" $iplist_tmp`);
4425 print "IP address:$ip\n" if $verbosity >=2;
4426
4427 # hostname for client
4428 # The default name will like fc192-168-0-1, fc10-0-0-1...,
4429 # i.e. $prefix{IP Address//./-}
4430 # If the hostname is assigned in /etc/drbl/client-ip-hostname,
4431 # we will ust that.
4432 my $ip_shown = $ip;
4433 $ip_shown =~ s/\./-/g;
4434 $label_default=$hostname_prefix.$ip_shown;
4435 chomp($label_assigned=`LC_ALL=C get-assigned-hn-by-ip $ip`);
4436 if ($label_assigned) {
4437 $label=$label_assigned;
4438 }else{
4439 $label=$label_default;
4440 }
4441 print "label:$label\n" if $verbosity >=2;
4442
4443 if( length($mac)!=0 ) {
4444 # MAC addresses list
4445 # generate dhcpd.conf
4446 # without nbi set in config file
4447 chomp (my $macadd=`perl -ne "$i..$i and print" $mac`);
4448 print DHCPD_OUT <<EOF;
4449 host $label {
4450 hardware ethernet $macadd;
4451 fixed-address $ip;
4452 # option host-name "$label";
4453 }
4454 EOF
4455 push @kea_reservations, " {\n" .
4456 " \"hw-address\": \"$macadd\",\n" .
4457 " \"ip-address\": \"$ip\",\n" .
4458 " \"hostname\": \"$label\"\n" .
4459 " }";
4460 } elsif( length($range)!=0 ) {
4461 # range list
4462 # do nothing
4463 print "In range loop with line $i\n" if $verbosity >=2;
4464 }
4465
4466 # generate netgroup
4467 print NETGROUP_OUT "($label,,) ";
4468
4469 # generate $CLIENT_IP_HOSTNAME_LIST
4470 print CLIENT_HOST_IP_LIST_OUT "$ip $label\n";
4471
4472 # append the hosts to hosts_list
4473 print HOSTS_LIST_OUT <<EOF;
4474 $ip
4475 EOF
4476
4477 #
4478 print DISKLESS_OUT q{
4479 # When none full drbl mode AND none full clonezilla mode, we turn on pseudo option
4480 [ "$clonezilla_mode" != "full_clonezilla_mode" -a "$drbl_mode" != "full_drbl_mode" ] && [ "$pseudo_flag" = "on" ] && pseudo_opt="-p"
4481 };
4482 print DISKLESS_OUT <<EOF;
4483 # $keep_old_files_flag is assigned in shell, not from perl.
4484 drbl-gen-client-files -l $language -h $ip -k \$keep_old_files_flag -n $nfsserver -a $label -i $nisserver \$pseudo_opt
4485 [ -z "\$template_client" ] && template_client="$ip"
4486 EOF
4487 print DISKLESS_OUT q{
4488 pseudo_flag=on
4489 };
4490 # next one
4491 $i++;
4492 print "Process line $i\n" if $verbosity >=2;
4493 }
4494
4495 # generate dhcpd.conf
4496 if( length($mac)!=0 ) { # mac - just close it
4497 print DHCPD_OUT "}\n";
4498 }
4499 elsif( length($range)!=0 ) { # range - generate range & filename
4500 # without nbi set in config file
4501 # HERE
4502 chomp(my $ipstart=`LC_ALL=C head -n 1 $iplist_tmp`);
4503 chomp(my $ipend=`LC_ALL=C tail -n 1 $iplist_tmp`);
4504 $kea_pool_start = $ipstart;
4505 $kea_pool_end = $ipend;
4506 print DHCPD_OUT <<EOF;
4507 pool {
4508 # allow members of "DRBL-Client";
4509 range $ipstart $ipend;
4510 }
4511 }
4512
4513 EOF
4514 }
4515 # Keep file as ref file for later use.
4516 system("cp -a $iplist_tmp clients-of-$nfsserver.txt");
4517 # Clean the temp IP addresses list file
4518 unlink ($iplist_tmp) if -f $iplist_tmp;
4519
4520 if ( $interface =~ /eth[0-9]+:[0-9]+/ ) {
4521 my $main_nic = $interface;
4522 my $main_nic_ip;
4523 my $main_nic_netmask;
4524 my $main_nic_subnet;
4525 # find the main NIC, i.e. eth0:1 -> eth0
4526 $main_nic =~ s/:[0-9]+//g;
4527 chomp($main_nic_ip=`drbl-get-ipadd $main_nic`);
4528 chomp($main_nic_netmask=`drbl-get-netmask $main_nic`);
4529 chomp($main_nic_subnet=`LC_ALL=C drbl-ipcalc $main_nic_ip/$main_nic_netmask | grep -Ei "^Network:" | awk -F " " '{print \$2}' | sed -re "s|\/.*||g"`);
4530 print DHCPD_OUT <<EOF;
4531 subnet $main_nic_subnet netmask $main_nic_netmask { }
4532 }
4533 EOF
4534 }
4535
4536 my $cidr = netmask_to_cidr($netmask_sys);
4537 my $subnet_json = " {\n" .
4538 " \"id\": " . scalar(@kea_subnets + 1) . ",\n" .
4539 " \"subnet\": \"$network/$cidr\",\n";
4540
4541 if ($kea_pool_start ne "" && $kea_pool_end ne "") {
4542 $subnet_json .= " \"pools\": [\n" .
4543 " { \"pool\": \"$kea_pool_start - $kea_pool_end\" }\n" .
4544 " ],\n";
4545 }
4546
4547 $subnet_json .= " \"option-data\": [\n" .
4548 " {\n" .
4549 " \"name\": \"routers\",\n" .
4550 " \"data\": \"$gateway\"\n" .
4551 " }\n" .
4552 " ],\n" .
4553 " \"next-server\": \"$bootserver\"";
4554
4555 if (@kea_reservations) {
4556 $subnet_json .= ",\n \"reservations\": [\n" .
4557 join(",\n", @kea_reservations) . "\n" .
4558 " ]";
4559 }
4560
4561 $subnet_json .= "\n }";
4562 push @kea_subnets, $subnet_json;
4563 }
4564
4565 #
4566 print DISKLESS_OUT q{
4567 # Generate the files for DRBL single system image SSI
4568 # Create the tarball template for DRBL SSI mode or Clonezilla box mode.
4569 if [ "$drbl_mode" = "drbl_ssi_mode" -o \
4570 "$clonezilla_mode" = "clonezilla_box_mode" ]; then
4571 echo "Template client for DRBL SSI, Clonezilla box mode or Clonezilla live client is $template_client"
4572 drbl-gen-ssi-files -n -t $template_client
4573 fi
4574
4575 #
4576 if [ "$run_drbl_ocs_live_prep" = "yes" ]; then
4577 if [ "$clonezilla_mode" = "clonezilla_live_mode" ]; then
4578 drbl_ocs_live_server_opt=""
4579 [ -n "$drbl_ocs_live_server" ] && drbl_ocs_live_server_opt="-s $drbl_ocs_live_server"
4580 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4581 echo 'Preparing the system to use clonezilla live as the OS of clients...'
4582 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4583 drbl-ocs-live-prep -b $live_client_branch -a $live_client_cpu_mode $drbl_ocs_live_server_opt
4584 else
4585 # Clean the previous Clonezilla live configuration.
4586 drbl-ocs-live-prep -u
4587 fi
4588 fi
4589
4590 # output dhcpd arguments or interfaces to sysconfig file
4591 dhcp_eths="$(awk -F"=" '/^interface=.*/ {print $2}' $config_file)"
4592 # if the itnerface is alias, print the original interface
4593 # i.e. if eth0:1, we print eth0
4594 dhcp_eths="$(echo $dhcp_eths | sed -e "s/:[0-9]*//g")"
4595 if [ -e "/etc/debian_version" ]; then
4596 # Debian, use the parameter "INTERFACESv4"
4597 echo "INTERFACESv4=\"$dhcp_eths\"" > $SYSCONF_PATH/$DHCP_SRV_NAME
4598 elif [ -e "/etc/SuSE-release" ]; then
4599 perl -pi -e "s/^[#]*[[:space:]]*[#]*DHCPD_INTERFACE=.*/DHCPD_INTERFACE=\"$dhcp_eths\"/g" $SYSCONF_PATH/$DHCP_SRV_NAME
4600 else
4601 # RH-like, use the parameter "DHCPDARGS"
4602 echo "# //NOTE from DRBL// This file is not used by Fedora/CentOS which uses systemd. This is only for older versions. However, we still need this for the function get_dhcpd_interface in drbl-functions" > $SYSCONF_PATH/$DHCP_SRV_NAME
4603 echo "DHCPDARGS=\"$dhcp_eths\"" >> $SYSCONF_PATH/$DHCP_SRV_NAME
4604 fi
4605
4606 # turn on pxelinux passwd if set
4607 if [ -n "$client_pxelinux_passwd" ]; then
4608 drbl-pxelinux-passwd -e --stdin $client_pxelinux_passwd
4609 else
4610 drbl-pxelinux-passwd --disable
4611 fi
4612
4613 # write the NISDOMAIN to system config file in DRBL server
4614 NET_sys_RH="/etc/sysconfig/network"
4615 NIS_Debian="/etc/defaultdomain"
4616 NIS_SuSE="/etc/defaultdomain"
4617 if [ -e /etc/debian_version ]; then
4618 echo "$nisdomain" > $NIS_Debian
4619 perl -p -i -e "s/^NISSERVER=.*/NISSERVER=master/" /etc/default/nis
4620 perl -p -i -e "s/^NISCLIENT=.*/NISCLIENT=true/" /etc/default/nis
4621 elif [ -e /etc/SuSE-release ]; then
4622 # SuSE
4623 echo "$nisdomain" > $NIS_SuSE
4624 else
4625 # RH-like
4626 NIS_sys=$(grep NISDOMAIN $NET_sys_RH 2>/dev/null)
4627 if [ -z "$NIS_sys" ]; then
4628 echo "NISDOMAIN=$nisdomain" >> $NET_sys_RH
4629 else
4630 perl -p -i -e "s/^NISDOMAIN=.*/NISDOMAIN=$nisdomain/" $NET_sys_RH
4631 fi
4632 fi
4633
4634 # before restart NIS, force the variable NISDOMAIN now is that set in config file
4635 nisdomainname $nisdomain
4636
4637 # Since we set tcp as the default NFS protocol, if tcp over NFS is not supported in the server running kernel, make a switch for client to use udp.
4638 # Ex:for RH9, tcp over NFS is not supported in the runnking kernel 2.4.20-8
4639 if [ "$nfs_protocol" = "udp" ]; then
4640 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4641 echo 'Switch "tcp over NFS" to "udp over NFS" for the DRBL clients...'
4642 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4643 drbl-nfs-conf --no-gen-ssi --protocol udp
4644 fi
4645
4646 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4647 echo "Now add necessary services to this DRBL server: DHCP, TFTP, NFS, NIS..."
4648 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4649
4650 # set the restrict in ntp.conf, only the subnet of DRBL clients can access.
4651 #drbl_subnet=
4652 #for ihost in /tftpboot/nodes/*; do
4653 # ip="`basename $ihost`"
4654 # subnet=$(echo $ip | cut -d"." -f1-3)
4655 # if [ -z "$(echo $drbl_subnet | grep $subnet 2> /dev/null)" ]; then
4656 # drbl_subnet="$drbl_subnet $subnet"
4657 # fi
4658 #done
4659 #for i_subnet in $drbl_subnet; do
4660 # if ! grep -q "^restrict $i_subnet.*" /etc/ntp.conf ; then
4661 # echo "restrict $i_subnet.0 mask 255.255.255.0 notrust nomodify notrap" >> /etc/ntp.conf
4662 # fi
4663 #done
4664
4665 # create NFS exports
4666 drbl-nfs-exports --no-restart generate
4667
4668 # start the iptables NAT
4669 case "$drbl_server_as_NAT_server" in
4670 n|N|[nN][oO])
4671 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4672 echo "$msg_drbl_server_is_NOT_NAT_server"
4673 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4674 drbl-nat-rules clean ;;
4675 *)
4676 drbl-nat-rules generate ;;
4677 esac
4678
4679 # set the YP securenets
4680 drbl-yp-securenets --no-restart generate
4681
4682 # add drbl-clients-nat service for Debian DRBL server. This is only for Debian and Ubuntu.
4683 if [ -e /etc/debian_version ]; then
4684 if is_systemd_init; then
4685 cp -f $drbl_setup_path/files/misc/drbl-clients-nat /etc/init.d
4686 cp -f $drbl_setup_path/files/misc/systemd/drbl-clients-nat.service /lib/systemd/system/
4687 systemctl enable drbl-clients-nat.service
4688 else
4689 cp -f $drbl_setup_path/files/misc/drbl-clients-nat /etc/init.d
4690 # before we do it, clean it to avoid the stalled files.
4691 if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
4692 insserv -f -r drbl-clients-nat &>/dev/null
4693 else
4694 update-rc.d -f drbl-clients-nat remove &>/dev/null
4695 # It will be added to rcX.d by "drbl-all-service add", so we do not add it here
4696 fi
4697 fi
4698 fi
4699
4700 # flush the YP
4701 echo "Update YP..."
4702 if [ -e /etc/debian_version ]; then
4703 # For Debian woody, it seems that /etc/networks is not automaticaly created.
4704 # If we can not find it, just touch it
4705 [ ! -e /etc/networks ] && touch /etc/networks
4706 fi
4707 # The hostname for the master is stored within each NIS map and so if you do not regenerate the maps the master returned will not change.
4708 # Ref: http://www.usenetlinux.com/archive/topic.php/t-224905.html
4709 # We need to update hosts.byname, hosts.byaddr...
4710 [ -e /var/yp/Makefile ] && touch /var/yp/Makefile
4711 # For FC17, it seems it won't work with "all" in the beginning. Therefore we addd the command without all.
4712 make -C /var/yp &> /dev/null
4713 make -C /var/yp all &> /dev/null
4714
4715 # Clean those pseudo clients (empty directories)
4716 rmdir $drblroot/* 2>/dev/null
4717
4718 # reset some stale status, maybe drblpush is run again.
4719 if [ -e "$ocs_lock_dir/clonezilla.lock" ]; then
4720 if type drbl-ocs &>/dev/null; then
4721 echo -n "Your system is already in clonezilla mode... we will stop the stale status... "
4722 drbl-ocs -n -l 0 stop &>/dev/null
4723 echo "done!"
4724 fi
4725 fi
4726
4727 # add and (re)start all the service which DRBL server need.
4728 # drbl-all-service will automatically add them to rcX.d before start them .
4729 if [ "$add_start_drbl_services_after_cfg" != "no" ]; then
4730 drbl-all-service start
4731 retv=$?
4732 if [ "$retv" -gt 0 ]; then
4733 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
4734 echo "$msg_something_went_wrong_when_start_drbl_related_srv"
4735 echo "$msg_you_can_try_to_run_the_following_again:"
4736 echo "drbl-all-service start"
4737 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4738 fi
4739 else
4740 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4741 echo $msg_drbl_related_services_not_added_started
4742 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4743 fi
4744
4745 #
4746 if [ "$use_existing_dhcp_srv" = "yes" ]; then
4747 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4748 echo "Use existing DHCP service, so now enable proxy DHCP mode..."
4749 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4750 # This will use one program, i.e., dnsmasq proxy mode for dhcp+tftp.
4751 drbl-proxy-dhcp enable
4752 else
4753 # This will use two programs, i.e., ISC dhcpd + tftpd.
4754 # No issue about dnsmasq proxy mode.
4755 # Ref: ocs-live-feed-img, check comments about "A workaround to fix the dnsmasq issue"
4756 # Hence we can try to enable uEFI network secure boot for clients if it is assigned to enable.
4757 if [ "$secure_boot_client" = "yes" ]; then
4758 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4759 echo "Not using existing DHCP service, so try to enable uEFI secure boot service for clients..."
4760 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4761 drbl-gen-grub-efi-nb -s
4762 fi
4763 fi
4764
4765 # set the boot prompt for clients if set
4766 case "$set_client_system_select" in
4767 y|Y|[yY][eE][sS])
4768 # process if we wan to turn on/off the thin client option in PXE boot menu
4769 case "$open_thin_client_option" in
4770 y|Y|[yY][eE][sS])
4771 # set the option for processing PXE boot menu
4772 client_select_opt="-e"
4773 # Turn on the thin client server (gdm/kdm...)
4774 drbl-powerful-thin-client --no-gen-ssi --thin -ln $language
4775 ;;
4776 n|N|[nN][oO])
4777 # set the option for processing PXE boot menu
4778 client_select_opt="-d"
4779 # Turn on the thin client server (gdm/kdm...)
4780 drbl-powerful-thin-client --no-gen-ssi --powerful -ln $language
4781 ;;
4782 esac
4783 drbl-client-system-select $client_select_opt -t $client_system_boot_timeout on
4784 ;;
4785 n|N|[nN][oO])
4786 drbl-client-system-select off
4787 ;;
4788 esac
4789 # set graphic/text pxe boot menu for clients
4790 case "$use_graphic_pxelinux_menu" in
4791 y|Y|[yY][eE][sS])
4792 switch-pxe-bg-mode -m graphic
4793 switch-efi-nb-bg-mode -m graphic
4794 ;;
4795 n|N|[nN][oO])
4796 switch-pxe-bg-mode -m text
4797 switch-efi-nb-bg-mode -m text
4798 ;;
4799 esac
4800
4801 # if drbl_mode is none, disable drbl in pxelinux menu, and set default as local
4802 if [ "$drbl_mode" = "none" ]; then
4803 # disable the DRBL in pxelinux menu
4804 hide_reveal_pxe_img drbl hide $pxecfg_pd/pxelinux.cfg/default
4805 # set local as default
4806 set-default-pxe-img -i local -c $pxecfg_pd/pxelinux.cfg/default
4807 fi
4808
4809 # Force to update the pxelinux config
4810 case "$drbl_mode" in
4811 "full_drbl_mode") drbl_mode_opt="-d 0" ;;
4812 "drbl_ssi_mode") drbl_mode_opt="-d 1" ;;
4813 "none") drbl_mode_opt="-d 2" ;;
4814 esac
4815 case "$clonezilla_mode" in
4816 "full_clonezilla_mode") clonezilla_mode_opt="-z 0" ;;
4817 "clonezilla_box_mode") clonezilla_mode_opt="-z 1" ;;
4818 "none") clonezilla_mode_opt="-z 2" ;;
4819 "clonezilla_live_mode") clonezilla_mode_opt="-z 3" ;;
4820 esac
4821 tune-clientdir-opt -l $language --no-create-ssi-template $drbl_mode_opt $clonezilla_mode_opt
4822
4823 #
4824 case "$purge_client" in
4825 n|N|[nN][oO])
4826 # Do not prompt user to restart client if no existing client exists
4827 tune_DBN_audio_plugdev_extra_opt="-r"
4828 ;;
4829 esac
4830 # set the DBN clients audio and plugdev if set
4831 if [ -e /etc/debian_version ]; then
4832 case "$set_DBN_client_audio_plugdev" in
4833 y|Y|[yY][eE][sS])
4834 tune-debian-dev-group-perm -l $language -g "$desktop_user_group_debian" -e $tune_DBN_audio_plugdev_extra_opt
4835 ;;
4836 esac
4837 fi
4838
4839 # post run
4840 if [ -n "$(unalias ls 2>/dev/null; ls $DRBLPUSH_POSTRUN_DIR/ 2>/dev/null)" ]; then
4841 echo "Some files are found in $DRBLPUSH_POSTRUN_DIR. Run them now..."
4842 drbl-run-parts $DRBLPUSH_POSTRUN_DIR
4843 fi
4844
4845 #
4846 # echo warning message if TCPwrapper is set.
4847 host_allow_set=$(grep -v "^[[:space:]]*#" /etc/hosts.allow 2>/dev/null)
4848 host_deny_set=$(grep -v "^[[:space:]]*#" /etc/hosts.deny 2>/dev/null)
4849 if [ -n "$host_allow_set" -o -n "$host_deny_set" ]; then
4850 client_ips="$(get-client-ip-list)"
4851 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4852 echo "$msg_hosts_allow_deny_is_set"
4853 echo "$msg_you_must_make_sure_these_clients"
4854 # format the output, 4 IP addresses in one line
4855 # --------------------
4856 i=0
4857 for ip in $client_ips; do
4858 i=$(($i+1))
4859 echo -n "$ip "
4860 [ "$(expr $i % 4)" -eq 0 ] && echo
4861 done
4862 echo
4863 # --------------------
4864 echo "$msg_can_access_this_DRBL_server"
4865 echo "$msg_otherwise_client_fail_to_boot"
4866 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4867 echo "TFTP open timeout"
4868 echo "TFTP......."
4869 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4870 echo "$msg_or"
4871 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4872 echo "mount: RPC: Unable to receive; errno = Connection refused"
4873 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4874 fi
4875
4876 # Check the NFSD no, it's very important when heavy client traffic.
4877 RUNNING_NFSDCOUNT="$(ps -ef | grep nfsd | grep -v grep | wc -l)"
4878 total_necessary_nfsd="$(get-necessary-nfsd-no)"
4879 if [ -z "$total_necessary_nfsd" ]; then
4880 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4881 echo "Warning! Unable to get the total necessary NFS daemon number!!!"
4882 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4883 fi
4884 if [ "$RUNNING_NFSDCOUNT" -lt "$total_necessary_nfsd" ]; then
4885 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4886 echo "The number of running NFS services in this DRBL number ($RUNNING_NFSDCOUNT) is not enough for clients, $total_necessary_nfsd nsfd is expected! The performance will NOT be good! Check the NFS setting in /etc/sysconfig/ or /etc/default/!!!"
4887 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4888 fi
4889
4890 #
4891 #echo "$msg_delimiter_star_line"
4892 #echo "Now syncing - flush filesystem buffers..."
4893 sync;sync;sync
4894 #
4895 export LC_ALL=$LC_ALL_org
4896
4897 echo "$msg_delimiter_star_line"
4898 echo "Enjoy DRBL!!!"
4899 echo "http://drbl.org; http://drbl.nchc.org.tw"
4900 echo "NCHC Free Software Labs, Taiwan. http://free.nchc.org.tw"
4901 echo "$msg_delimiter_star_line"
4902
4903 # ask user to reboot after first time upgrade the nfs-utils in
4904 # drblsrv_desktop.sh or get_drbl_kernel.sh
4905 # if not, user will see a lot of
4906 # "kernel: lockd: rejected NSM callback from 7f000001:1027"
4907 # in the server console and /var/log/messages in some Linux (RH8 ?).
4908 echo "$msg_if_you_like_you_can_reboot_to_make_sure_everthing"
4909 echo "$msg_delimiter_star_line"
4910 if [ "$add_start_drbl_services_after_cfg" != "no" ]; then
4911 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4912 echo "$msg_drbl_server_is_ready $msg_all_set_you_can_turn_on_clients"
4913 #echo "$msg_note! $msg_etherboot_5_4_is_required"
4914 echo "$msg_run_drblpush_with_config_again"
4915 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4916 else
4917 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
4918 echo $msg_drbl_related_services_not_added_started
4919 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
4920 fi
4921 };
4922
4923 print NETGROUP_OUT "\n";
4924 print NETGROUP_OUT "# Added by DRBL, end\n";
4925 print CLIENT_HOST_IP_LIST_OUT "# Created by DRBL (drblpush), end\n";
4926
4927 my $nameservers_json = $nameserver;
4928 $nameservers_json =~ s/\s+/,/g;
4929
4930 # Get list of DHCP interfaces
4931 my @dhcp_interfaces = ();
4932 foreach my $k2 ( sort(keys %$rHoH) ) {
4933 if( $k2=~/general/ ) { next; }
4934 my $interface=$rHoH->{$k2}{"INTERFACE"};
4935 push @dhcp_interfaces, $interface;
4936 }
4937 my $interfaces_list_json = join(", ", map { "\"$_\"" } @dhcp_interfaces);
4938
4939 my $kea_config_head = <<EOF;
4940 {
4941 "Dhcp4": {
4942 "server-hostname": "drbl",
4943 "interfaces-config": {
4944 "interfaces": [ $interfaces_list_json ]
4945 },
4946 "control-socket": {
4947 "socket-type": "unix",
4948 "socket-name": "/run/kea/kea4-ctrl-socket"
4949 },
4950 "lease-database": {
4951 "type": "memfile",
4952 "lfc-interval": 3600
4953 },
4954 "expired-leases-processing": {
4955 "reclaim-timer-wait-time": 10,
4956 "flush-reclaimed-timer-wait-time": 25,
4957 "hold-reclaimed-time": 3600,
4958 "max-reclaim-leases": 100,
4959 "max-reclaim-time": 250,
4960 "unwarned-reclaim-cycles": 5
4961 },
4962 "renew-timer": $DHCPD_DEFAULT_LEASE_TIME,
4963 "valid-lifetime": $DHCPD_MAX_LEASE_TIME,
4964 "option-data": [
4965 {
4966 "name": "domain-name-servers",
4967 "data": "$nameservers_json"
4968 },
4969 {
4970 "name": "domain-name",
4971 "data": "$domain"
4972 }
4973 ],
4974 "client-classes": [
4975 {
4976 "name": "PXE_lpxelinux",
4977 "test": "option[93].hex == 0x0000",
4978 "boot-file-name": "lpxelinux.0"
4979 },
4980 {
4981 "name": "PXE_ia32",
4982 "test": "option[93].hex == 0x0006",
4983 "boot-file-name": "bootia32.efi"
4984 },
4985 {
4986 "name": "PXE_x64_7",
4987 "test": "option[93].hex == 0x0007",
4988 "boot-file-name": "bootx64.efi"
4989 },
4990 {
4991 "name": "PXE_x64_9",
4992 "test": "option[93].hex == 0x0009",
4993 "boot-file-name": "bootx64.efi"
4994 },
4995 {
4996 "name": "PXE_arm32",
4997 "test": "option[93].hex == 0x000a",
4998 "boot-file-name": "bootarm.efi"
4999 },
5000 {
5001 "name": "PXE_arm64_b",
5002 "test": "option[93].hex == 0x000b",
5003 "boot-file-name": "bootaa64.efi"
5004 },
5005 {
5006 "name": "PXE_arm64_16",
5007 "test": "option[93].hex == 0x0016",
5008 "boot-file-name": "bootaa64.efi"
5009 },
5010 {
5011 "name": "HTTPBoot_x64",
5012 "test": "option[93].hex == 0x0010",
5013 "boot-file-name": "http://$primary_bootserver/tftpboot/nbi_img/shimx64.efi",
5014 "option-data": [
5015 {
5016 "name": "vendor-class-identifier",
5017 "data": "HTTPClient"
5018 }
5019 ]
5020 },
5021 {
5022 "name": "HTTPBoot_ia32",
5023 "test": "option[93].hex == 0x000f",
5024 "boot-file-name": "http://$primary_bootserver/tftpboot/nbi_img/bootia32.efi",
5025 "option-data": [
5026 {
5027 "name": "vendor-class-identifier",
5028 "data": "HTTPClient"
5029 }
5030 ]
5031 },
5032 {
5033 "name": "HTTPBoot_arm64",
5034 "test": "option[93].hex == 0x0013",
5035 "boot-file-name": "http://$primary_bootserver/tftpboot/nbi_img/shimaa64.efi",
5036 "option-data": [
5037 {
5038 "name": "vendor-class-identifier",
5039 "data": "HTTPClient"
5040 }
5041 ]
5042 }
5043 ],
5044 EOF
5045
5046 print KEA_OUT $kea_config_head;
5047 print KEA_OUT " \"subnet4\": [\n" . join(",\n", @kea_subnets) . "\n ]\n";
5048 print KEA_OUT "}\n}\n";
5049 close(KEA_OUT);
5050
5051 close(DHCPD_OUT);
5052 close(NETGROUP_OUT);
5053 close(CLIENT_HOST_IP_LIST_OUT);
5054 close(DISKLESS_OUT);
5055 close(NFSSERVER_OUT);
5056 close(HOSTS_LIST_OUT);
5057 close(SWAPCONF_OUT);
5058 #chnage its mode
5059 system("LC_ALL=C chmod 700 $main_sh");
5060
5061 # set public IP if options is yes
5062 if ("$set_client_public_ip_opt" eq "yes" && "$mode" eq "create_config_file"){
5063 # then user run drblpush with -i, create the $public_ip_list
5064 print "$delimiter{\"star_line\"}\n".
5065 "$lang_deploy{\"ok_let_do_it\"}\n".
5066 "$delimiter{\"dash_line\"}\n";
5067 # create the $public_ip_list file
5068 set_client_public_ip("$hosts_list","$public_ip_list");
5069 }
5070
5071 } # end of the drbl_server_parse
5072
5073 #
5074 sub check_MAC_file{
5075 my $macfile_dir="$_[0]";
5076 my $macfile_prefix="$_[1]";
5077 # note! maybe there are multiple MAC files when run drblpush with "-c"
5078 my $macfile_exist=system("LC_ALL=C ls $macfile_dir/$macfile_prefix* >/dev/null 2>&1");
5079 if ($macfile_exist == 256) {
5080 # unable to find the $macfile_prefix*
5081 print "$delimiter{\"star_line\"}\n".
5082 colored ("$lang_word{\"unable_to_find_the\"} $macfile_dir/$macfile_prefix; $lang_deploy{\"hint_for_detect_MAC\"} $macfile_prefix\n", "$color_warn").
5083 "$lang_deploy{\"press_enter_to_continue\"}";
5084 chomp($line=<STDIN>);
5085 print "$delimiter{\"dash_line\"}\n";
5086 }else{
5087 # MAC file exists, check if it contains illegal character.
5088 # empty those comment line, and delete the empty line and those comment line
5089 system("perl -p -i -e \"s/^[[:space:]]*#.*\$//g\" $macfile_dir/$macfile_prefix*");
5090 system("perl -p -i -e \"s/^[[:space:]]*\$//g\" $macfile_dir/$macfile_prefix*");
5091 my $macfile_check=`for ifile in $macfile_dir/$macfile_prefix*; do grep -v -E '([[:alnum:]]|:|^[[:space:]]*\$)' \$ifile; done`;
5092 chomp($macfile_check);
5093 if ( $macfile_check ) {
5094 print "$lang_deploy{\"illegal_char_in_MAC\"},".
5095 colored ("\"$macfile_check\"\n", "$color_fail").
5096 "$lang_deploy{\"fix_wrong_MAC_file\"} \n".
5097 "$lang_word{\"program_stop\"}!!!\n";
5098 exit(1);
5099 }
5100 }
5101 } # end of check_MAC_file
5102
5103 #########################################
5104 # Main program
5105 my $no_deploy = 0;
5106 my $config_file = "";
5107 our $verbosity = 1;
5108 # NOTE!!! Remember to update the usage_details also.
5109 our $usage="Usage: $0 [-c|--config config_file] [-d|--debug] [-e|--accept-one-nic] [-h|--help] [-i|--interactive] [-k|--keep_clients Y/n] [-l|--language index_number] [-m|--client_startup_mode 1/2] [-n|--no_deploy] [-o|--clonezilla_home DIR] [-p|--port_client_no number] [-q|--quiet] [-r|--drbl_mode 0|1|2] [-t|--live_client_branch 0|1|2|3] [-s|--swap_create y/N] [-v|--verbose] [-z|--clonezilla_mode 0|1|2|3] [--skip-drbl-ocs-live-prep] [--drbl-ocs-live-server IP]";
5110 sub usage_details{
5111 die "$usage\n".
5112 "-b, --not-add-start-drbl-srvi Do NOT add and start DRBL related services after the configuration is done\n".
5113 "-c, --config The DRBL config file, text format\n".
5114 "-d, --debug Turn on debug mode when run shell script\n".
5115 "-e, --accept-one-nic Accept to run DRBL service on only one network card. ///NOTE/// This might mess up your network environment especially if there is an existing DHCP service in your local network environment.\n".
5116 "-h, --help Show this help message\n".
5117 "-i, --interactive Interactive mode, setup step by step.\n".
5118 "-k, --keep_clients Y/n Keep previously saved files for clients.\n".
5119 "-m, --client_startup_mode [1|2] Assign client mode, 1 for graphic mode, 2 for text mode.\n".
5120 "-n, --no_deploy Just create files, do NOT deploy the files into system\n".
5121 "-o, --clonezilla_home DIR Use DIR as the Clonezilla image directory\n".
5122 "-p, --port_client_no number The client no. in each NIC port.\n".
5123 "-q, --quiet Be less verbose\n".
5124 "-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)\n".
5125 "-s, --swap_create y/N Switch to create and use local swap in clients (yes or no)\n".
5126 "-t, --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\n".
5127 "-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)\n".
5128 "-v, --verbose Be more verbose\n".
5129 "-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)\n".
5130 "--skip-drbl-ocs-live-prep Force to skip running drbl-ocs-live-prep\n".
5131 "--drbl-ocs-live-server IP Assign the Clonezilla live server as IP when running drbl-ocs-live-prep\n".
5132 "-l, --language INDEX Set the language to be shown (deprecated! Use environmental LC_ALL or LANG instead).\n".
5133 " [0]: English\n".
5134 " [1]: Traditional Chinese (Big5) - Taiwan\n".
5135 " [2]: Traditional Chinese (UTF-8, Unicode) - Taiwan\n".
5136 " [a|ask]: Prompt to ask the language index\n".
5137 "--ln INDEX Set the language to be shown (deprecated! Use environmental LC_ALL or LANG instead).\n".
5138 " [en_US]: English\n".
5139 " [zh_TW.BIG5]: Traditional Chinese (Big5) - Taiwan\n".
5140 " [zh_TW.UTF-8]: Traditional Chinese (UTF-8, Unicode) - Taiwan\n".
5141 "";
5142 } # end of usage_details
5143
5144 # Must have argument
5145 die "$usage\n" if $#ARGV<0;
5146
5147 # Parse command-line options
5148 while ($#ARGV != -1) {
5149 my $arg;
5150 $arg = shift(@ARGV);
5151 if (lc($arg) =~ /^(-)?(-)?l(anguage)?$/) {
5152 $lang_opt = shift(@ARGV);
5153 } elsif (lc($arg) =~ /^(-)?(-)?ln$/) {
5154 $language = shift(@ARGV);
5155 } elsif (lc($arg) =~ /^(-)?(-)?n(o_deploy)?$/) {
5156 $no_deploy = 1;
5157 } elsif (lc($arg) =~ /^(-)?(-)?c(config)?$/) {
5158 $config_file = shift(@ARGV);
5159 $mode="load_config_file";
5160 } elsif (lc($arg) =~ /^(-)?(-)?v(erbose)?$/) {
5161 $verbose_opt="-v";
5162 $verbosity++;
5163 } elsif (lc($arg) =~ /^(-)?(-)?q(uiet)?$/) {
5164 $verbosity--;
5165 } elsif (lc($arg) =~ /^(-)?(-)?p(ort_client_no)?$/) {
5166 $assign_client_no_each_port = shift(@ARGV);
5167 } elsif (lc($arg) =~ /^(-)?(-)?h(elp)?$/) {
5168 usage_details();
5169 } elsif (lc($arg) =~ /^(-)?(-)?i(nteractive)?$/) {
5170 $mode = "create_config_file";
5171 } elsif (lc($arg) =~ /^(-)?(-)?k(eep_clients)?$/) {
5172 $keep_client = shift(@ARGV);
5173 } elsif (lc($arg) =~ /^(-)?(-)?m(ode)?$/) {
5174 $client_startup_mode = shift(@ARGV);
5175 } elsif (lc($arg) =~ /^(-)?(-)?s(wap_mode)?$/) {
5176 $swap_create = shift(@ARGV);
5177 } elsif (lc($arg) =~ /^-z$|^--clonezilla_mode$/) {
5178 $clonezilla_mode = shift(@ARGV);
5179 } elsif (lc($arg) =~ /^-t$|^--live_client_branch$/) {
5180 $live_client_branch= shift(@ARGV);
5181 } elsif (lc($arg) =~ /^-u$|^--live_client_cpu_mode$/) {
5182 $live_client_cpu_mode = shift(@ARGV);
5183 } elsif (lc($arg) =~ /^-r$|^--drbl_mode$/) {
5184 $drbl_mode = shift(@ARGV);
5185 } elsif (lc($arg) =~ /^-o$|^--clonezilla_home$/) {
5186 $ocs_img_repo_dir = shift(@ARGV);
5187 } elsif (lc($arg) =~ /^-b$|^--not-add-start-drbl-srvi$/) {
5188 $add_start_drbl_services_after_cfg = "no";
5189 } elsif (lc($arg) =~ /^-e$|^--accept-one-nic$/) {
5190 $continue_with_one_port = "yes";
5191 } elsif (lc($arg) =~ /^--skip-drbl-ocs-live-prep$/) {
5192 $run_drbl_ocs_live_prep = "no";
5193 } elsif (lc($arg) =~ /^--drbl-ocs-live-server$/) {
5194 $drbl_ocs_live_server = shift(@ARGV);
5195 } elsif (lc($arg) =~ /^(-)?(-)?d(ebug)?$/) {
5196 $sh_debug = "-x";
5197 } else {
5198 usage_details();
5199 }
5200 }
5201
5202 # get the language
5203 $language=lang_set($lang_opt) if ( ! $language );
5204 require "$DRBL_SCRIPT_PATH/lang/perl/$language";
5205
5206 # hint for user to answer y/n
5207 print "$delimiter{\"star_line\"}\n".
5208 colored ("$lang_deploy{\"hint_for_answer\"}\n", "$color_warn");
5209
5210 # check if drbl server package is installed or not
5211 print "$delimiter{\"star_line\"}\n";
5212 print "$lang_deploy{\"searching_installed_drbl_packages\"}\n";
5213 # just pick package drbl to test
5214
5215 # return code is number divided by 256
5216 my $drbl_rpm = system("LC_ALL=C rpm -q drbl > /dev/null 2>&1") / 256;
5217 my $drbl_deb = system("LC_ALL=C dpkg -L drbl > /dev/null 2>&1") / 256;
5218 my $drbl = $drbl_rpm * $drbl_deb;
5219 if ($drbl eq 0) {
5220 print "$lang_deploy{\"finished_searching_installed_drbl_packages\"}\n";
5221 print "$delimiter{\"star_line\"}\n";
5222 }else{
5223 print "$delimiter{\"star_line\"}\n".
5224 colored ("$delimiter{\"warning_line\"}\n", "$color_warn").
5225 "$lang_deploy{\"no_drbl_server_package_found\"}\n".
5226 "[y/N] ";
5227 chomp($line=<STDIN>);
5228 SWITCH: for ($line) {
5229 /"^y"|"^yes"/i && do {
5230 print "$delimiter{\"star_line\"}\n".
5231 "$lang_deploy{\"ok_let_continue\"}\n".
5232 "$lang_deploy{\"but_you_will_see_errors\"}\n";
5233 last SWITCH;
5234 };
5235 /.*/ && do {
5236 print "!!!!!!!!!!!!!!!!!!!!!!!!!\n".
5237 "$lang_deploy{\"smart_decision\"}\n";
5238 exit(1);
5239 last SWITCH;
5240 };
5241 }
5242 }
5243
5244 if ("$mode" eq "create_config_file") {
5245 print "$delimiter{\"dash_line\"}\n".
5246 "$lang_deploy{\"interactive_mode_prompt\"}\n".
5247 "$delimiter{\"dash_line\"}\n";
5248 interactive_mode;
5249 $config_file=$DRBLPUSH_CONF;
5250 } elsif ("$mode" eq "load_config_file") {
5251 # copy the pre-saved setting file to this working directory
5252 # config_file
5253 # 2 possibilities, $config_file is inputted as absolute or relative path.
5254 # (1) $config_file is inputted as absolute path, like /etc/drbl/drblpush.conf
5255 system("[ -f $config_file ] && cp -f $config_file .");
5256 # (2) If the $config_file is input as relative path, like ./drblpush.conf, we have to copy it from $orig_wd, since now it's in working dir.
5257 system("[ -f $orig_wd/$config_file ] && cp -f $orig_wd/$config_file .");
5258 # public IP setting
5259 system("[ -f $drbl_syscfg/$public_ip_list ] && cp -f $drbl_syscfg/$public_ip_list $public_ip_list");
5260 # MAC address files
5261 system("cp -f $drbl_syscfg/macadr-*.txt . > /dev/null 2>&1");
5262
5263 }
5264 unless ( $config_file ) { die "$usage\n"; }
5265
5266 # parse the config file, then create the exe script file $main.sh
5267 drbl_server_parse($config_file);
5268
5269 print "$delimiter{\"star_line\"}\n";
5270 print "purge_client: $purge_client\n" if $verbosity >=2;
5271 if ( $client_exist_flag = "0" && $purge_client eq "no" ) {
5272 # old clients exist and we want to keep them, show warning messages
5273 print colored ("$lang_deploy{\"note_for_keep_client_setting\"}\n", "$color_warn").
5274 "$lang_deploy{\"press_enter_to_continue\"}";
5275 chomp($line=<STDIN>);
5276 }
5277
5278 # ready to go
5279 if ( $no_deploy ) {
5280 print "$delimiter{\"warning_line\"}\n".
5281 "$lang_deploy{\"no_deploy_prompt\"}\n";
5282 }
5283 else {
5284 print "$delimiter{\"star_line\"}\n".
5285 "$lang_deploy{\"ready_to_deploy\"}\n".
5286 colored ("$lang_deploy{\"overwrite_firewall_rule\"}\n", "$color_warn").
5287 colored ("$lang_deploy{\"backup_firewall_rule\"}\n", "$color_warn").
5288 "[Y/n] ";
5289 chomp($line=<STDIN>);
5290 if ($line eq "n" || $line eq "N" || $line eq "no" || $line eq "NO") {
5291 print "$delimiter{\"exclamation_line\"}\n".
5292 "$lang_deploy{\"oh_quit_now\"}\n";
5293 unlink ($main_sh) if -f $main_sh;
5294 } else {
5295 print "$delimiter{\"star_line\"}\n".
5296 "$lang_deploy{\"ok_let_do_it\"}\n".
5297 "$delimiter{\"dash_line\"}\n";
5298 my $whoiam = `LC_ALL=C id -nu`;
5299 chomp($whoiam);
5300 # Also copy the $DRBLPUSH_CONF to system so that we can re-run the
5301 # program by "drblpush -c $drbl_syscfg/$DRBLPUSH_CONF"
5302 my $run_main="LC_ALL=C ./$main_sh";
5303 if ("$whoiam" eq "root") {
5304 system("$run_main");
5305 }else{
5306 print "$lang_deploy{\"you_are_not_root\"},\n".
5307 "$lang_word{\"please_enter\"} ". colored("$lang_word{\"root_passwd\"} ","$color_warn") ."$lang_word{\"to_deploy_them\"}...\n";
5308 my $su_rlt=system("su -c '$run_main' root");
5309 while ($su_rlt == 256) {
5310 $su_rlt=system("su -c '$run_main' root");
5311 }
5312 # copy the config file to DRBL server
5313 }
5314 }
5315 }
5316 #
5317 chdir ($orig_wd) || die ("Could not change to the original working directory!!!");
5318 # clean the temp working directory
5319 rmtree ($drblpush_wd) if -d $drblpush_wd;
5320
5321 #########################################