RHEL 6 question

block921block921 Registered Users Posts: 7 ■□□□□□□□□□
Anyone know how to create a single rpm that installs hello.sh in /root/bin with 755? The stupid answer isn't in the useless work book and I had to drop from the virtual class so I missed the answer

Comments

  • Chris:/*Chris:/* Member Posts: 658 ■■■■■■■■□□
    Why do you want to do this in an RPM instead of creating a tar that allows you to unpack it as required with any user account and location?

    Perhaps you can find your answers here: https://pmc.ucsc.edu/~dmk/notes/RPMs/Creating_RPMs.html
    Degrees:
    M.S. Information Security and Assurance
    B.S. Computer Science - Summa Cum Laude
    A.A.S. Electronic Systems Technology
  • /pub/beer//pub/beer/ Member Posts: 67 ■■■□□□□□□□
    Use the fedora guide as a guide

    How to create a GNU Hello RPM package - FedoraProject
    How to create an RPM package - FedoraProject
    Chris:/* wrote: »
    Why do you want to do this in an RPM instead of creating a tar that allows you to unpack it as required with any user account and location?

    Building a simple RPM is an objective for the RCHE exam
    Certification Goal:
    - ¯\_(ツ)_/¯
  • Chris:/*Chris:/* Member Posts: 658 ■■■■■■■■□□
    Good to know
    Degrees:
    M.S. Information Security and Assurance
    B.S. Computer Science - Summa Cum Laude
    A.A.S. Electronic Systems Technology
  • NightShade03NightShade03 Member Posts: 1,383 ■■■■■■■□□□
    For a simple RPM like you could do the following:

    Create the required directories

    # mkdir -p /usr/src/redhat/{BUILD,RPMS,SOURCES,SPEC,SRPMS,tmp}

    Install the required packages:

    # yum install -y rpm-build

    Create the BASH file (mine is blank for this example):

    # mkdir /usr/src/redhat/SOURCES/sample
    # touch /usr/src/redhat/SOURCES/sample/hello.sh

    Create a SOURCES file that will actually only hold your single BASH script:

    # tar cvf sample.tar.gz /usr/src/redhat/SOURCES/sample
    # mv sample.tar.gz /usr/src/redhat/SOURCES

    Create a sample.spec file in the /usr/src/redhat/SPEC directory using the following as a template:

    ##### Sample SPEC File #####

    Summary: This package is a sample for the Red Hat exams.
    Name: sample
    Version: 1.0
    Release: 0
    License: GPL
    Packager: Joe Tester
    Group: Development/Tools
    Source: %{name}.tar.gz
    BuildRoot: /usr/src/redhat/tmp/%{name}-%{version}

    %description
    This package is just a sample for the Red Hat exams.

    # The %prep and %setup untar your SOURCES .tar.gz file and enter into that directory to perform the required actions.

    %prep
    %setup -n sample

    # Moves the hello.sh file into the /opt directory (only under our build root).

    %install
    mkdir -p "$RPM_BUILD_ROOT/opt/"
    cp -R * "$RPM_BUILD_ROOT/opt/"

    # All files you want in your RPM package must be listed here.
    # Listed directories contain every file and sub-directory within them.

    %files
    /opt/

    %clean
    rm -rf "$RPM_BUILD_ROOT"

    %post
    chown user01:user01 -R /opt/hello.sh
    chmod 775 -R /opt/

    ##### End SPEC File #####

    Once your SPEC file is in place and your sample.tar.gz is in place execute the following command to create the new RPM package:

    # rpmbuild -v -bb /usr/src/redhat/SPEC/sample.spec

    If there are any errors you will see them here and they should be easy enough to fix. If there are no errors you should now have a new RPM package in your /usr/src/redhat/RPMS directory.

    Run the following to test:

    # rpm -ivh sample.rpm

    Which in turn should install the hello.sh script into the /opt directory with the 775 permissions and owned by user01 and group user01.

    This should be everything that you need. If you get stuck or have any questions let me know.
  • block921block921 Registered Users Posts: 7 ■□□□□□□□□□
    just to be fair it also says we have to sign the rpm with a self signed cert and then make it available via custom yum repo:

    gpg -gen-key
    gpg --export a 'name' > public_key.txt
    gpg --list-keys

    vi ~/.rpmmacros
    %_signature gpg
    %_gpg_name <name used in key>

    rpm --resign file.rpm
  • block921block921 Registered Users Posts: 7 ■□□□□□□□□□
    For a simple RPM like you could do the following:

    Create the required directories

    # mkdir -p /usr/src/redhat/{BUILD,RPMS,SOURCES,SPEC,SRPMS,tmp}

    Install the required packages:

    # yum install -y rpm-build

    Create the BASH file (mine is blank for this example):

    # mkdir /usr/src/redhat/SOURCES/sample
    # touch /usr/src/redhat/SOURCES/sample/hello.sh

    Create a SOURCES file that will actually only hold your single BASH script:

    # tar cvf sample.tar.gz /usr/src/redhat/SOURCES/sample
    # mv sample.tar.gz /usr/src/redhat/SOURCES

    Create a sample.spec file in the /usr/src/redhat/SPEC directory using the following as a template:

    ##### Sample SPEC File #####

    Summary: This package is a sample for the Red Hat exams.
    Name: sample
    Version: 1.0
    Release: 0
    License: GPL
    Packager: Joe Tester
    Group: Development/Tools
    Source: %{name}.tar.gz
    BuildRoot: /usr/src/redhat/tmp/%{name}-%{version}

    %description
    This package is just a sample for the Red Hat exams.

    # The %prep and %setup untar your SOURCES .tar.gz file and enter into that directory to perform the required actions.

    %prep
    %setup -n sample

    # Moves the hello.sh file into the /opt directory (only under our build root).

    %install
    mkdir -p "$RPM_BUILD_ROOT/opt/"
    cp -R * "$RPM_BUILD_ROOT/opt/"

    # All files you want in your RPM package must be listed here.
    # Listed directories contain every file and sub-directory within them.

    %files
    /opt/

    %clean
    rm -rf "$RPM_BUILD_ROOT"

    %post
    chown user01:user01 -R /opt/hello.sh
    chmod 775 -R /opt/

    ##### End SPEC File #####

    Once your SPEC file is in place and your sample.tar.gz is in place execute the following command to create the new RPM package:

    # rpmbuild -v -bb /usr/src/redhat/SPEC/sample.spec

    If there are any errors you will see them here and they should be easy enough to fix. If there are no errors you should now have a new RPM package in your /usr/src/redhat/RPMS directory.

    Run the following to test:

    # rpm -ivh sample.rpm

    Which in turn should install the hello.sh script into the /opt directory with the 775 permissions and owned by user01 and group user01.

    This should be everything that you need. If you get stuck or have any questions let me know.

    doesn't work, it has someting to do with %setup -n sample, whats the difference between setup -q and setup -n ?
  • NightShade03NightShade03 Member Posts: 1,383 ■■■■■■■□□□
    What error are you getting? If you follow the output that is produced from the -v option with the rpmbuild command it should indicate where you issue is. The %prep and %setup essentially untar your sample.tar.gz file and the -n sample means the name of the directory it is expecting to cd into is "sample".
  • dnc92301dnc92301 Registered Users Posts: 1 ■□□□□□□□□□
    Hello thanks for the brief and concise RPM template. I hope this is thread still opened. But i need your help to help to debug the issue. I am getting this error:
    [root@SPECS]# rpmbuild -v -bb ntp.spec
    error: line 19: second %prep

    Basically I am doing litterly everything you had posted. I am trying to create a simple RPM with binary and startup script but need to be in RPM format to be installed in repo during installs. Thanks again.
Sign In or Register to comment.