Open23

How to create a GNU Hello RPM package/ja を Almalinux で試す

opparaoppara
Dockerfile
FROM almalinux:latest

# ユーザー名とパスワードのための環境変数
ARG USER_NAME
ARG USER_PASSWORD

# AlmaLinuxのパッケージ管理システムを更新し、必要なパッケージをインストール
RUN dnf -y update && \
    dnf -y install sudo passwd vim wget net-tools iputils iproute bash-completion && \
    dnf clean all

# 一般ユーザーの作成
RUN useradd -m ${USER_NAME} && \
    echo "${USER_NAME}:${USER_PASSWORD}" | chpasswd && \
    echo "${USER_NAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/${USER_NAME}

# 作業ディレクトリの設定
WORKDIR /home/${USER_NAME}

# コンテナ起動時に実行するコマンド
CMD ["/bin/bash"]
compose.yaml
services:
  almalinux_app:
    build:
      context: .
      args:
        USER_NAME: oppara
        USER_PASSWORD: hoihoi
    container_name: almalinux_custom_container
    tty: true
    volumes:
      - ./home:/home/user # ホストとコンテナ間でディレクトリを共有(任意)
Makefile
# 実行するコンテナ名
CONTAINER_NAME := almalinux_custom_container

.PHONY: up
up: ## docker compose up
	docker compose up -d
	docker compose ps

.PHONY: stop
stop: ## docker compose stop
	docker compose stop

.PHONY: down
down: ## docker compose down
	docker compose down

.PHONY: reload
reload: ## down & up
	@make down
	@make up

.PHONY: destroy
destroy: ## docker compose down -v
	docker compose down -v

.PHONY: bash
bash: ## docker exec -it ${CONTAINER_NAME} bash
	docker exec -it ${CONTAINER_NAME} bash

.PHONY: help
help: ## Display this help screen
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
opparaoppara

一般ユーザで作業する

# sudo su - oppara
$ id
uid=1000(oppara) gid=1000(oppara) groups=1000(oppara)
opparaoppara

クリーンな chroot の中でのビルドのプロシージャーを可能にさせるために、あなたには、あなたの non-privileged account を 'mock' グループの一員として、configure する必要があります:

$ sudo usermod -a -G mock oppara
usermod: group 'mock' does not exist

よく分からんので一旦無視

opparaoppara
$ ls -a1
.
..
.bash_logout
.bash_profile
.bashrc

$ rpmdev-setuptree

$ ls -a1
.
..
.bash_logout
.bash_profile
.bashrc
.rpmmacros
rpmbuild

$ ls -1a rpmbuild/
.
..
BUILD
RPMS
SOURCES
SPECS
SRPMS

$ cat .rpmmacros

%_topdir %(echo $HOME)/rpmbuild

%__arch_install_post \
    [ "%{buildarch}" = "noarch" ] || QA_CHECK_RPATHS=1 ; \
    case "${QA_CHECK_RPATHS:-}" in [1yY]*) /usr/lib/rpm/check-rpaths ;; esac \
    /usr/lib/rpm/check-buildroot
opparaoppara

ソースのダウンロード

$ cd ~/rpmbuild/SOURCES
$ wget http://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz
opparaoppara

.spec ファイルの作成

$ cd ~/rpmbuild/SPECS
$ rpmdev-newspec hello
$ cat hello.spec
Name:           hello
Version:
Release:        1%{?dist}
Summary:

License:
URL:
Source0:

BuildRequires:
Requires:

%description


%prep
%autosetup


%build
%configure
%make_build


%install
rm -rf $RPM_BUILD_ROOT
%make_install


%files
%license add-license-file-here
%doc add-docs-here



%changelog
* Sun Nov 17 2024 oppara
-
opparaoppara
.spac
Name:           hello
Version:        2.12
Release:        1%{?dist}
Summary:        The "Hello World" program from GNU

License:        GPLv3+
URL:            http://ftp.gnu.org/gnu/%{name}
Source0:        http://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.gz

BuildRequires:  gettext
Requires(post): info
Requires(preun): info

%description
The "Hello World" program, done with all bells and whistles of a proper FOSS
project, including configuration, build, internationalization, help files, etc.


