themactep / thingino-firmware

Open-source firmware for Ingenic SoC IP cameras
https://thingino.com
MIT License
79 stars 28 forks source link

Save/Restore root password and ssh keys across upgrades #100

Closed ckuethe closed 4 weeks ago

ckuethe commented 1 month ago

I suppose it's worth saying that you can copy this script to an existing camera and run S34rootcreds save and S34rootcreds status if you want to save and verify the saved credentials before updating...

themactep commented 1 month ago

ok, a few things...

init.d script are ran by system on startup and shutdown. they are not intended for user interaction so any extras like check and save are non-orthodox and call for a refactoring. any interactive part should be extracted to a separate script in /usr/sbin/, for running on start or shutdown only start and stop should be left in the init.d script.

we minimize writing to the flash chip for no reason so anything non-permanent like dealing with temporary files should be handled in tempfs which is actually a mapped ram.

variables and functions should be named in a way that eliminates the need for comments.

# in this function we calculate profitability (b) using money (c) and time (d)
function a() {
   b = c / d;
}

should become

function calculate_profitability() {
  profit = money / time;
}

ALL_CAPS_NAMES are reserved for constants. regular mutable variables go with lower snake case as regular_variable.

also, we recently added /etc/init.d/rc.common file which can care of of most common things between init.d scripts to reuse common practice and minimize footprtint. please take a loot at it.

gtxaspec commented 1 month ago

hi @ckuethe, just a ping. did you see @themactep's notes?

ckuethe commented 1 month ago

Yep, been working on some other stuff. I'll have some time this weekend to revisit this.

ckuethe commented 4 weeks ago

Tested on a local build for the W7, works as expected

ckuethe commented 4 weeks ago

Also tested on Wyze Cam v3, works as expected.