-
Notifications
You must be signed in to change notification settings - Fork 0
/
appr.sh
executable file
·168 lines (144 loc) · 3.19 KB
/
appr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
RESOURCES=
APP=
EXECUTABLE=
FORCE=0
APPNAME=
BUNDLEID=
VERSION=1.0
HIGHDPI="true"
while :
do
case $1 in
-e|--executable)
EXECUTABLE="$2"
shift
;;
-r|--resource)
RESOURCES="$RESOURCES $2"
shift
;;
-a|--app)
APP="$2"
shift
;;
-n|--appname)
APPNAME="$2"
shift
;;
-b|--bundleid)
BUNDLEID="$2"
shift
;;
-v|--version)
VERSION="$2"
shift
;;
-d|--highdpi)
HIGHDPI="$2"
shift
;;
-f|--force)
FORCE=1
;;
*)
break;
;;
esac
shift
done
if [ -z $EXECUTABLE ]
then
echo "Executable must be specified"
exit 1
fi
if [ ! -x $EXECUTABLE ]
then
echo "Executable must be executable!"
exit 1
fi
if [ -z $APP ]
then
echo "App must be specified"
exit 1
fi
if [[ $APP != *.app ]]
then
echo "App name must end with .app"
exit 1
fi
if [ -e $APP ]
then
if [ $FORCE -eq 0 ]
then
echo "Output directory already exists"
exit 1
fi
rm -rf $APP
fi
if [ -z $APPNAME ]
then
APPNAME=`BASENAME $APP|cut -d'.' -f1`
fi
if [ -z $BUNDLEID ]
then
BUNDLEID=appr.$APPNAME
fi
EXECUTABLE_NAME=`basename $EXECUTABLE`
echo "APP: $APP"
echo "APPNAME: $APPNAME"
echo "BUNDLEID: $BUNDLEID"
echo "RESOURCES: $RESOURCES"
echo "Creating app structure..."
mkdir -p $APP/Contents/MacOS
mkdir -p $APP/Contents/Frameworks
mkdir -p $APP/Contents/Resources
echo "Copying executable..."
EXECUTABLE_DEST=$APP/Contents/MacOS/$EXECUTABLE_NAME
cp $EXECUTABLE $EXECUTABLE_DEST
for res in $RESOURCES
do
echo "Copying $res"
cp -R $res $APP/Contents/Resources/
done
echo "APPL????" > $APP/Contents/PkgInfo
cat >$APP/Contents/Info.plist <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>$APPNAME</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleIdentifier</key>
<string>$BUNDLEID</string>
<key>CFBundleVersion</key>
<string>$VERSION</string>
<key>CFBundleSignature</key>
<string>$APPNAME</string>
<key>CFBundleExecutable</key>
<string>$EXECUTABLE_NAME</string>
<!-- Enable High DPI -->
<key>NSHighResolutionCapable</key>
<$HIGHDPI/>
<key>NSHighResolutionMagnifyAllowed</key>
<false/>
<!-- Tell our code that we started from the launcher -->
<key>LSEnvironment</key>
<dict>
<key>APPR</key>
<string>1</string>
</dict>
</dict>
</plist>
EOL
echo "Copying Frameworks..."
LOCALLIBS=`otool -l $EXECUTABLE_DEST 2>&1|grep "\/usr\/local"|cut -d' ' -f11`
for LIB in $LOCALLIBS
do
echo "Framework: $LIB"
LIBNAME=`basename $LIB`
install_name_tool -change $LIB @executable_path/../Frameworks/$LIBNAME $EXECUTABLE_DEST
cp $LIB $APP/Contents/Frameworks
done