Browse code

added motd for updateinfo notification

Change-Id: I41a05ffa46a89951886437effa1d493a44f146ad
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/2492
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Priyesh Padmavilasom <ppadmavilasom@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>

Bo Gan authored on 2017/04/21 07:24:20
Showing 10 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,71 @@
0
+%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
1
+%{!?python_version: %define python_version %(%{__python} -c "import sys ; print sys.version[:3]")}
2
+
3
+%define commit0 a152954dcf0583a6efd1af31c42f9e27e6a15bea
4
+
5
+Summary:	Message of the Day
6
+Name:		motd
7
+Version:	0.1.3
8
+Release:	1%{?dist}
9
+License:	GPLv3
10
+URL:		http://github.com/rtnpro/fedora-motd
11
+Source0:	https://github.com/rtnpro/motdgen/archive/motdgen-a152954.tar.gz
12
+%define sha1 motdgen-a152954.tar.gz=fd0b535df54515ce5f56933e53b0ed73c77d1137
13
+Patch0:		strip-dnf.patch
14
+
15
+BuildArchitectures: noarch
16
+
17
+BuildRequires:	python2-devel
18
+BuildRequires:	python-setuptools
19
+
20
+Requires:	Linux-PAM
21
+Requires:	systemd
22
+Requires:	python2
23
+
24
+%description
25
+Generates Dynamic MOTD.
26
+
27
+%prep
28
+%setup -q -n motdgen-%{commit0}
29
+%patch0 -p1
30
+
31
+%build
32
+%{__python} setup.py build
33
+
34
+%install
35
+%{__python} setup.py install -O1 --skip-build \
36
+	--install-data=%{_datadir} --root %{buildroot}
37
+
38
+#shadow is providing /etc/pam.d/sshd with (noreplace)
39
+
40
+%triggerin -- shadow
41
+[ $1 -eq 1 ] && [ $2 -eq 1 ] || exit 0
42
+echo "detected install of motd/shadow, patching /etc/pam.d/sshd"
43
+grep -q '^\s*session\s*include\s*motdgen.*$' %{_sysconfdir}/pam.d/sshd \
44
+	|| echo "session include motdgen" >> %{_sysconfdir}/pam.d/sshd
45
+
46
+%triggerun -- shadow
47
+[ $1 -eq 0 ] && [ $2 -eq 1 ] || exit 0
48
+# $1 $2
49
+# 0  1  motd is being uninstalled, shadow is installed
50
+echo "detected uninstall of motd/shadow, reverting /etc/pam.d/sshd"
51
+sed -i '/^\s*session\s*include\s*motdgen.*$/d' \
52
+	%{_sysconfdir}/pam.d/sshd || exit 0
53
+
54
+%postun
55
+[ $1 -eq 0 ] || exit 0
56
+rm -rf %{_localstatedir}/run/motdgen
57
+
58
+%files
59
+%doc README.md
60
+%defattr(-,root,root)
61
+%{python_sitelib}/motdgen-%{version}-py%{python_version}.egg-info/
62
+%{_sysconfdir}/pam.d/motdgen
63
+%{_sysconfdir}/motdgen.d
64
+%{_sysconfdir}/profile.d/motdgen.sh
65
+%{_bindir}/motdgen
66
+%{_sysconfdir}/systemd/system/motdgen.service
67
+
68
+%changelog
69
+*   Mon Apr 17 2017 Bo Gan <ganb@vmware.com> 0.1.3-1
70
+-   Initial packaging for motd
0 71
new file mode 100644
... ...
@@ -0,0 +1,25 @@
0
+diff --git a/setup.py b/setup.py
1
+index bb8375a..a141d5d 100644
2
+--- a/setup.py
3
+@@ -11,18 +11,14 @@ setup(
4
+     author_email='rtnpro@gmail.com',
5
+     url='https://github.com/rtnpro/motdgen',
6
+     license="GPLv2",
7
+-    scripts=["motdgen", "motdgen-cache-updateinfo"],
8
++    scripts=["motdgen"],
9
+     packages=find_packages(),
10
+     include_package_data=True,
11
+     data_files=[
12
+         ('/etc/profile.d', ['motdgen.sh']),
13
+         ('/etc/pam.d', ['pam.d/motdgen']),
14
+-        ('/usr/lib/python2.7/site-packages/dnf-plugins',
15
+-         ['dnf/plugins/cache_updateinfo.py']),
16
+         ('/etc/motdgen.d', [
17
+-            'motdgen.d/01-uptime.sh',
18
+-            'motdgen.d/02-updateinfo.sh']),
19
+-        ('/etc/cron.daily', ['motdgen-cache-updateinfo']),
20
++            'motdgen.d/01-uptime.sh']),
21
+         ('/etc/systemd/system', ['motdgen.service'])
22
+     ]
23
+ )
0 24
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+#!/bin/sh
1
+
2
+exec > /var/cache/tdnf/cached-updateinfo.txt
3
+
4
+tdnf -qC updateinfo
0 5
new file mode 100644
... ...
@@ -0,0 +1,9 @@
0
+[Unit]
1
+Description=Cache tdnf updateinfo
2
+
3
+[Service]
4
+ExecStart=/usr/bin/tdnf-cache-updateinfo
5
+Type=oneshot
6
+Nice=19
7
+IOSchedulingClass=2
8
+IOSchedulingPriority=7
0 9
new file mode 100644
... ...
@@ -0,0 +1,9 @@
0
+[Unit]
1
+Description=Run tdnf-cache-updateinfo.service daily
2
+
3
+[Timer]
4
+OnCalendar=*-*-* 0,6,12,18:00
5
+RandomizedDelaySec=6h
6
+
7
+[Install]
8
+WantedBy=multi-user.target
... ...
@@ -4,7 +4,7 @@
4 4
 Summary:        dnf/yum equivalent using C libs
