summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2008-09-25 18:35:38 +0000
committerOlivier Blin <oblin@mandriva.com>2008-09-25 18:35:38 +0000
commit74f05c5a4d1010f388bb7f360464f32a5d75ef92 (patch)
tree30a31758b55ac66b708d803e8d158088afca20e8
parentfd8293630e710c3da9ce840c57384639c4289209 (diff)
downloaddrakx-74f05c5a4d1010f388bb7f360464f32a5d75ef92.tar
drakx-74f05c5a4d1010f388bb7f360464f32a5d75ef92.tar.gz
drakx-74f05c5a4d1010f388bb7f360464f32a5d75ef92.tar.bz2
drakx-74f05c5a4d1010f388bb7f360464f32a5d75ef92.tar.xz
drakx-74f05c5a4d1010f388bb7f360464f32a5d75ef92.zip
add image restoration scripts ("restore" command line parameter) from Classmate installer (Caio Begotti)
-rw-r--r--rescue/NEWS2
-rw-r--r--rescue/list.xml11
-rwxr-xr-xrescue/restore-image-lib.sh77
-rwxr-xr-xrescue/restore-image.sh140
-rwxr-xr-xrescue/tree/etc/rc.sysinit2
5 files changed, 231 insertions, 1 deletions
diff --git a/rescue/NEWS b/rescue/NEWS
index 32d3b014e..b0cc93b09 100644
--- a/rescue/NEWS
+++ b/rescue/NEWS
@@ -1,3 +1,5 @@
+- add image restoration scripts ("restore" command line parameter)
+
Version 1.10 - 25 April 2008, by Olivier "blino" Blin
- fix "Mounting other partitions from fstab" which use UUID=xxx
diff --git a/rescue/list.xml b/rescue/list.xml
index 697736152..5030abbb2 100644
--- a/rescue/list.xml
+++ b/rescue/list.xml
@@ -112,6 +112,8 @@
uniq
wget
+ awk clear dialog
+
<if ARCH="i.86|x86_64|ia64">
dmidecode
</if>
@@ -306,9 +308,16 @@
replication.conf
</to>
</from>
+<from dir=".">
+ <to dir="/usr/sbin">
+ restore-image.sh
+ </to>
+ <to dir="/usr/lib">
+ restore-image-lib.sh
+ </to>
+</from>
<if set="RESCUE_FLASH">
<from expand="binary">
- clear
dirname
losetup
mlabel
diff --git a/rescue/restore-image-lib.sh b/rescue/restore-image-lib.sh
new file mode 100755
index 000000000..a56ac27e8
--- /dev/null
+++ b/rescue/restore-image-lib.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+TITLE=" Classmate Installation "
+BACKTITLE="Mandriva - Intel"
+
+debug="/dev/null"
+
+function _msgbox()
+{
+ dialog --timeout 60 --backtitle "$BACKTITLE" --title "$TITLE" --msgbox \
+ "$1" 0 0
+
+ return $?
+}
+
+function _infobox()
+{
+ dialog --backtitle "$BACKTITLE" --title "$TITLE" --sleep 2 \
+ --infobox "$1" 0 0
+
+ return $?
+}
+
+function _yesno()
+{
+ dialog --backtitle "$BACKTITLE" --title "$TITLE" \
+ --yes-label "Yes" --no-label "No" --yesno "$1" 0 0
+
+ return $?
+}
+
+function _mount()
+{
+ mount $1 $2 > $debug 2>&1
+
+ return $?
+}
+
+function _umount()
+{
+ umount $1 > $debug 2>&1
+
+ return $?
+}
+
+function _bind()
+{
+ mount --bind $1 $2 > $debug 2>&1
+
+ return $?
+}
+
+function _eject()
+{
+ eject $1 > $debug 2>&1
+
+ return $?
+}
+
+function _shutdown()
+{
+ clear
+ sync
+ echo s > /proc/sysrq-trigger
+ echo o > /proc/sysrq-trigger
+ exit
+}
+
+function _reboot()
+{
+ clear
+ sync
+ echo s > /proc/sysrq-trigger
+ echo b > /proc/sysrq-trigger
+ exit
+}
+
diff --git a/rescue/restore-image.sh b/rescue/restore-image.sh
new file mode 100755
index 000000000..e22763782
--- /dev/null
+++ b/rescue/restore-image.sh
@@ -0,0 +1,140 @@
+#!/bin/bash
+if [ -r ./restore-image-lib.sh ]; then
+ . ./restore-image-lib.sh
+elif [ -r /usr/lib/restore-image-lib.sh ]; then
+ . /usr/lib/restore-image-lib.sh
+fi
+
+export PATH="/sbin:/bin:/usr/sbin:/usr/bin"
+
+images_dir="/ramdisk/live/media/images"
+images="$images_dir/list"
+image=""
+
+function image_list()
+{
+ list=$(cat $images | awk -F',' \
+ '{ print $1 " " $2 " " $4 }')
+
+ echo $list
+}
+
+function image_file()
+{
+ country="$1"
+
+ file=$(grep ^$country $images | awk -F',' '{ print $3 }')
+
+ echo $file
+}
+
+function welcome()
+{
+ while true; do
+ clear
+ msg="\n Welcome to Classmate OEM Installer\n\
+\nThe following images were found, select one:\n "
+ opcao=$(dialog --backtitle "$BACKTITLE" --title "$TITLE" \
+ --stdout --radiolist "$msg" 0 0 0 \
+ $(image_list))
+
+ if [ "$?" != "0" ]; then
+ _yesno "\nInterrupt installation?\n "
+ if [ "$?" = "0" ]; then
+ _shutdown
+ fi
+ else
+ if [ -z "$opcao" ]; then
+ continue
+ else
+ image=$(image_file $opcao)
+ break
+ fi
+ fi
+ done
+
+ # disable kernel messages in the console
+ echo "1 4 1 7" > /proc/sys/kernel/printk
+}
+
+function install_warning()
+{
+ clear
+ _yesno "\nWARNING: This process will erase all data in this machine, \
+do you want to continue?\n "
+ if [ "$?" != "0" ]; then
+ _shutdown
+ fi
+}
+
+function detect_root()
+{
+ dev=$(sed '/ramdisk\/live\/media/!d;s/[0-9] .*$//;s/^.*\///' /proc/mounts)
+ devices=$(grep "^ .*[^0-9]$" < /proc/partitions | grep -v ${dev} | awk '{ print $4,$3 }')
+
+ if [ ! -z ${dev} ]; then
+ opcao=$(dialog --backtitle "$BACKTITLE" --title "$TITLE" --stdout --menu 'Choose one of the detected devices to restore to (check the blocks size column first):' 8 50 0 $devices )
+ if [ "$?" != "0" ]; then
+ _yesno "\nInterrupt installation?\n "
+ if [ "$?" = "0" ]; then
+ _shutdown
+ fi
+ else
+ root=$opcao
+ fi
+
+ echo "$root"
+ else
+ _msgbox "\nError writing image: disk device not detected\n"
+ fi
+}
+
+function write_image()
+{
+ root=$(detect_root)
+ bzcat $images_dir/$image | dd of=/dev/$root bs=4096 > /tmp/backup.out 2>&1 &
+
+ sleep 3
+ pid=$(ps ax | grep 'dd of' | grep -v grep | awk '{ print $1 }')
+ total=1000
+
+ while [ true ]; do
+ ps | grep -q $pid
+ if [ $? -eq 0 ]; then
+ /bin/kill -SIGUSR1 $pid
+ unit=$(tail -n 1 /tmp/backup.out | \
+ cut -d'(' -f2 | cut -d')' -f1 |\
+ awk '{ print $2 }')
+
+ complete=$(tail -n 1 /tmp/backup.out | \
+ cut -d'(' -f2 | cut -d')' -f1 | \
+ awk '{ print $1 }' | cut -d'.' -f1)
+ if [ x"$unit" = x"GB" ]; then
+ complete=$((complete*1000))
+ fi
+ echo $((complete*100/total))
+ sleep 1
+ else
+ break
+ fi
+ done | dialog --backtitle "$BACKTITLE" --title "$TITLE" --gauge "\nWriting image..." 8 45
+
+ in=$(tail -n 3 /tmp/backup.out | grep 'in$' | cut -d' ' -f1)
+ out=$(tail -n 3 /tmp/backup.out | grep 'out$' | cut -d' ' -f1)
+
+ if [ x"$in" != x"$out" ]; then
+ _msgbox "\nError writing image!\n"
+ sleep 24h
+ fi
+}
+
+# installation steps
+welcome
+install_warning
+write_image
+
+# all done!
+_msgbox "\nInstallation process finished.\nPress ENTER to shutdown.\n "
+
+_shutdown
+
diff --git a/rescue/tree/etc/rc.sysinit b/rescue/tree/etc/rc.sysinit
index 26dae0a35..bf8ffa13e 100755
--- a/rescue/tree/etc/rc.sysinit
+++ b/rescue/tree/etc/rc.sysinit
@@ -64,6 +64,8 @@ elif grep -q rest_all /proc/cmdline; then
else
partimage_whole_disk -s $partimage_server rest_all $partimage_dir
fi
+elif grep -q restore /proc/cmdline; then
+ /usr/sbin/restore-image.sh
elif grep -q kamethod /proc/cmdline; then
echo "Welcome to Ka"
drvinst