-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchroot_bootstrap.sh
More file actions
executable file
·158 lines (120 loc) · 4.43 KB
/
chroot_bootstrap.sh
File metadata and controls
executable file
·158 lines (120 loc) · 4.43 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
# Get directory containing scripts
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$SCRIPT_DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
source "${SCRIPT_DIR}/utils.sh"
if [[ -z "${TARGET_PROFILE}" ]]; then
error "TARGET_PROFILE is undefined"
exit 1
fi
echo -e "${RESET}${GREEN}${BOLD}Nextoo Chroot Bootstrap Script${RESET} ${BOLD}version <TAG ME>${RESET}"
# Enable debug output if requested
[[ "${DEBUG}" == "true" ]] && set -x
status 'Updating environment...'
env-update
status 'Sourcing profile...'
source /etc/profile
if [[ $- == *i* ]]; then
status 'Configuring prompt...'
export PROMPT_COMMAND="export RETVAL=\${?}"
export PS1="\[$(tput bold)\]\[$(tput setaf 6)\][Nextoo] \[$(tput setaf 1)\]\u@\h \[$(tput setaf 4)\]\w \[$(tput setaf 3)\]\${RETVAL} \[$(tput setaf 7)\][\j] \[$(tput setaf 4)\]\\$\[$(tput sgr0)\] "
else
status 'Not configuring prompt (not a terminal)'
fi
status 'Locating make.conf...'
# Set default make.conf file location
MAKE_CONF="/etc/portage/make.conf"
# Make sure the make.conf location is set correctly
if [[ ! -f "${MAKE_CONF}" ]]; then
MAKE_CONF="/etc/make.conf"
if [[ ! -f "${MAKE_CONF}" ]]; then
# Is this even a gentoo install?
error "Unable to locate your system's make.conf"
exit 1
fi
fi
if ! egrep "^\s*MAKEOPTS=" "${MAKE_CONF}" >/dev/null; then
ncpus="$(($(nproc) + $(nproc) / 2))"
status "Configuring MAKEOPTS (-j${ncpus})..."
echo "MAKEOPTS=\"-j${ncpus}\"" >> "${MAKE_CONF}"
else
status "Skipped MAKEOPTS configuration (already defined in make.conf)"
fi
# ONLY DO THIS ON A BUILD MACHINE, CLIENTS MUST STILL ACKNOWLEDGE AND ACCEPT LICENSES!
if ! egrep "^\s*ACCEPT_LICENSE=" "${MAKE_CONF}" >/dev/null; then
status "Configuring ACCEPT_LICENSE"
echo "ACCEPT_LICENSE=\"*\"" >> "${MAKE_CONF}"
fi
if [[ "${NEXTOO_BUILD}" == 'true' ]]; then
if ! egrep '^\s*FEATURES=' "${MAKE_CONF}" | grep "buildpkg" >/dev/null; then
status "Enabling portage 'buildpkg' feature..."
echo 'FEATURES="${FEATURES} buildpkg"' >> "${MAKE_CONF}"
else
status "Skipping portage 'buildpkg' feature (already enabled)"
fi
fi
if [[ "${NEXTOO_CLEAN}" == "true" ]]; then
status "Disallowing binary package sources (clean build)..."
if ! egrep '^\s*FEATURES=' "${MAKE_CONF}" | grep "-getbinpkg" >/dev/null; then
status "Disabling portage 'getbinpkg' feature..."
echo 'FEATURES="${FEATURES} -getbinpkg"' >> "${MAKE_CONF}"
else
status "Skipping disabling of portage 'getbinpkg' feature (already disabled)"
fi
fi
status "Creating missing directories..."
status ".../run/lock"
run mkdir -p /run/lock
status ".../run/shm"
run mkdir -p /run/shm
status "Mounting /run/shm as a tmpfs"
run mount -t tmpfs -o mode=1777 tmpfs /run/shm
if grep "time zone must be set" /etc/localtime >/dev/null; then
status "Updating timezone to 'America/Los_Angeles'..."
cd /etc
run rm localtime
run ln -s ../usr/share/zoneinfo/America/Los_Angeles localtime
cd - >/dev/null
else
status "Not touching timezone"
fi
status "Adding Nextoo overlay..."
run "${SCRIPT_DIR}/nextoo_repo_conf.sh"
# Temporary debug stuffs
status "Printing emerge info..."
run emerge --info
status "Setting profile to Nextoo ${TARGET_PROFILE} (${ARCH})..."
# Might want to check to see if the profile is already set. Use eselect profile show...
eselect profile set nextoo:default/linux/${ARCH}/${TARGET_PROFILE}
status "Environment setup complete"
# Temporary debug stuffs
status "Printing emerge info..."
run emerge --info
# Nope. Not anymore.
#status "Merging Nextoo kernel (prerequisite for some packages)..."
# run emerge -1Nu sys-kernel/nextoo-kernel
status "Checking for profile-specific bootstrap.sh in /etc/portage/make.profile/..."
if [[ -x /etc/portage/make.profile/bootstrap.sh ]]; then
status "Executing profile-specific bootstrap.sh..."
run /etc/portage/make.profile/bootstrap.sh
else
status "No profile-specific bootstrap.sh"
fi
# Temporary debug stuffs
status "Printing emerge info..."
run emerge --info
status "Emerging world..."
emerge -DNu @world
status "Emerge complete!"
# Check some flag for pushing binaries to a repo
if [[ "${WANTSHELL}" != "true" ]]; then
status "Exiting chroot..."
exit 0
fi
cd "${HOME}"
set +e