5 5
 Name:           tdnf
6 6
 Version:        1.1.0
7
-Release:        3%{?dist}
7
+Release:        4%{?dist}
8 8
 Vendor:         VMware, Inc.
9 9
 Distribution:   Photon
10 10
 License:        VMware
... ...
@@ -22,6 +22,10 @@ BuildRequires:  librepo-devel
22 22
 Source0:    %{name}-%{version}.tar.gz
23 23
 Patch0:     hy_sack_create.patch
24 24
 %define sha1 tdnf=15544a87ea01d6215fed35bd2d1299776f7daca1
25
+Source1:    cache-updateinfo
26
+Source2:    cache-updateinfo.service
27
+Source3:    cache-updateinfo.timer
28
+Source4:    updateinfo.sh
25 29
 
26 30
 %description
27 31
 tdnf is a yum/dnf equivalent
... ...
@@ -48,6 +52,10 @@ make %{?_smp_mflags}
48 48
 make DESTDIR=%{buildroot} install
49 49
 mkdir -p %{buildroot}/var/cache/tdnf
50 50
 ln -sf %{_bindir}/tdnf %{buildroot}%{_bindir}/tyum
51
+install -v -D -m 0755 %{SOURCE1} %{buildroot}%{_bindir}/tdnf-cache-updateinfo
52
+install -v -D -m 0644 %{SOURCE2} %{buildroot}%{_libdir}/systemd/system/tdnf-cache-updateinfo.service
53
+install -v -D -m 0644 %{SOURCE3} %{buildroot}%{_libdir}/systemd/system/tdnf-cache-updateinfo.timer
54
+install -v -D -m 0755 %{SOURCE4} %{buildroot}%{_sysconfdir}/motdgen.d/02-tdnf-updateinfo.sh
51 55
 
52 56
 # Pre-install
53 57
 %pre
... ...
@@ -63,12 +71,31 @@ ln -sf %{_bindir}/tdnf %{buildroot}%{_bindir}/tyum
63 63
 
64 64
     /sbin/ldconfig
65 65
 
66
+%triggerin -- motd
67
+[ $2 -eq 1 ] || exit 0
68
+if [ $1 -eq 1 ]; then
69
+    echo "detected install of tdnf/motd, enabling tdnf-cache-updateinfo.timer"
70
+    systemctl enable tdnf-cache-updateinfo.timer >/dev/null 2>&1 || :
71
+    systemctl start tdnf-cache-updateinfo.timer >/dev/null 2>&1 || :
72
+elif [ $1 -eq 2 ]; then
73
+    echo "detected upgrade of tdnf, daemon-reload"
74
+    systemctl daemon-reload >/dev/null 2>&1 || :
75
+fi
76
+
77
+
66 78
 # Pre-uninstall
