#!/bin/bash cross_compile=true TARGET_IP="192.168.8.115" TARGET_PATH="/data/sdcard/PassengerStatistics" 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/toolchain.cmake else toolchain_file="-DCROSS_BUILD=OFF" fi if [ ! -d ${build_path} ]; then mkdir ${build_path} fi cmake \ -G Ninja \ -S ${base_path} \ -B ${build_path} \ $toolchain_file \ -DCMAKE_BUILD_TYPE=Debug } 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 init() { if [ -n "$1" ]; then TARGET_IP=$1 fi echo "deploy libs to target $TARGET_IP..." BOOST_LIBDIR=/opt/aarch64-v01c01-linux-gnu-gcc/lib/boost_1_84_0/lib chmod 600 resources/ssh_host_rsa_key_ok ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "mount -o remount rw /;mount -o remount rw /system/" echo "put ${base_path}/resources/authorized_keys /system/.ssh" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} echo "put /opt/aarch64-v01c01-linux-gnu-gcc/lib/gdb-10.2/bin/gdbserver /system/bin" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_date_time* /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_regex* /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_log_setup.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_log.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_chrono.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_filesystem.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_atomic.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_container.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_thread.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_url.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_json.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} # echo "put ${BOOST_LIBDIR}/libboost_program_options.so.1.84.0 /system/lib" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "echo 'mount -o remount rw /' >> /etc/profile" ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "echo 'mount -o remount rw /system/' >> /etc/profile" ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "echo 'export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/system/lib' >> /etc/profile" } function deploy() { if [ -n "$1" ]; then TARGET_IP=$1 fi echo "deploy to target $TARGET_IP, path: ${TARGET_PATH} ..." echo "put ${build_path}/Main/PassengerStatistics ${TARGET_PATH}" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} echo "put ${build_path}/Tools/VideoRecoder/VideoRecoder ${TARGET_PATH}" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} ssh -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} "sync" } function clean() { if [ -d ${build_path} ]; then rm -fr ${build_path} fi } function main() { local cmd=$1 shift 1 case $cmd in build) build ;; scan) cmake_scan ;; clean) clean ;; deploy) deploy $@ ;; init) init $@ ;; *) build ;; esac } main $@