Move the common shell code to a helper script that is sourced by all parts. Add extra quoting to some variables in the snap config file and simplify. Fixes: #4304. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>