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