From 3f1c819276f48fe43a7d75f4e1f0a6c5bb76e926 Mon Sep 17 00:00:00 2001 From: Alfonso Gamboa Date: Wed, 20 Apr 2022 01:33:47 -0700 Subject: [PATCH] improve ability to hook stock system --- SD_ROOT/wz_mini/bin/factorycheck | 7 +++ SD_ROOT/wz_mini/etc/fstab | 9 +++ SD_ROOT/wz_mini/etc/init.d/v3_init.sh | 85 +++++++++++++++------------ SD_ROOT/wz_mini/etc/init.d/v3_post.sh | 16 +++++ SD_ROOT/wz_mini/etc/inittab | 34 +++++++++++ SD_ROOT/wz_mini/etc/profile | 3 + SD_ROOT/wz_mini/run_mmc.sh | 6 +- SD_ROOT/wz_mini/usr/bin/iCamera | 6 +- build.md | 1 + 9 files changed, 126 insertions(+), 41 deletions(-) create mode 100755 SD_ROOT/wz_mini/bin/factorycheck create mode 100644 SD_ROOT/wz_mini/etc/fstab create mode 100755 SD_ROOT/wz_mini/etc/init.d/v3_post.sh create mode 100644 SD_ROOT/wz_mini/etc/inittab create mode 100644 build.md diff --git a/SD_ROOT/wz_mini/bin/factorycheck b/SD_ROOT/wz_mini/bin/factorycheck new file mode 100755 index 0000000..9de55e0 --- /dev/null +++ b/SD_ROOT/wz_mini/bin/factorycheck @@ -0,0 +1,7 @@ +#!/bin/sh +echo [FC] mount tfcard finish! +echo [FC] Test.tar no exist +echo [FC] umount tfcard finish! +echo [FC] In [user] mode! + +touch /tmp/usrflag diff --git a/SD_ROOT/wz_mini/etc/fstab b/SD_ROOT/wz_mini/etc/fstab new file mode 100644 index 0000000..1cc29c9 --- /dev/null +++ b/SD_ROOT/wz_mini/etc/fstab @@ -0,0 +1,9 @@ +# +proc /proc proc defaults 0 0 +devpts /dev/pts devpts defaults,gid=5,mode=620 0 0 +#tmpfs /dev/shm tmpfs mode=0777 0 0 +tmpfs /tmp tmpfs mode=1777 0 0 +tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0 +sysfs /sys sysfs defaults 0 0 +media /media tmpfs mode=1777 0 0 +tmpfs /opt/wz_mini/tmp tmpfs mode=1777 0 0 diff --git a/SD_ROOT/wz_mini/etc/init.d/v3_init.sh b/SD_ROOT/wz_mini/etc/init.d/v3_init.sh index d9cf86c..87b0288 100755 --- a/SD_ROOT/wz_mini/etc/init.d/v3_init.sh +++ b/SD_ROOT/wz_mini/etc/init.d/v3_init.sh @@ -16,40 +16,42 @@ echo ' set -x -echo "mounting tempfs for workspace" -mount -t tmpfs /tmp -mount -t tmpfs /run - -echo "create workspace directory" -mkdir /run/.storage - -if [[ $(cat /opt/wz_mini/run_mmc.sh | grep "RTSP_ENABLED\=") == "RTSP_ENABLED\=\"true\"" ]]; then -cp /etc/init.d/rcS /run/.storage/rcS -sed -i '/^".*/aset -x' /run/.storage/rcS -sed -i '/^# Mount configs.*/i cp /system/bin/iCamera /run/.storage/\nmount -o ro,bind /opt/wz_mini/usr/bin/iCamera /system/bin/iCamera\n tail -f /system/bin/iCamera > /dev/null 2>&1 &' /run/.storage/rcS -sed -i '/sbin:/s/$/:\/opt\/wz_mini\/bin/' /run/.storage/rcS -sed -i '/system\/\lib/s/$/:\/opt\/wz_mini\/lib/' /run/.storage/rcS -mount --bind /run/.storage/rcS /etc/init.d/rcS -echo "load video loopback driver at video1" -insmod /opt/wz_mini/lib/modules/v4l2loopback.ko video_nr=1 -fi - -if [[ $(cat /opt/wz_mini/run_mmc.sh | grep "DEBUG_ENABLED\=") == "DEBUG_ENABLED\=\"true\"" ]]; then -cp /etc/init.d/rcS /run/.storage/rcS -sed -i '/app_init.sh/,+2d' /run/.storage/rcS -sed -i '/^# Run init/i/bin/sh /etc/profile' /run/.storage/rcS -mount --bind /run/.storage/rcS /etc/init.d/rcS -fi - -echo "replace stock password" -cp /opt/wz_mini/etc/shadow /run/.storage/shadow -mount --bind /run/.storage/shadow /etc/shadow -chmod 400 /etc/shadow +mount --bind /opt/wz_mini/etc/inittab /etc/inittab echo "bind /etc/profile for local/ssh shells" mount --bind /opt/wz_mini/etc/profile /etc/profile -if [[ -f /opt/wz_mini/swap.gz ]]; then +echo "mounting tempfs for workspace" +mount -t tmpfs /tmp +mount -t tmpfs /run + +echo "mount system to replace factorycheck with dummy, to prevent bind unmount" +mount /dev/mtdblock3 /system +mount --bind /opt/wz_mini/bin/factorycheck /system/bin/factorycheck +touch /tmp/usrflag + +echo "replace stock fstab" +mount --bind /opt/wz_mini/etc/fstab /etc/fstab + +echo "mount workplace dir" +mount -t tmpfs /opt/wz_mini/tmp + +echo "create workspace directory" +mkdir /opt/wz_mini/tmp/.storage + +echo "copy stock rcS" +cp /etc/init.d/rcS /opt/wz_mini/tmp/.storage/rcS + +echo "add v3_post inject to stock rcS" +sed -i '/^".*/aset -x' /opt/wz_mini/tmp/.storage/rcS +sed -i '/^# Mount configs.*/i/opt/wz_mini/etc/init.d/v3_post.sh\n' /opt/wz_mini/tmp/.storage/rcS + +echo "replace stock password" +cp /opt/wz_mini/etc/shadow /opt/wz_mini/tmp/.storage/shadow +mount --bind /opt/wz_mini/tmp/.storage/shadow /etc/shadow +chmod 400 /etc/shadow + +if [[ -e /opt/wz_mini/swap.gz ]]; then echo "swap archive present, extracting" gzip -d /opt/wz_mini/swap.gz mkswap /opt/wz_mini/swap @@ -58,17 +60,17 @@ else echo "swap archive not present, not extracting" fi -echo "mount configs partition for dropbear" -mount -t jffs2 /dev/mtdblock6 /configs - -if [[ -d /opt/wz_mini/usr/share/terminfo ]]; then +if [[ -d /opt/wz_mini/usr/share/terminfo ]]; then echo "terminfo already present" -else +else echo "terminfo not present, extract" tar xf /opt/wz_mini/usr/share/terminfo.tar -C /opt/wz_mini/usr/share/ fi +echo "mount configs partition for dropbear" +mount -t jffs2 /dev/mtdblock6 /configs + if [[ -d /configs/.ssh ]]; then echo "dropbear ssh config dir present" umount /configs @@ -81,6 +83,17 @@ fi echo "Run dropbear ssh server" /opt/wz_mini/bin/dropbearmulti dropbear -R -m -{ sleep 30; /media/mmc/wz_mini/run_mmc.sh 2> /media/mmc/wz_mini/log/wz_mini_hacks.log; } & +if [[ $(cat /opt/wz_mini/run_mmc.sh | grep "DEBUG_ENABLED\=") == "DEBUG_ENABLED\=\"true\"" ]]; then + sed -i '/app_init.sh/,+2d' /opt/wz_mini/tmp/.storage/rcS + sed -i '/^# Run init/i/bin/sh /etc/profile' /opt/wz_mini/tmp/.storage/rcS + touch /tmp/dbgflag +fi + +if ! [[ -e /tmp/dbgflag ]]; then + { sleep 30; /media/mmc/wz_mini/run_mmc.sh 2> /media/mmc/wz_mini/log/wz_mini_hacks.log; } & +else + echo "debug enabled, ignore run_mmc.sh" +fi + /linuxrc diff --git a/SD_ROOT/wz_mini/etc/init.d/v3_post.sh b/SD_ROOT/wz_mini/etc/init.d/v3_post.sh new file mode 100755 index 0000000..5379538 --- /dev/null +++ b/SD_ROOT/wz_mini/etc/init.d/v3_post.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -x + +echo "v3_post.sh" + +sed -i '/sbin:/s/$/:\/opt\/wz_mini\/bin/' /opt/wz_mini/tmp/.storage/rcS +sed -i '/system\/\lib/s/$/:\/opt\/wz_mini\/lib/' /opt/wz_mini/tmp/.storage/rcS + +if [[ $(cat /opt/wz_mini/run_mmc.sh | grep "RTSP_ENABLED\=") == "RTSP_ENABLED\=\"true\"" ]] && ! [[ -e /tmp/dbgflag ]]; then + cp /system/bin/iCamera /opt/wz_mini/tmp/.storage/ + mount -o ro,bind /opt/wz_mini/usr/bin/iCamera /system/bin/iCamera + echo "load video loopback driver at video1" + insmod /opt/wz_mini/lib/modules/v4l2loopback.ko video_nr=1 +fi + diff --git a/SD_ROOT/wz_mini/etc/inittab b/SD_ROOT/wz_mini/etc/inittab new file mode 100644 index 0000000..be1cd5a --- /dev/null +++ b/SD_ROOT/wz_mini/etc/inittab @@ -0,0 +1,34 @@ +# /etc/inittab +# +# Copyright (C) 2001 Erik Andersen +# +# Note: BusyBox init doesn't support runlevels. The runlevels field is +# completely ignored by BusyBox init. If you want runlevels, use +# sysvinit. +# +# Format for each entry: ::: +# +# id == tty to run on, or empty for /dev/console +# runlevels == ignored +# action == one of sysinit, respawn, askfirst, wait, and once +# process == program to run + +# Startup the system +::sysinit:/sbin/swapoff -a +::sysinit:/bin/mount -t tmpfs tmpfs /dev +::sysinit:/bin/mkdir -p /dev/pts +::sysinit:/bin/mkdir -p /dev/shm +::sysinit:/bin/mount -a +::sysinit:/bin/hostname -F /etc/hostname + +# now run any rc scripts +::sysinit:/opt/wz_mini/tmp/.storage/rcS + +# Put a getty on the serial port +console::respawn:/sbin/getty -L console 115200 vt100 # GENERIC_SERIAL + +# Stuff to do for the 3-finger salute +#::ctrlaltdel:/sbin/reboot + +# Stuff to do before rebooting +::shutdown:/bin/umount -a -r diff --git a/SD_ROOT/wz_mini/etc/profile b/SD_ROOT/wz_mini/etc/profile index d70d891..6843b6a 100644 --- a/SD_ROOT/wz_mini/etc/profile +++ b/SD_ROOT/wz_mini/etc/profile @@ -12,6 +12,9 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/wz_mini/bin export PATH=/system/bin:$PATH export LD_LIBRARY_PATH=/system/lib:/opt/wz_mini/lib export LD_LIBRARY_PATH=/thirdlib:$LD_LIBRARY_PATH +export TERMINFO=/opt/wz_mini/usr/share/terminfo +/opt/wz_mini/bin/busybox resize + #export TZ=UTC-8 # Set directoty and file default create permission diff --git a/SD_ROOT/wz_mini/run_mmc.sh b/SD_ROOT/wz_mini/run_mmc.sh index 5a6ab16..49e11a0 100755 --- a/SD_ROOT/wz_mini/run_mmc.sh +++ b/SD_ROOT/wz_mini/run_mmc.sh @@ -21,6 +21,7 @@ RTSP_ENABLE_AUDIO="false" ENABLE_IPV6="false" DEBUG_ENABLED="false" +#drops you to a shell via serial, doesn't load app_init.sh ##################################### ##########CONFIG END################# @@ -29,7 +30,7 @@ DEBUG_ENABLED="false" echo "run_mmc.sh start" > /dev/kmsg swap_enable() { - if [[ -f /media/mmc/wz_mini/swap ]]; then + if [[ -e /media/mmc/wz_mini/swap ]]; then echo "swap exists, enable" swapon /media/mmc/wz_mini/swap else @@ -112,9 +113,6 @@ fi echo "set hostname" hostname $HOSTNAME -echo "clean up tail" -pkill tail - sleep 3 ################################################# diff --git a/SD_ROOT/wz_mini/usr/bin/iCamera b/SD_ROOT/wz_mini/usr/bin/iCamera index a2e68f6..c3c3e78 100644 --- a/SD_ROOT/wz_mini/usr/bin/iCamera +++ b/SD_ROOT/wz_mini/usr/bin/iCamera @@ -1,5 +1,9 @@ #!/bin/sh set -x + echo "inject callback library and run" -LD_PRELOAD='libcallback.so:libtinyalsa.so.2.0.0:libsetunbuf.so' /run/.storage/iCamera + +export LD_LIBRARY_PATH='/thirdlib:/system/lib:/opt/wz_mini/lib' + +LD_PRELOAD='libcallback.so:libtinyalsa.so.2.0.0:libsetunbuf.so' /opt/wz_mini/tmp/.storage/iCamera diff --git a/build.md b/build.md new file mode 100644 index 0000000..8a7fb7a --- /dev/null +++ b/build.md @@ -0,0 +1 @@ +# process