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
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
3131current_path=" ${PWD} /compile-kernel"
3232config_path=" ${current_path} /tools/config"
3333kernel_patch_path=" ${current_path} /tools/patch"
@@ -38,7 +38,7 @@ docker_image="ophub/armbian-trixie:arm64"
3838docker_container=" armbian-ophub"
3939docker_script=" /usr/sbin/armbian-kernel"
4040
41- # Set the system file path to be used
41+ # Get host architecture and release info
4242arch_info=" $( uname -m) "
4343host_id=" $( cat /etc/os-release 2> /dev/null | grep ' ^ID=.*' | cut -d' =' -f2) "
4444host_release=" $( cat /etc/os-release 2> /dev/null | grep ' ^VERSION_CODENAME=.*' | cut -d' =' -f2) "
@@ -60,45 +60,48 @@ error_msg() {
6060init_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
162172init_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
171181echo -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