Rev 132 | Blame | Last modification | View Log | Download | RSS feed
#!/bin/bash## Saves data to a usbstick (default)# or a partition (user input)# Scientific Linux Live CD## Urs Beyerle#### definitionsCONFIG_FOLDER=""MOUNTDIR=livecd. /$MOUNTDIR/live/liblinuxlive# PSI setup?PSI=$( cmdline_parameter psi )# # folder where we find data which was previously stored# (can be on an usbstick or harddisk partition)SAVEFOLDER=SL_LIVECDecho### this script should be run as root# (if not, somethings will not be stored)if [ "$( whoami )" != "root" ]; thenecho "********************************************"echo "WARNING: Run this script as root or sudo !!"echo "As normal user not everything will be saved."echo "Run instead: # sudo $0"echo "********************************************"echoecho "Press a key to continue (CTRL-C to exit)"read -n 1fi### search usb sticksecho "Search for usbstick..."USBMOUNT=$( grep -i /media/usb /etc/fstab | tail -n 1 | awk '{ print $2 }' )if [ $USBMOUNT ]; then# mount usbstick, if not already mountedmount | grep -q " $USBMOUNT "if [ "$?" != "0" ]; thenecho "Mount $USBMOUNT"mount $USBMOUNT 2>/dev/nullfifi### if no usbstick, ask the user for a partitionif [ ! $USBMOUNT ]; thenecho "No usbstick found."echo "Type in a partition you want to store the data to."echo -n "(e.g. /dev/hda1, /dev/sda1, ...): "read MOUNT_DEV# search $MOUNT_DEV in fstabUSBMOUNT=$( grep "^$MOUNT_DEV " /etc/fstab | tail -n 1 | awk '{ print $2 }' )if [ ! $USBMOUNT ]; thenmkdir -p /mnt/$MOUNT_DEVUSBMOUNT=/mnt/$MOUNT_DEVfi# mount read writemount -rw $MOUNT_DEV $USBMOUNT 2>/dev/nullif [ "$?" != "0" ]; thenecho "ERROR: Can not mount $MOUNT_DEV to $USBMOUNT"sleep 5; exit 1elseecho "Mounted $MOUNT_DEV to $USBMOUNT."fifi### search for $SAVEFOLDER on $USBMOUNTif [ -d $USBMOUNT/$SAVEFOLDER ]; thenCONFIG_FOLDER=$USBMOUNT/$SAVEFOLDERecho "Found folder '$SAVEFOLDER' on $USBMOUNT."elsemkdir -p $USBMOUNT/$SAVEFOLDERif [ "$?" = "0" ]; thenecho "Folder $SAVEFOLDER created on $USBMOUNT."CONFIG_FOLDER=$USBMOUNT/$SAVEFOLDERelseecho "ERROR: Can not write to $USBMOUNT."CONFIG_FOLDER=""fifi### Create README.txt in $CONFIG_FOLDERecho "Do not delete this folder!" > $CONFIG_FOLDER/README.txtecho "It is used to store your data from LiveCD." >> $CONFIG_FOLDER/README.txtif [ "$?" = "0" ]; thenecho "Saved $CONFIG_FOLDER/README.txt"elseecho "ERROR: Could not save $CONFIG_FOLDER/README.txt !"fi### put parameter "keyboard" to config (if not yet there)CONFIG_FILE=$CONFIG_FOLDER/configgrep -q "KEYBOARD=" $CONFIG_FILE 2>/dev/nullif [ "$?" != "0" ]; then# what keyborad do I have?. /etc/sysconfig/keyboardecho KEYBOARD=$KEYTABLE >> $CONFIG_FILEecho "Saved $CONFIG_FILE"fi### put restore script to setup (if setup does not yet exists)SETUP_FILE=$CONFIG_FOLDER/setupif [ ! -e $SETUP_FILE ]; thencat > $SETUP_FILE <<'EOF'#!/bin/bash## restore tar.gz files, if found on usbstickfiles=$( ls $CONFIG_FOLDER/*.tar.gz )cd /for file in $files; dotar xfzP $file 2>/dev/nullif [ "$?" = "0" ]; thenecho "$file restored."fidoneEOFecho "Saved $SETUP_FILE"fi### save /home, /etc/passwd /etc/shadow, ...# as tar.gz. filesecho "Start saving tar.gz files to $CONFIG_FOLDER:"SAVES="/home \/root \/etc/passwd \/etc/shadow \/etc/group"for save in $SAVES; doecho -n "Save $save ... "tar cfzP $CONFIG_FOLDER/$( basename $save ).tar.gz $saveif [ "$?" = "0" ]; thenecho " done."elseecho "ERROR: Could not save $save to $USBMOUNT !"fidone### save /etc/X11/xorg.confcp -a /etc/X11/xorg.conf $CONFIG_FOLDER/echo "Xserver configuration file 'xorg.conf' saved to $CONFIG_FOLDER."### inform userecho "If you don't want to keep one of these config files, just delete it."echo### umount $USBMOUNTecho "Unmount $USBMOUNT"umount $USBMOUNT 2>/dev/nullecho "$0 finished."echoecho "Please <press a key> ..."read -n 1