#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL

# set the flag to show color output
BOOTUP=color
# some parameters for color output.
[ -z "$SETCOLOR_SUCCESS" ] && SETCOLOR_SUCCESS="echo -en \\033[1;32m"
[ -z "$SETCOLOR_FAILURE" ] && SETCOLOR_FAILURE="echo -en \\033[1;31m"
[ -z "$SETCOLOR_WARNING" ] && SETCOLOR_WARNING="echo -en \\033[1;33m"
[ -z "$SETCOLOR_NORMAL"  ] && SETCOLOR_NORMAL="echo -en \\033[0;39m"

# Append the PATH in system.
sudo echo "export PATH=/opt/drbl/sbin:/opt/drbl/bin:\$PATH" >> /etc/profile
sudo echo "export PATH=/opt/drbl/sbin:/opt/drbl/bin:\$PATH" >> /etc/bash.bashrc
# Clean /etc/motd to avoid the following message is missing.
sudo echo -n "" > /etc/motd
# Force to remount /live_media as rw, since if it's usb disk, we can try to save clonezilla image. If it's CD, never mind.
sudo mount -o remount,rw /live_media
# Prepare the program.
sudo tar -xzf /live_media/opt_drbl.tgz -C /
# We need to know ocsroot.
. /opt/drbl/sbin/drbl-conf-functions
# Prepare default ocsroot.
if sudo mkdir -p /live_media/$ocsroot 2>/dev/null; then
  sudo mkdir -p `dirname $ocsroot`
  sudo ln -fs /live_media/$ocsroot $ocsroot
else
  # mkdir a mount point to be used later.
  sudo mkdir -p $ocsroot
fi
# Show prompt
echo "****************************************************************"
echo "To use clonezilla to save an image:"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "0. Run \"sudo su -\" to become root."
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "1. If your boot media is Read-Only, such as CD/DVD, you have to prepare another device, and mount it as $ocsroot."
echo "   Ex. If you want to use clonezilla to save /dev/hda, and put the image in /dev/hdb1. Then you have to mount /dev/hdb1 as $ocsroot by:"
echo "       mount /dev/hdb1 $ocsroot"
echo "   If your boot media is writable, such as USB pendrive, $ocsroote is already mounted in your boot media."
echo "2. Then run"
echo "       ocs-sr -x"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "3. When everyting is done, remember to use 'poweroff' or 'reboot' to do a normal poweroff/reboot procedure. Otherwise if the boot media you are using is writable device, such as USB pendrive, it will NOT boot next time!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "****************************************************************"
