#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL
# Program to create Clonezilla live.

# load config file
. /live-hook-dir/drbl.conf
. /live-hook-dir/ocs-live-hook.conf
# load functions
. /live-hook-dir/ocs-live-hook-functions 

#
apt-get update; apt-get -y dist-upgrade
apt-get -y install $PKG_FROM_DRBL_INSTALLED_IN_SYSTEM

# preset lo network setting
cat <<-NET_END > /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

NET_END

# Touch an empty /etc/fstab
touch /etc/fstab

# set root passwd, I do not like root without passwd.
set_root_passwd

# We have to create account, say "user", otherwise there is a problem when we put command in user's ~/.bash_profile. See ocs-live-hook-functions for more details.
preseed_autologin_account

#
append_start_clonezilla_in_user_bash_profile

# put the clonezilla live script in rcS.d
cp_ocs_live_startup_to_rcS.d

# for better security
turn_off_ssh_service

# some required modules at startup
append_mod_in_etc_modules

# we need real /sbin/start-stop-daemon
remove_cdebootstrap-helper-diverts

# Turn on number lock when booting
turn_on_numlock_in_booting

# Exclude live mount point in /etc/init.d/umountfs to avoid error messages when rebooting or halting.
exclude_umount_live_mnt_point_in_umountfs

# run localepurge
set_localepurge
localepurge

# Fix the bug about login prompt too early (Ref: https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/65230)
fix_ubuntu_upstart_tty1_6_distorted_if_necessary

#
append_framebuffer_modules_for_ubuntu_if_necessary

# Update the variable BUILD_SYSTEM in /etc/live.conf (This is special for live-initramfs, not for casper)
update_build_system_in_etc_live_conf

# Dirty hacking: rm files
if [ "$dirty_hacking_remove_files_for_ocs_live" = "yes" ]; then
  dirty_hacking_rm_files_for_ocs_live
fi

# Create a list of all packages:
dpkg --get-selections > /root/Clonezilla-live-packages.txt

# ///Note/// This should be the last one after any apt-get.
# clean unnecessary backup file to save space
clean_unnecessary_backup_file_in_boot

### THE END ###
# DO NOT PUT ANY SCRIPT AFTHER THIS!!!
# kill this program before creating squashfs filesystem.
rm -rf /live-hook-dir
