summaryrefslogtreecommitdiff
path: root/functions/echo.sh
blob: a46f036a6ba7766696ea7ceabbb75c8c7edb72b4 (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
#!/bin/sh

## live-build(7) - System Build Scripts
## Copyright (C) 2016-2020 The Debian Live team
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.

exec 3>&1

Echo ()
{
	local STRING="${1}"
	shift

	printf "${STRING}\n" "${@}" >&3
}

Echo_debug ()
{
	if [ "${_DEBUG}" = "true" ]; then
		local STRING="${1}"
		shift

		printf "D: ${STRING}\n" "${@}" >&3
	fi
}

Echo_error ()
{
	local STRING="${1}"
	shift

	local PREFIX="${RED}E${NO_COLOR}"
	if [ "${_COLOR_ERR}" = "false" ]; then
		PREFIX="E"
	fi

	printf "${PREFIX}: ${STRING}\n" "${@}" >&2
}

Echo_message ()
{
	if [ "${_QUIET}" != "true" ]
	then
		local STRING="${1}"
		shift

		local PREFIX="${PURPLE}P${NO_COLOR}"
		if [ "${_COLOR_OUT}" = "false" ]; then
			PREFIX="P"
		fi

		printf "${PREFIX}: ${STRING}\n" "${@}" >&3
	fi
}

Echo_verbose ()
{
	if [ "${_VERBOSE}" = "true" ]; then
		local STRING="${1}"
		shift

		printf "I: ${STRING}\n" "${@}" >&3
	fi
}

Echo_warning ()
{
	local STRING="${1}"
	shift

	local PREFIX="${YELLOW}W${NO_COLOR}"
	if [ "${_COLOR_ERR}" = "false" ]; then
		PREFIX="W"
	fi

	printf "${PREFIX}: ${STRING}\n" "${@}" >&2
}

Echo_file ()
{
	local LINE
	while read -r LINE
	do
		echo "${1}: ${LINE}" >&3
	done < "${1}"
}