|
Target /
ShNote: The wiki formating screws this up. If you want to copy the source code, you will need to edit the page to see it properly.
uid=dsl
sourcemnt="/mnt/tmp"
sambashare="//mrsync_source/temp"
IP_LIST_FILE=$sourcemnt"/iplist.txt"
HDDpartition?=$HDDdevice"1"
tmpexpectfile="/tmp/expect.txt" tmpfile="/tmp/temp.txt"
finishflagfile=$sourcemnt"/finished.txt"
index=1 echo $index") Stopping Samba" sudo /etc/init.d/samba.dpkg-new stop let "index+=1" echo $index") Mount share on source to "$sourcemnt sudo mkdir $sourcemnt echo "Waiting for source machine to be available" echo "or type 'q' to quit" sudo rm -rf $tmpfile touch $tmpfile answer=""
while [ \( "$answer" != "q" \) -a \( ! -s $tmpfile \) ]; do sudo mount -t smbfs -o guest,rw,uid=$uid $sambashare $sourcemnt &>/dev/null read -n 1 -t 5 answer ls $sourcemnt > $tmpfile done
beep let "index+=1" if [ -z $answer ] then echo $index") Writing IP Address to source "$IP_LIST_FILE
ifconfig eth0 | grep 'inet addr' | sed -ne 's/^ *inet addr://' -e 's/ .*//p' > $tmpfile
read IPAddress? < $tmpfile
# This deletes the IP Address if it already exists then adds it to the bottom of the file
sed -ie /$IPAddress/d $IP_LIST_FILE
echo $IPAddress >> $IP_LIST_FILE
let "index+=1"
fi if [ -z $answer ] then echo $index") Read password from file on source share" read pass < $sourcemnt/password.txt let "index+=1" fi if [ -z $answer ] then echo $index") Change password for "$uid" to "$pass echo 'spawn sudo passwd '$uid > $tmpexpectfile echo 'after 5000' >> $tmpexpectfile echo 'expect "new UNIX password:"' >> $tmpexpectfile echo 'send "'$pass'\r"' >> $tmpexpectfile echo 'expect "new UNIX password:"' >> $tmpexpectfile echo 'send "'$pass'\r"' >> $tmpexpectfile echo 'expect "updated successfully"' >> $tmpexpectfile echo 'send_user "\rDone\r"' >> $tmpexpectfile # This is done twice as a kludge because the first time sometimes doesn't work for some reason expect -f $tmpexpectfile expect -f $tmpexpectfile echo let "index+=1" fi if [ -z $answer ] then echo $index") Copy MBR and partition boot sector from Samba share (without overwriting the Partition table)" # This copies the Master Boot Record without the Partition table sudo dd if=$sourcemnt/mbr.bin of=$HDDdevice bs=446 count=1 # This copies the Master Boot Record including the Partition table # and should be commented out normally # sudo dd if=$sourcemnt/mbr.bin of=$HDDdevice bs=512 count=1 #This copies the Partition boot sector sudo dd if=$sourcemnt/bootsect.bin of=$HDDpartition bs=512 count=1 let "index+=1" fi if [ -z $answer ] then echo $index") Format partition to NTFS and mount as Writable at "$HDDmnt sudo mkfs -t ntfs $HDDpartition --fast sudo mkdir $HDDmnt sudo mount -t ntfs-3g -o rw,uid=$uid $HDDpartition $HDDmnt -force let "index+=1" fi if [ -z $answer ] then echo $index") Wait for signal from source that copying is finished" # This loop justs checks for the existence of the flag file every 20 seconds # and exits when it finds it has been created. while [ ! -f $finishflagfile ]; do sleep 20 done let "index+=1" fi echo $index") Unmount drives and tidy up" sudo umount $HDDmnt sudo rmdir $HDDmnt sudo umount $sourcemnt sudo rmdir $sourcemnt let "index+=1" echo echo "Finished" echo
beep |