Linux shell脚本中的条件执行命令
我使用Cordova CLI在我的Ubuntu 16.04 VPS服务器上创建Android APK。一旦建立了APK,我将其复制到本地机器上的Dropbox,然后在我的Android测试设备上安装APK。我想使用Dropbox API直接上传APK,以避免不必要的3路传输:Linux shell脚本中的条件执行命令,linux,bash,ubuntu,Linux,Bash,Ubuntu,我使用Cordova CLI在我的Ubuntu 16.04 VPS服务器上创建Android APK。一旦建立了APK,我将其复制到本地机器上的Dropbox,然后在我的Android测试设备上安装APK。我想使用Dropbox API直接上传APK,以避免不必要的3路传输: Server -> Local Machine -> Dropbox -> Android test device. 操作的顺序是这样的 服务器上的Shell脚本(已经编写)清理Android源代码并
Server -> Local Machine -> Dropbox -> Android test device.
操作的顺序是这样的
- 服务器上的Shell脚本(已经编写)清理Android源代码并重建APK
- 这是通过Phonegap/Cordova详细输出完成的,该输出确保成功的构建在最后发出以下文本
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'
最后一步-只有在Cordova/Phonegap调试输出中发现构建成功时,才能将android apk上传到我的Dropbox。我已经把所有的东西都准备好了,但是我不确定我应该如何检查构建是否成功
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'
下面是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脚本的了解的缓冲区。我接下来想做什么:
- Test debug.txt,以确保生成成功
- 如果是这样,请调用我的最终shell脚本
moveapktodropbox$1!# /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
其中$1是我传递给当前shell脚本的参数,以提供APK在Dropbox中存储时所使用的名称。使用POSIX,每个程序退出时都应该有一个状态代码:0表示成功,1警告,2和更多错误 您可以测试进程生成是否以状态代码0退出
buildprocess
if [ $? -eq 0 ] ; then otherscript ; fi
$?表示最后一个状态代码
或者更简洁地说:
buildprocess && otherscript
我最终还是这样做了
x=$(grep -c "BUILD SUCCESSFUL" /path/to/my/app/debug.txt);
if [ $x -eq 1 ]; then
moveit $1;
echo "Good Build";
exit;
fi;
谢谢你,这不是我最后所做的,但它增加了我的知识。