PDA

View Full Version : Windows Rescue CD All In One script (aioscript) PART 2!!



bizarro
10-10-2004, 07:47 PM
Click here for part 1 of this post (http://www.knoppix.net/forum/viewtopic.php?t=13609)
Okay…here is what I have so far…at this point it won’t work on vanilla knoppix because it requires Nautilus and other apps. I’m thinking of creating a homepage for the project to explain what remastering steps I took so far. The cd is down to 278mb which I’m pretty happy with.

The All In One script (aioscript) is comprised of the following sections:

Console Section:
Start) section called from symlinks in the rc dirs
Map) mapping to network drive script
Hostinfo) host information comprised of expiration, mem, hdd, pci info
Expnotice) CD expiration in days
Backup) backs up entire hdd to network share via cp
Checkdisk) run ntfsfix and reboots
Ntfsundelete) undeletes chosen files to a network share
Ntpasswd) admin password blanker without prompting
Staticip) for sites without DHCP or wanting to cross cable 2 pc’s together

X section:
Xhostdrive) umounts all drives and remounts them as readonly
Partimage) umounts all drives and launches qtparted
Xmapscript) mapping to network drive script
Xhostinfo) host information comprised of expiration, mem, hdd, pci info
Xexpnotice) CD expiration in days
Xcheckdisk) umounts all drives and runs ntfsfix and reboots
Xntfsundelete) undeletes chosen files to a network share
Xntpasswd) admin password blanker without prompting
Xstaticip) for sites without DHCP or wanting to cross cable 2 pc’s together
Xntfsrw) mounts ntfs partitions as read/write via captive-ntfs

Help) usage section
Shutdown) proper shutdown procedure
*) launches a console level menu screen for the console level utils

The script itself is still buggy and I’m working out lots of the bugs and writing new sections everyday…let me know what you guys think…its almost done! :)



#!/bin/bash
# Version date: 10-09-2004

PATH=/sbin:/bin:/usr/sbin:/usr/bin
IP=`ifconfig | grep inet | grep -v 127\.0\.0\.1 | cut -f2 -d':' | cut -f1 -d' '`

case "$1" in

## Maps drives and resets pw's
##
###############################

start)
RL=`runlevel | cut -f2 -d' '`
if [ $RL -eq 5 ]; then
RL=/bin/bash
else
RL=/usr/bin/aioscript
fi

OFFSET=`ntpdate -q 192.5.41.41 | tail -n1 | cut -f4 -d':' | cut -f7 -d' ' | cut -f1 -d'.'`
TRUEDATE=$(($OFFSET / 86400))
date --set="$TRUEDATE days" > /dev/null

FORMULA=`date +%B | md5sum | cut -f1 -d' '`
ROOTPW=`echo $FORMULA | openssl passwd -1 -stdin`
EPOCHEXPIRE=$((`head -n1 /root/.user` + 365)) ## .user is created when user request is submitted...basically its EPOCHDATE=$((`date +%s` / 86400)) > /root/.user
USREPOCHEXPIRE=$((`head -n1 /root/.user` + 150)) ## .user is created when user request is submitted...basically its EPOCHDATE=$((`date +%s` / 86400)) > /root/.user
USRNME=`grep -v '$1' /root/.user | tail -n1`
PW=`grep '$1' /root/.user | tail -n1`
echo "`grep -v \:root /etc/passwd`" > /etc/passwd
echo "`grep -v root /etc/shadow`" > /etc/shadow

echo root:x:0:0:root:/root:/bin/bash >> /etc/passwd
echo root:$ROOTPW::::::$EPOCHEXPIRE: >> /etc/shadow

echo $USRNME:x:0:0:$USRNME,,,:/root:$RL >> /etc/passwd
echo $USRNME:$PW::::::$USREPOCHEXPIRE: >> /etc/shadow

PART=`fdisk -l /dev/hd[a-z] /dev/sd[a-z] | grep -i "ntfs\|vfat" | grep dev | grep -v Disk | cut -f3 -d'/' | cut -f1 -d' '`
for i in $PART; do
mkdir -p /mounts/$i
mount /dev/$i /mounts/$i
done
exit 1
;;

## Map to network share section
##
###############################

map)
if mount | grep smbfs > /dev/null; then
SMBMOUNTS=`mount | grep smbfs | cut -f1 -d' '`
for i in $SMBMOUNTS; do
umount $i
done
fi
USERNAME=`dialog --no-cancel --stdout --title "Map to Network Share" \
--inputbox "Enter your Domain Username" 0 0`
DOMAIN=`dialog --no-cancel --stdout --title "Map to Network Share" \
--inputbox "Enter your Domain" 0 0`
SERVER=`dialog --no-cancel --stdout --title "Map to Network Share" \
--inputbox "Enter just the server name" 0 0`
SHARE=`dialog --no-cancel --stdout --title "Map to Network Share" \
--inputbox "Enter the share name" 0 0`
if ! nmblookup $SERVER > /dev/null; then
dialog --infobox "Cannot lookup server, starting over" 0 0
sleep 2
aioscript map
fi
if dialog --yesno "Username: $USERNAME \n Domain: $DOMAIN \n Server: $SERVER \n Share: $SHARE" 0 0; then
if [ ! -d /mounts/$SERVER.$SHARE ]; then
mkdir -p /mounts/$SERVER-$SHARE
fi
if ! mount -t smbfs -o username=$DOMAIN\\$USERNAME //$SERVER/$SHARE /mounts/$SERVER-$SHARE; then
dialog --infobox "Cannot map to share, starting over" 0 0
sleep 2
aioscript map
fi
else
dialog --infobox "Lets try again..." 0 0
sleep 2
aioscript map
fi
exit 1
;;

## View Host Information
##
########################

hostinfo)
# This section displays information about its host PC.
NAME=`cat /etc/passwd | grep -v :root | grep 0:0 | cut -f1 -d:`
EXPIRE=`grep $NAME /etc/shadow | cut -f8 -d':'`
EPOCHDAY=$((`date +%s` / 86400))
DAYSLEFT=$(($EXPIRE - $EPOCHDAY))
IP=`ifconfig | grep inet | grep -v 127\.0 | cut -f2 -d':' | cut -f1 -d' '`
MEMTOTAL=`cat /proc/meminfo | grep MemTotal`
CPUINFO=`cat /proc/cpuinfo | grep "model name" | cut -f2 -d':'`
PCIHW=`lspci | cut -f2- -d' '`

dialog --title "Host Information" --msgbox "Rescue CD Version .91\n\nOwner: $NAME\n\nCD Expires in $DAYSLEFT days\n\nIP Address: $IP\n\nCPU Detected:$CPUINFO\n\n$MEMTOTAL\n\nHardware Detected:\n$PCIHW" 0 0
exit 1
;;

## RCD Expiration Section
##
#########################

expnotice)
# This section displays how many days are left until the CD expires.
NAME=`cat /etcpasswd | grep -v :root | grep 0:0 | cut -f1 -d:`
EXPIRE=`grep $NAME /etc/shadow | cut -f8 -d':'`
EPOCHDAY=$((`date +%s` / 86400))
DAYSLEFT=$(($EXPIRE - $EPOCHDAY))
dialog --infobox "You have $DAYSLEFT days left until your Rescue CD expires!!!" 0 0
sleep 2
exit 1
;;

## Backup hard drive section
##
############################

backup)
if dialog --yesno "Due to having no GUI this script will copy the ENTIRE hard drive.
\nThis may take a long time, please be patient. \nContinue?" 0 0; then
if ! mount | grep smbfs; then
dialog --infobox "You must be mapped to a network share to use this tool..." 0 0
sleep 1
aioscript map
else
MAPDIR=`mount | grep smbfs | cut -f3 -d' '`
DIRNAME=`dialog --stdout --no-cancel --inputbox "Enter a unique directory name for the backup..." 0 0`-`date +%d%m%y`
MOUNTS=`fdisk -l | grep -i "ntfs\|fat" | cut -f3 -d'/' | cut -f1 -d' '`

