On 23/11/17 18:39, Andrew W wrote: > Im trying to learn how to create RPMs but am a little confused by the > spec file. OK. I don't see a reply that answer your questions directly, so here I go... > > Im trying to package up some Python scripts, rather than binary files, > and I want them to be installed in a subdirectory under /usr/local > which I shall refer to as /usr/local/X > > Ive put the scripts in a tarball under /home/me/X/RPM/SOURCES Is this /home/me/RPM your rpm topdir? On my setup, sources should go in $HOME/rpmbuild/SOURCES (see below.) > > but Im getting terribly confused over what to put in the %build > %install and %files sections Build is building - compiling if you are using a "compiled language". Install should put everything on the directory where you want the final rpm to install it - but prefixed by the "build root" (i.e. your $RPM_BUILD_ROOT discussed below.) Files is a list of files to include in the package. It should match what you install to the build root. If you list a directory, all its files are recursively included, unless you put "%dir" in front of it. > > > If I set $RPM_BUILD_ROOT to /home/me/X/RPM/temp then put How so you set this up? In the environment? Usually, you include something like BuildRoot: /home/me/X/RPM/temp in the spec file, and "rpmbuild" sets up the variable for you during build. You can also use %{buildroot}. See https://www.redhat.com/archives/rpm-list/2002-July/msg00110.html. These days you generally get a usable build root without specifying anything. "%{...}" represents the expansion of a so-called rpm macro - it's the rpm macro equivalent to the shell's "${...}". rpmbuild defines a number of macros for you automatically and/or reads in definitions from config files; more on that below. > > %prep > > %setup -q > > that will unpack the tarball, yes?, but where to, /home/me/X/RPM/temp ? No. It will unpack to a directory specified by the rpm configuration. On my system (CentOS 6), the default is $HOME/rpmbuild. The configuration takes the form of an rpm macro, which is defined in /usr/lib/rpm/macros or /etc/rpm/macros. Look for _builddir and also _topdir in these files. (There may also be a user-specific location where you can configure this. I forget, as I'm generally OK with the defaults.) You should probably replace "setup -q" with just "setup", as the unpack command will then tell you more. > > how would I then tell it to move the files I want from there into > /usr/local/X and set appropriate permissions on them? The examples > online all assume you have a makefile with a make install target, > could I simply use the cp command under the %install section? Yes. You can put any shell command there. You should just copy the files to your install location "under the build root", i.e. for instance %{buildroot}/usr/local/X a.k.a. ${RPM_BUILD_ROOT}/usr/local/X. There are also macros that contain various standard commands, so you can for instance write "%{__cp}" instead of "cp". This is supposed to make the spec file more portable. Have a look /usr/lib/rpm/macros*. I wouldn't install on /usr/local, by the way (like some others who've responded.) Personally, I reckon /usr should be OK when using the "native" package manager, but some people argue that /opt is more proper. I'd use macros for this, too, anyhow. See _prefix, _bindir, _libdir etc. in the above mentioned files. > But where am I copying from and to? You copy from the current directory, where you'll find your tarball contents - rpmbuild automatically changes to the appropriate location. For the "to" part, see above. You should probably make sure the tarball has a toplevel directory of the form <name>-<version>, by the way. But see http://ftp.rpm.org/max-rpm/s1-rpm-specref-macros.html. > > My brain is tied in knots! Better? - Toralf > > Many thanks > > Andrew > > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.centos.org_mailman_listinfo_centos&d=DwIGaQ&c=KV_I7O14pmwRcmAVyJ1eg4Jwb8Y2JAxuL5YgMGHpjcQ&r=Q0oqxzgUp3xCCIiJDwS-RbNDndQ-KZDhj8wwveNoqU4&m=BZScovPxq9BPYdz5frQ6KpVS6IVKlibJ9upw-avjjDI&s=DLhKQr1YMQ1U4xTv4B-XM49U1jYozge37_hbhsMDxo8&e=