menios icon indicating copy to clipboard operation
menios copied to clipboard

Message of the Day (motd) support

Open pbalduino opened this issue 3 months ago • 0 comments

Summary

Implement a message of the day (motd) utility that displays a randomly selected message from /etc/motd when users log in or start a shell session.

Description

Add motd (message of the day) functionality to display welcome messages, system information, or tips when users log in. The utility should randomly select one message from /etc/motd and display it, with support for users to suppress display via ~/.hushlogin.

Inspiration

Idea borrowed from OpenBSD's motd system, which provides a clean way to communicate system information and welcome users.

Proposed Behavior

Display Trigger

  • Display motd when shell starts (integration with #314 .moshrc)
  • Display motd when user logs in (future login mechanism)
  • Can be invoked manually via /bin/motd command

Message Selection

  • Read messages from /etc/motd file
  • Messages separated by delimiter (e.g., --- or blank line)
  • Randomly select one message to display
  • Simple sequential display if randomization not desired

Suppression Mechanism

  • Check for ~/.hushlogin file in user's home directory
  • If .hushlogin exists, skip motd display
  • Allows users to opt out of motd without system changes

Example /etc/motd Format

Option 1: Simple (single message)

Welcome to meniOS!

System uptime: 3 days, 4 hours
Kernel version: 0.2.0

Option 2: Multiple messages (delimited)

Welcome to meniOS - A modern OS from scratch!
---
"Programs must be written for people to read, and only incidentally for machines to execute." - Abelson & Sussman
---
Tip: Use Ctrl+R for reverse command search in the shell!
---
Fun fact: meniOS can run Doom (1993)!
---
Remember: All bugs are shallow with enough eyeballs.

Implementation Details

Phase 1: Basic motd Command

  • Create /bin/motd utility
  • Read /etc/motd file
  • Display content to stdout
  • Simple, no randomization yet

Phase 2: Message Selection

  • Parse multi-message format (delimiter-separated)
  • Implement random selection using rand() (#241 ✅)
  • Seed random generator with time (time() #240 ✅)

Phase 3: .hushlogin Support

  • Check for ~/.hushlogin before display
  • Requires home directory path resolution
  • Silent skip if hushlogin exists

Phase 4: Shell Integration

  • Integrate with .moshrc (#314) for automatic display
  • Add motd call to default shell initialization
  • Respect .hushlogin in automatic context

File Locations

System Message File

  • /etc/motd - System-wide message of the day
  • Root-owned, world-readable
  • Created/maintained by administrator

User Suppression File

  • ~/.hushlogin - User-specific suppression flag
  • Empty file (existence check only)
  • Created by user to disable motd

Example Usage

Display motd

$ motd
Welcome to meniOS!

System uptime: 3 days, 4 hours
Kernel version: 0.2.0

Suppress motd

$ touch ~/.hushlogin
$ # motd will no longer display automatically

Re-enable motd

$ rm ~/.hushlogin
$ # motd will display on next login/shell

Implementation Considerations

File Format

  • Simple plain text for MVP
  • Delimiter-based multi-message support
  • No special formatting required initially
  • Future: support for ANSI colors, system variable expansion

Randomization

  • Use existing rand()/srand() from libc (#241 ✅)
  • Seed with time() for variety (#240 ✅)
  • Fallback to sequential/first message if random fails

Error Handling

  • Missing /etc/motd: silent skip (not an error)
  • Missing ~/.hushlogin: display motd (default behavior)
  • Read errors: log warning but don't block login
  • Malformed file: display what's parseable, ignore errors

Performance

  • Keep it fast - login shouldn't hang on motd
  • Limit message file size (e.g., 64 KiB max)
  • Avoid complex parsing or processing

Benefits

  • User Welcome: Friendly greeting for new users
  • System Information: Communicate uptime, version, news
  • Tips & Education: Share shell tips, keyboard shortcuts
  • Personality: Give meniOS character and charm
  • Community: Share quotes, facts, fun messages
  • Announcements: Notify users of maintenance, changes

Use Cases

Development/Testing

Welcome to meniOS Development Build!

Last build: 2025-10-19
Kernel features: buddy allocator, FAT32 writes, Doom support!

Happy hacking!

Production

meniOS v1.0 - Stable Release

Uptime: 42 days
Users online: 3
Disk usage: 45%

For support, see /usr/share/doc/README

Fun/Educational

"Talk is cheap. Show me the code." - Linus Torvalds

Did you know? meniOS implements a buddy allocator for efficient memory management!

Tip of the day: Use 'ps' to see running processes.

Dependencies

  • #193 (libc) ✅ - For file I/O, string operations
  • #240 (time()) ✅ - For random seed
  • #241 (rand()) ✅ - For message selection
  • #313 (filesystem organization) - For /etc directory structure
  • #314 (shell startup scripts) - For automatic motd integration
  • Ideally: home directory support for ~/.hushlogin

Testing

  1. Create /etc/motd with single message, verify display
  2. Create /etc/motd with multiple messages (delimiter-separated), verify random selection
  3. Create ~/.hushlogin, verify motd suppression
  4. Test with missing /etc/motd, verify silent skip
  5. Test with malformed /etc/motd, verify graceful handling
  6. Integrate with .moshrc, verify automatic display

Future Enhancements (Out of Scope)

  • Variable expansion (e.g., $USER, $HOSTNAME, $UPTIME)
  • ANSI color support for formatted messages
  • Multiple motd files (e.g., /etc/motd.d/*.motd)
  • Dynamic content generation (fortune-style)
  • Per-user custom motd overrides
  • Network-fetched motd (fetch from URL)
  • motd rotation schedule (daily/weekly/random)

Priority

Low - Nice-to-have feature, enhances user experience but not critical

Related Issues

  • #313 (Filesystem organization) - Establishes /etc directory
  • #314 (Shell startup scripts) - Provides automatic execution mechanism

Inspiration Examples

OpenBSD motd

  • Simple, clean, informative
  • Suppressible via .hushlogin
  • Administrator-controlled content

Linux motd

  • Often combined with dynamic scripts (/etc/update-motd.d/)
  • Can show system stats, package updates, etc.

FreeBSD motd

  • Traditional static message file
  • Often used for maintenance announcements

pbalduino avatar Oct 19 '25 16:10 pbalduino