11
11
# Description: Build Armbian rootfs file.
12
12
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
13
13
#
14
- # Command: ./compile-kernel/tools/script/docker/build_armbian_rootfs_file.sh -v <VERSION_CODENAME>
15
- # ./compile-kernel/tools/script/docker/build_armbian_rootfs_file.sh -v bookworm
14
+ # Optional parameters:
15
+ # -v, --VERSION_CODENAME: Set the version codename of Armbian rootfs file, e.g., bookworm, jammy, etc.
16
+ # -s, --SSHD_CONFIG: Enable or disable sshd_config file, default is false.
17
+ # -c, --COMMAND_COLORS: Enable or disable command colors, default is false.
18
+ # -u, --UBOOT_CONVERSION: Enable or disable u-boot conversion script, default is false.
19
+ #
20
+ # Usage: ./compile-kernel/tools/script/docker/build_armbian_rootfs_file.sh -v bookworm -s true -c true -u true
21
+ # ./compile-kernel/tools/script/docker/build_armbian_rootfs_file.sh -v bookworm
16
22
#
17
23
# ===================== Set make environment variables =====================
18
24
#
@@ -29,6 +35,7 @@ STEPS="[\033[95m STEPS \033[0m]"
29
35
INFO=" [\033[94m INFO \033[0m]"
30
36
SUCCESS=" [\033[92m SUCCESS \033[0m]"
31
37
WARNING=" [\033[93m WARNING \033[0m]"
38
+ NOTE=" [\033[93m NOTE \033[0m]"
32
39
ERROR=" [\033[91m ERROR \033[0m]"
33
40
#
34
41
# ==========================================================================
@@ -42,7 +49,7 @@ init_var() {
42
49
echo -e " ${STEPS} Start Initializing Variables..."
43
50
44
51
# If it is followed by [ : ], it means that the option requires a parameter value
45
- local options=" v:"
52
+ local options=" v:s:c:u: "
46
53
parsed_args=$( getopt -o " ${options} " -- " ${@ } " )
47
54
[[ ${?} -ne 0 ]] && error_msg " Parameter parsing failed."
48
55
eval set -- " ${parsed_args} "
@@ -57,6 +64,30 @@ init_var() {
57
64
error_msg " Invalid -v parameter [ ${2} ]!"
58
65
fi
59
66
;;
67
+ -s | --SSHD_CONFIG)
68
+ if [[ -n " ${2} " ]]; then
69
+ sshd_config_enable=" ${2} "
70
+ shift 2
71
+ else
72
+ error_msg " Invalid -s parameter [ ${2} ]!"
73
+ fi
74
+ ;;
75
+ -c | --COMMAND_COLORS)
76
+ if [[ -n " ${2} " ]]; then
77
+ command_colors=" ${2} "
78
+ shift 2
79
+ else
80
+ error_msg " Invalid -c parameter [ ${2} ]!"
81
+ fi
82
+ ;;
83
+ -u | --UBOOT_CONVERSION)
84
+ if [[ -n " ${2} " ]]; then
85
+ uboot_conversion=" ${2} "
86
+ shift 2
87
+ else
88
+ error_msg " Invalid -u parameter [ ${2} ]!"
89
+ fi
90
+ ;;
60
91
--)
61
92
shift
62
93
break
@@ -96,30 +127,37 @@ redo_rootfs() {
96
127
97
128
cd ${tmp_rootfs} /
98
129
99
- # SSH access is enabled by default
100
- ssh_config=" etc/ssh/sshd_config"
101
- [[ -f " ${ssh_config} " ]] && {
102
- sudo sed -i " s|^#*Port .*|Port 22|g" ${ssh_config}
103
- sudo sed -i " s|^#*PermitRootLogin .*|PermitRootLogin yes|g" ${ssh_config}
104
- sudo sed -i " s|^#*PasswordAuthentication .*|PasswordAuthentication yes|g" ${ssh_config}
105
- [[ -d " var/run/sshd" ]] || mkdir -p -m0755 var/run/sshd
106
- echo -e " ${INFO} 03. Adjusting sshd_config completed."
107
- } || error_msg " 03. Failed to adjust sshd_config!"
108
-
109
- # Set root password to 1234
110
- [[ -f " etc/shadow" ]] && {
111
- rootnewpasswd=" $( openssl passwd -6 " 1234" ) "
112
- sudo sed -i " s|^root:\*|root:${rootnewpasswd} |" etc/shadow
113
- echo -e " ${INFO} 04. Adjusting the default account completed."
114
- } || error_msg " 04. Failed to adjust root password!"
115
-
116
- # Set terminal colors
117
- [[ -f " usr/bin/dircolors" ]] && {
118
- # Set the default color for command
119
- sudo chmod +x usr/bin/dircolors
120
-
121
- # Add color support for command and set the default prompt
122
- sudo tee -a root/.bashrc > /dev/null << 'EOF '
130
+ # Set sshd_config
131
+ if [[ -n " ${sshd_config_enable} " && " ${sshd_config_enable} " =~ ^(true| yes)$ ]]; then
132
+ # SSH access is enabled by default
133
+ ssh_config=" etc/ssh/sshd_config"
134
+ [[ -f " ${ssh_config} " ]] && {
135
+ sudo sed -i " s|^#*Port .*|Port 22|g" ${ssh_config}
136
+ sudo sed -i " s|^#*PermitRootLogin .*|PermitRootLogin yes|g" ${ssh_config}
137
+ sudo sed -i " s|^#*PasswordAuthentication .*|PasswordAuthentication yes|g" ${ssh_config}
138
+ [[ -d " var/run/sshd" ]] || mkdir -p -m0755 var/run/sshd
139
+ echo -e " ${INFO} 03.01 Adjusting sshd_config completed."
140
+ } || error_msg " 03.01 Failed to adjust sshd_config!"
141
+
142
+ # Set root password to 1234
143
+ [[ -f " etc/shadow" ]] && {
144
+ rootnewpasswd=" $( openssl passwd -6 " 1234" ) "
145
+ sudo sed -i " s|^root:\*|root:${rootnewpasswd} |" etc/shadow
146
+ echo -e " ${INFO} 03.02 Adjusting the default account completed."
147
+ } || error_msg " 03.02 Failed to adjust root password!"
148
+ else
149
+ echo -e " ${NOTE} 03. Skipping sshd_config adjustment."
150
+ fi
151
+
152
+ # Set command colors
153
+ if [[ -n " ${command_colors} " && " ${command_colors} " =~ ^(true| yes)$ ]]; then
154
+ # Set terminal colors
155
+ [[ -f " usr/bin/dircolors" ]] && {
156
+ # Set the default color for command
157
+ sudo chmod +x usr/bin/dircolors
158
+
159
+ # Add color support for command and set the default prompt
160
+ sudo tee -a root/.bashrc > /dev/null << 'EOF '
123
161
124
162
# enable color support of ls and also add handy aliases
125
163
if [ -x /usr/bin/dircolors ]; then
134
172
PS1='\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\$ '
135
173
136
174
EOF
137
- # Add the bashrc file to the root profile
138
- sudo tee -a root/.profile > /dev/null << 'EOF '
175
+ # Add the bashrc file to the root profile
176
+ sudo tee -a root/.profile > /dev/null << 'EOF '
139
177
140
178
if [ -f "$HOME/.bashrc" ]; then
141
179
. "$HOME/.bashrc"
142
180
fi
143
181
144
182
EOF
145
- echo -e " ${INFO} 05. Adjusting the default color completed."
146
- } || error_msg " 05. Failed to adjust dircolors!"
183
+ echo -e " ${INFO} 04. Adjusting the default color completed."
184
+ } || error_msg " 04. Failed to adjust dircolors!"
185
+ else
186
+ echo -e " ${NOTE} 04. Skipping sshd_config adjustment."
187
+ fi
188
+
189
+ # Adjust u-boot conversion script
190
+ if [[ -n " ${uboot_conversion} " && " ${uboot_conversion} " =~ ^(true| yes)$ ]]; then
191
+ sudo mkdir -p etc/initramfs/post-update.d/
192
+ sudo chown root:root etc/initramfs/post-update.d/
193
+ sudo tee etc/initramfs/post-update.d/99-uboot > /dev/null << 'EOF '
194
+ #!/bin/bash -e
195
+
196
+ tempname="/boot/uInitrd-$1"
197
+ echo "update-initramfs: Armbian: Converting to u-boot format: ${tempname}" >&2
198
+ mkimage -A arm64 -O linux -T ramdisk -C gzip -n uInitrd -d $2 $tempname
199
+
200
+ echo "update-initramfs: Armbian: Symlinking ${tempname} to /boot/uInitrd" >&2
201
+ ln -sfv $(basename $tempname) /boot/uInitrd || {
202
+ echo "update-initramfs: Symlink failed, moving ${tempname} to /boot/uInitrd" >&2
203
+ mv -v $tempname /boot/uInitrd
204
+ }
205
+
206
+ echo "update-initramfs: Armbian: done." >&2
207
+
208
+ exit 0
209
+
210
+ EOF
211
+ sudo chmod +x etc/initramfs/post-update.d/99-uboot
212
+ [[ " ${?} " == " 0" ]] && echo -e " ${INFO} 05. Adding uInitrd generation script completed." || error_msg " 06. Failed to adjust uInitrd!"
213
+ else
214
+ echo -e " ${NOTE} 05. Skipping uInitrd adjustment."
215
+ fi
147
216
148
217
# Compress the rootfs file
149
218
sudo tar -czf ${rootfs_save_name} .tar.gz *
0 commit comments