write a shell script/tool for auto update

Job ID: 32609243

Budget: €30 – €250 EUR

General Requirements
The script/tool shall be a standard shell scripts.
The script shall log everything necessary to be able to easily track errors and bugs, but on the other hand it shouldn’t log unnecessary things. The log shall be written into “/config/auxilio/data/logs” and shall be named auxilio_update.log. The log shall overwrite the old log file.
The script shall be well documented (comment in the file are ok) for better understanding and easy editing. The comments/documentation have to be clear and shall also be easy to understand.
The script has to take care of a successful installation. If the installation fails, there should be a rollback action, to step back to the latest state.
This is of course only valid for files that have been copied before. Any modifications done by a script have to be rolled back by a dedicated script too. Details later in the document.
The scripts shall also provide a chance to optionally restart the device after the update process (method to be defined, can e.g. be a file called “RESTART” in the archive)
Designated Work Flow
The script will be executed as a cronjob once approximately once a day or few days. When executed, the script must perform the following steps in sequence:
1. Connect to a dedicated URL. Due to the staging concept, the URL differs depending on the stage (dev/test/prod). The URL will be provided as parameter on execution.
2. Download a file called “.checksum” that contains a SHA256 checksum to a temp folder.
3. Check if the checksum is equal to the local reference checksum located in “/config/auxilio/”.
4. If the checksums are equal, there is nothing to do but end the process
5. If the checksums are not equal, download the archive (auxilio_update.tar.gz) from the server into a temp folder.
6. For safety reasons calc the SHA256 checksum for the archive again and compare it with the checksum of the downloaded reference file.
7. If everything is ok, extract the archive in the temp folder.
8. Stop all auxilio*.services
9. Check if an old backup exists “/config/auxilio/backup” from the last update. If so, delete it.
10. Create a backup of the whole directory structure and files located in “/config/auxilio” and save it in “/config/auxilio/backup”.
11. Check if a file named “pre_install.sh” exists and execute it.
12. Copy the new files into their destination folders in “/config/auxilio”.
13. Check if a file named “post_install.sh” exists and execute it.
14. If there are no errors, restart the auxilio*.services.
15. Check if a restart shall be executed and schedule it to be executed in 30 seconds.
16. Delete the extracted temporary files and the tar.gz
If the update process fails, the steps performed have to be reverted. So if a backup has been created, the new files have to be deleted and the old files have to be copied back.

Check the existence of a “pre_uninstall.sh” and a “post_uninstall.sh” and execute them in the appropriate order.
Related categories: Linux Shell Script