%prep
%autosetup


%build
%configure
make %{?_smp_mflags}


%install
%make_install
%find_lang %{name}
rm -f %{buildroot}/%{_infodir}/dir

%post
/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || :

%preun
if [ $1 = 0 ] ; then
/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || :
fi

%files -f %{name}.lang
%{_mandir}/man1/hello.1.*
%{_infodir}/hello.info.*
%{_bindir}/hello

%doc AUTHORS ChangeLog NEWS README THANKS TODO
%license COPYING

%changelog
* Mon Jan 31 2022 The Coon of Ty <Ty@coon.org> 2.12-1
- Initial version of the package
```                                                                                                                                           1,21          Top
opparaoppara
$ rpmbuild -ba hello.spec

(ry

/home/oppara/rpmbuild/BUILD/hello-2.12/build-aux/missing: line 81: makeinfo: command not found
WARNING: 'makeinfo' is missing on your system.
         You should only need it if you modified a '.texi' file, or
         any other file indirectly affecting the aspect of the manual.
         You might want to install the Texinfo package:
         <https://www.gnu.org/software/texinfo/>
         The spurious makeinfo call might also be the consequence of
         using a buggy 'make' (AIX, DU, IRIX), in which case you might
         want to install GNU make:
         <https://www.gnu.org/software/make/>
make[2]: *** [Makefile:2289: doc/hello.info] Error 127
make[2]: Leaving directory '/home/oppara/rpmbuild/BUILD/hello-2.12'
make[1]: *** [Makefile:2496: install-recursive] Error 1
make[1]: Leaving directory '/home/oppara/rpmbuild/BUILD/hello-2.12'
make: *** [Makefile:3006: install] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.g4o63h (%install)

RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.g4o63h (%install)

makeinfo がないと怒られる

opparaoppara

arm な texinfo をインストールしてみる
RPM resource texinfo

$ sudo rpm -ivh https://rpmfind.net/linux/almalinux/8.10/PowerTools/aarch64/os/Packages/texinfo-6.5-7.el8.aarch64.rpm
Retrieving https://rpmfind.net/linux/almalinux/8.10/PowerTools/aarch64/os/Packages/texinfo-6.5-7.el8.aarch64.rpm
warning: /var/tmp/rpm-tmp.fa3EWH: Header V4 RSA/SHA256 Signature, key ID c21ad6ea: NOKEY
error: Failed dependencies:
        perl(Locale::Messages) is needed by texinfo-6.5-7.el8.aarch64
        perl(Text::Unidecode) is needed by texinfo-6.5-7.el8.aarch64
        perl(Unicode::EastAsianWidth) is needed by texinfo-6.5-7.el8.aarch64
        perl(Unicode::Normalize) is needed by texinfo-6.5-7.el8.aarch64
opparaoppara

cpanm のインストールして Perl のモジュールをインストールする

$ sudo yum install -y perl-App-cpanminus

$ sudo cpanm Locale::Messages
$ sudo cpanm Text::Unidecode
$ sudo cpanm Unicode::EastAsianWidth
$ sudo cpanm Unicode::Normalize
opparaoppara
$ sudo rpm -ivh https://rpmfind.net/linux/almalinux/8.10/PowerTools/aarch64/os/Packages/texinfo-6.5-7.el8.aarch64.rpm
Retrieving https://rpmfind.net/linux/almalinux/8.10/PowerTools/aarch64/os/Packages/texinfo-6.5-7.el8.aarch64.rpm
warning: /var/tmp/rpm-tmp.V9yi3u: Header V4 RSA/SHA256 Signature, key ID c21ad6ea: NOKEY
error: Failed dependencies:
        perl(Locale::Messages) is needed by texinfo-6.5-7.el8.aarch64
        perl(Text::Unidecode) is needed by texinfo-6.5-7.el8.aarch64
        perl(Unicode::EastAsianWidth) is needed by texinfo-6.5-7.el8.aarch64
opparaoppara
$ sudo rpm -ivh https://rpmfind.net/linux/dag/redhat/el5/en/ppc/fabian/RPMS/perl-libintl-1.16-1.el5.rf.noarch.rpm
$ sudo rpm -ivh https://rpmfind.net/linux/almalinux/8.10/PowerTools/aarch64/os/Packages/texinfo-6.5-7.el8.aarch64.rpm
Retrieving https://rpmfind.net/linux/almalinux/8.10/PowerTools/aarch64/os/Packages/texinfo-6.5-7.el8.aarch64.rpm
warning: /var/tmp/rpm-tmp.q7Lsck: Header V4 RSA/SHA256 Signature, key ID c21ad6ea: NOKEY
error: Failed dependencies:
        perl(Text::Unidecode) is needed by texinfo-6.5-7.el8.aarch64
        perl(Unicode::EastAsianWidth) is needed by texinfo-6.5-7.el8.aarch64
opparaoppara
$ sudo rpm -ivh https://rpmfind.net/linux/dag/redhat/el6/en/i386/dag/RPMS/perl-Unicode-EastAsianWidth-1.30-1.el6.rf.noarch.rpm
$ sudo rpm -ivh https://rpmfind.net/linux/almalinux/9.4/AppStream/aarch64/os/Packages/perl-Text-Unidecode-1.30-16.el9.noarch.rpm
$ sudo rpm -ivh https://rpmfind.net/linux/almalinux/8.10/PowerTools/aarch64/os/Packages/texinfo-6.5-7.el8.aarch64.rpm

とりあえず texinfo インストールできた?

opparaoppara

再度ビルド

$ ~/rpmbuild/SPECS
$ rpmbuild -ba hello.spec

(ry

+ exit 0

$ ls  -1R ../RPMS/
../RPMS/:
aarch64

../RPMS/aarch64:
hello-2.12-1.el9.aarch64.rpm
hello-debuginfo-2.12-1.el9.aarch64.rpm
hello-debugsource-2.12-1.el9.aarch64.rpm
opparaoppara

リント

$ rpmlint hello.spec ../SRPMS/hello* ../RPMS/*/hello*
-bash: rpmlint: command not found

$ sudo dnf install -y rpmlint

$ rpmlint hello.spec ../SRPMS/hello* ../RPMS/*/hello*
(none): E: no installed packages by name hello.spec
(none): E: no installed packages by name ../SRPMS/hello*
(none): E: no installed packages by name ../RPMS/*/hello*
0 packages and 0 specfiles checked; 0 errors, 0 warnings.
opparaoppara

インストールして実行

$ cd ~/rpmbuild/RPMS/aarch64/
$ sudo dnf install hello-2.12-1.el9.aarch64.rpm
$ which hello
/usr/bin/hello
$ hello
Hello, world!
$ hello --version
hello (GNU Hello) 2.12.1-6fe9
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Karl Berry, Sami Kerola, Jim Meyering,
and Reuben Thomas.
opparaoppara
$ cd ~/rpmbuild/RPMS/aarch64/
$ rpmrebuild --release=2.el9 --package hello-2.12-1.el9.aarch64.rpm
(GenRpmQf) remove tag line ENHANCESFLAGS
(GenRpmQf) remove tag line ENHANCESNAME
(GenRpmQf) remove tag line ENHANCESVERSION
(GenRpmQf) remove tag line SUGGESTSFLAGS
(GenRpmQf) remove tag line SUGGESTSNAME
(GenRpmQf) remove tag line SUGGESTSVERSION
warning: Explicit %attr() mode not applicable to symlink: /home/oppara/.tmp/rpmrebuild.11318/work/root/usr/lib/.build-id/93/a0d975ec777a3f713058a2d63daef190864c11
warning: File listed twice: /usr/lib/.build-id
warning: File listed twice: /usr/lib/.build-id/93/a0d975ec777a3f713058a2d63daef190864c11
result: /home/oppara/rpmbuild/RPMS/aarch64/hello-2.12-2.el9.aarch64.rpm
$ ls -1
hello-2.12-1.el9.aarch64.rpm
hello-2.12-2.el9.aarch64.rpm
hello-debuginfo-2.12-1.el9.aarch64.rpm
hello-debugsource-2.12-1.el9.aarch64.rpm