#!/bin/sh # # Version 1.0 # # Image restore script for SystemImager for use on rescue systems # # Useful on systems that can't be accessed physically so that no # autoinstall diskette/CD-ROM can be used but that have a rescue # system (e.g. BusyBox). # # Copyright (c) 2005, Falko Timme # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the distribution. # * Neither the name of the copyright holder nor the names of the # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # PATH=/sbin:/bin:/usr/bin:/usr/sbin:/tmp error () { echo "ERROR: $1" exit 1 } echo -n "Please enter your image server (e.g. 1.2.3.4 or imageserver.example.com): " read image_server echo -n "Please enter the name of the image to be restored: " read image_name echo -n "Please enter the ethernet device you want to use on this system to restore the image (normally eth0): " read ethernet_device rsync $image_server::scripts/$image_name.master /tmp if [ $? != 0 ]; then error "rsync of the master script failed!"; fi ### ADJUST THE MASTER SCRIPT ### modprobe reiserfs > /dev/null 2>&1 if [ $? != 0 ]; then grep -v "modprobe reiserfs" /tmp/$image_name.master > /tmp/$image_name.master_new mv /tmp/$image_name.master_new /tmp/$image_name.master fi modprobe ext2 > /dev/null 2>&1 if [ $? != 0 ]; then grep -v "modprobe ext2" /tmp/$image_name.master > /tmp/$image_name.master_new mv /tmp/$image_name.master_new /tmp/$image_name.master fi modprobe ext3 > /dev/null 2>&1 if [ $? != 0 ]; then grep -v "modprobe ext3" /tmp/$image_name.master > /tmp/$image_name.master_new mv /tmp/$image_name.master_new /tmp/$image_name.master fi modprobe jfs > /dev/null 2>&1 if [ $? != 0 ]; then grep -v "modprobe jfs" /tmp/$image_name.master > /tmp/$image_name.master_new mv /tmp/$image_name.master_new /tmp/$image_name.master fi modprobe xfs > /dev/null 2>&1 if [ $? != 0 ]; then grep -v "modprobe xfs" /tmp/$image_name.master > /tmp/$image_name.master_new mv /tmp/$image_name.master_new /tmp/$image_name.master fi grep -v beep /tmp/$image_name.master > /tmp/$image_name.master_new mv /tmp/$image_name.master_new /tmp/$image_name.master grep -v "ifconfig eth0 down || shellout" /tmp/$image_name.master > /tmp/$image_name.master_new mv /tmp/$image_name.master_new /tmp/$image_name.master chmod 755 /tmp/$image_name.master if [ -f /etc/init.d/functions ]; then mv /etc/init.d/functions /etc/init.d/functions_old fi wget http://www.falkotimme.com/howtos/dedicated_server_backup_restore_systemimager/functions if [ $? != 0 ]; then error "wget of the functions script failed!"; fi mv functions /etc/init.d/functions which bc > /dev/null 2>&1 if [ $? != 0 ]; then wget http://www.falkotimme.com/howtos/dedicated_server_backup_restore_systemimager/bc if [ $? != 0 ]; then error "wget of the bc script failed!"; fi mv bc /bin/bc chmod 755 /bin/bc fi ### CREATE /tmp/variables.txt ### echo "HOSTNAME=" > /tmp/variables.txt echo "DOMAINNAME=" >> /tmp/variables.txt echo "DEVICE=$ethernet_device" >> /tmp/variables.txt echo "IPADDR=" >> /tmp/variables.txt echo "NETMASK=" >> /tmp/variables.txt echo "NETWORK=" >> /tmp/variables.txt echo "BROADCAST=" >> /tmp/variables.txt echo "GATEWAY=" >> /tmp/variables.txt echo "GATEWAYDEV=$ethernet_device" >> /tmp/variables.txt echo "IMAGESERVER=$image_server" >> /tmp/variables.txt echo "IMAGENAME=$image_name" >> /tmp/variables.txt echo "LOG_SERVER=" >> /tmp/variables.txt echo "LOG_SERVER_PORT=" >> /tmp/variables.txt echo "TMPFS_STAGING=" >> /tmp/variables.txt echo "SSH_USER=" >> /tmp/variables.txt echo "SSH_DOWNLOAD_URL=" >> /tmp/variables.txt echo "FLAMETHROWER_DIRECTORY_PORTBASE=" >> /tmp/variables.txt /tmp/$image_name.master rm -f /tmp/$image_name.master rm -f /tmp/variables.txt ### RESTORE OLD FUNCTIONS SCRIPT ### if [ -f /etc/init.d/functions_old ]; then mv /etc/init.d/functions_old /etc/init.d/functions fi exit 0