summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xrescue-Flash/build32
-rw-r--r--rescue-Flash/flash-rescue-gui.c274
-rwxr-xr-xrescue-Flash/scripts/backup_systemloop106
-rwxr-xr-xrescue-Flash/scripts/clear_systemloop85
-rw-r--r--rescue-Flash/scripts/rescue_common149
-rwxr-xr-xrescue-Flash/scripts/reset_rootpass100
-rwxr-xr-xrescue-Flash/scripts/reset_userpass111
-rwxr-xr-xrescue-Flash/scripts/restore_systemloop167
-rwxr-xr-xrescue-Flash/scripts/test_badblocks69
9 files changed, 1093 insertions, 0 deletions
diff --git a/rescue-Flash/build b/rescue-Flash/build
new file mode 100755
index 000000000..cc6ece4d1
--- /dev/null
+++ b/rescue-Flash/build
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+output_name="FLASHRESCUE"
+output_file="flashrescue.iso"
+
+rm -f $output
+
+echo -n "Gerando imagem ISO de $output_name: "
+
+cd root
+
+genisoimage -o ../$output_file \
+ -b i586/isolinux/isolinux.bin \
+ -c i586/isolinux/boot.cat \
+ -input-charset ISO-8859-1 \
+ -no-emul-boot \
+ -boot-load-size 4 \
+ -J -R -l \
+ -quiet \
+ -V $output_name \
+ -boot-info-table .
+
+if [ $? -eq 0 ]; then
+ output_size=$(ls -lah ../$output_file | awk '{ print $5 }')
+ echo "ok [$output_size]."
+ md5=$(md5sum ../$output_file | awk '{ print $1 }')
+ echo " md5: $md5"
+else
+ echo "erro."
+fi
+
+cd - > /dev/null
diff --git a/rescue-Flash/flash-rescue-gui.c b/rescue-Flash/flash-rescue-gui.c
new file mode 100644
index 000000000..f2e17d6a3
--- /dev/null
+++ b/rescue-Flash/flash-rescue-gui.c
@@ -0,0 +1,274 @@
+/*
+ * Guillaume Cottenceau (gc@mandrakesoft.com)
+ *
+ * Copyright 2001-2007 Mandrakesoft
+ *
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdlib.h>
+#include <strings.h>
+#define _USE_BSD
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/mount.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/unistd.h>
+#include <sys/select.h>
+
+#include "config-stage1.h"
+#include "frontend.h"
+#include "tools.h"
+
+#ifndef LINE_MAX
+#define LINE_MAX 2048
+#endif
+
+char * env[] = {
+ "PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sbin:/mnt/usr/sbin:/mnt/bin:/mnt/usr/bin",
+ "LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/lib:/mnt/usr/lib:/usr/X11R6/lib:/mnt/usr/X11R6/lib",
+ "HOME=/",
+ "TERM=linux",
+ "TERMINFO=/etc/terminfo",
+ NULL
+};
+
+/* pause() already exists and causes the invoking process to sleep
+ until a signal is received */
+static void PAUSE(void)
+{
+ unsigned char t;
+ fflush(stdout);
+ read(0, &t, 1);
+}
+
+/* this is duplicated from `init.c', don't edit here */
+static inline _syscall3(int, reboot, int, magic, int, magic2, int, flag);
+
+#define LOOP_CLR_FD 0x4C01
+
+void del_loop(char *device)
+{
+ int fd;
+ if ((fd = open(device, O_RDONLY, 0)) < 0) {
+ printf("del_loop open failed\n");
+ return;
+ }
+
+ if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
+ printf("del_loop ioctl failed");
+ return;
+ }
+
+ close(fd);
+}
+
+struct filesystem {
+ char * dev;
+ char * name;
+ char * fs;
+ int mounted;
+};
+
+void unmount_filesystems(void)
+{
+ struct filesystem fs[500];
+ int i, nb, fd, size, numfs = 0;
+ char *buf, *p;
+
+ printf("unmounting filesystems...\n");
+
+ fd = open("/proc/mounts", O_RDONLY, 0);
+ if (fd == -1) {
+ printf("ERROR: failed to open /proc/mounts");
+ sleep(2);
+ return;
+ }
+
+ buf = (char *) malloc(LINE_MAX);
+ if (buf == NULL) {
+ printf("ERROR: not enough memory");
+ sleep(2);
+ return;
+ }
+ bzero(buf, LINE_MAX);
+ size = read(fd, buf, LINE_MAX - 1);
+ close(fd);
+
+ p = buf;
+ while (*p) {
+
+ fs[numfs].mounted = 1;
+ fs[numfs].dev = p;
+ while (*p != ' ')
+ p++;
+
+ *p++ = '\0';
+ fs[numfs].name = p;
+ while (*p != ' ')
+ p++;
+
+ *p++ = '\0';
+ fs[numfs].fs = p;
+ while (*p != ' ')
+ p++;
+
+ *p++ = '\0';
+ while (*p != '\n')
+ p++;
+ p++;
+ if (strcmp(fs[numfs].name, "/") != 0)
+ /* skip if root, no need to take initrd root
+ in account */
+ numfs++;
+ }
+
+ /* multiple passes trying to umount everything */
+ do {
+ nb = 0;
+ for (i = 0; i < numfs; i++) {
+ if (fs[i].mounted && umount(fs[i].name) == 0) {
+ if (strncmp(fs[i].dev + sizeof("/dev/") - 1,
+ "loop", sizeof("loop") - 1) == 0)
+ del_loop(fs[i].dev);
+
+ printf("\t%s\n", fs[i].name);
+ fs[i].mounted = 0;
+ nb++;
+ }
+ }
+ } while (nb);
+
+ for (i = nb = 0; i < numfs; i++) {
+ if (fs[i].mounted) {
+ printf("\t%s umount failed\n", fs[i].name);
+ if (strcmp(fs[i].fs, "ext2") == 0)
+ /* don't count not-ext2 umount failed */
+ nb++;
+ }
+ }
+
+ if (nb) {
+ printf("failed to umount some filesystems\n");
+ while (1);
+ }
+}
+
+void probe_that_type(void) { }
+
+int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)))
+{
+ enum return_type results;
+
+ char rootpass[] = "Reset Root Password";
+ char userpass[] = "Reset User Password";
+ char factory[] = "Reset to Factory Defaults";
+ char backup[] = "Backup User Files";
+ char restore[] = "Restore User Files from Backup";
+ char badblocks[] = "Test Key for Badblocks";
+ char reboot_[] = "Reboot";
+
+ char * actions[] = { rootpass, userpass, factory, backup, restore,
+ badblocks, reboot_, NULL };
+ char * choice;
+
+ init_frontend("Welcome to " DISTRIB_NAME " Rescue ("
+ DISTRIB_VERSION ") " __DATE__ " " __TIME__);
+
+ do {
+ int pid;
+ char * binary = NULL;
+
+ choice = "";
+ results = ask_from_list("Please choose the desired action.",
+ actions, &choice);
+
+ if (ptr_begins_static_str(choice, rootpass)) {
+ binary = "/usr/bin/reset_rootpass";
+ }
+ if (ptr_begins_static_str(choice, userpass)) {
+ binary = "/usr/bin/reset_userpass";
+ }
+ if (ptr_begins_static_str(choice, factory)) {
+ binary = "/usr/bin/clear_systemloop";
+ }
+ if (ptr_begins_static_str(choice, backup)) {
+ binary = "/usr/bin/backup_systemloop";
+ }
+ if (ptr_begins_static_str(choice, restore)) {
+ binary = "/usr/bin/restore_systemloop";
+ }
+ if (ptr_begins_static_str(choice, badblocks)) {
+ binary = "/usr/bin/test_badblocks";
+ }
+ if (ptr_begins_static_str(choice, reboot_)) {
+ finish_frontend();
+ sync(); sync();
+ sleep(2);
+ unmount_filesystems();
+ sync(); sync();
+ printf("rebooting system\n");
+ sleep(2);
+ reboot(0xfee1dead, 672274793, 0x01234567);
+ }
+
+ if (binary) {
+
+ int wait_status;
+
+ suspend_to_console();
+ pid = fork();
+ if (pid == -1) { /* error forking */
+
+ printf("Can't fork()\n");
+ return 33;
+
+ } else if (pid == 0) { /* child */
+
+ char * child_argv[2];
+ child_argv[0] = binary;
+ child_argv[1] = NULL;
+
+ execve(child_argv[0], child_argv, env);
+ printf("Can't execute binary (%s)\n<press Enter>\n", binary);
+ PAUSE();
+
+ return 33;
+ } else { /* parent */
+
+ while (wait4(-1, &wait_status, 0, NULL) != pid)
+ ;
+
+ printf("<press Enter to return to Rescue GUI>");
+ PAUSE();
+ resume_from_suspend();
+ if (!WIFEXITED(wait_status) || WEXITSTATUS(wait_status) != 0) {
+ error_message("Program exited abnormally (return code %d).",
+ WEXITSTATUS(wait_status));
+ if (WIFSIGNALED(wait_status))
+ error_message("(received signal %d)",
+ WTERMSIG(wait_status));
+ }
+ }
+ }
+
+ } while (results == RETURN_OK);
+
+ finish_frontend();
+ printf("Bye.\n");
+
+ return 0;
+}
diff --git a/rescue-Flash/scripts/backup_systemloop b/rescue-Flash/scripts/backup_systemloop
new file mode 100755
index 000000000..65c3185e6
--- /dev/null
+++ b/rescue-Flash/scripts/backup_systemloop
@@ -0,0 +1,106 @@
+#!/bin/bash
+
+# import functions library
+source rescue_common
+
+tmpdir="/tmp/flash-rescue-root"
+rootdir="$tmpdir/pen"
+
+function prepare() {
+
+ mkdir -p $rootdir
+
+ if ! mount_usbroot $rootdir; then
+ return 1
+ fi
+
+ if [ x"$version" = x"1.0" ]; then
+ mkdir -p $tmpdir/shared
+ if ! mount_sharedroot $tmpdir/shared; then
+ return 1
+ fi
+ fi
+
+ if [ ! -d $dir ]; then
+ mkdir $dir
+ fi
+
+ return 0
+}
+
+function doit() {
+
+ clear
+ echo
+ echo -n 'Creating backup file. This can take some time: '
+
+ bzip2 -c $loop > $target 2> /tmp/rescue-backup.err &
+
+ sleep 2
+
+ while ps | grep -q bzip2; do
+ progress
+ done
+
+ sync
+
+ echo
+ echo
+
+ errsize=$(ls -la /tmp/rescue-backup.err | cut -d' ' -f5)
+ if [ $errsize -ne 0 ]; then
+ echo "Error compressing user files into $target"
+ return 1
+ else
+ echo 'Backup file created!'
+ fi
+
+ echo
+
+ return 0
+}
+
+function cleanup() {
+
+ if [ x"$version" = x"1.0" ]; then
+ umount $tmpdir/shared > /dev/null 2>&1
+ rmdir $tmpdir/shared
+ fi
+
+ umount $rootdir > /dev/null 2>&1
+ rmdir $rootdir $tmpdir 2> /dev/null
+
+ return 0
+}
+
+clear
+trap cleanup SIGINT
+
+version=""
+if ! insert_pendrive; then
+ exit 1
+fi
+
+if [ x"$version" = x"1.0" ]; then
+ dir="$tmpdir/shared/backup"
+ loop="$rootdir/loopbacks/system.loop"
+else
+ dir="$rootdir/backup"
+ loop="$rootdir/.loopbacks/system.loop"
+fi
+
+file="backup-$(date +%Y%m%d).bz2"
+target="$dir/$file"
+
+if ! prepare; then
+ cleanup
+ exit 1
+fi
+
+if ! doit; then
+ cleanup
+ exit 1
+fi
+
+cleanup
+exit 0
diff --git a/rescue-Flash/scripts/clear_systemloop b/rescue-Flash/scripts/clear_systemloop
new file mode 100755
index 000000000..159f22119
--- /dev/null
+++ b/rescue-Flash/scripts/clear_systemloop
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+# import functions library
+source rescue_common
+
+tmpdir="/tmp/flash-rescue-root"
+rootdir="$tmpdir/pen"
+
+function prepare() {
+
+ mkdir -p $rootdir
+
+ if ! mount_usbroot $rootdir; then
+ return 1
+ fi
+
+ return 0
+}
+
+function doit() {
+
+ clear
+ echo
+ echo "WARNING!"
+ echo
+ echo "Mandriva Flash will be reseted to factory defaults!"
+ echo -n "All user files, customizations and new packages installed "
+ echo "will be removed."
+ echo
+ echo -n "Do you want to continue? [N/y] "
+ read confirm
+
+ if [ x"$confirm" = x"y" -o x"$confirm" = x"Y" ]; then
+
+ if [ ! -f $loop ]; then
+ dd if=/dev/zero of=$loop bs=4000000 count=100
+ fi
+
+ /sbin/mkfs.ext2 -q -F $loop
+
+ echo
+ if [ $? -ne 0 ]; then
+ echo 'Error reseting device to factory defaults'
+ return 1
+ else
+ echo 'Mandriva Flash was restored to factory defaults!'
+ fi
+ fi
+
+ echo
+
+ return 0
+}
+
+function cleanup() {
+
+ umount $rootdir > /dev/null 2>&1
+ rmdir $rootdir $tmpdir 2> /dev/null
+}
+
+clear
+trap cleanup SIGINT
+
+version=""
+if ! insert_pendrive; then
+ exit 1
+fi
+
+if [ x"$version" = x"1.0" ]; then
+ loop="$rootdir/loopbacks/system.loop"
+else
+ loop="$rootdir/.loopbacks/system.loop"
+fi
+
+if ! prepare; then
+ cleanup
+ exit 1
+fi
+
+if ! doit; then
+ cleanup
+ exit 1
+fi
+
+cleanup
diff --git a/rescue-Flash/scripts/rescue_common b/rescue-Flash/scripts/rescue_common
new file mode 100644
index 000000000..61718d52c
--- /dev/null
+++ b/rescue-Flash/scripts/rescue_common
@@ -0,0 +1,149 @@
+#!/bin/bash
+
+function detect_version() {
+
+ _tmpdir="/tmp/$$"
+
+ mkdir -p $_tmpdir
+
+ nash --force > /dev/null 2>&1 <<EOF
+mount -t vfat LABEL=Share $_tmpdir
+EOF
+ if [ $? -eq 0 ]; then
+ version="1.0"
+ else
+ version="1.05"
+ fi
+
+ umount $_tmpdir 2> /dev/null
+ rmdir $_tmpdir 2> /dev/null
+}
+
+function check_vendor() {
+
+ # list of supported vendors/models
+
+ # mandriva flash 1.0 (france)
+ vendors[0]="13fe"
+ models[0]="1a00"
+ # mandriva flash 1.0 (brazil)
+ vendors[1]="0930"
+ models[1]="653e"
+ # mandriva flash 4GB (france)
+ vendors[2]="13fe"
+ models[2]="1d00"
+
+ rc=1
+
+ mount -t usbfs none /proc/bus/usb
+
+ i=0
+ while [ ! -z "${vendors[$i]}" ]; do
+
+ grep "P:" /proc/bus/usb/devices | grep -q \
+ "Vendor=${vendors[$i]} ProdID=${models[$i]}"
+ if [ $? -eq 0 ]; then
+ rc=0
+ break
+ fi
+
+ let i++
+ done
+
+ umount /proc/bus/usb
+
+ return $rc
+}
+
+function insert_pendrive() {
+
+ _tmpdir="/tmp/rescue-temp"
+ mkdir -p $_tmpdir
+
+ modprobe usb-storage > /dev/null 2>&1
+ modprobe vfat > /dev/null 2>&1
+
+ echo
+ echo -n 'Please insert your Mandriva Flash pen drive and press ENTER when ready: '
+ read READY
+ echo
+ echo -n 'Detecting pen drive: '
+
+ for ((i=0; $i <= 15 ; i++)); do
+ nash --force > /dev/null 2>&1 <<EOF
+mount -t vfat LABEL=MDVUSBROOT $_tmpdir
+EOF
+ if [ $? -ne 0 ]; then
+ echo -n '.'
+ sleep 1
+ else
+ echo -n ' found!'
+
+ if ! check_vendor; then
+ echo
+ echo "This rescue system only works with Mandriva Flash keys."
+ echo
+ umount $_tmpdir
+ rmdir $_tmpdir 2> /dev/null
+ return 1
+ fi
+
+ cat /proc/mounts | grep $_tmpdir | cut -d' ' -f1 | \
+ sed 's/[0-9]*$//g' > /tmp/rescue-device
+ umount $_tmpdir
+ rmdir $_tmpdir 2> /dev/null
+
+ detect_version
+
+ return 0
+ fi
+ done
+
+ rmdir $_tmpdir 2> /dev/null
+
+ echo
+ echo
+ echo "Couldn't detect Mandriva Flash pen drive!"
+ echo
+
+ return 1
+}
+
+function mount_usbroot() {
+
+ nash --force > /dev/null 2>&1 <<EOF
+mount -t vfat LABEL=MDVUSBROOT $1
+EOF
+ if [ $? -ne 0 ]; then
+ echo "Error mounting device labeled MDVUSBROOT"
+ return 1
+ fi
+
+ return 0
+}
+
+function mount_sharedroot() {
+
+ nash --force > /dev/null 2>&1 <<EOF
+mount -t vfat LABEL=Share $1
+EOF
+ if [ $? -ne 0 ]; then
+ echo "Error mounting device labeled Share"
+ return 1
+ fi
+
+ return 0
+}
+
+function progress() {
+
+ echo -ne '\b|'
+ usleep 100000
+ echo -ne '\b/'
+ usleep 100000
+ echo -ne '\b-'
+ usleep 100000
+ echo -ne '\b\\'
+ usleep 100000
+}
+
diff --git a/rescue-Flash/scripts/reset_rootpass b/rescue-Flash/scripts/reset_rootpass
new file mode 100755
index 000000000..c0a505f21
--- /dev/null
+++ b/rescue-Flash/scripts/reset_rootpass
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+# import functions library
+source rescue_common
+
+tmpdir="/tmp/flash-rescue-root"
+rootdir="$tmpdir/pen"
+
+function prepare() {
+
+ modprobe unionfs > /dev/null 2>&1
+ modprobe squashfs > /dev/null 2>&1
+ modprobe loop > /dev/null 2>&1
+
+ mkdir -p $rootdir
+ mkdir -p $tmpdir/squash
+ mkdir -p $tmpdir/user
+ mkdir -p $tmpdir/union
+
+ if ! mount_usbroot $rootdir; then
+ return 1
+ fi
+
+ mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo "Error mounting distrib.sqfs"
+ return 1
+ fi
+
+ mount -t ext2 -o loop $sys_loop $tmpdir/user > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo "Error mounting system.loop"
+ return 1
+ fi
+
+ mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \
+ none $tmpdir/union
+ if [ $? -ne 0 ]; then
+ echo "Error creating union of distrib.sqfs and system.loop"
+ return 1
+ fi
+
+ chroot $tmpdir/union /etc/init.d/keytable start &> /dev/null
+ chroot $tmpdir/union /usr/bin/unicode_start
+
+ return 0
+}
+
+function doit() {
+
+ clear
+ echo
+ chroot $tmpdir/union passwd root
+ echo
+ echo
+
+ return 0
+}
+
+function cleanup() {
+
+ chroot $tmpdir/union /usr/bin/unicode_stop
+
+ umount $tmpdir/union > /dev/null 2>&1
+ umount $tmpdir/user > /dev/null 2>&1
+ umount $tmpdir/squash > /dev/null 2>&1
+ umount $rootdir > /dev/null 2>&1
+
+ rmdir $tmpdir/union $tmpdir/user $tmpdir/squash 2> /dev/null
+ rmdir $rootdir $tmpdir 2> /dev/null
+}
+
+clear
+trap cleanup SIGINT
+
+version=""
+if ! insert_pendrive; then
+ exit 1
+fi
+
+if [ x"$version" = x"1.0" ]; then
+ sys_loop="$rootdir/loopbacks/system.loop"
+ sfs_loop="$rootdir/loopbacks/distrib.sqfs"
+else
+ sys_loop="$rootdir/.loopbacks/system.loop"
+ sfs_loop="$rootdir/.loopbacks/distrib.sqfs"
+fi
+
+if ! prepare; then
+ cleanup
+ exit 1
+fi
+
+if ! doit; then
+ cleanup
+ exit 1
+fi
+
+cleanup
+exit 0
diff --git a/rescue-Flash/scripts/reset_userpass b/rescue-Flash/scripts/reset_userpass
new file mode 100755
index 000000000..d34b629bf
--- /dev/null
+++ b/rescue-Flash/scripts/reset_userpass
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+# import functions library
+source rescue_common
+
+tmpdir="/tmp/flash-rescue-root"
+rootdir="$tmpdir/pen"
+
+function prepare() {
+
+ modprobe unionfs > /dev/null 2>&1
+ modprobe squashfs > /dev/null 2>&1
+ modprobe loop > /dev/null 2>&1
+
+ mkdir -p $rootdir
+ mkdir -p $tmpdir/squash
+ mkdir -p $tmpdir/user
+ mkdir -p $tmpdir/union
+
+ if ! mount_usbroot $rootdir; then
+ return 1
+ fi
+
+ mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo "Error mounting distrib.sqfs"
+ return 1
+ fi
+
+ mount -t ext2 -o loop $sys_loop $tmpdir/user > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo "Error mounting system.loop"
+ return 1
+ fi
+
+ mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \
+ none $tmpdir/union > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo "Error creating union of distrib.sqfs and system.loop"
+ return 1
+ fi
+
+ chroot $tmpdir/union /etc/init.d/keytable start &> /dev/null
+ chroot $tmpdir/union /usr/bin/unicode_start
+
+ return 0
+}
+
+function doit() {
+
+ username=$(tail -1 $tmpdir/union/etc/passwd | cut -d ':' -f1)
+
+ clear
+ echo
+ echo -n "What is your username? [$username] "
+ read name
+
+ if [ -z "$name" ]; then
+ name="$username"
+ fi
+
+ echo
+ echo
+ chroot $tmpdir/union passwd $name
+ echo
+ echo
+
+ return 0
+}
+
+function cleanup() {
+
+ chroot $tmpdir/union /usr/bin/unicode_stop
+
+ umount $tmpdir/union > /dev/null 2>&1
+ umount $tmpdir/user > /dev/null 2>&1
+ umount $tmpdir/squash > /dev/null 2>&1
+ umount $rootdir > /dev/null 2>&1
+
+ rmdir $tmpdir/union $tmpdir/user $tmpdir/squash 2> /dev/null
+ rmdir $rootdir $tmpdir 2> /dev/null
+}
+
+clear
+trap cleanup SIGINT
+
+version=""
+if ! insert_pendrive; then
+ exit 1
+fi
+
+if [ x"$version" = x"1.0" ]; then
+ sys_loop="$rootdir/loopbacks/system.loop"
+ sfs_loop="$rootdir/loopbacks/distrib.sqfs"
+else
+ sys_loop="$rootdir/.loopbacks/system.loop"
+ sfs_loop="$rootdir/.loopbacks/distrib.sqfs"
+fi
+
+if ! prepare; then
+ cleanup
+ exit 1
+fi
+
+if ! doit; then
+ cleanup
+ exit 1
+fi
+
+cleanup
+exit 0
diff --git a/rescue-Flash/scripts/restore_systemloop b/rescue-Flash/scripts/restore_systemloop
new file mode 100755
index 000000000..39c56e030
--- /dev/null
+++ b/rescue-Flash/scripts/restore_systemloop
@@ -0,0 +1,167 @@
+#!/bin/bash
+
+# import functions library
+source rescue_common
+
+tmpdir="/tmp/flash-rescue-root"
+rootdir="$tmpdir/pen"
+
+function prepare() {
+
+ mkdir -p $rootdir
+
+ if ! mount_usbroot $rootdir; then
+ return 1
+ fi
+
+ if [ x"$version" = x"1.0" ]; then
+ mkdir -p $tmpdir/shared
+ if ! mount_sharedroot $tmpdir/shared; then
+ return 1
+ fi
+ fi
+
+ return 0
+}
+
+function doit() {
+
+ if [ ! -d $dir ]; then
+ echo
+ echo "Can't find a backup directory in the Share partition"
+ echo
+ return 0
+ fi
+
+ cd $dir
+ i=1
+ for file in $(ls -c1 backup-*.bz2 2> /dev/null | sort -r | head -10); do
+ files[$i]="$file"
+ let i++
+ done
+ cd - > /dev/null
+
+ if [ $i -eq 1 ]; then
+ echo
+ echo 'No backup files found!'
+ echo
+ return 0
+ fi
+
+ while [ true ]; do
+
+ clear
+ echo
+ echo "The following backup files were found:"
+ echo
+
+ i=1
+ while [ -n "${files[$i]}" ]; do
+ echo "[$i] ${files[$i]}"
+ let i++
+ done
+ let i--
+ echo
+ echo '[0] Cancel / Return to main menu'
+
+ echo
+ echo 'Select from the list above, the file that you want to restore.'
+ echo 'The most recent files come first in the list.'
+ echo
+ echo -n "What backup file do you want to restore? [1] "
+ read option
+
+ if [ -z "$option" ]; then
+ option=1
+ fi
+ if [ x"$option" = x"0" ]; then
+ return 0
+ fi
+
+ if [ ! -f $dir/${files[$option]} ]; then
+ echo
+ echo "Error reading backup file ${files[$option]}!"
+ echo
+ echo -n 'Do you want to restore another backup file? [N/y] '
+ read confirm
+
+ if [ x"$confirm" = x"y" -o x"$confirm" = x"Y" ]; then
+ continue
+ else
+ return 0
+ fi
+ else
+
+ echo
+ echo -n 'Restoring backup file. This can take some time: '
+
+ bunzip2 -c $dir/${files[$option]} > $loop \
+ 2> /tmp/rescue-backup.err &
+
+ sleep 2
+
+ while ps | grep -q bunzip2; do
+ progress
+ done
+
+ sync
+ echo
+ echo
+
+ errsize=$(ls -la /tmp/rescue-backup.err | cut -d' ' -f5)
+ if [ $errsize -ne 0 ]; then
+ echo 'Error restoring user files!'
+ echo
+ return 1
+ else
+ echo 'Backup file restored!'
+ echo
+ break
+ fi
+ fi
+ done
+
+ return 0
+}
+
+function cleanup() {
+
+ if [ x"$version" = x"1.0" ]; then
+ umount $tmpdir/shared > /dev/null 2>&1
+ rmdir $tmpdir/shared 2> /dev/null
+ fi
+
+ umount $rootdir > /dev/null 2>&1
+ rmdir $rootdir $tmpdir 2> /dev/null
+
+ return 0
+}
+
+clear
+trap cleanup SIGINT
+
+version=""
+if ! insert_pendrive; then
+ exit 1
+fi
+
+if [ x"$version" = x"1.0" ]; then
+ dir="$tmpdir/shared/backup"
+ loop="$rootdir/loopbacks/system.loop"
+else
+ dir="$rootdir/backup"
+ loop="$rootdir/.loopbacks/system.loop"
+fi
+
+if ! prepare; then
+ cleanup
+ exit 1
+fi
+
+if ! doit; then
+ cleanup
+ exit 1
+fi
+
+cleanup
+exit 0
diff --git a/rescue-Flash/scripts/test_badblocks b/rescue-Flash/scripts/test_badblocks
new file mode 100755
index 000000000..3fb1f34d8
--- /dev/null
+++ b/rescue-Flash/scripts/test_badblocks
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+# import functions library
+source rescue_common
+
+tmpdir="/tmp/flash-rescue-root"
+rootdir="$tmpdir/pen"
+
+function prepare() {
+
+ return 0
+}
+
+function doit() {
+
+ clear
+ echo
+ echo "WARNING!"
+ echo
+ echo "Searching for bad blocks in Mandriva Flash is a slow process."
+ echo
+ echo -n "Do you want to continue? [N/y] "
+ read confirm
+
+ echo
+ echo
+
+ device=$(cat /tmp/rescue-device)
+
+ if [ x"$confirm" = x"y" -o x"$confirm" = x"Y" ]; then
+
+ /sbin/badblocks -n -v -s ${device}1
+ if [ x"$version" = x"1.0" ]; then
+ /sbin/badblocks -n -v -s ${device}2
+ fi
+ fi
+
+ echo
+ echo 'Bad blocks scan completed!'
+ echo
+
+ return 0
+}
+
+function cleanup() {
+
+ umount $rootdir > /dev/null 2>&1
+ rmdir $rootdir $tmpdir 2> /dev/null
+}
+
+clear
+trap cleanup SIGINT
+
+version=""
+if ! insert_pendrive; then
+ exit 1
+fi
+
+if ! prepare; then
+ cleanup
+ exit 1
+fi
+
+if ! doit; then
+ cleanup
+ exit 1
+fi
+
+cleanup