]> arthur.barton.de Git - appify.git/blob - appify.sh
Add README and AUTHORS file
[appify.git] / appify.sh
1 #!/bin/bash
2 #
3 # appify -- convert non-interactive shell script into Mac OS X applications
4 # Copyright (C) 2010  Adam Backstrom
5 # Copyright (C) 2015  Alexander Barton <alex@barton.de>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (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 along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 args=$(getopt h $*)
22
23 function usage {
24     echo "Usage: $0 [-h] <script.sh> <target.app>"
25     exit 2
26 }
27
28 if [ $? != 0 ]; then
29     usage
30 fi
31
32 set -- $args
33 for i ; do
34     case "$i"
35     in
36         -h) usage ; shift ;;
37         --) shift ; break ;;
38     esac
39 done
40
41 if [ $# != 2 ]; then
42     usage
43 fi
44
45 SCRIPT=$1
46 TARGET=$2
47
48 BASENAME=`basename "$SCRIPT"`
49
50 if [ -e "$TARGET" ]; then
51     echo "$TARGET exists, exiting" 1>&2
52     exit 3
53 fi
54
55 SCRIPTSIZE=$(ls -l "$SCRIPT" | awk '{print $5}')
56
57 if [ $SCRIPTSIZE -lt 28 ]; then
58     echo -e "Script smaller than size allowed by OS. Please pad to 28 characters." 1>&2
59     exit 4
60 fi
61
62 #
63 # done checking args; create the app
64 #
65
66 umask 0022
67
68 mkdir -p "$TARGET/Contents/MacOS" || exit 1
69 mkdir -p "$TARGET/Contents/Resources" || exit 1
70
71 cat <<EOF >"$TARGET/Contents/Info.plist"
72 <?xml version="1.0" encoding="UTF-8"?>
73 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
74 <plist version="1.0">
75 <dict>
76     <key>CFBundleExecutable</key>
77     <string>${BASENAME}</string>
78     <key>CFBundleIconFile</key>
79     <string></string>
80     <key>CFBundleInfoDictionaryVersion</key>
81     <string>1.0</string>
82     <key>CFBundlePackageType</key>
83     <string>APPL</string>
84     <key>CFBundleSignature</key>
85     <string>????</string>
86     <key>CFBundleVersion</key>
87     <string>1.0</string>
88 </dict>
89 </plist>
90 EOF
91
92 cp "$SCRIPT" "$TARGET/Contents/MacOS/$BASENAME" || exit 1
93 chmod 755 "$TARGET/Contents/MacOS/$BASENAME" || exit 1