Add build script for generating packages

This adds a build script using make and removes the shell script that
was in place. It can generate deb packages and rpm packages. Versioning
is controlled in the top of the make file by setting the proper
variables. RHEL 7 and RHEL 8 use different spec files due to the
different naming conventions of the packages in the major releases. A
supported install and remove method are also provided.

Signed-off-by: Justin Thaler <thalerj@us.ibm.com>
Change-Id: I031d3e6af4ced0ef8281124f6e89401a7291e141
diff --git a/thalerj/build-scripts/Makefile b/thalerj/build-scripts/Makefile
new file mode 100755
index 0000000..5277a82
--- /dev/null
+++ b/thalerj/build-scripts/Makefile
@@ -0,0 +1,63 @@
+#Makefile for openbmctool
+# Copyright (c) 2017 International Business Machines.
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#        http://www.apache.org/licenses/LICENSE-2.0
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+
+VER=1.18
+REL=1
+ARCH=noarch
+PROD=openbmctool
+RHEL_VER=7
+NAME=$(PROD)-$(VER)-$(REL).$(ARCH)
+
+# Need to test RPMDIR to see if it is set. Otherwise set it.
+RPMDIR := $(if $(RPMDIR),$(RPMDIR),$(shell pwd)/build/rpm)
+
+# Need to test DEBDIR to see if it is set. Otherwise set it.
+DEBDIR := $(if $(DEBDIR),$(DEBDIR),$(shell pwd)/build/deb)
+
+default: 
+	mkdir -p ./build
+clean: ;rm -rf ./build
+remove: 
+	rm -f /usr/bin/openbmctool
+	rm -f /opt/ibm/ras/bin/openbmctool.py
+	rm -f /opt/ibm/ras/lib/policyTable.json
+install: 
+	cp ../openbmctool.py $(DESTDIR)/opt/ibm/ras/bin
+	cp ../policyTable.json $(DESTDIR)/opt/ibm/ras/lib
+	ln -s -f $(DESTDIR)/opt/ibm/ras/bin/openbmctool.py $(DESTDIR)/usr/bin/openbmctool
+
+rpm: default
+	rm -rf $(RPMDIR)
+	mkdir -p $(RPMDIR)
+	mkdir -p $(RPMDIR)/openbmctool
+	for i in BUILD BUILDROOT RPMS SOURCES SPECS SRPMS; do mkdir -p $(RPMDIR)/$$i; done
+	cp openbmctool-rhel$(RHEL_VER).spec $(RPMDIR)/SPECS
+	cp ../openbmctool.py ../policyTable.json $(RPMDIR)/openbmctool/
+	tar -cvzf $(RPMDIR)/SOURCES/openbmctool-$(VER)-$(REL).tgz -C $(RPMDIR) openbmctool
+	rpmbuild --define '_topdir $(RPMDIR)' --define "_version $(VER)" --define "_release $(REL)" -bb $(RPMDIR)/SPECS/openbmctool-rhel$(RHEL_VER).spec
+
+deb: default
+	rm -rf $(DEBDIR)
+	mkdir -p $(DEBDIR)
+	for i in bin lib; do mkdir -p $(DEBDIR)/opt/ibm/ras/$$i; done
+	mkdir -p $(DEBDIR)/usr/bin/
+	make install DESTDIR=$(DEBDIR)
+	mkdir -p $(DEBDIR)/DEBIAN
+	cp control $(DEBDIR)/DEBIAN
+	cd $(DEBDIR); find opt -type f -exec md5sum "{}" + >> DEBIAN/md5sums
+	cd $(DEBDIR); find usr -type f -exec md5sum "{}" + >> DEBIAN/md5sums
+	cd $(DEBDIR); echo "#!/bin/bash" >> DEBIAN/postinst
+	cd $(DEBDIR); echo "ln -s -f /opt/ibm/ras/bin/openbmctool.py /usr/bin/openbmctool" >> DEBIAN/postinst
+	chmod +x $(DEBDIR)/DEBIAN/postinst
+	chmod +x $(DEBDIR)/opt/ibm/ras/bin/openbmctool.py
+	dpkg-deb -b $(DEBDIR) $(DEBDIR)/DEBIAN/openbmctool-$(VER).$(REL)-$(ARCH).deb
+
diff --git a/thalerj/build-scripts/control b/thalerj/build-scripts/control
new file mode 100755
index 0000000..dec38f5
--- /dev/null
+++ b/thalerj/build-scripts/control
@@ -0,0 +1,13 @@
+Package: openbmctool
+Provides: openbmctool
+Version: 1.18.1
+License: Apache 2.0
+Vendor: IBM
+Architecture: all
+Maintainer: IBM
+Installed-Size: 1285
+Section: System Environment/Base
+Priority: extra
+Homepage: http://ibm.com
+Description: A tool based on ipmitool for interacting with OpenBMC via it's REST API
+Depends: python3, python3-requests, python3-simplejson
diff --git a/thalerj/build-scripts/openbmctool-rhel7.spec b/thalerj/build-scripts/openbmctool-rhel7.spec
new file mode 100644
index 0000000..7769223
--- /dev/null
+++ b/thalerj/build-scripts/openbmctool-rhel7.spec
@@ -0,0 +1,46 @@
+# Copyright (c) 2017 International Business Machines.  All right reserved.
+%define _binaries_in_noarch_packages_terminate_build   0
+Summary: IBM OpenBMC tool
+Name: openbmctool
+Version: %{_version}
+Release: %{_release}
+License: Apache 2.0
+Group: System Environment/Base
+BuildArch: noarch
+URL: http://www.ibm.com/
+Source0: %{name}-%{version}-%{release}.tgz
+Prefix: /opt
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
+
+Requires: python36
+Requires: python36-requests
+Requires: python36-simplejson
+
+# Turn off the brp-python-bytecompile script
+%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
+
+%description
+This package is to be applied to any linux machine that will be used to manage or interact with the IBM OpenBMC.
+It provides key functionality to easily work with the IBM OpenBMC RESTful API, making BMC management easy.
+
+%prep
+%setup -q -n %{name}
+
+%install
+export DESTDIR=$RPM_BUILD_ROOT/opt/ibm/ras
+mkdir -p $DESTDIR/bin
+mkdir -p $DESTDIR/lib
+cp openbmctool*.py $DESTDIR/bin
+cp *.json $DESTDIR/lib
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%attr(775,root,root) /opt/ibm/ras/bin/openbmctool.py
+%attr(664,root,root)/opt/ibm/ras/lib/policyTable.json
+
+%post
+ln -s -f /opt/ibm/ras/bin/openbmctool.py /usr/bin/openbmctool
+%changelog
diff --git a/thalerj/build-scripts/openbmctool-rhel8.spec b/thalerj/build-scripts/openbmctool-rhel8.spec
new file mode 100644
index 0000000..720b128
--- /dev/null
+++ b/thalerj/build-scripts/openbmctool-rhel8.spec
@@ -0,0 +1,46 @@
+# Copyright (c) 2017 International Business Machines.  All right reserved.
+%define _binaries_in_noarch_packages_terminate_build   0
+Summary: IBM OpenBMC tool
+Name: openbmctool
+Version: %{_version}
+Release: %{_release}
+License: Apache 2.0
+Group: System Environment/Base
+BuildArch: noarch
+URL: http://www.ibm.com/
+Source0: %{name}-%{version}-%{release}.tgz
+Prefix: /opt
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
+
+Requires: python3
+Requires: python3-requests
+Requires: python3-simplejson
+
+# Turn off the brp-python-bytecompile script
+%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
+
+%description
+This package is to be applied to any linux machine that will be used to manage or interact with the IBM OpenBMC.
+It provides key functionality to easily work with the IBM OpenBMC RESTful API, making BMC management easy.
+
+%prep
+%setup -q -n %{name}-%{version}-%{release}
+
+%install
+export DESTDIR=$RPM_BUILD_ROOT/opt/ibm/ras
+mkdir -p $DESTDIR/bin
+mkdir -p $DESTDIR/lib
+cp openbmctool*.py $DESTDIR/bin
+cp *.json $DESTDIR/lib
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%attr(775,root,root) /opt/ibm/ras/bin/openbmctool.py
+%attr(664,root,root)/opt/ibm/ras/lib/policyTable.json
+
+%post
+ln -s -f /opt/ibm/ras/bin/openbmctool.py /usr/bin/openbmctool
+%changelog