# Hey, Emacs, this is -*- sh -*- code # Copyright (c) 1999 Tim Barbour. All Rights Reserved. # This script may be used and distributed under the terms # of the GNU GPL, as published by the Free Software Foundation. # these functions provide low-level services to cdpio # Common functions for backup purposes # not very low-level, but needed by dump-cdr-image, temporarily at least ask_user_action() { cat /dev/null > $volume_change_mail_spool echo "$2" \ | mail -a "From: $volume_change_user" -a "Reply-To: $volume_change_user" -s "$1" $backup_operator until [ -n "`cat $volume_change_mail_spool`" ]; do sleep 10 done } is_mounted() { if(mount | grep $1 > /dev/null); then true else false fi } make_unmounted() { if(is_mounted $1); then umount $1 fi } # find the image or device for the supplied filesystem ($1) # if the filesystem_image variable is set, use that # otherwise work it out from /etc/fstab find_fs_image() { if [ -n "$image" ]; then echo $image elif !(grep -v '^#' /etc/fstab | grep $1 - > /dev/null); then exit -1 else grep -v '^#' /etc/fstab | grep $1 - | awk '{print $1;}' fi } find_free_loop_device() { for x in `ls /dev/loop/*`; do if(losetup $x 2>&1 | grep -i "no such device" > /dev/null); then # this loop device is free echo $x return fi done # no free loop devices, give up exit -1 } is_device() { if(echo $1 | egrep "^/dev/.+" > /dev/null); then true else false fi } # init_backup_fs image blocks mount_point label compression init_backup_fs() { make_unmounted $3 device="" should_release="" if(is_device $1); then device=$1 else # must be an image file, so we need to use a loop device device=`find_free_loop_device` losetup $device $1 should_release="yes" fi /sbin/mke2fs -m 0 -q -L $4 $device $2 if [ -n "$should_release" ]; then losetup -d $device fi mount $3 if [ -n "$5" ]; then # turn on ext2 compression chattr -m $5 $3 chattr +c $3 fi }