summaryrefslogtreecommitdiff
path: root/functions
blob: ec3e9860dac577660747f9277a139a37b89964bf (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
94
95
96
97
#!/bin/bash
#
# functions
#

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

# colors:

if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then

	C_MAIN="\033[1;37m"       # main text
	C_OTHER="\033[1;34m"      # prefix & brackets
	C_SEPARATOR="\033[1;30m"  # separator
	
	C_BUSY="\033[0;36m"		# busy
	C_FAIL="\033[1;31m"		# failed
	C_DONE="\033[1;37m"		# completed
	
	C_H1="\033[1;37m"		# highlight text 1
	C_H2="\033[1;36m"		# highlight text 2
	
	C_CLEAR="\033[1;0m"
fi

# prefixes:

PREFIX_REG="::"
PREFIX_HL=" >"

# functions:

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

printhl() {
	echo -e "$C_OTHER$PREFIX_HL $C_H1$1$C_CLEAR "
}

printsep() {
	echo -e "\n$C_SEPARATOR   ------------------------------\n"
}

stat_busy() {
	echo -ne "$C_OTHER$PREFIX_REG $C_MAIN$1$C_CLEAR "
	deltext
	echo -ne "   $C_OTHER[${C_BUSY}BUSY$C_OTHER]$C_CLEAR "
}

stat_done() {
	deltext
	echo -e "   $C_OTHER[${C_DONE}DONE$C_OTHER]$C_CLEAR "
}

stat_fail() {
	deltext
	echo -e "   $C_OTHER[${C_FAIL}FAIL$C_OTHER]$C_CLEAR "
}

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

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

# daemons:

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() {
	[ -f /var/run/daemons/$1 ] && return 1
	return 0
}

# End of file