forked from ophub/amlogic-s9xxx-armbian
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_armbian_docker_image.sh
More file actions
executable file
·94 lines (84 loc) · 3.36 KB
/
Copy pathbuild_armbian_docker_image.sh
File metadata and controls
executable file
·94 lines (84 loc) · 3.36 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
#!/bin/bash
#================================================================================================
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the Rebuild Armbian
# https://github.com/ophub/amlogic-s9xxx-armbian
#
# Description: Build Armbian docker image.
# Copyright (C) 2021~ https://github.com/ophub/amlogic-s9xxx-armbian
#
#
# Command: ./compile-kernel/tools/script/docker/build_armbian_docker_image.sh
#
#======================================== Functions list ========================================
#
# error_msg : Output error message
# find_armbian : Find Armbian file (armbian/*rootfs.tar.gz)
# build_docker : Build Armbian docker image
#
#================================ Set make environment variables ================================
#
# Set default parameters
current_path="${PWD}"
armbian_path="${current_path}/armbian"
armbian_rootfs_file="*rootfs.tar.gz"
docker_path="${current_path}/compile-kernel/tools/script/docker"
out_path="${current_path}/out"
# Set default parameters
STEPS="[\033[95m STEPS \033[0m]"
INFO="[\033[94m INFO \033[0m]"
SUCCESS="[\033[92m SUCCESS \033[0m]"
WARNING="[\033[93m WARNING \033[0m]"
ERROR="[\033[91m ERROR \033[0m]"
#
#================================================================================================
error_msg() {
echo -e "${ERROR} ${1}"
exit 1
}
find_armbian() {
cd ${current_path}
echo -e "${STEPS} Start searching for Armbian file..."
# Find whether the Armbian file exists
armbian_file_name="$(ls ${armbian_path}/${armbian_rootfs_file} 2>/dev/null | head -n 1 | awk -F "/" '{print $NF}')"
if [[ -n "${armbian_file_name}" ]]; then
version_codename="$(echo "${armbian_file_name}" | awk -F'[_-]' '{print $3}')"
echo -e "${INFO} Armbian file: [ ${armbian_file_name} ], version codename: [ ${version_codename} ]"
else
error_msg "There is no [ ${armbian_rootfs_file} ] file in the [ ${armbian_path} ] directory."
fi
# Check whether the Dockerfile exists
[[ -f "${docker_path}/Dockerfile" ]] || error_msg "Missing Dockerfile."
}
build_docker() {
cd ${current_path}
echo -e "${STEPS} Start building Armbian docker image..."
# Move the docker image to the output directory
rm -rf ${out_path} && mkdir -p ${out_path}
mv -f ${armbian_path}/${armbian_file_name} ${out_path}/armbian-${version_codename}-rootfs.tar.gz
[[ "${?}" -eq "0" ]] || error_msg "Docker image move failed."
echo -e "${INFO} Docker rootfs file added successfully."
# Add Dockerfile
cp -f ${docker_path}/Dockerfile ${out_path}
[[ "${?}" -eq "0" ]] || error_msg "Dockerfile addition failed."
sed -i "s|^ADD armbian-.*.tar.gz|ADD armbian-${version_codename}-rootfs.tar.gz|g" ${out_path}/Dockerfile
[[ "${?}" -eq "0" ]] || error_msg "Dockerfile version codename replacement failed."
echo -e "${INFO} Dockerfile added successfully."
# Display the output directory
sync && sleep 3
echo -e "${INFO} Docker files list: \n$(ls -lh ${out_path})"
echo -e "${SUCCESS} Docker image created successfully."
}
# Show welcome message
echo -e "${STEPS} Welcome to the Armbian Docker Image Builder."
echo -e "${INFO} Make path: [ ${PWD} ]"
#
find_armbian
build_docker
#
# All process completed
wait