Skip to content

In case you made changes to .bashrc and bash profiles and something went wrong, you may want to revert to the default bash profile. Use this script to go back to defaults.

License

Notifications You must be signed in to change notification settings

digitalxs/BashProfileReset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Debian Logo Bash Profile Reset Script

Version 1.4.0 OS Debian 12 License GPL v3 Shell Bash

A robust utility script to safely reset bash profile configuration files to Debian 12 defaults
with automatic backups, restoration capabilities, and advanced user controls.

Buy Me A Coffee


πŸš€ Quick Start

# Download the script
wget -v https://github.com/digitalxs/BashProfileReset/raw/refs/heads/main/reset-bash-profile.sh

# Make it executable
chmod +x reset-bash-profile.sh

# Run it (replace 'username' with the target user)
sudo ./reset-bash-profile.sh username

🎯 Features

  • Automatic timestamped backups of all bash configuration files
  • Customizable backup locations
  • Backup metadata tracking
  • Preservation of file attributes and permissions
  • Dry-run mode to preview changes without applying them
  • Force mode to skip confirmation prompts
  • Verbose mode for detailed operation logging
  • Custom backup location specification
  • List all available backups for a user
  • Restore from any previous backup
  • Safe restoration process with confirmations
  • Proper permission settings on all files
  • Secure backup directories (700 permissions)
  • Detailed operation logging
  • Color-coded output for better readability
  • Clear operation summaries
  • Helpful next-step guidance
  • Command-line help system

πŸ’Ύ Installation

  1. Download the script:

    wget -v https://github.com/digitalxs/BashProfileReset/raw/refs/heads/main/reset-bash-profile.sh
  2. Make the script executable:

    chmod +x reset-bash-profile.sh
  3. Verify installation:

    ./reset-bash-profile.sh --version

πŸ“š Usage

Basic Usage

Reset a user's bash profile to defaults on Debian 12:

sudo ./reset-bash-profile.sh username

See All Available Options

sudo ./reset-bash-profile.sh --help

Perform a Dry Run (Preview Without Changes)

sudo ./reset-bash-profile.sh username --dry-run

Use Force Mode (Skip Confirmations)

sudo ./reset-bash-profile.sh username --force

Specify a Custom Backup Directory

sudo ./reset-bash-profile.sh username --backup-dir /var/backups/bash

List All Available Backups

sudo ./reset-bash-profile.sh username --list-backups

Restore From a Backup

sudo ./reset-bash-profile.sh username --restore /home/username/bash_backup_20240327_123456

Combine Multiple Options

sudo ./reset-bash-profile.sh username --verbose --backup-dir /backups --force

πŸ“‹ What the Script Does

  • Checks for root privileges
  • Validates the username exists
  • Verifies the home directory is accessible
  • Creates a timestamped backup directory
  • Backs up all bash-related configuration files
  • Creates metadata about the backup
  • Sets secure permissions on the backup
  • Removes existing bash configuration files
  • Copies default files from /etc/skel/
  • Sets appropriate ownership and permissions
  • Provides a summary of operations performed
  • Shows the backup location
  • Gives instructions for applying changes

πŸ“ Files Affected

Primary Configuration Files

  • ~/.bashrc - Main bash configuration file
  • ~/.profile - Login shell configuration
  • ~/.bash_logout - Commands executed when logging out

Additional Files (Backed Up If Present)

  • ~/.bash_aliases - Custom command aliases
  • ~/.bash_functions - User-defined bash functions
  • ~/.bash_history - Command history
  • ~/.bashrc_help - Custom help files
  • ~/.inputrc - Readline configuration
  • ~/.config/starship.toml - Starship prompt configuration

πŸ” Troubleshooting

Common Issues

  1. "Error: Please run as root"

    • Solution: Run the script with sudo
  2. "Error: User 'username' does not exist"

    • Solution: Check if the username is correct
    • Verify the user exists on the system
  3. "Warning: Could not backup/copy file"

    • Solution: Check file permissions
    • Verify the source files exist in /etc/skel/
  4. "Error: Backup directory does not exist"

    • Solution: Verify the path provided to --restore is correct
    • Use --list-backups to see available backups

Debug Techniques

  1. Run with verbose mode to see detailed operation logs:

    sudo ./reset-bash-profile.sh username --verbose
  2. Use dry-run mode to test operations without making changes:

    sudo ./reset-bash-profile.sh username --dry-run

πŸ“œ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

GPL v3 Logo

GPL v3.0 Summary:

  • You can use, modify, and distribute this software.
  • If you distribute modified versions, you must make your source code available.
  • Changes must be documented.
  • The same license applies to derived works.

πŸ‘¨β€πŸ’» Author


πŸ™ Support

If you find this script useful, consider buying me a coffee! Your support helps maintain this project and develop new features.


Report Bug β€’ Request Feature β€’ Visit Website

Made with ❀️ for the Debian community

Debian Logo

About

In case you made changes to .bashrc and bash profiles and something went wrong, you may want to revert to the default bash profile. Use this script to go back to defaults.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages