Skip to content

Commit 234fda4

Browse files
committed
Optimize kernel compilation logic
1 parent 20fa632 commit 234fda4

File tree

3 files changed

+65
-61
lines changed

3 files changed

+65
-61
lines changed

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ runs:
205205
[[ -n "${{ inputs.armbian_fstype }}" ]] && make_command="${make_command} -t ${{ inputs.armbian_fstype }}"
206206
[[ -n "${{ inputs.armbian_size }}" ]] && make_command="${make_command} -s ${{ inputs.armbian_size }}"
207207
[[ -n "${{ inputs.builder_name }}" ]] && make_command="${make_command} -n ${{ inputs.builder_name }}"
208-
sudo ./rebuild ${make_command}
208+
read -r -a make_args <<< "${make_command}"
209+
sudo ./rebuild "${make_args[@]}"
209210
210211
cd ${{ github.action_path }}/${armbian_filepath}
211212
# Compress Armbian image file

compile-kernel/tools/script/armbian_compile_kernel.sh

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,12 @@ init_var() {
265265
error_msg "Invalid -l parameter [ ${2} ]!"
266266
fi
267267
;;
268-
-h | --DockerHostpath)
268+
# Ignore parameters used by the host system
269+
-h | -i)
269270
if [[ -n "${2}" ]]; then
270-
docker_hostpath="${2}"
271271
shift 2
272272
else
273-
error_msg "Invalid -h parameter [ ${2} ]!"
274-
fi
275-
;;
276-
-i | --DockerImage)
277-
if [[ -n "${2}" ]]; then
278-
docker_image="${2}"
279-
shift 2
280-
else
281-
error_msg "Invalid -i parameter [ ${2} ]!"
273+
error_msg "Invalid ${1} parameter [ ${2} ]!"
282274
fi
283275
;;
284276
--)
@@ -893,7 +885,7 @@ loop_recompile() {
893885
fi
894886

895887
# Show server start information
896-
echo -e "${INFO} Server space usage before starting to compile: \n$(df -hT ${kernel_path}) \n"
888+
echo -e "${INFO} Armbian space usage before starting to compile: \n$(df -hT ${kernel_path}) \n"
897889

898890
# Check disk space size
899891
echo -ne "(${j}) Start compiling the kernel [\033[92m ${kernel_version} \033[0m]. "
@@ -917,8 +909,9 @@ loop_recompile() {
917909
}
918910

919911
# Show welcome message
920-
echo -e "${STEPS} Welcome to compile kernel! \n"
921-
echo -e "${INFO} Server running on Armbian: [ Release: ${host_release} / Host: ${arch_info} ] \n"
912+
echo -e "${STEPS} Start compiling the kernel with Armbian..."
913+
echo -e "${INFO} The Armbian environment [ ${host_release} / ${arch_info} ]"
914+
922915
# Check script permission, supports running on Armbian system.
923916
[[ "$(id -u)" == "0" ]] || error_msg "Please run this script as root: [ sudo ./${0} ]"
924917
[[ "${arch_info}" == "aarch64" ]] || error_msg "The script only supports running under Armbian system."
@@ -950,5 +943,5 @@ echo -e "${INFO} Kernel List: [ $(echo ${build_kernel[@]} | xargs) ] \n"
950943
loop_recompile
951944

952945
# Show server end information
953-
echo -e "${STEPS} Server space usage after compilation: \n$(df -hT ${kernel_path}) \n"
954-
echo -e "${SUCCESS} All process completed successfully."
946+
echo -e "${STEPS} Armbian space usage after compilation: \n$(df -hT ${kernel_path}) \n"
947+
echo -e "${SUCCESS} Kernel compiled successfully"

recompile

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# This file is a part of the Rebuild Armbian
99
# https://github.com/ophub/amlogic-s9xxx-armbian
1010
#
11-
# Description: Run on the x86_64 and aarch64 platforms (ubuntu/debian), Compile the kernel.
11+
# Description: Compile the kernel with Armbian Docker container
1212
# Copyright (C) 2021~ https://www.kernel.org
1313
# Copyright (C) 2021~ https://github.com/unifreq
1414
# Copyright (C) 2021~ https://github.com/ophub/amlogic-s9xxx-armbian
@@ -18,16 +18,16 @@
1818
#
1919
#======================================= Functions list =======================================
2020
#
21-
# error_msg : Output error message
21+
# error_msg : Output error message
2222
#
23-
# init_var : Initialize all variables
24-
# install_docker : Install Docker engine
25-
# get_docker_image : Get Armbian Docker image
26-
# set_docker_env : Set up the Docker environment
23+
# init_var : Initialize all variables
24+
# install_docker_engine : Install Docker engine
25+
# launch_docker_container : Launch the Armbian Docker container
26+
# configure_and_compile : Configure the Docker environment and compile the kernel
2727
#
2828
#=============================== Set make environment variables ===============================
2929
#
30-
# Set current path and compile path
30+
# Set config and patch paths
3131
current_path="${PWD}/compile-kernel"
3232
config_path="${current_path}/tools/config"
3333
kernel_patch_path="${current_path}/tools/patch"
@@ -38,7 +38,7 @@ docker_image="ophub/armbian-trixie:arm64"
3838
docker_container="armbian-ophub"
3939
docker_script="/usr/sbin/armbian-kernel"
4040

41-
# Set the system file path to be used
41+
# Get host architecture and release info
4242
arch_info="$(uname -m)"
4343
host_id="$(cat /etc/os-release 2>/dev/null | grep '^ID=.*' | cut -d'=' -f2)"
4444
host_release="$(cat /etc/os-release 2>/dev/null | grep '^VERSION_CODENAME=.*' | cut -d'=' -f2)"
@@ -60,45 +60,48 @@ error_msg() {
6060
init_var() {
6161
echo -e "${STEPS} Start Initializing Variables..."
6262

63-
# Parse script parameters
64-
local args=("$@")
65-
local len=$#
63+
# If it is followed by [ : ], it means that the option requires a parameter value
64+
local options="k:a:n:m:p:r:t:c:d:s:z:l:g:h:i:"
65+
parsed_args=$(getopt -o "${options}" -- "${@}")
66+
[[ ${?} -ne 0 ]] && error_msg "Parameter parsing failed."
67+
eval set -- "${parsed_args}"
6668

67-
for ((i = 0; i < len; i++)); do
68-
current_arg="${args[i]}"
69-
next_arg="${args[i + 1]}"
70-
71-
case "${current_arg}" in
69+
while true; do
70+
case "${1}" in
7271
-h | --DockerHostpath)
73-
if [[ -n "${next_arg}" && "${next_arg}" != -* ]]; then
74-
docker_hostpath="${next_arg%/}"
75-
fi
72+
docker_hostpath="${2}"
73+
shift 2
7674
;;
7775
-i | --DockerImage)
78-
if [[ -n "${next_arg}" && "${next_arg}" != -* ]]; then
79-
docker_image="${next_arg}"
80-
fi
76+
docker_image="${2}"
77+
shift 2
78+
;;
79+
# Ignore parameters used by the Armbian Docker container
80+
-k | -a | -n | -m | -p | -r | -t | -c | -d | -s | -z | -l | -g)
81+
shift 2
82+
;;
83+
--)
84+
shift
85+
break
86+
;;
87+
*)
88+
[[ -n "${1}" ]] && error_msg "Invalid option [ ${1} ]!"
89+
break
8190
;;
8291
esac
8392
done
84-
85-
# Set Docker related paths
86-
compile_path="${docker_hostpath}/compile-kernel"
87-
ccache_path="${docker_hostpath}/ccache"
88-
[[ -d "${compile_path}" ]] || mkdir -p ${compile_path}
89-
[[ -d "${ccache_path}" ]] || mkdir -p ${ccache_path}
9093
}
9194

