#!/bin/bash
# 2026-01-29 14:12 created by niujiuru

set -e
set -o pipefail

ver_num="1.0.0.1"
cur_dir="$(pwd)"
pre_dir="$(dirname "$cur_dir")"

pkgname="yfkj_ssh_client"
pkg_dir="${cur_dir}/${pkgname}"
pkg_tar="${cur_dir}/${pkgname}_${ver_num}.tar.gz"

rm -rf "${pkg_dir}" "${pkg_tar}"
mkdir -p "${pkg_dir}"

echo "1, Building ${pkgname}..."
cd ${pre_dir}
make -C "${pre_dir}" clean
make -C "${pre_dir}" yfkj_ssh_client.out yfkj_ssh_client.exe
cd ${cur_dir}
cp -rf "${pre_dir}/sshd/client/config.ini" "${pkg_dir}"
cp -rf "${pre_dir}/yfkj_ssh_client.out" "${pkg_dir}"
cp -rf "${pre_dir}/yfkj_ssh_client.exe" "${pkg_dir}"
make -C "${pre_dir}" clean

echo "2, Packaging into ${pkg_tar}..."
tar -czvf "${pkg_tar}" -C "${cur_dir}" "${pkg_dir##*/}"

# 清理临时目录
rm -rf "${pkg_dir}"

echo "✅ Package build completed successfully: ${pkg_tar}"
exit 0
