#!/bin/sh # Copyright (C) 2007 Krzysztof Kozlowski # License: GNU General Public License version 2 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # version 2 as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # # Homepage: http://www.kozik.net.pl # # Last change: 8.04.2007 # # Useful functions. # # Usage: die [message] [error_code] die() { echo $1 if [ $# -eq 2 ]; then exit $2 fi exit 1 } # Usage: find_free_loop_dev # return: device node name (/dev/loopX) find_free_loop_dev() { _dev="/dev/loop" for i in 0 1 2 3 4 5 6 7 ; do is_used=`losetup -a | grep ${_dev}/${i}` if [ "$is_used" == "" ]; then echo ${_dev}${i} return fi done echo "" return } # Usage: absolute_pathname pathname absolute_pathname() { cd $1 || exit $? pwd return } # Usage: trim_string string trim_string() { echo `echo "$1" | sed -e 's/^ *//' -e 's/ *$//'` return }