67 79
 %preun
68 80
 
69 81
     # First argument is 0 => Uninstall
70 82
     # First argument is 1 => Upgrade
71 83
 
84
+%triggerun -- motd
85
+[ $1 -eq 1 ] && [ $2 -eq 1 ] && exit 0
86
+echo "detected uninstall of tdnf/motd, disabling tdnf-cache-updateinfo.timer"
87
+systemctl --no-reload disable tdnf-cache-updateinfo.timer >/dev/null 2>&1 || :
88
+systemctl stop tdnf-cache-updateinfo.timer >/dev/null 2>&1 || :
89
+rm -rf /var/cache/tdnf/cached-updateinfo.txt
90
+
72 91
 # Post-uninstall
73 92
 %postun
74 93
 
... ...
@@ -77,12 +104,21 @@ ln -sf %{_bindir}/tdnf %{buildroot}%{_bindir}/tyum
77 77
     # First argument is 0 => Uninstall
78 78
     # First argument is 1 => Upgrade
79 79
 
80
+%triggerpostun -- motd
81
+[ $1 -eq 1 ] && [ $2 -eq 1 ] || exit 0
82
+echo "detected upgrade of tdnf/motd, restarting tdnf-cache-updateinfo.timer"
83
+systemctl try-restart tdnf-cache-updateinfo.timer >/dev/null 2>&1 || :
84
+
80 85
 %files
81 86
     %defattr(-,root,root,0755)
82 87
     %{_bindir}/tdnf
83 88
     %{_bindir}/tyum
89
+    %{_bindir}/tdnf-cache-updateinfo
84 90
     %{_libdir}/*.so.*
85 91
     %config(noreplace) %{_sysconfdir}/tdnf/tdnf.conf
92
+    %config %{_libdir}/systemd/system/tdnf-cache-updateinfo.service
93
+    %config(noreplace) %{_libdir}/systemd/system/tdnf-cache-updateinfo.timer
94
+    %config %{_sysconfdir}/motdgen.d/02-tdnf-updateinfo.sh
86 95
     %dir /var/cache/tdnf
87 96
 
88 97
 %files devel
... ...
@@ -95,6 +131,8 @@ ln -sf %{_bindir}/tdnf %{buildroot}%{_bindir}/tyum
95 95
     %{_libdir}/pkgconfig/tdnf.pc
96 96
 
97 97
 %changelog
98
+*   Thu Apr 20 2017 Bo Gan <ganb@vmware.com> 1.1.0-4
99
+-   motd hooks/triggers for updateinfo notification
98 100
 *   Fri Apr 14 2017 Dheerajs Shetty <dheerajs@vmware.com> 1.1.0-3
99 101
 -   Adding a patch to compile with latest hawkey version
100 102
 *   Mon Dec 19 2016 Xiaolin Li <xiaolinl@vmware.com> 1.1.0-2
101 103
new file mode 100644
... ...
@@ -0,0 +1,7 @@
0
+path=/var/cache/tdnf/cached-updateinfo.txt
1
+
2
+if [ -f "$path" ]; then
3
+    cat $path
4
+else
5
+    echo "tdnf update info not available yet!"
6
+fi
... ...
@@ -190,6 +190,7 @@
190 190
         "c-ares",
191 191
         "dnsmasq",
192 192
         "ddclient",
193
-        "netmgmt"
193
+        "netmgmt",
194
+        "motd"
194 195
     ]
195 196
 }
... ...
@@ -9,7 +9,7 @@
9 9
                 "open-vm-tools",
10 10
                 "docker","bridge-utils",
11 11
                 "cloud-init", "tzdata",
12
-                "krb5", "which", "initramfs"]
12
+                "krb5", "which", "initramfs", "motd"]
13 13
 }
14 14
 
15 15
 
... ...
@@ -9,7 +9,7 @@
9 9
                 "open-vm-tools",
10 10
                 "docker","bridge-utils",
11 11
                 "cloud-init",
12
-                "krb5", "which", "tzdata"]
12
+                "krb5", "which", "tzdata", "motd"]
13 13
 }
14 14
 
15 15