add error handling to install.sh

Tue, 25 Jul 2023 17:18:53 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 25 Jul 2023 17:18:53 +0200
changeset 26
0a5e13216803
parent 25
f061eecae302
child 27
e6e7e63b8b5e

add error handling to install.sh

fixes #273

dist/install.sh file | annotate | diff | comparison | revisions
--- a/dist/install.sh	Sun Jul 16 13:29:41 2023 +0200
+++ b/dist/install.sh	Tue Jul 25 17:18:53 2023 +0200
@@ -10,6 +10,13 @@
 	echo "Default PREFIX: /usr/local"
 }
 
+# error function
+exit_on_error()
+{
+  echo "$1"
+  exit 1
+}
+
 #
 # parse arguments 
 #
@@ -22,13 +29,25 @@
 	esac
 done
 
-echo "mkdir -p $PREFIX/lib/uwproj"
-mkdir -p "$PREFIX/lib/uwproj"
+#
+# create install dir
+#
+echo "mkdir -p $PREFIX/lib/uwproj $PREFIX/bin"
+mkdir -p "$PREFIX/lib/uwproj" "$PREFIX/bin" \
+  || exit_on_error "Creating install directory failed."
 
+#
+# install the JAR file
+#
 echo "cp ../target/uwproj-0.1-jar-with-dependencies.jar $PREFIX/lib/uwproj/uwproj-0.1.jar"
-cp "../target/uwproj-0.1-jar-with-dependencies.jar" "$PREFIX/lib/uwproj/uwproj-0.1.jar"
+cp "../target/uwproj-0.1-jar-with-dependencies.jar" "$PREFIX/lib/uwproj/uwproj-0.1.jar" \
+   || exit_on_error "Installing JAR file failed."
 
+#
+# create a run script in the bin dir
+#
 echo "cp bin/uwproj $PREFIX/bin"
-sed "s:%%PREFIX%%:$PREFIX:g" "bin/uwproj" > "$PREFIX/bin/uwproj"
+sed "s:%%PREFIX%%:$PREFIX:g" "bin/uwproj" > "$PREFIX/bin/uwproj" \
+   || exit_on_error "Creating run script failed."
 
 

mercurial