Overlay: minor script refactoring (#1304)

pull/1305/head
viktorxda 2024-02-07 16:18:43 +01:00 committed by GitHub
parent 5511be0a29
commit e37099d6ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 80 additions and 171 deletions

View File

@ -10,7 +10,8 @@ case "$1" in
[ -r /etc/modules ] || exit 0 [ -r /etc/modules ] || exit 0
while read module args; do while read module args; do
case "$module" in case "$module" in
""|"#"*) continue ""|"#"*)
continue
;; ;;
esac esac

View File

@ -9,15 +9,13 @@ PID_FILE="/var/run/${NAME}.pid"
# Read configuration variable file if it is present # Read configuration variable file if it is present
[ -r "${CFG_FILE}" ] && . "${CFG_FILE}" [ -r "${CFG_FILE}" ] && . "${CFG_FILE}"
start() start() {
{
printf "Starting ${NAME}: " printf "Starting ${NAME}: "
start-stop-daemon -S -q -x "${DAEMON}" -- ${DAEMON_ARGS} start-stop-daemon -S -q -x "${DAEMON}" -- ${DAEMON_ARGS}
[ $? = 0 ] && echo "OK" || echo "FAIL" [ $? = 0 ] && echo "OK" || echo "FAIL"
} }
stop() stop() {
{
printf "Stopping ${NAME}: " printf "Stopping ${NAME}: "
# This daemon does not exit properly with the default TERM signal unless # This daemon does not exit properly with the default TERM signal unless
# it's forced to work by something reading /dev/random. Killing it and # it's forced to work by something reading /dev/random. Killing it and

View File

@ -4,4 +4,9 @@ case "$1" in
start) start)
system_fb system_fb
;; ;;
*)
echo "Usage: $0 {start}"
exit 1
;;
esac esac

View File

@ -1,7 +1,4 @@
#!/bin/sh #!/bin/sh
#
# Start mdev....
#
case "$1" in case "$1" in
start) start)
@ -10,14 +7,8 @@ case "$1" in
/sbin/mdev -s /sbin/mdev -s
;; ;;
stop)
;;
restart|reload)
;;
*) *)
echo "Usage: $0 {start|stop|restart|reload}" echo "Usage: $0 {start}"
exit 1 exit 1
;; ;;
esac esac

View File

@ -1,40 +1,20 @@
#!/bin/sh #!/bin/sh
#
# Start rc.local
#
start() { start() {
echo "Starting rc.local"
/etc/rc.local
}
restart() {
echo "Restarting rc.local"
/etc/rc.local /etc/rc.local
} }
stop() { stop() {
echo "Stopping rc.local" [ -x /etc/rc.local.stop ] && /etc/rc.local.stop
# Check if rc.local.stop exists and if so, execute it
if [ -x /etc/rc.local.stop ]; then
/etc/rc.local.stop
else
echo "/etc/rc.local.stop not found or not executable."
fi
} }
case "$1" in case "$1" in
start) start|stop)
start "$1"
;;
restart|reload)
restart
;;
stop)
stop
;; ;;
*) *)
echo "Usage: $0 {start|stop|restart|reload}" echo "Usage: $0 {start|stop}"
exit 1 exit 1
;; ;;
esac esac

View File

@ -1,65 +0,0 @@
#!/bin/sh
DAEMON="watchdog"
WATCHDOG_ENABLED=false
WATCHDOG_TIMEOUT=60
SUPPORTED_VENDORS="ingenic"
WATCHDOG_ARGS="-T $WATCHDOG_TIMEOUT /dev/watchdog"
WATCHDOG_VENDOR=$(ipcinfo -v)
vendor_supported() {
for vendor in $SUPPORTED_VENDORS; do
[ "$WATCHDOG_VENDOR" = "$vendor" ] && return 0
done
return 1
}
start()
{
if [ "$(cli -g .watchdog.enabled)" = "true" ]; then
printf "Starting ${DAEMON}: "
echo "majestic watchdog enabled"
exit 0
fi
if vendor_supported && [ "$WATCHDOG_ENABLED" = "true" ]; then
printf "Starting ${DAEMON}: "
start-stop-daemon -b -S -q -x "/sbin/${DAEMON}" -- ${WATCHDOG_ARGS}
if [ $? = 0 ]; then
echo "OK"
else
echo "FAIL"
fi
else
echo "Watchdog: System watchdog disabled"
exit 0
fi
}
stop()
{
printf "Stopping ${DAEMON}: "
if start-stop-daemon -K -q -s KILL -n "${DAEMON}"; then
echo "OK"
else
echo "FAIL"
fi
}
case "$1" in
start|stop)
"$1"
;;
restart|reload)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|reload}" >&2
exit 1
;;
esac

View File

