1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
|
#!/bin/bash
# Steven Shiau <steven _at_ clonezilla org>, Ceasar Sun <ceasar _at_ nchc org tw>
# License: GPL
#
# Loading setting
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
#
check_if_root
# drbl_deploy.conf can only be access by root, so check_if_root should be run first.
. /etc/drbl/drbl_deploy.conf
#
usage() {
echo "Usage: $0 Options"
echo "Options:"
language_help_prompt_by_idx_no
echo "-h, --host IP_ADDRESS: Generate the files of host with IP_ADDRESS"
echo "-k, --keep-files [y/N]: if assigned client files exists, keep newer files or not. Default is NO, i.e. overwrite all."
echo "-n, --nfsserver IP_ADDRESS: The nfsserver (IP address) for this client."
echo "-i, --nisserver IP_ADDRESS: The nisserver (IP address) for this client."
echo "-a, --label LABEL: The hostname of this client."
echo "-p, --pseudo: Pseudo mode, just create empty client dir to be used in DRBL SSI mode."
echo "Example:"
echo "$0 -l 0 -h 192.168.100.1 -k n -n 192.168.1.254 -a drbl101 -i 192.168.1.254"
}
#
pseudo=
while [ $# -gt 0 ]; do
case "$1" in
-h|--host)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
ip="$1"
shift
fi
;;
-k|--keep-files)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
keep_client_files="$1"
shift
fi
;;
-n|--nfsserver)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
nfsserver="$1"
shift
fi
;;
-a|--label)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
label="$1"
shift
fi
;;
-i|--nisserver)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
nisserver="$1"
shift
fi
;;
-l|--language)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
specified_lang="$1"
shift
fi
;;
-p|--pseudo)
shift
pseudo=on
;;
-*) echo "${0}: ${1}: invalid option" >&2
usage >& 2
exit 2 ;;
*) break ;;
esac
done
#
ask_and_load_lang_set $specified_lang
#
if [ -z "$ip" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "No specified client!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
usage
exit 1
fi
# Some checkings
if [ -z "$label" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "No assigned label!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
usage
exit 1
fi
#
if [ -z "$nfsserver" ]; then
nfsserver="$(drbl-get-nfsserver $ip)"
fi
# if nis server is not assigned, use the nfsserver.
if [ -z "$nisserver" ]; then
nisserver=$nfsserver
echo "NIS server is $nisserver"
fi
# checking
if [ -z "$nfs_protocol" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "Unable to find the nfs_protocol!!!"
echo "Does something go wrong with /etc/drbl/drbl_deploy.conf ?"
echo "Program terminated!!!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
exit 1
fi
# define the variables for fstab
# nfs_client_extra_opt is loaded from drbl.conf
nfs_ver_opt="nfsvers=3"
# If need, you can add "rsize=65536,wsize=65536"
# FSTAB_NFS_ROOT_OPT is for nfs root only. It's actually ro, while due to the service /etc/init.d/checkroot.sh will parse it and judge if it's read-only or not. we have to make it "like" rw, but actually it's ro.
FSTAB_NFS_ROOT_OPT="rw,soft,$nfs_ver_opt,$nfs_protocol,$nfs_client_extra_opt,defaults 0 0"
FSTAB_NFS_RO_OPT="ro,soft,$nfs_ver_opt,$nfs_protocol,$nfs_client_extra_opt,defaults 0 0"
FSTAB_NFS_RW_OPT="rw,hard,intr,$nfs_ver_opt,$nfs_protocol,$nfs_client_extra_opt,defaults 0 0"
#
case "$keep_client_files" in
y|Y|[yY][eE][sS])
RSYNC_OPT_EXTRA="-u"
;;
*)
RSYNC_OPT_EXTRA=""
;;
esac
# get the OS_Version and OS_type
check_distribution_name
# varlib_NOT_2_be_copied_2_each_client is loaded from drbl.conf
# prepare the options for rsync to exclude when copy files in
# /tftpboot/node_root/var/lib/* to /tftpboot/nodes/$IP/var/lib/
varlib_opts_common_to_each=""
for iv in $varlib_NOT_2_be_copied_2_each_client; do
varlib_opts_common_to_each="$varlib_opts_common_to_each --exclude=$iv/ "
done
#
echo -n "Creating DRBL client: "
[ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
echo -n "$label $ip... "
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
mkdir -p $drblroot/$ip
# If pseudo is on, then we finish here.
if [ "$pseudo" = "on" ]; then
echo "Pseudo client is created for DRBL SSI or clonezilla box mode! done!"
exit 0
fi
[ ! -d $drblroot ] && mkdir -p -m 700 $drblroot
mkdir -p $drblroot/$ip/root
mkdir -p $drblroot/$ip/dev
rsync -a $RSYNC_OPT_EXTRA $drbl_common_root/etc $drblroot/$ip/
rsync -a $RSYNC_OPT_EXTRA $drbl_common_root/root $drblroot/$ip/
# Let the boot scripts will not try to check filesystems in the client
echo "" > $drbl_common_root/fastboot
# Put a tag for FC3 or newer so that rc.sysinit will know it's a readonly root
case "$OS_type" in
RH|MDK)
echo "READONLY=yes" > $drblroot/$ip/etc/sysconfig/readonly-root
# put an empty file so rc.sysinit won't complain.
touch $drblroot/$ip/etc/rc.readonly
;;
esac
# copy the node_root/var to client,
# we do not have to copy /tftproot/node_root/var/lib/rpm /tftproot/node_root/var/lib/dpkg (big directory!),
# it will be mounted. i.e. # we just share that for every client.
#rsync -a $RSYNC_OPT_EXTRA --exclude=rpm/ --exclude=dpkg/ $drbl_common_root/var $drblroot/$ip/
rsync -a $RSYNC_OPT_EXTRA $varlib_opts_common_to_each $drbl_common_root/var $drblroot/$ip/
# For nfs statd, the file /var/lib/nfs/state is important, othewise it won't be started in the 1st time in some distribution (like Debian >= 8).
rsync -a $RSYNC_OPT_EXTRA $drbl_common_root/var/lib/nfs/state $drblroot/$ip/var/lib/nfs/
# create those directory excluding in varlib_opts_common_to_each
rsync -a $RSYNC_OPT_EXTRA --include="*/" --exclude="*" $drbl_common_root/var $drblroot/$ip/
# Instead, we need mount point $drblroot/$ip/var/lib/rpm and dpkg
# and $drblroot/$ip/var/spool/mail
# since /var/spool/mail maybe a symbolic dir (Debian-based, it is linked to /var/mail, RH-based, it's a dir), we use "-e" here
for idir in /var/lib/rpm /var/lib/dpkg /var/spool/mail; do
[ -e $idir ] && mkdir -p $drblroot/$ip/$idir
done
# comment this, now we use "mount -t tmpfs none /dev" in the beginning of
# initrd, so we will use mknode to create console, null, tty[0-5] runtime
## must have some dev for initrd when boot
#cp -a /dev/console /dev/null /dev/tty[0-5] $drblroot/$ip/dev
# output the file to $ip/etc/fstab
cat <<-FSTAB > $drblroot/$ip/etc/fstab
# No more comment this /, since we use mount.nfs from distribution system, not from busybox any more.
## Comment / to avoid mounting twice, since
## / is already mounted by busybox's mount, which differs
## to the mount in system. Mount options maybe differs, too.
## Therefore if this line is not commented, it will mount again.
## Keep this line here for ref only.
$nfsserver:$drbl_common_root / nfs nolock,$FSTAB_NFS_ROOT_OPT
$nfsserver:$drblroot/$ip/etc /etc nfs $FSTAB_NFS_RW_OPT
$nfsserver:$drblroot/$ip/var /var nfs $FSTAB_NFS_RW_OPT
$nfsserver:$drblroot/$ip/root /root nfs $FSTAB_NFS_RW_OPT
$nfsserver:/usr /usr nfs $FSTAB_NFS_RO_OPT
$nfsserver:/home /home nfs $FSTAB_NFS_RW_OPT
$nfsserver:/var/spool/mail /var/spool/mail nfs $FSTAB_NFS_RW_OPT
#none /proc proc defaults 0 0
tmpfs /tmp tmpfs nosuid,nodev 0 0
#/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
#/dev/sr0 /mnt/cdrom iso9660 iocharset=cp950,noauto,owner,kudzu,ro 0 0
FSTAB
# Only when dir /opt/ exists, drbl-nfs-export will export it, then client should mount it, too.
if [ -d /opt/ ]; then
cat <<-FSTAB >> $drblroot/$ip/etc/fstab
$nfsserver:/opt /opt nfs $FSTAB_NFS_RO_OPT
FSTAB
fi
# if $ocsroot is not under /home, or if $ocsroot is a mount point, client must mount it.
if [ -z "$(echo $ocsroot | grep -Ew "^/home")" -o \
-n "$(awk -F" " '{print $2}' /proc/mounts | grep -Ew "$ocsroot")" ]; then
cat <<-FSTAB >> $drblroot/$ip/etc/fstab
$nfsserver:$ocsroot $ocsroot nfs $FSTAB_NFS_RW_OPT
FSTAB
fi
# no matter it's drbl box or clonezilla box, /var/lib/rpm or /var/lib/dpkg is exported. But when client is clonezilla box and in rc1.d, it won't mount them.
case "$OS_type" in
RH|MDK|SUSE)
if [ -d /var/lib/rpm ]; then
cat <<-FSTAB >> $drblroot/$ip/etc/fstab
$nfsserver:$drbl_common_root/var/lib/rpm /var/lib/rpm nfs $FSTAB_NFS_RO_OPT
FSTAB
fi
# Generate the /dev/pts, /dev/shm... dir.
for i in $memfs_dir_in_rh_client_fstab; do
if LC_ALL=C grep -q -F "$i" /etc/fstab &>/dev/null; then
LC_ALL=C grep -F "$i" /etc/fstab >> $drblroot/$ip/etc/fstab
fi
done
;;
DBN)
if [ -d /var/lib/dpkg ]; then
cat <<-FSTAB >> $drblroot/$ip/etc/fstab
$nfsserver:$drbl_common_root/var/lib/dpkg /var/lib/dpkg nfs $FSTAB_NFS_RO_OPT
FSTAB
fi
;;
esac
# append /media, /mnt to fstab if necessary
for d in media mnt; do
if [ -d "$drbl_common_root/$d" ]; then
cat <<-FSTAB >> $drblroot/$ip/etc/fstab
tmpfs /$d tmpfs defaults 0 0
FSTAB
fi
done
# append user assigned dir
for d in $diskless_root_dir_ro_user_add; do
if [ -d "$drbl_common_root/$d" ]; then
cat <<-FSTAB >> $drblroot/$ip/etc/fstab
$nfsserver:$d $d nfs $FSTAB_NFS_RO_OPT
FSTAB
fi
done
for d in $diskless_root_dir_rw_user_add; do
if [ -d "$drbl_common_root/$d" ]; then
cat <<-FSTAB >> $drblroot/$ip/etc/fstab
$nfsserver:$d $d nfs $FSTAB_NFS_RW_OPT
FSTAB
fi
done
# append user assigned local dir
# only when there is setting, we will append the fstab
if [ -n "$(grep -vE "^[[:space:]]*#" $drbl_syscfg/client-append-fstab 2>/dev/null)" ]; then
echo "" >> $drblroot/$ip/etc/fstab
echo "# Extra mount point specified in $drbl_syscfg/client-append-fstab" >> $drblroot/$ip/etc/fstab
# filter the comment lines
(grep -vE "^[[:space:]]*#" $drbl_syscfg/client-append-fstab; echo) | # make sure there is a LF at the end
while read dev mnt_pnt others; do
# create the mount point
[ ! -d "$drbl_common_root/$mnt_pnt" ] && mkdir -p $drbl_common_root/$mnt_pnt
# append the fstab for client.
echo $dev $mnt_pnt $others >> $drblroot/$ip/etc/fstab
done
fi
# TODO, Debian/RH
# output the file to etc/sysconfig/network for DRBL clients.
case "$OS_type" in
RH|MDK)
cat <<-HOSTNAME_END > $drblroot/$ip/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=$label
DOMAINNAME=$domain
GATEWAY=$nfsserver
NISDOMAIN=$nisdomain
HOSTNAME_END
[ -f "$drblroot/$ip/etc/hostname" ] && echo $label > $drblroot/$ip/etc/hostname
;;
DBN)
echo $label > $drblroot/$ip/etc/hostname
echo $nisdomain > $drblroot/$ip/etc/defaultdomain
;;
SUSE)
echo $label > $drblroot/$ip/etc/HOSTNAME
echo $nisdomain > $drblroot/$ip/etc/defaultdomain
echo "default $nfsserver - -" > $drblroot/$ip/etc/sysconfig/network/routes
;;
esac
# clean all network setting, since we already set the network in init
if [ -e /etc/debian_version ]; then
# Debian
rm -f $drblroot/$ip/etc/network/interfaces
# Create a dummy file so that hotplug won't complain that.
cat <<-NIC_END > $drblroot/$ip/etc/network/interfaces
# This dummy file is automatically created by DRBL to avoid the warning of hotplug.
# You should *NOT* put any network interface setting here, since it already automatically configured in PXE initrd in this DRBL client, and network service default is not on!!!
NIC_END
elif [ -e /etc/SuSE-release ]; then
# SuSE
rm -f $drblroot/$ip/etc/sysconfig/network/ifcfg-eth*
# For SuSE, we do not generate dummy NIC conf files since
# (1) Until OpenSuSE 10.1 Not config file will be automatically created,
# (2) The file name is like ifcfg-eth-id-00:0c:29:45:9b:81, based on MAC address, we can not foresee that.
else
# RH-like
rm -f $drblroot/$ip/etc/sysconfig/network-scripts/ifcfg-eth*
for ethx in $dummy_eth_nics; do
cat <<-NIC_END > $drblroot/$ip/etc/sysconfig/network-scripts/ifcfg-$ethx
# This dummy file is automatically created by DRBL to avoid it to be recreated..
# You should *NOT* put any network interface setting here, since it already automatically configured in PXE initrd in this DRBL client, and network service default is not on!!!
DEVICE=$ethx
BOOTPROTO=dhcp
ONBOOT=no
NIC_END
done
fi
cat <<-YPCONF_ETH0 > $drblroot/$ip/etc/yp.conf
domain $nisdomain server $nisserver
YPCONF_ETH0
# Generate the OpenSSH host key for clients. For RH-like, sshd service will
# generated the keys if they do not exist.
case "$OS_type" in
DBN)
drbl-gen-ssh-host-keys generate $ip
;;
esac
[ -f "$drblroot/$ip/etc/resolv.conf" ] && rm -f $drblroot/$ip/etc/resolv.conf
for nameserver in $nameserver_; do
echo "nameserver $nameserver" >> $drblroot/$ip/etc/resolv.conf
done
# Comment this, it's not necessary now.
#ln -fs $drbl_common_root /tftpboot/$ip
# For client login mode
PASSWD_OPT=""
[ -n "$client_autologin_passwd" ] && PASSWD_OPT="-p $client_autologin_passwd"
case "$login_gdm_opt" in
"auto_login")
drbl-login-switch --no-gen-ssi -l $lang --auto --no_nis_update $PASSWD_OPT --host $ip
;;
"timed_login")
drbl-login-switch --no-gen-ssi -l $lang --timed $timed_login_time --no_nis_update $PASSWD_OPT --host $ip
;;
*)
drbl-login-switch --no-gen-ssi -l $lang --normal --no_nis_update --host $ip
;;
esac
# Now it's not necessary to change client's /etc files when clonezilla start, so
# we can put the ocs related files in client's rc1.d first.
# Here we force to use hardware detect for client's rc1.d
ocs-related-srv --hw-detect on -n $ip put
# put S19ocs-run
# By Ceasar :
# The reason we can not just sync from $common_root is because FC17/18 can't leave ocs-run linking file in rc*.d and it has already been deleted in $common_root
( cd $drblroot/$ip/$RCX_ROOTDIR/rc1.d/; ln -fs $RCX_REL_INITD/ocs-run S19ocs-run )
if is_systemd_init; then
( cd $drblroot/$ip/$RCX_ROOTDIR/rc1.d/; rm -rf S*ocs-run )
fi
# set the root's passwd for clients if set client_root_passwd
[ -n "$client_root_passwd" ] && drbl-client-root-passwd --no-gen-ssi --stdin $client_root_passwd --host $ip
|