Skip to content

Commit c081c0d

Browse files
committed
Adjust rootfs settings to optional parameters
1 parent b893e3f commit c081c0d

File tree

3 files changed

+102
-33
lines changed

3 files changed

+102
-33
lines changed

.github/workflows/build-armbian.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ jobs:
322322
run: |
323323
# Organize and keep essential files, delete unnecessary files
324324
chmod +x ${ROOTFS_SCRIPT}
325-
${ROOTFS_SCRIPT} -v ${{ inputs.set_release }}
325+
${ROOTFS_SCRIPT} -v ${{ inputs.set_release }} -s true -c true -u true
326326
327327
# Output cleaning result information
328328
df -hT ${PWD}

.github/workflows/build-homeassistant.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ jobs:
331331
run: |
332332
# Organize and keep essential files, delete unnecessary files
333333
chmod +x ${ROOTFS_SCRIPT}
334-
${ROOTFS_SCRIPT} -v ${{ inputs.set_release }}
334+
${ROOTFS_SCRIPT} -v ${{ inputs.set_release }} -s true -c true -u true
335335
336336
# Output cleaning result information
337337
df -hT ${PWD}

compile-kernel/tools/script/docker/build_armbian_rootfs_file.sh

Lines changed: 100 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
# Description: Build Armbian rootfs file.
1212
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
1313
#
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
1622
#
1723
#===================== Set make environment variables =====================
1824
#
@@ -29,6 +35,7 @@ STEPS="[\033[95m STEPS \033[0m]"
2935
INFO="[\033[94m INFO \033[0m]"
3036
SUCCESS="[\033[92m SUCCESS \033[0m]"
3137
WARNING="[\033[93m WARNING \033[0m]"
38+
NOTE="[\033[93m NOTE \033[0m]"
3239
ERROR="[\033[91m ERROR \033[0m]"
3340
#
3441
#==========================================================================
@@ -42,7 +49,7 @@ init_var() {
4249
echo -e "${STEPS} Start Initializing Variables..."
4350

4451
# 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:"
4653
parsed_args=$(getopt -o "${options}" -- "${@}")
4754
[[ ${?} -ne 0 ]] && error_msg "Parameter parsing failed."
4855
eval set -- "${parsed_args}"
@@ -57,6 +64,30 @@ init_var() {
5764
error_msg "Invalid -v parameter [ ${2} ]!"
5865
fi
5966
;;
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+
;;
6091
--)
6192
shift
6293
break
@@ -96,30 +127,37 @@ redo_rootfs() {
96127

97128
cd ${tmp_rootfs}/
98129

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'
123161
124162
# enable color support of ls and also add handy aliases
125163
if [ -x /usr/bin/dircolors ]; then
@@ -134,16 +172,47 @@ fi
134172
PS1='\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\$ '
135173
136174
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'
139177
140178
if [ -f "$HOME/.bashrc" ]; then
141179
. "$HOME/.bashrc"
142180
fi
143181
144182
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
147216

148217
# Compress the rootfs file
149218
sudo tar -czf ${rootfs_save_name}.tar.gz *

0 commit comments

Comments
 (0)