123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- #!/bin/bash
- export TERM=xterm
- RED=$(tput setaf 1)
- GREEN=$(tput setaf 2)
- YELLOW=$(tput setaf 3)
- NORMAL=$(tput op)
- die() {
- echo -e "${RED}$1${NORMAL}"
- exit 1
- }
- execute()
- {
- cmd=${1}
- echo $cmd >>$LOGFILE 2>&1
- $cmd >>$LOGFILE 2>&1
- status=$?
- [ "$2" != 0 ] && log_status $status
- if [ $status != 0 ]; then
- echo
- echo "! Command $cmd failed, exiting (status $status)"
- echo "! Check why here $LOGFILE"
- exit 1
- fi
- }
- execute_chroot()
- {
- execute "chroot $LOOPDIR env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $@"
- }
- echo_ok()
- {
- echo -e "${GREEN}$1${NORMAL}"
- }
- echo_failed()
- {
- echo -e "${RED}$1${NORMAL}"
- }
- echo_warn()
- {
- echo -e "${YELLOW}$1${NORMAL}"
- }
- log_action()
- {
- /bin/echo -n "[....] $1 "
- }
- log_status()
- {
- tput hpa 0
- if [ $1 -eq 0 ]; then
- /bin/echo -ne "[${GREEN} ok ${NORMAL}"
- else
- /bin/echo -ne "[${RED}FAIL${NORMAL}"
- fi
- echo
- }
- declare -a on_exit_items
- on_exit()
- {
- for ((onex=${#on_exit_items[@]}-1; onex>=0; onex--))
- do
- echo "On_Exit: ${on_exit_items[$onex]}" >>$LOGFILE
- ${on_exit_items[$onex]} >>$LOGFILE 2>&1
- done
- on_exit_items=""
- trap - EXIT
- }
- do_on_exit()
- {
- local n=${#on_exit_items[*]}
- on_exit_items[$n]="$*"
- if [ $n -eq 0 ]; then
- trap on_exit EXIT
- fi
- }
- graceful_umount()
- {
- secs=$2
- [ ! $secs ] && secs=5
- let steps=$secs*100
- for st in `seq 1 $steps`
- do
- umount $1 >>$LOGFILE 2>&1
- mount | grep $1 >/dev/null 2>&1
- [ $? -eq 0 ] || return 0
- sleep 0.01
- done
- return 1
- }
- load_qemu_nbd()
- {
- lsmod | grep ^nbd[[:space:]]* >/dev/null 2>&1
- if [ $? != 0 ]
- then
- log_action "Loading NBD kernel module"
- execute "modprobe nbd max_part=16"
- fi
- }
- check_commands()
- {
- for i in $*
- do
- command -v $i >/dev/null || { die "Required command $i not found"; exit 1; }
- done
- }
- running_any()
- {
- command -v virsh >/dev/null || return 1
- for host in $*
- do
- virsh list --name 2>/dev/null | grep "^$host$" >/dev/null && return 0
- done
- return 1
- }
- function searchandreplace {
- SEARCHSTRING="$1"
- REPLACESTRING="$2"
- DESTDIR="$3"
- [ -d "$DESTDIR" ] || die "$DESTDIR is not a directory!"
-
-
-
-
- for eachfoundfile in `find $DESTDIR -type f`
- do
- sed -i -e "s/$SEARCHSTRING/$REPLACESTRING/g" "$eachfoundfile"
- done
- }
|