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


Auto_build_config ()
{
	# Automatically build config
	if [ -x auto/config ] && [ ! -e .build/config ]; then
		Echo_message "Automatically populating config tree."
		lb config
	fi
}

Init_config_data ()
{
	Arguments "${@}"

	Read_conffiles $(Common_conffiles)
	Prepare_config

	# Apt v2.0.1 introduced color support, but it needs to be explicitly enabled.
	# This is done here so that the injection of the option does not get stored in the config file.
	if [ "${_COLOR_OUT}" = "true" ] && [ "${_COLOR_ERR}" = "true" ]; then
		APT_OPTIONS="${APT_OPTIONS} -o APT::Color=true"
		APTITUDE_OPTIONS="${APTITUDE_OPTIONS} -o APT::Color=true"
	else
		APT_OPTIONS="${APT_OPTIONS} -o APT::Color=false"
		APTITUDE_OPTIONS="${APTITUDE_OPTIONS} -o APT::Color=false"
	fi
}

# "Auto" script redirection.
#
# As a matter of convenience users can have a set of saved commandline options
# which will be automatically included in every execution of live-build. How
# this works is that the save file is itself a shell script saved in the config
# directory (one per top-level live-build command in fact). When `lb config`,
# `lb build` or `lb clean` is run, these scripts, if they see that an "auto"
# file exists in the config, they run that file, passing along any user
# arguments, and terminate once that ends. The "auto" script simply re-executes
# the same command (e.g. `lb config`), only with a first param of "noauto",
# used to stop an infinite loop of further redirection, then a fixed saved set
# of command line options, as saved in the file by the user, then any
# additional command line arguments passed into the script. This is simply a
# means of injecting a saved set of command line options into the execution of
# live-build.
#
# As for this function, it is a simple helper, used by the top-level commands
# to perform the redirection if the relevant "auto" file exists. It should only
# be called if the calling command script was not run with "noauto" as the
# first argument (the purpose of which was just described).
Maybe_auto_redirect ()
{
	local TYPE="${1}"; shift

	case "${TYPE}" in
		clean|config|build)
			;;
		*)
			Echo_error "Unknown auto redirect type"
			exit 1
			;;
	esac

	local AUTO_SCRIPT="auto/${TYPE}"
	if [ -x "${AUTO_SCRIPT}" ]; then
		Echo_message "Executing ${AUTO_SCRIPT} script."
		./"${AUTO_SCRIPT}" "${@}"
		exit ${?}
	elif [ -f "${AUTO_SCRIPT}" ]; then
		Echo_warning "The ${AUTO_SCRIPT} script exists but is not executable, ignoring."
	fi
}