first commit

This commit is contained in:
Your Name
2026-02-07 20:22:48 +08:00
commit 1b9711d5e4
2270 changed files with 805872 additions and 0 deletions

View File

@@ -0,0 +1 @@
../../share/chromium/master_preferences

View File

@@ -0,0 +1,9 @@
/boot/*
/dev/*
/proc/*
/sys/*
/media/*
/mnt/*
/run/*
/tmp/*
/ddbr/*

View File

@@ -0,0 +1,58 @@
#!/bin/bash
#
# 40-updates - create the list of packages for update with caching
# Copyright (c) 2015 Arkadiusz Raj
#
# Author: Arkadiusz Raj arek.raj@gmail.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
lock_file='/var/run/orangepi-motd-updates.lock'
if { set -C; 2>/dev/null >${lock_file}; }; then
trap "rm -f ${lock_file}" EXIT
else
exit 0
fi
# give up if packages are broken
[[ $(dpkg -l | grep ^..r) ]] && exit 0
# give up if there is a dependency problem
[[ "$((apt-get upgrade -s -qq) 2>&1)" == *"Unmet dependencies"* ]] && exit 0
myfile="/var/cache/apt/archives/updates.number"
# update procedure
DISTRO=$(lsb_release -c | cut -d ":" -f 2 | tr -d '[:space:]') && DISTRO=${DISTRO,,}
# run around the packages
upgrades=0
security_upgrades=0
while IFS= read -r LINE; do
# increment the upgrade counter
(( upgrades++ ))
# keep another count for security upgrades
[[ ${LINE} == *"${DISTRO}-sec"* ]] && (( security_upgrades++ ))
done < <(apt-get upgrade -s -qq | sed -n '/^Inst/p')
cat >|${myfile} <<EOT
NUM_UPDATES="${upgrades}"
NUM_SECURITY_UPDATES="${security_upgrades}"
DATE="$(date +"%Y-%m-%d %H:%M")"
EOT
exit 0

View File

@@ -0,0 +1,164 @@
#!/bin/sh
mixer() {
parm=${4:-on}
amixer -c "$1" sset "$2" "$3" $parm >/dev/null 2>&1
amixer -c "$1" sset "$2" $parm >/dev/null 2>&1
}
if [ -f $HOME/.config/sound.conf ]; then
alsactl restore -f $HOME/.config/sound.conf
else
# get card num
#card=`echo $1 | sed 's/[^0-9]*//g'`
card1=`aplay -l | grep "device 0" | awk '{print $3}'`
#echo $card
for card in $card1
do
#echo $card
# set common mixer params
mixer $card Master 0db
mixer $card Front 100%
mixer $card PCM 0db
mixer $card Synth 100%
# mute CD, since using digital audio instead
mixer $card CD 0% mute
# Only unmute Line and Aux if they are possibly used.
# mixer $card Line 100%
# mixer $card Aux 100%
# mute mic
mixer $card Mic 0% mute
# ESS 1969 chipset has 2 PCM channels
mixer $card PCM,1 100%
# Trident/YMFPCI/emu10k1
mixer $card Wave 100%
mixer $card Music 100%
mixer $card AC97 100%
mixer $card Surround 90%
mixer $card 'Surround Digital' 90%
mixer $card 'Wave Surround' 90%
mixer $card 'Duplicate Front' 90%
mixer $card 'Sigmatel 4-Speaker Stereo' 90%
# CS4237B chipset:
mixer $card 'Master Digital' 100%
# DRC
mixer $card 'Dynamic Range Compression' 90%
# Envy24 chips with analog outs
mixer $card DAC 100%
mixer $card DAC,0 100%
mixer $card DAC,1 100%
# some notebooks use headphone instead of master
mixer $card Headphone 100%
mixer $card Speaker 100%
mixer $card 'Internal Speaker' 0% mute
mixer $card Playback 100%
mixer $card Headphone 100%
mixer $card Speaker 100%
mixer $card Center 100%
mixer $card LFE 100%
mixer $card Center/LFE 100%
# Intel P4P800-MX (Ubuntu bug #5813)
mixer $card 'Master Playback Switch' on
# set digital output mixer params
mixer $card 'IEC958' 100% on
mixer $card 'IEC958 Output' 100%
mixer $card 'IEC958 Coaxial' 100%
mixer $card 'IEC958 LiveDrive' 100%
mixer $card 'IEC958 Optical Raw' 100%
mixer $card 'SPDIF Out' 100%
mixer $card 'SPDIF Front' 100%
mixer $card 'SPDIF Rear' 100%
mixer $card 'SPDIF Center/LFE' 100%
mixer $card 'Master Digital' 100%
mixer $card 'Analog Front' 100%
mixer $card 'Analog Rear' 100%
mixer $card 'Analog Center/LFE' 100%
# ASRock ION 330 (and perhaps others) has 2 IEC958 channels
mixer $card IEC958,0 on
mixer $card IEC958,1 on
# some ION2 has much more IEC958 channels ...
mixer $card IEC958,2 on
mixer $card IEC958,3 on
# ASRock ION 330 has Master Front set to 0
mixer $card 'Master Front' 100%
# Shuttle XS35GT needs this too
mixer $card 'Master',0 100% on
# and this for various Fusion devices like Zotac ZBOX
mixer $card 'Front',0 100% on
# NVidia CK804 sound devices
mixer $card 'IEC958 Playback AC97-SPSA' 100%
# Allwinner H3 Analog
mixer $card 'Line Out' 0db on
# Allwinner A20 Analog
mixer $card 'Power Amplifier' 0db
mixer $card 'Power Amplifier DAC' on
mixer $card 'Power Amplifier Mute' on
# Allwinner A64 Analog
mixer $card Headphone 0db on
mixer $card 'AIF1 Slot 0 Digital DAC' on
# Amlogic G12 HDMI to PCM0
mixer $card 'FRDDR_A SINK 1 SEL' 'OUT 1'
mixer $card 'FRDDR_A SRC 1 EN' on
mixer $card 'TDMOUT_B SRC SEL' 'IN 0'
mixer $card 'TOHDMITX I2S SRC' 'I2S B'
mixer $card 'TOHDMITX' on
# Amlogic G12 S/PDIF to PCM1
mixer $card 'FRDDR_B SINK 1 SEL' 'OUT 3'
mixer $card 'FRDDR_B SRC 1 EN' on
mixer $card 'SPDIFOUT SRC SEL' 'IN 1'
mixer $card 'SPDIFOUT Playback' on
# Amlogic GX HDMI and S/PDIF
mixer $card 'AIU HDMI CTRL SRC' 'I2S'
mixer $card 'AIU SPDIF SRC SEL' 'SPDIF'
# RockPI 4B Analog
mixer $card 'Right Headphone Mixer Right DAC' on
mixer $card 'Left Headphone Mixer Left DAC' on
# NanoPC T4 Analog
mixer $card 'HPO L' on
mixer $card 'HPO R' on
mixer $card 'HPOVOL L' on
mixer $card 'HPOVOL R' on
mixer $card 'HPO MIX HPVOL' on
mixer $card 'OUT MIXL DAC L1' on
mixer $card 'OUT MIXR DAC R1' on
mixer $card 'Stereo DAC MIXL DAC L1' on
mixer $card 'Stereo DAC MIXR DAC R1' on
done
fi

View File

@@ -0,0 +1,60 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
# Functions:
#
# show_motd_warning
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
my_name="${0##*/}"
Log=/var/log/orangepi-hardware-monitor.log
show_motd_warning() {
cat > /etc/update-motd.d/90-warning <<EOT
#!/bin/bash
echo -e "\e[0;91mAttention:\x1B[0m $1\n"
rm "\$0"
EOT
chmod +x /etc/update-motd.d/90-warning
} # show_motd_warning
get_random_mac ()
{
local prefixes=("02" "06" "0A" "0E")
local random=$(shuf -i 0-3 -n 1)
MACADDR=$(printf ${prefixes[$random]}':%02X:%02X:%02X:%02X:%02X\n' $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256])
}
# set fixed IP address from first randomly assigned one. If nothing is detected, generate one.
set_fixed_mac ()
{
if [ -n "$(command -v nmcli)" ]; then
CONNECTION="$(nmcli -f UUID,ACTIVE,DEVICE,TYPE connection show --active | tail -n1)"
UUID=$(awk -F" " '/ethernet/ {print $1}' <<< "${CONNECTION}")
DEVNAME=$(awk -F" " '/ethernet/ {print $3}' <<< "${CONNECTION}")
else
DEVNAME=eth0
fi
MACADDR=$(/sbin/ip link | grep -A1 ${DEVNAME} | awk -F" " '/ether / {print $2}')
[[ -z $MACADDR ]] && get_random_mac
if [[ -n "$(command -v nmcli)" && -n $UUID ]]; then
nmcli connection modify "$UUID" ethernet.cloned-mac-address "$MACADDR"
nmcli connection modify "$UUID" -ethernet.mac-address ""
nmcli connection down "$UUID" >/dev/null 2>&1
nmcli connection up "$UUID" >/dev/null 2>&1
elif [[ -f /etc/systemd/network/$DEVNAME.network ]]; then
if ! grep '^ *MACAddress=' /etc/systemd/network/$DEVNAME.network > /dev/null; then
sed -i "s/#MACAddress=/MACAddress=$MACADDR/g" /etc/systemd/network/$DEVNAME.network
fi
fi
return 0
} # set fixed mac to the 1st active network adapter

View File

