]> arthur.barton.de Git - appify.git/blob - appify.sh
Create usage line, -h flag. Better argument checking.
[appify.git] / appify.sh
1 #!/bin/bash
2
3 #
4 # appify -- convert your non-interactive shell script into a Mac OS X application
5 # Copyright (C) 2010  Adam Backstrom
6
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 #
21
22 args=$(getopt h $*)
23
24 function usage {
25     echo "Usage: $0 [-h] script.sh target.app"
26     exit 2
27 }
28
29 if [ $? != 0 ]; then
30     usage
31 fi
32
33 set -- $args
34 for i ; do
35     case "$i"
36     in
37         -h) usage ; shift ;;
38         --) shift ; break ;;
39     esac
40 done
41
42 if [ $# != 2 ]; then
43     usage
44 fi
45
46 SCRIPT=$1
47 TARGET=$2
48
49 if [ -d "$TARGET" ]; then
50     echo "$TARGET exists, exiting" 1>&2
51     exit 3
52 fi
53
54 SCRIPTSIZE=$(ls -l "$SCRIPT" | awk '{print $5}')
55
56 if [ $SCRIPTSIZE -lt 28 ]; then
57     echo -e "Script smaller than size allowed by OS. Please pad to 28 characters." 1>&2
58     exit 4
59 fi
60
61 #
62 # done checking args; create the app
63 #
64
65 mkdir -p "$TARGET/Contents/MacOS"
66 mkdir -p "$TARGET/Contents/Resources"
67
68 cat <<EOF >"$TARGET/Contents/Info.plist"
69 <?xml version="1.0" encoding="UTF-8"?>
70 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
71 <plist version="1.0">
72 <dict>
73     <key>CFBundleExecutable</key>
74     <string>run.sh</string>
75     <key>CFBundleIconFile</key>
76     <string></string>
77     <key>CFBundleInfoDictionaryVersion</key>
78     <string>1.0</string>
79     <key>CFBundlePackageType</key>
80     <string>APPL</string>
81     <key>CFBundleSignature</key>
82     <string>????</string>
83     <key>CFBundleVersion</key>
84     <string>1.0</string>
85 </dict>
86 </plist>
87 EOF
88
89 cp "$SCRIPT" "$TARGET/Contents/MacOS/run.sh"
90 chmod 755 "$TARGET/Contents/MacOS/run.sh"