added new feature and scripts
This commit is contained in:
592
README.md
592
README.md
@@ -1,136 +1,469 @@
|
|||||||
# Modular Bashrc Manager
|
# Modular Bashrc Manager
|
||||||
### A simple, modular, and clean way to manage your .bashrc file in Linux.
|
|
||||||
|
### A simple, modular, and clean way to manage your `.bashrc` file in Linux.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
This project provides a modular system for managing Bash scripts within the .bashrc environment. It allows users to easily enable, disable, create, and manage custom scripts through a well-structured directory layout, making the .bashrc configuration cleaner and easier to maintain.
|
`Modular Bashrc Manager` is a shell-based system designed to keep your Bash configuration clean, structured, and easy to maintain.
|
||||||
|
Instead of placing everything directly inside `.bashrc`, this project lets you split your configuration into modular scripts that are loaded automatically at shell startup.
|
||||||
|
|
||||||
|
The project includes:
|
||||||
|
|
||||||
|
- an installer
|
||||||
|
- a command-line management tool
|
||||||
|
- a modular directory layout
|
||||||
|
- default ready-to-use scripts
|
||||||
|
- a reusable colored echo utility
|
||||||
|
|
||||||
|
This makes it easier to add, remove, enable, disable, and maintain shell customizations without turning `.bashrc` into a long and messy file.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Modular Setup**: Keep your .bashrc organized by loading only necessary scripts at runtime.
|
- **Modular setup**
|
||||||
- **Script Management**: Easily create, enable, disable, and manage scripts through a simple command interface.
|
Keep `.bashrc` organized by loading only the scripts you need.
|
||||||
- **Automatic Directory Structure**: The installer automatically creates directories for managing available, enabled, removed, and required scripts.
|
|
||||||
- **Customizable Script Templates**: When creating a new script, a template with placeholders for options, variables, functions, and execution logic is provided.
|
- **Script management**
|
||||||
- **Easy Integration**: Automatically integrate with your existing .bashrc setup.
|
Create, enable, disable, remove, and modify scripts from a single command interface.
|
||||||
- **Colorful Echo (`ccecho`)**: Print colored and styled messages for better terminal output, ( usable even outside of the brc-script environment )
|
|
||||||
|
- **Automatic directory structure**
|
||||||
|
The installer creates all required folders for a modular Bash environment.
|
||||||
|
|
||||||
|
- **Default scripts included**
|
||||||
|
Three scripts are installed by default so users can start immediately.
|
||||||
|
|
||||||
|
- **Easy integration**
|
||||||
|
The project integrates with an existing Bash setup without requiring a full rewrite.
|
||||||
|
|
||||||
|
- **Reusable utility functions**
|
||||||
|
Includes `ccecho`, a colored echo helper for cleaner terminal output.
|
||||||
|
|
||||||
|
- **Clean startup behavior**
|
||||||
|
Only required scripts are loaded at shell startup, keeping startup logic predictable.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
The system adds a small loader block to your `.bashrc`.
|
||||||
|
That block sources scripts from the modular directories:
|
||||||
|
|
||||||
|
- `scripts-needed/`
|
||||||
|
Essential scripts required for the system to work.
|
||||||
|
|
||||||
|
- `scripts-enabled/`
|
||||||
|
Scripts that should be loaded at shell startup.
|
||||||
|
|
||||||
|
- `scripts-available/`
|
||||||
|
Scripts that are present but not automatically loaded.
|
||||||
|
|
||||||
|
- `scripts-removed/`
|
||||||
|
Scripts that were removed and stored as backups.
|
||||||
|
|
||||||
|
The idea is simple: keep `.bashrc` minimal, and move all additional Bash logic into dedicated modular files.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Directory Structure
|
## Directory Structure
|
||||||
|
|
||||||
After installation, the system uses the following directory layout to manage scripts:
|
After installation, the system uses the following layout:
|
||||||
|
|
||||||
- `~/.bashrc.d/`: Main directory for managing Bash scripts.
|
```text
|
||||||
- `installer/`: Contains the installer and base script.
|
~/.bashrc.d/
|
||||||
- `brc-script-install.sh`
|
├── scripts-needed/
|
||||||
- `scripts-available/`: Scripts available to be enabled.
|
│ ├── brc-script.sh
|
||||||
- `scripts-enabled/`: Symbolic links to enabled scripts.
|
│ └── ccecho.sh
|
||||||
- `scripts-needed/`: Essential scripts required for the system to work.
|
├── scripts-available/
|
||||||
- `brc-script.sh`
|
│ ├── 00_default.sh
|
||||||
- `ccecho.sh`
|
│ ├── 01_git-cli-highlitgh.sh
|
||||||
- `scripts-removed/`: Backup of removed scripts, timestamped.
|
│ └── 02_bashboard.sh
|
||||||
|
├── scripts-enabled/
|
||||||
|
└── scripts-removed/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Folder Purpose
|
||||||
|
|
||||||
|
#### `scripts-needed/`
|
||||||
|
Contains the core scripts required by the project itself. These are loaded automatically and should not normally be disabled.
|
||||||
|
|
||||||
|
#### `scripts-available/`
|
||||||
|
Contains scripts that are installed and ready to be enabled. They are available for use but are not necessarily loaded at shell startup.
|
||||||
|
|
||||||
|
#### `scripts-enabled/`
|
||||||
|
Contains the scripts that are actively enabled and sourced when Bash starts.
|
||||||
|
|
||||||
|
#### `scripts-removed/`
|
||||||
|
Stores removed scripts as backups, usually with timestamps, so they can be restored later if needed.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Default Scripts Included
|
||||||
|
|
||||||
|
The installer now copies three scripts into `scripts-available/` by default.
|
||||||
|
|
||||||
|
These scripts are included to provide immediate value and to demonstrate how the modular system can be used in practice.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### `00_default.sh` – Modular Bashrc Introduction and Migration Helper
|
||||||
|
|
||||||
|
This script is intended as a starting point for users who are moving from a traditional `.bashrc` file to a modular Bash setup.
|
||||||
|
|
||||||
|
It explains the philosophy of the project and reminds the user that the modular loader block has already been added to `.bashrc`.
|
||||||
|
|
||||||
|
#### Main purpose
|
||||||
|
|
||||||
|
- show a welcome message
|
||||||
|
- explain the modular system
|
||||||
|
- remind the user how to keep `.bashrc` clean
|
||||||
|
- provide a safe place to move old custom Bash configuration
|
||||||
|
|
||||||
|
#### What to put in this script
|
||||||
|
|
||||||
|
You can move the following content from your old `.bashrc` into `00_default.sh`:
|
||||||
|
|
||||||
|
- aliases
|
||||||
|
- functions
|
||||||
|
- exports
|
||||||
|
- prompt customizations
|
||||||
|
- shell variables
|
||||||
|
- other custom Bash logic that you want loaded automatically
|
||||||
|
|
||||||
|
#### Recommended workflow
|
||||||
|
|
||||||
|
1. Open your `.bashrc`
|
||||||
|
2. Copy your personal customizations from the old file
|
||||||
|
3. Paste them into:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
~/.bashrc.d/scripts-available/00_default.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Enable the script using:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brc-script -e
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Important note
|
||||||
|
|
||||||
|
Do **not** remove the modular loader block from `.bashrc`.
|
||||||
|
That block is required so Bash can load the modular scripts at startup.
|
||||||
|
|
||||||
|
#### Typical content of `.bashrc`
|
||||||
|
|
||||||
|
Your `.bashrc` should stay lightweight and contain mainly the modular loader block plus any absolutely necessary minimal settings.
|
||||||
|
|
||||||
|
A typical loader block looks like this:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Modular Bashrc
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-needed
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-enabled
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-available
|
||||||
|
|
||||||
|
if [ -d ~/.bashrc.d ]; then
|
||||||
|
for needed in ~/.bashrc.d/scripts-needed/*.sh; do
|
||||||
|
[ -r "$needed" ] && source "$needed"
|
||||||
|
done
|
||||||
|
unset needed
|
||||||
|
|
||||||
|
for file in ~/.bashrc.d/scripts-enabled/*.sh; do
|
||||||
|
[ -r "$file" ] && source "$file"
|
||||||
|
done
|
||||||
|
unset file
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
This keeps your shell configuration clean and maintainable.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### `01_git-cli-highlitgh.sh` – Git-Aware Prompt Enhancement
|
||||||
|
|
||||||
|
This script improves the Bash prompt by showing useful Git repository information directly in the terminal.
|
||||||
|
|
||||||
|
It is especially useful for developers who frequently work inside Git repositories and want an immediate visual overview of the repository state.
|
||||||
|
|
||||||
|
#### What it does
|
||||||
|
|
||||||
|
The script defines a `parse_git_branch()` function that detects whether the current directory is inside a Git repository. If it is, it builds a status summary for the prompt.
|
||||||
|
|
||||||
|
#### Information shown in the prompt
|
||||||
|
|
||||||
|
- current branch name
|
||||||
|
- staged changes
|
||||||
|
- modified files
|
||||||
|
- untracked files
|
||||||
|
- remote ahead/behind status
|
||||||
|
|
||||||
|
#### Visual behavior
|
||||||
|
|
||||||
|
The script uses color-coded output to help distinguish repository states:
|
||||||
|
|
||||||
|
- **green** for a clean repository
|
||||||
|
- **purple** when there are uncommitted changes
|
||||||
|
- **cyan** for ahead/behind indicators
|
||||||
|
- additional colors for staged, modified, and untracked changes
|
||||||
|
|
||||||
|
#### Example prompt
|
||||||
|
|
||||||
|
```text
|
||||||
|
user@host:~/repo(main ↑1 +2 M:1 N:3)$
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Notes
|
||||||
|
|
||||||
|
This script is useful for:
|
||||||
|
|
||||||
|
- developers
|
||||||
|
- DevOps users
|
||||||
|
- anyone working with Git directly in the terminal
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### `02_bashboard.sh` – Lightweight System Dashboard
|
||||||
|
|
||||||
|
This script displays a compact system dashboard directly in the terminal.
|
||||||
|
|
||||||
|
It is intended to give a quick overview of the machine without opening additional tools.
|
||||||
|
|
||||||
|
#### What it shows
|
||||||
|
|
||||||
|
- Linux distribution information
|
||||||
|
- hostname
|
||||||
|
- local IP addresses
|
||||||
|
- public IP address
|
||||||
|
- CPU usage
|
||||||
|
- RAM usage
|
||||||
|
- disk usage
|
||||||
|
- uptime
|
||||||
|
- load average
|
||||||
|
- available updates
|
||||||
|
- temperature, if available
|
||||||
|
|
||||||
|
#### Extra features
|
||||||
|
|
||||||
|
- Uses a cache directory in `/tmp` to avoid repeated network calls
|
||||||
|
- Avoids expensive update checks too frequently
|
||||||
|
- Can hide temperature information if the machine is a virtual machine
|
||||||
|
- Works best on Debian-based systems
|
||||||
|
|
||||||
|
#### Dependencies
|
||||||
|
|
||||||
|
This script requires:
|
||||||
|
|
||||||
|
- `curl`
|
||||||
|
- `lm-sensors`
|
||||||
|
|
||||||
|
You can install them with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
apt update && apt install curl lm-sensors
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Practical use cases
|
||||||
|
|
||||||
|
This script is useful for:
|
||||||
|
|
||||||
|
- system administration
|
||||||
|
- quick health checks
|
||||||
|
- monitoring a remote box in a terminal
|
||||||
|
- showing a terminal dashboard at login or on demand
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
The project can be installed using the included installer script.
|
||||||
|
|
||||||
### Automated Installation
|
### Automated Installation
|
||||||
|
|
||||||
1. Clone the repository:
|
1. Clone the repository:
|
||||||
```bash
|
|
||||||
git clone https://github.com/SimoLinuxDesign/Modular-Bashrc-Manager.git
|
```bash
|
||||||
cd modular-bashrc-manager/installer
|
git clone https://gitea.sld-server.org/sld-admin/Modular-Bashrc-Manager
|
||||||
```
|
cd Modular-Bashrc-Manager/installer
|
||||||
|
```
|
||||||
|
|
||||||
2. Make the installer executable and run it:
|
2. Make the installer executable and run it:
|
||||||
```bash
|
|
||||||
chmod +x brc-script-install.sh
|
```bash
|
||||||
./brc-script-install.sh
|
chmod +x brc-script-install.sh
|
||||||
```
|
./brc-script-install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### What the installer does
|
||||||
|
|
||||||
The installer will:
|
The installer will:
|
||||||
- Create the necessary directory structure: `scripts-needed`, `scripts-enabled`, `scripts-available`, and `scripts-removed`.
|
|
||||||
- Append the required configuration to your .bashrc file.
|
|
||||||
- Copy the main `brc-script.sh` script and `ccecho.sh` to `scripts-needed/`.
|
|
||||||
|
|
||||||
Reload the `.bashrc` file by running:
|
- detect or ask which user should receive the installation
|
||||||
|
- create the modular directory structure
|
||||||
|
- back up the existing `.bashrc`
|
||||||
|
- append the required loader block to `.bashrc`
|
||||||
|
- copy the project files into `~/.bashrc.d/`
|
||||||
|
- copy the three default scripts into `scripts-available/`
|
||||||
|
- reload the shell configuration
|
||||||
|
|
||||||
|
3. Reload `.bashrc` if needed:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
source ~/.bashrc
|
source ~/.bashrc
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Manual Installation
|
### Manual Installation
|
||||||
|
|
||||||
1. Copy the `brc-script.sh` and `ccecho.sh` files to the `~/.bashrc.d/scripts-needed/` folder:
|
If you prefer to install the project manually, you can do it step by step.
|
||||||
```bash
|
|
||||||
cp brc-script.sh ccecho.sh ~/.bashrc.d/scripts-needed/
|
|
||||||
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.sh ~/.bashrc.d/scripts-needed/ccecho.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Append the following lines to your `.bashrc` file:
|
#### 1. Create the directory structure
|
||||||
```bash
|
|
||||||
# Modular Bashrc
|
|
||||||
if [ -d ~/.bashrc.d ]; then
|
|
||||||
for needed in ~/.bashrc.d/scripts-needed/*.sh; do
|
|
||||||
[ -r "$needed" ] && source "$needed"
|
|
||||||
done
|
|
||||||
unset needed
|
|
||||||
for file in ~/.bashrc.d/scripts-enabled/*.sh; do
|
|
||||||
[ -r "$file" ] && source "$file"
|
|
||||||
done
|
|
||||||
unset file
|
|
||||||
fi
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Create the necessary directories:
|
```bash
|
||||||
```bash
|
mkdir -p ~/.bashrc.d/scripts-needed
|
||||||
mkdir -p ~/.bashrc.d/scripts-needed ~/.bashrc.d/scripts-enabled ~/.bashrc.d/scripts-available ~/.bashrc.d/scripts-removed
|
mkdir -p ~/.bashrc.d/scripts-enabled
|
||||||
```
|
mkdir -p ~/.bashrc.d/scripts-available
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-removed
|
||||||
|
```
|
||||||
|
|
||||||
4. Reload `.bashrc`:
|
#### 2. Copy the core scripts into `scripts-needed/`
|
||||||
```bash
|
|
||||||
source ~/.bashrc
|
```bash
|
||||||
```
|
cp brc-script.sh ccecho.sh ~/.bashrc.d/scripts-needed/
|
||||||
|
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.sh ~/.bashrc.d/scripts-needed/ccecho.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. Add the modular loader block to `.bashrc`
|
||||||
|
|
||||||
|
Append this block to the end of your `.bashrc` file:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Modular Bashrc
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-needed
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-enabled
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-available
|
||||||
|
|
||||||
|
if [ -d ~/.bashrc.d ]; then
|
||||||
|
for needed in ~/.bashrc.d/scripts-needed/*.sh; do
|
||||||
|
[ -r "$needed" ] && source "$needed"
|
||||||
|
done
|
||||||
|
unset needed
|
||||||
|
|
||||||
|
for file in ~/.bashrc.d/scripts-enabled/*.sh; do
|
||||||
|
[ -r "$file" ] && source "$file"
|
||||||
|
done
|
||||||
|
unset file
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4. Copy the default scripts into `scripts-available/`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp 00_default.sh 01_git-cli-highlitgh.sh 02_bashboard.sh ~/.bashrc.d/scripts-available/
|
||||||
|
ln -s ~/.bashrc.d/scripts-available/00_default.sh ~/.bashrc.d/scripts-enabled/00_default.sh
|
||||||
|
ln -s ~/.bashrc.d/scripts-available/01_git-cli-highlitgh.sh ~/.bashrc.d/scripts-enabled/01_git-cli-highlitgh.sh
|
||||||
|
ln -s ~/.bashrc.d/scripts-available/02_bashboard.sh ~/.bashrc.d/scripts-enabled/02_bashboard.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5. Reload the shell
|
||||||
|
|
||||||
|
```bash
|
||||||
|
source ~/.bashrc
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
The `brc-script.sh` script provides a series of commands to manage your .bashrc scripts:
|
The main management tool is `brc-script.sh`.
|
||||||
|
|
||||||
- `-c` : Create a new script in the `scripts-available/` folder.
|
It can be used to manage scripts stored in the modular directories.
|
||||||
- `-m` : Modify an existing script.
|
|
||||||
- `-l` : List all available and enabled scripts.
|
|
||||||
- `-e` : Enable a script from the `scripts-available/` folder.
|
|
||||||
- `-d` : Disable an enabled script.
|
|
||||||
- `-r` : Remove a script, backing it up in `scripts-removed/`.
|
|
||||||
|
|
||||||
### Example Commands
|
### Common commands
|
||||||
|
|
||||||
- Create a new script:
|
- `brc-script -c`
|
||||||
```bash
|
Create a new script in `scripts-available/`
|
||||||
brc-script -c
|
|
||||||
```
|
|
||||||
|
|
||||||
- List all available scripts:
|
- `brc-script -m`
|
||||||
```bash
|
Modify an existing script
|
||||||
brc-script -l
|
|
||||||
```
|
|
||||||
|
|
||||||
- Enable a script:
|
- `brc-script -l`
|
||||||
```bash
|
List all available and enabled scripts
|
||||||
brc-script -e
|
|
||||||
```
|
|
||||||
|
|
||||||
- Disable a script:
|
- `brc-script -e`
|
||||||
```bash
|
Enable a script from `scripts-available/`
|
||||||
brc-script -d
|
|
||||||
```
|
|
||||||
|
|
||||||
- Remove a script:
|
- `brc-script -d`
|
||||||
```bash
|
Disable an enabled script
|
||||||
brc-script -r
|
|
||||||
```
|
- `brc-script -r`
|
||||||
|
Remove a script and store it in `scripts-removed/`
|
||||||
|
|
||||||
|
### Example usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brc-script -c
|
||||||
|
brc-script -l
|
||||||
|
brc-script -e
|
||||||
|
brc-script -d
|
||||||
|
brc-script -r
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## How to Use `00_default.sh` Correctly
|
||||||
|
|
||||||
|
`00_default.sh` is the ideal place to move your personal Bash customizations.
|
||||||
|
|
||||||
|
### Move here from your old `.bashrc`
|
||||||
|
|
||||||
|
You can place inside `00_default.sh`:
|
||||||
|
|
||||||
|
- alias definitions
|
||||||
|
- functions
|
||||||
|
- environment variables
|
||||||
|
- exports
|
||||||
|
- shell helpers
|
||||||
|
- custom startup commands
|
||||||
|
|
||||||
|
### Keep out of `.bashrc`
|
||||||
|
|
||||||
|
The following should stay out of the main `.bashrc` file as much as possible:
|
||||||
|
|
||||||
|
- large alias blocks
|
||||||
|
- long function definitions
|
||||||
|
- extra startup logic
|
||||||
|
- custom prompts
|
||||||
|
- project-specific utilities
|
||||||
|
|
||||||
|
### Recommended structure
|
||||||
|
|
||||||
|
Your `.bashrc` should contain:
|
||||||
|
|
||||||
|
- the modular loader block
|
||||||
|
- only the minimum required shell settings
|
||||||
|
|
||||||
|
Everything else should live in modular scripts such as `00_default.sh`.
|
||||||
|
|
||||||
|
This approach makes your shell configuration:
|
||||||
|
|
||||||
|
- easier to read
|
||||||
|
- easier to debug
|
||||||
|
- easier to backup
|
||||||
|
- easier to share between machines
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Extra Utilities
|
## Extra Utilities
|
||||||
|
|
||||||
### `ccecho`: Colorful Echo for Enhanced Output
|
### `ccecho` – Colored Echo for Better Terminal Output
|
||||||
|
|
||||||
The project includes a utility script `ccecho.sh` located in `scripts-needed/`, which defines a function `ccecho`. This command allows you to print styled and colored messages to the terminal.
|
The project includes a reusable utility script called `ccecho.sh`, located in `scripts-needed/`.
|
||||||
|
|
||||||
#### Usage
|
It defines a `ccecho` function for printing styled and colored text to the terminal.
|
||||||
|
|
||||||
|
#### Example usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ccecho -t green -b black -s bold "Success!"
|
ccecho -t green -b black -s bold "Success!"
|
||||||
@@ -138,37 +471,94 @@ ccecho -t red -s underline "Error!"
|
|||||||
ccecho "Normal message without styling"
|
ccecho "Normal message without styling"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Available Text Colors
|
#### Available text colors
|
||||||
`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `bblack`, `bred`, `bgreen`, `byellow`, `bblue`, `bmagenta`, `bcyan`, `bwhite`
|
|
||||||
|
|
||||||
#### Background Colors
|
- `black`
|
||||||
Same as above, applied with `-b`
|
- `red`
|
||||||
|
- `green`
|
||||||
|
- `yellow`
|
||||||
|
- `blue`
|
||||||
|
- `magenta`
|
||||||
|
- `cyan`
|
||||||
|
- `white`
|
||||||
|
- `bblack`
|
||||||
|
- `bred`
|
||||||
|
- `bgreen`
|
||||||
|
- `byellow`
|
||||||
|
- `bblue`
|
||||||
|
- `bmagenta`
|
||||||
|
- `bcyan`
|
||||||
|
- `bwhite`
|
||||||
|
|
||||||
|
#### Background colors
|
||||||
|
|
||||||
|
The same color names can be used with `-b`.
|
||||||
|
|
||||||
#### Styles
|
#### Styles
|
||||||
`bold`, `dim`, `italic`, `underline`, `blink`, `reverse`, `hidden`, `strike`
|
|
||||||
|
|
||||||
#### Make `ccecho` Globally Available
|
- `bold`
|
||||||
|
- `dim`
|
||||||
|
- `italic`
|
||||||
|
- `underline`
|
||||||
|
- `blink`
|
||||||
|
- `reverse`
|
||||||
|
- `hidden`
|
||||||
|
- `strike`
|
||||||
|
|
||||||
If you'd like to use `ccecho` in other terminal sessions or scripts, you can source it in your `.bashrc`:
|
#### Make `ccecho` available in other sessions
|
||||||
|
|
||||||
|
If you want to use `ccecho` in other terminal sessions or scripts, source it from `.bashrc`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
source ~/.bashrc.d/scripts-needed/ccecho.sh
|
source ~/.bashrc.d/scripts-needed/ccecho.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Why Use This System?
|
## Why Use This System?
|
||||||
|
|
||||||
Managing a large .bashrc file can become unmanageable, especially when adding multiple custom commands or functions. This system offers a structured approach to handle modular scripts, making it easier to enable or disable specific configurations without manually editing the .bashrc file each time.
|
Managing a large `.bashrc` file can quickly become difficult, especially when multiple aliases, functions, and startup commands are added over time.
|
||||||
|
|
||||||
|
This system solves that problem by separating your Bash configuration into small, focused files.
|
||||||
|
|
||||||
### Benefits
|
### Benefits
|
||||||
|
|
||||||
- **Organization**: Keep your .bashrc clean and easy to maintain by separating scripts.
|
- **Organization**
|
||||||
- **Simplicity**: Use simple commands to manage scripts without editing .bashrc directly.
|
Keep your shell configuration structured and easier to understand.
|
||||||
- **Safety**: Removed scripts are safely backed up in the `scripts-removed/` directory.
|
|
||||||
|
- **Maintainability**
|
||||||
|
Update one script without editing a huge `.bashrc` file.
|
||||||
|
|
||||||
|
- **Safety**
|
||||||
|
Removed scripts are backed up in `scripts-removed/`.
|
||||||
|
|
||||||
|
- **Flexibility**
|
||||||
|
Enable or disable features without rewriting your shell setup.
|
||||||
|
|
||||||
|
- **Reusability**
|
||||||
|
Share modular scripts across systems more easily.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Contributions are welcome! If you find any bugs or have suggestions for improvements, feel free to open an issue or submit a pull request.
|
Contributions are welcome.
|
||||||
|
|
||||||
|
If you find bugs, edge cases, or improvements, feel free to open an issue or submit a pull request.
|
||||||
|
|
||||||
|
Possible improvements include:
|
||||||
|
|
||||||
|
- support for more shells
|
||||||
|
- richer installer feedback
|
||||||
|
- logging and debug mode
|
||||||
|
- better script validation
|
||||||
|
- package-based installation
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.html).
|
This project is licensed under the GNU General Public License v3.0.
|
||||||
|
|
||||||
|
For more information, see the [GPL v3 license](https://www.gnu.org/licenses/gpl-3.0.html).
|
||||||
|
|
||||||
|
|||||||
174
README.md.backup
174
README.md.backup
@@ -1,174 +0,0 @@
|
|||||||
# Modular Bashrc Manager
|
|
||||||
### A simple, modular, and clean way to manage your .bashrc file in Linux.
|
|
||||||
---
|
|
||||||
|
|
||||||
This project provides a modular system for managing Bash scripts within the .bashrc environment. It allows users to easily enable, disable, create, and manage custom scripts through a well-structured directory layout, making the .bashrc configuration cleaner and easier to maintain.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Modular Setup**: Keep your .bashrc organized by loading only necessary scripts at runtime.
|
|
||||||
- **Script Management**: Easily create, enable, disable, and manage scripts through a simple command interface.
|
|
||||||
- **Automatic Directory Structure**: The installer automatically creates directories for managing available, enabled, removed, and required scripts.
|
|
||||||
- **Customizable Script Templates**: When creating a new script, a template with placeholders for options, variables, functions, and execution logic is provided.
|
|
||||||
- **Easy Integration**: Automatically integrate with your existing .bashrc setup.
|
|
||||||
- **Colorful Echo (`ccecho`)**: Print colored and styled messages for better terminal output, ( usable even outside of the brc-script environment )
|
|
||||||
|
|
||||||
## Directory Structure
|
|
||||||
|
|
||||||
After installation, the system uses the following directory layout to manage scripts:
|
|
||||||
|
|
||||||
- `~/.bashrc.d/`: Main directory for managing Bash scripts.
|
|
||||||
- `installer/`: Contains the installer and base script.
|
|
||||||
- `brc-script-install.sh`
|
|
||||||
- `scripts-available/`: Scripts available to be enabled.
|
|
||||||
- `scripts-enabled/`: Symbolic links to enabled scripts.
|
|
||||||
- `scripts-needed/`: Essential scripts required for the system to work.
|
|
||||||
- `brc-script.sh`
|
|
||||||
- `ccecho.sh`
|
|
||||||
- `scripts-removed/`: Backup of removed scripts, timestamped.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
### Automated Installation
|
|
||||||
|
|
||||||
1. Clone the repository:
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/your-repo/modular-bashrc-manager.git
|
|
||||||
cd modular-bashrc-manager/installer
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Make the installer executable and run it:
|
|
||||||
```bash
|
|
||||||
chmod +x brc-script-install.sh
|
|
||||||
./brc-script-install.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
The installer will:
|
|
||||||
- Create the necessary directory structure: `scripts-needed`, `scripts-enabled`, `scripts-available`, and `scripts-removed`.
|
|
||||||
- Append the required configuration to your .bashrc file.
|
|
||||||
- Copy the main `brc-script.sh` script and `ccecho.sh` to `scripts-needed/`.
|
|
||||||
|
|
||||||
Reload the `.bashrc` file by running:
|
|
||||||
```bash
|
|
||||||
source ~/.bashrc
|
|
||||||
```
|
|
||||||
|
|
||||||
### Manual Installation
|
|
||||||
|
|
||||||
1. Copy the `brc-script.sh` and `ccecho.sh` files to the `~/.bashrc.d/scripts-needed/` folder:
|
|
||||||
```bash
|
|
||||||
cp brc-script.sh ccecho.sh ~/.bashrc.d/scripts-needed/
|
|
||||||
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.sh ~/.bashrc.d/scripts-needed/ccecho.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Append the following lines to your `.bashrc` file:
|
|
||||||
```bash
|
|
||||||
# Modular Bashrc
|
|
||||||
if [ -d ~/.bashrc.d ]; then
|
|
||||||
for needed in ~/.bashrc.d/scripts-needed/*.sh; do
|
|
||||||
[ -r "$needed" ] && source "$needed"
|
|
||||||
done
|
|
||||||
unset needed
|
|
||||||
for file in ~/.bashrc.d/scripts-enabled/*.sh; do
|
|
||||||
[ -r "$file" ] && source "$file"
|
|
||||||
done
|
|
||||||
unset file
|
|
||||||
fi
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Create the necessary directories:
|
|
||||||
```bash
|
|
||||||
mkdir -p ~/.bashrc.d/scripts-needed ~/.bashrc.d/scripts-enabled ~/.bashrc.d/scripts-available ~/.bashrc.d/scripts-removed
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Reload `.bashrc`:
|
|
||||||
```bash
|
|
||||||
source ~/.bashrc
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
The `brc-script.sh` script provides a series of commands to manage your .bashrc scripts:
|
|
||||||
|
|
||||||
- `-c` : Create a new script in the `scripts-available/` folder.
|
|
||||||
- `-m` : Modify an existing script.
|
|
||||||
- `-l` : List all available and enabled scripts.
|
|
||||||
- `-e` : Enable a script from the `scripts-available/` folder.
|
|
||||||
- `-d` : Disable an enabled script.
|
|
||||||
- `-r` : Remove a script, backing it up in `scripts-removed/`.
|
|
||||||
|
|
||||||
### Example Commands
|
|
||||||
|
|
||||||
- Create a new script:
|
|
||||||
```bash
|
|
||||||
brc-script -c
|
|
||||||
```
|
|
||||||
|
|
||||||
- List all available scripts:
|
|
||||||
```bash
|
|
||||||
brc-script -l
|
|
||||||
```
|
|
||||||
|
|
||||||
- Enable a script:
|
|
||||||
```bash
|
|
||||||
brc-script -e
|
|
||||||
```
|
|
||||||
|
|
||||||
- Disable a script:
|
|
||||||
```bash
|
|
||||||
brc-script -d
|
|
||||||
```
|
|
||||||
|
|
||||||
- Remove a script:
|
|
||||||
```bash
|
|
||||||
brc-script -r
|
|
||||||
```
|
|
||||||
|
|
||||||
## Extra Utilities
|
|
||||||
|
|
||||||
### `ccecho`: Colorful Echo for Enhanced Output
|
|
||||||
|
|
||||||
The project includes a utility script `ccecho.sh` located in `scripts-needed/`, which defines a function `ccecho`. This command allows you to print styled and colored messages to the terminal.
|
|
||||||
|
|
||||||
#### Usage
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ccecho -t green -b black -s bold "Success!"
|
|
||||||
ccecho -t red -s underline "Error!"
|
|
||||||
ccecho "Normal message without styling"
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Available Text Colors
|
|
||||||
`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `bblack`, `bred`, `bgreen`, `byellow`, `bblue`, `bmagenta`, `bcyan`, `bwhite`
|
|
||||||
|
|
||||||
#### Background Colors
|
|
||||||
Same as above, applied with `-b`
|
|
||||||
|
|
||||||
#### Styles
|
|
||||||
`bold`, `dim`, `italic`, `underline`, `blink`, `reverse`, `hidden`, `strike`
|
|
||||||
|
|
||||||
#### Make `ccecho` Globally Available
|
|
||||||
|
|
||||||
If you'd like to use `ccecho` in other terminal sessions or scripts, you can source it in your `.bashrc`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
source ~/.bashrc.d/scripts-needed/ccecho.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
## Why Use This System?
|
|
||||||
|
|
||||||
Managing a large .bashrc file can become unmanageable, especially when adding multiple custom commands or functions. This system offers a structured approach to handle modular scripts, making it easier to enable or disable specific configurations without manually editing the .bashrc file each time.
|
|
||||||
|
|
||||||
### Benefits
|
|
||||||
|
|
||||||
- **Organization**: Keep your .bashrc clean and easy to maintain by separating scripts.
|
|
||||||
- **Simplicity**: Use simple commands to manage scripts without editing .bashrc directly.
|
|
||||||
- **Safety**: Removed scripts are safely backed up in the `scripts-removed/` directory.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Contributions are welcome! If you find any bugs or have suggestions for improvements, feel free to open an issue or submit a pull request.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This project is licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.html).
|
|
||||||
27
installer/00_default.sh
Normal file
27
installer/00_default.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
echo "Welcome to the Modular Bashrc script!"
|
||||||
|
echo "In order to keep more clean as possibile you file bashrc, please copy all the bashrc (everything abot the beginning of the following entries:"
|
||||||
|
echo "--------------------------------------------------------------"
|
||||||
|
echo '
|
||||||
|
# Modular Bashrc
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-needed
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-enabled
|
||||||
|
mkdir -p ~/.bashrc.d/scripts-available
|
||||||
|
if [ -d ~/.bashrc.d ]; then
|
||||||
|
for needed in ~/.bashrc.d/scripts-needed/*.sh; do
|
||||||
|
[ -r "$needed" ] && source "$needed"
|
||||||
|
done
|
||||||
|
unset needed
|
||||||
|
for file in ~/.bashrc.d/scripts-enabled/*.sh; do
|
||||||
|
[ -r "$file" ] && source "$file"
|
||||||
|
done
|
||||||
|
unset file
|
||||||
|
|
||||||
|
fi'
|
||||||
|
echo "---------------------------------------------------------------"
|
||||||
|
echo "in the ~/.bashrc.d/script-available/00_default.sh"
|
||||||
|
echo "(Please note that this bit has been added once you installed the Modular Bashrc!)"
|
||||||
|
echo ""
|
||||||
|
echo "This way, you .bashrc will be keeped clean and tidy!"
|
||||||
|
echo "Enjoy!"
|
||||||
|
echo "Simone Cusano!"
|
||||||
|
echo "https://sld-server.org"
|
||||||
52
installer/01_git-cli-highlitgh.sh
Normal file
52
installer/01_git-cli-highlitgh.sh
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
parse_git_branch() {
|
||||||
|
if git rev-parse --is-inside-work-tree &>/dev/null; then
|
||||||
|
|
||||||
|
status_output=$(git status --porcelain --branch 2>/dev/null)
|
||||||
|
|
||||||
|
branch=$(echo "$status_output" | head -n1 | sed -E 's/^## ([^ .]+).*/\1/')
|
||||||
|
ahead=$(echo "$status_output" | grep -o 'ahead [0-9]*' | awk '{print $2}')
|
||||||
|
behind=$(echo "$status_output" | grep -o 'behind [0-9]*' | awk '{print $2}')
|
||||||
|
|
||||||
|
staged=$(echo "$status_output" | grep -E '^[A-Z]' | wc -l)
|
||||||
|
modified=$(echo "$status_output" | grep -E '^.[A-Z]' | wc -l)
|
||||||
|
untracked=$(echo "$status_output" | grep -E '^\?\?' | wc -l)
|
||||||
|
|
||||||
|
GREEN_BOLD="\[\033[1;32m\]"
|
||||||
|
PURPLE_BOLD="\[\033[1;35m\]"
|
||||||
|
YELLOW_BOLD="\[\033[1;33m\]"
|
||||||
|
RED_BOLD="\[\033[1;31m\]"
|
||||||
|
CYAN_BOLD="\[\033[1;36m\]"
|
||||||
|
RESET="\[\033[0m\]"
|
||||||
|
|
||||||
|
git_status=""
|
||||||
|
|
||||||
|
[ "$staged" -gt 0 ] && git_status="${git_status}${GREEN_BOLD}+${staged}${RESET} "
|
||||||
|
[ "$modified" -gt 0 ] && git_status="${git_status}${YELLOW_BOLD}M:${modified}${RESET} "
|
||||||
|
[ "$untracked" -gt 0 ] && git_status="${git_status}${RED_BOLD}N:${untracked}${RESET} "
|
||||||
|
|
||||||
|
# Remote State
|
||||||
|
remote_status=""
|
||||||
|
[ -n "$ahead" ] && remote_status="${remote_status}${CYAN_BOLD}↑${ahead}${RESET}"
|
||||||
|
[ -n "$behind" ] && remote_status="${remote_status}${CYAN_BOLD}↓${behind}${RESET}"
|
||||||
|
|
||||||
|
# Repo cleaning?
|
||||||
|
if [ "$staged" -eq 0 ] && [ "$modified" -eq 0 ] && [ "$untracked" -eq 0 ]; then
|
||||||
|
branch_display="${GREEN_BOLD}${branch}${RESET}"
|
||||||
|
else
|
||||||
|
branch_display="${PURPLE_BOLD}${branch}${RESET}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Final Building
|
||||||
|
output="(${branch_display}"
|
||||||
|
|
||||||
|
[ -n "$remote_status" ] && output="${output} ${remote_status}"
|
||||||
|
[ -n "$git_status" ] && output="${output} ${git_status}"
|
||||||
|
|
||||||
|
output=$(echo "$output" | sed 's/ $//')
|
||||||
|
output="${output})"
|
||||||
|
|
||||||
|
printf "%s" "$output"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
PROMPT_COMMAND='PS1="\[\033[1;32m\]\u\[\033[0m\]@\[\033[1;34m\]\h\[\033[0m\]:\[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)\$ "'
|
||||||
178
installer/02_bashboard.sh
Normal file
178
installer/02_bashboard.sh
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
############# DEPENDENCIES #############
|
||||||
|
|
||||||
|
# - Debian Based OS (for now)
|
||||||
|
# - curl
|
||||||
|
# - lm-sensors
|
||||||
|
# apt update && apt install curl lm-sensors
|
||||||
|
|
||||||
|
############################################
|
||||||
|
|
||||||
|
colorize() {
|
||||||
|
local value=$1
|
||||||
|
local green_limit=$2
|
||||||
|
local yellow_limit=$3
|
||||||
|
|
||||||
|
if [ "$value" -lt "$green_limit" ]; then
|
||||||
|
echo -e "${GREEN}${value}${NC}"
|
||||||
|
elif [ "$value" -lt "$yellow_limit" ]; then
|
||||||
|
echo -e "${YELLOW}${value}${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}${value}${NC}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function dashboard_fast() {
|
||||||
|
#### CHANGABLE OPTIONS ####
|
||||||
|
ISTHISVM=0 # Change to 1 if this is a VM. This will remove the temperature bit.
|
||||||
|
MIN_CHECK_IP=30 # Change this value to set the timing cache for checking the public IP
|
||||||
|
MIN_CHECK_UPDATE=120 # Change this value to set the timing cache for checking updates.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Colors ####
|
||||||
|
GREEN="\e[32m"
|
||||||
|
YELLOW="\e[33m"
|
||||||
|
RED="\e[31m"
|
||||||
|
CYAN="\e[36m"
|
||||||
|
BOLD="\e[1m"
|
||||||
|
NC="\e[0m" # reset
|
||||||
|
|
||||||
|
|
||||||
|
#### Cache ####
|
||||||
|
CACHE_DIR="/tmp/.dashboard_cache"
|
||||||
|
mkdir -p "$CACHE_DIR"
|
||||||
|
|
||||||
|
#### Overview ####
|
||||||
|
echo -e "${CYAN}========================================${NC}"
|
||||||
|
echo -e "${BOLD} 🖥️ SYSTEM OVERVIEW${NC}"
|
||||||
|
echo -e "${CYAN}========================================${NC}"
|
||||||
|
|
||||||
|
#### OS Informations Include ####
|
||||||
|
source /etc/os-release
|
||||||
|
|
||||||
|
|
||||||
|
#### OS info ###
|
||||||
|
echo -e "${CYAN}DISTRO:${NC} $PRETTY_NAME"
|
||||||
|
echo -e "${CYAN}ID:${NC} $ID"
|
||||||
|
echo -e "${CYAN}VERSION:${NC} $VERSION"
|
||||||
|
echo -e "${CYAN}URL:${NC} $HOME_URL"
|
||||||
|
echo -e "${CYAN}BUGS_URL:${NC} $BUG_REPORT_URL"
|
||||||
|
echo -e "${CYAN}========================================${NC}"
|
||||||
|
|
||||||
|
#### Hostname ####
|
||||||
|
echo "📛 $(hostname)"
|
||||||
|
|
||||||
|
|
||||||
|
#### Local IP ####
|
||||||
|
LOCAL_IPS=$(hostname -I 2>/dev/null | xargs)
|
||||||
|
PRIMARY_IP=$(echo "$LOCAL_IPS" | awk '{print $1}')
|
||||||
|
|
||||||
|
if [ -z "$LOCAL_IPS" ]; then
|
||||||
|
echo "🏠 Local IP: NOT AVAILABLE (no network?)"
|
||||||
|
echo "🌐 Web UI: NOT AVAILABLE"
|
||||||
|
else
|
||||||
|
echo "🏠 Local IP: $LOCAL_IPS"
|
||||||
|
echo "🌐 Web UI: http://$PRIMARY_IP:9090"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#### Public IP ####
|
||||||
|
if [ -f "$CACHE_DIR/public_ip" ] && find "$CACHE_DIR/public_ip" -mmin -$MIN_CHECK_IP | grep -q .; then
|
||||||
|
PUBLIC_IP=$(cat "$CACHE_DIR/public_ip")
|
||||||
|
else
|
||||||
|
PUBLIC_IP=$(timeout 2 curl -s ifconfig.me 2>/dev/null)
|
||||||
|
if [ -n "$PUBLIC_IP" ]; then
|
||||||
|
echo "$PUBLIC_IP" > "$CACHE_DIR/public_ip"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$PUBLIC_IP" ]; then
|
||||||
|
echo "🌍 Public IP: NOT AVAILABLE (no internet?)"
|
||||||
|
else
|
||||||
|
echo "🌍 Public IP: $PUBLIC_IP"
|
||||||
|
fi
|
||||||
|
#echo ""
|
||||||
|
echo -e "${CYAN} .................................. ${NC}"
|
||||||
|
|
||||||
|
#### Cpu ####
|
||||||
|
LOAD=$(awk '{print $1}' /proc/loadavg)
|
||||||
|
CPU_PCT=$(awk -v l="$LOAD" -v n="$(nproc)" 'BEGIN {printf "%d", (l*100/n)}')
|
||||||
|
CPU_COLOR=$(colorize "$CPU_PCT" 50 80)
|
||||||
|
echo -e "🧠 CPU: ${CPU_COLOR}%"
|
||||||
|
|
||||||
|
|
||||||
|
#### Ram ####
|
||||||
|
read MEM_TOTAL MEM_USED <<< $(free -m | awk '/Mem:/ {print $2, $3}')
|
||||||
|
MEM_PCT=$((MEM_USED * 100 / MEM_TOTAL))
|
||||||
|
MEM_COLOR=$(colorize "$MEM_PCT" 50 80)
|
||||||
|
echo -e "💾 RAM: ${MEM_COLOR}% (${MEM_USED}/${MEM_TOTAL}MB)"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Diskspace ####
|
||||||
|
DISK_PCT=$(df / | awk 'NR==2 {gsub("%",""); print $5}')
|
||||||
|
DISK_COLOR=$(colorize "$DISK_PCT" 50 80)
|
||||||
|
DISK=$(df -h / | awk 'NR==2 {print $3 "/" $2}')
|
||||||
|
echo -e "📦 Disk: ${DISK} (${DISK_COLOR}%)"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Uptime ####
|
||||||
|
echo "⏱️ Uptime: $(awk '{printf "%dd %dh %dm", $1/86400, ($1%86400)/3600, ($1%3600)/60}' /proc/uptime)"
|
||||||
|
|
||||||
|
|
||||||
|
#### Load Avarage ####
|
||||||
|
echo "📊 Load avg: $(awk '{print $1, $2, $3}' /proc/loadavg)"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Updates ####
|
||||||
|
if command -v apt >/dev/null 2>&1; then
|
||||||
|
if [ -f "$CACHE_DIR/updates" ] && find "$CACHE_DIR/updates" -mmin -$MIN_CHECK_UPDATE | grep -q .; then
|
||||||
|
UPDATES=$(cat "$CACHE_DIR/updates")
|
||||||
|
else
|
||||||
|
UPDATES=$(apt list --upgradable 2>/dev/null | wc -l)
|
||||||
|
UPDATES=$((UPDATES - 1))
|
||||||
|
echo "$UPDATES" > "$CACHE_DIR/updates"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## 🎨 Dinamic Color ##
|
||||||
|
if [ "$UPDATES" -eq 0 ]; then
|
||||||
|
UPD_COLOR="${GREEN}${UPDATES}${NC}"
|
||||||
|
elif [ "$UPDATES" -le 20 ]; then
|
||||||
|
UPD_COLOR="${YELLOW}${UPDATES}${NC}"
|
||||||
|
else
|
||||||
|
UPD_COLOR="${RED}${UPDATES}${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "📦 Updates: $UPD_COLOR"
|
||||||
|
else
|
||||||
|
echo "📦 Updates: N/A"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Temperature ####
|
||||||
|
if [ $ISTHISVM -ne 1 ]; then
|
||||||
|
if [ -f /sys/class/thermal/thermal_zone0/temp ]; then
|
||||||
|
TEMP_RAW=$(cat /sys/class/thermal/thermal_zone0/temp)
|
||||||
|
TEMP=$((TEMP_RAW/1000))
|
||||||
|
|
||||||
|
if [ "$TEMP" -lt 50 ]; then
|
||||||
|
TEMP_COLOR="${GREEN}${TEMP}°C${NC}"
|
||||||
|
elif [ "$TEMP" -lt 70 ]; then
|
||||||
|
TEMP_COLOR="${YELLOW}${TEMP}°C${NC}"
|
||||||
|
else
|
||||||
|
TEMP_COLOR="${RED}${TEMP}°C${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "🌡️ Temp: $TEMP_COLOR"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${CYAN}========================================${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
dashboard_fast
|
||||||
@@ -1,136 +1,172 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
clear
|
|
||||||
user=$(whoami) # Remove the extra space
|
|
||||||
|
|
||||||
follow() {
|
clear
|
||||||
read -p "Press 'Enter' to continue"
|
current_user="$(whoami)"
|
||||||
|
selected_user=""
|
||||||
|
|
||||||
|
pause() {
|
||||||
|
read -rp "Press Enter to continue..."
|
||||||
}
|
}
|
||||||
|
|
||||||
loop2=0
|
select_user() {
|
||||||
while [ $loop2 -lt 1 ]; do # Corrected the integer comparison
|
while true; do
|
||||||
|
echo "----------------------------"
|
||||||
|
echo "Available users:"
|
||||||
|
echo "----------------------------"
|
||||||
|
grep -E ':/home/' /etc/passwd | cut -d: -f1
|
||||||
|
echo "q = exit"
|
||||||
|
echo "----------------------------"
|
||||||
|
|
||||||
|
read -rp "Type the user: " choice
|
||||||
|
|
||||||
|
if [[ "$choice" == "q" ]]; then
|
||||||
|
echo "Exiting..."
|
||||||
|
exit 1
|
||||||
|
elif [[ -d "/home/$choice" ]]; then
|
||||||
|
read -rp "Confirm user '$choice'? (y/N): " confirm
|
||||||
|
if [[ "$confirm" == "y" ]]; then
|
||||||
|
selected_user="$choice"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "User '$choice' not valid!"
|
||||||
|
pause
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# ========================
|
||||||
|
# USER SELECTION
|
||||||
|
# ========================
|
||||||
|
while true; do
|
||||||
echo "### brc-script installer ###"
|
echo "### brc-script installer ###"
|
||||||
echo "---------------------------------------------"
|
echo "---------------------------------------------"
|
||||||
echo "Do you want to install for the current user ($user)?"
|
echo "Install for current user ($current_user)?"
|
||||||
echo "---------------------------------------------"
|
echo "---------------------------------------------"
|
||||||
echo " y - yes"
|
echo " y - yes"
|
||||||
echo " n - no"
|
echo " n - choose another user"
|
||||||
echo " q - exit"
|
echo " q - exit"
|
||||||
echo " default - yes"
|
echo " default - yes"
|
||||||
echo "---------------------------------------------"
|
echo "---------------------------------------------"
|
||||||
read choice
|
|
||||||
if [ "$choice" == "n" ]; then
|
read -rp "Choice: " choice
|
||||||
loop2=1
|
|
||||||
loop1=0
|
case "$choice" in
|
||||||
clear
|
n)
|
||||||
while [ $loop1 -lt 1 ]; do # Corrected the integer comparison
|
select_user
|
||||||
echo "----------------------------"
|
break
|
||||||
echo "List of the available users:"
|
;;
|
||||||
echo "----------------------------"
|
q)
|
||||||
for i in $(grep -E ':/home/' /etc/passwd | cut -d: -f1); do echo $i; done
|
echo "Exiting..."
|
||||||
echo "q = exit"
|
exit 1
|
||||||
echo "----------------------------"
|
;;
|
||||||
echo "Type the user:"
|
*)
|
||||||
read choice2
|
read -rp "Confirm current user '$current_user'? (y/N): " confirm
|
||||||
if [ -d "/home/$choice2" ]; then
|
if [[ "$confirm" == "y" ]]; then
|
||||||
user=$choice2
|
selected_user="$current_user"
|
||||||
echo "Selected user '$choice2'!"
|
break
|
||||||
echo "-------------------"
|
|
||||||
echo "Can you confirm it?"
|
|
||||||
echo "-------------------"
|
|
||||||
echo " y = yes "
|
|
||||||
echo " n = no "
|
|
||||||
echo " default = no "
|
|
||||||
echo "-------------------"
|
|
||||||
read confirm # Changed 'input' to 'read'
|
|
||||||
if [ "$confirm" == "y" ]; then
|
|
||||||
user=$choice2
|
|
||||||
echo "Using user '$choice2'"
|
|
||||||
loop1=1
|
|
||||||
else
|
|
||||||
echo "Wrong selection, for user '$choice2' "
|
|
||||||
follow
|
|
||||||
loop1=0
|
|
||||||
fi
|
|
||||||
elif [ "$choice2" == "q" ]; then
|
|
||||||
echo "Exit from the installer script"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "Home folder for '$choice2' does not exist!"
|
|
||||||
echo "Try with another one!"
|
|
||||||
fi
|
fi
|
||||||
done
|
;;
|
||||||
elif [ "$choice" == "q" ]; then
|
esac
|
||||||
echo "[ Exit from the installer script! ]"
|
|
||||||
exit 1
|
clear
|
||||||
|
done
|
||||||
|
|
||||||
|
# ========================
|
||||||
|
# VARIABLES
|
||||||
|
# ========================
|
||||||
|
home="/home/$selected_user"
|
||||||
|
bashrc="$home/.bashrc"
|
||||||
|
|
||||||
|
mainfolder="$home/.bashrc.d"
|
||||||
|
neededfolder="$mainfolder/scripts-needed"
|
||||||
|
availablefolder="$mainfolder/scripts-available"
|
||||||
|
enabledfolder="$mainfolder/scripts-enabled"
|
||||||
|
removedfolder="$mainfolder/scripts-removed"
|
||||||
|
|
||||||
|
script_dir="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
|
# ========================
|
||||||
|
# CREATE DIRECTORIES
|
||||||
|
# ========================
|
||||||
|
echo "[ Creating folders... ]"
|
||||||
|
|
||||||
|
mkdir -p "$neededfolder"
|
||||||
|
mkdir -p "$availablefolder"
|
||||||
|
mkdir -p "$enabledfolder"
|
||||||
|
mkdir -p "$removedfolder"
|
||||||
|
|
||||||
|
# ========================
|
||||||
|
# BACKUP .bashrc
|
||||||
|
# ========================
|
||||||
|
if [[ -f "$bashrc" ]]; then
|
||||||
|
cp "$bashrc" "$home/bashrc-backup-$(date +%F)"
|
||||||
|
echo "[ Backup created ]"
|
||||||
|
else
|
||||||
|
echo "[ WARNING: .bashrc not found, creating a new one ]"
|
||||||
|
touch "$bashrc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ========================
|
||||||
|
# MODIFY .bashrc
|
||||||
|
# ========================
|
||||||
|
if [[ -f "$script_dir/NEEDED-FOR-INSTALLER" ]]; then
|
||||||
|
cat "$script_dir/NEEDED-FOR-INSTALLER" >> "$bashrc"
|
||||||
|
echo "[ Updated .bashrc ]"
|
||||||
|
else
|
||||||
|
echo "[ ERROR: NEEDED-FOR-INSTALLER missing ]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ========================
|
||||||
|
# COPY MAIN STRUCTURE
|
||||||
|
# ========================
|
||||||
|
cp -r "$script_dir/../." "$mainfolder"
|
||||||
|
echo "[ Main folder installed ]"
|
||||||
|
|
||||||
|
# ========================
|
||||||
|
# COPY DEFAULT SCRIPTS
|
||||||
|
# ========================
|
||||||
|
echo "[ Installing default scripts... ]"
|
||||||
|
|
||||||
|
default_scripts=(
|
||||||
|
"00_default.sh"
|
||||||
|
"01_git-cli-highlitgh.sh"
|
||||||
|
"02_bashboard.sh"
|
||||||
|
)
|
||||||
|
|
||||||
|
for script in "${default_scripts[@]}"; do
|
||||||
|
if [[ -f "$script_dir/$script" ]]; then
|
||||||
|
cp "$script_dir/$script" "$availablefolder/"
|
||||||
|
echo " -> Copied $script"
|
||||||
else
|
else
|
||||||
clear
|
echo " -> WARNING: $script not found"
|
||||||
loop3=0
|
|
||||||
while [ $loop3 -eq 0 ]; do
|
|
||||||
echo "--------------------------------"
|
|
||||||
echo "Do you want to use '$user' user?"
|
|
||||||
echo "--------------------------------"
|
|
||||||
echo " y = yes"
|
|
||||||
echo " n = no "
|
|
||||||
echo "--------------------------------"
|
|
||||||
read choice3
|
|
||||||
if [ "$choice3" == "y" ]; then
|
|
||||||
echo "Selected the current user '$user'"
|
|
||||||
loop2=1
|
|
||||||
loop3=1
|
|
||||||
follow
|
|
||||||
elif [ "$choice3" == "n" ]; then # Corrected from 'no' to 'n'
|
|
||||||
echo "Not selected the current user '$user'"
|
|
||||||
loop3=1
|
|
||||||
follow
|
|
||||||
clear
|
|
||||||
else
|
|
||||||
echo "Pressed wrong button!"
|
|
||||||
follow
|
|
||||||
clear
|
|
||||||
clear
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
#### NEEDED VARIABLES ####
|
# ========================
|
||||||
location="$(pwd)/../"
|
# APPLY CHANGES
|
||||||
home="/home/$user"
|
# ========================
|
||||||
bashrc="$home/.bashrc"
|
# shellcheck disable=SC1090
|
||||||
mainfolder="$home/.bashrc.d/"
|
source "$bashrc"
|
||||||
neededfold="${mainfolder}scripts-needed"
|
echo "[ Bashrc reloaded ]"
|
||||||
avfolder="${mainfolder}scripts-available"
|
|
||||||
enfolder="${mainfolder}scripts-enabled"
|
|
||||||
rmfolder="${mainfolder}scripts-removed"
|
|
||||||
|
|
||||||
#### INSTALLATION ####
|
# ========================
|
||||||
cp "$bashrc" "bashrc-backup-`date +%F`"
|
# FINAL MESSAGE
|
||||||
echo "[ Created a backup ]"
|
# ========================
|
||||||
cat NEEDED-FOR-INSTALLER >> $bashrc
|
|
||||||
echo "[ Added info in the .bashrc file ]"
|
|
||||||
cp -r $location $mainfolder
|
|
||||||
echo "[ Installed Main Folder ]"
|
|
||||||
echo $mainfolder
|
|
||||||
source $bashrc
|
|
||||||
echo "[ Refreshed bashrc ]"
|
|
||||||
echo ""
|
|
||||||
echo "Intallation Completed!"
|
|
||||||
follow
|
|
||||||
clear
|
clear
|
||||||
## EXECUTION ##
|
|
||||||
echo "##################################"
|
echo "##################################"
|
||||||
echo " Small Introduction "
|
echo " Installation Done "
|
||||||
echo "##################################"
|
echo "##################################"
|
||||||
echo ""
|
echo ""
|
||||||
echo "You can handle your script by adding them in the $avfolder."
|
echo "Scripts available in:"
|
||||||
echo "Make sure that all the scripts you add are within a function, otherwise they will be loaded each time you open the bash CLI."
|
echo " $availablefolder"
|
||||||
echo "You can start managing scripts by using the command 'brc-script', and refresh bash with 'refresh-brc'."
|
echo ""
|
||||||
echo "You can create your own script using 'brc-script -c'."
|
echo "Use commands:"
|
||||||
echo "To enable an available script (after copying or creating one in the scripts-available), use 'brc-script -e' and provide the index."
|
echo " brc-script -> manage scripts"
|
||||||
echo "You can also modify existing scripts using 'brc-script -m'."
|
echo " refresh-brc -> reload config"
|
||||||
echo ""
|
echo ""
|
||||||
echo "##################################"
|
echo "##################################"
|
||||||
echo " Thanks for using this script. "
|
echo " Thanks for using this script! "
|
||||||
echo "##################################"
|
echo "##################################"
|
||||||
echo "Visit my website www.simolinuxdesign.org to discover more plugins I created!"
|
|
||||||
|
|
||||||
|
pause
|
||||||
|
|||||||
Reference in New Issue
Block a user