#!/bin/sh
# Author: Tianyukai <tianyukai068@pingan.com.cn>
# License: GPL
# Ref: http://sourceforge.net/forum/forum.php?thread_id=1759263&forum_id=394751
# In this example, it will allow your user to use clonezilla live to choose
# (1) backup the image of /dev/hda1 (or /dev/sda1) to /dev/hda5 (or /dev/sda5)
# (2) restore image in /dev/hda5 (or /dev/sda5) to /dev/hda1 (or /dev/sda1)
# When this script is ready, you can run
# ocs-iso -g en_US.UTF-8 -k NONE -s -m ./custom-ocs
# to create the iso file for CD/DVD. or
# ocs-live-dev -g en_US.UTF-8 -k NONE -s -c -m ./custom-ocs
# to create the zip file for USB flash drive.
# Begin of the scripts:
# Load DRBL setting and functions
# Load language file
# 1. Mount the clonezilla image home.
# Types: local_dev, ssh_server, samba_server, nfs_server
. /usr/share/drbl/sbin/drbl-conf-functions
. /etc/drbl/drbl-ocs.conf
. /usr/share/drbl/sbin/ocs-functions
. /etc/ocs/ocs-live.conf
# Load language file
ask_and_load_lang_set en_US.UTF-8
# 1. Mount the clonezilla image home.
# Types: local_dev, ssh_server, samba_server, nfs_server
sshpass -p PaCloud!@# ssh root@30.138.250.65 -o StrictHostKeyChecking=no 'exit'
sshfs -o ssh_command='sshpass -p PaCloud!@# ssh' -o cache=yes,allow_other root@30.138.250.65:/home/partimag /home/partimag
#sshfs -o ssh_command='sshpass -p PaCloud!@# ssh' root@30.138.250.65:/home/partimag /home/partimag
if [ "$?" -ne "0" ]
then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "Fail to find the Clonezilla image home /home/partimag!"
echo "Program terminated!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
#sed -i '6703i ocs-lvm2-stop' /usr/share/drbl/sbin/ocs-functions
SYSTEMNAME=`hostname`
Hdisk=`cat /proc/cmdline|sed 's/hdisk=/:/'|gawk -F: '{print $3}'|sed 's/\"//g'`
Passwd=`cat /proc/cmdline|sed 's/passwd=/:/'|gawk -F: '{print $3}'|cut -d" " -f1`
HW_sn=$(dmidecode -s system-serial-number 2>/dev/null | awk '/^[^#]/ { print $1 }')
IPADDR=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"|sed -n 1p`
cat /proc/cmdline|grep -o restore
if [ $? -eq "0" ]
then
sed -i '6703i ocs-lvm2-stop' /usr/share/drbl/sbin/ocs-functions
Title="Hard disk partition restore"
restore_version=`cat /proc/cmdline|sed 's/restore_version=/:/'|gawk -F: '{print $3}'|cut -d" " -f1`
#echo "$Passwd"|/usr/sbin/ocs-sr -g auto -e1 auto -e2 -t -r -j2 -k -p cmd restoreparts $restore_version sda1 sda2 sda3 sda4
echo "$Passwd"|/usr/sbin/ocs-sr -g auto -e1 auto -e2 -t -r -j2 -k -p cmd restoreparts $restore_version $Hdisk
if [ "$?" -eq "0" ]
then
result="normal"
curl -H "Content-Type: application/json" -X POST -d "{\"Sn\":\"$HW_sn\",\"IpAddr\":\"$IPADDR\",\"HostName\":\"$SYSTEMNAME\",\"Title\":\"$Title\",\"Status\":\"$result\",\"IsBackup\":\"Default\",\"BackupName\":\"Default\",\"IsRestory\":\"Yes\",\"RestoryName\":\"$restore_version\",\"Passwd\":\"$Passwd\"}" http://osinstall.com:8083/api/osinstall/v1/device/backupRestory
else
result="failed"
curl -H "Content-Type: application/json" -X POST -d "{\"Sn\":\"$HW_sn\",\"IpAddr\":\"$IPADDR\",\"HostName\":\"$SYSTEMNAME\",\"Title\":\"$Title\",\"Status\":\"$result\",\"IsBackup\":\"Default\",\"BackupName\":\"Default\",\"IsRestory\":\"Yes\",\"RestoryName\":\"$restore_version\",\"Passwd\":\"$Passwd\"}" http://osinstall.com:8083/api/osinstall/v1/device/backupRestory
fi
fi
cat /proc/cmdline|grep -o backup
if [ $? -eq "0" ]
then
Title="Hard disk partition backup"
Function=`cat /proc/cmdline|sed 's/function=/:/'|gawk -F: '{print $3}'|cut -d" " -f1`
if [ -z $Function ]
then
echo "function not set..."
exit
fi
FILENAME=`date +%Y-%m-%d`-$Function-img
#echo "$Passwd
#$Passwd"|/usr/sbin/ocs-sr -q2 -j2 -z1p -i 4096 -sfsck -enc -p cmd saveparts $FILENAME sda1 sda2 sda3 sda4
echo "$Passwd
$Passwd"|/usr/sbin/ocs-sr -q2 -j2 -z1p -i 4096 -sfsck -enc -p cmd saveparts $FILENAME $Hdisk
if [ "$?" -eq "0" ]
then
result="normal"
curl -H "Content-Type: application/json" -X POST -d "{\"Sn\":\"$HW_sn\",\"IpAddr\":\"$IPADDR\",\"HostName\":\"$SYSTEMNAME\",\"Title\":\"$Title\",\"Status\":\"$result\",\"IsBackup\":\"Yes\",\"BackupName\":\"$FILENAME\",\"IsRestory\":\"Default\",\"RestoryName\":\"Default\",\"Passwd\":\"$Passwd\"}" http://osinstall.com:8083/api/osinstall/v1/device/backupRestory
else
result="failed"
curl -H "Content-Type: application/json" -X POST -d "{\"Sn\":\"$HW_sn\",\"IpAddr\":\"$IPADDR\",\"HostName\":\"$SYSTEMNAME\",\"Title\":\"$Title\",\"Status\":\"$result\",\"IsBackup\":\"Yes\",\"BackupName\":\"$FILENAME\",\"IsRestory\":\"Default\",\"RestoryName\":\"Default\",\"Passwd\":\"$Passwd\"}" http://osinstall.com:8083/api/osinstall/v1/device/backupRestory
fi
fi