1 # Copyright 2011 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # The views and conclusions contained in the software and documentation are
27 # those of the authors and should not be interpreted as representing official
28 # policies, either expressed or implied, of GRNET S.A.
33 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
42 echo "ERROR: $@" | tee $RESULT >&2
49 if [ -e "$root_dir/etc/debian_version" ]; then
51 elif [ -e "$root_dir/etc/redhat-release" ]; then
53 elif [ -e "$root_dir/etc/slackware-version" ]; then
55 elif [ -e "$root_dir/SuSE-release" ]; then
57 elif [ -e "$root_dir/gentoo-release" ]; then
65 if [ -e "$root_dir/etc/debian_version" ]; then
67 if [ -e ${root_dir}/etc/lsb-release ]; then
68 ID=$(grep $DISTRIB_ID=${root_dir}/etc/lsb-release | cut -d= -f2)
69 if [ "x$ID" = "xUbuntu" ]; then
74 elif [ -e "$root_dir/etc/fedora-release" ]; then
76 elif [ -e "$root_dir/etc/centos-release" ]; then
78 elif [ -e "$root_dir/etc/redhat-release" ]; then
80 elif [ -e "$root_dir/etc/slackware-version" ]; then
82 elif [ -e "$root_dir/SuSE-release" ]; then
84 elif [ -e "$root_dir/gentoo-release" ]; then
90 # if something fails here, it souldn't call cleanup again...
93 if [ ${#CLEANUP[*]} -gt 0 ]; then
94 LAST_ELEMENT=$((${#CLEANUP[*]}-1))
95 REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0)
96 for i in $REVERSE_INDEXES; do
97 # If something fails here, it's better to retry it for a few times
98 # before we give up with an error. This is needed for kpartx when
99 # dealing with ntfs partitions mounted through fuse. umount is not
100 # synchronous and may return while the partition is still busy. A
101 # premature attempt to delete partition mappings through kpartx on a
102 # device that hosts previously mounted ntfs partition may fail with
103 # an `device-mapper: remove ioctl failed: Device or resource busy'
104 # error. A sensible workaround for this is to wait for a while and
106 local cmd=${CLEANUP[$i]}
107 $cmd || for interval in 0.25 0.5 1 2 4; do
108 echo "Command $cmd failed!"
109 echo "I'll wait for $interval secs and will retry..."
113 if [ "$?" != "0" ]; then
123 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :