Skip to content

Commit

Permalink
motd: upgrade to v1.0
Browse files Browse the repository at this point in the history
tdnf: remove updateinfo timer and service.

Instead of inidividual applications shipping timers for populating motd
content, MOTD now has its own timer.

Change-Id: I08c237c18a88b26223b208a66fb5bfec56186ca7
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Reviewed-on: http://photon-gerrit.lvn.broadcom.net/c/photon/+/24839
Tested-by: gerrit-photon <svc.photon-ci@broadcom.com>
Reviewed-by: Guruswamy Basavaiah <guruswamy.basavaiah@broadcom.com>
  • Loading branch information
sshedi committed Jan 31, 2025
1 parent c32e25d commit 50e943d
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 96 deletions.
1 change: 1 addition & 0 deletions SPECS/motd/motd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d /run/motdgen 0755 root root
47 changes: 23 additions & 24 deletions SPECS/motd/motd.spec
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
%define commit0 a152954dcf0583a6efd1af31c42f9e27e6a15bea
%define srcname photon-motdgen

Summary: Message of the Day
Name: motd
Version: 0.1.3
Release: 7%{?dist}
Version: 1.0
Release: 1%{?dist}
License: GPLv3
URL: http://github.com/rtnpro/fedora-motd
URL: https://github-vcf.devops.broadcom.net/vcf/photon-motdgen
Group: Applications/Daemons
Vendor: VMware, Inc.
Distribution: Photon

Source0: https://github.com/rtnpro/motdgen/archive/motdgen-a152954.tar.gz
%define sha512 motdgen-a152954.tar.gz=784d6fa426c48386a584c7d026a585718a8665a249cae9450073f812b5b4935fa20d4127dcb9c937ac4470b4f19e9349974bf0e4c341d95a162a04438ce98276
Source0: https://github-vcf.devops.broadcom.net/vcf/%{srcname}-%{version}.tar.gz
%define sha512 %{srcname}=031d2209e0a582bab9457cf82e80d920b2b121eab9a685dee54aaa0e4556598b949462e4e1fba6342dbbef22231ba29cd9c66d72139a0ed727b093d75eed5004

Patch0: strip-dnf.patch
Source1: %{name}.conf

BuildArch: noarch

BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-xml
BuildRequires: systemd-devel
BuildRequires: make
BuildRequires: coreutils
BuildRequires: systemd-devel

Requires: Linux-PAM
Requires: systemd
Requires: python3
Requires: /bin/grep
Requires: bash
Requires: Linux-PAM
Requires: systemd

%description
Generates Dynamic MOTD.

%prep
%autosetup -p1 -n motdgen-%{commit0}
%autosetup -p1 -n %{srcname}-%{version}

%build
%py3_build
%make_build

%install
python3 setup.py install -O1 --skip-build --install-data=%{_datadir} --root %{buildroot}
%make_install %{?_smp_mflags}
# SELinux: let systemd create our runtime directory and label it properly.
mkdir -p %{buildroot}%{_tmpfilesdir}
echo "d /run/motdgen 0755 root root" > %{buildroot}%{_tmpfilesdir}/motd.conf
install -D -m 644 %{SOURCE1} %{buildroot}%{_tmpfilesdir}/motd.conf

#shadow is providing /etc/pam.d/sshd with (noreplace)

Expand All @@ -60,20 +57,22 @@ sed -i '/^\s*session\s*include\s*motdgen.*$/d' \

%postun
[ $1 -eq 0 ] || exit 0
rm -rf %{_localstatedir}/run/motdgen
rm -rf %{_rundir}/motdgen

%files
%doc README.md
%defattr(-,root,root)
%{python3_sitelib}/*
%{_sysconfdir}/pam.d/motdgen
%{_sysconfdir}/motdgen.d
%{_sysconfdir}/profile.d/motdgen.sh
%{_bindir}/motdgen
%{_sysconfdir}/systemd/system/motdgen.service
%{_unitdir}/motdgen.service
%{_unitdir}/motdgen.timer
%{_tmpfilesdir}/motd.conf

%changelog
* Tue Nov 26 2024 Shreenidhi Shedi <shreenidhi.shedi@broadcom.com> 1.0-1
- Upgrade to v1.0
- Switch to photon-motdgen
* Fri Dec 02 2022 Prashant S Chauhan <psinghchauha@vmware.com> 0.1.3-7
- Update release to compile with python 3.11
* Thu Apr 30 2020 Alexey Makhalov <amakhalov@vmware.com> 0.1.3-6
Expand Down
25 changes: 0 additions & 25 deletions SPECS/motd/strip-dnf.patch

This file was deleted.

91 changes: 44 additions & 47 deletions SPECS/tdnf/tdnf.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
%define hist_db_dir %{_libdir}/sysimage/%{name}
%define history_db_fn %{hist_db_dir}/history.db
%define history_autoins %{_sharedstatedir}/%{name}/autoinstalled
%define history_util %{_libdir}/%{name}/%{name}-history-util
%define _tdnfpluginsdir %{_libdir}/%{name}-plugins

%global automatic_services %{name}-automatic.timer %{name}-automatic-notifyonly.timer %{name}-automatic-install.timer

Summary: dnf/yum equivalent using C libs
Name: tdnf
Version: 3.5.10
Release: 1%{?dist}
Release: 2%{?dist}
Vendor: VMware, Inc.
Distribution: Photon
License: LGPLv2.1,GPLv2
Expand All @@ -14,6 +22,7 @@ Source0: https://github.com/vmware/tdnf/archive/refs/tags/%{name}-%{version}.tar
Patch0: 0001-do-not-nuke-RPMBUILD_DIR-in-pytests-since-it-can-be-.patch
Patch1: rpm-keyring-API-calls-1.patch
Patch2: rpm-keyring-API-calls-2.patch
Patch3: updateinfo.patch

Requires: rpm-libs
Requires: curl-libs
Expand Down Expand Up @@ -57,9 +66,6 @@ Provides: yum
%description
%{name} is a yum/dnf equivalent which uses libsolv and libcurl

%define _tdnfpluginsdir %{_libdir}/%{name}-plugins
%define _tdnf_history_db_dir /usr/lib/sysimage/%{name}

%package devel
Summary: A Library providing C API for %{name}
Group: Development/Libraries
Expand Down Expand Up @@ -138,42 +144,43 @@ Systemd units that can periodically download package upgrades and apply them.
%autosetup -p1 -n %{name}-%{version}

%build
%cmake \
%{cmake} \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_LIBDIR:PATH=%{_libdir} \
-DSYSTEMD_DIR=%{_unitdir} \
-DHISTORY_DB_DIR=%{_tdnf_history_db_dir}

%cmake_build
-DHISTORY_DB_DIR=%{hist_db_dir}

cd %{__cmake_builddir}
%make_build python
%{cmake_build}

%if 0%{?with_check}
%check
pip3 install flake8
cd %{__cmake_builddir} && make %{?_smp_mflags} check
%endif
%make_build -C %{__cmake_builddir} python

%install
%cmake_install
find %{buildroot} -name '*.a' -delete
mkdir -p %{buildroot}/var/cache/%{name} %{buildroot}%{_unitdir}
mkdir -p %{buildroot}%{_tdnf_history_db_dir}
%{cmake_install}

protected_dir="%{_sysconfdir}/%{name}/protected.d"

mkdir -p %{buildroot}{%{_var}/cache/%{name},%{_unitdir}} \
%{buildroot}%{hist_db_dir} \
%{buildroot}${protected_dir}

ln -sfv %{name} %{buildroot}%{_bindir}/tyum
ln -sfv %{name} %{buildroot}%{_bindir}/yum
ln -sfv %{name} %{buildroot}%{_bindir}/tdnfj

mkdir -p %{buildroot}%{_sysconfdir}/%{name}/protected.d && \
echo %{name} > %{buildroot}%{_sysconfdir}/%{name}/protected.d/%{name}.conf
echo %{name} > %{buildroot}${protected_dir}/%{name}.conf

pushd %{__cmake_builddir}/python
%py3_install
popd
find %{buildroot} -name '*.pyc' -delete

%pre
find %{buildroot} \( -name '*.a' -o -name '*.pyc' \) -delete

rm %{buildroot}%{_unitdir}/%{name}-cache-updateinfo.{timer,service}

%check
pip3 install flake8
%make_build -C %{__cmake_builddir} check

%post
/sbin/ldconfig
Expand All @@ -183,46 +190,36 @@ find %{buildroot} -name '*.pyc' -delete
# to the new db.
# must be postrans because we read the rpm db
# cannot use tdnf because that is still running even in postrans
[ -f %{_tdnf_history_db_dir}/history.db ] || %{_libdir}/tdnf/tdnf-history-util init
if [ -f %{_sharedstatedir}/tdnf/autoinstalled ] ; then
%{_libdir}/tdnf/tdnf-history-util mark remove $(cat %{_sharedstatedir}/tdnf/autoinstalled) && \
rm %{_sharedstatedir}/tdnf/autoinstalled
[ -d %{hist_db_dir} ] || mkdir -p %{hist_db_dir}
[ -f %{history_db_fn} ] || %{history_util} init
if [ -f %{history_autoins} ]; then
%{history_util} mark remove $(cat %{history_autoins})
mv %{history_autoins} %{history_autoins}.backup
fi
exit 0

%triggerin -- motd
[ $2 -eq 1 ] || exit 0
if [ $1 -eq 1 ]; then
echo "detected install of %{name}/motd, enabling %{name}-cache-updateinfo.timer" >&2
systemctl enable %{name}-cache-updateinfo.timer >/dev/null 2>&1 || :
systemctl start %{name}-cache-updateinfo.timer >/dev/null 2>&1 || :
elif [ $1 -eq 2 ]; then
if [ $1 -eq 2 ]; then
echo "detected upgrade of %{name}, daemon-reload" >&2
systemctl daemon-reload >/dev/null 2>&1 || :
fi

%preun
%triggerun -- motd
[ $1 -eq 1 ] && [ $2 -eq 1 ] && exit 0
echo "detected uninstall of %{name}/motd, disabling %{name}-cache-updateinfo.timer" >&2
systemctl --no-reload disable %{name}-cache-updateinfo.timer >/dev/null 2>&1 || :
systemctl stop %{name}-cache-updateinfo.timer >/dev/null 2>&1 || :
rm -f /var/cache/%{name}/cached-updateinfo.txt
echo "detected uninstall of %{name}/motd" >&2
rm -f %{_var}/cache/%{name}/cached-updateinfo.txt

%postun
/sbin/ldconfig
%triggerpostun -- motd
[ $1 -eq 1 ] && [ $2 -eq 1 ] || exit 0
echo "detected upgrade of %{name}/motd, restarting %{name}-cache-updateinfo.timer" >&2
systemctl try-restart %{name}-cache-updateinfo.timer >/dev/null 2>&1 || :

%post cli-libs
/sbin/ldconfig

%postun cli-libs
/sbin/ldconfig

%global automatic_services %{name}-automatic.timer %{name}-automatic-notifyonly.timer %{name}-automatic-install.timer

%post automatic
%systemd_post %{automatic_services}

Expand All @@ -239,16 +236,13 @@ systemctl try-restart %{name}-cache-updateinfo.timer >/dev/null 2>&1 || :
%{_bindir}/yum
%{_bindir}/tdnfj
%{_bindir}/tdnf-config
%{_bindir}/tdnf-cache-updateinfo
%{_libdir}/libtdnf.so.*
%{_libdir}/tdnf/tdnf-history-util
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%config(noreplace) %{_sysconfdir}/%{name}/protected.d/%{name}.conf
%config %{_unitdir}/%{name}-cache-updateinfo.service
%config(noreplace) %{_unitdir}/%{name}-cache-updateinfo.timer
%config %{_sysconfdir}/motdgen.d/02-%{name}-updateinfo.sh
%dir /var/cache/%{name}
%dir %{_tdnf_history_db_dir}
%dir %{_var}/cache/%{name}
%dir %{hist_db_dir}
%{_datadir}/bash-completion/completions/%{name}

%files devel
Expand Down Expand Up @@ -297,6 +291,9 @@ systemctl try-restart %{name}-cache-updateinfo.timer >/dev/null 2>&1 || :
%{_unitdir}/%{name}-automatic-notifyonly.service

%changelog
* Fri Jan 31 2025 Shreenidhi Shedi <shreenidhi.shedi@broadcom.com> 3.5.10-2
- Remove updateinfo timer
- MOTD has its own timer now
* Wed Dec 18 2024 Shreenidhi Shedi <shreenidhi.shedi@broadcom.com> 3.5.10-1
- Upgrade to v3.5.10
* Tue Jun 25 2024 Oliver Kurth <oliver.kurth@broadcom.com> 3.5.7-1
Expand Down
79 changes: 79 additions & 0 deletions SPECS/tdnf/updateinfo.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
From 938816ad9a924ab3c3b00b9d15c359737bdd900d Mon Sep 17 00:00:00 2001
From: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Date: Wed, 4 Dec 2024 05:47:27 +0000
Subject: [PATCH] Fix updateinfo script

Move instructions from bin/tdnf-cache-updateinfo to 02-tdnf-updateinfo,
when motd triggers it, it will generate the right data.

Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
---
CMakeLists.txt | 1 -
bin/CMakeLists.txt | 1 -
bin/tdnf-cache-updateinfo.in | 15 ---------------
etc/motdgen.d/02-tdnf-updateinfo.sh | 10 +++++++---
4 files changed, 7 insertions(+), 20 deletions(-)
delete mode 100755 bin/tdnf-cache-updateinfo.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c0aa5071..4cc4d7da 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -101,6 +101,5 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/tools")
add_subdirectory("${PROJECT_SOURCE_DIR}/pytests")

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/tdnf-automatic.in ${PROJECT_SOURCE_DIR}/bin/tdnf-automatic @ONLY)
-CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/tdnf-cache-updateinfo.in ${PROJECT_SOURCE_DIR}/bin/tdnf-cache-updateinfo @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/tdnf.spec.in ${CMAKE_SOURCE_DIR}/tdnf.spec @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/scripts/build-tdnf-rpms.in ${CMAKE_SOURCE_DIR}/scripts/build-tdnf-rpms @ONLY)
diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt
index 3becd28a..49f3a2f9 100644
--- a/bin/CMakeLists.txt
+++ b/bin/CMakeLists.txt
@@ -7,4 +7,3 @@
#

install(PROGRAMS "tdnf-automatic" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binary)
-install(PROGRAMS "tdnf-cache-updateinfo" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binary)
diff --git a/bin/tdnf-cache-updateinfo.in b/bin/tdnf-cache-updateinfo.in
deleted file mode 100755
index 6ab77161..00000000
--- a/bin/tdnf-cache-updateinfo.in
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-
-#
-# Copyright (C) 2020 VMware, Inc. All Rights Reserved.
-#
-# Licensed under the GNU General Public License v2 (the "License");
-# you may not use this file except in compliance with the License. The terms
-# of the License are located in the COPYING file of this distribution.
-#
-
-exec > /var/cache/tdnf/cached-updateinfo.txt
-
-tdnf -q --refresh updateinfo | grep -vE '^Refreshing|^Disabling'
-
-exit ${PIPESTATUS[0]}
diff --git a/etc/motdgen.d/02-tdnf-updateinfo.sh b/etc/motdgen.d/02-tdnf-updateinfo.sh
index fb386a08..031ab1f5 100755
--- a/etc/motdgen.d/02-tdnf-updateinfo.sh
+++ b/etc/motdgen.d/02-tdnf-updateinfo.sh
@@ -10,9 +10,13 @@

path="/var/cache/tdnf/cached-updateinfo.txt"

+tdnf -q --refresh updateinfo | grep -vE '^Refreshing|^Disabling' > "${path}"
+
if [ -s "${path}" ]; then
- grep -qE 'Security|Bugfix|Enhancement' "${path}" || exit 0
- echo; cat "${path}"; echo "Run 'tdnf updateinfo info' to see the details."
+ grep -qE 'Security|Bugfix|Enhancement' "${path}" || exit 0
+ echo
+ cat "${path}"
+ echo "Run 'tdnf updateinfo info' to see the details."
else
- echo "tdnf update info not available yet!"
+ echo "tdnf update info not available yet!"
fi

0 comments on commit 50e943d

Please sign in to comment.