2
0

feat: support build deb

This commit is contained in:
zhangsz
2025-02-19 14:38:52 +08:00
parent b550614a4a
commit a208cc75d4
9 changed files with 63 additions and 131 deletions

8
.gitignore vendored
View File

@@ -86,4 +86,10 @@ yarn.lock
# release # release
release/debs/*.deb release/debs/*.deb
release/tars/*.tar.gz release/tars/*.tar.gz
release/src-tars/*.tar.gz release/src-tars/*.tar.gz
debbuild
!debbuild/DEBIAN/control
!debbuild/DEBIAN/postinst
!debbuild/DEBIAN/preinst
!debbuild/DEBIAN/postrm
!debbuild/DEBIAN/prerm

View File

@@ -12,6 +12,12 @@ BuildRootDir=${GitRootDir}/build.wfc
WFCWorkDir=/opt/wfc WFCWorkDir=/opt/wfc
BuildDockerDir=${BuildRootDir}/build/docker BuildDockerDir=${BuildRootDir}/build/docker
ReleseDir=${BuildRootDir}/release ReleseDir=${BuildRootDir}/release
SystemdDir=${BuildRootDir}/build/systemd/system
DebBuildDir=${BuildRootDir}/debbuild
DebReleseDir=${ReleseDir}/debs
DebSystemdDir=${DebBuildDir}/etc/systemd/system
TmpDir=${BuildRootDir}/tmp TmpDir=${BuildRootDir}/tmp
TmpEnvFile=${TmpDir}/.env.tmp TmpEnvFile=${TmpDir}/.env.tmp
@@ -58,9 +64,7 @@ pre-build-deb(){
if [ ! -d ${ReleseDir}/debs ]; then if [ ! -d ${ReleseDir}/debs ]; then
mkdir -p ${ReleseDir}/debs mkdir -p ${ReleseDir}/debs
fi fi
if [ -f ${BuildDockerDir}/.env ]; then # source ${BuildRootDir}/bin/control.sh
mv -f ${BuildDockerDir}/.env ${TmpEnvFile}
fi
} }
build-extras(){ build-extras(){
@@ -111,6 +115,20 @@ copy-file(){
cp -f ${BuildRootDir}/bin/printJarVer.class ${BuildRootDir}/build/bin/ cp -f ${BuildRootDir}/bin/printJarVer.class ${BuildRootDir}/build/bin/
} }
copy-file-debbuild(){
rm -rf ${DebBuildDir}/opt/wfc/*
cp -rf ${BuildRootDir}/build/bin/ ${DebBuildDir}/opt/wfc
cp -rf ${BuildRootDir}/build/docker/ ${DebBuildDir}/opt/wfc
cp -rf ${BuildRootDir}/build/systemd/ ${DebBuildDir}/opt/wfc
if [ -f ${DebBuildDir}/opt/wfc/docker/.env ]; then
rm ${DebBuildDir}/opt/wfc/docker/.env
fi
cp -rf ${SystemdDir}/* ${DebSystemdDir}/
chmod 755 ${DebBuildDir}/DEBIAN/preinst
chmod 755 ${DebBuildDir}/DEBIAN/postinst
chmod 755 ${DebBuildDir}/DEBIAN/postrm
}
# create tar package # create tar package
create-tar(){ create-tar(){
TarFileName=${ProjectL}-${RelVersion}-${RelDate}.tar.gz TarFileName=${ProjectL}-${RelVersion}-${RelDate}.tar.gz
@@ -162,7 +180,10 @@ create-src-tar(){
# create deb package # create deb package
create-deb(){ create-deb(){
echo -n "Begin build deb package ... " Version=$(grep '^Version:' ${DebBuildDir}/DEBIAN/control | awk '{print $2}')
DebPkgFile=${ProjectL}-${Version}-${RelDate}-ub22.deb
echo -n "Begin build deb package(${DebPkgFile}) ... "
dpkg -b ${DebBuildDir} ${DebReleseDir}/${DebPkgFile} 1>/dev/null
echo "done" echo "done"
} }
@@ -201,11 +222,12 @@ case "$1" in
if [ "$SKIP_PRE_GIT_PULL" = false ]; then if [ "$SKIP_PRE_GIT_PULL" = false ]; then
pre-git-pull pre-git-pull
fi fi
# pre-build-deb pre-build-deb
build-extras build-extras
build-jar build-jar
build-dist build-dist
copy-file copy-file
copy-file-debbuild
create-deb create-deb
# post-build # post-build
;; ;;
@@ -225,4 +247,4 @@ case "$1" in
*) *)
usage usage
;; ;;
esac esac

View File

@@ -31,7 +31,6 @@ conf_dirs=" ${docker_work_dir}/conf
${docker_work_dir}/wfc/modules/file/conf ${docker_work_dir}/wfc/modules/file/conf
${docker_work_dir}/wfc/modules/payment/conf ${docker_work_dir}/wfc/modules/payment/conf
" "
case "$1" in case "$1" in
env) env)
# prepare directory # prepare directory
@@ -42,9 +41,11 @@ case "$1" in
fi fi
# setup system serivce # setup system serivce
cp -rf ${src_service_dir}/wfccontrol.service ${dst_service_dir}/ if [ -f ${src_service_dir}/wfccontrol.service ]; then
systemctl daemon-reload cp -rf ${src_service_dir}/wfccontrol.service ${dst_service_dir}/
systemctl enable wfccontrol.service systemctl daemon-reload
systemctl enable wfccontrol.service
fi
if [ ! -f ${docker_work_dir}/docker-compose.yml ]; then if [ ! -f ${docker_work_dir}/docker-compose.yml ]; then
cp ${docker_work_dir}/compose/docker-compose.yml ${docker_work_dir}/docker-compose.yml cp ${docker_work_dir}/compose/docker-compose.yml ${docker_work_dir}/docker-compose.yml

View File

@@ -151,7 +151,7 @@ services:
- SPRING_CONFIG_ADDITIONAL_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/ - SPRING_CONFIG_ADDITIONAL_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/
- TZ=${TZ} - TZ=${TZ}
healthcheck: healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:${AUTH_SERVER_PORT}/actuator/health || exit 1"] test: ["CMD-SHELL", "curl -f http://localhost:${AUTH_SERVER_PORT}/actuator/health || exit 1"]
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 10 retries: 10

View File

@@ -1,8 +1,9 @@
Package: WFC Package: WFC
Version: 1.0.7-YYYYMMDD Version: 1.0.7
Section: WFC Section: WFC
Prioritt: optional Prioritt: optional
Architecture: amd64 Architecture: amd64
Maintainer: wfc Maintainer: wfc
Depends: Depends:
Description: WANFi Controller Description: WANFi Control and Billing System

92
debbuild/DEBIAN/postinst Normal file → Executable file
View File

@@ -1,94 +1,14 @@
# !/bin/bash # !/bin/bash
WFCRootDir=/opt/wfc wfc_root_dir=/opt/wfc
SystemdRootDir=/usr/lib/systemd/system systemd_dir=/etc/systemd/system
WFCEtcDir=${WFCRootDir}/etc fe_dist_dir=${wfc_root_dir}/opt/wfc/docker/nginx/html/dist
FERootDir=${WFCRootDir}/nginx/html/dist wfc_bin_dir=${wfc_root_dir}/bin
wfcBinDir=${WFCRootDir}/bin
UsrLocalBinDir=/usr/local/bin
wfcDaemon=wfcd
NginxEtcDir=/etc/nginx
NginxConfDir=${NginxEtcDir}/conf.d
CFileList="restconf.yaml crontask.yaml tasks.yaml sshsvc.yaml capconf.yaml wfc.conf"
LogoFileList="zh_brand.png zh_icon.png en_brand.png en_icon.png"
echo "" chmod +rx ${wfc_root_dir}/bin/*
echo "* To start/stop/restart/status wfc service, please run:"
echo " sudo systemctl start/stop/restart/status restagent.service"
echo " or run: "
echo " sudo /usr/local/wfc/bin/wfcsvc.sh start/stop/restart/status"
echo ""
chmod +rx ${WFCRootDir}/bin/*
chmod +rx ${WFCRootDir}/*
chmod +rx ${UsrLocalBinDir}/*
chmod -R 755 ${WFCRootDir}/htdocs/front
for CFile in ${CFileList}; do
if [ ! -e "${WFCEtcDir}/${CFile}" ]; then
cp -f ${WFCEtcDir}/default/${CFile} ${WFCEtcDir}
else
# mv -f ${WFCEtcDir}/${CFile} ${WFCEtcDir}/${CFile}.bak
# cp -f ${WFCEtcDir}/default/${CFile} ${WFCEtcDir}
if [ -e "${WFCBinDir}/upgconf.sh" ]; then
${WFCBinDir}/upgconf.sh
fi
fi
done
if [ ! -e "${FERootDir}/config.js" ]; then
cp ${FERootDir}/default/config.js ${FERootDir};
fi
for LogoFile in ${LogoFileList}; do
if [ ! -e "${WFCStaticDir}/logo/${LogoFile}" ]; then
cp ${WFCStaticDir}/wfc.d/logo/${LogoFile} ${WFCStaticDir}/logo;
fi
done
if ! id -u wfc >/dev/null 2>&1 ; then
useradd -d /opt/wfc -m -s /bin/bash -pwfc123 wfc;
mkdir -p /opt/wfc/ftp
else
echo "user wfc exist";
fi
if [ ! -e "${NginxConfDir}/wfc.conf" ]; then
mkdir -p ${NginxConfDir}
cp -f ${WFCEtcDir}/nginx/wfc.conf ${NginxConfDir};
fi
systemctl daemon-reload systemctl daemon-reload
systemctl enable wfccontrol.service
# disable auto upgrade
systemctl disable --now unattended-upgrades
systemctl enable restagent.service
systemctl enable crontask.service
systemctl enable sshsvc.service
systemctl enable captrace.service
systemctl daemon-reload
# read environment parameter and to do
if [ "$M_PARAM" = "install" -o "$M_PARAM" = "upgrade" ]; then
echo "M parameter: $M_PARAM"
if [ -n "$C_PARAM" ]; then
echo "C parameter: $C_PARAM"
${WFCRootDir}/bin/setwfc.sh -m $M_PARAM -c $C_PARAM
else
${WFCRootDir}/bin/setwfc.sh -m $M_PARAM
fi
# exit while failed to run setwfc.sh
if [ $? -ne 0 ]; then
echo "setwfc.sh execution failed. Exiting."
exit 1
fi
fi
echo -n "Starting WFC service ... "
systemctl start crontask.service
systemctl start sshsvc.service
systemctl start captrace.service
systemctl start restagent.service
echo "done"

21
debbuild/DEBIAN/postrm Normal file → Executable file
View File

@@ -1,23 +1,6 @@
# !/bin/bash # !/bin/bash
#rm -rf /usr/local/omc
rm -rf /etc/nginx/conf.d/omc.conf
rm -f /usr/local/bin/omcd
systemctl daemon-reload systemctl daemon-reload
# systemctl stop wfccontrol.service
systemctl disable wfccontrol.service
if systemctl list-units --type=service --all | grep -q 'restagent.service'; then
echo -n "Stopping OMC service ... "
systemctl stop restagent.service
systemctl stop crontask.service
systemctl stop sshsvc.service
systemctl stop captrace.service
echo "done"
fi
systemctl disable restagent.service
systemctl disable crontask.service
systemctl disable sshsvc.service
systemctl disable captrace.service
systemctl daemon-reload

16
debbuild/DEBIAN/preinst Normal file → Executable file
View File

@@ -1,16 +1,8 @@
# !/bin/bash # !/bin/bash
systemctl daemon-reload fe_dist_dir=/opt/wfc/docker/nginx/html/dist
if systemctl list-units --type=service --all | grep -q 'restagent.service'; then
echo -n "Stopping WFC service ... "
systemctl stop restagent.service
echo "done"
fi
FERootDir=/usr/local/omc/htdocs/front
# apt-get install zip
# clear front-end old hash js files # clear front-end old hash js files
rm -rf ${FERootDir}/assets rm -rf ${fe_dist_dir}/sys
rm -rf ${FERootDir}/js rm -rf ${fe_dist_dir}/u
rm -rf ${FERootDir}/index.*.js

7
debbuild/DEBIAN/prerm Executable file
View File

@@ -0,0 +1,7 @@
# !/bin/bash
wfc_bin_dir=/opt/wfc/bin
${wfc_bin_dir}/wfccontrol.sh stop
${wfc_bin_dir}/wfcsetup.sh rm all