summaryrefslogtreecommitdiffstats
path: root/rescue-Flash/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'rescue-Flash/scripts')
-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
7 files changed, 787 insertions, 0 deletions
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