-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy patharmbian-fix
executable file
·215 lines (193 loc) · 11.1 KB
/
armbian-fix
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/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
#
# Dependent script: /usr/lib/armbian/armbian-firstrun
# Function: Fix permissions and related settings(Executed at system initialization)
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
#
# Command: armbian-fix
#
#=============================== Set default parameters ===============================
#
# Set the armbian release check file
armbian_release_file="/etc/armbian-release"
# Set the ophub release check file
ophub_release_file="/etc/ophub-release"
# Custom armbian-fix Log
fix_log="/tmp/armbian-fix.log"
#
#======================================================================================
# Add log
tolog() {
echo -e "${1}"
echo -e "[$(date +"%Y.%m.%d.%H:%M:%S")] ${1}" >>${fix_log}
}
# Show start message
echo "" >${fix_log} && tolog "Start fixing..."
# ===== Start repairing system permissions =====
# Fix common releases permissions
[[ -d "/var/tmp" ]] && sudo chmod 777 /var/tmp && tolog "01. Fix tmp permissions"
[[ -d "/etc/update-motd.d" ]] && sudo chmod -x /etc/update-motd.d/* && sudo chmod +x /etc/update-motd.d/{10-*,30-*} 2>/dev/null && tolog "02. Fix update-motd.d permissions"
[[ -d "/var/cache/man" ]] && sudo chown man:root /var/cache/man -R && tolog "03. Fix man permissions"
[[ -d "/var/cache/man" ]] && sudo chmod g+s /var/cache/man -R && tolog "04. Fix man permissions"
[[ -f "/etc/sudoers" ]] && sudo chown root:root /etc/sudoers && tolog "05. Fix man permissions"
[[ -f "/etc/sudoers" ]] && sudo chmod 440 /etc/sudoers && tolog "06. Fix man permissions"
[[ -f "/usr/bin/sudo" ]] && sudo chown root:root /usr/bin/sudo && tolog "07. Fix sudo permissions"
[[ -f "/usr/bin/sudo" ]] && sudo chmod 4755 /usr/bin/sudo && tolog "08. Fix sudo permissions"
# Fix focal permissions
[[ -f "/usr/lib/sudo/sudoers.so" ]] && sudo chown 0 /usr/lib/sudo/sudoers.so && tolog "09. Fix sudoers.so permissions"
[[ -f "/usr/lib/sudo/sudoers.so" ]] && sudo chmod 644 /usr/lib/sudo/sudoers.so && tolog "10. Fix sudoers.so permissions"
[[ -f "/usr/lib/policykit-1/polkit-agent-helper-1" ]] && sudo chmod 4755 /usr/lib/policykit-1/polkit-agent-helper-1 && tolog "11. Fix polkit-agent-helper-1 permissions"
# Fix jammy permissions
[[ -f "/usr/libexec/sudo/sudoers.so" ]] && sudo chown 0 /usr/libexec/sudo/sudoers.so && tolog "12. Fix sudoers.so permissions"
[[ -f "/usr/libexec/sudo/sudoers.so" ]] && sudo chmod 644 /usr/libexec/sudo/sudoers.so && tolog "13. Fix sudoers.so permissions"
[[ -f "/usr/libexec/polkit-agent-helper-1" ]] && sudo chmod 4755 /usr/libexec/polkit-agent-helper-1 && tolog "14. Fix polkit-agent-helper-1 permissions"
# ===== Start removing useless packages and scripts =====
# Remove packages
sudo apt-get clean -y && sudo rm -rf /var/cache/apt/* && sudo rm -rf /var/lib/apt/* && tolog "20. Clean up local installation packages"
[[ -n "$(dpkg -l | awk '{print $2}' | grep linux-image-*)" ]] && sudo apt-get remove -qq --purge -y linux-image-* && tolog "21. Remove linux-image-*"
[[ -n "$(dpkg -l | awk '{print $2}' | grep linux-dtb-*)" ]] && sudo apt-get remove -qq --purge -y linux-dtb-* && tolog "22. Remove linux-dtb-*"
[[ -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-*"
[[ -n "$(dpkg -l | awk '{print $2}' | grep armbian-bsp-cli-*)" ]] && sudo apt-mark hold armbian-bsp-cli-* && tolog "24. Hold armbian-bsp-cli-*"
[[ -n "$(dpkg -l | awk '{print $2}' | grep u-boot-tools)" ]] && sudo apt-mark hold u-boot-tools && tolog "25. Hold u-boot-tools"
[[ -n "$(dpkg -l | awk '{print $2}' | grep sunxi-tools)" ]] && sudo apt-mark hold sunxi-tools && tolog "26. Hold sunxi-tools"
[[ -n "$(dpkg -l | awk '{print $2}' | grep initramfs-tools*)" ]] && sudo apt-mark hold initramfs-tools* && tolog "27. Hold initramfs-tools*"
# Remove the scripts contained in [ armbian-bsp-cli-odroidn2 ] that will cause the system to fail to start
# [ dpkg -c armbian-bsp-cli-odroidn2_23.02.2_arm64.deb ] : https://paste.armbian.com/aloxuvokol
# Move /usr/share/armbian to armbian.bak. [ dpkg -S boot.cmd ] : [ armbian-bsp-cli-odroidn2: /usr/share/armbian/boot.cmd ]
[[ -d "/usr/share/armbian" ]] && mv -f /usr/share/armbian /usr/share/armbian.bak && tolog "28. Move /usr/share/armbian to .bak"
# Move /usr/lib/nand-sata-install to nand-sata-install.bak. [ Useless bootloader and u-boot ]
[[ -d "/usr/lib/nand-sata-install" ]] && mv -f /usr/lib/nand-sata-install /usr/lib/nand-sata-install.bak && tolog "29. Move /usr/lib/nand-sata-install to .bak"
# Disable update_initramfs
initramfs_conf="/etc/initramfs-tools/update-initramfs.conf"
[[ -f "${initramfs_conf}" ]] && sed -i "s|^update_initramfs=.*|update_initramfs=no|g" ${initramfs_conf} && tolog "30. Set update-initramfs.conf"
# ===== Start disabling system services =====
# Regenerate new machine-id
sudo rm -f /etc/machine-id /var/lib/dbus/machine-id && tolog "50. Delete machine-id"
sudo dbus-uuidgen --ensure=/etc/machine-id && tolog "51. Generate /etc/machine-id"
sudo dbus-uuidgen --ensure && tolog "52. Generate /var/lib/dbus/machine-id"
# Turn off automatic hibernation to prevent hard drives from hanging
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target && tolog "53. Turn off automatic sleep mode"
# Disable tips of the day for [ /etc/update-motd.d/35-armbian-tips ]
motd_tips="/etc/default/armbian-motd"
[[ -f "${motd_tips}" ]] && {
sed -i 's|^MOTD_DISABLE=""|MOTD_DISABLE="tips"|g' ${motd_tips}
tolog "54. Disable tips of the day"
}
quotes_cron="/etc/cron.weekly/armbian-quotes"
[[ -f "${quotes_cron}" ]] && {
sed -i "s|^curl |#curl |g" ${quotes_cron}
tolog "55. Disable quotes cron plan"
}
# Remove motd-news service
motd_timer="/usr/lib/systemd/system/motd-news.timer"
[[ -f "${motd_timer}" ]] && {
sudo systemctl stop motd-news.timer
sudo systemctl disable motd-news.timer
sudo rm -f ${motd_timer}
tolog "56. Disable motd-news.timer"
}
motd_service="/usr/lib/systemd/system/motd-news.service"
[[ -f "${motd_service}" ]] && {
sudo systemctl stop motd-news.service
sudo systemctl disable motd-news.service
sudo rm -f ${motd_service}
tolog "57. Disable motd-news.service"
}
sudo rm -f /var/lib/systemd/deb-systemd-helper-enabled/timers.target.wants/motd-news.timer
sudo rm -f /var/lib/systemd/deb-systemd-helper-enabled/motd-news.timer.dsh-also
sudo rm -f /etc/systemd/system/timers.target.wants/motd-news.timer
sudo rm -f /etc/update-motd.d/50-motd-news
# Disable the system's partition adjustment service
sudo systemctl stop armbian-resize-filesystem.service 2>/dev/null
sudo systemctl disable armbian-resize-filesystem.service 2>/dev/null
tolog "58. Disable the armbian-resize-filesystem.service"
# Disable the ssh.socket: https://github.com/ophub/amlogic-s9xxx-armbian/discussions/1476
sudo systemctl disable --now ssh.socket 2>/dev/null
sudo systemctl enable --now ssh.service 2>/dev/null
tolog "59. Disable the ssh.socket and enable ssh.service"
# ===== Start adjusting custom settings =====
# Fix version differences(After 2022.12.03)
[[ -f "/etc/amlogic_model_database.conf" ]] && {
mv -f /etc/amlogic_model_database.conf /etc/model_database.conf
tolog "70. Adjust the model_database.conf file name"
}
[[ -f "/etc/rockchip_model_database.conf" ]] && {
mv -f /etc/rockchip_model_database.conf /etc/model_database.conf
tolog "71. Adjust the model_database.conf file name"
}
# Confirm device information
[[ -f "${ophub_release_file}" ]] && {
# Get welcome banner value
platform_name="$(cat ${ophub_release_file} | grep -E "^PLATFORM=" | cut -d"'" -f2)"
soc_name="$(cat ${ophub_release_file} | grep -E "^SOC=" | cut -d"'" -f2 | sed -e "s|\b[a-z]|\U&|g")"
board_name="$(cat ${ophub_release_file} | grep -E "^BOARD=" | cut -d"'" -f2 | sed -e "s|\b[a-z]|\U&|g")"
# Adjustment parameter name for ANDROID_UBOOT
[[ -n "$(cat ${ophub_release_file} | grep -E "^ANDROID_UBOOT=")" ]] && {
sed -i "s|^ANDROID_UBOOT=|BOOTLOADER_IMG=|g" ${ophub_release_file}
tolog "80. Adjust the ANDROID_UBOOT name"
}
# Adjustment parameter name for UBOOT_STATUS
[[ -n "$(cat ${ophub_release_file} | grep -E "^UBOOT_STATUS=")" ]] && {
sed -i "s|^UBOOT_STATUS=|MLUBOOT_STATUS=|g" ${ophub_release_file}
tolog "81. Adjust the UBOOT_STATUS name"
}
# Add default kernel tags
sed -i "s|^KERNEL_BRANCH=|KERNEL_TAGS=|g" ${ophub_release_file}
sed -i "s|^KERNEL_TAGS='6.x.y'|KERNEL_TAGS='6.1.y'|g" ${ophub_release_file}
[[ -n "$(cat ${ophub_release_file} | grep -E "^KERNEL_TAGS=")" ]] || {
[[ "${soc_name,,}" == "rk3588" ]] && KERNEL_TAGS="rk3588" || KERNEL_TAGS="stable"
echo "KERNEL_TAGS='${KERNEL_TAGS}'" >>${ophub_release_file}
tolog "82. Add the KERNEL_TAGS name"
}
# Add default GITHUB_CDN URL (CDN accelerated domain name)
[[ -n "$(cat ${ophub_release_file} | grep -E "^GITHUB_CDN=")" ]] || {
echo "GITHUB_CDN=''" >>${ophub_release_file}
tolog "83. Add the custom GITHUB_CDN URL"
}
# Add default KERNEL_REPO (Kernel download repository)
[[ -n "$(cat ${ophub_release_file} | grep -E "^KERNEL_REPO=")" ]] || {
echo "KERNEL_REPO='ophub/kernel'" >>${ophub_release_file}
tolog "84. Add the custom KERNEL_REPO URL"
}
# Add default KERNEL_BACKUP (Automatic backup kernel)
[[ -n "$(cat ${ophub_release_file} | grep -E "^KERNEL_BACKUP=")" ]] || {
echo "KERNEL_BACKUP='yes'" >>${ophub_release_file}
tolog "85. Add the custom KERNEL_BACKUP"
}
# Fix custom banner name
[[ "${platform_name}" == "amlogic" ]] && bd_name="Aml-${soc_name}"
[[ "${platform_name}" == "rockchip" ]] && bd_name="RK-${board_name}"
[[ "${platform_name}" == "allwinner" ]] && bd_name="AW-${board_name}"
[[ -f "${armbian_release_file}" && -n "${bd_name}" ]] && {
sed -i "s|^BOARD_NAME=.*|BOARD_NAME=\"${bd_name}\"|g" ${armbian_release_file}
tolog "86. Fix custom board name: ${bd_name}"
}
# Shorten release version number
short_version="$(cat ${armbian_release_file} | grep -E '^VERSION=' | grep -oE '[2-9][0-9]\.[0-9]{1,2}\.[0-9]{1,2}' | head -n 1)"
[[ -n "${short_version}" && -f "${armbian_release_file}" ]] && {
sed -i "s|^VERSION=.*|VERSION=${short_version}-trunk|g" ${armbian_release_file}
tolog "87. Set release version: ${short_version}-trunk"
}
# Disable ttyFIQ0 & ttyAML0 (ttyS2)
[[ "${platform_name}" == "rockchip" ]] && {
sudo systemctl disable serial-getty@ttyFIQ0 2>/dev/null
sudo systemctl disable serial-getty@ttyAML0 2>/dev/null
tolog "88. Disable ttyFIQ0 & ttyAML0 (ttyS2)"
}
}
# Maximize root partition size
todo_rootfs_resize="/root/.no_rootfs_resize"
[[ -f "${todo_rootfs_resize}" && "$(cat ${todo_rootfs_resize} 2>/dev/null | xargs)" == "yes" ]] && {
armbian-tf 2>/dev/null &&
tolog "89. Root partition resized successfully..."
}
# Show end message
tolog "successfully fixed."