summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author崔一鸣 <[email protected]>2018-12-10 18:49:30 +0800
committer崔一鸣 <[email protected]>2018-12-10 18:49:30 +0800
commitb16f3c0a0f9775a36daf34b1e7feb4089000083e (patch)
tree217bb692cee8bf3759ab65316e67a3ec73210b62
parent1e16fbaf51236ffcb6b0ed5e272c28c3ea8cb0e2 (diff)
添加打包脚本
-rwxr-xr-xscript/rpm_build/build_rpm.sh26
-rw-r--r--script/rpm_build/mgw.spec46
-rw-r--r--script/systemd/mgw.service4
-rw-r--r--script/systemd/mgw.sh19
4 files changed, 84 insertions, 11 deletions
diff --git a/script/rpm_build/build_rpm.sh b/script/rpm_build/build_rpm.sh
new file mode 100755
index 0000000..35ded6c
--- /dev/null
+++ b/script/rpm_build/build_rpm.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+#init
+VERSION=$1
+if [ "${VERSION}" = "" ]; then
+echo "USAGE: ./build_rpm.sh 1.0.0" && exit 0
+fi
+TAR_NAME="mgw-${VERSION}.tar.gz"
+[ ! -f ${TAR_NAME} ] && echo "${TAR_NAME} not existed, exit" && exit 0
+rm -rf ~/rpmbuild/BUILD mkdir ~/rpmbuild/BUILD
+rm -rf ~/rpmbuild/BUILDROOT mkdir ~/rpmbuild/BUILDROOT
+rm -rf ~/rpmbuild/RPMS && mkdir ~/rpmbuild/RPMS
+rm -rf ~/rpmbuild/SOURCES && mkdir ~/rpmbuild/SOURCES
+rm -rf ~/rpmbuild/SPECS && mkdir ~/rpmbuild/SPECS
+rm -rf ~/rpmbuild/SRPMS && mkdir ~/rpmbuild/SRPMS
+cp ${TAR_NAME} ~/rpmbuild/SOURCES
+
+#rpmbuild
+cp ${TAR_NAME} ~/rpmbuild/SOURCES
+cp ./mgw.spec ~/rpmbuild/SPECS
+sed -i "s/\$VERSION/${VERSION}/g" ~/rpmbuild/SPECS/mgw.spec
+sed -i "s/\$TAR_NAME/${TAR_NAME}/g" ~/rpmbuild/SPECS/mgw.spec
+rpmbuild -ba ~/rpmbuild/SPECS/mgw.spec
+
+#cp rpm
+cp -rf ~/rpmbuild/RPMS ./
diff --git a/script/rpm_build/mgw.spec b/script/rpm_build/mgw.spec
new file mode 100644
index 0000000..555ee42
--- /dev/null
+++ b/script/rpm_build/mgw.spec
@@ -0,0 +1,46 @@
+Name: mgw
+Version: $VERSION
+Release: 1%{?dist}
+Summary: matrix gateway
+
+License: GPL
+Source0: $TAR_NAME
+
+
+%description
+matrix gateway for IPREUSE
+
+%prep
+%setup -q
+
+
+%build
+mkdir build && cd build
+cmake -DCMAKE_BUILD_TYPE=Debug ../
+make
+
+%install
+rm -rf /opt/mgw && mkdir /opt/mgw
+mkdir -p %{buildroot}/opt/mgw/script
+cp ./README.md %{buildroot}/opt/mgw
+cp -f ./build/access/mgw %{buildroot}/opt/mgw
+cp -rf ./conf/ %{buildroot}/opt/mgw
+cp -rf ./script/systemd %{buildroot}/opt/mgw/script
+
+%files
+/opt/mgw/*
+
+%post
+cp -f /opt/mgw/script/systemd/mgw.service /etc/systemd/system/mgw.service
+systemctl daemon-reload
+systemctl enable mgw.service
+
+%postun
+rm /etc/systemd/system/mgw.service
+systemctl daemon-reload
+
+%clean
+rm -rf $RPM_BUILD_DIR/*
+rm -rf %{buildroot}/../*
+%changelog
+
diff --git a/script/systemd/mgw.service b/script/systemd/mgw.service
index 398d93c..4a19563 100644
--- a/script/systemd/mgw.service
+++ b/script/systemd/mgw.service
@@ -1,6 +1,6 @@
[Service]
-ExecStart=/opt/mgw/script/mgw.sh start
-ExecStop=/opt/mgw/script/mgw.sh stop
+ExecStart=/bin/bash /opt/mgw/script/systemd/mgw.sh start
+ExecStop=/bin/bash /opt/mgw/script/systemd/mgw.sh stop
Restart=always
[Install]
WantedBy=default.target
diff --git a/script/systemd/mgw.sh b/script/systemd/mgw.sh
index d3234f5..b0e864a 100644
--- a/script/systemd/mgw.sh
+++ b/script/systemd/mgw.sh
@@ -34,15 +34,15 @@ start_mgw() {
[[ ${status} -eq 1 ]] && exit_msg "mgw is running"
#set tap/tun
- ip addr add ${TAP_ADDR} dev ${TAP_NAME} && \
- ip tuntap add dev ${TUN_NAME} mode tun && \
- ifconfig ${TUN_NAME} up && \
- ip rule add iif ${TAP_NAME} tab 100 && \
- ip route add default dev ${TUN_NAME} table 100 && \
- echo 1 > /proc/sys/net/ipv4/ip_forward && \
- echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter && \
+ ip addr add ${TAP_ADDR} dev ${TAP_NAME}
+ ip tuntap add dev ${TUN_NAME} mode tun
+ ifconfig ${TUN_NAME} up
+ ip rule add iif ${TAP_NAME} tab 100
+ ip route add default dev ${TUN_NAME} table 100
+ echo 1 > /proc/sys/net/ipv4/ip_forward
+ echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
sysctl -w net.ipv4.conf.default.rp_filter=0 >> /dev/null
- [[ $? -ne 0 ]] && exit_msg "failed at setup tap/tun"
+ #[[ $? -ne 0 ]] && exit_msg "failed at setup tap/tun"
#start mgw
[ ! -f "${ROOT_DIR}/mgw" ] && exit_msg "${ROOT_DIR}/mgw not existed"
@@ -58,7 +58,7 @@ start_mgw() {
stop_mgw
exit_msg "mgw has stopped"
fi
- sleep 5
+ sleep 3
done
}
@@ -73,6 +73,7 @@ check_mgw(){
stop_mgw() {
[ -f ${PID_FILE} ] && ps -hp $(cat ${PID_FILE}) >> /dev/null && kill -9 $(cat ${PID_FILE})
+ rm -f ${PID_FILE}
#unset tap/tun
ip addr del ${TAP_ADDR} dev ${TAP_NAME} >> /dev/null 2>&1
ip rule del iif ${TAP_NAME} tab 100 >> /dev/null 2>&1