mirror of https://github.com/OpenIPC/firmware.git
				
				
				
			Overlay: minor script refactoring (#1304)
							parent
							
								
									5511be0a29
								
							
						
					
					
						commit
						e37099d6ee
					
				|  | @ -10,12 +10,13 @@ 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 | ||||||
| 
 | 
 | ||||||
| 			# attempt to load modules | 			# attempt to load modules | ||||||
| 			modprobe ${module} ${args} >/dev/null | 			modprobe ${module} ${args} > /dev/null | ||||||
| 		done < /etc/modules | 		done < /etc/modules | ||||||
| 		;; | 		;; | ||||||
| esac | esac | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  |  | ||||||
|  | @ -4,4 +4,9 @@ case "$1" in | ||||||
| 	start) | 	start) | ||||||
| 		system_fb | 		system_fb | ||||||
| 		;; | 		;; | ||||||
|  | 
 | ||||||
|  | 	*) | ||||||
|  | 		echo "Usage: $0 {start}" | ||||||
|  | 		exit 1 | ||||||
|  | 		;; | ||||||
| esac | esac | ||||||
|  |  | ||||||
|  | @ -1,23 +1,14 @@ | ||||||
| #!/bin/sh | #!/bin/sh | ||||||
| # |  | ||||||
| # Start mdev.... |  | ||||||
| # |  | ||||||
| 
 | 
 | ||||||
| case "$1" in | case "$1" in | ||||||
| 	start) | 	start) | ||||||
| 		echo "Starting mdev..." | 		echo "Starting mdev..." | ||||||
| 		echo /sbin/mdev >/proc/sys/kernel/hotplug | 		echo /sbin/mdev > /proc/sys/kernel/hotplug | ||||||
| 		/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 | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  |  | ||||||
|  | @ -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 |  | ||||||
|  | @ -9,7 +9,7 @@ export TZ=$(cat /etc/TZ) | ||||||
| 
 | 
 | ||||||
| # Start all init scripts in /etc/init.d | # Start all init scripts in /etc/init.d | ||||||
| # executing them in numerical order. | # executing them in numerical order. | ||||||
| for i in /etc/init.d/S??* ; do | for i in /etc/init.d/S??*; do | ||||||
| 	# Ignore dangling symlinks (if any). | 	# Ignore dangling symlinks (if any). | ||||||
| 	[ ! -f "$i" ] && continue | 	[ ! -f "$i" ] && continue | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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,43 +34,32 @@ 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() { | ||||||
| 	grep -r '$1..=' /etc/wireless | cut -d '"' -f 4 | sort | grep -e $(fw_printenv -n soc) -e generic | 	grep -r '$1..=' /etc/wireless | cut -d '"' -f4 | sort | grep -e $(fw_printenv -n soc) -e generic | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| network() { | 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 | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  | @ -25,18 +23,19 @@ my_mount() | ||||||
| 	[ -d "${destdir}/$1/autoconfig" ] && cp -afv ${destdir}/$1/autoconfig/* / | logger -s -p daemon.info -t autoconfig | 	[ -d "${destdir}/$1/autoconfig" ] && cp -afv ${destdir}/$1/autoconfig/* / | logger -s -p daemon.info -t autoconfig | ||||||
| 
 | 
 | ||||||
| 	# execution of the specified commands one time | 	# execution of the specified commands one time | ||||||
| 	[ -f "${destdir}/$1/autoconfig.sh" ] && (sh ${destdir}/$1/autoconfig.sh ; rm -f ${destdir}/$1/autoconfig.sh) | logger -s -p daemon.info -t autoconfig | 	[ -f "${destdir}/$1/autoconfig.sh" ] && (sh ${destdir}/$1/autoconfig.sh; rm -f ${destdir}/$1/autoconfig.sh) | logger -s -p daemon.info -t autoconfig | ||||||
| 
 | 
 | ||||||
| 	# execution of the specified commands | 	# execution of the specified commands | ||||||
| 	[ -f "${destdir}/$1/autostart.sh" ] && sh ${destdir}/$1/autostart.sh | logger -s -p daemon.info -t autostart | 	[ -f "${destdir}/$1/autostart.sh" ] && sh ${destdir}/$1/autostart.sh | logger -s -p daemon.info -t autostart | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| case "${ACTION}" in | case "${ACTION}" in | ||||||
| add|"") | 	add|"") | ||||||
| 		my_umount ${MDEV} | 		my_umount ${MDEV} | ||||||
| 		my_mount ${MDEV} | 		my_mount ${MDEV} | ||||||
| 		;; | 		;; | ||||||
| remove) | 
 | ||||||
|  | 	remove) | ||||||
| 		my_umount ${MDEV} | 		my_umount ${MDEV} | ||||||
| 		;; | 		;; | ||||||
| esac | esac | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue