最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

linux - How to display shell output script during RPM installation - Stack Overflow

programmeradmin7浏览0评论

I am trying to create RPM package for RHEL which allow me to speed up my daily work, however I have some problem with SPEC file for RPM. As source of my RPM I use shell script which normally I use for installation my application. When I execute script from cmd

./instll_app.sh 

then I see progress of installation like in example below:

Step 1. Download file
Step 2. Stop current process.
Step 3. Remove old instance
Step 4. Install in progres
Step 5 ....
....

I created RPM which I can install but during RPM installation script is not display "progress".

Freed space: 314
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                      1/1
  Erasing          : hello-0.0.1-1.el9.noarch                                                                                                                                                             1/1
  Verifying        : hello-0.0.1-1.el9.noarch                                                                                                                                                             1/1
Installed products updated.

Removed:
  hello-0.0.1-1.el9.noarch

Complete!

I would like to see same steps which are executed by script which are inside in RPM.I tried to add script into %post section but, script not display progress. Any idea?

So far for test purpose my SPEC file looks like below

%prep
%setup -q

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
cp %{name}.sh $RPM_BUILD_ROOT/%{_bindir}
sh $RPM_BUILD_ROOT/%{_bindir}/%{name}.sh

%clean
rm -rf $RPM_BUILD_ROOT


%files
%{_bindir}/%{name}.sh

%post

I am trying to create RPM package for RHEL which allow me to speed up my daily work, however I have some problem with SPEC file for RPM. As source of my RPM I use shell script which normally I use for installation my application. When I execute script from cmd

./instll_app.sh 

then I see progress of installation like in example below:

Step 1. Download file
Step 2. Stop current process.
Step 3. Remove old instance
Step 4. Install in progres
Step 5 ....
....

I created RPM which I can install but during RPM installation script is not display "progress".

Freed space: 314
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                      1/1
  Erasing          : hello-0.0.1-1.el9.noarch                                                                                                                                                             1/1
  Verifying        : hello-0.0.1-1.el9.noarch                                                                                                                                                             1/1
Installed products updated.

Removed:
  hello-0.0.1-1.el9.noarch

Complete!

I would like to see same steps which are executed by script which are inside in RPM.I tried to add script into %post section but, script not display progress. Any idea?

So far for test purpose my SPEC file looks like below

%prep
%setup -q

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
cp %{name}.sh $RPM_BUILD_ROOT/%{_bindir}
sh $RPM_BUILD_ROOT/%{_bindir}/%{name}.sh

%clean
rm -rf $RPM_BUILD_ROOT


%files
%{_bindir}/%{name}.sh

%post

Share Improve this question asked Mar 24 at 14:52 majanmajan 1392 silver badges17 bronze badges 1
  • superuser/questions/1155016/… – tink Commented Mar 24 at 15:41
Add a comment  | 

1 Answer 1

Reset to default 0

I created RPM which I can install but during RPM installation script is not display "progress".

No, it doesn't, because with the spec provided, there is no such progress at RPM installation time.

Packaging formats such as RPM and DEB are primarily about delivering and managing consistent sets of files. Although they contain provisions for scripting actions to take when certain events occur, they are by no means intended to be used as scripting elements themselves. That seems to be what you're looking for, and if so, then RPM is the wrong tool for the job.

Building an RPM works by constructing an image of the fileset to be managed via the package, which is then packed up so that it can later be dropped into place without further action. The original idea was very much to capture the result of performing an installation from source on one machine, so as to pick up the resulting files from all the locations where they went, and later be able to drop them into place on other machines without going through any preliminaries. The %install scriptlet in an RPM spec is intended to perform the part where the files are actually dropped into the image, analogous to (and often comprising) a make install. %install runs during RPM building, on the build host. It does not run during installation of the resulting RPM.

I would like to see same steps which are executed by script which are inside in RPM.I tried to add script into %post section but, script not display progress. Any idea?

The %post scriptlet can contain script that executes programs or scripts delivered in the RPM. The scriptlet inherits its standard streams from its parent rpm command, so if you install such an RPM interactively then the scriptlet's standard streams will be connected to your terminal. It's unclear what exactly you tried or what actually happened when you tried it, but you absolutely can receive output from a scriptlet this way.

However, if you are expecting that installing the RPM will cause the system to download and a separate installation package and unpack files from it onto the system then that's a gross misuse of RPM. The intended approach is that

  • any needed resources are pre-downloaded and included among the RPM's sources

  • all file installation is performed by the %install scriptlet, into a staging area (at $RPM_BUILD_ROOT, which you can also spell %{buildroot}) laid out as if the root of that staging area were / of the destination machine's filesystem

  • All resulting files are listed in the %files section of the spec; they will be packaged in the resulting RPM, not (re)generated when the RPM is installed.

    Since RPM knows what files these are, it will also handle removing them when the RPM is removed, or as appropriate when the RPM is updated by a new version that does not provide all the same files.

If there are any needed (RPM-)installation time operations, such as shutting down a previous version of the software, then that is the purpose of the %pre, %post, %preun and %postun scriptlets. In particular, shutting down the previously installed version seems like a job for the %preun scriptlet, though that placement will be effective only when you uninstall or replace a version of the RPM that already has the appropriate %preun code.

发布评论

评论列表(0)

  1. 暂无评论