@@ -0,0 +1,480 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
. /etc/orangepi-release
check_abort()
{
echo -e "\nDisabling user account creation procedure\n"
rm -f /root/.not_logged_in_yet
if [[ ${USER_SHELL} == zsh ]]; then
printf "\nYou selected \e[0;91mZSH\x1B[0m as your default shell. If you want to use it right away, please logout and login! \n\n"
fi
trap - INT
exit 0
}
read_password()
{
unset password
unset charcount
prompt="$1 password: "
stty -echo
charcount=0
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]
then
break
fi
# Handle backspace
if [[ $char == $'\177' ]]
then
if [ $charcount -gt 0 ]
then
charcount=$((charcount-1))
prompt=$'\b \b'
password="${password%?}"
else
prompt=''
fi
else
charcount=$((charcount+1))
prompt='*'
password+="$char"
fi
done
stty echo
}
set_shell()
{
optionsAudits=($(cat /etc/shells | grep "zsh\|/bash" | sed 's/\/bin\///g' | sed 's/\/usr//g' | uniq))
USER_SHELL="bash"
if [[ "${#optionsAudits[@]}" -gt 1 ]]; then
while :
do
i=1
echo -e "\nChoose default system command shell:\n"
for o in "${optionsAudits[@]}"; do
echo "$i) $o"
let i++
done
read -n1 -s reply
case $reply in
"1"|"${optionsAudits[0]}") USER_SHELL="${optionsAudits[0]}"; break;;
"2"|"${optionsAudits[1]}") USER_SHELL="${optionsAudits[1]}"; break;;
*) USER_SHELL="${optionsAudits[0]}"; break;;
esac
done
fi
SHELL_PATH=$(grep /$USER_SHELL$ /etc/shells | tail -1)
chsh -s $(grep -iF "/$USER_SHELL" /etc/shells | tail -1)
echo -e "\nShell: \x1B[92m${USER_SHELL^^}\x1B[0m"
# change shell for future users
sed -i "s|^SHELL=.*|SHELL=${SHELL_PATH}|" /etc/default/useradd
sed -i "s|^DSHELL=.*|DSHELL=${SHELL_PATH}|" /etc/adduser.conf
}
set_timezone_and_locales()
{
# Grab this machine's public IP address
PUBLIC_IP=`curl --max-time 5 -s https://ipinfo.io/ip`
# Check if we have wireless adaptor
WIFI_DEVICE=$(LC_ALL=C nmcli dev status | grep " wifi " 2>/dev/null)
if [ -z "$PUBLIC_IP" ]; then
# ask for connecting to wireless if wifi device is found
if [[ -n "$WIFI_DEVICE" ]]; then
echo -e "Internet connection was \x1B[91mnot detected\x1B[0m."
echo ""
read -n1 -s -r -p "Connect via wireless? [Y/n] " response
echo ""
if [[ "${response}" =~ ^(Y|y|"")$ ]]; then
nmtui-connect
fi
echo ""
fi
fi
# Grab IP once again if not found
[[ -z "$PUBLIC_IP" && -n "$WIFI_DEVICE" ]] && PUBLIC_IP=`curl --max-time 5 -s https://ipinfo.io/ip`
# Call the geolocation API and capture the output
RES=$(
curl --max-time 5 -s http://ipwhois.app/json/${PUBLIC_IP} | \
jq '.timezone, .country, .country_code' | \
while read -r TIMEZONE; do
read -r COUNTRY
echo "${TIMEZONE},${COUNTRY},${COUNTRYCODE}" | tr --delete \"
done
)
TZDATA=$(echo ${RES} | cut -d"," -f1)
STATE=$(echo ${RES} | cut -d"," -f2)
CCODE=$(echo ${RES} | cut -d"," -f3 | xargs)
echo -e "Detected timezone: \x1B[92m$TZDATA\x1B[0m"
echo ""
unset response
while [[ ! "${response}" =~ ^(Y|y|N|n)$ ]]; do
read -n1 -s -r -p "Set user language based on your location? [Y/n] " response
echo ""
done
# change it only if we have a match and if we agree
if [[ "${response}" =~ ^(N|n)$ ]]; then
unset CCODE TZDATA
fi
LOCALES=$(grep territory /usr/share/i18n/locales/* | grep _"$CCODE" | cut -d ":" -f 1 | cut -d "/" -f 6 | \
xargs -I{} grep {} /usr/share/i18n/SUPPORTED | grep "\.UTF-8" | cut -d " " -f 1)
# UTF8 is not present everywhere so check again in case it returns empty value
[[ -z "$LOCALES" ]] && LOCALES=$(grep territory /usr/share/i18n/locales/* | grep _"$CCODE" | cut -d ":" -f 1 | cut -d "/" -f 6 | \
xargs -I{} grep {} /usr/share/i18n/SUPPORTED | cut -d " " -f 1)
options=(`echo ${LOCALES}`);
# when having more locales, prompt for choosing one
if [[ "${#options[@]}" -gt 1 ]]; then
options+=("Skip generating locales")
echo -e "\nAt your location, more locales are possible:\n"
PS3='Please enter your choice:'
select opt in "${options[@]}"
do
if [[ " ${options[@]} " =~ " ${opt} " ]]; then
LOCALES=${opt}
break
fi
done
fi
if [[ "${LOCALES}" != *Skip* ]]; then
# if TZDATA was not detected, we need to select one
if [[ -z ${TZDATA} ]]; then
TZDATA=$(tzselect | tail -1)
fi
timedatectl set-timezone "${TZDATA}"
dpkg-reconfigure --frontend=noninteractive tzdata > /dev/null 2>&1
# generate locales
echo ""
sed -i 's/# '"${LOCALES}"'/'"${LOCALES}"'/' /etc/locale.gen
echo -e "Generating locales: \x1B[92m${LOCALES}\x1B[0m"
locale-gen "${LOCALES}" > /dev/null 2>&1
# setting detected locales only for user
echo "export LC_ALL=$LOCALES" >> /home/"$RealUserName"/.bashrc
echo "export LANG=$LOCALES" >> /home/"$RealUserName"/.bashrc
echo "export LANGUAGE=$LOCALES" >> /home/"$RealUserName"/.bashrc
echo "export LC_ALL=$LOCALES" >> /home/"$RealUserName"/.xsessionrc
echo "export LANG=$LOCALES" >> /home/"$RealUserName"/.xsessionrc
echo "export LANGUAGE=$LOCALES" >> /home/"$RealUserName"/.xsessionrc
fi
}
add_profile_sync_settings()
{
/usr/bin/psd >/dev/null 2>&1
config_file="${HOME}/.config/psd/psd.conf"
if [ -f "${config_file}" ]; then
# test for overlayfs
sed -i 's/#USE_OVERLAYFS=.*/USE_OVERLAYFS="yes"/' "${config_file}"
case $(/usr/bin/psd p 2>/dev/null | grep Overlayfs) in
*active*)
echo -e "\nConfigured profile sync daemon with overlayfs."
;;
*)
echo -e "\nConfigured profile sync daemon."
sed -i 's/USE_OVERLAYFS="yes"/#USE_OVERLAYFS="no"/' "${config_file}"
;;
esac
fi
systemctl --user enable psd.service >/dev/null 2>&1
systemctl --user start psd.service >/dev/null 2>&1
}
add_user()
{
read -t 0 temp
REPEATS=3
while [ -f "/root/.not_logged_in_yet" ]; do
echo -e "\nPlease provide a username (eg. your first name): \c"
read -e username
if ! grep '^[a-zA-Z]*$' <<< $username > /dev/null ; then
echo -e "\n\x1B[91mError\x1B[0m: illegal characters in username"
return
fi
RealUserName="$(echo "$username" | tr '[:upper:]' '[:lower:]' | tr -d -c '[:alnum:]')"
[ -z "$RealUserName" ] && return
if ! id "$RealUserName" >/dev/null 2>&1; then break; else echo -e "Username \e[0;31m$RealUserName\x1B[0m already exists on the system."; fi
done
while [ -f "/root/.not_logged_in_yet" ]; do
read_password "Create user ($username)"
first_input="$password"
echo ""
read_password "Repeat user ($username)"
second_input="$password"
echo ""
if [[ "$first_input" == "$second_input" ]]; then
result="$(cracklib-check <<<"$password")"
okay="$(awk -F': ' '{ print $2}' <<<"$result")"
if [[ "$okay" == "OK" ]]; then
echo -e ""
read -e -p "Please provide your real name: " -i "${RealUserName^}" RealName
adduser --quiet --disabled-password --home /home/"$RealUserName" --gecos "$RealName" "$RealUserName"
(echo "$first_input";echo "$second_input";) | passwd "$RealUserName" >/dev/null 2>&1
for additionalgroup in sudo netdev audio video disk tty users games dialout plugdev input bluetooth systemd-journal ssh; do
usermod -aG "${additionalgroup}" "${RealUserName}" 2>/dev/null
done
# fix for gksu in Xenial
touch /home/"$RealUserName"/.Xauthority
chown "$RealUserName":"$RealUserName" /home/"$RealUserName"/.Xauthority
RealName="$(awk -F":" "/^${RealUserName}:/ {print \$5}" </etc/passwd | cut -d',' -f1)"
[ -z "$RealName" ] && RealName="$RealUserName"
echo -e "\nDear \e[0;92m${RealName}\x1B[0m, your account \e[0;92m${RealUserName}\x1B[0m has been created and is sudo enabled."
echo -e "Please use this account for your daily work from now on.\n"
rm -f /root/.not_logged_in_yet
chmod +x /etc/update-motd.d/*
# set up profile sync daemon on desktop systems
command -v psd >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${RealUserName} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers
touch /home/"${RealUserName}"/.activate_psd
chown "$RealUserName":"$RealUserName" /home/"${RealUserName}"/.activate_psd
fi
break
else
echo -e "Rejected - \e[0;31m$okay.\x1B[0m Try again [${REPEATS}]."
REPEATS=$((REPEATS - 1))
fi
elif [[ -n $password ]]; then
echo -e "Rejected - \e[0;31mpasswords do not match.\x1B[0m Try again [${REPEATS}]."
REPEATS=$((REPEATS - 1))
fi
[[ "$REPEATS" -eq 0 ]] && exit
done
}
if [[ -f /root/.not_logged_in_yet && -n $(tty) ]]; then
# disable autologin
#rm -f /etc/systemd/system/getty@.service.d/override.conf
#rm -f /etc/systemd/system/serial-getty@.service.d/override.conf
#systemctl daemon-reload
# detect display manager
#desktop_lightdm=$(dpkg-query -W -f='${db:Status-Abbrev}\n' lightdm 2>/dev/null)
#desktop_gdm3=$(dpkg-query -W -f='${db:Status-Abbrev}\n' gdm3 2>/dev/null)
#echo -e "\nWaiting for system to finish booting ...\n"
#systemctl is-system-running --wait >/dev/null
#if [ "$IMAGE_TYPE" != "nightly" ]; then
# if [ "$BRANCH" == "dev" ]; then
# echo -e "\nYou are using an Orange Pi preview build !!!"
# echo -e "\nThis image is provided \e[0;31mAS IS\x1B[0m with \e[0;31mNO WARRANTY\x1B[0m and \e[0;31mNO END USER SUPPORT!\x1B[0m.\n"
# elif [ "$DISTRIBUTION_STATUS" != "supported" ]; then
# echo -e "\nYou are using an Orange Pi with unsupported ($DISTRIBUTION_CODENAME) userspace !!!"
# echo -e "\nThis image is provided \e[0;31mAS IS\x1B[0m with \e[0;31mNO WARRANTY\x1B[0m and \e[0;31mNO END USER SUPPORT!\x1B[0m.\n"
# fi
#else
# echo -e "\nYou are using an Orange Pi nightly build meant only for developers to provide"
# echo -e "constructive feedback to improve build system, OS settings or user experience."
# echo -e "If this does not apply to you, \e[0;31mSTOP NOW!\x1B[0m. Especially don't use this image for"
# echo -e "daily work since things might not work as expected or at all and may break"
# echo -e "anytime with next update. \e[0;31mYOU HAVE BEEN WARNED!\x1B[0m"
# echo -e "\nThis image is provided \e[0;31mAS IS\x1B[0m with \e[0;31mNO WARRANTY\x1B[0m and \e[0;31mNO END USER SUPPORT!\x1B[0m.\n"
#fi
echo -e "New to Orange Pi? Support: \e[1m\e[39mhttp://www.orangepi.org\x1B[0m\n"
#trap '' 2
#while [ -f "/root/.not_logged_in_yet" ]; do
# read_password "New root"
# # only allow one login. Once you enter root password, kill others.
# loginfrom=$(who am i | awk '{print $2}')
# who -la | grep root | grep -v "$loginfrom" | awk '{print $7}' | xargs --no-run-if-empty kill -9
# first_input=$password
# echo ""
# read_password "Repeat"
# second_input=$password
# echo ""
# if [[ $first_input == $second_input ]]; then
# result="$(cracklib-check <<<"$password")"
# okay="$(awk -F': ' '{ print $2}' <<<"$result")"
# if [[ "$okay" == "OK" ]]; then
# (echo $first_input;echo $second_input;) | passwd root >/dev/null 2>&1
# break
# else
# echo -e "Rejected - \e[0;31m$okay.\x1B[0m Try again."
# fi
# elif [[ -n $password ]]; then
# echo -e "Rejected - \e[0;31mpasswords do not match.\x1B[0m Try again."
# fi
#done
#trap - INT TERM EXIT
# ask user to select shell
#trap '' 2
#set_shell
#trap - INT TERM EXIT
#trap check_abort INT
#while [ -f "/root/.not_logged_in_yet" ]; do
# echo -e "\nCreating a new user account. Press <Ctrl-C> to abort"
# [ -n "$desktop_lightdm" ] && echo -e "\n\e[0;31mDesktop environment will not be enabled if you abort the new user creation\x1B[0m"
# add_user
#done
#trap - INT TERM EXIT
## ask user to select automated locales or not
#trap '' 2
#set_timezone_and_locales
#trap - INT TERM EXIT
#if [[ ${USER_SHELL} == zsh ]]; then
# printf "\nYou selected \e[0;91mZSH\x1B[0m as your default shell. If you want to use it right away, please logout and login! \n\n"
#fi
# check whether desktop environment has to be considered
#if [ -n "$desktop_lightdm" ] && [ -n "$RealName" ] ; then
# # 1st run goes without login
# mkdir -p /etc/lightdm/lightdm.conf.d
# cat <<-EOF > /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
# [Seat:*]
# autologin-user=$RealUserName
# autologin-user-timeout=0
# user-session=xfce
# EOF
# # select gnome session (has to be first or it breaks budgie/cinnamon desktop autologin and user-session)
# [[ -x $(which gnome-session) ]] && sed -i "s/user-session.*/user-session=ubuntu/" /etc/lightdm/lightdm.conf.d/11-orangepi.conf
# [[ -x $(which gnome-session) ]] && sed -i "s/user-session.*/user-session=ubuntu/" /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
# # select budgie session
# [[ -x $(which budgie-desktop) ]] && sed -i "s/user-session.*/user-session=budgie-desktop/" /etc/lightdm/lightdm.conf.d/11-orangepi.conf
# [[ -x $(which budgie-desktop) ]] && sed -i "s/user-session.*/user-session=budgie-desktop/" /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
# # select deepin session
# [[ -x $(which deepin-wm) ]] && sed -i "s/user-session.*/user-session=deepin/" /etc/lightdm/lightdm.conf.d/11-orangepi.conf
# [[ -x $(which deepin-wm) ]] && sed -i "s/user-session.*/user-session=deepin/" /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
# # select cinnamon session
# [[ -x $(which cinnamon) ]] && sed -i "s/user-session.*/user-session=cinnamon/" /etc/lightdm/lightdm.conf.d/11-orangepi.conf
# [[ -x $(which cinnamon) ]] && sed -i "s/user-session.*/user-session=cinnamon/" /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
# # select mate session
# [[ -x $(which mate-wm) ]] && sed -i "s/user-session.*/user-session=mate/" /etc/lightdm/lightdm.conf.d/11-orangepi.conf
# [[ -x $(which mate-wm) ]] && sed -i "s/user-session.*/user-session=mate/" /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
# ln -sf /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service
# if [[ -f /var/run/resize2fs-reboot ]]; then
# # Let the user reboot now otherwise start desktop environment
# printf "\n\n\e[0;91mWarning: a reboot is needed to finish resizing the filesystem \x1B[0m \n"
# printf "\e[0;91mPlease reboot the system now \x1B[0m \n\n"
# elif [ -z "$ConfigureDisplay" ] || [ "$ConfigureDisplay" = "n" ] || [ "$ConfigureDisplay" = "N" ]; then
# echo -e "\n\e[1m\e[39mNow starting desktop environment...\x1B[0m\n"
# sleep 1
# service lightdm start 2>/dev/null
# if [ -f /root/.desktop_autologin ]; then
# rm /root/.desktop_autologin
# else
# systemctl -q enable orangepi-disable-autologin.timer
# systemctl start orangepi-disable-autologin.timer
# fi
# # logout if logged at console
# [[ -n $(who -la | grep root | grep tty1) ]] && exit 1
# fi
#elif [ -n "$desktop_gdm3" ] && [ -n "$RealName" ] ; then
# # 1st run goes without login
# mkdir -p /etc/gdm3
# cat <<-EOF > /etc/gdm3/custom.conf
# [daemon]
# AutomaticLoginEnable = true
# AutomaticLogin = $RealUserName
# EOF
# ln -sf /lib/systemd/system/gdm3.service /etc/systemd/system/display-manager.service
# if [[ -f /var/run/resize2fs-reboot ]]; then
# # Let the user reboot now otherwise start desktop environment
# printf "\n\n\e[0;91mWarning: a reboot is needed to finish resizing the filesystem \x1B[0m \n"
# printf "\e[0;91mPlease reboot the system now \x1B[0m \n\n"
# elif [ -z "$ConfigureDisplay" ] || [ "$ConfigureDisplay" = "n" ] || [ "$ConfigureDisplay" = "N" ]; then
# echo -e "\n\e[1m\e[39mNow starting desktop environment...\x1B[0m\n"
# sleep 1
# service gdm3 start 2>/dev/null
# if [ -f /root/.desktop_autologin ]; then
# rm /root/.desktop_autologin
# else
# (sleep 20; sed -i "s/AutomaticLoginEnable.*/AutomaticLoginEnable = false/" /etc/gdm3/custom.conf) &
# fi
# # logout if logged at console
# [[ -n $(who -la | grep root | grep tty1) ]] && exit 1
# fi
#else
# # Display reboot recommendation if necessary
# if [[ -f /var/run/resize2fs-reboot ]]; then
# printf "\n\n\e[0;91mWarning: a reboot is needed to finish resizing the filesystem \x1B[0m \n"
# printf "\e[0;91mPlease reboot the system now \x1B[0m \n\n"
# fi
#fi
rm -f /root/.not_logged_in_yet
fi

View File

@@ -0,0 +1,115 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
. /etc/orangepi-release
. /etc/os-release
. /lib/init/vars.sh
. /lib/lsb/init-functions
. /usr/lib/orangepi/orangepi-common
case "$1" in
start)
# read number of cores needed below
cpu_cores=$(grep -c '^processor' /proc/cpuinfo | sed 's/^0$/1/')
# adjust custom htop initial configuration based on CPU count https://github.com/avafinger/htop-2.1.1_enhanced-version
right_meters="Hostname Tasks LoadAverage DiskIO NetworkIO Uptime Systemd CpuFreq"
right_meter_modes="2 2 2 2 2 2 2 2"
sed -i 's/header_margin=.*/header_margin=1/g' /etc/skel/.config/htop/htoprc
sed -i 's/left_meters=.*/left_meters=AllCPUs Memory Zram Swap CpuTemp/g' /etc/skel/.config/htop/htoprc
sed -i 's/left_meter_modes=.*/left_meter_modes=1 1 1 1 2/g' /etc/skel/.config/htop/htoprc
sed -i "s/right_meters=.*/right_meters=$right_meters/g" /etc/skel/.config/htop/htoprc
sed -i "s/right_meter_modes=.*/right_meter_modes=$right_meter_modes/g" /etc/skel/.config/htop/htoprc
# copy predefined settings for root user
cp -R /etc/skel/.config /root/
# Run a q&d benchmark to be able to identify cards way too slow easily
echo -e "\n### quick iozone test:$(cd /root; iozone -e -I -a -s 1M -r 4k -i 0 -i 1 -i 2 | grep '^ 1024' | sed 's/ 1024 //')" >> $Log
# Bluetooth tweaks
#case ${BOARD} in
# orangepizeroplus2*|orangepiwin)
# update-rc.d ap6212-bluetooth defaults
# ;;
#esac
# Debian Buster desktop bugfix https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=923289
[[ -d /etc/lightdm ]] && dpkg-reconfigure libgdk-pixbuf2.0-0 && update-mime-database /usr/share/mime
# update console info
setupcon --save
# add unique installation id to the image release file
sed '1s/^/IMAGE_UUID=/' /proc/sys/kernel/random/uuid >> /etc/orangepi-image-release
# SSH Keys creation
rm -f /etc/ssh/ssh_host*
read entropy_before </proc/sys/kernel/random/entropy_avail
dpkg-reconfigure openssh-server >/dev/null 2>&1
service sshd restart
read entropy_after </proc/sys/kernel/random/entropy_avail
echo -e "\n### [firstrun] Recreated SSH keys (entropy: ${entropy_before} ${entropy_after})" >>${Log}
# get rid of purple background color in newt apps whiptail, partimage, debconf ... Reverting to Debian look.
[[ -f /etc/newt/palette ]] && sed -e 's/magenta/blue/g' -i /etc/newt/palette
# desktop tweaks - enable show windows content on stronger boards
if [[ ${cpu_cores} -gt 2 && -f /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml ]]; then
sed -i 's/<property name="box_move" type="bool" value=".*/<property name="box_move" type="bool" value="false"\/>/g' \
/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml
fi
# randomize mac in orangepiEnv.txt
if [[ -f /boot/orangepiEnv.txt ]]; then
get_random_mac
sed -i "s/^ethaddr=.*/ethaddr=$MACADDR/" /boot/orangepiEnv.txt
get_random_mac
sed -i "s/^eth1addr=.*/eth1addr=$MACADDR/" /boot/orangepiEnv.txt
fi
# hardware workarounds per family
case $LINUXFAMILY in
sun7i|sun8i)
# set some mac address for BT
[[ -n $(lsmod | egrep "dhd|brcmfmac" ) ]] && \
(MACADDR=$(printf '43:29:B1:%02X:%02X:%02X\n' $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]) ; \
sed -i "s/^MAC_ADDR=.*/MAC_ADDR=${MACADDR}/" /etc/default/brcm40183 ;\
sed -i "s/^MAC_ADDR=.*/MAC_ADDR=${MACADDR}/" /etc/default/ap6212 \
echo -e "\n### [firstrun] Use MAC address ${MACADDR} for Bluetooth from now" >>${Log})
case $BOARD_NAME in
"Orange Pi Zero")
get_random_mac
echo "options xradio_wlan macaddr=${MACADDR}" >/etc/modprobe.d/xradio_wlan.conf
echo -e "\n### [firstrun] Use MAC address ${MACADDR} for Wi-Fi from now" >>${Log}
cd /etc/network/ && ln -sf interfaces.network-manager interfaces
(modprobe -r xradio_wlan && sleep 1 && modprobe xradio_wlan) &
;;
esac
# trigger red or blue LED as user feedback
echo heartbeat >/sys/class/leds/*red*/trigger 2>/dev/null || echo heartbeat >/sys/class/leds/*blue*/trigger 2>/dev/null
;;
*)
esac
# varios temporary hardware workarounds
#[[ $LINUXFAMILY == rk3399 || $LINUXFAMILY == rockchip64 ]] && [[ $BOARD != helios64 && $BOARD != khadas-edge ]] && set_fixed_mac
#[[ $LINUXFAMILY == rk3399 ]] && set_fixed_mac
systemctl disable orangepi-firstrun
exit 0
;;
*)
echo "Usage: $0 start"
exit 0
;;
esac

