Add packaging files
[src/xds/xds-agent.git] / conf.d / packaging / rpm / agl-xds-agent.spec
diff --git a/conf.d/packaging/rpm/agl-xds-agent.spec b/conf.d/packaging/rpm/agl-xds-agent.spec
new file mode 100644 (file)
index 0000000..b6e3fff
--- /dev/null
@@ -0,0 +1,81 @@
+#
+# spec file for package agl-xds-agent
+#
+
+%define _prefix /opt/AGL
+%global debug_package %{nil}
+
+Name:           agl-xds-agent
+Version:        1.1.1
+Release:        0
+License:        Apache-2.0
+Summary:        XDS agent/client tool
+Url:            https://github.com/iotbzh/xds-agent.git
+Source0:        xds-agent_linux-amd64-v%{version}_2018-04-05_112625.zip
+BuildRequires:  unzip
+BuildRoot:      %{_tmppath}/%{name}-%{version}-build
+
+# currently embedded with xds
+# Requires:       syncthing
+
+
+%description
+XDS-agent is an client tool that must run on your local machine when you use XDS
+
+%prep
+%setup -q -n xds-agent
+
+%build
+
+%install
+mkdir -p %{?buildroot}%{_prefix}/xds/agent %{?buildroot}%{_bindir}
+cp -r * %{?buildroot}%{_prefix}/xds/agent
+rm -rf %{?buildroot}%{_prefix}/xds/agent/conf.d
+ln -s ../xds/agent/xds-agent %{?buildroot}%{_bindir}/xds-agent
+
+mkdir -p %{?buildroot}%{_userunitdir}
+cp ./conf.d/usr/lib/systemd/user/xds-agent.service %{?buildroot}%{_userunitdir}
+
+mkdir -p %{?buildroot}/%{_sysconfdir}/default
+cp ./conf.d/etc/default/xds-agent %{?buildroot}/%{_sysconfdir}/default/
+
+mkdir -p %{?buildroot}/%{_sysconfdir}/xds/agent
+cp ./conf.d/etc/xds/agent/* %{?buildroot}/%{_sysconfdir}/xds/agent/
+
+mkdir -p %{?buildroot}%{_userunitdir}/default.target.wants && ln -s ../xds-agent.service %{?buildroot}%{_userunitdir}/default.target.wants/
+
+mkdir -p %{?buildroot}%{_sysconfdir}/profile.d
+sed -e "s;@XDS_INSTALL_BIN_DIR@;%{_bindir};g" ./conf.d/etc/profile.d/xds-agent.sh > %{buildroot}%{_sysconfdir}/profile.d/%{name}.sh
+
+
+%files
+%defattr(-,root,root)
+%dir %{_prefix}
+%dir %{_bindir}
+%dir %{_prefix}/xds
+%dir %{_prefix}/xds/agent
+%{_prefix}/xds/agent/*
+%{_bindir}/xds-agent
+%dir %{_sysconfdir}/xds
+%dir %{_sysconfdir}/xds/agent
+%config %{_sysconfdir}/default/xds-agent
+%config %{_sysconfdir}/xds/agent/agent-config.json
+%config %{_sysconfdir}/profile.d/%{name}.sh
+%dir %{_userunitdir}
+%{_userunitdir}/xds-agent.service
+%dir %{_userunitdir}/default.target.wants
+%{_userunitdir}/default.target.wants/xds-agent.service
+
+%post
+if [ "$1" -ge 2 ]; then
+  if [ -f "${_sysconfdir}/xds-agent/config.json" ]; then
+    install -b -S .rpmsave ${_sysconfdir}/xds-agent/config.json ${_sysconfdir}/xds/agent/agent-config.json
+  fi
+fi
+exit 0
+
+%preun
+if [ "$1" -ge 2 ]; then
+  rm -f %{_sysconfdir}/xds-agent/*.rpm*
+fi
+exit 0