summaryrefslogtreecommitdiff
path: root/functions
blob: ab88827beb80c39c2d667abc53c5f84b2858bc9d (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
#
# functions
#

STAT_COL=$[`stty size | awk 'BEGIN { RS=" " }; END { print $1 }'` - 12]

deltext() {
	echo -ne "\033[$(($STAT_COL+4))G"
}

stat_busy() {
	if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
		echo -ne "\033[1;32m| \033[1;37m$1\033[1;0m "
		awk "BEGIN { for (j=length(\"$1\"); j<$STAT_COL; j++) printf \" \" }"
		echo -ne "   \033[1;34m[\033[1;33mbusy\033[1;34m]\033[1;0m"
	else
		echo -n "| $1 "
		awk "BEGIN { for (j=length(\"$1\"); j<$STAT_COL; j++) printf \" \" }"
		echo -n "   [busy]"
	fi
}

stat_done() {
	deltext
	if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
		echo -e "   \033[1;34m[\033[1;32mdone\033[1;34m]\033[1;0m"
	else
		echo "   [done]"
	fi
}

stat_fail() {
	deltext
	if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
		echo -e "   \033[1;34m[\033[1;31mfail\033[1;34m]\033[1;0m"
	else
		echo "   [fail]"
	fi
}

stat_die() {
	retval=1
	[ "$1" = "" ] || retval=$1
	stat_fail
	exit $retval
}

#
# here for legcay reasons: use 'status' instead
#
checkret() {
	$* >/dev/null 2>&1
	if [ $? -gt 0 ]; then
		stat_fail
		return 0
	else
		stat_done
		return 1
	fi
}

status() {
	stat_busy "$1"
	shift
	$* >/dev/null 2>&1
	if [ $? -eq 0 ]; then
		stat_done
		return 0
	else
		stat_fail
		return 1
	fi
}

add_daemon() {
	[ -d /var/run/daemons ] || mkdir -p /var/run/daemons
	touch /var/run/daemons/$1
}

rm_daemon() {
	rm -f /var/run/daemons/$1
}

ck_daemon() {
	if [ -f /var/run/daemons/$1 ]; then
		return 1
	else
		return 0
	fi
}

# End of file