@ -4,14 +4,15 @@ export HOME=${HOME:-/root}
export TZ=$(cat /etc/TZ) export TZ=$(cat /etc/TZ)
export SENSOR=$(fw_printenv -n sensor) export SENSOR=$(fw_printenv -n sensor)
echo_c() { echo -ne "\e[1;$1m$2\e[0m"; } echo_c() {
echo -ne "\e[1;$1m$2\e[0m"
}
if [ "$PS1" ]; then if [ "$PS1" ]; then
[ -f /etc/os-release ] && . /etc/os-release [ -f /etc/os-release ] && . /etc/os-release
[ -f /etc/openipc_banner ] && echo_c 34 "$(cat /etc/openipc_banner)" [ -f /etc/openipc_banner ] && echo_c 34 "$(cat /etc/openipc_banner)"
echo_c 32 "$(printf "%56s" "${GITHUB_VERSION}")" echo_c 32 "$(printf "%56s" "${GITHUB_VERSION}")"
[ -f /etc/openipc_donors ] && echo_c 37 "\n\n$(cat /etc/openipc_donors)\n\n" [ -f /etc/openipc_donors ] && echo_c 37 "\n\n$(cat /etc/openipc_donors)\n\n"
#
if [ "$(id -u)" -eq 0 ]; then if [ "$(id -u)" -eq 0 ]; then
export PS1='\u@\h:\w\# ' export PS1='\u@\h:\w\# '
else else
@ -21,7 +22,9 @@ fi
export EDITOR='/bin/vi' export EDITOR='/bin/vi'
[ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; } [ -x /usr/bin/arp ] || arp() {
cat /proc/net/arp
}
differ() { differ() {
diff -rN "/rom$1" "$1" diff -rN "/rom$1" "$1"
@ -31,22 +34,22 @@ majestic_changes() {
diff -L "Majestic changes" -U 3 /rom/etc/majestic.yaml /etc/majestic.yaml diff -L "Majestic changes" -U 3 /rom/etc/majestic.yaml /etc/majestic.yaml
} }
show_modules() { set_fullname() {
echo; cat /proc/modules | cut -f 1 -d " " | while read module; do echo "Module: $module"; \ show_fullname >/etc/hostname
if [ -d "/sys/module/$module/parameters" ]; then ls /sys/module/$module/parameters/ | while read parameter; \
do echo -n "Parameter: $parameter --> "; cat /sys/module/$module/parameters/$parameter; done; fi; echo; done
} }
show_fullname() { show_fullname() {
echo "openipc-$(ipcinfo --chip-name)-$(ipcinfo --short-sensor)" echo "openipc-$(ipcinfo --chip-name)-$(ipcinfo --short-sensor)"
} }
set_fullname() { show_modules() {
show_fullname >/etc/hostname echo; cat /proc/modules | cut -f1 -d " " | while read module; do echo "Module: $module"; \
if [ -d "/sys/module/$module/parameters" ]; then ls /sys/module/$module/parameters/ | while read parameter; \
do echo -n "Parameter: $parameter --> "; cat /sys/module/$module/parameters/$parameter; done; fi; echo; done
} }
show_gain() { show_gain() {
while sleep 1; do wget -q -O - http://127.0.0.1/metrics/isp | grep ^isp_again; done while sleep 1; do wget -T1 -q -O - http://127.0.0.1/metrics/isp | grep ^isp_again; done
} }
show_wlan() { show_wlan() {
@ -57,17 +60,6 @@ network() {
/etc/init.d/S40network "$1" /etc/init.d/S40network "$1"
} }
switch_debug() {
[ "$1" = "on" ] && action='+' report='enabled' || action='-' report='disabled'
mount | grep -q 'debugfs' || mount -t debugfs none /sys/kernel/debug
echo "${action}p" > /sys/kernel/debug/dynamic_debug/control
for entry in mmc_core avpu squashfs mtdblock; do
echo "module $entry -p" > /sys/kernel/debug/dynamic_debug/control
done
echo "file fs/sysfs/file.c -p" > /sys/kernel/debug/dynamic_debug/control
echo "Dynamic debug for all files has been $report."
}
# Source configuration files from /etc/profile.d # Source configuration files from /etc/profile.d
for i in /etc/profile.d/*.sh; do for i in /etc/profile.d/*.sh; do
[ -r "$i" ] && . $i [ -r "$i" ] && . $i

View File

@ -2,17 +2,15 @@
destdir=/mnt destdir=/mnt
my_umount() my_umount() {
{
if grep -qs "^/dev/$1 " /proc/mounts; then if grep -qs "^/dev/$1 " /proc/mounts; then
umount "${destdir}/$1"; umount "${destdir}/$1"
fi fi
[ -d "${destdir}/$1" ] && rmdir "${destdir}/$1" [ -d "${destdir}/$1" ] && rmdir "${destdir}/$1"
} }
my_mount() my_mount() {
{
mkdir -p "${destdir}/$1" || exit 1 mkdir -p "${destdir}/$1" || exit 1
if ! mount -t auto -o sync "/dev/$1" "${destdir}/$1"; then if ! mount -t auto -o sync "/dev/$1" "${destdir}/$1"; then
@ -36,6 +34,7 @@ add|"")
my_umount ${MDEV} my_umount ${MDEV}
my_mount ${MDEV} my_mount ${MDEV}
;; ;;
remove) remove)
my_umount ${MDEV} my_umount ${MDEV}
;; ;;

View File

@ -4,10 +4,18 @@
# #
. /etc/datalink.conf . /etc/datalink.conf
chip=$(ipcinfo -c) chip=$(ipcinfo -c)
skip=$(fw_printenv -n fpv)
fw=$(grep "BUILD_OPTION" "/etc/os-release" | cut -d= -f2) fw=$(grep "BUILD_OPTION" "/etc/os-release" | cut -d= -f2)
case "$1" in case "$1" in
start) start)
if [ ${skip} = "true" ]; then
sed -i "s/console/#console/g" /etc/inittab
elif [ ${skip} = "false" ]; then
sed -i "s/#console/console/g" /etc/inittab
exit 0
fi
if ! [ -f /etc/system.ok ]; then if ! [ -f /etc/system.ok ]; then
tweaksys ${chip} tweaksys ${chip}
fi fi