#!/bin/bash # # $Header: /CVSROOT/public/scylla-charybdis/md5backup/bin/sc-setup.sh,v 1.2 2006/10/03 21:16:33 tino Exp $ # # Just run it after bin/dobackup.sh # It does the rest of the setup for you. # # $Log: sc-setup.sh,v $ # Revision 1.2 2006/10/03 21:16:33 tino # See Changelog, commit for dist # # Revision 1.1 2004/09/29 00:02:35 tino # added #if [ -z "$TINO_DEVEL" ]; then echo "This script is not ready yet!"; exit; fi MD5B="/backup/md5backup" HERE="/backup/charybdis" BINS="charybdis" CONF="sc-move.conf" if [ .root != ".`id -un`" ] then echo "$0 must be called as root. SU to root and try again." >&2 exit 1 fi presskey() { echo -n "Press return to continue, ^D to abort -> " read || exit 1 echo } pressy() { echo -n "+-+ $* (y/N)? " read || exit 1 [ .y = ".$REPLY" ] || exit 1 echo } pressyonce() { povar="$1" poval="$2" potxt="$3" shift 3 [ -n "${!povar}" ] && return echo p="+-+" for a do echo "$p $a" p="! !" done | awk -v VAL="$poval" '{ gsub(/###/,VAL); print; }' pressy "$potxt" eval $povar=1 } error() { echo "error: $*" >&2 exit 1 } isme() { cmp -s "$0" "$1" } realpath() { ( cd "$1" || exit 1 /bin/pwd ) } find_bin() { find "$@" -name "$BINS" | { while read n do d="`dirname "$n"`" done echo "$d" } } do_mkdir() { if [ ! -e "$1" ] then pressyonce dirs "$1" "$@" "Shall I create missing directories" "Directory ### is missing." mkdir "$1" && echo "mkdir $1" || error "cannot mkdir $1" fi [ ! -d "$1" ] && error "is not a directory: $a" } do_softlink() { TO="$2" [ -n "$TO" ] || TO="$HERE/`basename "$1"`" if [ ! -e "$TO" ] then pressyonce softlinks "$TO" "Shall I create missing softlinks" "Softlink ### is missing." ln -s "$1" "$TO" && echo "softlink $TO" || error "cannot create softlink $TO" fi [ ! -L "$TO" ] && error "is not a softlink: $TO" } info() { echo "+-+ From screen or ptybuffer run" echo "! !" echo "! ! $HERE/sc-loop.sh" echo "! !" echo "! ! This runs the permanent backup loop" echo "! !" echo "! ! First:" echo "! ! Use the command 'setpw' to set the mysql root password." echo "+-+ Use a dummy password if you don't want a mysql backup." } pressy "This script is not ready yet, continue" echo echo "+-+ This does the setup of networking part of md5backup." echo "! !" echo "! ! Note that this part is a quick hack and will be" echo "! ! considered obsolete in (some far) future, when the" echo "! ! networking option of md5backup (or the successor of" echo "+-+ it will evolve. However for now it's all there is." while [ ! -d "$MD5B" ] do echo "+-+ The directory $MD5B" echo "! ! does not exist. This means, you have never run" echo "! !" echo "! ! bin/dobackup.sh" echo "! !" pressy "Shall I run it now" bin/dobackup.sh echo echo "+=+ OK, it has been run, continuing with sc-setup.sh" echo done do_mkdir "$HERE" do_mkdir "$MD5B/ln1" do_mkdir "$HERE/tmp" do_mkdir "$HERE/md5move" do_softlink ../md5backup/bin/sc-loop.sh do_softlink ../md5backup/bin/sc-backup.sh do_softlink ../md5backup/bin/sc-move.sh do_softlink ../md5backup/bin/sc-mysql.sh MYDIR="$HERE/md5move/mysql" if [ ! -x "$HERE/bin/$BINS" ] then bindir="`dirname "$0"`" bindir="`find_bin /usr/local "$HOME/bin" "$bindir"/../../scylla-charybdis-* "$@"`" if [ -z "$bindir" ] then echo echo "+-+ $BINS cannot be located on various places." echo "! ! Please give a path to it on the commandline." echo "+-+ STOP WITH ERROR" exit 1 fi bindir="`realpath "$bindir"`" do_softlink "$bindir" "$HERE/bin" fi echo info dirs= do_mkdir "$MYDIR" "The mysql backup directory is not created yet." "Without this directory mysql is not backed up." echo