92-
install_docker() {
95+
install_docker_engine() {
9396
echo -e "${STEPS} Start installing Docker engine..."
9497

9598
curl -fsSL https://get.docker.com | sh
96-
sudo usermod -aG docker ${USER}
97-
sudo newgrp docker
99+
usermod -aG docker ${USER}
100+
newgrp docker
98101
}
99102

100-
get_docker_image() {
101-
echo -e "${STEPS} Start pulling the Docker image..."
103+
launch_docker_container() {
104+
echo -e "${STEPS} Start launching the Armbian Docker container..."
102105

103106
# Check if the Armbian Docker container is running
104107
if [[ "$(docker ps -q -f name=${docker_container})" ]]; then
@@ -114,6 +117,13 @@ get_docker_image() {
114117
echo -e "${INFO} Enable QEMU emulation for multi-architecture builds..."
115118
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 2>/dev/null || true
116119

120+
# Set Docker mount paths
121+
echo -e "${INFO} Setting up Docker host mount paths..."
122+
compile_path="${docker_hostpath}/compile-kernel"
123+
ccache_path="${docker_hostpath}/ccache"
124+
[[ -d "${compile_path}" ]] || mkdir -p ${compile_path}
125+
[[ -d "${ccache_path}" ]] || mkdir -p ${ccache_path}
126+
117127
# Pull the Armbian Docker image
118128
echo -e "${INFO} Start pulling the Docker image: [ ${docker_image} ]..."
119129
docker run -d --privileged \
@@ -128,8 +138,8 @@ get_docker_image() {
128138
fi
129139
}
130140

131-
set_docker_env() {
132-
echo -e "${STEPS} Start setting up the Docker environment..."
141+
configure_and_compile() {
142+
echo -e "${STEPS} Start configuring the Docker environment and compiling the kernel..."
133143

134144
echo -e "${INFO} Synchronize server time."
135145
ntpdate ntp.ubuntu.com 0.pool.ntp.org || true
@@ -149,24 +159,24 @@ set_docker_env() {
149159
docker exec -i "${docker_container}" ls -Alh /opt/kernel/compile-kernel/tools/patch/ || true
150160

151161
echo -e "${INFO} Start compiling the kernel inside the Docker container..."
152-
docker exec -i "${docker_container}" bash "${docker_script}" "$@"
162+
docker exec -i "${docker_container}" bash "${docker_script}" "${@}"
153163
}
154164

155165
# Show welcome message
156-
echo -e "${STEPS} Welcome to compile kernel!"
157-
echo -e "${INFO} Server running on ${host_id}: [ Release: ${host_release} / Host: ${arch_info} ] \n"
166+
echo -e "${STEPS} Welcome to compile kernel"
167+
echo -e "${INFO} The host environment [ ${host_id}: ${host_release} / ${arch_info} ]"
158168
# Check script permission
159169
[[ "$(id -u)" == "0" ]] || error_msg "Please run this script as root: [ sudo ./${0} ]"
160170

161171
# Initialize variables
162172
init_var "${@}"
163173
# Install Docker engine if it is not installed
164-
[[ -x "$(command -v docker)" ]] || install_docker
165-
# Get Armbian Docker image and start the container
166-
get_docker_image
167-
# Set up the Docker environment and start compiling the kernel
168-
set_docker_env "${@}"
174+
[[ -x "$(command -v docker)" ]] || install_docker_engine
175+
# Launch the Armbian Docker container
176+
launch_docker_container
177+
# Configure the Docker environment and compile the kernel
178+
configure_and_compile "${@}"
169179

170180
# Show server end information
171181
echo -e "${STEPS} Host space usage after compilation: \n$(df -hT ${docker_hostpath}) \n"
172-
echo -e "${SUCCESS} Kernel compilation completed successfully!"
182+
echo -e "${SUCCESS} All processes completed successfully"

0 commit comments

Comments
 (0)