写一个shell脚本,连接手机,定义一个path,把.so文件push进去,再重启
时间: 2024-04-11 09:25:55 浏览: 79
你可以使用以下的shell脚本来连接手机、定义路径、将.so文件push到手机并重启:
```bash
#!/bin/bash
# 连接手机
adb connect <手机IP地址>:5555
# 定义路径
path="/sdcard/your/path"
# push .so文件到手机
adb push yourfile.so $path
# 重启手机
adb reboot
```
请将 `<手机IP地址>` 替换为你手机的实际IP地址,并将 `yourfile.so` 替换为你要push的.so文件的实际文件名。记得给脚本执行权限,然后运行它即可。
相关问题
#!/bin/bash # Assets TEST_IMG=demo.png SDK_ROOT=$PWD TEST_ROOT=$PWD BIN_NAME=test_demo DEVICE_TEST_PATH=/data/local/tmp/ts_ai_sdk_test MODEL_PATH=/sdcard/models RUSULT=/data/local/tmp/ts_ai_sdk_test/results/ RUNTIME=DSP adb root # Push test assets adb shell rm -rf $DEVICE_TEST_PATH # adb shell rm -rf $MODEL_PATH adb shell mkdir -p $DEVICE_TEST_PATH/jpgs adb shell mkdir -p $DEVICE_TEST_PATH/results/post_result adb shell mkdir -p $DEVICE_TEST_PATH/results/img_result #adb shell mkdir -p $MODEL_PATH adb push images/* $DEVICE_TEST_PATH/jpgs # Push SNPE libraries adb push ${SDK_ROOT}/libs/ $DEVICE_TEST_PATH adb push ${SDK_ROOT}/models/model.exf $DEVICE_TEST_PATH/ # Push executable adb push build/$BIN_NAME $DEVICE_TEST_PATH # Test adb shell "chmod +x $DEVICE_TEST_PATH/$BIN_NAME" echo "Running on Android device ..." echo "LD_LIBRARY_PATH='$DEVICE_TEST_PATH/libs' $DEVICE_TEST_PATH/$BIN_NAME $DEVICE_TEST_PATH/jpgs $RUSULT $DEVICE_TEST_PATH/model.exf" echo "Done." adb shell "LD_LIBRARY_PATH='$DEVICE_TEST_PATH/libs' $DEVICE_TEST_PATH/$BIN_NAME $DEVICE_TEST_PATH/jpgs $RUSULT $DEVICE_TEST_PATH/model.exf" # Pull result adb pull $DEVICE_TEST_PATH/results/ . sleep 1改为bat脚本
将该脚本转换为 Windows 的 batch 脚本,需要进行以下修改:
1. 更改第一行为 `@echo off`,表示关闭命令回显。
2. 将变量的赋值方式从 `$变量名=值` 改为 `set 变量名=值`。
3. 将 `adb` 命令行中的路径分隔符 `/` 改为 Windows 下的路径分隔符 `\`。
4. 在执行命令行时需要使用 `call` 命令。
修改后的 batch 脚本如下:
```
@echo off
REM Assets
set TEST_IMG=demo.png
set SDK_ROOT=%cd%
set TEST_ROOT=%cd%
set BIN_NAME=test_demo
set DEVICE_TEST_PATH=/data/local/tmp/ts_ai_sdk_test
set MODEL_PATH=/sdcard/models
set RESULT=/data/local/tmp/ts_ai_sdk_test/results/
set RUNTIME=DSP
REM Push test assets
adb root
adb shell rm -rf %DEVICE_TEST_PATH%
adb shell mkdir -p %DEVICE_TEST_PATH%/jpgs
adb shell mkdir -p %DEVICE_TEST_PATH%/results/post_result
adb shell mkdir -p %DEVICE_TEST_PATH%/results/img_result
adb push images\* %DEVICE_TEST_PATH%/jpgs
REM Push SNPE libraries
adb push %SDK_ROOT%\libs\ %DEVICE_TEST_PATH%
adb push %SDK_ROOT%\models\model.exf %DEVICE_TEST_PATH%\
REM Push executable
adb push build\%BIN_NAME% %DEVICE_TEST_PATH%\
REM Test
adb shell "chmod +x %DEVICE_TEST_PATH%\%BIN_NAME%"
echo Running on Android device ...
echo "LD_LIBRARY_PATH='%DEVICE_TEST_PATH%\libs' %DEVICE_TEST_PATH%\%BIN_NAME% %DEVICE_TEST_PATH%/jpgs %RESULT% %DEVICE_TEST_PATH%/model.exf"
echo Done.
call adb shell "LD_LIBRARY_PATH='%DEVICE_TEST_PATH%\libs' %DEVICE_TEST_PATH%\%BIN_NAME% %DEVICE_TEST_PATH%/jpgs %RESULT% %DEVICE_TEST_PATH%\model.exf"
REM Pull result
adb pull %DEVICE_TEST_PATH%/results/ .
timeout /t 1
```
开发者通常会利用Jenkins来创建一个完整的流水线,从源码到构建镜像再到推送镜像到仓库。写一个shell脚本命令
创建一个Jenkins流水线脚本,通常涉及到使用`jenkinsfile`或者`.groovy`(Groovy DSL)语法。下面是一个基本的示例,展示了一个从源码到构建镜像再到推送镜像的过程,假设我们使用Docker:
```groovy
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git url: 'https://github.com/your-repo.git'
}
}
stage('Build') {
steps {
sh 'docker build -t your-image-name .'
}
}
stage('Test') {
steps {
sh 'docker run --rm your-image-name /path/to/test/script'
// 添加测试逻辑...
}
}
stage('Push Image') {
steps {
script {
if (env.BUILD_NUMBER) { // 如果这是持续集成环境
docker.withRegistry('https://your-docker-registry.com', 'your-username', 'your-password') { // 登录到私有仓库
dockerImage = docker.build('your-image-name')
dockerImage.push()
}
} else {
echo 'Not pushing to registry in a manual run.'
}
}
}
}
}
}
```
在这个例子中,`agent any`表示可以在任何节点上运行,`stages`部分定义了四个阶段:`Checkout`拉取源码,`Build`构建镜像,`Test`运行测试,最后`Push Image`将镜像推送到私有仓库。
阅读全文