-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy patharmbian-fix
More file actions
executable file
·111 lines (100 loc) · 6.78 KB
/
armbian-fix
File metadata and controls
executable file
·111 lines (100 loc) · 6.78 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/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"
#
#======================================================================================
# Fix common releases permissions
[[ -d "/var/tmp" ]] && sudo chmod 777 /var/tmp && echo "01. Fix tmp permissions"
[[ -d "/etc/update-motd.d" ]] && sudo chmod 755 /etc/update-motd.d/* && echo "02. Fix update-motd.d permissions"
[[ -d "/var/cache/man" ]] && sudo chown man:root /var/cache/man -R && echo "03. Fix man permissions"
[[ -d "/var/cache/man" ]] && sudo chmod g+s /var/cache/man -R && echo "04. Fix man permissions"
[[ -f "/etc/sudoers" ]] && sudo chown root:root /etc/sudoers && echo "05. Fix man permissions"
[[ -f "/etc/sudoers" ]] && sudo chmod 440 /etc/sudoers && echo "06. Fix man permissions"
[[ -f "/usr/bin/sudo" ]] && sudo chown root:root /usr/bin/sudo && echo "07. Fix sudo permissions"
[[ -f "/usr/bin/sudo" ]] && sudo chmod 4755 /usr/bin/sudo && echo "08. Fix sudo permissions"
# Fix focal permissions
[[ -f "/usr/lib/sudo/sudoers.so" ]] && sudo chown 0 /usr/lib/sudo/sudoers.so && echo "09. Fix sudoers.so permissions"
[[ -f "/usr/lib/sudo/sudoers.so" ]] && sudo chmod 644 /usr/lib/sudo/sudoers.so && echo "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 && echo "11. Fix polkit-agent-helper-1 permissions"
# Fix jammy permissions
[[ -f "/usr/libexec/sudo/sudoers.so" ]] && sudo chown 0 /usr/libexec/sudo/sudoers.so && echo "12. Fix sudoers.so permissions"
[[ -f "/usr/libexec/sudo/sudoers.so" ]] && sudo chmod 644 /usr/libexec/sudo/sudoers.so && echo "13. Fix sudoers.so permissions"
[[ -f "/usr/libexec/polkit-agent-helper-1" ]] && sudo chmod 4755 /usr/libexec/polkit-agent-helper-1 && echo "14. Fix polkit-agent-helper-1 permissions"
# Remove packages
[[ -n "$(dpkg -l | awk '{print $2}' | grep linux-image-*)" ]] && sudo apt-get remove -qq --purge -y linux-image-* && echo "15. Remove linux-image-*"
[[ -n "$(dpkg -l | awk '{print $2}' | grep linux-dtb-*)" ]] && sudo apt-get remove -qq --purge -y linux-dtb-* && echo "16. Remove linux-dtb-*"
[[ -n "$(dpkg -l | awk '{print $2}' | grep linux-u-boot-*)" ]] && sudo apt-get remove -qq --purge -y linux-u-boot-* && echo "17. Remove linux-u-boot-*"
sudo apt-get clean -y && sudo rm -rf /var/cache/apt/* && sudo rm -rf /var/lib/apt/* && echo "18. Clean up local installation packages"
# Regenerate new machine-id
sudo rm -f /etc/machine-id /var/lib/dbus/machine-id && echo "19. Delete machine-id"
sudo dbus-uuidgen --ensure=/etc/machine-id && echo "20. Generate /etc/machine-id"
sudo dbus-uuidgen --ensure && echo "21. 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 && echo "22. Turn off automatic sleep mode"
# Fix version differences(After 2022.12.03)
[[ -f "/etc/amlogic_model_database.conf" ]] && mv -f /etc/amlogic_model_database.conf /etc/model_database.conf && echo "23. Adjust the model_database.conf file name"
[[ -f "/etc/rockchip_model_database.conf" ]] && mv -f /etc/rockchip_model_database.conf /etc/model_database.conf && echo "24. 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")"
# Adjust parameter name(After 2022.12.03)
[[ -n "$(cat ${ophub_release_file} | grep -E "^ANDROID_UBOOT=")" ]] && sed -i "s|ANDROID_UBOOT=|BOOTLOADER_IMG=|g" ${ophub_release_file} && echo "25. Adjust the ANDROID_UBOOT name"
[[ -n "$(cat ${ophub_release_file} | grep -E "^UBOOT_STATUS=")" ]] && sed -i "s|UBOOT_STATUS=|MLUBOOT_STATUS=|g" ${ophub_release_file} && echo "26. Adjust the UBOOT_STATUS name"
[[ -n "$(cat ${ophub_release_file} | grep -E "^KERNEL_BRANCH=")" ]] || {
[[ "${soc_name,,}" == "rk3588" ]] && KERNEL_BRANCH="rk3588" || KERNEL_BRANCH="stable"
echo "KERNEL_BRANCH='${KERNEL_BRANCH}'" >>${ophub_release_file} && echo "27. Add the KERNEL_BRANCH name"
}
}
# Fix custom banner name
[[ "${platform_name}" == "amlogic" ]] && bd_name="Aml ${soc_name}"
[[ "${platform_name}" == "rockchip" || "${platform_name}" == "allwinner" ]] && bd_name="${board_name}"
[[ -f "${armbian_release_file}" && -n "${bd_name}" ]] && sed -i "s|BOARD_NAME=.*|BOARD_NAME=\"${bd_name}\"|g" ${armbian_release_file} && echo "28. Fix custom board name: ${bd_name}"
# Disable ttyFIQ0 (ttyS2)
[[ "${platform_name}" == "rockchip" ]] && sudo systemctl disable serial-getty@ttyFIQ0 2>/dev/null && echo "29. Disable ttyFIQ0 (ttyS2)"
# 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} && echo "30. Disable tips of the day"
quotes_cron="/etc/cron.weekly/armbian-quotes"
[[ -f "${quotes_cron}" ]] && sed -i "s|^curl |#curl |g" ${quotes_cron} && echo "31. 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}
echo "32. 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}
echo "33. 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
sync && echo "armbian-fix: Loading finished."