#!/bin/bash
set -e

# minimal(?) steps to create an rpm, mainly to test unmute.py
# 2020-03-21, https://ocv.me/dev/?gist/make-rpm.sh

mkdir -p ~/rpm/{BUILD,RPMS}
echo '%_topdir %(echo "$HOME")/rpm' >~/.rpmmacros

rm -rf ~/asdf
mkdir -p ~/asdf
cd ~/asdf

cat >asdf.spec <<'EOF'
Summary: asdf
Name: asdf
Version: 1.0
Release: 1
License: WTFPL
Source: %{expand:%%(pwd)}
BuildRoot: %{_topdir}/BUILD/%{name}-%{version}-%{release}

%description
%{summary}

%prep
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin
cd $RPM_BUILD_ROOT
cp -a %{SOURCEURL0}/unmute.py ./usr/bin/

%clean
rm -rf "$RPM_BUILD_ROOT"

%files
%defattr(755,root,root)
%{_bindir}/unmute.py

%post
unmute.py
EOF

cp -pv ~/unmute.py ~/asdf
rpmbuild -bb asdf.spec

cd
yum -y erase asdf || true
#rpm -ivh ~/rpm/RPMS/x86_64/asdf-*.rpm
yum -y install ~/rpm/RPMS/x86_64/asdf-*.rpm

