I am writing a program in C on Linux environment (Debian-Lenny) and would like the program to be updated when an update is available (the program gets notified when a new update is available). I am looking for a way that the program can update itself.
What I am thinking is that the main program invokes a new program to handle the update. The updater program will have(access to) the source code and receive the update information about the changes on the source code, something like that:
edit1: line 20, remove column 5 to 20; edit2: line25, remove column 4-7 then add "if(x>3){" from the column4 edit3: line 26, enter a new line and insert "x++;"
then kill the main process, recompile the source code, and then replace the new binary with the old one.
or is there a better (easier) and standard way to implement the ability that a program can update itself?
I use the program to control a system with a Linux embedded board. Therefore, I don’t want the source code to be accessible to another person (if the system is hacked or something). If the best way to update a program by using the source code, how do you suggest me to secure the source code? If you suggest me to encrypt the source code, what function (Linux C) can the program use to encrypt and decrypt the source file?
Advertisement
Answer
If your target system is Debian, then you should just take advantage of the Debian packaging system to provide updates. Package your compiled application in a .deb
package, distribute it on an APT archive which is included in your system’s sources.list
, and just use cron to schedule a regular update check with apt
. The .deb
package can include a post-installation script that restarts your application.
You could run an apt-proxy
caching proxy on your “gateway” nodes that have internet access, and have the other nodes use that as their apt
source.
Distributing source code in this case is probably not appropriate, because then you would need to include a full compiler toolchain on your target system.