View File

@@ -0,0 +1,140 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
# Function calculates number of bit in a netmask
#
mask2cidr() {
nbits=0
IFS=.
for dec in $1 ; do
case $dec in
255) let nbits+=8;;
254) let nbits+=7;;
252) let nbits+=6;;
248) let nbits+=5;;
240) let nbits+=4;;
224) let nbits+=3;;
192) let nbits+=2;;
128) let nbits+=1;;
0);;
*) echo "Error: $dec is not recognised"; exit 1
esac
done
echo "$nbits"
}
do_firstrun_automated_user_configuration()
{
#-----------------------------------------------------------------------------
#Notes:
# - See /boot/orangepi_first_run.txt for full list of available variables
# - Variable names here must here must match ones in packages/bsp/orangepi_first_run.txt.template
#-----------------------------------------------------------------------------
#Config FP
local fp_config='/boot/orangepi_first_run.txt'
#-----------------------------------------------------------------------------
#Grab user requested settings
if [[ -f $fp_config ]]; then
# Convert line endings to Unix from Dos
sed -i $'s/\r$//' "$fp_config"
# check syntax
bash -n "$fp_config" || return
# Load vars directly from file
source "$fp_config"
# Obtain backward configuration compatibility
FR_net_static_dns=${FR_net_static_dns// /,}
FR_net_static_mask=$(mask2cidr $FR_net_static_mask)
#-----------------------------------------------------------------------------
# - Remove configuration file
if [[ $FR_general_delete_this_file_after_completion == 1 ]]; then
dd if=/dev/urandom of="$fp_config" bs=16K count=1
sync
rm "$fp_config"
else
mv "$fp_config" "${fp_config}.old"
fi
#-----------------------------------------------------------------------------
# Set Network
if [[ $FR_net_change_defaults == 1 ]]; then
# - Get 1st index of available wlan and eth adapters
local fp_ifconfig_tmp='/tmp/.ifconfig'
ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\|bond0\|sit0\|ip6tnl0\)$/d' > "$fp_ifconfig_tmp" #export to file, should be quicker in loop than calling ifconfig each time.
# find eth[0-9]
for ((i=0; i<=9; i++))
do
if (( $(cat "$fp_ifconfig_tmp" | grep -ci -m1 "eth$i") )); then
eth_index=eth${i}
break
fi
done
# Predictable Network Interface Names
[[ -z $eth_index ]] && eth_index=$(cat "$fp_ifconfig_tmp" | grep -m1 "en" | cut -f1 -d":" | head -1)
# find wlan[0-9]
for ((i=0; i<=9; i++))
do
if (( $(cat "$fp_ifconfig_tmp" | grep -ci -m1 "wlan$i") )); then
wlan_index=wlan${i}
break
fi
done
# Predictable Network Interface Names
[[ -z $wlan_index ]] && wlan_index=$(cat "$fp_ifconfig_tmp" | grep -m1 "wl" | cut -f1 -d":" | head -1)
rm "$fp_ifconfig_tmp"
# for static IP we only append settings
if [[ $FR_net_use_static == 1 ]]; then
local FIXED_IP_SETTINGS="ipv4.method manual ipv4.address ${FR_net_static_ip}/${FR_net_static_mask} ipv4.dns ${FR_net_static_dns} ipv4.gateway ${FR_net_static_gateway}"
fi
if [[ -n $eth_index || -n $wlan_index ]]; then
# delete all current connections
LC_ALL=C nmcli -t -f UUID,DEVICE connection show | awk '{print $1}' | cut -f1 -d":" | xargs nmcli connection delete
# - Wifi enable
if [[ $FR_net_wifi_enabled == 1 ]]; then
#Set wifi country code
iw reg set "$FR_net_wifi_countrycode"
nmcli con add con-name "Orange Pi wireless" type wifi ifname ${wlan_index} ssid "$FR_net_wifi_ssid" -- wifi-sec.key-mgmt wpa-psk wifi-sec.psk "$FR_net_wifi_key" ${FIXED_IP_SETTINGS}
nmcli con up "Orange Pi wireless"
#Enable Wlan, disable Eth
FR_net_ethernet_enabled=0
# - Ethernet enable
elif [[ $FR_net_ethernet_enabled == 1 ]]; then
nmcli con add con-name "Orange Pi ethernet" type ethernet ifname ${eth_index} -- ${FIXED_IP_SETTINGS}
nmcli con up "Orange Pi ethernet"
#Enable Eth, disable Wlan
FR_net_wifi_enabled=0
fi
fi
fi
fi
} #do_firstrun_automated_user_configuration
do_firstrun_automated_user_configuration
exit 0

View File

