LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-20-2022, 08:00 PM   #1
RedMan1001001
LQ Newbie
 
Registered: Oct 2020
Posts: 7

Rep: Reputation: Disabled
How to add a custom shell script to a RPM


Hello all,

I am learning how to build RPM's and have a quick question I'm hoping someone can help me with.

I am running RHEL 7.9 OS.

I want to install the Zabbix-Agent RPM but would like for a shell script to run as part of the RPM install which re-configures the zabbix-agent.conf file to point the agent to a specific IP address.

The zabbix agent version is zabbix-agent.x86_64 5.0.19-1.el7.

I am familiar with some of the basics of creating RPM's but the part that i get confused on is the SPEC file. How do i set up a spec file to do the above and where in the tree structure does the RPM go and where does the shell script go?

Any help will be appreciated

Thanks
 
Old 01-20-2022, 10:37 PM   #2
enigma9o7
Senior Member
 
Registered: Jul 2018
Location: Silicon Valley
Distribution: Bodhi Linux
Posts: 1,388

Rep: Reputation: 560Reputation: 560Reputation: 560Reputation: 560Reputation: 560Reputation: 560
I've only ever made one rpm, so I am not good adviser for this. But, I think I know the answer..

If you want commands to run during installation, you put them under "%install" in the SPEC file, don't call external scripts.

Remember, people install packages as root, and you don't normally put anything into anyone's home folders at all during installation. If the app needs config files in users folder, it will create them for each user when that user runs it. If you want a default config file to end up in user folders you can put it in skel, but that will only affect new users created afterwards, not existing users.
 
Old 01-21-2022, 04:00 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,686

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
there are two ways:
1. you modify the original zabbix package (I don't really recommend this)
2. you create your own zabbix_setup package and the original one will be just a requirement (dependency)
In any case you need to put your config script into the rpm and execute it during the installation of the package.
You need to check the %post section in the spec file.
 
Old 01-21-2022, 07:58 AM   #4
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by RedMan1001001 View Post
zabbix-agent.x86_64 5.0.19-1.el7
This is not the official RPM package from EPEL for EL7, the latter is called zabbix50-agent.x86_64 5.0.18-1.el7 (the version 5.0.19 is currently in epel-testing). This begs the question: where did you get the package from?

Quote:
Originally Posted by enigma9o7 View Post
If you want commands to run during installation, you put them under "%install" in the SPEC file, don't call external scripts.
An RPM package is supposed to be installed on many systems. Custom configuration (IP address) cannot go into %install as that part is executed on builder's host when package is being built. Rather, like pan64 suggests
Quote:
Originally Posted by pan64 View Post
You need to check the %post section in the spec file.
EPEL provides an rpmrebuild tool, but honestly, creating a small wrapper package as pan64 suggested above would probably be easier for you. An additional benefit is that the wrapper package won't get upgraded when EPEL ships a new version of Zabbix, potentially overwriting your custom changes.

You'll have to install rpm-build. I also recommend installing rpmdevtools and using rpmdev-newspec to generate the spec file template. Alternatively, some editors provide support for RPM spec files. I'm pretty sure Eclipse does. I myself use Vim. CentOS 7 ships Vim with a spec file template that will be used when you create a new file with .spec suffix. That functionality has been disabled in recent Fedora releases because of rhbz#1724126, but can be trivially re-enabled.

Last edited by shruggy; 01-21-2022 at 10:58 AM.
 
  


Reply

Tags
rpm, script, shell, zabbix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with logging the output of a custom daemon with a custom init script d1s4st3r *BSD 3 04-30-2010 04:46 AM
Add a custom-built rpm to a repository neildomo Red Hat 6 10-15-2008 09:11 PM
Hosed my rpm installation (i.e. "rpm -e rpm") Mad Scientist Fedora 6 03-02-2007 12:42 AM
rpm error only says"rpm: relocation error: rpm: undefined symbol: poptAliasOptions" dlrsims Linux - Newbie 2 11-14-2003 09:22 PM
.src.rpm, .i386.rpm and .i686.rpm hhegab Linux - Software 2 06-19-2003 07:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration