Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Phase 1: Foundation Infrastructure for Script Modernization #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
errnair merged 1 commit into master from errnair/phase1-foundation-infrastructure
Oct 28, 2025

Conversation

@errnair
Copy link
Owner

@errnair errnair commented Oct 28, 2025

Description

This PR establishes the foundation infrastructure for modernizing the sysadmin-shell-scripts repository. Phase 1 creates shared libraries, configuration management, comprehensive documentation, and testing infrastructure that will be used across all scripts in future phases.

Objective: Build a solid foundation for script modernization with reusable components, security best practices, and multi-OS support.

Changes

1. Shared Function Library (lib/common.sh)

  • 548 lines of reusable bash functions
  • 40+ functions covering:
    • Color output (5 functions): print_info, print_success, print_warning, print_error, print_header
    • OS detection (3 functions): detect_os, detect_os_version, get_package_manager
    • Input validation (4 functions): validate_domain, validate_ip, validate_port, validate_hostname
    • Backup utilities (2 functions): backup_file, backup_dir
    • Logging (3 functions): log_info, log_error, log_success
    • Service management (2 functions): start_and_enable, restart_service
    • Firewall management (1 function): open_firewall_port
    • Error handling (2 functions): error_exit, cleanup_on_exit
    • Dry-run support (2 functions): is_dry_run, dry_run_execute
    • Network utilities (3 functions): get_public_ip, get_private_ip, check_internet
    • File integrity (2 functions): verify_checksum, download_with_verify
    • User interaction (2 functions): confirm, read_password

2. Configuration Management (config/)

  • Global defaults (defaults.conf): Backup settings, network timeouts, security defaults
  • Template configurations for major scripts:
    • ansible.conf.example: Version, installation method, collections
    • flask.conf.example: Domain, SSL, Gunicorn settings
    • jenkins.conf.example: Java version, plugins, memory settings
    • backup.conf.example: S3/rsync, retention, encryption
  • Configuration guide (config/README.md): 226 lines with examples and troubleshooting

3. Documentation

  • Enhanced README.md (350 lines): Complete documentation with examples, compatibility matrix, troubleshooting
  • CONTRIBUTING.md (403 lines): Development guidelines, coding standards, testing requirements, PR process
  • LICENSE: MIT License for open source
  • CHANGELOG.md: Version history tracking

4. Security & Version Control

  • .gitignore (166 lines): Protects credentials, SSH keys, config files, backups
  • Secure defaults in configuration
  • Password handling guidelines

5. Testing Infrastructure

  • tests/test_common_demo.sh: Demo test script validating library functions
  • All core functions tested and passing
  • Ready for BATS integration

6. Summary Documentation

  • PHASE1_SUMMARY.md: Comprehensive implementation summary with metrics and next steps

Tests

Library Function Tests

All tests passing - Validated via tests/test_common_demo.sh

Test Coverage:

  • ✅ Color output functions (5/5)
  • ✅ OS detection (works on macOS, Linux detection ready)
  • ✅ Command existence checks
  • ✅ Input validation:
    • ✅ Valid IP: 192.168.1.1 (accepted)
    • ✅ Invalid IP: 999.999.999.999 (rejected)
    • ✅ Valid port: 8080 (accepted)
    • ✅ Invalid port: 99999 (rejected)
    • ✅ Valid hostname: myserver (accepted)
    • ✅ Invalid hostname: invalid-hostname- (rejected)
    • ✅ Valid domain: example.com (accepted)
    • ✅ Invalid domain: notadomain (rejected)
  • ✅ Version comparison
  • ✅ Dry-run mode simulation

Test Execution:

bash tests/test_common_demo.sh
# All tests pass successfully

Manual Testing

  • ✅ Library loads without errors
  • ✅ Functions work as expected
  • ✅ Configuration files parse correctly
  • ✅ Documentation renders properly

Static Analysis

  • ✅ Bash scripts use proper shebangs
  • ✅ Files have correct permissions (executable where needed)
  • ✅ No syntax errors in shell scripts

Metrics

Metric Value
Files Created 13
Files Modified 1 (README.md)
Total Lines Added ~2,500
Functions in Library 40+
Configuration Templates 5
Documentation Pages 4

Impact

  • No breaking changes - All existing scripts remain functional
  • Backward compatible - New infrastructure is additive only
  • Ready for Phase 2 - Foundation set for modernizing existing scripts

Next Steps

After this PR is merged, Phase 2 will:

  1. Fix critical security issues (password handling in create_db.sh, sync_emails.sh)
  2. Fix corrupted portcheck.py file
  3. Modernize installation scripts with common library integration
  4. Add multi-OS support across all scripts

This commit establishes the foundation for modernizing the sysadmin-shell-scripts repository with shared libraries, configuration management, comprehensive documentation, and testing infrastructure.
@errnair errnair merged commit e3636ed into master Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /