From 5bf0ea82a312b21ed600c615f75953efcd203363 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Thu, 5 Jul 2007 13:55:45 +0000 Subject: move rescue-Flash/scripts as rescue/Flash/scripts --- rescue/Flash/scripts/reset_userpass | 111 ++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100755 rescue/Flash/scripts/reset_userpass (limited to 'rescue/Flash/scripts/reset_userpass') 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 -- cgit v1.2.1