@@ -0,0 +1,180 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
# Functions:
#
# prepare_temp_monitoring
# log_hardware_info
# get_flash_information
# check_sd_card_speed
# Read in basic OS image information
. /etc/orangepi-release
# and script configuration
. /usr/lib/orangepi/orangepi-common
prepare_temp_monitoring() {
# still an ugly hack but better do it just once at startup instead of every login
[ -d /etc/orangepimonitor/datasources ] || mkdir -p -m775 /etc/orangepimonitor/datasources
# PMIC check
if [[ -f /sys/power/axp_pmu/pmu/temp ]]; then
ln -fs /sys/power/axp_pmu/pmu/temp /etc/orangepimonitor/datasources/pmictemp
elif [[ -f /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034//temp1_input ]]; then
ln -fs /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input \
/etc/orangepimonitor/datasources/pmictemp
elif [[ -f /sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/ic_temperature ]]; then
ln -fs /sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/ic_temperature \
/etc/orangepimonitor/datasources/pmictemp
elif [[ -f /sys/class/axppower/ic_temp ]]; then
ln -fs /sys/class/axppower/ic_temp /etc/orangepimonitor/datasources/pmictemp
fi
# SoC temp: check sun7i legacy exception first, then standard path(s)
if [[ -d "/sys/devices/platform/a20-tp-hwmon" ]]; then
# sun7i legacy
ln -fs /sys/devices/platform/a20-tp-hwmon/temp1_input /etc/orangepimonitor/datasources/soctemp
elif [[ -f /sys/class/hwmon/hwmon0/temp1_input && ${BOARDFAMILY} != "mvebu" ]]; then
# usual convention with modern kernels
ln -fs /sys/class/hwmon/hwmon0/temp1_input /etc/orangepimonitor/datasources/soctemp
else
# all other boards/kernels use the same sysfs node except of Actions Semi S500:
[[ ${BOARDFAMILY} == s500 ]] && THERMAL_ZONE="thermal_zone1" || THERMAL_ZONE="thermal_zone0"
ln -fs /sys/devices/virtual/thermal/${THERMAL_ZONE}/temp /etc/orangepimonitor/datasources/soctemp
fi
# Ambient temp
if [[ ${BOARD} == "helios4" && -f /dev/thermal-board/temp1_input ]]; then
ln -fs /dev/thermal-board/temp1_input /etc/orangepimonitor/datasources/ambienttemp
fi
} # prepare_temp_monitoring
log_hardware_info() {
[ -f "/etc/logrotate.d/${0##*/}" ] || \
echo -e "${Log} {\n rotate 12\n weekly\n compress\n missingok\n notifempty\n}" \
> "/etc/logrotate.d/${0##*/}" ; chmod 644 "/etc/logrotate.d/${0##*/}"
CPU_ARCH=$(lscpu | awk '/Architecture/ {print $2}')
DISTRO_ARCH=$(dpkg --print-architecture)
KERNELID=$(uname -r)
echo -e "\n$(date) | ${BOARD_NAME} | ${VERSION} | ${DISTRO_ARCH} | ${CPU_ARCH} | ${KERNELID}" >>${Log}
chmod 644 ${Log}
echo -e "\n### dmesg:\n" >>${Log}
dmesg >>${Log}
echo -e "\n### orangepi-release:\n" >>${Log}
cat /etc/orangepi-release >>${Log}
echo -e "\n### boot environment:\n" >>${Log}
cat /boot/orangepiEnv.txt >>${Log} 2>/dev/null || grep -v "^#" /boot/boot.ini | sed '/^\s*$/d' >>${Log}
echo -e "\n### lsusb:\n" >>${Log}
lsusb 2>/dev/null >>${Log}
echo -e "\n### lscpu:\n" >>${Log}
lscpu >>${Log}
echo -e "\n### cpuinfo:\n" >>${Log}
cat /proc/cpuinfo >>${Log}
echo -e "\n### meminfo:\n" >>${Log}
cat /proc/meminfo >>${Log}
echo -e "\n### virtual memory:\n" >>${Log}
for sysfsnode in /proc/sys/vm/* ; do sysctl $(echo ${sysfsnode} | sed 's|/proc/sys/vm/|vm.|'); done >>${Log}
if [ -x /sbin/ip ]; then
echo -e "\n### ip addr:\n" >>${Log}
/sbin/ip r s >>${Log} ; /sbin/ip a >>${Log}
echo " " >>${Log}
else
echo -e "\n### ifconfig:\n" >>${Log}
ifconfig >>${Log}
fi
echo -e "### partitions:\n" >>${Log}
grep -v " ram" /proc/partitions >>${Log}
echo -e "\n### df:\n" >>${Log}
df -h | egrep '^udev|^tmpfs|^/dev/|log2ram|folder2ram' >>${Log}
which zpool >/dev/null 2>&1 && echo -e "\n### zpools:\n\n$(zpool list)\n\n### zfs datasets:\n\n$(zfs list)" >>${Log}
echo -e "\n### lsblk:\n" >>${Log}
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,UUID | grep -v "SWAP" >>${Log}
which zramctl >/dev/null 2>&1 && echo -e "\n### zramctl:\n\n$(zramctl)" >>${Log}
echo -e "\n### mtab:\n" >>${Log}
egrep '^/dev/|\ zfs\ ' /etc/mtab | egrep -v "log2ram|folder2ram" | sort >>${Log}
[[ -e /boot/script.bin ]] && echo -e "\n### /boot/script.bin --> $(readlink /boot/script.bin)" >>${Log}
get_flash_information >>${Log}
echo -e "\n### Boot system health:\n" >>${Log}
orangepimonitor -s | egrep "^Time|^[0-9]" >>${Log}
} # log_hardware_info
get_flash_information() {
# http://www.bunniestudios.com/blog/?page_id=1022
find /sys -name oemid | while read Device ; do
DeviceNode="${Device%/*}"
DeviceName="${DeviceNode##*/}"
echo -e "\n### ${DeviceName} info:\n"
find "${DeviceNode}" -maxdepth 1 -type f | while read ; do
NodeName="${REPLY##*/}"
echo -e "$(printf "%20s" ${NodeName}): $(cat "${DeviceNode}/${NodeName}" | tr '\n' " ")"
done
done
} # get_flash_information
check_sd_card_speed() {
# function that checks on 3rd boot whether firstrun script made a quick benchmark
# and displays a motd warning when _random_ I/O is below some tresholds.
if [ -f /var/log/orangepi-hardware-monitor.log ]; then
RebootCount=$(grep -c '^### df:' /var/log/orangepi-hardware-monitor.log)
if [ ${RebootCount} -eq 2 ]; then
# check whether iozone data has been collected
IozoneResults="$(awk -F" " '/^### quick iozone test/ {print $10"\t"$11}' </var/log/orangepi-hardware-monitor.log)"
if [ "X${IozoneResults}" != "X" ]; then
set ${IozoneResults}
Readspeed=$1
Writespeed=$2
if [ ${Readspeed} -lt 500 -o ${Writespeed} -lt 250 ]; then
show_motd_warning "Your SD card seems to be very slow. Please check performance using orangepimonitor -c"
fi
fi
fi
fi
} # check_sd_card_speed
case $1 in
*start*)
# check sd card speed once on 3rd boot too warn for too slow media
check_sd_card_speed &
# prepare correct temperature readouts
prepare_temp_monitoring &
# log hardware id to file, write log
echo $BOARD_NAME >/var/run/machine.id # we should leave this, maybe users depend on it
if [ $? -ne 0 ]; then
# most probably readonly fs. We'll try to warn the user.
show_motd_warning "It seems the rootfs is readonly at the moment. Please check your SD card for errors"
fi
# check whether auto detection override exists and if true use this for machine.id
[ -f /root/.machine.id ] && cat /root/.machine.id >/var/run/machine.id
log_hardware_info &
;;
*stop*)
case ${BOARDFAMILY} in
sun?i)
# redefine green led to blink until shutdown, try to switch OTG port to host
(echo heartbeat >/sys/class/leds/*green*/trigger) 2>/dev/null
echo 0 > /sys/bus/platform/devices/sunxi_usb_udc/otg_role 2>/dev/null
;;
esac
# some kernel modules are known to crash the kernel on shutdown (an example
# is the mass storage gadget module at least on sun7i). We try to unload as
# much modules as possible to minimize such situations:
/sbin/modprobe -r $(cut -f1 -d' ' </proc/modules)
# shutdown logging
if [ -f /var/log.hdd/orangepi-hardware-monitor.log ]; then
echo -e "\n### shutdown:\n\n$(iostat -p zram0)\n\n$(vmstat -w)\n\n$(free -h)\n\n$(dmesg | tail -n 100)" >>/var/log.hdd/orangepi-hardware-monitor.log
else
echo -e "\n### shutdown:\n\n$(iostat -p zram0)\n\n$(vmstat -w)\n\n$(free -h)\n\n$(dmesg | tail -n 100)" >>/var/log/orangepi-hardware-monitor.log
fi
sync
;;
esac

View File

