mirror of
https://github.com/DrHo1y/orangepi-build.git
synced 2026-11-12 19:13:48 +07:00
First Commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
[connection]
|
||||
wifi.mac-address-randomization=1
|
||||
|
||||
[device]
|
||||
wifi.scan-rand-mac-address=no
|
||||
@@ -0,0 +1,2 @@
|
||||
[connection]
|
||||
wifi.powersave = 2
|
||||
23
external/packages/bsp/common/etc/NetworkManager/dispatcher.d/30-offload
vendored
Normal file
23
external/packages/bsp/common/etc/NetworkManager/dispatcher.d/30-offload
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# With offloading enabled, Samba becomes completely useless - transfers to a Windows PC freezes randomly
|
||||
# Disabling offloading should solve this - all RK3399
|
||||
|
||||
IFACE=$1
|
||||
EVENT=$2
|
||||
|
||||
if [[ "$EVENT" != "up" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if linux-version compare $(uname -r | cut -d '.' -f1,2) gt 4.4; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
ETHTOOL=/sbin/ethtool
|
||||
|
||||
[ -f $ETHTOOL ] || exit 2
|
||||
[ -d /sys/devices/platform/fe300000.ethernet/net/$IFACE ] || exit 3
|
||||
|
||||
$ETHTOOL -K $IFACE rx off tx off
|
||||
exit 0
|
||||
10
external/packages/bsp/common/etc/X11/xorg.conf.d/01-orangepi-defaults.conf
vendored
Normal file
10
external/packages/bsp/common/etc/X11/xorg.conf.d/01-orangepi-defaults.conf
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
Section "Monitor"
|
||||
Identifier "Monitor0"
|
||||
Option "DPMS" "false"
|
||||
EndSection
|
||||
Section "ServerFlags"
|
||||
Option "BlankTime" "0"
|
||||
Option "StandbyTime" "0"
|
||||
Option "SuspendTime" "0"
|
||||
Option "OffTime" "0"
|
||||
EndSection
|
||||
2
external/packages/bsp/common/etc/apt/apt.conf.d/02-orangepi-compress-indexes
vendored
Normal file
2
external/packages/bsp/common/etc/apt/apt.conf.d/02-orangepi-compress-indexes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
Acquire::GzipIndexes "true";
|
||||
Acquire::CompressionTypes::Order:: "gz";
|
||||
22
external/packages/bsp/common/etc/apt/apt.conf.d/02-orangepi-periodic
vendored
Normal file
22
external/packages/bsp/common/etc/apt/apt.conf.d/02-orangepi-periodic
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Enable the update/upgrade script (0=disable)
|
||||
APT::Periodic::Enable "0";
|
||||
|
||||
// Do "apt-get update" automatically every n-days (0=disable)
|
||||
APT::Periodic::Update-Package-Lists "21";
|
||||
|
||||
// Do "apt-get upgrade --download-only" every n-days (0=disable)
|
||||
APT::Periodic::Download-Upgradeable-Packages "0";
|
||||
|
||||
// Run the "unattended-upgrade" security upgrade script
|
||||
// every n-days (0=disabled)
|
||||
// Requires the package "unattended-upgrades" and will write
|
||||
// a log in /var/log/unattended-upgrades
|
||||
APT::Periodic::Unattended-Upgrade "7";
|
||||
|
||||
// Do "apt-get autoclean" every n-days (0=disable)
|
||||
APT::Periodic::AutocleanInterval "120";
|
||||
|
||||
// Define basic patterns
|
||||
Unattended-Upgrade::Origins-Pattern {
|
||||
"origin=${distro_id},codename=${distro_codename}";
|
||||
};
|
||||
2
external/packages/bsp/common/etc/apt/apt.conf.d/71-orangepi-no-recommends
vendored
Normal file
2
external/packages/bsp/common/etc/apt/apt.conf.d/71-orangepi-no-recommends
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
APT::Install-Recommends "0";
|
||||
APT::Install-Suggests "0";
|
||||
1
external/packages/bsp/common/etc/apt/apt.conf.d/81-orangepi-no-languages
vendored
Normal file
1
external/packages/bsp/common/etc/apt/apt.conf.d/81-orangepi-no-languages
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Acquire::Languages "none";
|
||||
4
external/packages/bsp/common/etc/cron.d/orangepi-truncate-logs
vendored
Normal file
4
external/packages/bsp/common/etc/cron.d/orangepi-truncate-logs
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
|
||||
*/15 * * * * root /usr/lib/orangepi/orangepi-truncate-logs
|
||||
|
||||
2
external/packages/bsp/common/etc/cron.d/orangepi-updates
vendored
Normal file
2
external/packages/bsp/common/etc/cron.d/orangepi-updates
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
@reboot root /usr/lib/orangepi/orangepi-apt-updates
|
||||
@daily root /usr/lib/orangepi/orangepi-apt-updates
|
||||
2
external/packages/bsp/common/etc/cron.daily/orangepi-ram-logging
vendored
Normal file
2
external/packages/bsp/common/etc/cron.daily/orangepi-ram-logging
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
/usr/lib/orangepi/orangepi-ramlog write >/dev/null 2>&1
|
||||
6
external/packages/bsp/common/etc/default/orangepi-motd.dpkg-dist
vendored
Normal file
6
external/packages/bsp/common/etc/default/orangepi-motd.dpkg-dist
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# add space-separated list of MOTD script names (without number) to exclude them from MOTD
|
||||
# Example:
|
||||
# MOTD_DISABLE="header tips updates"
|
||||
|
||||
MOTD_DISABLE=""
|
||||
ONE_WIRE="" # yes = show 1-wire temperature sensor if attached
|
||||
12
external/packages/bsp/common/etc/default/orangepi-ramlog.dpkg-dist
vendored
Normal file
12
external/packages/bsp/common/etc/default/orangepi-ramlog.dpkg-dist
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# configuration values for the orangepi-ram-logging service
|
||||
#
|
||||
# enable the orangepi-ram-logging service?
|
||||
ENABLED=true
|
||||
#
|
||||
# size of the tmpfs mount -- please keep in mind to adjust /etc/default/orangepi-zram-config too when increasing
|
||||
SIZE=50M
|
||||
#
|
||||
# use rsync instead of cp -r
|
||||
# requires rsync installed, may provide better performance
|
||||
# due to copying only new and changed files
|
||||
USE_RSYNC=true
|
||||
34
external/packages/bsp/common/etc/default/orangepi-zram-config.dpkg-dist
vendored
Normal file
34
external/packages/bsp/common/etc/default/orangepi-zram-config.dpkg-dist
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# configuration values for the orangepi-zram-config service
|
||||
#
|
||||
# enable the orangepi-zram-config service?
|
||||
ENABLED=true
|
||||
|
||||
# percentage of zram used as swap compared to physically available DRAM.
|
||||
# Huge overcommitment (300) is possible and sometimes desirable. See
|
||||
# https://forum.armbian.com/topic/5565-zram-vs-swap/?do=findComment&comment=61082
|
||||
# and don't forget to adjust $MEM_LIMIT_PERCENTAGE below too.
|
||||
# ZRAM_PERCENTAGE=50
|
||||
|
||||
# percentage of DRAM available to zram. If this amount is exceeded the zram
|
||||
# devices used for swap simply behave as if the device is full. You need to
|
||||
# adjust/increase this value only if you want to work with massive memory
|
||||
# overcommitment (ZRAM_PERCENTAGE exceeding 150 for example)
|
||||
# MEM_LIMIT_PERCENTAGE=50
|
||||
|
||||
# create how many zram devices max for swap
|
||||
# ZRAM_MAX_DEVICES=4
|
||||
|
||||
# Which algorithm for zram based swapping. Seems lzo is best choice on ARM:
|
||||
# https://forum.armbian.com/topic/8161-swap-on-sbc/?do=findComment&comment=61668
|
||||
# SWAP_ALGORITHM=lzo
|
||||
|
||||
# Which algorithm to choose for zram based ramlog partition
|
||||
# RAMLOG_ALGORITHM=zstd
|
||||
|
||||
# Which algorithm to choose for zram based /tmp
|
||||
# TMP_ALGORITHM=zstd
|
||||
|
||||
# If defined a separate partition will be used as zram backing device. Be CAREFUL
|
||||
# which partition you assign and read starting from CONFIG_ZRAM_WRITEBACK in
|
||||
# https://www.kernel.org/doc/Documentation/blockdev/zram.txt
|
||||
# ZRAM_BACKING_DEV=/dev/nvme0n2
|
||||
11
external/packages/bsp/common/etc/initramfs/post-update.d/99-uboot
vendored
Executable file
11
external/packages/bsp/common/etc/initramfs/post-update.d/99-uboot
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
. /etc/orangepi-release
|
||||
|
||||
echo "update-initramfs: Converting to u-boot format" >&2
|
||||
tempname="/boot/uInitrd-$1"
|
||||
mkimage -A $INITRD_ARCH -O linux -T ramdisk -C gzip -n uInitrd -d $2 $tempname > /dev/null
|
||||
|
||||
ln -sf $(basename $tempname) /boot/uInitrd > /dev/null 2>&1 || mv $tempname /boot/uInitrd
|
||||
|
||||
exit 0
|
||||
1
external/packages/bsp/common/etc/modprobe.d/r8723bs.conf
vendored
Normal file
1
external/packages/bsp/common/etc/modprobe.d/r8723bs.conf
vendored
Normal file
@@ -0,0 +1 @@
|
||||
options r8723bs rtw_power_mgnt=0 rtw_enusbss=0
|
||||
4
external/packages/bsp/common/etc/network/interfaces.default
vendored
Normal file
4
external/packages/bsp/common/etc/network/interfaces.default
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
source /etc/network/interfaces.d/*
|
||||
# Network is managed by Network manager
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
31
external/packages/bsp/common/etc/profile.d/orangepi-activate-profile-sync-daemon.sh
vendored
Normal file
31
external/packages/bsp/common/etc/profile.d/orangepi-activate-profile-sync-daemon.sh
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) Authors: http://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.
|
||||
|
||||
# acticate profile sync daemon
|
||||
|
||||
if [ -f "${HOME}/.activate_psd" ]; then
|
||||
rm -f ${HOME}/.activate_psd
|
||||
/usr/bin/psd >/dev/null 2>&1
|
||||
config_file="${HOME}/.config/psd/psd.conf"
|
||||
if [ -f "${config_file}" ]; then
|
||||
# test for overlayfs
|
||||
# TODO: don't enable on btrfs
|
||||
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
|
||||
fi
|
||||
15
external/packages/bsp/common/etc/profile.d/orangepi-check-first-login-reboot.sh
vendored
Normal file
15
external/packages/bsp/common/etc/profile.d/orangepi-check-first-login-reboot.sh
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) Authors: http://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.
|
||||
|
||||
# only do this for interactive shells
|
||||
if [ "$-" != "${-#*i}" ]; then
|
||||
printf "\n"
|
||||
if [ -f "/var/run/.reboot_required" ]; then
|
||||
printf "[\e[0;91m Kernel was updated, please reboot\x1B[0m ]\n\n"
|
||||
fi
|
||||
fi
|
||||
274
external/packages/bsp/common/etc/profile.d/orangepi-check-first-login.sh
vendored
Normal file
274
external/packages/bsp/common/etc/profile.d/orangepi-check-first-login.sh
vendored
Normal file
@@ -0,0 +1,274 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) Authors: http://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
|
||||
trap - INT
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
function read_password()
|
||||
{
|
||||
unset password
|
||||
prompt="$1 password: "
|
||||
while IFS= read -p "$prompt" -r -s -n 1 char
|
||||
do
|
||||
if [[ $char == $'\0' ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
prompt='*'
|
||||
password+="$char"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
set_timezone_and_locales()
|
||||
{
|
||||
|
||||
# Grab this machine's public IP address
|
||||
PUBLIC_IP=`curl --max-time 5 -s https://ipinfo.io/ip`
|
||||
if [ $? -eq 0 ]; then
|
||||
|
||||
# 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)
|
||||
LOCALES=$(grep territory /usr/share/i18n/locales/* | grep "$STATE" | cut -d ":" -f 1 | cut -d "/" -f 6 | xargs -I{} grep {} /usr/share/i18n/SUPPORTED | grep "\.UTF-8" | cut -d " " -f 1)
|
||||
CCODE=$(echo ${RES} | cut -d"," -f3 | awk '{print tolower($0)}' | xargs)
|
||||
options=(`echo ${LOCALES}`);
|
||||
|
||||
# reconfigure tzdata
|
||||
timedatectl set-timezone "${TZDATA}"
|
||||
dpkg-reconfigure --frontend=noninteractive tzdata > /dev/null 2>&1
|
||||
|
||||
echo -e "Detected timezone: \x1B[92m$(LC_ALL=C timedatectl | grep "Time zone" | cut -d":" -f2 | xargs)\x1B[0m"
|
||||
echo -e "Do you want to set locales and console keyboard automatically from your location [Y/n]"
|
||||
read -sn1 SetLocales
|
||||
if [ "$SetLocales" != "n" ] && [ "$SetLocales" != "N" ]; then
|
||||
|
||||
# when having more locales, prompt for choosing one
|
||||
if [[ "${#options[@]}" -gt 1 ]]; then
|
||||
|
||||
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
|
||||
|
||||
# generate locales
|
||||
sed -i 's/# '"${LOCALES}"'/'"${LOCALES}"'/' /etc/locale.gen
|
||||
echo -e "Generating locales: \x1B[92m${LOCALES}\x1B[0m"
|
||||
locale-gen $LOCALES > /dev/null 2>&1
|
||||
update-locale LANG=$LOCALES LANGUAGE=$LOCALES LC=$LOCALES LC_MESSAGES=$LOCALES
|
||||
|
||||
# setting up keyboard
|
||||
echo -e "Console keyboard layout: \x1B[92m$CCODE\x1B[0m"
|
||||
sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\"$CCODE\"/" /etc/default/keyboard
|
||||
setupcon -k --force
|
||||
else
|
||||
|
||||
echo -e "You can use \x1B[92morangepi-config\x1B[0m to set locales and console keyboard."
|
||||
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
while [ -f "/root/.not_logged_in_yet" ]; do
|
||||
echo -e "\nPlease provide a username (eg. your forename): \c"
|
||||
read -e username
|
||||
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"
|
||||
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 -e "\nPlease provide your real name (eg. John Doe): \c"
|
||||
read -e RealName
|
||||
adduser --quiet --disabled-password --shell /bin/bash --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
|
||||
|
||||
# set up profile sync daemon on desktop systems
|
||||
which 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."
|
||||
fi
|
||||
elif [[ -n $password ]]; then
|
||||
echo -e "Rejected - \e[0;31mpasswords do not match.\x1B[0m Try again."
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
if [ -f /root/.not_logged_in_yet ] && [ -n "$BASH_VERSION" ] && [ "$-" != "${-#*i}" ]; 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 lightdm
|
||||
#desktop_lightdm=$(dpkg-query -W -f='${db:Status-Abbrev}\n' lightdm 2>/dev/null)
|
||||
|
||||
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
|
||||
# set_timezone_and_locales
|
||||
# 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
|
||||
|
||||
#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 "Desktop environment will not be enabled if you abort the new user creation"
|
||||
# add_user
|
||||
#done
|
||||
#trap - INT TERM EXIT
|
||||
|
||||
rm -f /root/.not_logged_in_yet
|
||||
|
||||
# check whether desktop environment has to be considered
|
||||
#if [ -n "$desktop_lightdm" ]; 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
|
||||
#
|
||||
# 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
|
||||
# (sleep 20; rm /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.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
|
||||
fi
|
||||
4
external/packages/bsp/common/etc/profile.d/orangepi-lang.sh
vendored
Normal file
4
external/packages/bsp/common/etc/profile.d/orangepi-lang.sh
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# This should fix
|
||||
# perl: warning: Setting locale failed.
|
||||
|
||||
export LC_ALL=$LANG
|
||||
14
external/packages/bsp/common/etc/profile.d/orangepi-ssh-title.sh
vendored
Normal file
14
external/packages/bsp/common/etc/profile.d/orangepi-ssh-title.sh
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) Authors: http://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.
|
||||
|
||||
if [ -n "$PS1" ] && ( [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] ); then
|
||||
tput tsl > /dev/null
|
||||
if [ "$?" -eq 0 ]; then
|
||||
echo `tput tsl` `whoami`@`hostname` `tput fsl`
|
||||
fi
|
||||
fi
|
||||
40
external/packages/bsp/common/etc/skel/.config/htop/htoprc
vendored
Normal file
40
external/packages/bsp/common/etc/skel/.config/htop/htoprc
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# Beware! This file is rewritten by htop when settings are changed in the interface.
|
||||
# The parser is also very primitive, and not human-friendly.
|
||||
fields=0 48 17 18 38 39 40 2 46 47 49 1
|
||||
sort_key=1
|
||||
sort_direction=1
|
||||
hide_threads=0
|
||||
hide_kernel_threads=1
|
||||
hide_userland_threads=0
|
||||
shadow_other_users=0
|
||||
show_thread_names=0
|
||||
show_program_path=1
|
||||
highlight_base_name=0
|
||||
highlight_megabytes=1
|
||||
highlight_threads=1
|
||||
tree_view=0
|
||||
header_margin=1
|
||||
detailed_cpu_time=0
|
||||
cpu_count_from_zero=0
|
||||
update_process_names=0
|
||||
account_guest_in_cpu_meter=0
|
||||
color_scheme=0
|
||||
delay=15
|
||||
left_meters=AllCPUs Memory Swap CpuTemp
|
||||
left_meter_modes=1 1 1 2
|
||||
right_meters=OrangePiversion Hostname Tasks LoadAverage Uptime CpuFreq Eth0 Eth0stat
|
||||
right_meter_modes=2 2 2 2 2 2 2 2
|
||||
# SBC hardware and Kernel specific path.
|
||||
# Editable manually.
|
||||
BoardName=
|
||||
CpuFreq_handler=
|
||||
CpuTemp_handler=
|
||||
CpuVCore_l_handler=
|
||||
CpuVCore_b_handler=
|
||||
GpuVCore_handler=
|
||||
GpuTemp_handler=
|
||||
# Wlan / Eth alias
|
||||
eth0_alias=
|
||||
eth1_alias=
|
||||
wlan0_alias=
|
||||
wlan1_alias=
|
||||
28
external/packages/bsp/common/etc/systemd/system/logrotate.service
vendored
Normal file
28
external/packages/bsp/common/etc/systemd/system/logrotate.service
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
[Unit]
|
||||
Description=Rotate log files
|
||||
Documentation=man:logrotate(8) man:logrotate.conf(5)
|
||||
ConditionACPower=true
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStartPre=/usr/lib/orangepi/orangepi-ramlog write
|
||||
ExecStart=/usr/sbin/logrotate /etc/logrotate.conf
|
||||
ExecStartPost=/usr/lib/orangepi/orangepi-ramlog postrotate
|
||||
|
||||
# performance options
|
||||
Nice=19
|
||||
IOSchedulingClass=best-effort
|
||||
IOSchedulingPriority=7
|
||||
|
||||
# hardening options
|
||||
# details: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
|
||||
# no ProtectHome for userdir logs
|
||||
# no PrivateNetwork for mail deliviery
|
||||
# no ProtectKernelTunables for working SELinux with systemd older than 235
|
||||
# no MemoryDenyWriteExecute for gzip on i686
|
||||
PrivateDevices=true
|
||||
PrivateTmp=true
|
||||
ProtectControlGroups=true
|
||||
ProtectKernelModules=true
|
||||
ProtectSystem=full
|
||||
RestrictRealtime=true
|
||||
1
external/packages/bsp/common/etc/udev/rules.d/10-wifi-disable-powermanagement.rules
vendored
Normal file
1
external/packages/bsp/common/etc/udev/rules.d/10-wifi-disable-powermanagement.rules
vendored
Normal file
@@ -0,0 +1 @@
|
||||
KERNEL=="wlan*", ACTION=="add", RUN+="/sbin/iwconfig wlan0 power off"
|
||||
26
external/packages/bsp/common/etc/update-motd.d/10-orangepi-header
vendored
Executable file
26
external/packages/bsp/common/etc/update-motd.d/10-orangepi-header
vendored
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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.
|
||||
|
||||
# DO NOT EDIT THIS FILE but add config options to /etc/default/orangepi-motd
|
||||
# any changes will be lost on board support package update
|
||||
|
||||
THIS_SCRIPT="header"
|
||||
MOTD_DISABLE=""
|
||||
|
||||
[[ -f /etc/default/orangepi-motd ]] && . /etc/default/orangepi-motd
|
||||
|
||||
for f in $MOTD_DISABLE; do
|
||||
[[ $f == $THIS_SCRIPT ]] && exit 0
|
||||
done
|
||||
|
||||
. /etc/os-release
|
||||
. /etc/orangepi-release
|
||||
|
||||
KERNELID=$(uname -r)
|
||||
TERM=linux toilet -f standard -F metal $(echo $BOARD_NAME | sed 's/Orange Pi/OPi/')
|
||||
echo -e "Welcome to \e[0;91mOrange Pi \x1B[0m$(if [[ $ID == debian ]]; then echo ${PRETTY_NAME##*\(} | sed -e 's/^.*Linux //' | sed "s/\/.*//" | sed 's|)||'; else echo -n ${VERSION_CODENAME^};fi) with \e[0;91mLinux $KERNELID\x1B[0m\n"
|
||||
207
external/packages/bsp/common/etc/update-motd.d/30-orangepi-sysinfo
vendored
Executable file
207
external/packages/bsp/common/etc/update-motd.d/30-orangepi-sysinfo
vendored
Executable file
@@ -0,0 +1,207 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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.
|
||||
#
|
||||
|
||||
# DO NOT EDIT THIS FILE but add config options to /etc/default/orangepi-motd
|
||||
# generate system information
|
||||
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
THIS_SCRIPT="sysinfo"
|
||||
MOTD_DISABLE=""
|
||||
STORAGE=/dev/sda1
|
||||
SHOW_IP_PATTERN="^bond.*|^[ewr].*|^br.*|^lt.*|^umts.*|^lan.*"
|
||||
|
||||
CPU_TEMP_LIMIT=45
|
||||
AMB_TEMP_LIMIT=40
|
||||
|
||||
[[ -f /etc/default/orangepi-motd ]] && . /etc/default/orangepi-motd
|
||||
|
||||
for f in $MOTD_DISABLE; do
|
||||
[[ $f == $THIS_SCRIPT ]] && exit 0
|
||||
done
|
||||
|
||||
# don't edit below here
|
||||
|
||||
function display() {
|
||||
# $1=name $2=value $3=red_limit $4=minimal_show_limit $5=unit $6=after $7=acs/desc{
|
||||
# battery red color is opposite, lower number
|
||||
if [[ "$1" == "Battery" ]]; then local great="<"; else local great=">"; fi
|
||||
if [[ -n "$2" && "$2" > "0" && (( "${2%.*}" -ge "$4" )) ]]; then
|
||||
printf "%-14s%s" "$1:"
|
||||
if awk "BEGIN{exit ! ($2 $great $3)}"; then echo -ne "\e[0;91m $2"; else echo -ne "\e[0;92m $2"; fi
|
||||
printf "%-1s%s\x1B[0m" "$5"
|
||||
printf "%-11s%s\t" "$6"
|
||||
return 1
|
||||
fi
|
||||
} # display
|
||||
|
||||
function getboardtemp() {
|
||||
if [ -f /etc/orangepimonitor/datasources/soctemp ]; then
|
||||
read raw_temp </etc/orangepimonitor/datasources/soctemp 2>/dev/null
|
||||
if [ ! -z $(echo "$raw_temp" | grep -o "^[1-9][0-9]*\.\?[0-9]*$") ] && (( $(echo "${raw_temp} < 200" |bc -l) )); then
|
||||
# Allwinner legacy kernels output degree C
|
||||
board_temp=${raw_temp}
|
||||
else
|
||||
board_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp})
|
||||
fi
|
||||
elif [ -f /etc/orangepimonitor/datasources/pmictemp ]; then
|
||||
# fallback to PMIC temperature
|
||||
board_temp=$(awk '{printf("%d",$1/1000)}' </etc/orangepimonitor/datasources/pmictemp)
|
||||
fi
|
||||
} # getboardtemp
|
||||
|
||||
function batteryinfo() {
|
||||
# Battery info for Allwinner
|
||||
mainline_dir="/sys/power/axp_pmu"
|
||||
legacy_dir="/sys/class/power_supply"
|
||||
if [[ -e "$mainline_dir" ]]; then
|
||||
read status_battery_connected < $mainline_dir/battery/connected 2>/dev/null
|
||||
if [[ "$status_battery_connected" == "1" ]]; then
|
||||
read status_battery_charging < $mainline_dir/charger/charging
|
||||
read status_ac_connect < $mainline_dir/ac/connected
|
||||
read battery_percent< $mainline_dir/battery/capacity
|
||||
# dispay charging / percentage
|
||||
if [[ "$status_ac_connect" == "1" && "$battery_percent" -lt "100" ]]; then
|
||||
status_battery_text=" charging"
|
||||
elif [[ "$status_ac_connect" == "1" && "$battery_percent" -eq "100" ]]; then
|
||||
status_battery_text=" charged"
|
||||
else
|
||||
status_battery_text=" discharging"
|
||||
fi
|
||||
fi
|
||||
elif [[ -e "$legacy_dir/axp813-ac" ]]; then
|
||||
read status_battery_connected < $legacy_dir/axp20x-battery/present
|
||||
if [[ "$status_battery_connected" == "1" ]]; then
|
||||
status_battery_text=" "$(awk '{print tolower($0)}' < $legacy_dir/axp20x-battery/status)
|
||||
read status_ac_connect < $legacy_dir/axp813-ac/present
|
||||
read battery_percent< $legacy_dir/axp20x-battery/capacity
|
||||
fi
|
||||
elif [[ -e "$legacy_dir/battery" ]]; then
|
||||
if [[ (("$(cat $legacy_dir/battery/voltage_now)" -gt "5" )) ]]; then
|
||||
status_battery_text=" "$(awk '{print tolower($0)}' < $legacy_dir/battery/status)
|
||||
read battery_percent <$legacy_dir/battery/capacity
|
||||
fi
|
||||
fi
|
||||
} # batteryinfo
|
||||
|
||||
function ambienttemp() {
|
||||
# define where w1 usually shows up
|
||||
W1_DIR="/sys/devices/w1_bus_master1/"
|
||||
if [ -f /etc/orangepimonitor/datasources/ambienttemp ]; then
|
||||
read raw_temp </etc/orangepimonitor/datasources/ambienttemp 2>/dev/null
|
||||
amb_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp})
|
||||
echo $amb_temp
|
||||
elif [[ -d $W1_DIR && $ONE_WIRE == yes ]]; then
|
||||
device=$(ls -1 $W1_DIR | grep -Eo '^[0-9]{1,4}' | head -1)
|
||||
if [[ -n $device ]]; then
|
||||
if [[ -d ${W1_DIR}${device}/hwmon/hwmon0 ]]; then hwmon=0; else hwmon=1; fi
|
||||
read raw_temp < ${W1_DIR}${device}/hwmon/hwmon${hwmon}/temp1_input 2>/dev/null
|
||||
amb_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp})
|
||||
echo $amb_temp
|
||||
fi
|
||||
else
|
||||
# read ambient temperature from USB device if available
|
||||
if [[ ! -f /usr/bin/temper ]]; then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
amb_temp=$(temper -c 2>/dev/null)
|
||||
case ${amb_temp} in
|
||||
*"find the USB device"*)
|
||||
echo ""
|
||||
;;
|
||||
*)
|
||||
amb_temp=$(awk '{print $NF}' <<<$amb_temp | sed 's/C//g')
|
||||
echo -n "scale=1;${amb_temp}/1" | grep -oE "\-?[[:digit:]]+\.[[:digit:]]"
|
||||
esac
|
||||
fi
|
||||
} # ambienttemp
|
||||
|
||||
#function get_ip_addresses() {
|
||||
# # return up to 2 IPv4 address(es) comma separated
|
||||
# hostname -I | tr " " "\n" | \
|
||||
# grep -E "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" | \
|
||||
# tail -n2 | sed ':a;N;$!ba;s/\n/,/g'
|
||||
#} # get_ip_addresses
|
||||
|
||||
function get_ip_addresses() {
|
||||
local ips=()
|
||||
for f in /sys/class/net/*; do
|
||||
local intf=$(basename $f)
|
||||
# match only interface names starting with e (Ethernet), br (bridge), w (wireless), r (some Ralink drivers use ra<number> format)
|
||||
if [[ $intf =~ $SHOW_IP_PATTERN ]]; then
|
||||
local tmp=$(ip -4 addr show dev $intf | awk '/inet/ {print $2}' | cut -d'/' -f1)
|
||||
# add both name and IP - can be informative but becomes ugly with long persistent/predictable device names
|
||||
#[[ -n $tmp ]] && ips+=("$intf: $tmp")
|
||||
# add IP only
|
||||
[[ -n $tmp ]] && ips+=("$tmp")
|
||||
fi
|
||||
done
|
||||
echo "${ips[@]}"
|
||||
} # get_ip_addresses
|
||||
|
||||
function storage_info() {
|
||||
# storage info
|
||||
RootInfo=$(df -h /)
|
||||
root_usage=$(awk '/\// {print $(NF-1)}' <<<${RootInfo} | sed 's/%//g')
|
||||
root_total=$(awk '/\// {print $(NF-4)}' <<<${RootInfo})
|
||||
StorageInfo=$(df -h $STORAGE 2>/dev/null | grep $STORAGE)
|
||||
if [[ -n "${StorageInfo}" && ${RootInfo} != *$STORAGE* ]]; then
|
||||
storage_usage=$(awk '/\// {print $(NF-1)}' <<<${StorageInfo} | sed 's/%//g')
|
||||
storage_total=$(awk '/\// {print $(NF-4)}' <<<${StorageInfo})
|
||||
fi
|
||||
} # storage_info
|
||||
|
||||
# query various systems and send some stuff to the background for overall faster execution.
|
||||
# Works only with ambienttemp and batteryinfo since A20 is slow enough :)
|
||||
amb_temp=$(ambienttemp &)
|
||||
ip_address=$(get_ip_addresses &)
|
||||
batteryinfo
|
||||
storage_info
|
||||
getboardtemp
|
||||
critical_load=$(( 1 + $(grep -c processor /proc/cpuinfo) / 2 ))
|
||||
|
||||
# get uptime, logged in users and load in one take
|
||||
UPTIME=$(LC_ALL=C uptime)
|
||||
UPT1=${UPTIME#*'up '}
|
||||
UPT2=${UPT1%'user'*}
|
||||
users=${UPT2//*','}
|
||||
users=${users//' '}
|
||||
time=${UPT2%','*}
|
||||
time=${time//','}
|
||||
load=${UPTIME#*'load average: '}
|
||||
load=${load//','}
|
||||
|
||||
# memory and swap
|
||||
mem_info=$(LC_ALL=C free -w 2>/dev/null | grep "^Mem" || LC_ALL=C free | grep "^Mem")
|
||||
memory_usage=$(awk '{printf("%.0f",(($2-($4+$6+$7))/$2) * 100)}' <<<${mem_info})
|
||||
memory_total=$(awk '{printf("%d",$2/1024)}' <<<${mem_info})
|
||||
swap_info=$(LC_ALL=C free -m | grep "^Swap")
|
||||
swap_usage=$( (awk '/Swap/ { printf("%3.0f", $3/$2*100) }' <<<${swap_info} 2>/dev/null || echo 0) | tr -c -d '[:digit:]')
|
||||
swap_total=$(awk '{print $(2)}' <<<${swap_info})
|
||||
|
||||
# display info
|
||||
display "System load" "${load%% *}" "${critical_load}" "0" "" "${load#* }"
|
||||
printf "Up time: \x1B[92m%s\x1B[0m\t\t" "$time"
|
||||
display "Local users" "${users##* }" "3" "2" ""
|
||||
echo "" # fixed newline
|
||||
display "Memory usage" "$memory_usage" "70" "0" " %" " of ${memory_total}MB"
|
||||
display "Zram usage" "$swap_usage" "75" "0" " %" " of $swap_total""Mb"
|
||||
printf "IP: "
|
||||
printf "\x1B[92m%s\x1B[0m" "$ip_address"
|
||||
echo "" # fixed newline
|
||||
a=0;b=0;c=0
|
||||
display "CPU temp" "$board_temp" $CPU_TEMP_LIMIT "0" "°C" "" ; a=$?
|
||||
display "Ambient temp" "$amb_temp" $AMB_TEMP_LIMIT "0" "°C" "" ; b=$?
|
||||
(( ($a+$b) >0 )) && echo "" # new line only if some value is displayed
|
||||
display "Usage of /" "$root_usage" "90" "1" "%" " of $root_total"
|
||||
display "storage/" "$storage_usage" "90" "1" "%" " of $storage_total"
|
||||
display "Battery" "$battery_percent" "20" "1" "%" "$status_battery_text"
|
||||
echo ""
|
||||
echo ""
|
||||
30
external/packages/bsp/common/etc/update-motd.d/41-orangepi-config
vendored
Executable file
30
external/packages/bsp/common/etc/update-motd.d/41-orangepi-config
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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.
|
||||
|
||||
# DO NOT EDIT THIS FILE but add config options to /etc/default/orangepi-motd
|
||||
# any changes will be lost on board support package update
|
||||
|
||||
THIS_SCRIPT="config"
|
||||
MOTD_DISABLE=""
|
||||
|
||||
[[ -f /etc/default/orangepi-motd ]] && . /etc/default/orangepi-motd
|
||||
|
||||
for f in $MOTD_DISABLE; do
|
||||
[[ $f == $THIS_SCRIPT ]] && exit 0
|
||||
done
|
||||
|
||||
if [[ $(( $RANDOM % 2 )) == 0 ]]; then
|
||||
if [[ -f /usr/sbin/orangepi-config ]]; then
|
||||
echo -e "[\e[31m General system configuration (beta)\e[0m: \e[1morangepi-config\e[0m ]\n"
|
||||
else
|
||||
echo -e "[\e[31m Menu-driven system configuration (beta)\e[0m: \e[1msudo dpkg -i orangepi-config.deb\e[0m ]\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
17
external/packages/bsp/common/lib/systemd/system/bootsplash-ask-password-console.path
vendored
Normal file
17
external/packages/bsp/common/lib/systemd/system/bootsplash-ask-password-console.path
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Dispatch Password Requests to Console Directory Watch when bootsplash is active
|
||||
DefaultDependencies=no
|
||||
Conflicts=shutdown.target
|
||||
Conflicts=systemd-ask-password-console.path
|
||||
Conflicts=systemd-ask-password-console.service
|
||||
After=plymouth-start.service
|
||||
Before=paths.target shutdown.target cryptsetup.target
|
||||
ConditionPathExists=!/run/plymouth/pid
|
||||
ConditionPathExists=/sys/devices/platform/bootsplash.0/enabled
|
||||
|
||||
[Path]
|
||||
DirectoryNotEmpty=/run/systemd/ask-password
|
||||
MakeDirectory=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=sysinit.target
|
||||
16
external/packages/bsp/common/lib/systemd/system/bootsplash-ask-password-console.service
vendored
Normal file
16
external/packages/bsp/common/lib/systemd/system/bootsplash-ask-password-console.service
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=Dispatch Password Requests to Console when bootsplash is active
|
||||
DefaultDependencies=no
|
||||
Conflicts=shutdown.target
|
||||
Conflicts=systemd-ask-password-console.path
|
||||
Conflicts=systemd-ask-password-console.service
|
||||
After=plymouth-start.service systemd-vconsole-setup.service
|
||||
Before=shutdown.target
|
||||
ConditionPathExists=!/run/plymouth/pid
|
||||
ConditionPathExists=/sys/devices/platform/bootsplash.0/enabled
|
||||
|
||||
[Service]
|
||||
ExecStartPre=-/bin/sh -c '/bin/cat /sys/devices/platform/bootsplash.0/enabled > /run/systemd/ask-password/bootsplash-state ; exec /bin/echo off > /sys/devices/platform/bootsplash.0/enabled'
|
||||
ExecStart=/usr/bin/systemd-tty-ask-password-agent --query --console
|
||||
ExecStartPost=-/bin/sh -c 'exec /bin/cat /run/systemd/ask-password/bootsplash-state > /sys/devices/platform/bootsplash.0/enabled ; /bin/rm /run/systemd/ask-password/bootsplash-state'
|
||||
Type=oneshot
|
||||
14
external/packages/bsp/common/lib/systemd/system/bootsplash-hide-when-booted.service
vendored
Normal file
14
external/packages/bsp/common/lib/systemd/system/bootsplash-hide-when-booted.service
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Hide bootsplash after starting the system
|
||||
After=graphical.target
|
||||
DefaultDependencies=no
|
||||
ConditionPathExists=/sys/devices/platform/bootsplash.0/enabled
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/bin/sh -c 'exec /bin/sleep 15'
|
||||
ExecStart=/bin/sh -c 'exec /bin/echo off > /sys/devices/platform/bootsplash.0/enabled'
|
||||
Restart=no
|
||||
Type=oneshot
|
||||
|
||||
[Install]
|
||||
WantedBy=graphical.target
|
||||
19
external/packages/bsp/common/lib/systemd/system/bootsplash-show-on-shutdown.service
vendored
Normal file
19
external/packages/bsp/common/lib/systemd/system/bootsplash-show-on-shutdown.service
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Description=Show bootsplash on system halt, power off, reboot, or kexec
|
||||
Before=systemd-halt.service
|
||||
Before=systemd-kexec.service
|
||||
Before=systemd-poweroff.service
|
||||
Before=systemd-reboot.service
|
||||
DefaultDependencies=no
|
||||
ConditionPathExists=/sys/devices/platform/bootsplash.0/enabled
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -c 'exec /bin/echo on > /sys/devices/platform/bootsplash.0/enabled'
|
||||
Restart=no
|
||||
Type=oneshot
|
||||
|
||||
[Install]
|
||||
WantedBy=halt.target
|
||||
WantedBy=kexec.target
|
||||
WantedBy=poweroff.target
|
||||
WantedBy=reboot.target
|
||||
2
external/packages/bsp/common/lib/systemd/system/getty@tty1.service.d/10-noclear.conf
vendored
Normal file
2
external/packages/bsp/common/lib/systemd/system/getty@tty1.service.d/10-noclear.conf
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
[Service]
|
||||
TTYVTDisallocate=no
|
||||
18
external/packages/bsp/common/lib/systemd/system/orangepi-firstrun-config.service
vendored
Normal file
18
external/packages/bsp/common/lib/systemd/system/orangepi-firstrun-config.service
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# Orange Pi firstrun configuration service
|
||||
# This service will run in parallel with other services
|
||||
|
||||
[Unit]
|
||||
Description=Orange Pi first run optional user configuration
|
||||
Wants=network-online.target
|
||||
After=network.target network-online.target
|
||||
ConditionPathExists=/boot/orangepi_first_run.txt
|
||||
ConditionPathExists=/root/.not_logged_in_yet
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/lib/orangepi/orangepi-firstrun-config
|
||||
TimeoutStartSec=2min
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
17
external/packages/bsp/common/lib/systemd/system/orangepi-firstrun.service
vendored
Normal file
17
external/packages/bsp/common/lib/systemd/system/orangepi-firstrun.service
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Orange Pi firstrun service
|
||||
# Regenerates the SSH keys and performs additional first run tweaks
|
||||
# This service will run in parallel with other services
|
||||
|
||||
[Unit]
|
||||
Description=Orange Pi first run tasks
|
||||
Before=getty.target system-getty.slice
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/lib/orangepi/orangepi-firstrun start
|
||||
TimeoutStartSec=2min
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
19
external/packages/bsp/common/lib/systemd/system/orangepi-hardware-monitor.service
vendored
Normal file
19
external/packages/bsp/common/lib/systemd/system/orangepi-hardware-monitor.service
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# Orange Pi hardware monitor service
|
||||
# Detects and sets various features on boot
|
||||
# This service may block the boot process for up to 2 minutes
|
||||
|
||||
[Unit]
|
||||
Description=Orange Pi hardware monitoring
|
||||
Before=basic.target
|
||||
After=sysinit.target local-fs.target
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/lib/orangepi/orangepi-hardware-monitor start
|
||||
ExecStop=/usr/lib/orangepi/orangepi-hardware-monitor stop
|
||||
RemainAfterExit=yes
|
||||
TimeoutStartSec=2min
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
19
external/packages/bsp/common/lib/systemd/system/orangepi-hardware-optimize.service
vendored
Normal file
19
external/packages/bsp/common/lib/systemd/system/orangepi-hardware-optimize.service
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# Orange Pi hardware optimization service
|
||||
# Apply optimisations
|
||||
# This service may block the boot process for up to 2 minutes
|
||||
|
||||
[Unit]
|
||||
Description=Orange Pi hardware optimization
|
||||
Before=basic.target
|
||||
After=sysinit.target local-fs.target orangepi-hardware-monitor.target
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/lib/orangepi/orangepi-hardware-optimization start
|
||||
ExecStop=/usr/lib/orangepi/orangepi-hardware-optimization stop
|
||||
RemainAfterExit=yes
|
||||
TimeoutStartSec=2min
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
23
external/packages/bsp/common/lib/systemd/system/orangepi-ramlog.service
vendored
Normal file
23
external/packages/bsp/common/lib/systemd/system/orangepi-ramlog.service
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# Orange Pi ramlog service
|
||||
# Stores logs in (compressed) memory
|
||||
# This service may block the boot process for up to 30 sec
|
||||
|
||||
[Unit]
|
||||
Description=Orange Pi memory supported logging
|
||||
DefaultDependencies=no
|
||||
Before=rsyslog.service sysinit.target syslog.target
|
||||
After=orangepi-zram-config.service
|
||||
Conflicts=shutdown.target
|
||||
RequiresMountsFor=/var/log /var/log.hdd
|
||||
IgnoreOnIsolate=yes
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/lib/orangepi/orangepi-ramlog start
|
||||
ExecStop=/usr/lib/orangepi/orangepi-ramlog stop
|
||||
ExecReload=/usr/lib/orangepi/orangepi-ramlog write
|
||||
RemainAfterExit=yes
|
||||
TimeoutStartSec=30sec
|
||||
|
||||
[Install]
|
||||
WantedBy=sysinit.target
|
||||
18
external/packages/bsp/common/lib/systemd/system/orangepi-resize-filesystem.service
vendored
Normal file
18
external/packages/bsp/common/lib/systemd/system/orangepi-resize-filesystem.service
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# Orange Pi resize filesystem service
|
||||
# Resizes partition and filesystem on first/second boot
|
||||
# This service may block the boot process for up to 3 minutes
|
||||
|
||||
[Unit]
|
||||
Description=Orange Pi filesystem resize
|
||||
Before=basic.target
|
||||
After=sysinit.target local-fs.target
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/lib/orangepi/orangepi-resize-filesystem start
|
||||
TimeoutStartSec=6min
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
20
external/packages/bsp/common/lib/systemd/system/orangepi-zram-config.service
vendored
Normal file
20
external/packages/bsp/common/lib/systemd/system/orangepi-zram-config.service
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# Orange Pi ZRAM configuration service
|
||||
# Create 1 + number of cores compressed block devices
|
||||
# This service may block the boot process for up to 30 sec
|
||||
|
||||
[Unit]
|
||||
Description=Orange Pi ZRAM config
|
||||
DefaultDependencies=no
|
||||
After=local-fs.target
|
||||
Before=orangepi-ramlog.target
|
||||
Conflicts=shutdown.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/lib/orangepi/orangepi-zram-config start
|
||||
ExecStop=/usr/lib/orangepi/orangepi-zram-config stop
|
||||
RemainAfterExit=yes
|
||||
TimeoutStartSec=30sec
|
||||
|
||||
[Install]
|
||||
WantedBy=sysinit.target
|
||||
2
external/packages/bsp/common/lib/systemd/system/serial-getty@.service.d/10-term.conf
vendored
Normal file
2
external/packages/bsp/common/lib/systemd/system/serial-getty@.service.d/10-term.conf
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
[Service]
|
||||
Environment=TERM=linux
|
||||
2
external/packages/bsp/common/lib/systemd/system/systemd-journald.service.d/override.conf
vendored
Normal file
2
external/packages/bsp/common/lib/systemd/system/systemd-journald.service.d/override.conf
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
[Unit]
|
||||
After=orangepi-ramlog.service
|
||||
@@ -0,0 +1,2 @@
|
||||
[Service]
|
||||
TimeoutStopSec=10
|
||||
5
external/packages/bsp/common/lib/udev/rules.d/71-axp-power-button.rules
vendored
Normal file
5
external/packages/bsp/common/lib/udev/rules.d/71-axp-power-button.rules
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
# Handle AXP power button with systemd
|
||||
ACTION=="remove", GOTO="power_switch_end"
|
||||
SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="axp20x-pek", TAG+="power-switch"
|
||||
SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="axp[12][890]-supplyer", TAG+="power-switch"
|
||||
LABEL="power_switch_end"
|
||||
1215
external/packages/bsp/common/usr/bin/orangepimonitor
vendored
Executable file
1215
external/packages/bsp/common/usr/bin/orangepimonitor
vendored
Executable file
File diff suppressed because it is too large
Load Diff
1
external/packages/bsp/common/usr/lib/chromium-browser/master_preferences.dpkg-dist
vendored
Symbolic link
1
external/packages/bsp/common/usr/lib/chromium-browser/master_preferences.dpkg-dist
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../../share/chromium/master_preferences
|
||||
8
external/packages/bsp/common/usr/lib/nand-sata-install/exclude.txt
vendored
Normal file
8
external/packages/bsp/common/usr/lib/nand-sata-install/exclude.txt
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/boot/*
|
||||
/dev/*
|
||||
/proc/*
|
||||
/sys/*
|
||||
/media/*
|
||||
/mnt/*
|
||||
/run/*
|
||||
/tmp/*
|
||||
55
external/packages/bsp/common/usr/lib/orangepi/orangepi-apt-updates
vendored
Executable file
55
external/packages/bsp/common/usr/lib/orangepi/orangepi-apt-updates
vendored
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/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
|
||||
|
||||
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
|
||||
|
||||
52
external/packages/bsp/common/usr/lib/orangepi/orangepi-common
vendored
Executable file
52
external/packages/bsp/common/usr/lib/orangepi/orangepi-common
vendored
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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 deteceted, generate one.
|
||||
set_fixed_mac ()
|
||||
{
|
||||
|
||||
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}")
|
||||
MACADDR=$(/sbin/ip link | grep -A1 ${DEVNAME} | awk -F" " '/ether / {print $2}')
|
||||
|
||||
[[ -z $MACADDR ]] && get_random_mac
|
||||
|
||||
if [[ -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
|
||||
return 0
|
||||
fi
|
||||
} # set fixed mac to the 1st active network adapter
|
||||
120
external/packages/bsp/common/usr/lib/orangepi/orangepi-firstrun
vendored
Executable file
120
external/packages/bsp/common/usr/lib/orangepi/orangepi-firstrun
vendored
Executable file
@@ -0,0 +1,120 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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 Uptime"
|
||||
right_meter_modes="2 2 2 2"
|
||||
x=1
|
||||
until [ $x -gt $cpu_cores ]; do
|
||||
right_meters=$right_meters" CpuFreq($x)"
|
||||
right_meter_modes=$right_meter_modes" 2"
|
||||
let x+=1
|
||||
done
|
||||
sed -i 's/header_margin=.*/header_margin=1/g' /etc/skel/.config/htop/htoprc
|
||||
sed -i 's/left_meters=.*/left_meters=AllCPUs Memory Swap CpuTemp/g' /etc/skel/.config/htop/htoprc
|
||||
sed -i 's/left_meter_modes=.*/left_meter_modes=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 ]] && set_fixed_mac
|
||||
systemctl disable orangepi-firstrun
|
||||
exit 0
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 start"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
140
external/packages/bsp/common/usr/lib/orangepi/orangepi-firstrun-config
vendored
Executable file
140
external/packages/bsp/common/usr/lib/orangepi/orangepi-firstrun-config
vendored
Executable file
@@ -0,0 +1,140 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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
|
||||
180
external/packages/bsp/common/usr/lib/orangepi/orangepi-hardware-monitor
vendored
Executable file
180
external/packages/bsp/common/usr/lib/orangepi/orangepi-hardware-monitor
vendored
Executable file
@@ -0,0 +1,180 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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
|
||||
227
external/packages/bsp/common/usr/lib/orangepi/orangepi-hardware-optimization
vendored
Executable file
227
external/packages/bsp/common/usr/lib/orangepi/orangepi-hardware-optimization
vendored
Executable file
@@ -0,0 +1,227 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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_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/zram0" || "${CheckDevice}" == "orangepi-ramlog" ]]; then
|
||||
for ConfigFile in /etc/logrotate.d/* ; do sed -i -e "s/\/log\//\/log.hdd\//g" "${ConfigFile}"; done
|
||||
sed -i "s/\/log\//\/log.hdd\//g" /etc/logrotate.conf
|
||||
else
|
||||
for ConfigFile in /etc/logrotate.d/* ; do sed -i -e "s/\/log.hdd\//\/log\//g" "${ConfigFile}"; done
|
||||
sed -i "s/\/log.hdd\//\/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 -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
|
||||
|
||||
case ${BOARDFAMILY} in
|
||||
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
|
||||
echo 2 >/proc/irq/$(awk -F":" "/ehci/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
|
||||
echo 2 >/proc/irq/$(awk -F":" "/ohci/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
|
||||
echo 4 >/proc/irq/$(awk -F":" "/xhci/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
|
||||
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
|
||||
;;
|
||||
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 == default ]] && 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
|
||||
|
||||
case $1 in
|
||||
*start*)
|
||||
# set optimal disk scheduler settings
|
||||
set_io_scheduler &
|
||||
|
||||
# hardware preparation
|
||||
prepare_board &
|
||||
|
||||
# add usb quirks
|
||||
add_usb_storage_quirks &
|
||||
;;
|
||||
esac
|
||||
129
external/packages/bsp/common/usr/lib/orangepi/orangepi-ramlog
vendored
Executable file
129
external/packages/bsp/common/usr/lib/orangepi/orangepi-ramlog
vendored
Executable file
@@ -0,0 +1,129 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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=$(which 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 --links $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 $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
|
||||
if [ "$(blkid -s TYPE /dev/zram0 | awk ' { print $2 } ' | grep ext4)" ]; then
|
||||
LOG_TYPE="zram"
|
||||
else
|
||||
LOG_TYPE="tmpfs"
|
||||
fi
|
||||
|
||||
case $LOG_TYPE in
|
||||
zram)
|
||||
echo -e "Mounting /dev/zram0 as $RAM_LOG \c" | $LOG_OUTPUT
|
||||
mount -o discard /dev/zram0 $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
|
||||
202
external/packages/bsp/common/usr/lib/orangepi/orangepi-resize-filesystem
vendored
Executable file
202
external/packages/bsp/common/usr/lib/orangepi/orangepi-resize-filesystem
vendored
Executable file
@@ -0,0 +1,202 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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()
|
||||
{
|
||||
# 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
|
||||
|
||||
# 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 32
|
||||
# as divider and substract 1)
|
||||
local percentage=$(echo $RESIZE_VALUE | tr -c -d '[:digit:]')
|
||||
local lastsector=$(( 32 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * $percentage / 3200))}") - 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=$(( 32 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * 99 / 3200))}") -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=$(( 32 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * 95 / 3200))}") -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=$(( 32 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * 98 / 3200))}") -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=$(( 32 * $(parted $rootdevicepath unit s print -sm | grep "^$rootdevicepath" | awk -F":" "{printf (\"%0d\", ( \$2 * 99 / 3200))}") -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=$?
|
||||
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) # 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
|
||||
}
|
||||
|
||||
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}
|
||||
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
|
||||
30
external/packages/bsp/common/usr/lib/orangepi/orangepi-truncate-logs
vendored
Executable file
30
external/packages/bsp/common/usr/lib/orangepi/orangepi-truncate-logs
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) Authors: http://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 # %
|
||||
|
||||
[ -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
|
||||
fi
|
||||
137
external/packages/bsp/common/usr/lib/orangepi/orangepi-zram-config
vendored
Executable file
137
external/packages/bsp/common/usr/lib/orangepi/orangepi-zram-config
vendored
Executable file
@@ -0,0 +1,137 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://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_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 ZRAM_PERCENTAGE, ZRAM_MAX_DEVICES, SWAP_ALGORITHM,
|
||||
# RAMLOG_ALGORITHM and TMP_ALGORITHM here:
|
||||
[ -f /etc/default/orangepi-zram-config ] && . /etc/default/orangepi-zram-config
|
||||
|
||||
activate_zram_swap() {
|
||||
# Do not interfere with already present config-zram package
|
||||
dpkg -l | grep -q 'zram-config' && exit 0
|
||||
|
||||
[[ "$ENABLED" != "true" ]] && exit 0
|
||||
|
||||
# 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
|
||||
|
||||
# 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")
|
||||
memory_total=$(awk '{printf("%d",$2*1024)}' <<<${mem_info})
|
||||
mem_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${zram_percent} / 100 ))
|
||||
|
||||
# Limit memory available to zram to 50% by default
|
||||
mem_limit_percent=${MEM_LIMIT_PERCENTAGE:=50}
|
||||
mem_limit_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${mem_limit_percent} / 100 ))
|
||||
|
||||
# Limit Journal size to 20Mb
|
||||
sed -i "s/.*SystemMaxUse=$/SystemMaxUse=20M/" /etc/systemd/journald.conf
|
||||
|
||||
swap_algo=${SWAP_ALGORITHM:=lzo}
|
||||
for (( i=1; i<=zram_devices; i++ )); do
|
||||
if [ -f /sys/block/zram${i}/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/zram${i}/comp_algorithm && \
|
||||
[[ "X${swap_algo}" = "Xlzo" ]] && swap_algo="lzo-rle"
|
||||
echo ${swap_algo} >/sys/block/zram${i}/comp_algorithm 2>/dev/null
|
||||
fi
|
||||
if [ "X${ZRAM_BACKING_DEV}" != "X" ]; then
|
||||
echo ${ZRAM_BACKING_DEV} >/sys/block/zram${i}/backing_dev
|
||||
fi
|
||||
echo -n ${ZRAM_MAX_DEVICES:=4} > /sys/block/zram${i}/max_comp_streams
|
||||
echo -n ${mem_per_zram_device} > /sys/block/zram${i}/disksize
|
||||
echo -n ${mem_limit_per_zram_device} > /sys/block/zram${i}/mem_limit
|
||||
mkswap /dev/zram${i}
|
||||
swapon -p 5 /dev/zram${i}
|
||||
done
|
||||
|
||||
# Swapping to HDDs is stupid so switch to settings made for flash memory and zram/zswap
|
||||
echo 0 > /proc/sys/vm/page-cluster
|
||||
|
||||
echo -e "\n### Activated ${zram_devices} ${swap_algo} zram swap devices with $(( ${mem_per_zram_device} / 1048576 )) MB each\n" >>${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
|
||||
|
||||
# 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/zram0/comp_algorithm 2>/dev/null
|
||||
done
|
||||
else
|
||||
echo ${RAMLOG_ALGORITHM} >/sys/block/zram0/comp_algorithm 2>/dev/null
|
||||
fi
|
||||
echo -n ${disksize} > /sys/block/zram0/disksize
|
||||
|
||||
# if it fails, select $swap_algo. Workaround for some older kernels
|
||||
if [[ $? == 1 ]]; then
|
||||
echo ${swap_algo} > /sys/block/zram0/comp_algorithm 2>/dev/null
|
||||
echo -n ${disksize} > /sys/block/zram0/disksize
|
||||
fi
|
||||
|
||||
mkfs.ext4 -O ^has_journal -s 1024 -L log2ram /dev/zram0
|
||||
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/zram0/comp_algorithm)
|
||||
echo -e "### Activated Orange Pi ramlog partition with ${algo} compression" >>${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=$(( ${zram_devices} + 1 ))
|
||||
if [[ -f /sys/block/zram${tmp_device}/comp_algorithm ]]; then
|
||||
if [ "X${TMP_ALGORITHM}" = "X" ]; then
|
||||
echo ${swap_algo} >/sys/block/zram${tmp_device}/comp_algorithm 2>/dev/null
|
||||
else
|
||||
echo ${TMP_ALGORITHM} >/sys/block/zram${tmp_device}/comp_algorithm 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
echo -n $(( ${memory_total} / 2 )) > /sys/block/zram${tmp_device}/disksize
|
||||
mkfs.ext4 -O ^has_journal -s 1024 -L tmp /dev/zram${tmp_device}
|
||||
mount -o nosuid,discard /dev/zram${tmp_device} /tmp
|
||||
chmod 777 /tmp
|
||||
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/zram${tmp_device}/comp_algorithm)
|
||||
echo -e "\n### Activated ${algo} compressed /tmp" >>${Log}
|
||||
} # activate_compressed_tmp
|
||||
|
||||
case $1 in
|
||||
*start*)
|
||||
activate_zram_swap
|
||||
activate_ramlog_partition
|
||||
activate_compressed_tmp
|
||||
;;
|
||||
esac
|
||||
728
external/packages/bsp/common/usr/sbin/nand-sata-install
vendored
Executable file
728
external/packages/bsp/common/usr/sbin/nand-sata-install
vendored
Executable file
@@ -0,0 +1,728 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://www.armbian.com/authors
|
||||
#
|
||||
# Tool to transfer the rootfs of an already running Orange Pi installation from SD card
|
||||
# to NAND, eMMC, SATA or USB storage. In case of eMMC it's also possible to transfer
|
||||
# the bootloader to eMMC in a single step so from then on running without SD card is
|
||||
# possible.
|
||||
|
||||
# Import:
|
||||
# DIR: path to u-boot directory
|
||||
# write_uboot_platform: function to write u-boot to a block device
|
||||
|
||||
[[ -f /usr/lib/u-boot/platform_install.sh ]] && source /usr/lib/u-boot/platform_install.sh
|
||||
|
||||
# script configuration
|
||||
CWD="/usr/lib/nand-sata-install"
|
||||
EX_LIST="${CWD}/exclude.txt"
|
||||
[ -f /etc/default/openmediavault ] && echo '/srv/*' >> "${EX_LIST}"
|
||||
logfile="/var/log/nand-sata-install.log"
|
||||
|
||||
# read in board info
|
||||
[[ -f /etc/orangepi-release ]] && source /etc/orangepi-release
|
||||
backtitle="$BOARD_NAME install script, http://www.orangepi.org"
|
||||
title="eMMC and USB Orange Pi installer v${VERSION}"
|
||||
|
||||
# exceptions
|
||||
if grep -q 'sun4i' /proc/cpuinfo; then DEVICE_TYPE="a10";
|
||||
elif grep -q 'sun5i' /proc/cpuinfo; then DEVICE_TYPE="a13";
|
||||
else DEVICE_TYPE="a20"; fi
|
||||
BOOTLOADER="${CWD}/${DEVICE_TYPE}/bootloader"
|
||||
case ${LINUXFAMILY} in
|
||||
rk3328|rk3399|rockchip64)
|
||||
FIRSTSECTOR=32768
|
||||
;;
|
||||
*)
|
||||
FIRSTSECTOR=8192
|
||||
;;
|
||||
esac
|
||||
|
||||
#recognize_root
|
||||
root_uuid=$(sed -e 's/^.*root=//' -e 's/ .*$//' < /proc/cmdline)
|
||||
root_partition=$(blkid | tr -d '":' | grep "${root_uuid}" | awk '{print $1}')
|
||||
root_partition_device="${root_partition::-2}"
|
||||
|
||||
# find targets: NAND, EMMC, SATA, SPI flash, NVMe
|
||||
[[ -b /dev/nand ]] && nandcheck=$(ls -d -1 /dev/nand* | grep -w 'nand' | awk '{print $NF}');
|
||||
emmccheck=$(ls -d -1 /dev/mmcblk* | grep -w 'mmcblk[0-9]' | grep -v "$root_partition_device");
|
||||
diskcheck=$(lsblk -l | awk -F" " '/ disk / {print $1}' | grep -E '^sd|^nvme')
|
||||
spicheck=$(grep 'mtd' /proc/partitions | awk '{print $NF}')
|
||||
|
||||
# define makefs and mount options
|
||||
declare -A mkopts mountopts
|
||||
# for ARMv7 remove 64bit feature from default mke2fs format features
|
||||
if [[ $LINUXFAMILY == mvebu ]]; then
|
||||
mkopts[ext2]='-O ^64bit -qF'
|
||||
mkopts[ext3]='-O ^64bit -qF'
|
||||
mkopts[ext4]='-O ^64bit -qF'
|
||||
else
|
||||
mkopts[ext2]='-qF'
|
||||
mkopts[ext3]='-qF'
|
||||
mkopts[ext4]='-qF'
|
||||
fi
|
||||
mkopts[btrfs]='-f'
|
||||
mkopts[f2fs]='-f'
|
||||
|
||||
mountopts[ext2]='defaults,noatime,nodiratime,commit=600,errors=remount-ro,x-gvfs-hide 0 1'
|
||||
mountopts[ext3]='defaults,noatime,nodiratime,commit=600,errors=remount-ro,x-gvfs-hide 0 1'
|
||||
mountopts[ext4]='defaults,noatime,nodiratime,commit=600,errors=remount-ro,x-gvfs-hide 0 1'
|
||||
mountopts[btrfs]='defaults,noatime,nodiratime,commit=600,compress=lzo,x-gvfs-hide 0 2'
|
||||
mountopts[f2fs]='defaults,noatime,nodiratime,x-gvfs-hide 0 2'
|
||||
|
||||
# Create boot and root file system "$1" = boot, "$2" = root (Example: create_orangepi "/dev/nand1" "/dev/sda3")
|
||||
create_orangepi()
|
||||
{
|
||||
# create mount points, mount and clean
|
||||
TempDir=$(mktemp -d /mnt/${0##*/}.XXXXXX || exit 2)
|
||||
sync && mkdir -p "${TempDir}"/bootfs "${TempDir}"/rootfs
|
||||
if [[ $eMMCFilesystemChoosen =~ ^(btrfs|f2fs)$ ]]; then
|
||||
[[ -n $1 ]] && mount ${1::-1}"1" "${TempDir}"/bootfs
|
||||
[[ -n $2 ]] && ( mount -o compress-force=zlib "$2" "${TempDir}"/rootfs 2> /dev/null || mount "$2" "${TempDir}"/rootfs )
|
||||
else
|
||||
[[ -n $2 ]] && ( mount -o compress-force=zlib "$2" "${TempDir}"/rootfs 2> /dev/null || mount "$2" "${TempDir}"/rootfs )
|
||||
[[ -n $1 && $1 != "spi" ]] && mount "$1" "${TempDir}"/bootfs
|
||||
fi
|
||||
rm -rf "${TempDir}"/bootfs/* "${TempDir}"/rootfs/*
|
||||
|
||||
# sata root part
|
||||
# UUID=xxx...
|
||||
satauuid=$(blkid -o export "$2" | grep -w UUID)
|
||||
|
||||
# SD card boot part -- wrong since more than one entry on various platforms
|
||||
# UUID=xxx...
|
||||
sduuid=$(blkid -o export /dev/mmcblk*p1 | grep -w UUID | grep -v "$root_partition_device")
|
||||
|
||||
# write information to log
|
||||
echo -e "\nOld UUID: ${root_uuid}" >> $logfile
|
||||
echo "SD UUID: $sduuid" >> $logfile
|
||||
echo "SATA UUID: $satauuid" >> $logfile
|
||||
echo "eMMC UUID: $emmcuuid $eMMCFilesystemChoosen" >> $logfile
|
||||
echo "Boot: \$1 $1 $eMMCFilesystemChoosen" >> $logfile
|
||||
echo "Root: \$2 $2 $FilesystemChoosen" >> $logfile
|
||||
|
||||
# calculate usage and see if it fits on destination
|
||||
USAGE=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
|
||||
DEST=$(df -BM | grep ^/dev | grep "${TempDir}"/rootfs | awk '{print $4}' | tr -cd '[0-9]. \n')
|
||||
if [[ $USAGE -gt $DEST ]]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox\
|
||||
"\n\Z1Partition too small.\Zn Needed: $USAGE MB Avaliable: $DEST MB" 5 60
|
||||
umount_device "$1"; umount_device "$2"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
if [[ $1 == *nand* ]]; then
|
||||
# creating nand boot. Copy precompiled uboot
|
||||
rsync -aqc $BOOTLOADER/* "${TempDir}"/bootfs
|
||||
fi
|
||||
|
||||
# write information to log
|
||||
echo "Usage: $USAGE" >> $logfile
|
||||
echo -e "Dest: $DEST\n\n/etc/fstab:" >> $logfile
|
||||
cat /etc/fstab >> $logfile
|
||||
echo -e "\n/etc/mtab:" >> $logfile
|
||||
grep '^/dev/' /etc/mtab | grep -E -v "log2ram|folder2ram" | sort >> $logfile
|
||||
|
||||
# stop running services
|
||||
echo -e "\nFiles currently open for writing:" >> $logfile
|
||||
lsof / | awk 'NR==1 || $4~/[0-9][uw]/' | grep -v "^COMMAND" >> $logfile
|
||||
echo -e "\nTrying to stop running services to minimize open files:\c" >> $logfile
|
||||
stop_running_services "nfs-|smbd|nmbd|winbind|ftpd|netatalk|monit|cron|webmin|rrdcached" >> $logfile
|
||||
stop_running_services "fail2ban|ramlog|folder2ram|postgres|mariadb|mysql|postfix|mail|nginx|apache|snmpd" >> $logfile
|
||||
pkill dhclient 2>/dev/null
|
||||
LANG=C echo -e "\n\nChecking again for open files:" >> $logfile
|
||||
lsof / | awk 'NR==1 || $4~/[0-9][uw]/' | grep -v "^COMMAND" >> $logfile
|
||||
|
||||
# count files is needed for progress bar
|
||||
dialog --title " $title " --backtitle "$backtitle" --infobox "\n Counting files ... few seconds." 5 60
|
||||
TODO=$(rsync -ahvrltDn --delete --stats --exclude-from=$EX_LIST / "${TempDir}"/rootfs | grep "Number of files:"|awk '{print $4}' | tr -d '.,')
|
||||
echo -e "\nCopying ${TODO} files to $2. \c" >> $logfile
|
||||
|
||||
# creating rootfs
|
||||
# Speed copy increased x10
|
||||
# Variables for interfacing with rsync progress
|
||||
nsi_conn_path="${TempDir}/nand-sata-install"
|
||||
nsi_conn_done="${nsi_conn_path}/done"
|
||||
nsi_conn_progress="${nsi_conn_path}/progress"
|
||||
mkdir -p "${nsi_conn_path}"
|
||||
echo 0 >"${nsi_conn_progress}"
|
||||
echo no >"${nsi_conn_done}"
|
||||
|
||||
# Launch rsync in background
|
||||
{ \
|
||||
rsync -avrltD --delete --exclude-from=$EX_LIST / "${TempDir}"/rootfs | \
|
||||
nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \
|
||||
> "${nsi_conn_progress}" ;
|
||||
# save exit code from rsync
|
||||
echo ${PIPESTATUS[0]} >"${nsi_conn_done}"
|
||||
} &
|
||||
|
||||
# while variables
|
||||
rsync_copy_finish=0
|
||||
rsync_progress=0
|
||||
prev_progress=0
|
||||
rsync_done=""
|
||||
while [ "${rsync_copy_finish}" -eq 0 ]; do
|
||||
# Sometimes reads the progress file while writing and only partial numbers (like 1 when is 15)
|
||||
prev_progress=${rsync_progress}
|
||||
rsync_progress=$(tail -n1 "${nsi_conn_progress}")
|
||||
if [[ -z ${rsync_progress} ]]; then
|
||||
rsync_progress=${prev_progress}
|
||||
fi
|
||||
if [ ${prev_progress} -gt ${rsync_progress} ]; then
|
||||
rsync_progress=${prev_progress}
|
||||
fi
|
||||
echo "${rsync_progress}"
|
||||
# finish the while if the rsync is finished
|
||||
rsync_done=$(cat ${nsi_conn_done})
|
||||
if [[ "${rsync_done}" != "no" ]]; then
|
||||
if [[ ${rsync_done} -eq 0 ]]; then
|
||||
rm -rf "${nsi_conn_path}"
|
||||
rsync_copy_finish=1
|
||||
else
|
||||
# if rsync return error
|
||||
echo "Error: could not copy rootfs files, exiting"
|
||||
exit 4
|
||||
fi
|
||||
else
|
||||
sleep 0.5
|
||||
fi
|
||||
|
||||
done | \
|
||||
dialog --backtitle "$backtitle" --title " $title " --gauge "\n\n Transferring rootfs to $2 ($USAGE MB). \n\n \
|
||||
This will take approximately $(( $((USAGE/300)) * 1 )) minutes to finish. Please wait!\n\n" 11 80
|
||||
|
||||
# run rsync again to silently catch outstanding changes between / and "${TempDir}"/rootfs/
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... Almost done." 5 40
|
||||
rsync -avrltD --delete --exclude-from=$EX_LIST / "${TempDir}"/rootfs >/dev/null 2>&1
|
||||
|
||||
# creating fstab from scratch
|
||||
rm -f "${TempDir}"/rootfs/etc/fstab
|
||||
mkdir -p "${TempDir}"/rootfs/etc "${TempDir}"/rootfs/media/mmcboot "${TempDir}"/rootfs/media/mmcroot
|
||||
|
||||
# Restore TMP and swap
|
||||
echo "# <file system> <mount point> <type> <options> <dump> <pass>" > "${TempDir}"/rootfs/etc/fstab
|
||||
echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> "${TempDir}"/rootfs/etc/fstab
|
||||
grep swap /etc/fstab >> "${TempDir}"/rootfs/etc/fstab
|
||||
|
||||
# creating fstab, kernel and boot script for NAND partition
|
||||
#
|
||||
if [[ $1 == *nand* ]]; then
|
||||
echo "Finishing installation to NAND." >> $logfile
|
||||
REMOVESDTXT="and remove SD to boot from NAND"
|
||||
echo "$1 /boot vfat defaults 0 0" >> "${TempDir}"/rootfs/etc/fstab
|
||||
echo "$2 / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" >> "${TempDir}"/rootfs/etc/fstab
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nConverting kernel ... few seconds." 5 60
|
||||
mkimage -A arm -O linux -T kernel -C none -a "0x40008000" -e "0x40008000" -n "Linux kernel" -d \
|
||||
/boot/zImage "${TempDir}"/bootfs/uImage >/dev/null 2>&1
|
||||
cp /boot/script.bin "${TempDir}"/bootfs/
|
||||
|
||||
if [[ $DEVICE_TYPE != a13 ]]; then
|
||||
# Note: Not using UUID based boot for NAND
|
||||
cat <<-EOF > "${TempDir}"/bootfs/uEnv.txt
|
||||
console=ttyS0,115200
|
||||
root=$2 rootwait
|
||||
extraargs="console=tty1 hdmi.audio=EDID:0 disp.screen0_output_mode=EDID:0 consoleblank=0 loglevel=1"
|
||||
EOF
|
||||
else
|
||||
# Note: Not using UUID based boot for NAND
|
||||
cat <<-EOF > "${TempDir}"/bootfs/uEnv.txt
|
||||
console=ttyS0,115200
|
||||
root=$2 rootwait
|
||||
extraargs="consoleblank=0 loglevel=1"
|
||||
EOF
|
||||
fi
|
||||
|
||||
sync
|
||||
|
||||
[[ $DEVICE_TYPE = a20 ]] && echo "machid=10bb" >> "${TempDir}"/bootfs/uEnv.txt
|
||||
# ugly hack becouse we don't have sources for A10 nand uboot
|
||||
if [[ $ID == Cubieboard || $BOARD_NAME == Cubieboard || $ID == "Lime A10" || $BOARD_NAME == "Lime A10" ]]; then
|
||||
cp "${TempDir}"/bootfs/uEnv.txt "${TempDir}"/rootfs/boot/uEnv.txt
|
||||
cp "${TempDir}"/bootfs/script.bin "${TempDir}"/rootfs/boot/script.bin
|
||||
cp "${TempDir}"/bootfs/uImage "${TempDir}"/rootfs/boot/uImage
|
||||
fi
|
||||
umount_device "/dev/nand"
|
||||
tune2fs -o journal_data_writeback /dev/nand2 >/dev/null 2>&1
|
||||
tune2fs -O ^has_journal /dev/nand2 >/dev/null 2>&1
|
||||
e2fsck -f /dev/nand2 >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
# Boot from eMMC, root = eMMC or SATA / USB
|
||||
#
|
||||
if [[ $2 == ${emmccheck}p* || $1 == ${emmccheck}p* ]]; then
|
||||
|
||||
if [[ $2 == ${DISK_ROOT_PART} ]]; then
|
||||
local targetuuid=$satauuid
|
||||
local choosen_fs=$FilesystemChoosen
|
||||
echo "Finalizing: boot from eMMC, rootfs on USB/SATA/NVMe." >> $logfile
|
||||
if [[ $eMMCFilesystemChoosen =~ ^(btrfs|f2fs)$ ]]; then
|
||||
echo "$emmcuuid /media/mmcroot $eMMCFilesystemChoosen ${mountopts[$eMMCFilesystemChoosen]}" >> "${TempDir}"/rootfs/etc/fstab
|
||||
fi
|
||||
else
|
||||
local targetuuid=$emmcuuid
|
||||
local choosen_fs=$eMMCFilesystemChoosen
|
||||
echo "Finishing full install to eMMC." >> $logfile
|
||||
fi
|
||||
|
||||
# fix that we can have one exlude file
|
||||
cp -R /boot "${TempDir}"/bootfs
|
||||
# old boot scripts
|
||||
sed -e 's,root='"$root_uuid"',root='"$targetuuid"',g' -i "${TempDir}"/bootfs/boot/boot.cmd
|
||||
# new boot scripts
|
||||
if [[ -f "${TempDir}"/bootfs/boot/orangepiEnv.txt ]]; then
|
||||
sed -e 's,rootdev=.*,rootdev='"$targetuuid"',g' -i "${TempDir}"/bootfs/boot/orangepiEnv.txt
|
||||
grep -q '^rootdev' "${TempDir}"/bootfs/boot/orangepiEnv.txt || echo "rootdev=$targetuuid" >> "${TempDir}"/bootfs/boot/orangepiEnv.txt
|
||||
else
|
||||
sed -e 's,setenv rootdev.*,setenv rootdev '"$targetuuid"',g' -i "${TempDir}"/bootfs/boot/boot.cmd
|
||||
[[ -f "${TempDir}"/bootfs/boot/boot.ini ]] && sed -e 's,^setenv rootdev.*$,setenv rootdev "'"$targetuuid"'",' -i "${TempDir}"/bootfs/boot/boot.ini
|
||||
[[ -f "${TempDir}"/rootfs/boot/boot.ini ]] && sed -e 's,^setenv rootdev.*$,setenv rootdev "'"$targetuuid"'",' -i "${TempDir}"/rootfs/boot/boot.ini
|
||||
fi
|
||||
mkimage -C none -A arm -T script -d "${TempDir}"/bootfs/boot/boot.cmd "${TempDir}"/bootfs/boot/boot.scr >/dev/null 2>&1 || (echo 'Error while creating U-Boot loader image with mkimage' >&2 ; exit 5)
|
||||
|
||||
# fstab adj
|
||||
if [[ "$1" != "$2" ]]; then
|
||||
echo "$emmcbootuuid /media/mmcboot ext4 ${mountopts[ext4]}" >> "${TempDir}"/rootfs/etc/fstab
|
||||
echo "/media/mmcboot/boot /boot none bind 0 0" >> "${TempDir}"/rootfs/etc/fstab
|
||||
fi
|
||||
# if the rootfstype is not defined as cmdline argument on orangepiEnv.txt
|
||||
if ! grep -qE '^rootfstype=.*' "${TempDir}"/bootfs/boot/orangepiEnv.txt; then
|
||||
# Add the line of type of the selected rootfstype to the file orangepiEnv.txt
|
||||
echo "rootfstype=$choosen_fs" >> "${TempDir}"/bootfs/boot/orangepiEnv.txt
|
||||
fi
|
||||
|
||||
if [[ $eMMCFilesystemChoosen =~ ^(btrfs|f2fs)$ ]]; then
|
||||
echo "$targetuuid / $choosen_fs ${mountopts[$choosen_fs]}" >> "${TempDir}"/rootfs/etc/fstab
|
||||
# swap file not supported under btrfs but we might have made a partition
|
||||
[[ -n ${emmcswapuuid} ]] && sed -e 's,/var/swap.*,'$emmcswapuuid' none swap sw 0 0,g' -i "${TempDir}"/rootfs/etc/fstab
|
||||
sed -e 's,rootfstype=.*,rootfstype='$eMMCFilesystemChoosen',g' -i "${TempDir}"/bootfs/boot/orangepiEnv.txt
|
||||
else
|
||||
sed -e 's,rootfstype=.*,rootfstype='$choosen_fs',g' -i "${TempDir}"/bootfs/boot/orangepiEnv.txt
|
||||
echo "$targetuuid / $choosen_fs ${mountopts[$choosen_fs]}" >> "${TempDir}"/rootfs/etc/fstab
|
||||
fi
|
||||
|
||||
if [[ $(type -t write_uboot_platform) != function ]]; then
|
||||
echo "Error: no u-boot package found, exiting"
|
||||
exit 6
|
||||
fi
|
||||
write_uboot_platform "$DIR" $emmccheck
|
||||
|
||||
fi
|
||||
|
||||
# Boot from SD card, root = SATA / USB
|
||||
#
|
||||
if [[ $2 == ${DISK_ROOT_PART} && -z $1 ]]; then
|
||||
echo -e "Finishing transfer to disk, boot from SD/eMMC" >> $logfile
|
||||
[[ -f /boot/boot.cmd ]] && sed -e 's,root='"$root_uuid"',root='"$satauuid"',g' -i /boot/boot.cmd
|
||||
[[ -f /boot/boot.ini ]] && sed -e 's,^setenv rootdev.*$,setenv rootdev "'"$satauuid"'",' -i /boot/boot.ini
|
||||
# new boot scripts
|
||||
if [[ -f /boot/orangepiEnv.txt ]]; then
|
||||
sed -e 's,rootdev=.*,rootdev='"$satauuid"',g' -i /boot/orangepiEnv.txt
|
||||
grep -q '^rootdev' /boot/orangepiEnv.txt || echo "rootdev=$satauuid" >> /boot/orangepiEnv.txt
|
||||
sed -e 's,rootfstype=.*,rootfstype='$FilesystemChoosen',g' -i /boot/orangepiEnv.txt
|
||||
grep -q '^rootfstype' /boot/orangepiEnv.txt || echo "rootfstype=$FilesystemChoosen" >> /boot/orangepiEnv.txt
|
||||
else
|
||||
sed -e 's,setenv rootdev.*,setenv rootdev '"$satauuid"',' -i /boot/boot.cmd
|
||||
sed -e 's,setenv rootdev.*,setenv rootdev '"$satauuid"',' -i /boot/boot.ini
|
||||
sed -e 's,setenv rootfstype.*,setenv rootfstype '"$FilesystemChoosen"',' -i /boot/boot.cmd
|
||||
sed -e 's,setenv rootfstype.*,setenv rootfstype '"$FilesystemChoosen"',' -i /boot/boot.ini
|
||||
fi
|
||||
[[ -f /boot/boot.cmd ]] && mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1 || (echo 'Error while creating U-Boot loader image with mkimage' >&2 ; exit 7)
|
||||
mkdir -p "${TempDir}"/rootfs/media/mmc/boot
|
||||
echo "${sduuid} /media/mmcboot ext4 ${mountopts[ext4]}" >> "${TempDir}"/rootfs/etc/fstab
|
||||
echo "/media/mmcboot/boot /boot none bind 0 0" >> "${TempDir}"/rootfs/etc/fstab
|
||||
echo "$satauuid / $FilesystemChoosen ${mountopts[$FilesystemChoosen]}" >> "${TempDir}"/rootfs/etc/fstab
|
||||
# recreate swap file if already existing (might be missing since zram only)
|
||||
if [ -f /var/swap ]; then
|
||||
fallocate -l 128M "${TempDir}"/rootfs/var/swap || dd if=/dev/zero of="${TempDir}"/rootfs/var/swap bs=1M count=128 status=noxfer
|
||||
mkswap "${TempDir}"/rootfs/var/swap
|
||||
fi
|
||||
fi
|
||||
|
||||
# Boot from SPI, root = SATA / USB
|
||||
#
|
||||
if [[ $1 == *spi* ]]; then
|
||||
sed -e 's,rootdev=.*,rootdev='"$satauuid"',g' -i "${TempDir}"/rootfs/boot/orangepiEnv.txt
|
||||
echo "$satauuid / $FilesystemChoosen ${mountopts[$FilesystemChoosen]}" >> "${TempDir}"/rootfs/etc/fstab
|
||||
fi
|
||||
|
||||
# recreate OMV mounts at destination if needed
|
||||
grep -q ' /srv/' /etc/fstab
|
||||
if [ $? -eq 0 -a -f /etc/default/openmediavault ]; then
|
||||
echo -e '# >>> [openmediavault]' >> "${TempDir}"/rootfs/etc/fstab
|
||||
grep ' /srv/' /etc/fstab | while read ; do
|
||||
echo "${REPLY}" >> "${TempDir}"/rootfs/etc/fstab
|
||||
mkdir -p -m700 "${TempDir}/rootfs$(awk -F" " '{print $2}' <<<"${REPLY}")"
|
||||
done
|
||||
echo -e '# <<< [openmediavault]' >> "${TempDir}"/rootfs/etc/fstab
|
||||
fi
|
||||
|
||||
echo -e "\nChecking again for open files:" >> $logfile
|
||||
lsof / | awk 'NR==1 || $4~/[0-9][uw]/' | grep -v "^COMMAND" >> $logfile
|
||||
LANG=C echo -e "\n$(date): Finished\n\n" >> $logfile
|
||||
cat $logfile > "${TempDir}"/rootfs${logfile}
|
||||
sync
|
||||
|
||||
umount "${TempDir}"/rootfs
|
||||
[[ $1 != "spi" ]] && umount "${TempDir}"/bootfs
|
||||
} # create_orangepi
|
||||
|
||||
# Accept device as parameter: for example /dev/sda unmounts all their mounts
|
||||
umount_device()
|
||||
{
|
||||
if [[ -n $1 ]]; then
|
||||
device="$1";
|
||||
for n in ${device}*; do
|
||||
if [[ $device != "$n" ]]; then
|
||||
if mount|grep -q "$n"; then
|
||||
umount -l "$n" >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
} # umount_device
|
||||
|
||||
show_nand_warning()
|
||||
{
|
||||
local temp_rc=$(mktemp)
|
||||
cat <<-'EOF' > $temp_rc
|
||||
screen_color = (WHITE,RED,ON)
|
||||
EOF
|
||||
local warn_text="You are installing the system to sunxi NAND.
|
||||
|
||||
This is not recommended as NAND has \Z1worse performance
|
||||
and reliability\Zn than a good SD card.
|
||||
|
||||
You have been warned."
|
||||
|
||||
DIALOGRC=$temp_rc dialog --title "NAND warning" --backtitle "$backtitle" --colors \
|
||||
--ok-label "I understand and agree" --msgbox "$warn_text" 10 70
|
||||
}
|
||||
|
||||
# formatting sunxi NAND - no parameters, fixed solution.
|
||||
#
|
||||
format_nand()
|
||||
{
|
||||
[[ ! -e /dev/nand ]] && echo '/dev/nand does not exist' >&2 && exit 8
|
||||
|
||||
show_nand_warning
|
||||
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating ... up to one minute." 5 40
|
||||
if [[ $DEVICE_TYPE = a20 ]]; then
|
||||
(echo y;) | sunxi-nand-part -f a20 /dev/nand 65536 'bootloader 65536' 'linux 0' >> $logfile 2>&1
|
||||
else
|
||||
(echo y;) | sunxi-nand-part -f a10 /dev/nand 65536 'bootloader 65536' 'linux 0' >> $logfile 2>&1
|
||||
fi
|
||||
|
||||
mkfs.vfat /dev/nand1 >> $logfile 2>&1
|
||||
mkfs.ext4 -qF /dev/nand2 >> $logfile 2>&1
|
||||
}
|
||||
|
||||
|
||||
# formatting eMMC [device] example /dev/mmcblk1 - one can select filesystem type
|
||||
#
|
||||
format_emmc()
|
||||
{
|
||||
# choose and create fs
|
||||
IFS=" "
|
||||
BTRFS=$(grep -o btrfs /proc/filesystems)
|
||||
FilesystemTargets="1 ext4 2 ext3 3 ext2 4 f2fs"
|
||||
[[ -n $BTRFS && ! `uname -r | grep '^3.' ` ]] && FilesystemTargets=$FilesystemTargets" 5 $BTRFS"
|
||||
FilesystemOptions=($FilesystemTargets)
|
||||
|
||||
FilesystemCmd=(dialog --title "Select filesystem type for eMMC $1" --backtitle "$backtitle" --menu "\n$infos" 10 60 16)
|
||||
FilesystemChoices=$("${FilesystemCmd[@]}" "${FilesystemOptions[@]}" 2>&1 >/dev/tty)
|
||||
|
||||
[[ $? -ne 0 ]] && exit 9
|
||||
eMMCFilesystemChoosen=${FilesystemOptions[(2*$FilesystemChoices)-1]}
|
||||
|
||||
# deletes all partitions on eMMC drive
|
||||
dd bs=1 seek=446 count=64 if=/dev/zero of="$1" >/dev/null 2>&1
|
||||
# calculate capacity and reserve some unused space to ease cloning of the installation
|
||||
# to other media 'of the same size' (one sector less and cloning will fail)
|
||||
QUOTED_DEVICE=$(echo "$1" | sed 's:/:\\\/:g')
|
||||
CAPACITY=$(parted "$1" unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", \$2 / ( 1024 / \$4 ))}")
|
||||
|
||||
if [[ $CAPACITY -lt 4000000 ]]; then
|
||||
# Leave 2 percent unpartitioned when eMMC size is less than 4GB (unlikely)
|
||||
LASTSECTOR=$(( 32 * $(parted "$1" unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", ( \$2 * 98 / 3200))}") -1 ))
|
||||
else
|
||||
# Leave 1 percent unpartitioned
|
||||
LASTSECTOR=$(( 32 * $(parted "$1" unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", ( \$2 * 99 / 3200))}") -1 ))
|
||||
fi
|
||||
|
||||
parted -s "$1" -- mklabel msdos
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating $1 to $eMMCFilesystemChoosen ... please wait." 5 60
|
||||
# we can't boot from btrfs or f2fs
|
||||
if [[ $eMMCFilesystemChoosen =~ ^(btrfs|f2fs)$ ]]; then
|
||||
local partedFsType="${eMMCFilesystemChoosen}"
|
||||
if [[ $eMMCFilesystemChoosen == "f2fs" ]]; then
|
||||
partedFsType=''
|
||||
fi
|
||||
|
||||
# default boot partition size, in MiB
|
||||
DEFAULT_BOOTSIZE=96
|
||||
|
||||
# (convert to sectors for partitioning)
|
||||
DEFAULT_BOOTSIZE_SECTORS=$(((${DEFAULT_BOOTSIZE} * 1024 * 1024) / 512))
|
||||
|
||||
# check whether swap is currently defined and a new swap partition is needed
|
||||
grep -q swap /etc/fstab
|
||||
case $? in
|
||||
0)
|
||||
parted -s "$1" -- mkpart primary $partedFsType ${FIRSTSECTOR}s $(( ${FIRSTSECTOR} + ${DEFAULT_BOOTSIZE_SECTORS} - 1 ))s
|
||||
parted -s "$1" -- mkpart primary $partedFsType $(( ${FIRSTSECTOR} + ${DEFAULT_BOOTSIZE_SECTORS} ))s $(( ${FIRSTSECTOR} + 393215 ))s
|
||||
parted -s "$1" -- mkpart primary $partedFsType $(( ${FIRSTSECTOR} + 393216 ))s ${LASTSECTOR}s
|
||||
partprobe "$1"
|
||||
mkfs.ext4 ${mkopts[ext4]} "$1"'p1' >> $logfile 2>&1
|
||||
mkswap "$1"'p2' >> $logfile 2>&1
|
||||
mkfs.${eMMCFilesystemChoosen} "$1"'p3' ${mkopts[$eMMCFilesystemChoosen]} >> $logfile 2>&1
|
||||
emmcbootuuid=$(blkid -o export "$1"'p1' | grep -w UUID)
|
||||
emmcswapuuid=$(blkid -o export "$1"'p2' | grep -w UUID)
|
||||
emmcuuid=$(blkid -o export "$1"'p3' | grep -w UUID)
|
||||
dest_root=$emmccheck'p3'
|
||||
;;
|
||||
*)
|
||||
parted -s "$1" -- mkpart primary $partedFsType ${FIRSTSECTOR}s $(( ${FIRSTSECTOR} + ${DEFAULT_BOOTSIZE_SECTORS} - 1 ))s
|
||||
parted -s "$1" -- mkpart primary $partedFsType $(( ${FIRSTSECTOR} + ${DEFAULT_BOOTSIZE_SECTORS} ))s ${LASTSECTOR}s
|
||||
partprobe "$1"
|
||||
mkfs.ext4 ${mkopts[ext4]} "$1"'p1' >> $logfile 2>&1
|
||||
mkfs.${eMMCFilesystemChoosen} "$1"'p2' ${mkopts[$eMMCFilesystemChoosen]} >> $logfile 2>&1
|
||||
emmcbootuuid=$(blkid -o export "$1"'p1' | grep -w UUID)
|
||||
emmcuuid=$(blkid -o export "$1"'p2' | grep -w UUID)
|
||||
dest_root=$emmccheck'p2'
|
||||
;;
|
||||
esac
|
||||
else
|
||||
parted -s "$1" -- mkpart primary $eMMCFilesystemChoosen ${FIRSTSECTOR}s ${LASTSECTOR}s
|
||||
partprobe "$1"
|
||||
mkfs.${eMMCFilesystemChoosen} ${mkopts[$eMMCFilesystemChoosen]} "$1"'p1' >> $logfile 2>&1
|
||||
emmcuuid=$(blkid -o export "$1"'p1' | grep -w UUID)
|
||||
emmcbootuuid=$emmcuuid
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# formatting SATA/USB/NVMe partition, examples: /dev/sda3 or /dev/nvme0n1p1
|
||||
#
|
||||
format_disk()
|
||||
{
|
||||
# choose and create fs
|
||||
IFS=" "
|
||||
ROOTFSTYPE=$(lsblk -o MOUNTPOINT,FSTYPE | awk -F" " '/^\/\ / {print $2}')
|
||||
case ${ROOTFSTYPE} in
|
||||
btrfs)
|
||||
FilesystemTargets='1 btrfs'
|
||||
;;
|
||||
*)
|
||||
BTRFS=$(grep -o btrfs /proc/filesystems)
|
||||
FilesystemTargets='1 ext4 2 ext3 3 ext2'
|
||||
[[ -n $BTRFS && ! `uname -r | grep '^3.' ` && $choice != 6 ]] && FilesystemTargets=$FilesystemTargets" 4 $BTRFS"
|
||||
;;
|
||||
esac
|
||||
FilesystemOptions=($FilesystemTargets)
|
||||
|
||||
FilesystemCmd=(dialog --title "Select filesystem type for $1" --backtitle "$backtitle" --menu "\n$infos" 10 60 16)
|
||||
FilesystemChoices=$("${FilesystemCmd[@]}" "${FilesystemOptions[@]}" 2>&1 >/dev/tty)
|
||||
|
||||
[[ $? -ne 0 ]] && exit 10
|
||||
FilesystemChoosen=${FilesystemOptions[(2*$FilesystemChoices)-1]}
|
||||
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating $1 to $FilesystemChoosen ... please wait." 5 60
|
||||
mkfs.${FilesystemChoosen} ${mkopts[$FilesystemChoosen]} "$1" >> $logfile 2>&1
|
||||
}
|
||||
|
||||
|
||||
# choose target SATA/USB/NVMe partition.
|
||||
check_partitions()
|
||||
{
|
||||
IFS=" "
|
||||
AvailablePartitions=$(lsblk -l | awk -F" " '/ part | raid..? / {print $1}' | grep -E '^sd|^nvme|^md')
|
||||
if [[ -z $AvailablePartitions ]]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --msgbox \
|
||||
"\n\Z1There are no avaliable partitions. Please create them.\Zn" 7 60
|
||||
# We need gdisk for proper partition alignment
|
||||
apt-get -y -q install gdisk >/dev/null 2>&1
|
||||
gdisk /dev/$diskcheck
|
||||
fi
|
||||
AvailablePartitions=$(lsblk -l | awk -F" " '/ part | raid..? / {print $1}' | grep -E '^sd|^nvme|^md' | uniq | sed 's|^|/dev/|' | nl | xargs echo -n)
|
||||
PartitionOptions=($AvailablePartitions)
|
||||
|
||||
PartitionCmd=(dialog --title 'Select destination:' --backtitle "$backtitle" --menu "\n$infos" 10 60 16)
|
||||
PartitionChoices=$("${PartitionCmd[@]}" "${PartitionOptions[@]}" 2>&1 >/dev/tty)
|
||||
|
||||
[[ $? -ne 0 ]] && exit 11
|
||||
DISK_ROOT_PART=${PartitionOptions[(2*$PartitionChoices)-1]}
|
||||
}
|
||||
|
||||
# build and update new bootscript
|
||||
update_bootscript()
|
||||
{
|
||||
if [ -f /boot/boot.cmd.new ]; then
|
||||
mv -f /boot/boot.cmd.new /boot/boot.cmd >/dev/null 2>&1
|
||||
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1
|
||||
elif [ -f /boot/boot.ini.new ]; then
|
||||
mv -f /boot/boot.ini.new /boot/boot.ini >/dev/null 2>&1
|
||||
rootdev=$(sed -e 's/^.*root=//' -e 's/ .*$//' < /proc/cmdline)
|
||||
rootfstype=$(sed -e 's/^.*rootfstype=//' -e 's/ .*$//' < /proc/cmdline)
|
||||
sed -i "s/setenv rootfstype.*/setenv rootfstype \"$rootfstype\"/" /boot/boot.ini
|
||||
sed -i "s/setenv rootdev.*/setenv rootdev \"$rootdev\"/" /boot/boot.ini
|
||||
fi
|
||||
}
|
||||
|
||||
# show warning [TEXT]
|
||||
show_warning()
|
||||
{
|
||||
dialog --title "$title" --backtitle "$backtitle" --cr-wrap --colors --yesno " \Z1$(toilet -W -f ascii9 WARNING)\Zn\n$1" 14 53
|
||||
[[ $? -ne 0 ]] && exit 13
|
||||
}
|
||||
|
||||
# try to stop running services
|
||||
stop_running_services()
|
||||
{
|
||||
systemctl --state=running | awk -F" " '/.service/ {print $1}' | sort -r | \
|
||||
grep -E -e "$1" | while read ; do
|
||||
echo -e "\nStopping ${REPLY} \c"
|
||||
systemctl stop ${REPLY} 2>&1
|
||||
done
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
# This tool must run under root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo 'This tool must run as root. Exiting ...' >&2
|
||||
exit 14
|
||||
fi
|
||||
|
||||
# Check if we run it from SD card
|
||||
# TODO: Disable/remove this in the future
|
||||
case ${root_partition_device} in
|
||||
/dev/mmcblk*) # mmc device, we can continue
|
||||
:
|
||||
;;
|
||||
*)
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox '\n\Z1This tool must run from SD-card! \Zn' 5 37
|
||||
exit 15
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -f $logfile ] && echo -e '\n\n\n' >> $logfile
|
||||
LANG=C echo -e "$(date): Start ${0##*/}.\n" >> $logfile
|
||||
|
||||
IFS="'"
|
||||
options=()
|
||||
if [[ -n $emmccheck ]]; then
|
||||
ichip='eMMC';
|
||||
dest_boot=$emmccheck'p1'
|
||||
dest_root=$emmccheck'p1'
|
||||
else
|
||||
ichip='NAND'
|
||||
dest_boot='/dev/nand1'
|
||||
dest_root='/dev/nand2'
|
||||
fi
|
||||
|
||||
# Boot + RootFS relocation options
|
||||
[[ -n $diskcheck ]] && options+=(1 'Boot from SD - system on SATA, USB or NVMe')
|
||||
[[ -n $nandcheck || -n $emmccheck ]] && options+=(2 "Boot from $ichip - system on $ichip")
|
||||
[[ ( -n $nandcheck || -n $emmccheck ) && -n $diskcheck ]] && options+=(3 "Boot from $ichip - system on SATA, USB or NVMe")
|
||||
[[ -n $spicheck ]] && options+=(4 'Boot from SPI - system on SATA, USB or NVMe')
|
||||
|
||||
# U-boot install/update options
|
||||
[[ -n ${root_partition_device} ]] && options+=(5 'Install/Update the bootloader on SD/eMMC')
|
||||
[[ ( $LINUXFAMILY == odroidxu4 || $LINUXFAMILY == mvebu* || $LINUXFAMILY == mt7623 ) && ( -b /dev/mmcblk0boot0 || -b /dev/mmcblk1boot0 ) ]] && options+=(6 'Install/Update the bootloader on special eMMC partition')
|
||||
[[ -n $spicheck && $(type -t write_uboot_platform_mtd) == function ]] && options+=(7 'Install/Update the bootloader on SPI Flash')
|
||||
|
||||
[[ ${#options[@]} -eq 0 || "$root_uuid" == "$emmcuuid" || "$root_uuid" == "/dev/nand2" ]] && \
|
||||
dialog --ok-label 'Cancel' --title ' Warning ' --backtitle "$backtitle" --colors --no-collapse --msgbox '\n\Z1There are no targets. Please check your drives.\Zn' 7 52
|
||||
cmd=(dialog --title 'Choose an option:' --backtitle "$backtitle" --menu "\nCurrent root: $root_uuid \n \n" 14 60 7)
|
||||
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
||||
[[ $? -ne 0 ]] && exit 16
|
||||
|
||||
for choice in $choices
|
||||
do
|
||||
case $choice in
|
||||
1)
|
||||
title='MMC (SD/eMMC) boot | USB/SATA/NVMe root install'
|
||||
command='Reboot'
|
||||
check_partitions
|
||||
show_warning "This script will erase your device $DISK_ROOT_PART. Continue?"
|
||||
format_disk "$DISK_ROOT_PART"
|
||||
create_orangepi "" "$DISK_ROOT_PART"
|
||||
;;
|
||||
2)
|
||||
title="$ichip install"
|
||||
command='Power off'
|
||||
show_warning "This script will erase your $ichip. Continue?"
|
||||
if [[ -n $emmccheck ]]; then
|
||||
umount_device "$emmccheck"
|
||||
format_emmc "$emmccheck"
|
||||
else
|
||||
umount_device '/dev/nand'
|
||||
format_nand
|
||||
fi
|
||||
create_orangepi "$dest_boot" "$dest_root"
|
||||
;;
|
||||
3)
|
||||
title="$ichip boot | USB/SATA/NVMe root install"
|
||||
command='Power off'
|
||||
check_partitions
|
||||
show_warning "This script will erase your $ichip and $DISK_ROOT_PART. Continue?"
|
||||
if [[ -n $emmccheck ]]; then
|
||||
umount_device "$emmccheck"
|
||||
format_emmc "$emmccheck"
|
||||
else
|
||||
umount_device '/dev/nand'
|
||||
format_nand
|
||||
fi
|
||||
umount_device "${DISK_ROOT_PART//[0-9]*/}"
|
||||
format_disk "$DISK_ROOT_PART"
|
||||
create_orangepi "$dest_boot" "$DISK_ROOT_PART"
|
||||
;;
|
||||
4)
|
||||
# Espressobin has flash boot by default
|
||||
title='SPI flash boot | USB/SATA/NVMe root install'
|
||||
command='Power off'
|
||||
# we need to copy boot
|
||||
sed -i '/boot/d' $EX_LIST
|
||||
check_partitions
|
||||
show_warning "This script will erase your device $DISK_ROOT_PART. Continue?"
|
||||
format_disk "$DISK_ROOT_PART"
|
||||
create_orangepi 'spi' "$DISK_ROOT_PART"
|
||||
;;
|
||||
5)
|
||||
show_warning 'This script will update the bootloader on SD/eMMC. Continue?'
|
||||
write_uboot_platform "$DIR" "${root_partition_device}"
|
||||
update_bootscript
|
||||
dialog --backtitle "$backtitle" --title 'Writing bootloader' --msgbox '\n Done.' 7 30
|
||||
return
|
||||
;;
|
||||
6)
|
||||
if [[ -b /dev/mmcblk0boot0 ]]; then
|
||||
BOOTPART='/dev/mmcblk0'
|
||||
elif [[ -b /dev/mmcblk1boot0 ]]; then
|
||||
BOOTPART='/dev/mmcblk1'
|
||||
fi
|
||||
show_warning "This script will update the bootloader on $BOOTPART. Continue?"
|
||||
write_uboot_platform "$DIR" $BOOTPART
|
||||
echo 'Done'
|
||||
return
|
||||
;;
|
||||
7)
|
||||
MTD_BLK="/dev/${spicheck}"
|
||||
show_warning "This script will update the bootloader on SPI Flash $MTD_BLK. Continue?"
|
||||
write_uboot_platform_mtd "$DIR" $MTD_BLK
|
||||
update_bootscript
|
||||
echo 'Done'
|
||||
return
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
dialog --title "$title" --backtitle "$backtitle" --yes-label "$command" --no-label 'Exit' --yesno "\nAll done. $command $REMOVESDTXT" 7 70
|
||||
[[ $? -eq 0 ]] && "$(echo ${command,,} | sed 's/ //')"
|
||||
} # main
|
||||
|
||||
main "$@"
|
||||
101
external/packages/bsp/common/usr/sbin/orangepi-add-overlay
vendored
Executable file
101
external/packages/bsp/common/usr/sbin/orangepi-add-overlay
vendored
Executable file
@@ -0,0 +1,101 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) 2017 The Armbian Project https://www.armbian.com/
|
||||
#
|
||||
# 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.
|
||||
|
||||
if [[ ! -n $1 ]]; then
|
||||
echo >&2 "Usage: $0 <overlay_source_file.dts>"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo >&2 "This program must be run with superuser rights"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [[ ! -f $1 ]]; then
|
||||
echo >&2 "Can't open file $1. File does not exist?"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [[ $1 == *.dts ]]; then
|
||||
fname=$(basename $1 .dts)
|
||||
else
|
||||
echo >&2 "Overlay source file name should have the .dts extension"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [[ ! -f /etc/orangepi-release || ! -f /boot/orangepiEnv.txt ]]; then
|
||||
echo >&2 "Orange Pi is not installed properly. Missing orangepi-release or orangepiEnv.txt"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
. /etc/orangepi-release
|
||||
|
||||
case "${LINUXFAMILY}" in
|
||||
sunxi|sunxi64|rockchip64)
|
||||
:;;
|
||||
*)
|
||||
echo >&2 "Overlays are not supported on ${LINUXFAMILY^} based boards."
|
||||
exit -1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -d /lib/modules/$(uname -r)/build/scripts/dtc ]]; then
|
||||
if [[ ! -x /lib/modules/$(uname -r)/build/scripts/dtc/dtc ]]; then
|
||||
# Can't use distribution provided (i.e. Bionic) dtc yet
|
||||
# https://git.kernel.org/pub/scm/utils/dtc/dtc.git/commit/livetree.c?id=bba26a5291c8343101e0296b0e478deb4c9b60b0
|
||||
echo >&2 "Error: kernel headers are not installed properly"
|
||||
echo >&2 "Can't find dtc that supports compiling overlays"
|
||||
echo >&2 "Please install the headers package for kernel $(uname -r)"
|
||||
exit -1
|
||||
else
|
||||
export PATH=/lib/modules/$(uname -r)/build/scripts/dtc/:$PATH
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! type dtc > /dev/null ; then
|
||||
echo "Error: dtc not found in PATH"
|
||||
echo "Please try to install matching kernel headers"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if ! grep -q 'symbols' <(dtc --help) ; then
|
||||
echo "Error: dtc does not support compiling overlays"
|
||||
# echo "Please try to install matching kernel headers"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [[ ! -d /boot/overlay-user ]]; then
|
||||
mkdir -p /boot/overlay-user
|
||||
fi
|
||||
|
||||
temp_dir=$(mktemp -d)
|
||||
|
||||
echo "Compiling the overlay"
|
||||
|
||||
dtc -@ -q -I dts -O dtb -o ${temp_dir}/${fname}.dtbo $1
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo >&2 "Error compiling the overlay"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
echo "Copying the compiled overlay file to /boot/overlay-user/"
|
||||
cp ${temp_dir}/${fname}.dtbo /boot/overlay-user/${fname}.dtbo
|
||||
|
||||
if grep -q '^user_overlays=' /boot/orangepiEnv.txt; then
|
||||
line=$(grep '^user_overlays=' /boot/orangepiEnv.txt | cut -d'=' -f2)
|
||||
if grep -qE "(^|[[:space:]])${fname}([[:space:]]|$)" <<< $line; then
|
||||
echo "Overlay ${fname} was already added to /boot/orangepiEnv.txt, skipping"
|
||||
else
|
||||
sed -i -e "/^user_overlays=/ s/$/ ${fname}/" /boot/orangepiEnv.txt
|
||||
fi
|
||||
else
|
||||
sed -i -e "\$auser_overlays=${fname}" /boot/orangepiEnv.txt
|
||||
fi
|
||||
|
||||
echo "Reboot is required to apply the changes"
|
||||
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/backlight.pkla
vendored
Normal file
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/backlight.pkla
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[Allow setting brightness]
|
||||
Identity=unix-group:sudo
|
||||
Action=org.xfce.power.backlight-helper
|
||||
ResultAny=yes
|
||||
ResultInactive=yes
|
||||
ResultActive=yes
|
||||
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/networkmanager.pkla
vendored
Normal file
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/networkmanager.pkla
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[nm-applet]
|
||||
Identity=unix-group:netdev;unix-group:sudo
|
||||
Action=org.freedesktop.NetworkManager.*
|
||||
ResultAny=yes
|
||||
ResultInactive=no
|
||||
ResultActive=yes
|
||||
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/plugdev.pkla
vendored
Normal file
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/plugdev.pkla
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[Allow Automount]
|
||||
Identity=unix-group:plugdev
|
||||
Action=org.freedesktop.udisks2.filesystem-mount;org.freedesktop.udisks2.filesystem-mount-system;org.freedesktop.udisks2.filesystem-mount-other-seat;org.freedesktop.udisks2.filesystem-unmount-others;org.freedesktop.udisks2.eject-media;org.freedesktop.udisks2.eject-media-system;org.freedesktop.udisks2.power-off-drive*
|
||||
ResultAny=yes
|
||||
ResultInactive=yes
|
||||
ResultActive=yes
|
||||
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/power.pkla
vendored
Normal file
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/power.pkla
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[Allow Desktopstuff]
|
||||
Identity=unix-group:sudo
|
||||
Action=org.freedesktop.login1.reboot;org.freedesktop.login1.reboot-multiple-session;org.freedesktop.login1.power-off;org.freedesktop.login1.power-off-multiple-sessions;org.freedesktop.login1.suspend;org.freedesktop.login1.suspend-multiple-sessions;org.freedesktop.login1.hibernate;org.freedesktop.login1.hibernate-multiple-sessions
|
||||
ResultAny=yes
|
||||
ResultInactive=yes
|
||||
ResultActive=yes
|
||||
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/printing.pkla
vendored
Normal file
6
external/packages/bsp/common/var/lib/polkit-1/localauthority/50-local.d/printing.pkla
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[printing]
|
||||
Identity=unix-group:netdev;unix-group:sudo
|
||||
Action=org.opensuse.cupspkhelper.mechanism.*
|
||||
ResultAny=yes
|
||||
ResultInactive=no
|
||||
ResultActive=yes
|
||||
Reference in New Issue
Block a user