Issue
Basically I want my build process to do this:
- Run a shell script that strips data from csv files and combines them into a single csv.
- The resulting csv output from that script is then packaged in the rpm.
- When rpm -install is run, the csv file (not the script) is placed in a specific location on the target machine.
I'm very new to RPM so I'm sorry if I've made a blunder with the code below, but it gives me several errors when trying to build or install.
I attempted to run a script from the sources directory
I'm a little confused on how the expected flow of rpm should work. In testing, I'm building and installing on the same machine, but in practice it will be on two machines.
When I run the code below, does it put a copy of my source files into the .rpm file? I'm wondering why it doesn't work. (it says process.sh does not exist)
Name: Test
Version: 1
Release: 1
Summary: Test
License: FIXME
%description
this is a test build
%prep
echo "BUILDROOT = $RPM_BUILD_ROOT"
mkdir -p -m777 $RPM_BUILD_ROOT/usr/local/bin/
cp /home/myuser/foo/util/* $RPM_BUILD_ROOT/usr/local/bin
cd $RPM_BUILD_ROOT/usr/local/bin/
./process.sh hosts.csv processed.csv
exit
%files
%attr(0777, root, root) /foo/processed.csv
Solution
You need to:
- Set up the build tree for your user, e.g. run
rpmdev-setuptree
- Place the source files to
SOURCES
in the build tree - Declare some
Source
tags. It is crucial for a proper build. Because this is how you reference the files that make up your build, during the build.
E.g.
Source0: process.sh
Source1: util.tar.gz
The util.tar.gz
can be the tarball for all the numerous CSV files (I assume there are too many, so it would be not feasible to have an individual Source
entry for each of them.
Then:
- in the
%prep
section you would extract%{SOURCE1}
. - in the
%build
section you can combine them into a single file - in the
%install
section you would install the combined file
%prep
cp -p %{SOURCE0} .
tar zxvf %{SOURCE1}
# ...
%install
%{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/%{name}
%{__install} -m 644 -p processed.csv \
$RPM_BUILD_ROOT%{_datadir}/%{name}/
%files
%{_datadir}/%{name}/processed.csv
P.S. I know for a beginner it would sound a bit an unnecessary task to copy something to the SOURCES
directory when you already have it elsewhere, but this is the way to go still.
Answered By - Danila Vershinin Answer Checked By - Willingham (WPSolving Volunteer)