test

#!/bin/bash

# Script to update SONIC configuration
# Usage: ./update_sonic_config.sh

# Exit on any error
set -e

# Configuration - no trailing slashes
target_script_dir="/srv/tftp/sonic"
source_dir="./bin/scripts"
tftp_dir="/tmp/tftp"
new_bin_file="new.bin"
link_name="one.bin"
config_file="default_config_db.json"
config_backup="${config_file}.bak"
source_config_file="config_db.json"

# Function: precheck
precheck() {
    echo "=== Running precheck ==="
    
    # Check if default_config_db.json file exists
    if [ -f "${target_script_dir}/${config_file}" ]; then
        echo "Found ${target_script_dir}/${config_file}"
    else
        echo "ERROR: ${target_script_dir}/${config_file} not found!"
        exit 1
    fi
    
    echo "Precheck completed successfully"
    echo ""
}

# Function: main
main() {
    echo "=== Running main operations ==="
    
    # Backup the default_config_db.json file
    echo "Creating backup of ${config_file}..."
    mv "${target_script_dir}/${config_file}" "${target_script_dir}/${config_backup}"
    echo "Backup created: ${config_backup}"
    
    # Copy files from ./bin/scripts/ to target directory
    echo "Copying files from ${source_dir}/ to ${target_script_dir}/..."
    if [ -d "${source_dir}" ]; then
        cp -v "${source_dir}"/* "${target_script_dir}/"
        echo "Files copied successfully"
    else
        echo "ERROR: Source directory ${source_dir} not found!"
        exit 1
    fi
    
    # Rename config_db.json to default_config_db.json
    echo "Renaming ${source_config_file} to ${config_file}..."
    if [ -f "${target_script_dir}/${source_config_file}" ]; then
        mv "${target_script_dir}/${source_config_file}" "${target_script_dir}/${config_file}"
        echo "Rename completed"
    else
        echo "WARNING: ${source_config_file} not found in target directory"
    fi
    
    # Create symbolic link
    echo "Creating symbolic link in ${tftp_dir}/..."
    # Ensure tftp directory exists
    mkdir -p "${tftp_dir}"
    
    # Change to tftp directory and create symlink
    cd "${tftp_dir}"
    ln -sf "sonic/${new_bin_file}" "${link_name}"
    echo "Symbolic link created: ${tftp_dir}/${link_name} -> sonic/${new_bin_file}"
    
    # Return to original directory
    cd - > /dev/null
    
    echo "Main operations completed successfully"
    echo ""
}

# Function: postcheck
postcheck() {
    echo "=== Running postcheck ==="
    
    # Check if symbolic link is created properly
    echo "Checking symbolic link: ${tftp_dir}/${link_name}"
    if [ -L "${tftp_dir}/${link_name}" ]; then
        # Get the target of the symlink
        link_target=$(readlink "${tftp_dir}/${link_name}")
        expected_target="sonic/${new_bin_file}"
        
        if [ "${link_target}" = "${expected_target}" ]; then
            echo "Symbolic link is correct: ${link_name} -> ${link_target}"
        else
            echo "ERROR: Symbolic link target is incorrect!"
            echo "  Expected: ${expected_target}"
            echo "  Actual: ${link_target}"
            exit 1
        fi
    else
        echo "ERROR: Symbolic link ${tftp_dir}/${link_name} not found or is not a symlink!"
        exit 1
    fi
    
    # Check if default_config_db.json file is present
    echo "Checking for ${target_script_dir}/${config_file}..."
    if [ -f "${target_script_dir}/${config_file}" ]; then
        echo "Found ${target_script_dir}/${config_file}"
        echo "File details:"
        ls -la "${target_script_dir}/${config_file}"
    else
        echo "ERROR: ${target_script_dir}/${config_file} not found!"
        exit 1
    fi
    
    echo "Postcheck completed successfully"
    echo ""
}

# Main execution
main_execution() {
    echo "========================================="
    echo "SONIC Configuration Update Script"
    echo "========================================="
    echo ""
    
    # Run functions in order
    precheck
    main
    postcheck
    
    echo "========================================="
    echo "All operations completed successfully!"
    echo "========================================="
}

# Run the main execution
main_execution

Comments

Popular posts from this blog

Modern Tamil Boy Names | மாடர்ன் ஆண் குழந்தை பெயர்கள் | Baby Names Tamil | TOP TRENDING | 2026

ஆண் குழந்தை பெயர்கள் | ப வரிசை| Tamil Names For Boys | P, B

ஆண் குழந்தை பெயர்கள் | க வரிசை| Tamil Names For Boys | K,G

ஆண் குழந்தை பெயர்கள் | ச வரிசை| Tamil Names For Boys | S, C

Tamil Baby Boy Names | ஆண் குழந்தை பெயர்கள் | Baby Names Tamil | TOP TRENDING 2026