- mkdir -p $CD_ROOT/dev/pts
- mkdir -p $CD_ROOT/proc
- mkdir -p $CD_ROOT/etc
-
- echo "copy fstab and mtab"
- cp -f $CONF_FILES_DIR/fstab $CD_ROOT/etc/
- cp -f $CONF_FILES_DIR/mtab $CD_ROOT/etc/
-
- echo "setup rpm to install only en_US locale and no docs"
- mkdir -p $CD_ROOT/etc/rpm
- cp -f $CONF_FILES_DIR/macros $CD_ROOT/etc/rpm
-
- echo "initialize rpm db"
- mkdir -p $CD_ROOT/var/lib/rpm
- rpm --root $CD_ROOT --initdb
-
- echo "install boot cd base rpms"
- yum -c yum.conf --installroot=$CD_ROOT -y groupinstall $BOOTCD_YUM_GROUP
-
- echo "removing unneccessary build files"
- (cd $CD_ROOT/lib/modules && \
- find ./ -type d -name build -maxdepth 2 -exec rm -rf {} \;)
-
- echo "setting up non-ssh authentication"
- mkdir -p $CD_ROOT/etc/samba
- chroot $CD_ROOT /usr/sbin/authconfig --nostart --kickstart \
- --enablemd5 --enableshadow
-
- echo "setting root password"
- sed -i "s#root::#root:$ROOT_PASSWD:#g" $CD_ROOT/etc/shadow
-
- echo "relocate some large directories out of the root system"
- # get /var/lib/rpm out, its 12mb. create in its place a
- # symbolic link to /usr/relocated/var/lib/rpm
- mkdir -p $CD_ROOT/usr/relocated/var/lib/
- mv $CD_ROOT/var/lib/rpm $CD_ROOT/usr/relocated/var/lib/
- (cd $CD_ROOT/var/lib && ln -s ../../usr/relocated/var/lib/rpm rpm)
-
- # get /lib/tls out
- mkdir -p $CD_ROOT/usr/relocated/lib
- mv $CD_ROOT/lib/tls $CD_ROOT/usr/relocated/lib/
- (cd $CD_ROOT/lib && ln -s ../usr/relocated/lib/tls tls)
-
- echo "extracting syslinux, copying isolinux files to cd"
- mkdir -p syslinux
- mkdir -p $CD_ROOT/usr/isolinux/
- tar -C syslinux -xjvf $SYSLINUX_SRC
- find syslinux -name isolinux.bin -exec cp -f {} $CD_ROOT/usr/isolinux/ \;
-
- echo "moving kernel to isolinux directory"
- KERNEL=$CD_ROOT/boot/vmlinuz-*
- mv -f $KERNEL $CD_ROOT/usr/isolinux/kernel
-
- echo "creating version files"
- echo "$FULL_VERSION_STRING" > $CD_ROOT/usr/isolinux/pl_version
- echo "$FULL_VERSION_STRING" > $CD_ROOT/pl_version
-
- touch $CD_ROOT/.built
-}
-
-function build_initrd()
-{
- echo "building initrd"
- rm -f $INITRD
- rm -f $INITRD.gz
-
- echo "copy fstab and mtab"
- cp -f $CONF_FILES_DIR/fstab $CD_ROOT/etc/
- cp -f $CONF_FILES_DIR/mtab $CD_ROOT/etc/
-
- echo "installing generic modprobe.conf"
- cp -f $CONF_FILES_DIR/modprobe.conf $CD_ROOT/etc/
-
- echo "installing our own inittab and init scripts"
- cp -f $CONF_FILES_DIR/inittab $CD_ROOT/etc
- init_scripts="pl_sysinit pl_hwinit pl_netinit pl_validateconf pl_boot"
- for script in $init_scripts; do
- cp -f $CONF_FILES_DIR/$script $CD_ROOT/etc/init.d/
- chmod +x $CD_ROOT/etc/init.d/$script
+ # Set root password
+ echo "* Setting root password"
+
+ if [ -z "$ROOT_PASSWORD" ] ; then
+ # Generate an encrypted password with crypt() if not defined
+ # in a static configuration.
+ ROOT_PASSWORD=$(python <<EOF
+import crypt, random, string
+salt = [random.choice(string.letters + string.digits + "./") for i in range(0,8)]
+print crypt.crypt('$PLC_ROOT_PASSWORD', '\$1\$' + "".join(salt) + '\$')
+EOF
+)
+ fi
+
+ # build/passwd copied out by prep.sh
+ sed -e "s@^root:[^:]*:\(.*\)@root:$ROOT_PASSWORD:\1@" ${VARIANT}/passwd >$OVERLAY/etc/passwd
+
+ # Install node configuration file (e.g., if node has no floppy disk or USB slot)
+ if [ -f "$NODE_CONFIGURATION_FILE" ] ; then
+ echo "* Installing node configuration file $NODE_CONFIGURATION_FILE -> /usr/boot/plnode.txt of the bootcd image"
+ install -D -m 644 $NODE_CONFIGURATION_FILE $OVERLAY/usr/boot/plnode.txt
+ NODE_ID=$(source $NODE_CONFIGURATION_FILE; echo $NODE_ID)
+ echo "* Building network configuration for $NODE_ID"
+ plnet -- --root $OVERLAY --files-only --program BootCD $NODE_ID
+ fi
+
+ if [ -n "$IS_SERIAL" ] ; then
+ KARGS_STR="$KARGS_STR ${console_spec}"
+ fi
+
+ if [ -n "$KARGS_STR" ] ; then
+ echo "$KARGS_STR" > $OVERLAY/kargs.txt
+ kernel_args=$KARGS_STR
+ fi
+
+ # Pack overlay files into a compressed archive
+ echo "* Compressing overlay image"
+ (cd $OVERLAY && find . | cpio --quiet -c -o) | gzip -9 >$ISOFS/overlay.img
+
+ rm -rf $OVERLAY
+ pop_cleanup
+
+ if [ -n "$CUSTOM_DIR" ]; then
+ echo "* Compressing custom image"
+ (cd "$CUSTOM_DIR" && find . | cpio --quiet -c -o) | gzip -9 >$ISOFS/custom.img
+ fi
+
+ # Calculate ramdisk size (total uncompressed size of both archives)
+ ramdisk_size=$(gzip -l $ISOFS/bootcd.img $ISOFS/overlay.img ${CUSTOM_DIR:+$ISOFS/custom.img} | tail -1 | awk '{ print $2; }') # bytes
+ ramdisk_size=$((($ramdisk_size + 1023) / 1024)) # kilobytes
+
+ echo "$FULL_VERSION_STRING" >$ISOFS/pl_version
+
+ popd
+}
+
+#################### plain ISO
+function build_iso() {
+ local iso="$1" ; shift
+ local custom="$1"
+
+ # Write isolinux configuration
+ cat >$ISOFS/isolinux.cfg <<EOF
+${console_serial_line}
+DEFAULT kernel
+APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img${custom:+,custom.img} root=/dev/ram0 rw ${kernel_args}
+DISPLAY pl_version
+PROMPT 0
+TIMEOUT 40
+EOF
+
+ # Create ISO image
+ echo "* Creating ISO image"
+ mkisofs -o "$iso" $MKISOFS_OPTS $ISOFS
+}
+
+#################### USB with partitions
+function build_usb_partition() {
+ echo -n "* Creating USB image with partitions..."
+ local usb="$1" ; shift
+ local custom="$1"
+
+ local size=$(($(du -Lsk $ISOFS | awk '{ print $1; }') + $FREE_SPACE))
+ size=$(( $size / 1024 ))
+
+ local heads=64
+ local sectors=32
+ local cylinders=$(( ($size*1024*2)/($heads*$sectors) ))
+ local offset=$(( $sectors*512 ))
+
+ if [ -f /usr/lib/syslinux/mkdiskimage ] ; then
+ /usr/lib/syslinux/mkdiskimage -M -4 "$usb" $size $heads $sectors
+ else
+ mkdiskimage -M -4 "$usb" $size $heads $sectors
+ fi
+
+ cat >${BUILDTMP}/mtools.conf<<EOF
+drive z:
+file="${usb}"
+cylinders=$cylinders
+heads=$heads
+sectors=$sectors
+offset=$offset
+mformat_only
+mtools_skip_check=1
+EOF
+ # environment variable for mtools
+ export MTOOLSRC="${BUILDTMP}/mtools.conf"
+
+ ### COPIED FROM build_usb() below!!!!
+ echo -n " populating USB image... "
+ mcopy -bsQ -i "$usb" "$ISOFS"/* z:/
+
+ # Use syslinux instead of isolinux to make the image bootable
+ tmp="${BUILDTMP}/syslinux.cfg"
+ cat >$tmp <<EOF
+${console_serial_line}
+DEFAULT kernel
+APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img${custom:+,custom.img} root=/dev/ram0 rw ${kernel_args}
+DISPLAY pl_version
+PROMPT 0
+TIMEOUT 40
+EOF
+ mdel -i "$usb" z:/isolinux.cfg 2>/dev/null || :
+ mcopy -i "$usb" "$tmp" z:/syslinux.cfg
+ rm -f "$tmp"
+ rm -f "${MTOOLSRC}"
+ unset MTOOLSRC
+
+ echo "making USB image bootable."
+ syslinux -o $offset "$usb"
+
+}
+
+#################### plain USB
+function build_usb() {
+ echo -n "* Creating USB image... "
+ local usb="$1" ; shift
+ local custom="$1"
+
+ rm -f "$usb"
+ mkfs.vfat -C "$usb" $(($(du -Lsk $ISOFS | awk '{ print $1; }') + $FREE_SPACE))
+
+ cat >${BUILDTMP}/mtools.conf<<EOF
+mtools_skip_check=1
+EOF
+ # environment variable for mtools
+ export MTOOLSRC="${BUILDTMP}/mtools.conf"
+
+ # Populate it
+ echo -n " populating USB image... "
+ mcopy -bsQ -i "$usb" "$ISOFS"/* ::/
+
+ # Use syslinux instead of isolinux to make the image bootable
+ tmp="${BUILDTMP}/syslinux.cfg"
+ cat >$tmp <<EOF
+${console_serial_line}
+DEFAULT kernel
+APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img${custom:+,custom.img} root=/dev/ram0 rw ${kernel_args}
+DISPLAY pl_version
+PROMPT 0
+TIMEOUT 40
+EOF
+ mdel -i "$usb" ::/isolinux.cfg 2>/dev/null || :
+ mcopy -i "$usb" "$tmp" ::/syslinux.cfg
+ rm -f "$tmp"
+ rm -f "${MTOOLSRC}"
+ unset MTOOLSRC
+
+ echo "making USB image bootable."
+ syslinux "$usb"
+}
+
+#################### utility to setup CRAMFS related support
+function prepare_cramfs() {
+ [ -n "$CRAMFS_PREPARED" ] && return 0
+ local custom=$1;
+
+ echo "* Setting up CRAMFS-based images"
+ local tmp="${BUILDTMP}/cramfs-tree"
+ mkdir -p "$tmp"
+ push_cleanup rm -rf $tmp
+ pushd $tmp
+ gzip -d -c $ISOFS/bootcd.img | cpio -diu
+ gzip -d -c $ISOFS/overlay.img | cpio -diu
+ [ -n "$custom" ] && \
+ gzip -d -c $ISOFS/custom.img | cpio -diu
+
+ # clean out unnecessary rpm lib
+ echo "* clearing var/lib/rpm/*"
+ rm -f var/lib/rpm/*
+
+ # bootcd requires this directory
+ mkdir -p mnt/confdevice
+
+ # relocate various directory to /tmp
+ rm -rf root
+ ln -fs /tmp/root root
+ ln -fs /sbin/init linuxrc
+ ln -fs /tmp/resolv.conf etc/resolv.conf
+ ln -fs /tmp/etc/mtab etc/mtab
+
+ # have pl_rsysinit copy over appropriate etc & var directories into /tmp/etc/
+ # make /tmp/etc
+ echo "* renaming dirs in ./etc"
+ pushd etc
+ for dir in `find * -type d -prune | grep -v rc.d`; do
+ mv ${dir} ${dir}_o
+ ln -fs /tmp/etc/${dir} ${dir}
+ done
+ popd
+
+ echo "* renaming dirs in ./var"
+ # rename all top-level directories and put in a symlink to /tmp/var
+ pushd var
+ for dir in `find * -type d -prune`; do
+ mv ${dir} ${dir}_o
+ ln -fs /tmp/var/${dir} ${dir}
+ done
+ popd
+
+ # overwrite fstab to mount / as cramfs and /tmp as tmpfs
+ echo "* Overwriting etc/fstab to use cramfs and tmpfs"
+ rm -f ./etc/fstab
+ cat >./etc/fstab <<EOF
+/dev/ram0 / cramfs ro 0 0
+none /dev/pts devpts gid=5,mode=620 0 0
+none /proc proc defaults 0 0
+none /sys sysfs defaults 0 0
+EOF
+
+ pushd dev
+ rm -f console
+ mknod console c 5 1
+ #for i in 0 1 2 3 4 5 6 7 8; do rm -f ram${i} ; done
+ #for i in 0 1 2 3 4 5 6 7 8; do mknod ram${i} b 1 ${i} ; done
+ #ln -fs ram1 ram
+ #ln -fs ram0 ramdisk
+ popd
+
+ # update etc/inittab to start with pl_rsysinit
+ for file in etc/inittab etc/event.d/rcS etc/init/rcS.conf; do
+ [ -f $file ] && sed -i 's,pl_sysinit,pl_rsysinit,' $file