Debian Codegraph @

scripts/sbin/drbl-ssi-client-prepare

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Author: Steven Shiau, <steven _at_ clonezilla org>
3 # License: GPL
4
5 # Loading setting
6 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
7
8 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
9
10 # Option
11 nfsserver=$1
12 RO_NFS_EXTRA_OPT=$2
13 RL=$3
14
15 # functions
16 jobs_for_clonezilla_boxscip-shell shell shell-project 0.0.0 jobs_for_clonezilla_box().() {
17 # 1. comment unnesessary mount, /opt, /var/spool/mail, /var/lib/rpm/ and /var/lib/dpkg
18 # 2. remove ntp
19 # 3. set runlevel in /etc/inittab to cheat kudzu
20 # 4. copy necessary files from rc1.d
21
22 # (1)
23 for im in /optscip-shell filesystem . . `/opt`. /var/spool/mailscip-shell filesystem . . `/var/spool/mail`. /var/lib/rpmscip-shell filesystem . . `/var/lib/rpm`. /var/lib/dpkgscip-shell filesystem . . `/var/lib/dpkg`.; do
24 # Use subshell to avoid some parameter to be overwriten
25 (
26 . /etc/drbl/drbl.confscip-shell source . . `/etc/drbl/drbl.conf`.
27 # If $ocsroot is happened to be /opt/xxx or /var/spool/mail/xxx... we have
28 # to avoid that to be commented, since we need the $ocsroot as clonezilla
29 # image dir.
30 # /etc/fstab
31 # Example 1 (with $ocsroot=/opt/partimag):
32 # -------------------------
33 # 192.168.123.254:/opt /opt nfs rw,rsize=65536,wsize=65536,tcp,defaults 0 0
34 # 192.168.123.254:/opt/partimag /opt/partimag nfs rw,rsize=65536,wsize=65536,tcp,defaults 0 0
35 # -------------------------
36 # We will NOT comment 192.168.123.254:/opt and 192.168.123.254:/opt/partimag
37 # because we need /opt/ and its subdirectories as mount point.
38 # Example 2 (with $ocsroot=/opt2):
39 # -------------------------
40 # 192.168.123.254:/opt /opt nfs rw,rsize=65536,wsize=65536,tcp,defaults 0 0
41 # 192.168.123.254:/opt2 /opt2 nfs rw,rsize=65536,wsize=65536,tcp,defaults 0 0
42 # -------------------------
43 # We will comment 192.168.123.254:/opt, but will NOT comment 192.168.123.254:/opt2
44 if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $ocsroot | grepscip-shell system . . grep. -Ew "$im")" ]; then
45 perlscip-shell system . . perl. -pi -e "s|(^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+:.*$im[[:space:]]+.*)|# \$1|g" /etc/fstabscip-shell filesystem . . `/etc/fstab`.
46 fi
47 )
48 done
49
50 # (2)
51 # Remove ntp setting, we do not need that in cloinezilla box
52 # Debian-based: /etc/default/ntpdate
53 # RH-like, SuSE: /etc/ntp.conf
54 for intp in /etc/ntp.confscip-shell filesystem . . `/etc/ntp.conf`. /etc/default/ntpdatescip-shell filesystem . . `/etc/default/ntpdate`.; do
55 if [scip-shell system . . `[`. -f $intp ]; then
56 rmscip-shell system . . rm. -f $intp
57 # create an empty file so that the NTPSERVERS is none.
58 touchscip-shell system . . touch. $intp
59 fi
60 done
61
62 # (3)
63 # We need to cheat the inittab (Note! Now init.org not start yet), and in FC,
64 # kudzu will check inittab, and if it's rc 5, it will switch to rc 5...
65 # Therefore here we force to make inittab 1.
66 # Command "runlevel" in this stage is useless. we have to check by ourself
67 # Check if "1" exists in /proc/cmdline
68 # For Ubuntu 6.10 or later, no /etc/inittab.
69 if [scip-shell system . . `[`. -e /etc/inittabscip-shell filesystem . . `/etc/inittab`. ]; then
70 perlscip-shell system . . perl. -pi -e "s/^id:[1-5]:initdefault:/id:1:initdefault:/g" /etc/inittabscip-shell filesystem . . `/etc/inittab`.
71 fi
72
73 # (4)
74 # we need to mount rc1.d if ocs start, since this won't exist in the etc template.
75 if [scip-shell system . . `[`. -n "$(unalias ls 2>/dev/nullscip-shell filesystem . . `/dev/null`.; lsscip-shell system . . ls. /drbl_ssi/rc1.d/* 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
76 if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
77 # Debian # RCX_ROOTDIR="/etc"
78 rc1_mnt_pnt=/etc/rc1.dscip-shell filesystem . . `/etc/rc1.d`.
79 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
80 # SuSE # RCX_ROOTDIR="/etc/init.d"
81 rc1_mnt_pnt=/etc/init.d/rc1.dscip-shell filesystem . . `/etc/init.d/rc1.d`.
82 else
83 # RH-like # RCX_ROOTDIR="/etc"
84 rc1_mnt_pnt=/etc/rc1.dscip-shell filesystem . . `/etc/rc1.d`.
85 fi
86
87 # (1)
88 # If we use symbolic link, the ../init.d/ will not exist.. Any solution ?
89 #rm -rf $rc1_mnt_pnt
90 #ln -fs /drbl_ssi/rc1.d $rc1_mnt_pnt
91 # (2) # Use NFS mount ?
92 # mount -n $nfsserver:$nfsimagedir/drbl_ssi/rc1.d $rc1_mnt_pnt -o $RO_NFS_EXTRA_OPT
93 # (3) just copy the files...
94 [scip-shell system . . `[`. -d "$rc1_mnt_pnt" -a "$(echoscip-shell system . . echo. $rc1_mnt_pnt | grepscip-shell system . . grep. "rc1.d")" ] && rmscip-shell system . . rm. -rf $rc1_mnt_pnt/*
95 cpscip-shell system . . cp. -af /drbl_ssi/rc1.d/* $rc1_mnt_pnt/
96 fi
97 } # end of jobs_for_clonezilla_box
98
99 #
100 jobs_for_DRBL_SSIscip-shell shell shell-project 0.0.0 jobs_for_DRBL_SSI().() {
101 # (1) GDM/KDM autologin if necessary
102 # (2) Overwrite some setting from /drbl_ssi/clients/$IP/ to /
103
104 # (1)
105 # GDM/KDM autologin if necessary
106 # Here we just force to change the login ID, and let the original config file to
107 # control auto/timed/normal login option.
108
109 # Get the gdm or kdm config filename
110 get_gdm_kdm_conf_filename
111
112 case "$HN" in
113 "[0-9]*")
114 echoscip-shell system . . echo. "$HN can NOT be a login name for autologin, we won't change Gnome/KDE config file!"
115 ;;
116 *)
117 auto_login_id="$HN"
118 if [scip-shell system . . `[`. -e "$GDM_CFG" ]; then
119 # change timed login account
120 perlscip-shell system . . perl. -p -i -e "s/^[[:space:]]*#*[[:space:]]*TimedLogin=.*/TimedLogin=$auto_login_id/" $GDM_CFG
121 # change auto login account
122 perlscip-shell system . . perl. -p -i -e "s/^[[:space:]]*#*[[:space:]]*AutomaticLogin=.*/AutomaticLogin=$auto_login_id/" $GDM_CFG
123 fi
124 if [scip-shell system . . `[`. -e "$KDM_CFG" ]; then
125 # change auto login account
126 perlscip-shell system . . perl. -p -i -e "s/^[[:space:]]*#*[[:space:]]*AutoLoginUser=.*/AutoLoginUser=$auto_login_id/" $KDM_CFG
127 fi
128 if [scip-shell system . . `[`. -e "$LIGHTDM_CFG" ]; then
129 # To config these two parameters:
130 # autologin-user=<YOUR USER>
131 # autologin-user-timeout=0
132 perlscip-shell system . . perl. -pi -e "s/^[[:space:]]*#*[[:space:]]*autologin-user=.*/autologin-user=$auto_login_id/" $LIGHTDM_CFG
133 perlscip-shell system . . perl. -pi -e "s/^[[:space:]]*#*[[:space:]]*autologin-user-timeout=.*/autologin-user-timeout=0/" $LIGHTDM_CFG
134 fi
135 ;;
136 esac
137
138 # (2) Overwrite some setting from /drbl_ssi/clients/$IP/
139 if [scip-shell system . . `[`. -n "$(unalias ls 2>/dev/nullscip-shell filesystem . . `/dev/null`.; lsscip-shell system . . ls. /drbl_ssi/clients/$ip/* 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
140 echoscip-shell system . . echo. -n "Syncing files from /drbl_ssi/clients/$ip/ to /... "
141 rsyncscip-shell system . . rsync. -aq /drbl_ssi/clients/$ip/* /scip-shell filesystem . . `/`.
142 echoscip-shell system . . echo. "done!"
143 fi
144 } # end of jobs_for_DRBL_SSI
145
146 ############
147 ### MAIN ###
148 ############
149 # This part is common for DRBL SSI and clonezilla box
150 if [scip-shell system . . `[`. -f /etc/fstabscip-shell filesystem . . `/etc/fstab`. ]; then
151 # remove those /tftpboot/nodes/$IP.
152 # now it's single system image
153 # First we find the template machine IP address:
154 template_host_ip="$(LANG=C grepscip-shell system . . grep. -E "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+:/tftpboot/nodes/.*/etc" /etc/fstabscip-shell filesystem . . `/etc/fstab`. | cutscip-shell system . . cut. -d":" -f 1)"
155 echoscip-shell system . . echo. "# This fstab is modified by DRBL SSI (init.drbl)." > /etc/fstab.modscip-shell filesystem . . `/etc/fstab.mod`.
156 grepscip-shell system . . grep. -vE "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+:/tftpboot/nodes/" /etc/fstabscip-shell filesystem . . `/etc/fstab`. >> /etc/fstab.modscip-shell filesystem . . `/etc/fstab.mod`.
157 #perl -pi -e "s/^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+:/$nfsserver:/g" /etc/fstab.mod
158 perlscip-shell system . . perl. -pi -e "s/^$template_host_ip:/$nfsserver:/g" /etc/fstab.modscip-shell filesystem . . `/etc/fstab.mod`.
159 mvscip-shell system . . mv. -f /etc/fstab.modscip-shell filesystem . . `/etc/fstab.mod`. /etc/fstabscip-shell filesystem . . `/etc/fstab`.
160 fi
161
162 # Modify hostname, yp.conf...
163 # Hostname, remove the hostname to let DHCP server provide that.
164 ip=""
165 netdevices="$(get-nic-devs)"
166 for device in $netdevices; do
167 ip="$(drbl-get-ipadd $device)"
168 [scip-shell system . . `[`. -n "$ip" ] && break
169 done
170 # Try to mapping the hostname from /etc/hosts, if not, use IP-based hostname
171 HN="$(grepscip-shell system . . grep. "^[[:space:]]*$ip\>" /etc/hostsscip-shell filesystem . . `/etc/hosts`. | awkscip-shell system . . awk. -F" " '{print $NF}')"
172 [scip-shell system . . `[`. -z "$HN" ] && HN="$(echoscip-shell system . . echo. $ip | sedscip-shell system . . sed. -e "s/\./-/g")"
173 if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
174 # Debian
175 echoscip-shell system . . echo. $HN > /etc/hostnamescip-shell filesystem . . `/etc/hostname`.
176 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
177 # SuSE
178 echoscip-shell system . . echo. $HN > /etc/HOSTNAMEscip-shell filesystem . . `/etc/HOSTNAME`.
179 else
180 # RH-like
181 perlscip-shell system . . perl. -pi -e "s/^[[:space:]]*HOSTNAME=.*/HOSTNAME=$HN/g" /etc/sysconfig/networkscip-shell filesystem . . `/etc/sysconfig/network`.
182 fi
183 # Set the hostname now
184 hostnamescip-shell system . . hostname. $HN
185
186 # for YP
187 perlscip-shell system . . perl. -pi -e "s/(domain.*server)[[:space:]]+.*/\$1 $nfsserver/g" /etc/yp.confscip-shell filesystem . . `/etc/yp.conf`.
188
189 # ssh public key so that we can run drbl-doit
190 # /drbl_ssi/root_ssh_key/authorized_keys is already copied from root's home by drbl-gen-ssi-files
191 if [scip-shell system . . `[`. -d "/drbl_ssi/root_ssh_keyscip-shell filesystem . . `/drbl_ssi/root_ssh_key`." ]; then
192 mkdirscip-shell system . . mkdir. -m 600 /root/.sshscip-shell filesystem . . `/root/.ssh`.
193 if [scip-shell system . . `[`. -f "/drbl_ssi/root_ssh_key/authorized_keysscip-shell filesystem . . `/drbl_ssi/root_ssh_key/authorized_keys`." ]; then
194 cpscip-shell system . . cp. -f /drbl_ssi/root_ssh_key/authorized_keysscip-shell filesystem . . `/drbl_ssi/root_ssh_key/authorized_keys`. /root/.ssh/scip-shell filesystem . . `/root/.ssh/`.
195 fi
196 fi
197
198 #
199 if [scip-shell system . . `[`. "$RL" = "1" ]; then
200 # If runlevel 1, it's clonezilla box mode.
201 jobs_for_clonezilla_boxscip-shell shell shell-project 0.0.0 jobs_for_clonezilla_box().
202 else
203 # not in runleve 1, it's DRBL SSI mode.
204 jobs_for_DRBL_SSIscip-shell shell shell-project 0.0.0 jobs_for_DRBL_SSI().
205 fi