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/RPMbuildfiles/README b/thalerj/RPMbuildfiles/README
deleted file mode 100644
index 34a1be3..0000000
--- a/thalerj/RPMbuildfiles/README
+++ /dev/null
@@ -1,7 +0,0 @@
-README for build script
-
-This script is used to simplify the build process for rpms. It must be run with root privileges.
-simply run the script with the current directory structure. It will prompt the user for the version
-and the release number to use. It will then create a tarball for the rpm content
-and then build the rpm. Once complete the new rpm can be found in /tmp/openbmctool-{version-release)/
-directory.
diff --git a/thalerj/RPMbuildfiles/buildOpenbmctool.sh b/thalerj/RPMbuildfiles/buildOpenbmctool.sh
deleted file mode 100644
index 504f85c..0000000
--- a/thalerj/RPMbuildfiles/buildOpenbmctool.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/bash
-echo "Version: ex 1.0"
-read version
-echo "Release: ex 4"
-read release
-mkdir -p /tmp/openbmctool-$version-$release
-rm -rf /tmp/openbmctool-$version-$release/*
-cp ../* /tmp/openbmctool-$version-$release
-tar -cvzf /root/rpmbuild/SOURCES/openbmctool-$version-$release.tgz -C /tmp openbmctool-$version-$release
-rpmbuild -ba --define "_version $version" --define "_release $release" /root/rpmbuild/SPECS/openbmctool.spec
-cp /root/rpmbuild/RPMS/noarch/openbmctool-$version-$release.noarch.rpm /tmp/openbmctool-$version-$release/
-
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/RPMbuildfiles/openbmctool.spec b/thalerj/build-scripts/openbmctool-rhel7.spec
similarity index 75%
copy from thalerj/RPMbuildfiles/openbmctool.spec
copy to thalerj/build-scripts/openbmctool-rhel7.spec
index 46e37f2..7769223 100644
--- a/thalerj/RPMbuildfiles/openbmctool.spec
+++ b/thalerj/build-scripts/openbmctool-rhel7.spec
@@ -12,14 +12,9 @@
 Prefix: /opt
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
 
-Requires: python34
-Requires: python34-requests
-
-#%if 0%{?_unitdir:1}
-#Requires(post): systemd-units
-#Requires(preun): systemd-units
-#Requires(postun): systemd-units
-#%endif
+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')
@@ -28,19 +23,13 @@
 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.
 
-#%build
-#%{__make}
 %prep
-%setup -q -n %{name}-%{version}-%{release}
+%setup -q -n %{name}
 
 %install
-#rm -rf $RPM_BUILD_ROOT
 export DESTDIR=$RPM_BUILD_ROOT/opt/ibm/ras
 mkdir -p $DESTDIR/bin
-#mkdir -p $DESTDIR/bin/ppc64le
-#mkdir -p $DESTDIR/etc
 mkdir -p $DESTDIR/lib
-#mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system
 cp openbmctool*.py $DESTDIR/bin
 cp *.json $DESTDIR/lib
 
@@ -49,7 +38,6 @@
 rm -rf $RPM_BUILD_ROOT
 
 %files
-#%defattr(-,root,root,-)
 %attr(775,root,root) /opt/ibm/ras/bin/openbmctool.py
 %attr(664,root,root)/opt/ibm/ras/lib/policyTable.json
 
diff --git a/thalerj/RPMbuildfiles/openbmctool.spec b/thalerj/build-scripts/openbmctool-rhel8.spec
similarity index 78%
rename from thalerj/RPMbuildfiles/openbmctool.spec
rename to thalerj/build-scripts/openbmctool-rhel8.spec
index 46e37f2..720b128 100644
--- a/thalerj/RPMbuildfiles/openbmctool.spec
+++ b/thalerj/build-scripts/openbmctool-rhel8.spec
@@ -12,14 +12,9 @@
 Prefix: /opt
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
 
-Requires: python34
-Requires: python34-requests
-
-#%if 0%{?_unitdir:1}
-#Requires(post): systemd-units
-#Requires(preun): systemd-units
-#Requires(postun): systemd-units
-#%endif
+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')
@@ -28,19 +23,13 @@
 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.
 
-#%build
-#%{__make}
 %prep
 %setup -q -n %{name}-%{version}-%{release}
 
 %install
-#rm -rf $RPM_BUILD_ROOT
 export DESTDIR=$RPM_BUILD_ROOT/opt/ibm/ras
 mkdir -p $DESTDIR/bin
-#mkdir -p $DESTDIR/bin/ppc64le
-#mkdir -p $DESTDIR/etc
 mkdir -p $DESTDIR/lib
-#mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system
 cp openbmctool*.py $DESTDIR/bin
 cp *.json $DESTDIR/lib
 
@@ -49,7 +38,6 @@
 rm -rf $RPM_BUILD_ROOT
 
 %files
-#%defattr(-,root,root,-)
 %attr(775,root,root) /opt/ibm/ras/bin/openbmctool.py
 %attr(664,root,root)/opt/ibm/ras/lib/policyTable.json