forked from sartura/replica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.sh
105 lines (87 loc) · 2.48 KB
/
environment.sh
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
98
99
100
101
102
103
104
105
# SPDX-License-Identifier: MIT
#
# Copyright (c) 2021 Sartura Ltd.
#
# Local variables
#
ENVFILE=/run/environment
REPODIR=/var/db/repos/gentoo
TCECLASS=${REPODIR}/eclass/toolchain-funcs.eclass
J=$(grep -c ^processor /proc/cpuinfo)
# Inherit and export current dynamic environment
#
if [[ -f ${ENVFILE} ]]; then
set -a
source ${ENVFILE}
set +a
fi
# Sane defaults if dynamic variables are not set
#
[[ -z ${MAKEOPTS} ]] && MAKEOPTS="--jobs=${J}"
[[ -z ${EMERGE_DEFAULT_OPTS} ]] && EMERGE_DEFAULT_OPTS="--jobs=${J}"
# Additional helper variables
#
if [[ -n ${CTARGET} ]]; then
TPARCH=$(inherit() { :; }; EAPI=8; source ${TCECLASS}; tc-arch)
TKARCH=$(inherit() { :; }; EAPI=8; source ${TCECLASS}; tc-arch-kernel)
fi
# Additional helper functions
#
die() {
echo
echo -e "error: ${1}" >&2
exit 1
}
check_rootportage_dir() {
if [[ ! -d "${1}/etc/portage" ]]; then
return 1
fi
return 0
}
check_repo_dir() {
if [[ ! -d "${1}" || ! -d "${1}/metadata" ]]; then
return 1
fi
return 0
}
set_repository_conf() {
local ROOTDIR="${1%/}"
local REPO="${2%/}"
local PRIORITY="${3}"
local CONFDIR="${ROOTDIR}/etc/portage/repos.conf"
# is repo relative?
[[ "${REPO}" == "${REPO#/}" ]] && REPO="/var/db/repos/${REPO}"
local REPONAME="$(basename ${REPO})"
# sanity check
check_rootportage_dir "${ROOTDIR}" || die "${FUNCNAME[0]}: invalid portage dir"
check_repo_dir "${REPO}" || die "${FUNCNAME[0]}: invalid repo dir"
[[ -d ${CONFDIR} ]] || die "${FUNCNAME[0]}: invalid conf dir"
# create file
printf '[%s]\nlocation = %s' "${REPONAME}" "${REPO}" > ${CONFDIR}/${REPONAME}.conf \
|| die "${FUNCNAME[0]}"
# priority is a signed integer
if [[ "${PRIORITY}" =~ ^-?[0-9]+$ ]]; then
printf '\npriority = %s' "${PRIORITY}" >> ${CONFDIR}/${REPONAME}.conf \
|| die "${FUNCNAME[0]}"
fi
return 0
}
set_portage_profile() {
local ROOTDIR="${1%/}"
local REPO="${2%/}"
local PROFILE="${3}"
# is repo relative?
[[ "${REPO}" == "${REPO#/}" ]] && REPO=/var/db/repos/${REPO}
# sanity check
check_rootportage_dir "${ROOTDIR}" || die "${FUNCNAME[0]}: invalid portage dir"
check_repo_dir "${REPO}" || die "${FUNCNAME[0]}: invalid repo dir"
[[ -d "${REPO}/profiles/${PROFILE}" ]] || die "${FUNCNAME[0]}: invalid profile dir"
# replace profile
rm ${ROOTDIR}/etc/portage/make.profile || die "${FUNCNAME[0]}"
ln -s ${REPO}/profiles/${PROFILE} ${ROOTDIR}/etc/portage/make.profile \
|| die "${FUNCNAME[0]}"
return 0
}
# Export local environment
#
export MAKEOPTS EMERGE_DEFAULT_OPTS TPARCH TKARCH