summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/10_functions.inc
blob: e3c22bb089b10a4c088113931ef7e473312b40b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
### Funktionen ####################################

function xor()
{	local RES=($(echo "$1" | sed "s/../0x& /g"))
	shift 1
	while [[ "$1" ]]; do
		local ONE=($(echo "$1" | sed "s/../0x& /g"))
		local COUNT1=${#RES[@]}
		if [ $COUNT1 -lt ${#ONE[@]} ]; then
			COUNT1=${#ONE[@]}
		fi
		for (( i = 0; i < $COUNT1; i++ )); do
			RES[$i]=$((${ONE[$i]:-0} ^ ${RES[$i]:-0}))
		done
		shift 1
	done
	printf "%02x" "${RES[@]}"
}

function already_mounted()
{
	# Ausgabe: gemountet = true = 0, nicht gemountet = false = 1
	local AUSGANG
	mount | grep -q " ${1} " && AUSGANG=0 || AUSGANG=1 
	return $AUSGANG
}

function mounter()
{
	# Ausgabe: konnte mounten: 0, konnte nicht mounten: 1, schon gemountet 2
	already_mounted "$3"
	ERR=$?
	if [ "$ERR" -eq 0 ]; then
		logger "openslx sharemapper: $3 already mounted."
		AUSGANG=2	
	else	
		AUSGANG=0
		x=2
		while ! mount $1 $2 $3 2>/dev/null 1>&2; do
			logger "openslx sharemapper: could not mount ${2} to ${3}, waited another $x seconds, retrying."
			sleep $x
			if [ "$x" -gt 6 ]; then
				AUSGANG=1
				logger "openslx sharemapper: timeout, could not mount ${2} to ${3}."
				break
			fi
			let x=x+2
		done
		[ "$AUSGANG" -eq 0 ] 	&& logger "openslx sharemapper: ${2} mounted to ${3}."	# Todo: Schöner schreiben:)
	fi
	return $AUSGANG
}

### Funktionen Ende ###############################