To create an RPM package from a directory such as /opt/asd in SuSE, you can follow these general steps:

  1. First, you need to install the RPM build tools on your SuSE system. You can do this by running the following command as root:

zypper install rpm-build

  1. Next, create a directory for your RPM build environment. This can be done anywhere on your system, but it is recommended to create it in your home directory. For example, you could create a directory called rpmbuild by running the following command:

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

This will create a directory structure that is required for building RPM packages.

  1. Copy the contents of /opt/asd into a new directory under the SOURCES directory created in step 2. For example, you could create a directory called asd under SOURCES and copy the contents of /opt/asd into it:

mkdir -p ~/rpmbuild/SOURCES/asd
cp -r /opt/asd/* ~/rpmbuild/SOURCES/asd/

  1. Create a new RPM spec file in the SPECS directory that describes your package. For example, you could create a file called asd.spec with the following contents:

Name: asd
Version: 1.0
Release: 1
Summary: Example RPM package for /opt/asd

License: GPL
Group: Applications/System
Source0: %{name}-%{version}.tar.gz

%description
This is an example RPM package for /opt/asd.

%prep
%setup -q -n %{name}-%{version}

%build

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/opt/asd
cp -r * $RPM_BUILD_ROOT/opt/asd/

%files
/opt/asd/*

This spec file defines the name, version, summary, license, and files included in the package.

  1. Build the RPM package by running the following command in the SPECS directory:

rpmbuild -bb asd.spec

This will build the RPM package and place it in the RPMS directory.

  1. Your RPM package is now ready to be installed on other SuSE systems using the rpm command. For example, you could install the package by running the following command:

rpm -ivh ~/rpmbuild/RPMS/x86_64/asd-1.0-1.x86_64.rpm

If you need to add a custom Bash command during the installation of an RPM package, you can include it in the %post section of your RPM spec file. This section is executed after the package has been installed on the system.

To add a custom Bash command, you would add the command(s) to the %post section of your RPM spec file, like so:

%post
echo "Running custom Bash command"
my_command

In this example, the Bash command my_command is being run after the package is installed.

You can include any valid Bash commands in the %post section, as long as they do not depend on other packages that have not been installed yet.

Once you have added your custom Bash command to the %post section, you can rebuild the RPM package using the rpmbuild command and install the new package on your system. When the package is installed, the %post section will be executed, including your custom Bash command.

In an RPM spec file, the %install section is responsible for copying files into the final installation location, and it is executed during the installation process of the RPM package.

The %post section, on the other hand, is executed after the RPM package has been installed on the system. It is typically used to perform additional tasks or configuration that are required after the installation has completed, such as setting environment variables, creating directories, starting services, or running custom Bash commands.

So, the %post section should come after the %install section in the RPM spec file. Here is an example of a spec file that includes both sections:

Name: mypackage
Version: 1.0
Release: 1
Summary: My package summary

%description
This is my package description.

%prep
%setup -q

%build
# Build commands go here

%install
# Installation commands go here

%post
# Post-installation commands go here

In this example, the %install section includes commands that copy files to their final locations on the system. The %post section includes additional Bash commands that are executed after the installation has completed.