@@ -0,0 +1,687 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
# Functions:
#
# set_io_scheduler
# prepare_board
# add_usb_storage_quirks
# Read in basic OS image information
. /etc/orangepi-release
# and script configuration
. /usr/lib/orangepi/orangepi-common
# set audio
#. /usr/lib/orangepi/orangepi-audio-config
set_io_scheduler() {
# Convert kernel version to integer
KERNELID=$(uname -r | awk -F'.' '{print ($1 * 100) + $2}')
for i in $( lsblk -idn -o NAME | grep -v zram ); do
read ROTATE </sys/block/$i/queue/rotational
case ${ROTATE} in
1) # mechanical drives
[[ $KERNELID -lt 420 ]] && sched=cfq || sched=bfq
;;
0) # flash based
[[ $KERNELID -lt 420 ]] && sched=noop || sched=none
;;
*)
continue
;;
esac
echo $sched >/sys/block/$i/queue/scheduler
echo -e "[\e[0;32m ok \x1B[0m] Setting $sched I/O scheduler for $i"
done
} # set_io_scheduler
prepare_board() {
CheckDevice=$(for i in /var/log /var / ; do findmnt -n -o SOURCE $i && break ; done)
# adjust logrotate configs
if [[ "${CheckDevice}" == *"/dev/zram"* || "${CheckDevice}" == "orangepi-ramlog" ]]; then
for ConfigFile in /etc/logrotate.d/* ; do sed -i -e "s/\/var\/log\//\/var\/log.hdd\//g" "${ConfigFile}"; done
sed -i "s/\/var\/log\//\/var\/log.hdd\//g" /etc/logrotate.conf
else
for ConfigFile in /etc/logrotate.d/* ; do sed -i -e "s/\/var\/log.hdd\//\/var\/log\//g" "${ConfigFile}"; done
sed -i "s/\/var\/log.hdd\//\/var\/log\//g" /etc/logrotate.conf
fi
# unlock cpuinfo_cur_freq to be accesible by a normal user
prefix="/sys/devices/system/cpu/cpufreq"
for f in $(ls -1 $prefix 2> /dev/null)
do
[[ -f $prefix/$f/cpuinfo_cur_freq ]] && chmod +r $prefix/$f/cpuinfo_cur_freq 2> /dev/null
done
# older kernels
prefix="/sys/devices/system/cpu/cpu0/cpufreq/"
[[ -f $prefix/cpuinfo_cur_freq ]] && chmod +r $prefix/cpuinfo_cur_freq 2> /dev/null
# enable compression where not exists
find /etc/logrotate.d/. -type f | xargs grep -H -c 'compress' | grep 0$ | cut -d':' -f1 | xargs -r -L1 sed -i '/{/ a compress'
sed -i "s/#compress/compress/" /etc/logrotate.conf
# tweak ondemand cpufreq governor settings to increase cpufreq with IO load
grep -q ondemand /etc/default/cpufrequtils
if [ $? -eq 0 ]; then
echo ondemand >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
cd /sys/devices/system/cpu
for i in cpufreq/ondemand cpu0/cpufreq/ondemand cpu4/cpufreq/ondemand ; do
if [ -d $i ]; then
echo 1 >${i}/io_is_busy
echo 25 >${i}/up_threshold
echo 10 >${i}/sampling_down_factor
echo 200000 >${i}/sampling_rate
fi
done
fi
chmod +x /etc/update-motd.d/*
# IRQ distribution based on $BOARDFAMILY and/or $BOARD_NAME
case ${BOARD} in
rockpro64|renegade-elite|pinebook-pro|station-p1)
BOARDFAMILY=rk3399
;;
orangepi5|orangepicm5|orangepicm5-tablet|orangepi5b|orangepi5plus|orangepiaimax|orangepi5pro|orangepi5max|orangepi5ultra|orangepitab|orangepi900)
[[ $BOARD =~ orangepi5|orangepi5b ]] && echo host > /sys/kernel/debug/usb/fc000000.usb/mode
if [[ $BOARD =~ orangepicm5 ]]; then
while true; do
echo "set host!"
echo host > /sys/kernel/debug/usb/fc000000.usb/mode
sleep 0.5
count=0
for i in {1..3}; do
sleep 0.5
echo "check"
if [[ "$(cat /sys/kernel/debug/usb/fc000000.usb/mode)" == "host" ]]; then
((count++))
else
break
fi
echo "check host $count"
done
[[ $count -eq 3 ]] && break
echo "fail"
done
fi
if [[ ${BOARD}x == orangepicm5-tabletx ]]; then
tinymix -D 2 aw87xxx_profile_switch_0 Music
tinymix -D 2 aw87xxx_profile_switch_1 Music
fi
if [[ ${BOARD}x == orangepicm5x ]]; then
declare -A led_map=(
["wan"]="end|eth"
["lan1"]="enP4"
["lan2"]="enP3"
)
for led in "${!led_map[@]}"; do
interface=$(ls /sys/class/net/ | grep -E "${led_map[$led]}" | sed -n 1p)
echo netdev > "/sys/class/leds/$led/trigger"
echo "$interface" > "/sys/class/leds/$led/device_name"
echo 1 > "/sys/class/leds/$led/tx"
echo 1 > "/sys/class/leds/$led/rx"
echo 1 > "/sys/class/leds/$led/link"
done
fi
if [[ $BOARD =~ orangepi900 ]]; then
es8388_card=$(aplay -l | grep "es8388" | cut -d ':' -f 1 | cut -d ' ' -f 2)
jack_num=$(tinymix -D ${es8388_card} | grep "Headphone Jack" | cut -c1-2)
if [[ $(tinymix -D ${es8388_card} $jack_num | cut -d ":" -f 2) == *On ]]; then
tinymix -D ${es8388_card} 25 2
tinymix -D ${es8388_card} 27 2
else
tinymix -D ${es8388_card} 25 0
tinymix -D ${es8388_card} 27 0
fi
elif [[ $BOARD =~ orangepi5plus|orangepiaimax ]]; then
amixer -c ${es8388_card} cset name='PCM Volume' 190 >/dev/null 2>&1
amixer -c ${es8388_card} cset name='Right Mixer Right Playback Switch' off >/dev/null 2>&1
fi
if [[ -c /dev/mpp_service ]]; then
chmod 0666 /dev/mpp_service
if [[ $DISTRIBUTION_CODENAME =~ bullseye|bookworm|jammy ]]; then
{
echo "type=dec"
echo "codecs=VP8:VP9:H.264:H.265:AV1"
echo "max-width=7680"
echo "max-height=4320"
} > /dev/video-dec0
else
echo dec > /dev/video-dec0
fi
# Create dummy video node for chromium V4L2 VDA/VEA with rkmpp plugin
echo enc > /dev/video-enc0
chmod 0660 /dev/video-*
chown root:video /dev/video-*
fi
for p in $(modetest|grep "^Planes:" -A 9999|grep -o "^[0-9]*");
do
modetest -M rockchip -aw $p:ASYNC_COMMIT:1 &>/dev/null
done
bt_status=$(cat /proc/device-tree/wireless-bluetooth/status)
wifi_chip=$(cat /proc/device-tree/wireless-wlan/wifi_chip_type)
if [[ ${wifi_chip} == "ap6275p" && ${bt_status} == "okay" ]]; then
rfkill unblock all
brcm_patchram_plus --bd_addr_rand --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 \
--baudrate 1500000 --patchram /lib/firmware/ap6275p/BCM4362A2.hcd /dev/ttyS9 &
fi
es8388_card=$(aplay -l | grep "es8388" | cut -d ':' -f 1 | cut -d ' ' -f 2)
amixer -c ${es8388_card} cset name='OUT1 Switch' on >/dev/null 2>&1
amixer -c ${es8388_card} cset name='ALC Capture NG Switch' 1 >/dev/null 2>&1
amixer -c ${es8388_card} cset name='ALC Capture Function' 3 >/dev/null 2>&1
if [[ $BOARD =~ orangepi5pro|orangepicm5-tablet ]]; then
es8388_card=$(aplay -l | grep "es8388" | cut -d ':' -f 1 | cut -d ' ' -f 2)
tinymix -D ${es8388_card} 37 1
rfkill unblock all
brcm_patchram_plus --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 \
--baudrate 1500000 --patchram /lib/firmware/BCM4345C0.hcd /dev/ttyS9 &
elif [[ $BOARD =~ orangepi5max|orangepi5ultra ]]; then
rfkill unblock all
sleep 2
brcm_patchram_plus --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 \
--baudrate 1500000 --patchram /lib/firmware/SYN43711A0.hcd /dev/ttyS7 &
fi
;;
orangepi6plus)
if [ ! -e /dev/dma_heap/linux,cma ]; then
ln -s /dev/dma_heap/reserved /dev/dma_heap/linux,cma
fi
;;
orangepi3-lts)
#aplay /usr/share/sounds/alsa/audio.wav -D hw:0,0 > /dev/null 2>&1
rfkill unblock all
/usr/bin/hciattach_opi -n -s 1500000 /dev/ttyBT0 sprd &
;;
orangepi800)
[[ -f /sys/class/leds/caps_led/brightness ]] && chmod 666 /sys/class/leds/caps_led/brightness
[[ -f /sys/class/leds/num_led/brightness ]] && chmod 666 /sys/class/leds/num_led/brightness
if [[ -c /dev/mpp_service ]]; then
chmod 666 /dev/mpp_service
# Create dummy video node for chromium V4L2 VDA/VEA with rkmpp plugin
echo dec > /dev/video-dec0
echo enc > /dev/video-enc0
chmod 660 /dev/video-*
chown root.video /dev/video-*
fi
rfkill unblock all
/usr/bin/hciattach_opi -n -s 1500000 /dev/ttyBT0 sprd &
;;
orangepir1plus|orangepir1plus-lts)
echo netdev > /sys/class/leds/lan_led/trigger
echo lan0 > /sys/class/leds/lan_led/device_name
echo 1 > /sys/class/leds/lan_led/link
/usr/bin/pwm-fan.sh &
;;
orangepizero2|orangepizero2-lts|orangepizero2-b|orangepizero3|orangepizero3plus|orangepir1b|orangepizero2w)
kv=$(uname -r)
#if [[ $BRANCH == current ]]; then
# # Initial hdmi audio
# aplay /usr/share/sounds/alsa/mute.wav -D hw:0,0 > /dev/null 2>&1
# aplay /usr/share/sounds/alsa/mute.wav -D hw:1,0 > /dev/null 2>&1
# aplay /usr/share/sounds/alsa/mute.wav -D hw:0,0 > /dev/null 2>&1
#fi
if [[ $BOARD == orangepizero2w ]]; then
if [[ ${DISTRIBUTION_CODENAME} == "bookworm" || ${DISTRIBUTION_CODENAME} == "noble" ]]; then
interface_100m="end0"
else
interface_100m="eth0"
fi
echo netdev > /sys/class/leds/100m_act/trigger
echo "${interface_100m}" > /sys/class/leds/100m_act/device_name
echo 1 > /sys/class/leds/100m_act/tx
echo 1 > /sys/class/leds/100m_act/rx
echo netdev > /sys/class/leds/100m_link/trigger
echo ${interface_100m} > /sys/class/leds/100m_link/device_name
echo 1 > /sys/class/leds/100m_link/link
fi
if [[ $BOARD == orangepir1b ]]; then
#for 100m interface
interface_100m="eth1"
echo netdev > /sys/class/leds/100m_act/trigger
echo "${interface_100m}" > /sys/class/leds/100m_act/device_name
echo 1 > /sys/class/leds/100m_act/tx
echo 1 > /sys/class/leds/100m_act/rx
echo netdev > /sys/class/leds/100m_link/trigger
echo ${interface_100m} > /sys/class/leds/100m_link/device_name
echo 1 > /sys/class/leds/100m_link/link
echo netdev > /sys/class/leds/lan_led/trigger
echo ${interface_100m} > /sys/class/leds/lan_led/device_name
echo 1 > /sys/class/leds/lan_led/link
echo 1 > /sys/class/leds/lan_led/tx
echo 1 > /sys/class/leds/lan_led/rx
#for 1000m interface
interface_1000m="eth0"
echo netdev > /sys/class/leds/wan_led/trigger
echo ${interface_1000m} > /sys/class/leds/wan_led/device_name
echo 1 > /sys/class/leds/wan_led/link
echo 1 > /sys/class/leds/wan_led/tx
echo 1 > /sys/class/leds/wan_led/rx
fi
if [[ ${kv} == 4.9* ]]; then
aplay /usr/share/sounds/alsa/audio.wav -D hw:2,0 > /dev/null 2>&1
fi
if [[ $BOARD == orangepizero3plus ]]; then
(while [[ ! -e /proc/bluetooth/sleep/btwrite ]]; do sleep 1; done; echo 1 > /proc/bluetooth/sleep/btwrite; \
/usr/bin/hciattach_opi -n -s 1500000 /dev/ttyAS1 aic) &
else
rfkill unblock all
/usr/bin/hciattach_opi -n -s 1500000 /dev/ttyBT0 sprd &
fi
;;
orangepi400)
rfkill unblock all
/usr/bin/hciattach_opi -n -s 1500000 /dev/ttyBT0 sprd &
[[ -f /sys/class/leds/caps_led/brightness ]] && chmod 666 /sys/class/leds/caps_led/brightness
[[ -f /sys/class/leds/num_led/brightness ]] && chmod 666 /sys/class/leds/num_led/brightness
;;
orangepi4)
if [[ -c /dev/mpp_service ]]; then
chmod 666 /dev/mpp_service
elif [[ -c /dev/vpu_service ]]; then
chmod 666 /dev/vpu_service
fi
# Create dummy video node for chromium V4L2 VDA/VEA with rkmpp plugin
echo dec > /dev/video-dec0
echo enc > /dev/video-enc0
chmod 660 /dev/video-*
chown root.video /dev/video-*
rfkill unblock all
/usr/bin/brcm_patchram_plus -d --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 \
--baudrate 1500000 --patchram /lib/firmware/brcm/BCM4345C5.hcd /dev/ttyS0 &
;;
orangepi4-lts)
# RK3399 - 1.8GHz
# RK3399-T - 1.6GHz
sed -i "s/MAX_SPEED=.*/MAX_SPEED=$(cpufreq-info -c 4 -l | awk '{ print $2 }')/" /etc/default/cpufrequtils
CODEC_CARD=0
amixer -c ${CODEC_CARD} cset name='Differential Mux' 1 >/dev/null 2>&1
if [[ -c /dev/mpp_service ]]; then
chmod 666 /dev/mpp_service
elif [[ -c /dev/vpu_service ]]; then
chmod 666 /dev/vpu_service
fi
# Create dummy video node for chromium V4L2 VDA/VEA with rkmpp plugin
echo dec > /dev/video-dec0
echo enc > /dev/video-enc0
chmod 660 /dev/video-*
chown root.video /dev/video-*
rfkill unblock all
/usr/bin/hciattach_opi -n -s 1500000 /dev/ttyBT0 sprd &
;;
orangepi4a)
echo usb_host > /sys/devices/platform/soc@3000000/10.usbc0/otg_role
echo 4 1 > /sys/devices/platform/soc@3000000/2020000.nsi-controller/nsi-pmu/hwmon0/port_abs_bwlen
echo 4 400 > /sys/devices/platform/soc@3000000/2020000.nsi-controller/nsi-pmu/hwmon0/port_abs_bwl
chmod 666 /dev/vipcore
tinymix -D 0 23 1
tinymix -D 0 26 1
rfkill unblock all
/usr/bin/brcm_patchram_plus --enable_hci --no2bytes --tosleep 200000 \
--baudrate 1500000 --patchram /lib/firmware/BCM4345C5.hcd /dev/ttyAS1 &
;;
orangepicm4|orangepi3b)
echo host > /sys/devices/platform/fe8a0000.usb2-phy/otg_mode
if [[ -c /dev/mpp_service ]]; then
chmod 666 /dev/mpp_service
# Create dummy video node for chromium V4L2 VDA/VEA with rkmpp plugin
echo dec > /dev/video-dec0
echo enc > /dev/video-enc0
chmod 660 /dev/video-*
chown root.video /dev/video-*
fi
for p in $(modetest|grep "^Planes:" -A 9999|grep -o "^[0-9]*");
do
modetest -M rockchip -aw $p:ASYNC_COMMIT:1 &>/dev/null
done
amixer -c 0 cset name='Playback Path' HP > /dev/null 2>&1
amixer -c 0 cset name='Capture MIC Path' 'Main Mic' > /dev/null 2>&1
bt_status=$(cat /proc/device-tree/wireless-bluetooth/status)
wifi_chip=$(cat /proc/device-tree/wireless-wlan/wifi_chip_type)
if [[ "${wifi_chip}" == "ap6256" && "${bt_status}" == "okay" ]]; then
rfkill unblock all
brcm_patchram_plus --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 \
--baudrate 1500000 --patchram /lib/firmware/BCM4345C0.hcd /dev/ttyS1 &
else
rfkill unblock all
(while [ ! -e /dev/ttyBT0 ]; do sleep 1; done; hciattach_opi -n -s 1500000 /dev/ttyBT0 sprd) &
fi
;;
orangepi3plus)
gpio mode 28 in
gpio mode 28 up
gpio read 28
;;
orangepirv)
echo 30 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio30/direction
echo 0 > /sys/class/gpio/gpio30/value
sleep 1
echo 1 > /sys/class/gpio/gpio30/value
/usr/bin/brcm_patchram_plus -d --enable_hci --no2bytes --tosleep 200000 \
--baudrate 115200 --patchram /lib/firmware/BCM4345C5.hcd /dev/ttyS1 &
media-ctl --set-v4l2 '"imx219 6-0010":0[fmt:SRGGB10_1X10/1920x1080]'
/opt/media-ctl-pipeline.sh -d /dev/media0 -i csiphy0 -s ISP0 -a start
/opt/ISP/stf_isp_ctrl -m imx219mipi -j 0 -a 1 &
;;
orangepirv2)
rfkill unblock all
/usr/bin/brcm_patchram_plus --enable_hci --no2bytes --tosleep 200000 \
--baudrate 1500000 --patchram /lib/firmware/BCM4345C5.hcd /dev/ttyS2 &
;;
orangepir2s)
echo ff > /sys/class/net/enP2p1s0/queues/rx-0/rps_cpus
echo ff > /sys/class/net/enP1p1s0/queues/rx-0/rps_cpus
echo 4096 > /sys/class/net/enP2p1s0/queues/rx-0/rps_flow_cnt
echo 4096 > /sys/class/net/enP1p1s0/queues/rx-0/rps_flow_cnt
;;
aipcliteb)
echo usb_host > /sys/devices/platform/soc@3000000/10.usbc0/otg_role
(
echo 1 > /sys/bus/pci/rescan
if lspci | grep -q BCM43752; then
rfkill unblock all
sleep 5
brcm_patchram_plus --enable_hci \
--no2bytes --use_baudrate_for_download --tosleep 200000 --baudrate 1500000 \
--patchram /lib/firmware/ap6275p/BCM4362A2.hcd /dev/ttyAS1
fi
) &
;;
orangepi4pro)
/sbin/insmod /opt/pvrsrvkm.ko
echo 40 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio40/direction
echo 1 > /sys/class/gpio/gpio40/value
echo usb_host > /sys/devices/platform/soc@3000000/10.usbc0/otg_role
(while [[ ! -e /proc/bluetooth/sleep/btwrite ]]; do sleep 1; done; echo 1 > /proc/bluetooth/sleep/btwrite; \
/usr/bin/hciattach_opi -n -s 1500000 /dev/ttyS1 aic) &
#/sbin/rmmod sunxi_stmmac && /sbin/modprobe sunxi_stmmac
amixer -c 1 cset name='ADCL PGA Volume' 10 >/dev/null 2>&1
amixer -c 1 cset name='ADCR PGA Volume' 10 >/dev/null 2>&1
;;
orangepizero3w)
/sbin/insmod /opt/pvrsrvkm.ko
echo usb_host > /sys/devices/platform/soc@3000000/10.usbc0/otg_role
(while [[ ! -e /proc/bluetooth/sleep/btwrite ]]; do sleep 1; done; echo 1 > /proc/bluetooth/sleep/btwrite; \
/usr/bin/hciattach_opi -n -s 1500000 /dev/ttyS1 aic) &
;;
esac
case ${BOARDFAMILY} in
rockchip) # RK3288: usb1 on cpu1, usb3 (EHCI) on cpu2, eth0 and GPU on cpu3
echo 2 >/proc/irq/$(awk -F":" "/usb1/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
echo 4 >/proc/irq/$(awk -F":" "/usb3/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
echo 8 >/proc/irq/$(awk -F":" "/eth0/ {print \$1}" </proc/interrupts | sed 's/\ //g' | head -n1)/smp_affinity
echo 7 >/sys/class/net/eth0/queues/rx-0/rps_cpus
for i in $(awk -F':' '/gpu/{print $1}' /proc/interrupts | sed 's/\ //g'); do
echo 8 >/proc/irq/$i/smp_affinity
done
;;
rockchip64) # Rock64 and Renegade: GPU on cpu1, USB3 on cpu2, Ethernet on cpu3
for i in $(awk -F':' '/Mali/{print $1}' </proc/interrupts | sed 's/\ //g'); do
echo 2 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F":" "/ehci/ {print \$1}" </proc/interrupts | sed 's/\ //g'); do
echo 2 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F":" "/ohci/ {print \$1}" </proc/interrupts | sed 's/\ //g'); do
echo 2 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F":" "/xhci/ {print \$1}" </proc/interrupts | sed 's/\ //g'); do
echo 4 >/proc/irq/$i/smp_affinity
done
# Wait (up to 5s) until eth0 brought up
for i in {1..5}; do
grep -q "eth0" /proc/interrupts && break
sleep 1
done
echo 8 >/proc/irq/$(awk -F":" "/eth0/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
echo 7 >/sys/class/net/eth0/queues/rx-0/rps_cpus
echo 32768 >/proc/sys/net/core/rps_sock_flow_entries
echo 32768 >/sys/class/net/eth0/queues/rx-0/rps_flow_cnt
;;
rk3399)
for i in $(awk -F':' '/gpu/{print $1}' </proc/interrupts | sed 's/\ //g'); do
echo 2 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F':' '/dw-mci/{print $1}' </proc/interrupts | sed 's/\ //g'); do
echo 2 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F":" "/ehci/ {print \$1}" </proc/interrupts | sed 's/\ //g'); do
echo 2 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F":" "/ohci/ {print \$1}" </proc/interrupts | sed 's/\ //g'); do
echo 2 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F":" "/xhci/ {print \$1}" </proc/interrupts | sed 's/\ //g'); do
echo 4 >/proc/irq/$i/smp_affinity
done
# Wait (up to 5s) until eth0 brought up
for i in {1..5}; do
grep -q "eth0" /proc/interrupts && break
sleep 1
done
echo 8 >/proc/irq/$(awk -F":" "/eth0/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
echo 7 >/sys/class/net/eth0/queues/rx-0/rps_cpus
echo 32768 >/proc/sys/net/core/rps_sock_flow_entries
echo 32768 >/sys/class/net/eth0/queues/rx-0/rps_flow_cnt
for i in $(awk -F':' 'tolower($0) ~ /pcie/{print $1}' </proc/interrupts | sed 's/\ //g'); do
echo 16 >/proc/irq/$i/smp_affinity
done
# set dmc memory governor to performance with default kernel
if [ -f /sys/bus/platform/drivers/rockchip-dmc/dmc/devfreq/dmc/governor ]; then
echo performance > /sys/bus/platform/drivers/rockchip-dmc/dmc/devfreq/dmc/governor
fi
;;
sun4i|sun5i|rda8810) # only one core, nothing to improve
:
;;
sun8i*) # H3/R40/V40 boards, try to do the best based on specific board since interfaces vary a lot
# 10 or 120 sec user feedback that the board is ready after 1st login with 3.4 kernel
SwapState="$(grep swap /etc/fstab)"
if [ "X${SwapState}" != "X" ]; then
(echo heartbeat >/sys/class/leds/*green*/trigger) 2>/dev/null
[ -f "/root/.not_logged_in_yet" ] && BlinkTime=120 || BlinkTime=10
(sleep ${BlinkTime} && (echo default-on >/sys/class/leds/*green*/trigger) 2>/dev/null) &
fi
# check kernel version for IRQ/module names
case ${KERNELID} in
3*)
# BSP kernel
GbE="gmac0"; WiFi="wlan0"; USB1="usb2"; USB2="usb3"; USB3="usb4"
;;
*)
# Mainline kernel
GbE="eth0"; WiFi="wlan0"; USB1="usb3"; USB2="usb4"; USB3="usb5"
;;
esac
# Assign 1st and 2nd USB port to cpu1 and cpu2 on every sun8i board
echo 2 >/proc/irq/$(awk -F":" "/${USB1}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
echo 4 >/proc/irq/$(awk -F":" "/${USB2}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
case ${BOARD_NAME} in
"Orange Pi+"|"Orange Pi+ 2"|"Orange Pi+ 2E"|"Banana Pi M2*"|"NanoPi M1 Plus")
# Send GBit Ethernet IRQs to cpu3
echo 8 >/proc/irq/$(awk -F":" "/${GbE}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
echo 7 >/sys/class/net/eth0/queues/rx-0/rps_cpus
;;
"NanoPi M1"|"Orange Pi PC Plus"|"Orange Pi PC +"|"Orange Pi PC"|"NanoPi Neo"|"Orange Pi Zero")
# Send 3rd USB port's IRQs to cpu3
echo 8 >/proc/irq/$(awk -F":" "/${USB3}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
;;
"Orange Pi Lite"|"NanoPi Air"|"Lime A33"|"Orange Pi Zero Plus 2"*)
# Send SDIO/mmc IRQs to cpu3
for i in $(awk -F':' '/sunxi-mmc/{print $1}' </proc/interrupts | sed 's/\ //g'); do
echo 8 >/proc/irq/$i/smp_affinity
done
;;
"Beelink X2"|"Orange Pi R1")
# Wifi module reload workaround / fix
[[ -n $(lsmod | grep 8189es) ]] && rmmod 8189es && modprobe 8189es
# Send SDIO to cpu1, USB to cpu2, Ethernet to cpu3
for i in $(awk -F':' '/sunxi-mmc/{print $1}' </proc/interrupts | sed 's/\ //g'); do
echo 2 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F':' '/hcd:usb/{print $1}' </proc/interrupts | sed 's/\ //g'); do
echo 4 >/proc/irq/$i/smp_affinity
done
echo 8 >/proc/irq/$(awk -F":" "/${GbE}/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
;;
esac
;;
sun50i*|sunxi64*) # A64/H5 based boards like Pine64, OPi PC 2, NanoPi NEO 2
# Send IRQs for the lower real USB port (usb2) to cpu2 and for the upper (OTG/usb1) to cpu1
echo 2 >/proc/irq/$(awk -F":" "/usb1/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
echo 4 >/proc/irq/$(awk -F":" "/usb2/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
echo 8 >/proc/irq/$(awk -F":" "/sunxi-mmc/ {print \$1}" </proc/interrupts | sed 's/\ //g' | head -n1)/smp_affinity
echo 8 >/proc/irq/$(awk -F":" "/eth/ {print \$1}" </proc/interrupts | sed 's/\ //g' | head -n1)/smp_affinity
echo 7 >/sys/class/net/eth0/queues/rx-0/rps_cpus
# OrangePi win GMAC is very unstable on gigabit. Limit it down to 100Mb solve problems
[[ $BOARD == orangepiwin && $BRANCH == legacy ]] && ethtool -s eth0 speed 100 duplex full
;;
esac
} # prepare_board
add_usb_storage_quirks() {
# check for /boot/orangepiEnv.txt existence
[ -f /boot/orangepiEnv.txt ] || return
# cleanup. add LF. This prevents adding parameters to the same line
echo "" >> /boot/orangepiEnv.txt; sed -i '/^$/d;$G' /boot/orangepiEnv.txt; sed -i '/^$/d;$G' /boot/orangepiEnv.txt
# cleanup. remove empty lines in the middle
sed -i '/^$/d' /boot/orangepiEnv.txt
# preserve old contents if existent
TMPFILE=$(mktemp /tmp/${0##*/}.XXXXXX)
trap "sleep 1 ; rm \"${TMPFILE}\" ; exit 0" 0 1 2 3 15
awk -F"=" '/^usbstoragequirks/ {print $2}' </boot/orangepiEnv.txt | tr -d -c '[:graph:]' >${TMPFILE}
# UAS blacklist Norelsys NS1068X and NS1066X since broken. Can be removed once
# they're blacklisted upstream
[ -s ${TMPFILE} ] || echo "0x2537:0x1066:u,0x2537:0x1068:u" >${TMPFILE}
# check for connected Seagate or WD HDD enclosures and blacklist them all
lsusb | awk -F" " '{print "0x"$6}' | sed 's/:/:0x/' | sort | uniq | while read ; do
case ${REPLY} in
"0x0bc2:"*|"0x1058:"*)
grep -q "${REPLY}" ${TMPFILE} || sed -i "1 s/\$/,${REPLY}:u/" ${TMPFILE}
;;
esac
done
read USBQUIRKS <${TMPFILE}
sed -i '/^usbstoragequirks/d' /boot/orangepiEnv.txt
echo "usbstoragequirks=${USBQUIRKS}" >>/boot/orangepiEnv.txt
sync &
if [ -f /sys/module/usb_storage/parameters/quirks ]; then
echo ${USBQUIRKS} >/sys/module/usb_storage/parameters/quirks
fi
} # add_usb_storage_quirks
branch_naming_workaround()
# https://armbian.atlassian.net/browse/AR-748
# Once we rework kernel packages, this can be done better
{
if [[ -z $(cat /etc/orangepi-release | grep BRANCH) ]]; then
BRANCH=$(dpkg -l | egrep "linux-image" | egrep "current|legacy|edge" | awk '{print $2}' | cut -d"-" -f3 | head -1)
[[ -n ${BRANCH} ]] && echo "BRANCH=$BRANCH" >> /etc/orangepi-release
fi
}
case $1 in
*start*)
# set optimal disk scheduler settings
set_io_scheduler &
# hardware preparation
prepare_board &
# add usb quirks
# add_usb_storage_quirks &
# branch naming workaround
branch_naming_workaround &
;;
esac

View File

@@ -0,0 +1,140 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
SIZE=50M
USE_RSYNC=true
ENABLED=false
[ -f /etc/default/orangepi-ramlog ] && . /etc/default/orangepi-ramlog
[ "$ENABLED" != true ] && exit 0
# Never touch anything below here. Only edit /etc/default/orangepi-ramlog
HDD_LOG=/var/log.hdd/
RAM_LOG=/var/log/
LOG2RAM_LOG="${HDD_LOG}orangepi-ramlog.log"
LOG_OUTPUT="tee -a $LOG2RAM_LOG"
isSafe () {
[ -d $HDD_LOG ] || (echo "ERROR: $HDD_LOG doesn't exist! Can't sync." >&2 ; exit 1)
NoCache=$(command -v nocache 2>/dev/null)
}
RecreateLogs (){
# in case of crash those services don't start if there are no dirs & logs
check_if_installed apache2 && [ ! -d /var/log/apache2 ] && mkdir -p /var/log/apache2
check_if_installed cron-apt && [ ! -d /var/log/cron-apt ] && \
(mkdir -p /var/log/cron-apt ; touch /var/log/cron-apt/log)
check_if_installed proftpd-basic && [ ! -d /var/log/proftpd ] && \
(mkdir -p /var/log/proftpd ; touch /var/log/proftpd/controls.log)
check_if_installed nginx && [ ! -d /var/log/nginx ] && \
(mkdir -p /var/log/nginx ; touch /var/log/nginx/access.log ; touch /var/log/nginx/error.log)
check_if_installed lighttpd && [ ! -d /var/log/lighttpd ] && \
(mkdir -p /var/log/lighttpd ; touch /var/log/lighttpd/access.log ; touch /var/log/lighttpd/error.log)
check_if_installed samba && [ ! -d /var/log/samba ] && mkdir -p /var/log/samba
check_if_installed unattended-upgrades && [ ! -d /var/log/unattended-upgrades ] && mkdir -p /var/log/unattended-upgrades
return 0
}
syncToDisk () {
isSafe
echo -e "\n\n$(date): Syncing logs to storage\n" | $LOG_OUTPUT
if [ "$USE_RSYNC" = true ]; then
${NoCache} rsync -aXWv \
--exclude "lost+found" --exclude orangepi-ramlog.log \
--delete \
--links \
${XTRA_RSYNC_TO[@]+"${XTRA_RSYNC_TO[@]}"} \
$RAM_LOG $HDD_LOG 2>&1 | $LOG_OUTPUT
else
${NoCache} cp -rfup $RAM_LOG -T $HDD_LOG 2>&1 | $LOG_OUTPUT
fi
sync /
}
syncFromDisk () {
isSafe
echo -e "\n\n$(date): Loading logs from storage\n" | $LOG_OUTPUT
if [ "$USE_RSYNC" = true ]; then
${NoCache} rsync -aXWv --delete \
--exclude "lost+found" --exclude orangepi-ramlog.log \
--exclude *.gz --exclude *.xz --exclude='*.[0-9]' \
--links \
${XTRA_RSYNC_FROM[@]+"${XTRA_RSYNC_FROM[@]}"} \
$HDD_LOG $RAM_LOG 2>&1 | $LOG_OUTPUT
else
${NoCache} find $HDD_LOG* -maxdepth 1 -type f -not \( -name '*.[0-9]' -or -name '*.xz*' -or -name '*.gz' \) | xargs cp -ut $RAM_LOG
fi
sync /
}
check_if_installed () {
local DPKG_Status="$(dpkg -s "$1" 2>/dev/null | awk -F": " '/^Status/ {print $2}')"
if [[ "X${DPKG_Status}" = "X" || "${DPKG_Status}" = *deinstall* ]]; then
return 1
else
return 0
fi
}
case "$1" in
start)
[ -d $HDD_LOG ] || mkdir -p $HDD_LOG
mount --bind $RAM_LOG $HDD_LOG
mount --make-private $HDD_LOG
# Check whether zram device is available or we need to use tmpfs
LOG_TYPE="tmpfs"
for rd in /dev/zram*; do
if [[ "$(e2label $rd)" == "log2ram" ]]; then
LOG_TYPE="zram"
break
fi
done
case $LOG_TYPE in
zram)
echo -e "Mounting $rd as $RAM_LOG \c" | $LOG_OUTPUT
mount -o discard $rd $RAM_LOG 2>&1 | $LOG_OUTPUT
;;
tmpfs)
echo -e "Setting up $RAM_LOG as tmpfs \c" | $LOG_OUTPUT
mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=$SIZE orangepi-ramlog $RAM_LOG 2>&1 | $LOG_OUTPUT
;;
esac
syncFromDisk
RecreateLogs
;;
stop)
syncToDisk
umount -l $RAM_LOG
umount -l $HDD_LOG
;;
write)
syncToDisk
;;
postrotate)
cd /var/log.hdd/
find . -type f -print | grep -E -v "(\.gz|\.xz|\.[0-9]|orangepi-ramlog)" | while IFS= read -r file
do
dest="/var/log/$file"
cat $file > $dest
done
;;
*)
echo "Usage: ${0##*/} {start|stop|write}" >&2
exit 1
;;
esac

