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

# functions
set_localepurge(){
  # keep some locales.
  echo "Set nonepurge locales..."
  debconf-communicate -fnoninteractive localepurge > /dev/null <<EOF
set localepurge/dontbothernew false
set localepurge/mandelete true
set localepurge/none_selected false
set localepurge/nopurge $locale_to_keep
set localepurge/quickndirtycalc true
set localepurge/showfreedspace true
set localepurge/verbose true
EOF
  # apply it
  dpkg-reconfigure --unseen-only localepurge
  echo "The content of /etc/locale.nopurge:"
  cat /etc/locale.nopurge
} # end of set_localepurge

# set root passwd, I do not like root without passwd.
set_root_passwd() {
  echo "root:$root_passwd" | /usr/sbin/chpasswd
}

# put the clonezilla live script in rc2.d
move_ocs_live_startup_to_rc2.d() {
  mv -f /S[0-9][0-9]* /etc/rc2.d/; chown root.root /etc/rc2.d/S[0-9][0-9]*
}

# clean unnecessary backup file to save space
clean_unnecessary_backup_file_in_boot() {
  rm -f /boot/initrd*.bak
}

# since ssh services is on, and casper is known for the whole world, we have to block it.
block_all_clients_by_tcpwrapper() {
  echo 'ALL: ALL EXCEPT localhost' >> /etc/hosts.deny
}

# force to load fuse in live CD to avoid if sshfs is used, no /dev/fuse.
append_mod_in_etc_modules() {
  for imod in $mod_loaded_at_startup; do
    echo "$imod" >> /etc/modules
  done
}

#
clean_ocs_hook_files_in_chroot() {
  # all the file name including ocs and in the / in chroot will be removed.
  echo "Removing DRBL/Clonezilla live related hook files in chroot..."
  find ./ -maxdepth 1 -name "*ocs*" -type f -exec rm -fv {} \;
}
