#!/bin/sh
#
# diskless-makeroot.sh
#
# Developed by Ondrej Jombik <nepto@platon.sk>
# Copyright (c) 2003-2005 Platon Group, http://platon.sk/
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 16/03/2003 - created
# 20/03/2003 - do not copy /dev/ if already exists
# 01/07/2003 - configurable $TFTPBOOT_ROOT and $TFTPBOOT_FIXED variables
# 14/07/2003 - created $DISABLED_SERVICES variable
#
# $Platon: scripts/shell/sysadmin/diskless-makeroot.sh,v 1.7 2005/09/13 17:30:28 nepto Exp $
TFTPBOOT_ROOT="/var/tftpboot/";
TFTPBOOT_FIXED="/etc/tftpboot/";
# This is a subset of services, that should be disabled on diskless client.
# Do not hesitate to update this list.
# -- Nepto [10/3/2003]
DISABLED_SERVICES="resolvconf kudzu mserver mysql msql wwwoffled squid smb bind bind9 apache httpd tftpd-hpa dhcpd dhcp3-server iptables xinetd routed postfix xfs portmap nfs nfslock nfs-common nfs-kernel-server quota quotarpc mountnfs.sh nis cups cupsys lpd mdadm mdadm-raid lvm";
#
# Input parameter check
#
if [ $# != 1 ]; then
echo "Usage: $0 <client-IP-address>";
exit 1;
fi
#
# Sanity check
#
ip=`echo "$1" | tr -d '/ '`;
if [ "$ip" != "$1" ]; then
echo "No spaces and slashes are allowed in IP-address parameter.";
exit 2;
fi
#
# Message function
#
function print_message()
{
echo "[36m$1[0m";
}
#
# Startup
#
print_message 'Startup...';
umask 022;
cd / || exit;
#
# Root directory
#
print_message 'Creating root directory.';
echo " $TFTPBOOT_ROOT/$ip";
mkdir -p "$TFTPBOOT_ROOT/$ip" || exit;
#
# Basic subdirectories
#
print_message 'Creating basic subdirectories.';
for d in home mnt proc usr opt var var/tmp; do
echo " $TFTPBOOT_ROOT/$ip/$d";
mkdir -p "$TFTPBOOT_ROOT/$ip/$d" || exit;
done
#
# Preserving directory structure of /mnt/ and /var/
#
print_message 'Preserving directory structure of /mnt/ directory.';
find /mnt/ -maxdepth 1 -type d | sed "s,^/,$TFTPBOOT_ROOT/$ip/,g" | xargs mkdir -p
print_message 'Preserving directory structure of /var/ directory.';
find /var/ -maxdepth 4 -type d | sed "s,^/,$TFTPBOOT_ROOT/$ip/,g" | xargs mkdir -p
#
# Symbolic links
#
print_message "Creating symbolic links.";
echo " $TFTPBOOT_ROOT/$ip/tmp -> $TFTPBOOT_ROOT/$ip/var/tmp";
if [ ! -e "$TFTPBOOT_ROOT/$ip/tmp" ]; then
ln -s "/var/tmp" "$TFTPBOOT_ROOT/$ip/tmp" || exit;
fi
echo " $TFTPBOOT_ROOT/$ip/var/mail -> $TFTPBOOT_ROOT/$ip/var/spool/mail";
if [ ! -e "$TFTPBOOT_ROOT/$ip/var/mail" ]; then
ln -s "/var/spool/mail" "$TFTPBOOT_ROOT/$ip/var/mail" || exit;
fi
#
# Copying directories
#
print_message 'Copying core directories.';
for d in bin lib sbin dev etc root; do
echo -n " $TFTPBOOT_ROOT/$ip/$d";
if [ "$d" = dev ]; then
if [ -d "$TFTPBOOT_ROOT/$ip/$d" ]; then
echo ": already exists, skipping";
continue;
fi
fi
echo "";
mkdir -p "$TFTPBOOT_ROOT/$ip/$d" || exit;
cp -f -a $d "$TFTPBOOT_ROOT/$ip/";
done
#
# Removing some directories.
#
print_message 'Removing some directories.';
echo " $TFTPBOOT_ROOT/$ip/etc/my-rc.d/";
rm -r -f "$TFTPBOOT_ROOT/$ip/etc/my-rc.d/";
echo " $TFTPBOOT_ROOT/$ip/etc/my-ppp/";
rm -r -f "$TFTPBOOT_ROOT/$ip/etc/my-ppp/";
#
# Removing services starting.
#
print_message 'Removing services starting.';
for service in $DISABLED_SERVICES; do
echo " $TFTPBOOT_ROOT/$ip/etc/rc.d/init.d/$service";
rm -f "$TFTPBOOT_ROOT/$ip/etc/rc.d/init.d/$service" || exit;
rm -f "$TFTPBOOT_ROOT/$ip/etc/init.d/$service" || exit;
done
#
# Overwritting with fixed files
#
print_message 'Overwritting with fixed files.';
for src_file in `find "$TFTPBOOT_FIXED/$ip/" -type f -o -type d`; do
dest_file=`echo "$src_file" | sed "s,^$TFTPBOOT_FIXED/$ip,$TFTPBOOT_ROOT/$ip,g"`;
if [ "$src_file" = "$dest_file" ]; then
exit;
fi
if [ -d "$src_file" ]; then
mkdir -p "$dest_file";
fi
if [ -f "$src_file" ]; then
echo " $dest_file";
cp -rfa "$src_file" "$dest_file" || exit;
fi
done
#
# Fastboot
#
print_message "Creating fast booting undeletable file.";
echo " $TFTPBOOT_ROOT/$ip/fastboot";
touch "$TFTPBOOT_ROOT/$ip/fastboot" || exit;
#chattr +i "$TFTPBOOT_ROOT/$ip/fastboot" || exit;
#
# Other fixes
#
chown -R gdm.gdm "$TFTPBOOT_ROOT/$ip/var/lib/gdm";
chmod -R 0750 "$TFTPBOOT_ROOT/$ip/var/lib/gdm";
chmod -R 1777 "$TFTPBOOT_ROOT/$ip/var/tmp";
chmod -R 1777 "$TFTPBOOT_ROOT/$ip/var/lib/texmf";
chmod --reference=/var/spool/mail "$TFTPBOOT_ROOT/$ip/var/spool/mail";
Platon Group <platon@platon.org> http://platon.org/
|