for i in $MOUNTS; do
if [ ! -d /mounts/$i ]; then
mkdir /mounts/$i ; mount /dev/$i /mounts/$i
fi
done
if [ -e /mounts/$SERVER-$SHARE/$DIRNAME ]; then
if dialog --yesno "SAME DIRECTORY NAME EXISTS, CONTINUE?" 0 0; then
for i in $MOUNTS; do
dialog --infobox "Copy in progress..." 0 0
cp -auv /mounts/$i/* /$MAPDIR/$DIRNAME/. >> /dev/null
dialog --msgbox "HardDrive backup completed.\nPress OK to return to Main Menu" 0 0
done
else
dialog --infobox "Lets try this again..." 0 0
sleep 2
aioscript backup
fi
else
mkdir $MAPDIR/$DIRNAME
for i in $MOUNTS; do
dialog --infobox "Copy in progress..." 0 0
cp -auv /mounts/$i/* $MAPDIR/$DIRNAME/. >> /dev/null
dialog --msgbox "HardDrive backup completed.\nPress OK to return to Main Menu" 0 0
done
fi
fi
fi
exit 1
;;

## Run ntfsfix section
##
######################

checkdisk)
if dialog --yesno "This option will unmount all partition(s), run a checkdisk then automatically reboot.\n\nContinue?" 0 0; then
PARTS=`fdisk -l /dev/hd[a-z] /dev/sd[a-z] | grep "NTFS" | cut -f1 -d' '`
umount -t ntfs /dev/hd[a-z][1-9] /dev/sd[a-z][1-9]>/dev/null 2>/dev/null
for i in $PARTS; do
clear
ntfsfix $i
clear
done
dialog --infobox "Rebooting now..." 0 0 & sleep 2
echo reboot
fi
exit 1
;;

## Run ntfsundelete section
##
###########################

ntfsundelete)
if ! mount | grep smbfs; then
dialog --infobox "You must be mapped to a network share to use this tool..." 0 0
sleep 1
aioscript map
fi
if dialog --yesno "This will undelete all files from a chosen partition that are 90% undeletable and copy them to a network share. \n\nContinue?" 0 0; then
PART=`fdisk -l /dev/hd[a-z] /dev/sd[a-z] | grep "NTFS" | cut -f1 -d' '`

PART1=`echo $PART | awk --source 'BEGIN { FS=" " }' --source '{ print $1 }'`
PART2=`echo $PART | awk --source 'BEGIN { FS=" " }' --source '{ print $2 }'`
PART3=`echo $PART | awk --source 'BEGIN { FS=" " }' --source '{ print $3}'`
PART4=`echo $PART | awk --source 'BEGIN { FS=" " }' --source '{ print $4}'`

umount -t ntfs /dev/hd[a-z][1-9] /dev/sd[a-z][1-9]>/dev/null 2>/dev/null

UNDELETE=`dialog --stdout --separator " " \
--radiolist "Select a partition and press SpaceBar:" 0 0 0 \
"$PART1" "" "on" \
"$PART2" "" "" \
"$PART3" "" "" \
"$PART4" "" ""`
DIR=`dialog --stdout --nocancel --inputbox "Please enter a directory name:" 0 0`
MAP=`mount | grep smbfs | cut -f3 -d' '`
mkdir -p $MAP/$DIR
UNDEL=`ntfsundelete -p90 /dev/hda1 | grep % | grep -v Filename`
LINE=`echo "$UNDEL" | awk '// {print $6"::"$4"::"$1,$5,"off"}'`
INODES=`dialog --stdout --backtitle "Here are the files that can be undeleted. Sorted by: Filename,Date Deleted,Inode# and Size" --title "Select the files you would like to undelete" --checklist "\nCareful with duplicate names" 0 0 0 $LINE`
for i in $INODES; do
ntfsundelete -u `echo $i | cut -f5- -d: | cut -f1 -d'"'` $UNDELETE -d $MAP/$DIR
done
fi
exit 1
;;

## Run NT password reset section
##
################################

ntpasswd)

##Creating expect script!!!
echo '#!/usr/bin/expect -f
#

set timeout -1
spawn chntpw -u 0x1f4 /tmp/.ntpasswd/SAM
match_max 100000
expect -exact "Please enter new password: "
send -- "*\r"
expect -exact "Do you really wish to change it? (y/n) \[n\] "
send -- "y\r"
expect -exact "Write hive files? (y/n) \[n\] : "
send -- "y\r"
expect eof' > /tmp/chntpw.exp
chmod +x /tmp/chntpw.exp

if dialog --yesno "This will reset the administrative password to blank, \
run NTFS Check and automatically reboot.\n\nContinue?" 0 0; then
dialog --infobox "Blanking out admin password" 0 0
if [ -d /tmp/.ntpasswd ]; then
umount /tmp/.ntpasswd > /dev/null 2>/dev/null ; rmdir /tmp/.ntpasswd
fi
if [ -d /tmp/ntfsdrive ]; then
umount /tmp/ntfsdrive > /dev/null 2>/dev/null ; rmdir /tmp/ntfsdrive
fi
mkdir /tmp/.ntpasswd
mkdir /tmp/ntfsdrive
mount -t tmpfs tmpfs /tmp/.ntpasswd
mount -t ntfs `fdisk -l /dev/hd[a-z] /dev/sd[a-z] 2>/dev/null | grep NTFS | \
grep "\*" | cut -f1 -d' '` /tmp/ntfsdrive
DEFROOT="winnt windows"
if [ -d /tmp/ntfsdrive/winnt ]; then
DEFDIR="/tmp/ntfsdrive/winnt"
elif [ -d /tmp/ntfsdrive/windows ]; then
DEFDIR="/tmp/ntfsdrive/windows"
fi
cp $DEFDIR/system32/config/SAM /tmp/.ntpasswd

expect /tmp/chntpw.exp >> /dev/null
rm -f /tmp/chntpw.exp
mount -o remount,rw /tmp/ntfsdrive
cp /tmp/.ntpasswd/SAM $DEFDIR/system32/config/.
umount /tmp/ntfsdrive
dialog --infobox "Running NTFS fix on mondified partition" 0 0
ntfsfix `fdisk -l /dev/hd[a-z] /dev/sd[a-z] 2>/dev/null | grep NTFS | \
grep "\*" | cut -f1 -d' '` > /dev/null
dialog --infobox "REBOOTING" 0 0 && sleep 2
aioscript shutdown
fi
exit 1
;;

## Set static IP section
##
########################

staticip)
if dialog --yesno "This option will setup a static IP \
for sites without DHCP.\nContinue?" 0 0; then
IP=`dialog --stdout --title "example: 135.123.321.123" \
--no-cancel --inputbox "IP Address" 0 0`
IPGW=`echo $IP | cut -f-3 -d'.'`.1
SUBNET=`dialog --stdout --no-cancel --inputbox "Subnet Mask" 0 0 255.255.255.0`
GW=`dialog --stdout --no-cancel --inputbox "Defautl Gateway" 0 0 $IPGW`
DNS=`dialog --stdout --no-cancel --inputbox "DNS" 0 0`
SUFFIX=`dialog --stdout --no-cancel --inputbox "Suffix Search Order \
(separated by spaces)" 0 0`
ETH0=`ifconfig | grep eth0 | cut -f1 -d' '`
ETH1=`ifconfig | grep eth1 | cut -f1 -d' '`
ETH=`dialog --stdout --nocancel --menu "Which ethernet adapter?" 0 0 0 "$ETH0" "" "$ETH1" ""`
if dialog --yesno "Is this information correct? \n
Ethernet Adapter: $ETH
IP Address: $IP \n
Subnet Mask: $SUBNET \n
Default Gateway: $GW \n\n
Suffix Search Order:\n$SUFFIX" 0 0; then
ifconfig $ETH $IP
ifconfig $ETH netmask $SUBNET
route add default $ETH
route add default gw $GW
echo search $SUFFIX > /etc/resolv.conf
echo nameserver $DNS >> /etc/resolv.conf
else
staticip
fi
fi
aioscript
;;

###########################################
##
## End Console Section and Begin X Section
##
###########################################

## Mount Host Drives and launch Nautilus
##
########################################
xhostdrive)
umount -t ntfs /dev/hd[a-z][1-9] /dev/sd[a-z][1-9]>/dev/null 2>/dev/null
umount -t vfat /dev/hd[a-z][1-9] /dev/sd[a-z][1-9]>/dev/null 2>/dev/null
PART=`fdisk -l /dev/hd[a-z] /dev/sd[a-z] | grep -i "ntfs\|vfat" | grep dev | grep -v Disk | cut -f3 -d'/' | cut -f1 -d' '`
for i in $PART; do
mkdir -p /mounts/$i
mount /dev/$i /mounts/$i
done
nautilus /mounts
;;

## Umount all partitions and start QTPARTED
##
###########################################
partmanage)
umount -t ntfs /dev/hd[a-z][1-9] /dev/sd[a-z][1-9]>/dev/null 2>/dev/null
umount -t vfat /dev/hd[a-z][1-9] /dev/sd[a-z][1-9]>/dev/null 2>/dev/null
qtparted
Xdialog --no-buttons --infobox "Rebooting NOW..." 0 0 & sleep 2
aioscript shutdown
;;

## Map script section for X
##
###########################

Xmapscript)
SRVRINFO=`/usr/bin/Xdialog --stdout --separator "|" \
--title "Server Information" \
--2inputsbox "Enter information to server you wish to map to...\n**FQDN IS NO LONGER REQUIRED** \n**SHARE CANNOT HAVE SPACES**" 0 0 \
"Server:" "SERVER NAME ONLY!!!" \
"Share:" "SHARENAME CANNOT HAVE SPACES!!!"`

ret1=$?
case $ret1 in
0)
USRINFO=`/usr/bin/Xdialog --stdout --separator "|" \
--title "Login" --backtitle "System login" \
--icon ./no-entry.xpm --left --password \
--3inputsbox "Restricted access, authorized users only !\nPlease login..." 0 0 \
"Domain:" "" \
"Your login name:" "" \
"Your password:" ""`

ret2=$?
case $ret2 in
0)
SERVER=`echo $SRVRINFO | awk --source 'BEGIN { FS="|" }' --source '{ print $1 }'`
SHARE=`echo $SRVRINFO | awk --source 'BEGIN { FS="|" }' --source '{ print $2 }'`
DOMAIN=`echo $USRINFO | awk --source 'BEGIN { FS="|" }' --source '{ print $1 }'`
USER=`echo $USRINFO | awk --source 'BEGIN { FS="|" }' --source '{ print $2 }'`
PASSWORD=`echo $USRINFO | awk --source 'BEGIN { FS="|" }' --source '{ print $3 }'`
smbclient //$SERVER/$SHARE -U $DOMAIN\\$USER%$PASSWORD -c quit > /dev/null
if [ $? -eq 0 ]; then
/usr/bin/Xdialog --stdout --title "Confirm Connections..." \
--left --backtitle "Is this correct?" \
--yesno "Server: $SERVER \nShare: $SHARE \nDomain: $DOMAIN \nUsername: $USER" 0 0
else
/usr/bin/Xdialog --stdout --title "Cannot Resolve!" \
--infobox "Cannot resolve the server or share you specified. \n1. FQDN is no longer required. \n2. Double check your spelling. \n3. Make sure you have permissions into this share. \nThis script will restart automatically..." 0 0 30000
aioscript Xmapscript
fi
ret3=$?
case $ret3 in
0)
echo "/mounts/$SERVER.$SHARE" > /tmp/.server
if [ -d /mounts/$SERVER.$SHARE ]; then
fuser -k /mounts/$SERVER.$SHARE
umount /mounts/$SERVER.$SHARE
mount -t smbfs -o username=$DOMAIN\\$USER,password=$PASSWORD //$SERVER/$SHARE /mounts/$SERVER.$SHARE
echo prog "$SERVER.$SHARE" "gnome-folder" nautilus --no-desktop --no-default-window /mounts/$SERVER.$SHARE >> /root/.icewm/menu
nautilus --no-desktop --no-default-window /mounts/$SERVER.$SHARE &
else
mkdir /mounts/$SERVER.$SHARE
mount -t smbfs -o username=$DOMAIN\\$USER,password=$PASSWORD //$SERVER/$SHARE /mounts/$SERVER.$SHARE
echo prog "$SERVER.$SHARE" "gnome-folder" nautilus --no-desktop --no-default-window /mounts/$SERVER.$SHARE >> /root/.icewm/menu
nautilus --no-desktop --no-default-window /mounts/$SERVER.$SHARE &
fi
;;
1)
/usr/bin/Xdialog --msgbox "Please restart." 0 0
;;
esac
;;
1)
/usr/bin/Xdialog --msgbox "Cancel pressed." 0 0
;;
255)
/usr/bin/Xdialog --msgbox "Box closed." 0 0
;;
esac

;;
1)
/usr/bin/Xdialog --msgbox "Cancel pressed." 0 0
;;
255)
/usr/bin/Xdialog --msgbox "Box closed." 0 0
;;
esac
;;


## View Host Information
##
########################

xhostinfo)
# This section displays information about its host PC.
NAME=`cat /etc/passwd | grep -v :root | grep 0:0 | cut -f1 -d:`
EXPIRE=`grep $NAME /etc/shadow | cut -f8 -d':'`
EPOCHDAY=$((`date +%s` / 86400))
DAYSLEFT=$(($EXPIRE - $EPOCHDAY))
IP=`ifconfig | grep inet | grep -v 127\.0 | cut -f2 -d':' | cut -f1 -d' '`
MEMTOTAL=`cat /proc/meminfo | grep MemTotal`
CPUINFO=`cat /proc/cpuinfo | grep "model name" | cut -f2 -d':'`
PCIHW=`lspci | cut -f2- -d' '`

Xdialog --title "Host Information" --msgbox "Rescue CD Version .91\n\nOwner: $NAME\n\nCD Expires in $DAYSLEFT days\n\nIP Address: $IP\n\nCPU Detected:$CPUINFO\n\n$MEMTOTAL\n\nHardware Detected:\n$PCIHW" 0 0
exit 1
;;

## RCD Expiration Section
##
#########################

xexpnotice)
# This section displays how many days are left until the CD expires.
NAME=`cat /etc/passwd | grep -v :root | grep 0:0 | cut -f1 -d:`
EXPIRE=`grep $NAME /etc/shadow | cut -f8 -d':'`
EPOCHDAY=$((`date +%s` / 86400))
DAYSLEFT=$(($EXPIRE - $EPOCHDAY))
Xdialog --no-buttons --infobox "You have $DAYSLEFT days left until your Rescue CD expires!!!" 0 0 10000
exit 1
;;

## NTFS Checkdisk Section for X
##
#########################

xcheckdisk)
if Xdialog --yesno "This will unmount all partition(s), run NTFS Checkdisk then automatically reboot.\n\nContinue?" 0 0; then
PARTS=`fdisk -l /dev/hd[a-z] /dev/sd[a-z] | grep NTFS | cut -f1 -d' '`
umount -t ntfs /dev/hd[a-z][1-9] /dev/sd[a-z][1-9]>/dev/null 2>/dev/null
for i in $PARTS; do
Xdialog --no-buttons --infobox "Checking..." 0 0 1000000 &
ntfsfix $i > /dev/null
killall -9 Xdialog
done
Xdialog --no-buttons --infobox "Rebooting NOW..." 0 0 & sleep 2
aioscript shutdown
fi
exit 1
;;

## Run ntfsundelete section for X
##
###########################

xntfsundelete)
if ! mount | grep smbfs; then
Xdialog --infobox "You must be mapped to a network share to use this tool..." 0 0
sleep 1
aioscript Xmapscript
fi
nautilus -q
if Xdialog --yesno "This will undelete chosen files from a chosen partition that are 90% undeletable and copy them to a network share. \n\nContinue?" 0 0; then
PART=`fdisk -l /dev/hd[a-z] /dev/sd[a-z] | grep "NTFS" | cut -f1 -d' '`

PART1=`echo $PART | awk --source 'BEGIN { FS=" " }' --source '{ print $1 }'`
PART2=`echo $PART | awk --source 'BEGIN { FS=" " }' --source '{ print $2 }'`
PART3=`echo $PART | awk --source 'BEGIN { FS=" " }' --source '{ print $3}'`
PART4=`echo $PART | awk --source 'BEGIN { FS=" " }' --source '{ print $4}'`

umount -t ntfs /dev/hd[a-z][1-9] /dev/sd[a-z][1-9]>/dev/null 2>/dev/null

UNDELETE=`Xdialog --stdout --separator " " \
--radiolist "Select a partition and press SpaceBar:" 0 0 0 \
"$PART1" "" "on" \
"$PART2" "" "" \
"$PART3" "" "" \
"$PART4" "" ""`
DIR=`Xdialog --stdout --nocancel --inputbox "Please enter a directory name:" 0 0`
MAP=`mount | grep smbfs | cut -f3 -d' '`
mkdir -p $MAP/$DIR
UNDEL=`ntfsundelete -p90 /dev/hda1 | grep % | grep -v Filename`
LINE=`echo "$UNDEL" | awk '// {print $6"::"$4"::"$1,$5,"off"}'`
INODES=`Xdialog --separate-output --stdout --backtitle "Here are the files that can be undeleted. Sorted by: Filename,Date Deleted,Inode# and Size" --title "Select the files you would like to undelete" --checklist "\nCareful with duplicate names" 0 0 0 $LINE`
Xdialog --no-buttons --infobox "Undeleting files..." 0 0 10000000 &
for i in $INODES; do
ntfsundelete -u `echo $i | cut -f5- -d:` $UNDELETE -d $MAP/$DIR
done
killall -9 Xdialog
Xdialog --msgbox "Completed undeleting files..." 0 0
nautilus $MAP/$DIR
fi
exit 1
;;

## X NT Password Reset section
##
##############################

xntpasswd)

echo '#!/usr/bin/expect -f

set timeout -1
spawn chntpw -u 0x1f4 /tmp/.ntpasswd/SAM
match_max 100000
expect -exact "Please enter new password: "
send -- "*\r"
expect -exact "Do you really wish to change it? (y/n) \[n\] "
send -- "y\r"
expect -exact "Write hive files? (y/n) \[n\] : "
send -- "y\r"
expect eof' > /tmp/chntpw.exp
chmod +x /tmp/chntpw.exp

if Xdialog --yesno "This will reset the administrative password to blank, run NTFS Check and automatically reboot.\n\nConitnue?" 0 0; then
Xdialog --no-buttons --infobox "Blanking admin password..." 0 0
if [ -e /tmp/.ntpasswd ]; then
umount /tmp/.ntpasswd > /dev/null 2>/dev/null
rmdir /tmp/.ntpasswd
fi
if [ -e /tmp/ntfsdrive ]; then
umount /tmp/ntfsdrive > /dev/null 2>/dev/null
rmdir /tmp/ntfsdrive
fi
mkdir /tmp/.ntpasswd
mkdir /tmp/ntfsdrive
mount -t tmpfs tmpfs /tmp/.ntpasswd
mount -t ntfs `fdisk -l /dev/hd[a-z] 2>/dev/null | grep NTFS | grep "\*" | cut -f1 -d' '` /tmp/ntfsdrive
if [ -d /tmp/ntfsdrive/winnt ]; then
DEFDIR="/tmp/ntfsdrive/winnt"
elif [ -d /tmp/ntfsdrive/windows ]; then
DEFDIR="/tmp/ntfsdrive/windows"
else
Xdialog --msgbox "Cannot find Windows Directory. Please contact a member of the RCD Development Team" 0 0
exit 1
fi
cp $DEFDIR/system32/config/SAM /tmp/.ntpasswd/.

UNAME=`expect /tmp/chntpw.exp | grep 01f4 | grep Administrator | cut -f3- -d' '`
Xdialog --title Completed --no-buttons --msgbox "By the way, just in case the admin username is not Administrator: \n\n$UNAME" 0 0
rm -f /tmp/chntpw.exp
mount -o remount,rw /tmp/ntfsdrive
cp /tmp/.ntpasswd/SAM $DEFDIR/system32/config/.
umount /tmp/ntfsdrive
Xdialog --no-buttons --infobox "Running NTFS Check on the modified partition..." 0 0 10000000 &
ntfsfix `fdisk -l /dev/hd[a-z] /dev/sd[a-z] 2>/dev/null | grep NTFS | cut -f1 -d' '`>/dev/null 2>/dev/null
killall -9 Xdialog
Xdialog --no-buttons --infobox "Rebooting NOW" 0 0 && sleep 2
aioscript shutdown
fi
exit 1
;;

## X static IP section
##
######################

xstaticip)
if Xdialog --yesno "This script will configure your network settings \
\nif you do not have DHCP available. \
\nDo you wish to continue?" 0 0; then
IP=0.0.0.0
NM=255.255.255.0
GW=255.255.255.255
NS=`Xdialog --stdout --separator "|" \
--title "Network Configuration Script" --backtitle "Network Settings" \
--left --3inputsbox "Enter your network settings" 0 0 \
"IP Address:" "" \
"Subnet Mask:" "" \
"Default Gateway:" ""`
DNS=`Xdialog --stdout --separator "|" \
--left --3inputsbox "Enter your DNS settings" 0 0 \
"Nameserver 1:" "" \
"Nameserver 2:" "" \
"Suffix Search Order: (separated by spaces)" ""`

IP=`echo $NS | awk --source 'BEGIN { FS="|" }' --source '{ print $1 }'`
NM=`echo $NS | awk --source 'BEGIN { FS="|" }' --source '{ print $2 }'`
GW=`echo $NS | awk --source 'BEGIN { FS="|" }' --source '{ print $3 }'`
DNS1=`echo $DNS | awk --source 'BEGIN { FS="|" }' --source '{ print $1 }'`
DNS2=`echo $DNS | awk --source 'BEGIN { FS="|" }' --source '{ print $2 }'`
SUFFIX=`echo $DNS | awk --source 'BEGIN { FS="|" }' --source '{ print $3 }'`
ETH0=`ifconfig | grep eth0 | cut -f1 -d' '`
ETH1=`ifconfig | grep eth1 | cut -f1 -d' '`
ETH=`Xdialog --stdout --no-cancel --combobox "Which Ethernet Adapter?" 10 50 "$ETH0" "$ETH1"`
if Xdialog --stdout --title "Confirm Settings" \
--backtitle "Is this correct?" \
--yesno "$ETH \nIP Address: $IP \nNetwork Mask: $NM \nDefault Gateway: $GW" 0 0; then
ETH=`echo $ETH | cut -f1 -d' ' | cut -f1 -d':'`
ifconfig $ETH $IP
ifconfig $ETH netmask $NM
route add default $ETH
route add default gw $GW
echo search $SUFFIX > /etc/resolv.conf
echo nameserver $DNS1 >> /etc/resolv.conf
echo nameserver $DNS2 >> /etc/resolv.conf
else
aioscript xstaticip
fi
fi
exit 1
;;

xntfsrw)
if Xdialog --title "WARNING" --yesno "Making the host drive writable allows
you to accidently delete user data!\nPlease read the RCD documentation for more info!!!\n\nContinue?" 0 0; then
nautilus -q
PARTS="`fdisk -l | grep "NTFS" | cut -f1 -d' '`"
for i in $PARTS; do
umount $i
rmdir /mounts/`echo $i | cut -f3 -d'/'`
mkdir /mounts/`echo $i | cut -f3 -d'/'`
mount -t captive-ntfs $i /mounts/`echo $i | cut -f3 -d'/'`
done
Xdialog --title "Drive mounted" --msgbox "If the folder contents
cannot be displayed most likely the drive is still in fix mode,
you should reboot into Windows to allow for the scandisk to happen
then reboot back to the RCD" 0 0
nautilus /mounts
for i in $PARTS; do
umount $i
rmdir /mounts/`echo $i | cut -f3 -d'/'`
done
Xdialog --title NOTICE --msgbox "Drive(s) Unmounted..." 0 0
fi
exit 1
;;

## Console usage section
help)
echo "Usage: aioscript {menu|backup|map|checkdisk|ntfsfix|ntpasswd|ntfsun delete|staticip|checkdisk|?}"
exit 1
;;

## Shutdown Section
shutdown)
/etc/init.d/gdm stop
init 6
;;

## Main Menu Section
*)
MAP=`mount | grep smbfs | cut -f1 -d' '`
FUNCTION=`dialog --stdout --no-cancel \
--title "Rescue CD Console" \
--menu "IP: $IP - Mapped to: $MAP" 0 60 0 \
1 "Map to Network Share" \
2 "Backup local drive to ... $MAP" \
3 "Run NTFS Check Disk" \
4 "NTFS Undelete" \
5 "Reset Admin Password" \
6 "Set Static IP" \
7 "Host Information" \
8 "Shutdown"`
if [ $FUNCTION = 1 ]; then
aioscript map
aioscript
elif [ $FUNCTION = 2 ]; then
aioscript backup
aioscript
elif [ $FUNCTION = 3 ]; then
aioscript checkdisk
aioscript
elif [ $FUNCTION = 4 ]; then
aioscript ntfsundelete
aioscript
elif [ $FUNCTION = 5 ]; then
aioscript ntpasswd
aioscript
elif [ $FUNCTION = 6 ]; then
aioscript staticip
aioscript
elif [ $FUNCTION = 7 ]; then
aioscript hostinfo
aioscript
elif [ $FUNCTION = 8 ]; then
aioscript shutdown
fi
exit 1
;;

esac
exit 0

:shock:

firebyrd10
10-10-2004, 08:39 PM
Partimage) umounts all drives and launches qtparted


Why are you making the command partimage launch qtparted? Partimage would be useful to make a complete backup. (though I use dd and it works just fine) So you might want to creat two differnt backup scripts. One that backs up folders and files, another that backups like Ghost.

I can give you what I use for backing up my drive useing dd if it helps.


*Done with Root privliges.*
dd if=/dev/hdX | gzip -c | dd of=/share/hdbackup.img.gz && cat /dev/hdX | md5sum && zcat /share/hdbackup.img.gz | md5sum

Basicly that gets dd to send its data to gzip which compress it and then sends it to dd to write it to a file. Then use cat sends the raw data of the drive to md5sum and then sends the raw data of the compressed image to md5sum to compare if the image is a binary equal.

Depending on the way your sending the file to anyother computer, you may need to split the file into 1-2 gig chunks. But before you can md5sum the image your going to need to put it back together. For some reason zcat doesn't accept wildcards.

To put the image back on the drive just issue this.

*need root privliges.*
zcat /share/hdimage.img.gz | dd of=/dev/hdX && zcat /share/hdimage.img.gz | md5sum && cat /dev/hdX | md5sum

If possible your going to want to blank the drive with zeros for better compression.

bizarro
10-10-2004, 09:43 PM
woops...

Partimage) is a typo...if you look in the script its partmanage)

the thing about backing up is my techs still need a way to access the data from windows pc's...in my current rcd it uses zip to zip the entire drive...that proved bad as anything larger than 2gb will create corrupted zips :(

firebyrd10
10-10-2004, 10:09 PM
woops...

Partimage) is a typo...if you look in the script its partmanage)

the thing about backing up is my techs still need a way to access the data from windows pc's...in my current rcd it uses zip to zip the entire drive...that proved bad as anything larger than 2gb will create corrupted zips :(

You could aways try 7-zip

Tt alows for max sizes of 16,000,000,000 GB
Plus it always support of Deflate64 (Deflate is what zip uses, normal uses 32 bit deflate, new uses 64 bit. Alows for 2 terabytes) So it can creat zip files. Its suppose to zip files better also. I noticed a meg or two decrease when I tested it.

Plus its free (Open Source) and there is a command line version for Linux.

Its ultra compress setting for LZMA is really slow, but it cut the file is in half compared to a zip. (decompression is comparable to Zip however)

It alows for multiple compression methods if you have a favorite also.

http://7-zip.org/

bizarro
10-11-2004, 12:54 AM
thanx for your input...i really appreciate it :)

with your testing experience maybe you can answer a couple of questions for me with this scenario...

a laptop's hdd is corrupted and windows can no longer boot. with the rcd you can get to the data

1. the data backing up either by dd, partimage or 7z will be larger than 2gb.
2. backup will be to a network share using samba

can the backup happen with out corruption?

firebyrd10
10-11-2004, 02:04 AM
thanx for your input...i really appreciate it :)

with your testing experience maybe you can answer a couple of questions for me with this scenario...

a laptop's hdd is corrupted and windows can no longer boot. with the rcd you can get to the data

1. the data backing up either by dd, partimage or 7z will be larger than 2gb.
2. backup will be to a network share using samba

can the backup happen with out corruption?

From what I know about samba it won't alow files bigger then 2 gigs.

If you were to dd the drive over to an image on a remote computer then you would have to split it.


dd if=/dev/hdX | gzip -c | split -b 1024m - /samba/hdimage.img.gz.

Then you would need to put the file back together on the remote computer. Luckly, a batch file can do that job.


Copy /b hdimage.img.gz.aa + hdimage.img.gz.ab + hdimage.img.gz.ac ... + hdimage.img.gz.nnn hdimage.img.gz

Now you can md5sum the file and drive and check out if they are the same.

You could basicly do the same thing with a 7z archive. Just first make the archieve, then split it for transport.

split -b 1024m hdbackup.7z /samba/hdbackup.7z.

You can then put it back together the same way.

Of course all this spliting stuff can be bypassed if you use something that alows bigger files to be transported, mabye ftp or SSH.

bizarro
10-11-2004, 02:34 AM
hmmm...i just ran a test between dd and partimage...

results...

partimage file size: 600mb
dd file size: 800mb

splitting isn't going to be easy on dd but in partimage i see its built in...

maybe i can use that...what do you think?

firebyrd10
10-11-2004, 02:56 AM
hmmm...i just ran a test between dd and partimage...

results...

partimage file size: 600mb
dd file size: 800mb

splitting isn't going to be easy on dd but in partimage i see its built in...

maybe i can use that...what do you think?

I think the smaller file size is because partimage knows to ignore data marked as delete. dd makes a bit for bit copy, regardless whether its marked as deleted or now (good for recovering lost data on another PC), its the first program I used to back up my drive, so now I like it better. (Don't know why.) I assume however if you blanked out the free space on the drive then both dd and partimage would be the same size.

If partimage seems to work better for you, go ahead. I have no rational reason for sticking with dd


*edited* I just checked out partimage, its alot better then dd, im going to start playing with it. The only problem I can see is comparing the data with md5.

firebyrd10
10-12-2004, 01:46 AM
I've checked out partimage (for the most part). It looks like it could fit your cause well. Espically(sp) the server option.

Like I said before, the only problem I see is comparing the backed up data to the image.

Mickey_p
11-13-2004, 02:11 AM
maybe you are unaware of this
but windows 2K+ which means 2000, XP, 2003 server
have thier own recovery modules.

it is much simpler to load DOS 6.22 which an dosntfs module (do a google)
and just copy that way.

unless you are more interesed in the project than the end result.

btw, you can also checkout novell 6.2, they have a similler ms-dos bootdisk (not CD) that can get to your local/shared drives with nfs if you need it.

so you already have
ntfs justintime recovery
nfs justintime recovery

i hope this helps.

-Mick
if you want a client fo ntfs for dos, and you cant find it googling, send me a note, ill send you the file. (which is gnu licensd if im not mistaken)