summaryrefslogtreecommitdiffstats
path: root/manager/scripts/_env.sh
blob: 52697ca0b8c73e9dc6a7d457f86f3a2387391499 (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
# fail on errors
set -o errexit

# define color codes
red="\033[0;31m"
yellow="\033[0;33m"
green="\033[0;32m"
bright_black="\033[0;90m"
blue="\033[0;34m"
reset="\033[0m"

# ensure consistent top level directory
gitroot="$(git rev-parse --show-toplevel)"
if test -z "$gitroot"; then
	echo -e "${red}This command can be run only in a git repository tree.${reset}"
	exit 1
fi
cd $gitroot/manager

# ensure consistent environment with virtualenv
if test -z "$VIRTUAL_ENV" -a "$CI" != "true" -a -z "$KNOT_ENV"; then
	echo -e "${yellow}You are NOT running the script within the project's virtual environment.${reset}"
	echo -e "Do you want to continue regardless? [yN]"
	read cont
	if test "$cont" != "y" -a "$cont" != "Y"; then
		echo -e "${red}Exiting early...${reset}"
		exit 1
	fi
fi

# update PATH with node_modules
PATH="$PATH:$gitroot/node_modules/.bin"

# fail even on unbound variables
set -o nounset


function build_kresd {
	echo
	echo Building Knot Resolver
	echo ----------------------
	echo -e "${blue}In case of an compilation error, run this command to try to fix it:${reset}"
	echo -e "\t${blue}rm -r $(realpath .install_kresd) $(realpath .build_kresd)${reset}"
	echo
	pushd ..
	mkdir -p manager/.build_kresd manager/.install_kresd
	meson manager/.build_kresd --prefix=$(realpath manager/.install_kresd) --default-library=static --buildtype=debug
	ninja -C manager/.build_kresd
	ninja install -C manager/.build_kresd
	export PATH="$(realpath manager/.install_kresd)/sbin:$PATH"
	popd
}

function build_kresd_new_policy {
	echo
	echo Building Knot Resolver
	echo ----------------------
	echo -e "${blue}In case of an compilation error, run this command to try to fix it:${reset}"
	echo -e "\t${blue}rm -r $(realpath .install_kresd) $(realpath .build_kresd)${reset}"
	echo


	pushd ..
	rm -rf manager/.install_kresd manager/.build_kresd
	mkdir -p manager/.build_kresd manager/.install_kresd

	if [ -d "kres-new-policy" ]
	then
	echo updating repository...
	cd kres-new-policy
	git pull
	else
	echo cloning repository...
	git clone -b new-policy https://gitlab.nic.cz/knot/knot-resolver.git kres-new-policy
	cd kres-new-policy
	git submodule update --init --recursive
	fi

	meson setup ../manager/.build_kresd --prefix=$(realpath ../manager/.install_kresd) --default-library=static --buildtype=debug
	ninja -C ../manager/.build_kresd
	ninja install -C ../manager/.build_kresd
	cd ..
	export PATH="$(realpath manager/.install_kresd)/sbin:$PATH"
	popd
}