44#
55# Description:
66# This script automates the installation and configuration of RANCID (Really
7- # Awesome New Cisco confIg Differ) on RHEL 10 systems. It handles package
8- # installation, user/group creation, directory structure setup, Git repository
9- # initialization, and cron job configuration.
7+ # Awesome New Cisco confIg Differ) on RHEL 10 systems. It handles RANCID source
8+ # installation (download, compile, install), dependency installation, user/group
9+ # creation, directory structure setup, Git repository initialization, and cron
10+ # job configuration.
1011#
1112# Features:
1213# - Idempotent: Safe to run multiple times
@@ -418,9 +419,9 @@ load_env() {
418419# Installation Functions
419420# ############################################
420421
421- # Install required packages via dnf
422+ # Install required packages and RANCID from source
422423install_packages () {
423- log " Installing required packages..."
424+ log " Installing required packages and dependencies ..."
424425
425426 if ! command_exists dnf; then
426427 die " dnf package manager not found. This script requires RHEL 10 or compatible."
@@ -431,26 +432,148 @@ install_packages() {
431432 die " Failed to update OS packages"
432433 fi
433434
434- log " Installing EPEL repository..."
435- if ! dnf -y install epel-release; then
436- die " Failed to install EPEL repository"
437- fi
438-
439- log " Installing RANCID and dependencies..."
435+ log " Installing RANCID runtime dependencies..."
440436 local packages=(
441- " rancid"
442437 " git"
443438 " perl-Expect"
444439 " perl-TermReadKey"
445440 " net-snmp-utils"
446441 " openssh-clients"
447442 )
448443
444+ # Install runtime dependencies
449445 if ! dnf -y install " ${packages[@]} " ; then
450- die " Failed to install RANCID packages"
446+ die " Failed to install RANCID dependencies"
447+ fi
448+
449+ # Check if RANCID is already installed
450+ if command_exists rancid-run; then
451+ log " RANCID appears to be installed (found rancid-run command)"
452+ local version_output
453+ version_output=$( rancid-run -V 2>&1 | head -1 || true)
454+ if [[ -n " ${version_output} " ]]; then
455+ log " Version: ${version_output} "
456+ fi
457+ else
458+ log " Installing RANCID from source..."
459+ install_rancid_from_source
460+ fi
461+
462+ log " Package installation completed"
463+ }
464+
465+ # Install RANCID from source
466+ install_rancid_from_source () {
467+ log " Installing RANCID from source..."
468+
469+ # Install build prerequisites
470+ log " Installing build prerequisites..."
471+ local build_packages=(
472+ " gcc"
473+ " make"
474+ " expect"
475+ " perl-devel"
476+ )
477+
478+ if ! dnf -y install " ${build_packages[@]} " ; then
479+ die " Failed to install build prerequisites for RANCID source installation"
480+ fi
481+
482+ # Check if curl is available (required for download)
483+ if ! command_exists curl; then
484+ log " Installing curl (required for source download)..."
485+ if ! dnf -y install curl; then
486+ die " Failed to install curl, required for downloading RANCID source"
487+ fi
488+ fi
489+
490+ # Set up temporary build directory
491+ local build_dir=" /tmp/rancid-build"
492+ local rancid_version=" 3.13"
493+ local rancid_url=" http://www.shrubbery.net/pub/rancid/rancid-${rancid_version} .tar.gz"
494+ local rancid_tarball=" ${build_dir} /rancid-${rancid_version} .tar.gz"
495+ local rancid_src=" ${build_dir} /rancid-${rancid_version} "
496+
497+ # Create build directory (clean up if it exists from previous failed attempt)
498+ if [[ -d " ${build_dir} " ]]; then
499+ log " Cleaning up previous build directory..."
500+ rm -rf " ${build_dir} "
501+ fi
502+ mkdir -p " ${build_dir} "
503+
504+ # Download RANCID source
505+ log " Downloading RANCID ${rancid_version} from ${rancid_url} ..."
506+ if ! curl -L -f -o " ${rancid_tarball} " " ${rancid_url} " ; then
507+ die " Failed to download RANCID source from ${rancid_url} "
508+ fi
509+
510+ # Verify tarball was downloaded
511+ if [[ ! -f " ${rancid_tarball} " ]]; then
512+ die " RANCID tarball not found after download: ${rancid_tarball} "
451513 fi
452514
453- log " Package installation completed successfully"
515+ # Extract source
516+ log " Extracting RANCID source..."
517+ if ! tar -xzf " ${rancid_tarball} " -C " ${build_dir} " ; then
518+ die " Failed to extract RANCID source tarball"
519+ fi
520+
521+ # Verify source directory exists
522+ if [[ ! -d " ${rancid_src} " ]]; then
523+ die " RANCID source directory not found after extraction: ${rancid_src} "
524+ fi
525+
526+ # Configure, compile, and install (use subshell to avoid changing working directory)
527+ log " Configuring RANCID build..."
528+ (
529+ cd " ${rancid_src} " || die " Failed to change to RANCID source directory: ${rancid_src} "
530+
531+ if ! ./configure --prefix=/usr/local --sysconfdir=/etc/rancid; then
532+ die " Failed to configure RANCID build"
533+ fi
534+
535+ log " Compiling RANCID..."
536+ if ! make; then
537+ die " Failed to compile RANCID"
538+ fi
539+
540+ log " Installing RANCID..."
541+ if ! make install; then
542+ die " Failed to install RANCID"
543+ fi
544+ )
545+
546+ # Create symlinks in /usr/bin for PATH compatibility
547+ log " Creating symlinks in /usr/bin..."
548+ local binaries=(" rancid" " rancid-run" " clogin" )
549+ for binary in " ${binaries[@]} " ; do
550+ if [[ -f " /usr/local/bin/${binary} " ]]; then
551+ if [[ -L " /usr/bin/${binary} " ]] || [[ -f " /usr/bin/${binary} " ]]; then
552+ log " Symlink or file already exists: /usr/bin/${binary} , skipping"
553+ else
554+ ln -sf " /usr/local/bin/${binary} " " /usr/bin/${binary} "
555+ log " Created symlink: /usr/bin/${binary} -> /usr/local/bin/${binary} "
556+ fi
557+ else
558+ log_warn " Binary not found after installation: /usr/local/bin/${binary} "
559+ fi
560+ done
561+
562+ # Clean up build directory
563+ log " Cleaning up build directory..."
564+ rm -rf " ${build_dir} "
565+
566+ # Verify installation
567+ if command_exists rancid-run; then
568+ log " RANCID installed successfully from source"
569+ local version_output
570+ version_output=$( rancid-run -V 2>&1 | head -1 || true)
571+ if [[ -n " ${version_output} " ]]; then
572+ log " Version: ${version_output} "
573+ fi
574+ else
575+ die " RANCID installation completed but rancid-run command not found"
576+ fi
454577}
455578
456579# Create RANCID user and group
@@ -729,13 +852,19 @@ ${CRON_LINE}"
729852post_checks () {
730853 log " Performing post-installation validation..."
731854
732- # Verify RANCID commands are available
855+ # Verify RANCID commands are available (warn if not found, don't fail)
733856 if ! command_exists rancid-run; then
734- die " rancid-run not found on PATH after installation"
857+ log_warn " rancid-run not found on PATH"
858+ log_warn " RANCID may need to be installed from source"
859+ log_warn " See: https://www.shrubbery.net/rancid/ for installation instructions"
860+ else
861+ log " RANCID commands verified: rancid-run found"
735862 fi
736863
737864 if ! command_exists rancid; then
738- die " rancid not found on PATH after installation"
865+ log_warn " rancid command not found on PATH"
866+ else
867+ log " RANCID commands verified: rancid found"
739868 fi
740869
741870 log " Verifying ownership and permissions..."
0 commit comments