FaceAccess/resources/build.sh
2024-09-04 17:57:23 +08:00

251 lines
11 KiB
Bash
Executable File

#!/bin/bash
cross_compile=true
build_hisi=false
debug_deploy=false
TARGET_IP="172.16.103.92"
TARGET_PATH="/system/bin"
base_path=$(pwd)
libraries_root="/opt/Libraries"
if [ $base_path==/home/* ]; then
build_path=${base_path}/build
else
build_path=/tmp/build
fi
echo "build directory: $build_path"
function cmake_scan() {
if [ $cross_compile = true ]; then
toolchain_file=-DCMAKE_TOOLCHAIN_FILE=resources/cmake/toolchain.cmake
else
toolchain_file="-DCROSS_BUILD=OFF"
fi
if [ ! -d ${build_path} ]; then
mkdir ${build_path}
fi
if [ $debug_deploy = true ]; then
build_debug=-DCMAKE_BUILD_TYPE=Debug
else
build_debug=""
fi
cmake \
-G Ninja \
-S ${base_path} \
-B ${build_path} \
$build_debug \
$toolchain_file
}
function qtmoc() {
MOC_EXE="docker run --rm -v $(pwd):$(pwd) -w $(pwd) frp-by1.wwvvww.cn:45288/ubuntu_dev:16.04 moc"
declare -a files=(
"src/qt/mainUi/mainUi.h:src/qt/mainUi/moc_mainUi.cpp"
"src/qt/utility/UiTools.h:src/qt/utility/moc_UiTools.cpp"
"src/qt/recoUi/recoUi.h:src/qt/recoUi/moc_recoUi.cpp"
"src/qt/recoUi/recoUiRecognize.h:src/qt/recoUi/moc_recoUiRecognize.cpp"
"src/qt/recoUi/recoUiRecognizeTypeBase.h:src/qt/recoUi/moc_recoUiRecognizeTypeBase.cpp"
"src/qt/recoUi/recoUiCallConsole.h:src/qt/recoUi/moc_recoUiCallConsole.cpp"
"src/qt/recoUi/recoUiCallDial.h:src/qt/recoUi/moc_recoUiCallDial.cpp"
"src/qt/utility/DndModeCountDownItem.h:src/qt/utility/moc_DndModeCountDownItem.cpp"
"src/qt/mainUi/UvcView.h:src/qt/mainUi/moc_UvcView.cpp"
)
for file in "${files[@]}"; do
IFS=":" read -r input output <<<"$file"
if [[ -f $input ]]; then
echo "Processing $input..."
$MOC_EXE "$input" -o "$output"
else
echo "Warning: $input does not exist. Skipping..."
fi
done
}
function build() {
if [ ! -f "${build_path}/CMakeCache.txt" ]; then
cmake_scan
fi
if [ $? -ne 0 ]; then
exit 1
fi
cmake \
--build ${build_path} \
--target all
if [ $? -ne 0 ]; then
exit 1
fi
if [ $cross_compile = true ]; then
deploy
fi
}
function deploy() {
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/system/lib
if [ -n "$1" ]; then
TARGET_IP=$1
fi
if [ $debug_deploy = true ]; then
TARGET_PATH="/data/sdcard"
fi
echo "deploy to target $TARGET_IP, path: ${TARGET_PATH} ..."
ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "mount -o remount rw /system/; mount -o remount rw /"
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "killall start-app.sh; pgrep -f GateFace | xargs kill -s 9"
ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "pgrep -f VoucherVerifyServer | xargs kill -s 9"
ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "pgrep -f Record | xargs kill -s 9"
scp -i resources/ssh_host_rsa_key_ok ${build_path}/Record/Record root@${TARGET_IP}:/sdcard/
ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "sync"
# ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "echo 116 > /sys/class/gpio/export"
# ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "echo out > /sys/class/gpio/gpio116/direction"
# ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "echo 1 > /sys/class/gpio/gpio116/value"
if [ $debug_deploy != true ]; then
echo "reboot remote device."
ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "reboot"
fi
}
function clean() {
if [ -d ${build_path} ]; then
rm -fr ${build_path}
fi
}
function copy_ssh() {
if [ -n "$1" ]; then
TARGET_IP=$1
fi
SSH_KEY=$(cat ~/.ssh/id_rsa.pub)
echo "ssh copy id to ${TARGET_IP} ..."
# chmod 600 ./resources/ssh_host_rsa_key_ok
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "mount -o remount rw /system/; mount -o remount rw /"
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "if [ ! -f /usr/bin/scp ]; then cp /oem/bin/scp /usr/bin/; else echo 'scp exist'; fi"
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "echo ${SSH_KEY} >> /oem/.ssh/authorized_keys"
scp -i ~/Projects/ssh_host_rsa_key_ok /mnt/e/Documents/gdb-rk root@${TARGET_IP}:/sdcard/gdb
scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-linux-gnueabihf/mpp/rk-libs/libeasymedia.so.1.0.1 root@${TARGET_IP}:/usr/lib/
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/toolchains/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/bin/gdbserver root@${TARGET_IP}:/sdcard
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_url* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_log* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_program_options* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_date_time* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_filesystem* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_thread* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_regex* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_chrono* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_atomic* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_container* root@${TARGET_IP}:/system/lib
scp -i ~/Projects/ssh_host_rsa_key_ok /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/lib/boost_1_84_0/lib/libboost_json* root@${TARGET_IP}:/system/lib
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "sync"
}
function build_old() {
# start-app.sh 以下就可以让应用不开机自启
# d_state=0
# l_state=0
# n_state=1
# i_state=1
if [ -n "$1" ]; then
TARGET_IP=$1
fi
if [ $debug_deploy = true ]; then
TARGET_PATH="/data/sdcard"
fi
qtmoc
# if [ $? -ne 0 ]; then
# exit 1
# fi
if [ $build_hisi = true ]; then
docker run -it --rm --user 1000:1000 -v /opt:/opt -v $(pwd):$(pwd) -w $(pwd) frp-by1.wwvvww.cn:45288/nanopb:0.3.9.3 make server_protocol
docker run -it --rm --user 1000:1000 -v /opt:/opt -v $(pwd):$(pwd) -w $(pwd) frp-by1.wwvvww.cn:45288/nanopb:0.3.9.3 make -j4
else
docker run -it --rm --user 1000:1000 -v /opt:/opt -v $(pwd):$(pwd) -w $(pwd) -e PATH="/opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin:$PATH" frp-by1.wwvvww.cn:45288/nanopb:0.3.9.3 make PLATFORM=rv1109 server_protocol
make PLATFORM=rv1109 -j4
fi
if [ $? -ne 0 ]; then
exit 1
fi
deploy_old $TARGET_IP
# deploy_old "172.16.103.98"
# deploy_old "172.16.103.117"
}
function deploy_old() {
# killall start-app.sh; ps | grep GateFace | grep -v "grep" | awk '{print $1}' | xargs kill -s 9
if [ -n "$1" ]; then
TARGET_IP=$1
fi
echo "deply to $TARGET_IP, path $TARGET_PATH"
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "mount -o remount rw /; mount -o remount rw /system/"
if [ $build_hisi = true ]; then
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "killall start-app.sh; killall GateFace; sleep 1"
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "killall start-app.sh; killall GateFace"
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "killall start-app.sh; killall GateFace"
else
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "killall start-app.sh; killall GateFace;"
fi
# scp -r -i ~/Projects/ssh_host_rsa_key_ok src/web/php/*.php root@${TARGET_IP}:/system/www/web/
# scp -r -i ~/Projects/ssh_host_rsa_key_ok resources/audio/*.wav root@${TARGET_IP}:/system/audio
scp -i ~/Projects/ssh_host_rsa_key_ok ./build/GateFace root@${TARGET_IP}:$TARGET_PATH
# scp -i ~/Projects/ssh_host_rsa_key_ok resources/language/FaceTick_EN.qm root@${TARGET_IP}:/system/language
# scp -i ~/Projects/ssh_host_rsa_key_ok ./build/netconfig root@${TARGET_IP}:$TARGET_PATH
if [ $build_hisi = true ]; then
scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-himix200-linux/rwStageProtocol/lib/librwSrvProtocol.so root@${TARGET_IP}:/system/lib/
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "reboot"
else
# scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-linux-gnueabihf/librwhscheckpw/lib/librwhscheckpw.so root@${TARGET_IP}:/system/lib/
scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-linux-gnueabihf/rwStageProtocol/lib/librwSrvProtocol.so root@${TARGET_IP}:/system/lib/
# scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-linux-gnueabihf/ffmepg/lib/libavdevice.so.58 root@${TARGET_IP}:/system/lib/
# scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-linux-gnueabihf/ffmepg/lib/libavfilter.so.7 root@${TARGET_IP}:/system/lib/
# scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-linux-gnueabihf/ffmepg/lib/libavformat.so.58 root@${TARGET_IP}:/system/lib/
# scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-linux-gnueabihf/ffmepg/lib/libavutil.so.56 root@${TARGET_IP}:/system/lib/
# scp -i ~/Projects/ssh_host_rsa_key_ok ./3rdparty/arm-linux-gnueabihf/ffmepg/lib/libswresample.so.3 root@${TARGET_IP}:/system/lib/
fi
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "sync"
if [ $debug_deploy = false ]; then
if [ $build_hisi = false ]; then
ssh -i ~/Projects/ssh_host_rsa_key_ok root@${TARGET_IP} "echo 1 > /dev/watchdog"
fi
fi
}
function main() {
local cmd=$1
shift 1
case $cmd in
build)
build
;;
scan)
cmake_scan
;;
clean)
clean
;;
old)
build_old $@
;;
ssh)
copy_ssh $@
;;
*)
build
;;
esac
}
main $@