View File

@@ -0,0 +1,234 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
. /etc/orangepi-release
. /lib/init/vars.sh
. /lib/lsb/init-functions
. /usr/lib/orangepi/orangepi-common
do_expand_partition()
{
# check if growroot (from cloud-initramfs-growroot package) is installed.
# despite it's name, that package does NOT require cloud-init.
# if so, it means the partition with root filesystem was already resized during initramfs.
# in this case do nothing here, but return 0 to allow resize2fs to run (growroot does not handle that).
if [[ -f /usr/share/initramfs-tools/hooks/growroot ]] || [[ -f /usr/share/initramfs-tools/scripts/local-bottom/growroot ]]; then
echo "partition resize skipped: growroot detected."
return 0
fi
# trim any btrfs subvolume identifier given in square brackets (e.g. /dev/mapper/orangepi-root[/@])
local rootsource=$(findmnt -n -o SOURCE / | sed 's~\[.*\]~~') # i.e. /dev/mmcblk0p1 or /dev/mapper/orangepi-root
old_partuuid=$(sudo blkid ${rootsource} -s PARTUUID -o value)
# check for device type
local roottype=$(lsblk -n -o TYPE $rootsource) # crypt, part or disk
case ${roottype} in
crypt)
IS_CRYPTDEVICE=true
local cryptname=$(lsblk -n -o NAME $rootsource)
local parent_uuid=$(cat /etc/crypttab | awk '{if($1=="'$cryptname'"){print $2}}' | sed 's/UUID=//')
local rootpart=$(blkid -U $parent_uuid)
;;
part)
local rootpart=$rootsource # i.e. /dev/mmcblk0p1
;;
esac
local rootdevice=$(lsblk -n -o PKNAME $rootpart | head -1) # i.e. mmcblk0
# due to the bug in util-linux 2.34 which fails to show device, let's use this failover:
[[ -z $rootdevice ]] && rootdevice=$(echo $rootpart | sed -e "s/^\/dev\///" | sed "s/p.*//")
local rootdevicepath="/dev/$rootdevice" # i.e. /dev/mmcblk0
# get count of partitions and their boundaries
local partitions=$(parted $rootdevicepath print -sm | tail -1 | awk -F ':' '{print $1}')
local partstart=$(parted $rootdevicepath unit s print -sm | tail -1 | cut -d: -f2 | sed 's/s//') # start of first partition
local partend=$(parted $rootdevicepath unit s print -sm | head -3 | tail -1 | cut -d: -f3 | sed 's/s//') # end of first partition
local startfrom=$(( $partend + 1 ))
[[ $partitions == 1 ]] && startfrom=$partstart
local capacity=$(( $(lsblk -n -b -d -o SIZE $rootdevicepath) / 1024 / 1024 / 1024 )) # GiB
# check whether a resizing rule is defined. We will take this value if it's not too low. In
# this case the value will be ignored and resizing to the whole card size happens.
if [[ -f /root/.rootfs_resize ]]; then
read RESIZE_VALUE </root/.rootfs_resize
ResizeLog="Resize rule $RESIZE_VALUE defined for root partition"
case $RESIZE_VALUE in
*%)
# percentage value, we try to use 16MiB to align partitions since this is
# the erase block size of more recent SD cards (512 byte sectors, so we use 32768
# as divider and substract 1)
local percentage=$(echo $RESIZE_VALUE | tr -c -d '[:digit:]')
local lastsector=$(( 32768 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * $percentage / 3276800))}") - 1 ))
[[ $lastsector -lt $partend ]] && unset lastsector
;;
*s)
# sector value, we use it directly
local lastsector=$(echo $RESIZE_VALUE | tr -c -d '[:digit:]')
[[ $lastsector -lt $partend ]] && unset lastsector
;;
esac
# if SD card is larger than 4GiB then create another partition behind first one(s)
if [[ $capacity -ge 5 ]]; then
local secondpartition=$(( 32768 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * 99 / 3276800))}") -1 ))
if [[ $secondpartition -lt $partend ]]; then
unset secondpartition
fi
fi
else
# check device capacity. If 4GiB or below do not use whole card but leave a 5% spare area
# to help older cards with wear leveling and garbage collection. In case this reduced card
# capacity is less than the actual image capacity this is a clear sign that someone wants
# to use Orange Pi on a card of inappropriate size so he gets what he deserves (at least he
# should know what he's doing)
if [[ $capacity -lt 5 ]]; then # 4 GiB or less
local lastsector=$(( 32768 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * 95 / 3276800))}") -1 ))
if [[ $lastsector -lt $partend ]]; then
unset lastsector
else
ResizeLog="4GiB or smaller media - leaving 5% spare area"
fi
elif [[ $capacity -lt 9 ]]; then # 8 GiB or less
# Leave 2 percent unpartitioned
local lastsector=$(( 32768 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * 98 / 3276800))}") -1 ))
if [[ $lastsector -lt $partend ]]; then
unset lastsector
else
ResizeLog="8GiB or smaller media - leaving 2% spare area"
fi
else
# Leave 1 percent unpartitioned
local lastsector=$(( 32768 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * 99 / 3276800))}") -1 ))
if [[ $lastsector -lt $partend ]]; then
unset lastsector
else
ResizeLog="Leaving 1% spare area"
fi
fi
fi
# Start resizing
echo -e "\n### [resize2fs] ${ResizeLog}. Start resizing partition $rootsource now:\n" >>${Log}
cat /proc/partitions >>${Log}
echo -e "\nExecuting fdisk, fsck and partprobe:" >>${Log}
local fdisk_version=$(fdisk --version | awk '{print $NF}' | grep -oE "^[[:digit:]]\.[[:digit:]]+")
if [[ $partitions == 1 ]] && awk "BEGIN{exit ! ($fdisk_version >= 2.27 )}"; then
# if dealing with fdisk from util-linux 2.27+ we need a workaround for just 1 partition
# though it does not break anything - just prevents an "unexpected command" to fdisk
# https://github.com/igorpecovnik/lib/issues/353#issuecomment-224728506
((echo d; echo n; echo p; echo ; echo $startfrom; echo $lastsector ; echo w;) | fdisk $rootdevicepath) >>${Log} 2>&1
else
((echo d; echo $partitions; echo n; echo p; echo ; echo $startfrom; echo $lastsector ; echo w;) | fdisk $rootdevicepath) >>${Log} 2>&1
fi
[[ -n $secondpartition ]] && \
((echo n; echo p; echo ; echo $(( $lastsector + 1 )); echo $secondpartition ; echo w;) | fdisk $rootdevicepath) >>${Log} 2>&1
local s=0
partprobe $rootdevicepath >>${Log} 2>&1 || s=$?
#
# Workaround for Kernel bug in 5.8.y and up. Ignore partprobe returning error and inticating that fs is not expended while it is
#
KERNELID=$(uname -r | awk -F'.' '{print ($1 * 100) + $2}')
[[ ${KERNELID} -gt 507 ]] && s=0
#
#
#
echo -e "New partition table:\n" >>${Log}
cat /proc/partitions >>${Log}
echo -e "\nNow trying to resize $1 filesystem on $rootsource to the limits:\n" >>${Log}
# if crypt-device, resize LUKS container first
if [[ $IS_CRYPTDEVICE ]]; then
do_resize_crypt $cryptname
fi
case $1 in
ext4)
resize2fs $rootsource >>${Log} 2>&1
# check whether reboot is necessary for resize2fs to take effect
local usedpercent=$(findmnt --target / -n -o USE% -b | sed 's/[^0-9]*//g') # images before resize have 70-75%
if [[ $s != 0 || $usedpercent -gt 70 ]]; then
touch /var/run/resize2fs-reboot
echo -e "\n### [resize2fs] Automated reboot needed to finish the resize procedure" >>${Log}
fi
;;
btrfs)
btrfs filesystem resize max / >> ${Log} 2>&1
;;
esac
if [[ ${BOARD} == orangepi6plus ]]; then
new_partuuid=$(sudo blkid ${rootsource} -s PARTUUID -o value)
if [[ ${rootdevice} == *sd* ]]; then
mount ${rootdevicepath}1 /mnt/
else
mount ${rootdevicepath}p1 /mnt/
fi
sed -i "s/root=PARTUUID=${old_partuuid}/root=PARTUUID=${new_partuuid}/g" /mnt/GRUB/GRUB.CFG
umount /mnt/
fi
}
do_resize_crypt()
{
echo -e "\n### [resize2fs] Start resizing LUKS container now\n" >> ${Log}
cryptsetup resize $1
}
do_expand_ext4()
{
echo -e "\n### [resize2fs] Start resizing ext4 partition $1 now\n" >> ${Log}
echo "Running 'resize2fs ${rootpart}' now..."
resize2fs ${rootpart} >> ${Log} 2>&1
}
do_expand_btrfs()
{
echo -e "\n### [resize2fs] Start resizing btrfs partition $1 now\n" >> ${Log}
btrfs filesystem resize max / >> ${Log} 2>&1
}
case "$1" in
start)
# skip resizing if rootfs is neither ext4 not btrfs or if explicitly disabled
if [[ -f /root/.no_rootfs_resize ]]; then
systemctl disable orangepi-resize-filesystem
exit 0
fi
# Logging header
CPU_ARCH=$(lscpu | awk '/Architecture/ {print $2}')
DISTRO_ARCH=$(dpkg --print-architecture)
KERNELID=$(uname -r)
echo "$(date) | ${BOARD_NAME} | ${VERSION} | ${DISTRO_ARCH} | ${CPU_ARCH} | ${KERNELID}" >>${Log}
chmod 644 ${Log}
rootfstype=$(findmnt -n -o FSTYPE /)
rootpart=$(findmnt -n -o SOURCE /) # i.e. /dev/mmcblk0p1
case ${rootfstype} in
ext4)
# first stage - resize the rootfs partition
[[ ! -f /var/lib/orangepi/resize_second_stage ]] && do_expand_partition ${rootfstype}
# second stage - resize the filesystem
[[ ! -f /var/run/resize2fs-reboot ]] && do_expand_ext4 ${rootpart}
;;
btrfs)
do_expand_partition ${rootfstype} && systemctl disable orangepi-resize-filesystem
;;
esac
# disable itself
[[ ! -f /var/run/resize2fs-reboot ]] && systemctl disable orangepi-resize-filesystem
exit 0
;;
*)
echo "Usage: $0 start"
exit 0
;;
esac

