/
palm-run
executable file
·298 lines (259 loc) · 9.47 KB
/
palm-run
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
# -----------------------------------------------------------------------------
# palm-run [-d DEVICE] [-L] [-o DIRECTORY] [-p excludes.file] [-P] [directory | ipk]
#
# This command packages, installs, and then looks at the logs for a webOS
# application that you are developing.
#
# -d DEVICE: Defaults to installing to the first device
# -I : By default palm-launch uses -i for inspector
# -L : By default the palm-log command is run. This suppresses that
# -o OUTPUT: By default the ipk is generated to /tmp
# -p exfile: By default looks for 'excludes.txt' file
# -P : Turns on production mode (development by default)
#
# Usage examples:
#
# palm-run ~/myproject # deploy from /tmp to emulator
# palm-run -d usb -L -o /packages ~/myproject
# palm-run /path/to/com.palm.app.videogallery_1.0.1_all.ipk
# # has to be in the format of path/ID_VERSION.ipk
# palm-run -d tcp -p myexcludes.txt
# # use the emulator and package with exclude_from myexcludes.txt
# palm-run -P # looks for config/framework_production.json + config/excludes_production.txt
# palm-run # use the current directory and all the defaults
# -----------------------------------------------------------------------------
# -- Configuration settings
device=""
runlog="true"
appdir=$PWD
appfilename=""
exclude_from=""
excludes_file="package-excludes.txt"
outputdir=/tmp
production="false"
inspector="-i"
numcount=0
# read in the command line arguments
while getopts "d:o:s:p:ILP" opt; do
case $opt in
d)
device="-d $OPTARG"
let numcount=numcount+2
;;
I)
inspector=""
let numcount=numcount+1
;;
o)
outputdir=$OPTARG
let numcount=numcount+2
;;
s)
launchService=$OPTARG
let numcount=numcount+2
;;
p)
excludes_file=$OPTARG
let numcount=numcount+2
;;
P)
production="true"
echo "*** Production Mode Turned On ***\n"
let numcount=numcount+1
;;
L)
runlog="false"
let numcount=numcount+1
;;
esac
done
# shift over all of the arguments
shift $numcount
# if we have arguments left we have the directory we need
if [ $# -gt 0 ]; then
appdir=$1
fi
# Helper Functions
##################
function trim() {
echo $1;
}
function extractJsonString {
local line=`grep "$2" $1`
echo $line | sed "s/.*\"$2\"[^:]*:[^\"]\"\([^\"]*\)\".*/\1/"
}
function parsePackageInfo {
id=$(extractJsonString $package_info "id")
packageAppId=$(extractJsonString $package_info "app")
version=$(extractJsonString $package_info "version")
# Load the services
services=`awk '/"services"[ \t]*:/ { serviceSeen=1 } serviceSeen { printf("%s", $0); }serviceSeen && /\]/ { serviceSeen=0; }' $package_info`
services=`echo $services | sed -e 's/.*\[[ \t]*\(.*\)[ \t]*\]/\1/' -e 's/[^"]*"\([^"]*\)\"[^"]*/\1 /g'`
# Load the accounts
accounts=`awk '/"accounts"[ \t]*:/ { accountSeen=1 } accountSeen { printf("%s", $0); }accountSeen && /\]/ { accountSeen=0; }' $package_info`
accounts=`echo $accounts | sed -e 's/.*\[[ \t]*\(.*\)[ \t]*\]/\1/' -e 's/[^"]*"\([^"]*\)\"[^"]*/\1 /g'`
}
function package {
cmd_package="palm-package -o $outputdir $exclude_from $@"
echo "=====> $cmd_package"
package_return=`$cmd_package 2>&1`
# We want to test for the last token in the output being the start header, any additional output is a failures
successStr="in $outputdir"
testStr=${package_return:(-1*${#successStr})}
if [[ $testStr =~ $successStr ]]; then
echo $package_return
else
echo $package_return
echo "\nDue to palm-package error, aborting."
exit
fi
packageFilename=$outputdir/${id}_${version}*.ipk
if [ -f ./postPackage.sh ]; then
./postPackage.sh $packageFilename
fi
}
# Run the default target of the Rakefile if one exists
if [ -f "Rakefile" ]; then
rake
fi
# -- If it is a file, then it should be a ipk file
# has to use the name: /path/to/ID_VERSION.ipk
if [ -f $appdir ]; then
packageFilename=$appdir
appId=$(echo $appfilename | perl -e '@a = split "/", <>; ($appId) = split "_", @a[-1]; chomp($appId); print $appId')
# not a file, so test for the directory and package
elif [ -e "$appdir/appinfo.json" ]; then
appId=$(extractJsonString $appdir/appinfo.json "id")
id=$appId
version=$(extractJsonString $appdir/appinfo.json "version")
framework_config="$appdir/framework_config.json"
# Verify that this is not indented to be part of a package
if [[ `grep "requires_package.*true" $appdir/palm-run.properties` ]]; then
echo Attempting to build app that requires a package as standalone.
exit
fi
# if the config directory is available, do smart things for the given type of package
if [ -d "$appdir/config" ]; then
# set the extension type for use in the filename
if [ "$production" == "true" ]; then
type_ext="production"
else
type_ext="development"
fi
# copy the framework config over to the right place
framework_config_by_type="$appdir/config/framework_${type_ext}.json"
if [ -e "$framework_config_by_type" ]; then
echo "Using framework config found at: $framework_config_by_type"
cp $framework_config_by_type $framework_config
delete_framework_config_after_package="true"
fi
# if the excludes file exists, use that
excludes_file_by_type="$appdir/config/excludes_${type_ext}.txt"
if [ -e "$excludes_file_by_type" ]; then
echo "Using excludes file found at: $excludes_file_by_type"
exclude_from="--exclude-from=$excludes_file_by_type"
fi
else
# if an exclusion file is found, --exclude-from it
if [ -e "$appdir/$excludes_file" ]; then
exclude_from="--exclude-from=$excludes_file"
fi
fi
package $appdir
# delete the framework config that we loaded in from $framework_config_by_type instead
if [ "$delete_framework_config_after_package" == "true" ]; then
rm $framework_config
fi
elif [ `find -L . -maxdepth 2 -name packageinfo.json` ]; then
# Find the package info
package_info=`find -L . -maxdepth 2 -name packageinfo.json`
package_dir=`dirname "$package_info"`
echo Loading package from $package using $package_info
parsePackageInfo
# Find and validate the app
for x in `find -L . -maxdepth 2 -name appinfo.json`; do
appId=$(extractJsonString $x "id")
if [[ "$appId" == "$packageAppId" ]]; then
if [[ "$app_dir" ]]; then
echo "Warning found multiple application directories with id $appId"
exit
fi
app_dir=`dirname $x`
echo "Found app $appId in dir $app_dir"
else
echo "Warning unknown app id found: $appId"
fi
done
# Find, validate, and stop the services
serviceList=( $services )
servideDirs=( )
for x in `find -L . -maxdepth 2 -name services.json`; do
serviceId=$(extractJsonString $x "id")
for index in `gseq 0 $((${#serviceList[*]}-1))`; do
if [[ "$serviceId" == "${serviceList[$index]}" ]]; then
serviceDirs[$index]=`dirname $x`
break
fi
done
done
# Find and validate the accounts
accountList=( $accounts )
accountDirs=( )
for x in `find -L . -maxdepth 2 -name account-template.json`; do
echo $x
accountId=$(extractJsonString $x "templateId")
for index in `gseq 0 $((${#accountList[*]}-1))`; do
if [[ "$accountId" == "${accountList[$index]}" ]]; then
accountDirs[$index]=`dirname $x`
break
fi
done
done
# if an exclusion file is found, --exclude-from it
if [ -e "$appdir/$excludes_file" ]; then
exclude_from="--exclude-from=$excludes_file"
fi
package $package_dir $app_dir ${serviceDirs[*]} ${accountDirs[*]}
else
echo "No appinfo.json file found at $appdir/appinfo.json. This must not be a webOS application"
exit
fi
echo "=====> Stopping services"
for index in `gseq 0 $((${#serviceList[*]}-1))`; do
echo "Stopping service ${serviceList[$index]}"
novacom -- run file:///usr/bin/luna-send -n 1 palm://${serviceList[$index]}/__quit '{}'
done
echo "=====> palm-remove -r $id"
palm-install $device -r $id
# -- Run the commands
cmd_install="palm-install $device $packageFilename"
echo "=====> $cmd_install"
install_return=`$cmd_install 2>&1`
if [ "$?" -ne "0" ]; then
if [ "$device" == "-d usb" ]; then
echo "Unable to connect to the phone. Make sure that it is plugged into USB and in developer mode."
else
echo "Unable to connect to the emulator. Make sure that it is running."
fi
exit
else
echo $install_return
fi
if [ "$launchService" ]; then
novacom -- run file:///usr/bin/run-js-service "/media/cryptofs/apps/usr/palm/services/$launchService"
elif [ "$appId" ]; then
if [ $runlog == "true" ]; then
set -m
cmd_log="palm-log -f $device $appId"
echo "=====> $cmd_log"
$cmd_log &
sleep 1
fi
cmd_launch="palm-launch $device $inspector $appId"
echo "=====> $cmd_launch"
$cmd_launch
if [ $runlog == "true" ]; then
fg
fi
fi