Skip to content

Commit 8ef860f

Browse files
committed
armbian-fix: optimize code
1 parent 2f89979 commit 8ef860f

File tree

1 file changed

+33
-28
lines changed
  • build-armbian/armbian-files/common-files/usr/sbin

1 file changed

+33
-28
lines changed

build-armbian/armbian-files/common-files/usr/sbin/armbian-fix

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#
1717
#=============================== Set default parameters ===============================
1818
#
19+
export DEBIAN_FRONTEND=noninteractive
20+
1921
# Set the armbian release check file
2022
armbian_release_file="/etc/armbian-release"
2123
armbian_image_file="/etc/armbian-image-release"
@@ -66,13 +68,28 @@ echo "" >${fix_log} && tolog "Start fixing..."
6668

6769
# Remove packages
6870
sudo apt-get clean -y && sudo rm -rf /var/cache/apt/* && sudo rm -rf /var/lib/apt/* && tolog "20. Clean up local installation packages"
69-
[[ -n "$(dpkg -l | awk '{print $2}' | grep linux-image-*)" ]] && sudo apt-get remove -qq --purge -y linux-image-* && tolog "21. Remove linux-image-*"
70-
[[ -n "$(dpkg -l | awk '{print $2}' | grep linux-dtb-*)" ]] && sudo apt-get remove -qq --purge -y linux-dtb-* && tolog "22. Remove linux-dtb-*"
71-
[[ -n "$(dpkg -l | awk '{print $2}' | grep linux-u-boot-*)" ]] && sudo apt-get remove -qq --purge -y linux-u-boot-* && tolog "23. Remove linux-u-boot-*"
72-
[[ -n "$(dpkg -l | awk '{print $2}' | grep armbian-bsp-cli-*)" ]] && sudo apt-mark hold armbian-bsp-cli-* && tolog "24. Hold armbian-bsp-cli-*"
73-
[[ -n "$(dpkg -l | awk '{print $2}' | grep u-boot-tools)" ]] && sudo apt-mark hold u-boot-tools && tolog "25. Hold u-boot-tools"
74-
[[ -n "$(dpkg -l | awk '{print $2}' | grep sunxi-tools)" ]] && sudo apt-mark hold sunxi-tools && tolog "26. Hold sunxi-tools"
75-
[[ -n "$(dpkg -l | awk '{print $2}' | grep initramfs-tools*)" ]] && sudo apt-mark hold initramfs-tools* && tolog "27. Hold initramfs-tools*"
71+
72+
# 21. Remove linux-image-*
73+
pkg_linux_image=$(dpkg -l | awk '{print $2}' | grep "^linux-image-" || true)
74+
if [[ -n "${pkg_linux_image}" ]]; then
75+
sudo apt-get remove -qq --purge -y --allow-change-held-packages ${pkg_linux_image} 2>/dev/null && tolog "21. Remove linux-image-*"
76+
fi
77+
# 22. Remove linux-dtb-*
78+
pkg_linux_dtb=$(dpkg -l | awk '{print $2}' | grep "^linux-dtb-" || true)
79+
if [[ -n "${pkg_linux_dtb}" ]]; then
80+
sudo apt-get remove -qq --purge -y --allow-change-held-packages ${pkg_linux_dtb} 2>/dev/null && tolog "22. Remove linux-dtb-*"
81+
fi
82+
# 23. Remove linux-u-boot-*
83+
pkg_linux_uboot=$(dpkg -l | awk '{print $2}' | grep "^linux-u-boot-" || true)
84+
if [[ -n "${pkg_linux_uboot}" ]]; then
85+
sudo apt-get remove -qq --purge -y --allow-change-held-packages ${pkg_linux_uboot} 2>/dev/null && tolog "23. Remove linux-u-boot-*"
86+
fi
87+
88+
# Hold packages
89+
[[ -n "$(dpkg -l | awk '{print $2}' | grep armbian-bsp-cli-)" ]] && sudo apt-mark hold armbian-bsp-cli-* 2>/dev/null && tolog "24. Hold armbian-bsp-cli-*"
90+
[[ -n "$(dpkg -l | awk '{print $2}' | grep u-boot-tools)" ]] && sudo apt-mark hold u-boot-tools 2>/dev/null && tolog "25. Hold u-boot-tools"
91+
[[ -n "$(dpkg -l | awk '{print $2}' | grep sunxi-tools)" ]] && sudo apt-mark hold sunxi-tools 2>/dev/null && tolog "26. Hold sunxi-tools"
92+
[[ -n "$(dpkg -l | awk '{print $2}' | grep initramfs-tools)" ]] && sudo apt-mark hold initramfs-tools* 2>/dev/null && tolog "27. Hold initramfs-tools*"
7693

7794
# Remove the scripts contained in [ armbian-bsp-cli-odroidn2 ] that will cause the system to fail to start
7895
# [ dpkg -c armbian-bsp-cli-odroidn2_23.02.2_arm64.deb ] : https://paste.armbian.com/aloxuvokol
@@ -109,15 +126,15 @@ quotes_cron="/etc/cron.daily/armbian-quotes"
109126
# Remove motd-news service
110127
motd_timer="/usr/lib/systemd/system/motd-news.timer"
111128
[[ -f "${motd_timer}" ]] && {
112-
sudo systemctl stop motd-news.timer
113-
sudo systemctl disable motd-news.timer
129+
sudo systemctl stop motd-news.timer 2>/dev/null
130+
sudo systemctl disable motd-news.timer 2>/dev/null
114131
sudo rm -f ${motd_timer}
115132
tolog "56. Disable motd-news.timer"
116133
}
117134
motd_service="/usr/lib/systemd/system/motd-news.service"
118135
[[ -f "${motd_service}" ]] && {
119-
sudo systemctl stop motd-news.service
120-
sudo systemctl disable motd-news.service
136+
sudo systemctl stop motd-news.service 2>/dev/null
137+
sudo systemctl disable motd-news.service 2>/dev/null
121138
sudo rm -f ${motd_service}
122139
tolog "57. Disable motd-news.service"
123140
}
@@ -150,10 +167,10 @@ tolog "59. Disable the ssh.socket and enable ssh.service"
150167
# Confirm device information
151168
[[ -f "${ophub_release_file}" ]] && {
152169
# Get welcome banner value
153-
family_name="$(cat ${ophub_release_file} | grep -E "^FAMILY=" | cut -d"'" -f2)"
154-
platform_name="$(cat ${ophub_release_file} | grep -E "^PLATFORM=" | cut -d"'" -f2)"
155-
soc_name="$(cat ${ophub_release_file} | grep -E "^SOC=" | cut -d"'" -f2 | sed -e "s|\b[a-z]|\U&|g")"
156-
board_name="$(cat ${ophub_release_file} | grep -E "^BOARD=" | cut -d"'" -f2 | sed -e "s|\b[a-z]|\U&|g")"
170+
family_name="$(cat ${ophub_release_file} | grep -E "^FAMILY=" | cut -d"'" -f2 || true)"
171+
platform_name="$(cat ${ophub_release_file} | grep -E "^PLATFORM=" | cut -d"'" -f2 || true)"
172+
soc_name="$(cat ${ophub_release_file} | grep -E "^SOC=" | cut -d"'" -f2 | sed -e "s|\b[a-z]|\U&|g" || true)"
173+
board_name="$(cat ${ophub_release_file} | grep -E "^BOARD=" | cut -d"'" -f2 | sed -e "s|\b[a-z]|\U&|g" || true)"
157174

158175
# Adjustment parameter name for ANDROID_UBOOT
159176
[[ -n "$(cat ${ophub_release_file} | grep -E "^ANDROID_UBOOT=")" ]] && {
@@ -270,24 +287,12 @@ todo_rootfs_resize="/root/.no_rootfs_resize"
270287
tolog "91. Root partition resized successfully"
271288
}
272289

273-
# Update the MAC address for the wireless network card
274-
[[ -d "/lib/firmware" ]] && {
275-
find "/lib/firmware" \
276-
-type f -name "*.txt" ! -xtype l \
277-
-exec grep -q '^macaddr=.*' {} \; \
278-
-exec sh -c '
279-
new_mac=$(openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/.$//; s/^./2/")
280-
sed -i "s/^macaddr=.*/macaddr=${new_mac}/" "${1}"
281-
' _ {} \; 2>/dev/null
282-
tolog "92. Update the MAC address for the wireless network card"
283-
}
284-
285290
# Hidd the IP address of WAN & IPv6
286291
ip_info_file="/etc/update-motd.d/20-ip-info"
287292
[[ -f "${ip_info_file}" ]] && {
288293
sed -i '/^get_wan.*_address/s/{.*/{ true; }/' ${ip_info_file}
289294
sed -i '/if.*ipv6s.*||.*wan6/,/fi/s/^/#/' ${ip_info_file}
290-
tolog "93. Hide the IP address of WAN & IPv6"
295+
tolog "92. Hide the IP address of WAN & IPv6"
291296
}
292297

293298
# Show end message

0 commit comments

Comments
 (0)