I am writing a set Debian packaging scripts for an application that currently exists as a git repo. The basic process seems easy enough, but one thing I am not sure about is how to handle errors as the package install scripts are running.
For example:
I am creating the application directory /opt/app
. But what if it exists? Should the install script die or should I notify the user the directory can’t be created? I feel like having the script exit with status > 0 makes sense since I foresee a cascading set of failures if I don’t create the root directory since a lot of things will depend on the former processes.
However, some other processes “might” not be as fatal such as creating a user / group for the application. But still have the script exit status > 0 seems like a way to ensure you don’t end up with half an application installed.
On the subject of things missing, let’s say I cannot create the user account and decide to continue. What is a safe method to only execute functions that would return a status code 0? If I go to create a directory tree since I didn’t create the user account or group I cannot assign it to the directory since that would fail. Would it be safer to “remember” that the account was not created and skip the user and permission assignment or would be safer to assign to the group that already exists? My concern there is if the group already exists that might be used for something else and could mess things up.
What is the proper way to resolve these types of conflicts? Is it best to always have the script fail or would it even be a good idea to have the script forcefully remove the conflicting user / group before creating a new one?