From 28d4a73bcc825978e0bee606bfe3016bfccc08ea Mon Sep 17 00:00:00 2001 From: rfairley Date: Nov 13 2018 16:25:13 +0000 Subject: propagate renaming to remaining source files --- diff --git a/README.md b/README.md index e2ae856..7c14412 100644 --- a/README.md +++ b/README.md @@ -20,19 +20,14 @@ Let `x` denote `{motd,issue}`. - [x] ip address in issue - [x] some info on updates (booting, pending, etc) from rpm-ostree status --json? in motd (db, upgrade, status, version) (see https://github.com/rtnpro/motdgen/blob/master/motdgen-cache-updateinfo) - [x] failed units on login -- [ ] check installation against FCOS +- [ ] check installation against FCOS, F29, F29AH, Rawhide - [ ] ensure licensing is correct - [ ] %check - [ ] CI for master branch - [ ] tidy up code, comments - [ ] user manual (brief) -## Issues to figure out - -- [ ] After installing the rpms generated by `rpm-build.sh` more tmpfiles named `pkg-console-login-helper-messages-*.conf` are -created, which include lines to create directories in run; `/run/console-login-helper-messages`, `/run/console-login-helper-messages/issue.d`, `/run/console-login-helper-messages/motd.d`. This clutters up tmpfiles.d (given that this package contains 3 tmpfiles already). May want to consider another something like CL's [baselayout](https://github.com/coreos/baselayout/blob/master/tmpfiles.d/baselayout.conf) rather than have several tmpfiles. -- [ ] systemd tmpfiles @macros@ - ## Enhancements for future - [x] have upstream PAM include the "trying" functionality, use this config rather than symlinks - [ ] have upstream PAM search issue.d with pam_issue.so (rather than agetty, go through one interface - PAM) +- [ ] automake @macros@ \ No newline at end of file diff --git a/console-login-helper-messages.spec b/console-login-helper-messages.spec index 881e7f9..33e7803 100644 --- a/console-login-helper-messages.spec +++ b/console-login-helper-messages.spec @@ -84,14 +84,14 @@ install -DpZm 0644 usr/lib/systemd/system/issuegen.service %{buildroot}%{_unitdi install -DpZm 0644 usr/lib/tmpfiles.d/issuegen-tmpfiles.conf %{buildroot}%{_tmpfilesdir}/issuegen.conf install -DpZm 0644 usr/lib/systemd/system/motdgen.path %{buildroot}%{_unitdir}/motdgen.path install -DpZm 0644 usr/lib/systemd/system/motdgen.service %{buildroot}%{_unitdir}/motdgen.service -install -DpZm 0644 usr/lib/tmpfiles.d/coreos-profile-tmpfiles.conf %{buildroot}%{_tmpfilesdir}/%{name}-profile.conf +install -DpZm 0644 usr/lib/tmpfiles.d/%{name}-profile-tmpfiles.conf %{buildroot}%{_tmpfilesdir}/%{name}-profile.conf install -DpZm 0644 usr/lib/udev/rules.d/91-issuegen.rules %{buildroot}%{_prefix}/lib/udev/rules.d/91-issuegen.rules -install -DpZm 0755 usr/lib/coreos/issuegen %{buildroot}%{_prefix}/lib/%{name}/issuegen -install -DpZm 0644 usr/lib/coreos/issue.d/* %{buildroot}%{_prefix}/lib/%{name}/issue.d -install -DpZm 0755 usr/lib/coreos/motdgen %{buildroot}%{_prefix}/lib/%{name}/motdgen -install -DpZm 0644 usr/lib/coreos/motd.d/* %{buildroot}%{_prefix}/lib/%{name}/motd.d -install -DpZm 0755 usr/share/coreos/coreos-profile.sh %{buildroot}%{_prefix}/share/%{name}/%{name}-profile.sh +install -DpZm 0755 usr/lib/%{name}/issuegen %{buildroot}%{_prefix}/lib/%{name}/issuegen +install -DpZm 0644 usr/lib/%{name}/issue.d/* %{buildroot}%{_prefix}/lib/%{name}/issue.d +install -DpZm 0755 usr/lib/%{name}/motdgen %{buildroot}%{_prefix}/lib/%{name}/motdgen +install -DpZm 0644 usr/lib/%{name}/motd.d/* %{buildroot}%{_prefix}/lib/%{name}/motd.d +install -DpZm 0755 usr/share/%{name}/%{name}-profile.sh %{buildroot}%{_prefix}/share/%{name}/%{name}-profile.sh ln -snf /run/issue.d/%{name}.issue %{buildroot}%{_sysconfdir}/issue.d/%{name}.issue ln -snf %{_prefix}/share/%{name}/%{name}-profile.sh %{buildroot}%{_sysconfdir}/profile.d/%{name}-profile.sh @@ -99,7 +99,6 @@ ln -snf %{_prefix}/share/%{name}/%{name}-profile.sh %{buildroot}%{_sysconfdir}/p # TODO: handle pkg-* being created more nicely %pre %tmpfiles_create_package issuegen issuegen-tmpfiles.conf -%tmpfiles_create_package motdgen motdgen-tmpfiles.conf %tmpfiles_create_package %{name}-profile %{name}-profile-tmpfiles.conf # TODO: check presets will enable the services in RHCOS diff --git a/usr/lib/console-login-helper-messages/issue.d/base.issue b/usr/lib/console-login-helper-messages/issue.d/base.issue new file mode 100644 index 0000000..e5d72e1 --- /dev/null +++ b/usr/lib/console-login-helper-messages/issue.d/base.issue @@ -0,0 +1,3 @@ +---- +This is \n (\s \m \r) \t +---- diff --git a/usr/lib/console-login-helper-messages/issuegen b/usr/lib/console-login-helper-messages/issuegen new file mode 100755 index 0000000..d6f2e1f --- /dev/null +++ b/usr/lib/console-login-helper-messages/issuegen @@ -0,0 +1,45 @@ +#!/bin/bash + +set -e + +PKG_NAME=console-login-helper-messages +ISSUE_DIR_PUBLIC=issue.d +ISSUE_DIR_PRIVATE=${PKG_NAME}/issue.d +GENERATED_ISSUE=/run/${ISSUE_DIR_PUBLIC}/${PKG_NAME}.issue +SSH_DIR=/etc/ssh + +mkdir -p ${SSH_DIR} +mkdir -p /run/${ISSUE_DIR_PUBLIC} +mkdir -p /run/${ISSUE_DIR_PRIVATE} +rm -f $GENERATED_ISSUE + +# Data from udev rules +case "$1" in + add) + echo "${2}: \\4{${2}} \\6{${2}}" > "/run/${ISSUE_DIR_PRIVATE}/${2}" + ;; + remove) + rm -f "/run/${ISSUE_DIR_PRIVATE}/${2}" + ;; +esac + +# Provide key fingerprints via issue +for KEY_FILE in $(find ${SSH_DIR} -name 'ssh_host_*_key') ; do + ssh-keygen -l -f ${KEY_FILE} +done | awk '{print "SSH host key: " $2 " " $4}' > /run/${ISSUE_DIR_PRIVATE}/00_ssh_host_keys + +echo + +if [[ -d "/etc/${ISSUE_DIR_PRIVATE}" ]]; then + cat /etc/${ISSUE_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_ISSUE} || true +fi + +if [[ -d "/run/${ISSUE_DIR_PRIVATE}" ]]; then + cat /run/${ISSUE_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_ISSUE} || true +fi + +if [[ -d "/usr/lib/${ISSUE_DIR_PRIVATE}" ]]; then + cat /usr/lib/${ISSUE_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_ISSUE} || true +fi + +echo diff --git a/usr/lib/console-login-helper-messages/motd.d/base.motd b/usr/lib/console-login-helper-messages/motd.d/base.motd new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/usr/lib/console-login-helper-messages/motd.d/base.motd diff --git a/usr/lib/console-login-helper-messages/motdgen b/usr/lib/console-login-helper-messages/motdgen new file mode 100755 index 0000000..69fb544 --- /dev/null +++ b/usr/lib/console-login-helper-messages/motdgen @@ -0,0 +1,96 @@ +#!/bin/bash + +set -e + +PKG_NAME=console-login-helper-messages +MOTD_DIR_PUBLIC=motd.d +MOTD_DIR_PRIVATE=${PKG_NAME}/motd.d +GENERATED_MOTD=/run/${MOTD_DIR_PUBLIC}/${PKG_NAME}.motd +RUN_DROP_DIR=/run/${PKG_NAME} + +ANSI_LIGHT_RED='\033[1;31m' +ANSI_LIGHT_BLUE='\033[1;34m' +ANSI_NC='\033[0m' +SUBPOINT=' |->' + +source /usr/lib/os-release + +print_rpm_ostree_update_info() { + echo -e "\n[ostree]" + + rpm-ostree status --json > ${RUN_DROP_DIR}/rpm-ostree-status.json + rpm-ostree upgrade --check > ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out + + sec_advisories=$(cat ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out | grep "SecAdvisories") + pkg_diff=$(cat ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out | grep "Diff") + up_version=$(cat ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out | grep "Version") + up_version=$(awk '{ print $2 }' <<< "${up_version}") + up_commit=$(cat ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out | grep "Commit") + up_commit=$(awk '{ print $2 }' <<< "${up_commit}") + upgrade_deployment_pending_reboot=$(jq --arg commit "${up_commit}" '(.deployments[0].booted == false) and (.deployments[0]."base-checksum" | tostring == $commit])' ${RUN_DROP_DIR}/rpm-ostree-status.json) + up_commit=$(echo "${up_commit}" | awk '{ print substr($0,0,6) }') + cur_version=$(jq '.deployments | map(select(.booted == true)) | .[]."version"' ${RUN_DROP_DIR}/rpm-ostree-status.json) + cur_version=$(sed -e 's/^"//' -e 's/"$//' <<< "${cur_version}") + cur_commit=$(jq '.deployments | map(select(.booted == true)) | .[]."base-checksum"' ${RUN_DROP_DIR}/rpm-ostree-status.json) + cur_commit=$(sed -e 's/^"//' -e 's/"$//' <<< "${cur_commit}") + cur_commit=$(echo "${cur_commit}" | awk '{ print substr($0,0,6) }') + + echo -e "current: ${cur_version} (${cur_commit})" + update_available_msg=$(echo -e "${ANSI_LIGHT_BLUE}available${ANSI_NC}: ${up_version} (${up_commit})") + if [ -n "${up_commit}" ]; then + if [ "${upgrade_deployment_pending_reboot}" = "true" ]; then + echo "${update_available_msg} - deployment pending next reboot" + else + echo "${update_available_msg}" + fi + fi + + if [ -n "${sec_advisories}" ]; then + sec_advisories=$(awk '{$1=""; sub(" ", " "); print}' <<< "${sec_advisories}") + sec_advisories=$(echo "${sec_advisories}" | sed -e "s/^[[:space:]]*//") + echo -e "${SUBPOINT} ${ANSI_LIGHT_RED}advisories${ANSI_NC}: ${sec_advisories}" + fi + if [ -n "${pkg_diff}" ]; then + pkg_diff=$(awk '{ $1="" ; sub(" ", " ") ; print }' <<< "${pkg_diff}") + pkg_diff=$(echo "${pkg_diff}" | sed -e "s/^[[:space:]]*//") + echo -e "${SUBPOINT} packages: ${pkg_diff}" + fi +} + +print_dnf_update_info() { + echo -e "\n[dnf]" + dnf -qC updateinfo > ${RUN_DROP_DIR}/dnf-updateinfo.out + cat ${RUN_DROP_DIR}/dnf-updateinfo.out +} + +mkdir -p /run/${MOTD_DIR_PRIVATE} +mkdir -p /run/${MOTD_DIR_PUBLIC} +mkdir -p /run/${RUN_DROP_DIR} +rm -f ${GENERATED_MOTD} + +# Get updated system information and print it to the +# generated motd +echo -e "\e[${ANSI_COLOR}m${NAME}\e[39m (${VERSION})" > ${GENERATED_MOTD} + +if [ -x "$(command -v rpm-ostree)" ]; then + set +e + print_rpm_ostree_update_info >> ${GENERATED_MOTD} + set -e +fi +if [ -x "$(command -v dnf)" ]; then + set +e + print_dnf_update_info >> ${GENERATED_MOTD} + set -e +fi + +if [[ -d "/usr/lib/${MOTD_DIR_PRIVATE}" ]]; then + cat /usr/lib/${MOTD_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_MOTD} || true +fi + +if [[ -d "/run/${MOTD_DIR_PRIVATE}" ]]; then + cat /run/${MOTD_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_MOTD} || true +fi + +if [[ -d "/etc/${MOTD_DIR_PRIVATE}" ]]; then + cat /etc/${MOTD_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_MOTD} || true +fi diff --git a/usr/lib/coreos/issue.d/base.issue b/usr/lib/coreos/issue.d/base.issue deleted file mode 100644 index e5d72e1..0000000 --- a/usr/lib/coreos/issue.d/base.issue +++ /dev/null @@ -1,3 +0,0 @@ ----- -This is \n (\s \m \r) \t ----- diff --git a/usr/lib/coreos/issuegen b/usr/lib/coreos/issuegen deleted file mode 100755 index d6f2e1f..0000000 --- a/usr/lib/coreos/issuegen +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -set -e - -PKG_NAME=console-login-helper-messages -ISSUE_DIR_PUBLIC=issue.d -ISSUE_DIR_PRIVATE=${PKG_NAME}/issue.d -GENERATED_ISSUE=/run/${ISSUE_DIR_PUBLIC}/${PKG_NAME}.issue -SSH_DIR=/etc/ssh - -mkdir -p ${SSH_DIR} -mkdir -p /run/${ISSUE_DIR_PUBLIC} -mkdir -p /run/${ISSUE_DIR_PRIVATE} -rm -f $GENERATED_ISSUE - -# Data from udev rules -case "$1" in - add) - echo "${2}: \\4{${2}} \\6{${2}}" > "/run/${ISSUE_DIR_PRIVATE}/${2}" - ;; - remove) - rm -f "/run/${ISSUE_DIR_PRIVATE}/${2}" - ;; -esac - -# Provide key fingerprints via issue -for KEY_FILE in $(find ${SSH_DIR} -name 'ssh_host_*_key') ; do - ssh-keygen -l -f ${KEY_FILE} -done | awk '{print "SSH host key: " $2 " " $4}' > /run/${ISSUE_DIR_PRIVATE}/00_ssh_host_keys - -echo - -if [[ -d "/etc/${ISSUE_DIR_PRIVATE}" ]]; then - cat /etc/${ISSUE_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_ISSUE} || true -fi - -if [[ -d "/run/${ISSUE_DIR_PRIVATE}" ]]; then - cat /run/${ISSUE_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_ISSUE} || true -fi - -if [[ -d "/usr/lib/${ISSUE_DIR_PRIVATE}" ]]; then - cat /usr/lib/${ISSUE_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_ISSUE} || true -fi - -echo diff --git a/usr/lib/coreos/motd.d/base.motd b/usr/lib/coreos/motd.d/base.motd deleted file mode 100644 index e69de29..0000000 --- a/usr/lib/coreos/motd.d/base.motd +++ /dev/null diff --git a/usr/lib/coreos/motdgen b/usr/lib/coreos/motdgen deleted file mode 100755 index 69fb544..0000000 --- a/usr/lib/coreos/motdgen +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -set -e - -PKG_NAME=console-login-helper-messages -MOTD_DIR_PUBLIC=motd.d -MOTD_DIR_PRIVATE=${PKG_NAME}/motd.d -GENERATED_MOTD=/run/${MOTD_DIR_PUBLIC}/${PKG_NAME}.motd -RUN_DROP_DIR=/run/${PKG_NAME} - -ANSI_LIGHT_RED='\033[1;31m' -ANSI_LIGHT_BLUE='\033[1;34m' -ANSI_NC='\033[0m' -SUBPOINT=' |->' - -source /usr/lib/os-release - -print_rpm_ostree_update_info() { - echo -e "\n[ostree]" - - rpm-ostree status --json > ${RUN_DROP_DIR}/rpm-ostree-status.json - rpm-ostree upgrade --check > ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out - - sec_advisories=$(cat ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out | grep "SecAdvisories") - pkg_diff=$(cat ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out | grep "Diff") - up_version=$(cat ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out | grep "Version") - up_version=$(awk '{ print $2 }' <<< "${up_version}") - up_commit=$(cat ${RUN_DROP_DIR}/rpm-ostree-upgrade-check.out | grep "Commit") - up_commit=$(awk '{ print $2 }' <<< "${up_commit}") - upgrade_deployment_pending_reboot=$(jq --arg commit "${up_commit}" '(.deployments[0].booted == false) and (.deployments[0]."base-checksum" | tostring == $commit])' ${RUN_DROP_DIR}/rpm-ostree-status.json) - up_commit=$(echo "${up_commit}" | awk '{ print substr($0,0,6) }') - cur_version=$(jq '.deployments | map(select(.booted == true)) | .[]."version"' ${RUN_DROP_DIR}/rpm-ostree-status.json) - cur_version=$(sed -e 's/^"//' -e 's/"$//' <<< "${cur_version}") - cur_commit=$(jq '.deployments | map(select(.booted == true)) | .[]."base-checksum"' ${RUN_DROP_DIR}/rpm-ostree-status.json) - cur_commit=$(sed -e 's/^"//' -e 's/"$//' <<< "${cur_commit}") - cur_commit=$(echo "${cur_commit}" | awk '{ print substr($0,0,6) }') - - echo -e "current: ${cur_version} (${cur_commit})" - update_available_msg=$(echo -e "${ANSI_LIGHT_BLUE}available${ANSI_NC}: ${up_version} (${up_commit})") - if [ -n "${up_commit}" ]; then - if [ "${upgrade_deployment_pending_reboot}" = "true" ]; then - echo "${update_available_msg} - deployment pending next reboot" - else - echo "${update_available_msg}" - fi - fi - - if [ -n "${sec_advisories}" ]; then - sec_advisories=$(awk '{$1=""; sub(" ", " "); print}' <<< "${sec_advisories}") - sec_advisories=$(echo "${sec_advisories}" | sed -e "s/^[[:space:]]*//") - echo -e "${SUBPOINT} ${ANSI_LIGHT_RED}advisories${ANSI_NC}: ${sec_advisories}" - fi - if [ -n "${pkg_diff}" ]; then - pkg_diff=$(awk '{ $1="" ; sub(" ", " ") ; print }' <<< "${pkg_diff}") - pkg_diff=$(echo "${pkg_diff}" | sed -e "s/^[[:space:]]*//") - echo -e "${SUBPOINT} packages: ${pkg_diff}" - fi -} - -print_dnf_update_info() { - echo -e "\n[dnf]" - dnf -qC updateinfo > ${RUN_DROP_DIR}/dnf-updateinfo.out - cat ${RUN_DROP_DIR}/dnf-updateinfo.out -} - -mkdir -p /run/${MOTD_DIR_PRIVATE} -mkdir -p /run/${MOTD_DIR_PUBLIC} -mkdir -p /run/${RUN_DROP_DIR} -rm -f ${GENERATED_MOTD} - -# Get updated system information and print it to the -# generated motd -echo -e "\e[${ANSI_COLOR}m${NAME}\e[39m (${VERSION})" > ${GENERATED_MOTD} - -if [ -x "$(command -v rpm-ostree)" ]; then - set +e - print_rpm_ostree_update_info >> ${GENERATED_MOTD} - set -e -fi -if [ -x "$(command -v dnf)" ]; then - set +e - print_dnf_update_info >> ${GENERATED_MOTD} - set -e -fi - -if [[ -d "/usr/lib/${MOTD_DIR_PRIVATE}" ]]; then - cat /usr/lib/${MOTD_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_MOTD} || true -fi - -if [[ -d "/run/${MOTD_DIR_PRIVATE}" ]]; then - cat /run/${MOTD_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_MOTD} || true -fi - -if [[ -d "/etc/${MOTD_DIR_PRIVATE}" ]]; then - cat /etc/${MOTD_DIR_PRIVATE}/* 2>/dev/null >> ${GENERATED_MOTD} || true -fi diff --git a/usr/lib/tmpfiles.d/console-login-helper-messages-profile-tmpfiles.conf b/usr/lib/tmpfiles.d/console-login-helper-messages-profile-tmpfiles.conf new file mode 100644 index 0000000..36f8237 --- /dev/null +++ b/usr/lib/tmpfiles.d/console-login-helper-messages-profile-tmpfiles.conf @@ -0,0 +1 @@ +L /etc/profile.d/console-login-helper-messages-profile.sh - - - - ../../usr/share/console-login-helper-messages/console-login-helper-messages-profile.sh diff --git a/usr/lib/tmpfiles.d/coreos-profile-tmpfiles.conf b/usr/lib/tmpfiles.d/coreos-profile-tmpfiles.conf deleted file mode 100644 index 36f8237..0000000 --- a/usr/lib/tmpfiles.d/coreos-profile-tmpfiles.conf +++ /dev/null @@ -1 +0,0 @@ -L /etc/profile.d/console-login-helper-messages-profile.sh - - - - ../../usr/share/console-login-helper-messages/console-login-helper-messages-profile.sh diff --git a/usr/share/console-login-helper-messages/console-login-helper-messages-profile.sh b/usr/share/console-login-helper-messages/console-login-helper-messages-profile.sh new file mode 100755 index 0000000..11e3307 --- /dev/null +++ b/usr/share/console-login-helper-messages/console-login-helper-messages-profile.sh @@ -0,0 +1,13 @@ +# /usr/share/console-login-helper-messages/console-login-helper-messages-profile.sh + +# Only print for interactive shells. +if [[ $- == *i* ]]; then + FAILED=$(systemctl list-units --state=failed --no-legend) + + if [[ ! -z "${FAILED}" ]]; then + COUNT=$(wc -l <<<"${FAILED}") + echo "[systemd]" + echo -e "Failed Units: \033[31m${COUNT}\033[39m" + awk '{ print " " $1 }' <<<"${FAILED}" + fi +fi diff --git a/usr/share/coreos/coreos-profile.sh b/usr/share/coreos/coreos-profile.sh deleted file mode 100755 index 11e3307..0000000 --- a/usr/share/coreos/coreos-profile.sh +++ /dev/null @@ -1,13 +0,0 @@ -# /usr/share/console-login-helper-messages/console-login-helper-messages-profile.sh - -# Only print for interactive shells. -if [[ $- == *i* ]]; then - FAILED=$(systemctl list-units --state=failed --no-legend) - - if [[ ! -z "${FAILED}" ]]; then - COUNT=$(wc -l <<<"${FAILED}") - echo "[systemd]" - echo -e "Failed Units: \033[31m${COUNT}\033[39m" - awk '{ print " " $1 }' <<<"${FAILED}" - fi -fi