#!/bin/bash base_path=$(pwd) build_path=${base_path}/build libraries_root="/opt/Libraries" server_location=/root/Server if command -v cmake >/dev/null 2>&1; then cmake_exe=cmake else cmake_exe=/opt/Qt/Tools/CMake/bin/cmake fi function cmake_scan() { if [ ! -d ${build_path} ]; then mkdir ${build_path} fi ${cmake_exe} -G Ninja -S ${base_path} -B ${build_path} \ -DCMAKE_BUILD_TYPE=Debug \ -DBOOST_ROOT=${libraries_root}/boost_1_86_0 } function build() { reset pkill -9 HttpServer cp -r /opt/Libraries/wt-4.11.0/share/Wt/* ./build if [ ! -f "${build_path}/CMakeCache.txt" ]; then cmake_scan fi if [ $? -ne 0 ]; then exit 1 fi ${cmake_exe} --build ${build_path} --target all if [ $? -ne 0 ]; then exit 1 fi cp WebApplication/blog.xml ./build/ mkdir -p ${build_path}/css; cp WebApplication/blog.css ./build/css/ cp WebApplication/rss.png ./build/css/ cp WebApplication/blogexample.css ./build/css/ cp WebApplication/asciidoc.css ./build/css/ build/UnitTest/UnitTest } function deploy() { build if [ $? -ne 0 ]; then echo "build backend failed ..." exit 1 fi rsync -azv build/Server/HttpServer Server/conf Server/lua root@amass.fun:${server_location} ssh root@amass.fun "pkill HttpServer; source /etc/profile && \ openresty -p ${server_location} -s reload && \ cd ${server_location}; \ nohup ./HttpServer >logs/HttpServer.log 2>&1 &" } function init() { scp -r /opt/Libraries/boost_1_85_0 root@amass.fun:/opt/Libraries/ } function build_docker_images(){ local DOCKERFILE=$1 echo "build $DOCKERFILE" if [[ $DOCKERFILE == *"act_runner.dockerfile" ]]; then ACT_RUNNER_VERSION=$(grep 'ENV ACT_VERSION' act_runner.dockerfile | awk '{print $3}') docker build --progress=plain -f $DOCKERFILE -t registry.cn-shenzhen.aliyuncs.com/amass_toolset/act_runner:$ACT_RUNNER_VERSION . docker push registry.cn-shenzhen.aliyuncs.com/amass_toolset/act_runner:$ACT_RUNNER_VERSION elif [[ $DOCKERFILE == *"nanopb.dockerfile" ]]; then docker build --progress=plain -f $DOCKERFILE -t registry.cn-shenzhen.aliyuncs.com/amass_toolset/nanopb:0.3.9.3 . docker push registry.cn-shenzhen.aliyuncs.com/amass_toolset/nanopb:0.3.9.3 elif [[ $DOCKERFILE == *"ubuntu2404.dockerfile" ]]; then docker build --progress=plain -f $DOCKERFILE -t registry.cn-shenzhen.aliyuncs.com/amass_toolset/ubuntu_dev:24.04 . docker push registry.cn-shenzhen.aliyuncs.com/amass_toolset/ubuntu_dev:24.04 elif [[ $DOCKERFILE == *"ubuntu2204.dockerfile" ]]; then docker build --progress=plain -f $DOCKERFILE -t registry.cn-shenzhen.aliyuncs.com/amass_toolset/ubuntu_dev:22.04 . docker push registry.cn-shenzhen.aliyuncs.com/amass_toolset/ubuntu_dev:22.04 elif [[ $DOCKERFILE == *"ubuntu1604.dockerfile" ]]; then docker build --progress=plain -f $DOCKERFILE -t registry.cn-shenzhen.aliyuncs.com/amass_toolset/ubuntu_dev:16.04 . docker push registry.cn-shenzhen.aliyuncs.com/amass_toolset/ubuntu_dev:16.04 elif [[ $DOCKERFILE == *"frpc.dockerfile" ]]; then FRP_VERSION=$(grep 'ENV FRP_VERSION' $DOCKERFILE | awk '{print $3}') docker build --progress=plain -f $DOCKERFILE -t registry.cn-shenzhen.aliyuncs.com/amass_toolset/frpc:$FRP_VERSION . docker push registry.cn-shenzhen.aliyuncs.com/amass_toolset/frpc:$FRP_VERSION elif [[ $DOCKERFILE == *"yoctools.dockerfile" ]]; then docker build --progress=plain -f $DOCKERFILE -t registry.cn-shenzhen.aliyuncs.com/amass_toolset/yoctools:22.04 . docker push registry.cn-shenzhen.aliyuncs.com/amass_toolset/yoctools:22.04 else echo "not found steps for build $DOCKERFILE ..." fi } function main() { local cmd=$1 shift 1 case $cmd in deploy) deploy ;; build) build ;; docker) build_docker_images ;; *) build ;; esac } main $@ # curl -k --insecure https://127.0.0.1/lua # openresty -p Server # sudo openresty -p Server -s reload # export LD_LIBRARY_PATH=/opt/Libraries/boost_1_85_0/lib:$LD_LIBRARY_PATH