View File

@@ -0,0 +1,33 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
#
# truncate, save and clean logs if they get over 75% of the /var/log size
# working only when orangepi-ramlog is enabled
treshold=75 # %
JOURNAL_SIZE=5M # size to shrink systemd-journal
[ -f /etc/default/orangepi-ramlog ] && . /etc/default/orangepi-ramlog
[ "$ENABLED" != true ] && exit 0
logusage=$(df /var/log/ --output=pcent | tail -1 |cut -d "%" -f 1)
if [ $logusage -ge $treshold ]; then
# write to SD
/usr/lib/orangepi/orangepi-ramlog write >/dev/null 2>&1
# rotate logs on "disk"
/usr/sbin/logrotate --force /etc/logrotate.conf
# truncate
/usr/bin/find /var/log -name '*.log' -or -name '*.xz' -or -name 'lastlog' -or -name 'messages' -or -name 'debug' -or -name 'syslog' | xargs -r truncate --size 0
/usr/bin/find /var/log -name 'btmp' -or -name 'wtmp' -or -name 'faillog' -or -name 'firewalld' | xargs -r truncate --size 0
/usr/bin/find /var/log -name 'mail.err' -or -name 'mail.info' -or -name 'mail.warning' | xargs -r truncate --size 0
# remove
/usr/bin/find /var/log -name '*.[0-9]' -or -name '*.gz' | xargs -r rm -f
# vacuum systemd-journald
[ -d /var/log/journal ] && journalctl --quiet --vacuum-size=${JOURNAL_SIZE}
fi

