]> arthur.barton.de Git - appify.git/blobdiff - appify.sh
Make sure that source script exists and target app does not
[appify.git] / appify.sh
index 1ebf8bb1a20b3a69c3cef8e945d6594f2df7927d..a7db78620f05e361fbf60059f9aff50c0beaf282 100755 (executable)
--- a/appify.sh
+++ b/appify.sh
@@ -1,7 +1,9 @@
 #!/bin/bash
 #
-# appify -- convert your non-interactive shell script into a Mac OS X application
+# appify -- convert non-interactive shell script into Mac OS X applications
 # Copyright (C) 2010  Adam Backstrom
+# Copyright (C) 2015  Alexander Barton <alex@barton.de>
+#
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or
@@ -19,7 +21,7 @@
 args=$(getopt h $*)
 
 function usage {
-    echo "Usage: $0 [-h] script.sh target.app"
+    echo "Usage: $0 [-h] <script.sh> <target.app>"
     exit 2
 }
 
@@ -45,8 +47,13 @@ TARGET=$2
 
 BASENAME=`basename "$SCRIPT"`
 
+if [ ! -r "$SCRIPT" ]; then
+    echo "$SCRIPT isn't readable!" 1>&2
+    exit 3
+fi
+
 if [ -e "$TARGET" ]; then
-    echo "$TARGET exists, exiting" 1>&2
+    echo "$TARGET exists!" 1>&2
     exit 3
 fi
 
@@ -61,8 +68,10 @@ fi
 # done checking args; create the app
 #
 
-mkdir -p "$TARGET/Contents/MacOS"
-mkdir -p "$TARGET/Contents/Resources"
+umask 0022
+
+mkdir -p "$TARGET/Contents/MacOS" || exit 1
+mkdir -p "$TARGET/Contents/Resources" || exit 1
 
 cat <<EOF >"$TARGET/Contents/Info.plist"
 <?xml version="1.0" encoding="UTF-8"?>
@@ -85,5 +94,5 @@ cat <<EOF >"$TARGET/Contents/Info.plist"
 </plist>
 EOF
 
-cp "$SCRIPT" "$TARGET/Contents/MacOS/$BASENAME"
-chmod 755 "$TARGET/Contents/MacOS/$BASENAME"
+cp "$SCRIPT" "$TARGET/Contents/MacOS/$BASENAME" || exit 1
+chmod 755 "$TARGET/Contents/MacOS/$BASENAME" || exit 1