2016-12-02 104 views
1

我使用Cordova CLI在我的Ubuntu 16.04 VPS服务器上创建Android APK。一旦建立了APK,我将它复制到本地机器上的Dropbox,然后在我的Android测试设备上安装APK。我想使用的Dropbox API将APK文件直接上传所以我尽量避免不必要的3路传输:在Linux shell脚本中有条件执行命令

Server -> Local Machine -> Dropbox -> Android test device. 

操作的顺序会是这样的

  • Shell脚本(已写入)上的服务器清理了Android源和重建APK
  • 这是通过在其上确保成功生成发射在端
以下文本的PhoneGap /科尔多瓦详细输出做0

生成成功

Total time: 5.495 secs 
Built the following apk(s): 
/path/to/app/source/platforms/android/build/outputs/apk/android-debug.apk 


No scripts found for hook "after_compile". 


No scripts found for hook "after_build". 


[36m[phonegap][39m completed 'cordova build android -d --no-telemetry' 

的最后一步 - 上传的Android APK我的Dropbox,如果BUILD成功的科尔多瓦/ PhoneGap的调试输出被发现时才需要这样做。我有在地方的一切,但我不知道我应该怎么检查BUILD SUCCESSFUL

这里是shell脚本

!# /bin/bash 
pgclean; 
# pgclean is another shell script that cleans up the Phonegap project in the 
# current folder 
pgbuild; 
# this rebuilds the APK and saves the detailed debug output to 
# /path/to/my/project/debug.txt 
# it is debug.txt which would contain BUILD SUCCESSFUL etc 

这里是我的bash脚本的知识命中缓冲区的伪代码。我想下一步该怎么做:

  • 测试DEBUG.TXT,以上,以确保构建成功
  • 如果是这样叫我的最后的shell脚本

    moveapktodropbox $ 1

其中$ 1是我传递给当前shell脚本以提供APK在Dropbox中存储的名称的参数。

回答

3

随着POSIX每个程序应用的状态代码退出:装置成功警告,更错误

你可以测试,如果构建过程与退出状态代码0

buildprocess 
if [ $? -eq 0 ] ; then otherscript ; fi 

$?意味着最后状态代码

或更简洁:

buildprocess && otherscript 
+0

感谢你为这个 - 不是我最后还是没买,但它增加了无论如何,我的知识。 – DroidOS

0

我终于结束了做这个

x=$(grep -c "BUILD SUCCESSFUL" /path/to/my/app/debug.txt); 
if [ $x -eq 1 ]; then 
moveit $1; 
echo "Good Build"; 
exit; 
fi;