View File

@@ -0,0 +1,157 @@
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# 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.
# Functions:
#
# activate_zram
# activate_zram_swap
# activate_ramlog_partition
# activate_compressed_tmp
# Read in basic OS image information
. /etc/orangepi-release
# and script configuration
. /usr/lib/orangepi/orangepi-common
# It's possible to override SWAP, ZRAM_PERCENTAGE, MEM_LIMIT_PERCENTAGE, ZRAM_MAX_DEVICES,
# SWAP_ALGORITHM, RAMLOG_ALGORITHM, TMP_ALGORITHM and TMP_SIZE here:
ENABLED=false
[ -f /etc/default/orangepi-zram-config ] && . /etc/default/orangepi-zram-config
# Exit if not Enabled
[[ "$ENABLED" != "true" ]] && exit 0
# Do not interfere with already present zram-config package
dpkg -l | grep -q 'zram-config' && exit 0
activate_zram() {
# Load zram module with n instances for swap: one per CPU core, $ZRAM_MAX_DEVICES
# defines the maximum, on modern kernels we overwrite this with 1 and rely on
# max_comp_streams being set to count of CPU cores or $ZRAM_MAX_DEVICES
uname -r | grep -q '^3.' && zram_max_devs=${ZRAM_MAX_DEVICES:=4} || zram_max_devs=1
cpu_cores=$(grep -c '^processor' /proc/cpuinfo | sed 's/^0$/1/')
[[ ${cpu_cores} -gt ${zram_max_devs} ]] && zram_devices=${zram_max_devs} || zram_devices=${cpu_cores}
module_args="$(modinfo zram | awk -F" " '/num_devices/ {print $2}' | cut -f1 -d:)"
[[ -n ${module_args} ]] && modprobe zram ${module_args}=$(( zram_devices + 2 )) || return
swap_algo=${SWAP_ALGORITHM:=lzo}
# Expose 50% of real memory as swap space by default
zram_percent=${ZRAM_PERCENTAGE:=50}
mem_info=$(LC_ALL=C free -w 2>/dev/null | grep "^Mem" || LC_ALL=C free | grep "^Mem")
mem_info=$(echo $mem_info | awk '{print $2}')
memory_total=$(( mem_info * 1024 ))
mem_per_zram_device=$(( memory_total * zram_percent / zram_devices / 100 ))
# Limit memory available to zram to 50% by default
mem_limit_percent=${MEM_LIMIT_PERCENTAGE:=50}
mem_limit_per_zram_device=$(( memory_total * mem_limit_percent / zram_devices / 100 ))
}
activate_zram_swap() {
# Return is SWAP is disabled (enabled by default)
[[ -n "$SWAP" && "$SWAP" != "true" ]] && return;
# Disable zswap if zram should be used. To make use of zswap instead a
# swap file or partition on *capable* storage needs to be chosen and
# defined as swap and also in /etc/default/orangepi-zram-config SWAP=false
# needs to be set.
echo 0 >/sys/module/zswap/parameters/enabled 2>/dev/null
# Limit Journal size to 20Mb
sed -i "s/.*SystemMaxUse=$/SystemMaxUse=20M/" /etc/systemd/journald.conf
for (( i=1; i<=zram_devices; i++ )); do
swap_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${swap_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${swap_device}" >> ${Log} && exit 1;
if [ -f /sys/block/${swap_device}/comp_algorithm ]; then
# set compression algorithm, if defined as lzo choose lzo-rle if available
# https://www.phoronix.com/scan.php?page=news_item&px=ZRAM-Linux-5.1-Better-Perform
grep -q 'lzo-rle' /sys/block/${swap_device}/comp_algorithm && \
[[ "X${swap_algo}" = "Xlzo" ]] && swap_algo="lzo-rle"
echo ${swap_algo} >/sys/block/${swap_device}/comp_algorithm 2>/dev/null
fi
if [ "X${ZRAM_BACKING_DEV}" != "X" ]; then
echo ${ZRAM_BACKING_DEV} >/sys/block/${swap_device}/backing_dev
fi
echo -n ${ZRAM_MAX_DEVICES:=4} > /sys/block/${swap_device}/max_comp_streams
echo -n ${mem_per_zram_device} > /sys/block/${swap_device}/disksize
echo -n ${mem_limit_per_zram_device} > /sys/block/${swap_device}/mem_limit
mkswap /dev/${swap_device}
swapon -p 5 /dev/${swap_device}
done
# Swapping to HDDs is stupid so switch to settings made for flash memory and zram/zswap
echo 0 > /proc/sys/vm/page-cluster
printf "\n### Activated %s %s zram swap devices with %dMB each.\n" "${zram_devices}" "${swap_algo}" "$((mem_per_zram_device / 1048576))" >> ${Log}
} # activate_zram_swap
activate_ramlog_partition() {
# /dev/zram0 will be used as a compressed /var/log partition in RAM if
# ENABLED=true in /etc/default/orangepi-ramlog is set
ENABLED=$(awk -F"=" '/^ENABLED/ {print $2}' /etc/default/orangepi-ramlog)
[[ "$ENABLED" != "true" ]] && return
log_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${log_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${log_device}" >> ${Log} && exit 1;
# read size also from /etc/default/orangepi-ramlog
ramlogsize=$(awk -F"=" '/^SIZE/ {print $2}' /etc/default/orangepi-ramlog)
disksize=$(sed -e 's/M$/*1048576/' -e 's/K$/*1024/' <<<${ramlogsize:=50M} | bc)
# choose RAMLOG_ALGORITHM if defined in /etc/default/orangepi-zram-config
# otherwise try to choose most efficient compression scheme available.
# See https://patchwork.kernel.org/patch/9918897/
if [ "X${RAMLOG_ALGORITHM}" = "X" ]; then
for algo in lz4 lz4hc quicklz zlib brotli zstd ; do
echo ${algo} >/sys/block/${log_device}/comp_algorithm 2>/dev/null
done
else
echo ${RAMLOG_ALGORITHM} >/sys/block/${log_device}/comp_algorithm 2>/dev/null
fi
echo -n ${disksize} > /sys/block/${log_device}/disksize
# if it fails, select $swap_algo. Workaround for some older kernels
if [[ $? == 1 ]]; then
echo ${swap_algo} > /sys/block/${log_device}/comp_algorithm 2>/dev/null
echo -n ${disksize} > /sys/block/${log_device}/disksize
fi
mkfs.ext4 -O ^has_journal -s 1024 -L log2ram /dev/${log_device}
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/${log_device}/comp_algorithm)
printf "### Activated Orange Pi ramlog partition with %s compression\n" "${algo}" >> ${Log}
} # activate_ramlog_partition
activate_compressed_tmp() {
# create /tmp not as tmpfs but zram compressed if no fstab entry exists
grep -q '^tmpfs /tmp' /etc/mtab && return
tmp_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${tmp_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${tmp_device}" >> ${Log} && exit 1;
if [[ -f /sys/block/${tmp_device}/comp_algorithm ]]; then
if [ "X${TMP_ALGORITHM}" = "X" ]; then
echo ${swap_algo} >/sys/block/${tmp_device}/comp_algorithm 2>/dev/null
else
echo ${TMP_ALGORITHM} >/sys/block/${tmp_device}/comp_algorithm 2>/dev/null
fi
fi
[[ -z ${TMP_SIZE} ]] && echo -n $(( memory_total / 2 )) > /sys/block/${tmp_device}/disksize || echo -n ${TMP_SIZE} > /sys/block/${tmp_device}/disksize
mkfs.ext4 -O ^has_journal -s 1024 -L tmp /dev/${tmp_device}
mount -o nosuid,discard /dev/${tmp_device} /tmp
chmod 1777 /tmp
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/${tmp_device}/comp_algorithm)
printf "\n### Activated %s compressed /tmp\n" "${algo}" >> ${Log}
} # activate_compressed_tmp
case $1 in
*start*)
activate_zram
activate_zram_swap
activate_ramlog_partition
activate_compressed_tmp
;;
esac