Compare commits
21 Commits
d1a2570c23
...
fixing-ins
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b5cf4d28c | |||
| fc56e2100f | |||
| bc281476c5 | |||
| 07f6e4c947 | |||
| 6ffbb1bde2 | |||
| ab0b1cd7cc | |||
| 4a0e976a88 | |||
| 60533b99de | |||
| 6401a41cb0 | |||
| 2d58116014 | |||
| 782aff492c | |||
| 53aa364139 | |||
| 4762d195b7 | |||
|
|
a736a3ae27 | ||
|
|
d1f6dec046 | ||
| b1c3dac09b | |||
| 5b6960643d | |||
| c350409018 | |||
| c761614013 | |||
| 875b570148 | |||
| b06c592037 |
618
README.md
618
README.md
@@ -1,144 +1,564 @@
|
||||
# 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.
|
||||
### A simple, modular, and clean way to manage your `.bashrc` file in Linux.
|
||||
|
||||
---
|
||||
|
||||
`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
|
||||
|
||||
- **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.
|
||||
- **Modular setup**
|
||||
Keep `.bashrc` organized by loading only the scripts you need.
|
||||
|
||||
- **Script management**
|
||||
Create, enable, disable, remove, and modify scripts from a single command interface.
|
||||
|
||||
- **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
|
||||
|
||||
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.
|
||||
- `installer/`: Contains the installer and base script.
|
||||
- `brc-script-install.sh`
|
||||
- `brc-script.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`
|
||||
- `scripts-removed/`: Backup of removed scripts, timestamped.
|
||||
|
||||
## Installation
|
||||
|
||||
### Automated Installation
|
||||
|
||||
To install the system automatically, follow these steps:
|
||||
|
||||
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 to `scripts-needed/`.
|
||||
|
||||
After the installation completes, restart your shell or reload the .bashrc file by running:
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```text
|
||||
~/.bashrc.d/
|
||||
├── scripts-needed/
|
||||
│ ├── brc-script.sh
|
||||
│ └── ccecho.sh
|
||||
├── scripts-available/
|
||||
│ ├── 00_default.sh
|
||||
│ ├── 01_git-cli-highlitgh.sh
|
||||
│ └── 02_bashboard.sh
|
||||
├── scripts-enabled/
|
||||
└── scripts-removed/
|
||||
```
|
||||
### Manual Installation
|
||||
|
||||
If you prefer a manual installation process, follow these steps:
|
||||
### Folder Purpose
|
||||
|
||||
1. Copy the `brc-script.sh` file to the `~/.bashrc.d/scripts-needed/` folder:
|
||||
```bash
|
||||
cp brc-script.sh ~/.bashrc.d/scripts-needed/
|
||||
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.sh
|
||||
```
|
||||
#### `scripts-needed/`
|
||||
Contains the core scripts required by the project itself. These are loaded automatically and should not normally be disabled.
|
||||
|
||||
2. Append the following lines to your `.bashrc` file:
|
||||
```bash
|
||||
# Modular Bashrc
|
||||
if [ -d ~/.bashrc.d ]; then
|
||||
#### `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
|
||||
```
|
||||
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
|
||||
```
|
||||
This keeps your shell configuration clean and maintainable.
|
||||
|
||||
4. Restart your shell or source `.bashrc`:
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```
|
||||
---
|
||||
|
||||
### `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
|
||||
|
||||
The project can be installed using the included installer script.
|
||||
|
||||
### Automated Installation
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
```bash
|
||||
chmod +x brc-script-install.sh
|
||||
./brc-script-install.sh
|
||||
```
|
||||
|
||||
### What the installer does
|
||||
|
||||
The installer will:
|
||||
|
||||
- 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
|
||||
source ~/.bashrc
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Manual Installation
|
||||
|
||||
If you prefer to install the project manually, you can do it step by step.
|
||||
|
||||
#### 1. Create the directory structure
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.bashrc.d/scripts-needed
|
||||
mkdir -p ~/.bashrc.d/scripts-enabled
|
||||
mkdir -p ~/.bashrc.d/scripts-available
|
||||
mkdir -p ~/.bashrc.d/scripts-removed
|
||||
```
|
||||
|
||||
#### 2. Copy the core scripts into `scripts-needed/`
|
||||
|
||||
```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
|
||||
|
||||
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.
|
||||
- `-m` : Modify an existing script.
|
||||
- `-l` : List all available and enabled scripts.
|
||||
- `-e <index>` : Enable a script from the `scripts-available/` folder.
|
||||
- `-d <index>` : Disable an enabled script.
|
||||
- `-r <index>` : Remove a script, backing it up in `scripts-removed/`.
|
||||
It can be used to manage scripts stored in the modular directories.
|
||||
|
||||
### Example Commands
|
||||
### Common commands
|
||||
|
||||
- Create a new script:
|
||||
```bash
|
||||
brc-script -c
|
||||
```
|
||||
- `brc-script -c`
|
||||
Create a new script in `scripts-available/`
|
||||
|
||||
- List all available scripts:
|
||||
```bash
|
||||
brc-script -l
|
||||
```
|
||||
- `brc-script -m`
|
||||
Modify an existing script
|
||||
|
||||
- Enable a script:
|
||||
```bash
|
||||
brc-script -e <index>
|
||||
```
|
||||
- `brc-script -l`
|
||||
List all available and enabled scripts
|
||||
|
||||
- Disable a script:
|
||||
```bash
|
||||
brc-script -d <index>
|
||||
```
|
||||
- `brc-script -e`
|
||||
Enable a script from `scripts-available/`
|
||||
|
||||
- Remove a script:
|
||||
```bash
|
||||
brc-script -r <index>
|
||||
```
|
||||
- `brc-script -d`
|
||||
Disable an enabled script
|
||||
|
||||
- `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
|
||||
|
||||
### `ccecho` – Colored Echo for Better Terminal Output
|
||||
|
||||
The project includes a reusable utility script called `ccecho.sh`, located in `scripts-needed/`.
|
||||
|
||||
It defines a `ccecho` function for printing styled and colored text to the terminal.
|
||||
|
||||
#### Example 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
|
||||
|
||||
The same color names can be used with `-b`.
|
||||
|
||||
#### Styles
|
||||
|
||||
- `bold`
|
||||
- `dim`
|
||||
- `italic`
|
||||
- `underline`
|
||||
- `blink`
|
||||
- `reverse`
|
||||
- `hidden`
|
||||
- `strike`
|
||||
|
||||
#### Make `ccecho` available in other sessions
|
||||
|
||||
If you want to use `ccecho` in other terminal sessions or scripts, source it from `.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.
|
||||
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
|
||||
|
||||
- **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.
|
||||
- **Organization**
|
||||
Keep your shell configuration structured and easier to understand.
|
||||
|
||||
- **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
|
||||
|
||||
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
|
||||
|
||||
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).
|
||||
|
||||
|
||||
144
README.md.backup
144
README.md.backup
@@ -1,144 +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.
|
||||
|
||||
## 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`
|
||||
- `brc-script.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`
|
||||
- `scripts-removed/`: Backup of removed scripts, timestamped.
|
||||
|
||||
## Installation
|
||||
|
||||
### Automated Installation
|
||||
|
||||
To install the system automatically, follow these steps:
|
||||
|
||||
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 to `scripts-needed/`.
|
||||
|
||||
After the installation completes, restart your shell or reload the .bashrc file by running:
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```
|
||||
### Manual Installation
|
||||
|
||||
If you prefer a manual installation process, follow these steps:
|
||||
|
||||
1. Copy the `brc-script.sh` file to the `~/.bashrc.d/scripts-needed/` folder:
|
||||
```bash
|
||||
cp brc-script.sh ~/.bashrc.d/scripts-needed/
|
||||
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.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. Restart your shell or source `.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 <index>` : Enable a script from the `scripts-available/` folder.
|
||||
- `-d <index>` : Disable an enabled script.
|
||||
- `-r <index>` : 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 <index>
|
||||
```
|
||||
|
||||
- Disable a script:
|
||||
```bash
|
||||
brc-script -d <index>
|
||||
```
|
||||
|
||||
- Remove a script:
|
||||
```bash
|
||||
brc-script -r <index>
|
||||
```
|
||||
|
||||
## 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).
|
||||
@@ -1,78 +0,0 @@
|
||||
#!/bin/bash
|
||||
home="/home/$(whoami)"
|
||||
bashrc="$home/.bashrc"
|
||||
mainfolder="$home/.bashrc.d/"
|
||||
neededfold="${mainfolder}scripts-needed"
|
||||
avfolder="${mainfolder}scripts-available"
|
||||
enfolder="${mainfolder}scripts-enabled"
|
||||
rmfolder="${mainfolder}scripts-removed"
|
||||
|
||||
## FUNCTIONS ##
|
||||
createdir(){
|
||||
if [ ! -d "$mainfolder" ]; then
|
||||
mkdir $mainfolder
|
||||
echo "[ Created $mainfolder ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$neededfold" ]; then
|
||||
mkdir $neededfold
|
||||
echo "[ Created $neededfold ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$avfolder" ]; then
|
||||
mkdir $avfolder
|
||||
echo "[ Created $avfolder ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$enfolder" ]; then
|
||||
mkdir $enfolder
|
||||
echo "[ Created $enfolder ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$rmfolder" ]; then
|
||||
mkdir $rmfolder
|
||||
echo "[ Created $rmfolder ]"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
modular-bashrc(){
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-needed' >> $bashrc
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-enabled' >> $bashrc
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-available' >> $bashrc
|
||||
echo 'if [ -d ~/.bashrc.d ]; then' >> $bashrc
|
||||
echo ' for needed in ~/.bashrc.d/scripts-needed/*.sh; do' >> $bashrc
|
||||
echo ' [ -r "$needed" ] && source "$needed"' >> $bashrc
|
||||
echo ' done' >> $bashrc
|
||||
echo ' unset needed' >> $bashrc
|
||||
echo ' for file in ~/.bashrc.d/scripts-enabled/*.sh; do' >> $bashrc
|
||||
echo ' [ -r "$file" ] && source "$file"' >> $bashrc
|
||||
echo ' done' >> $bashrc
|
||||
echo ' unset file' >> $bashrc
|
||||
echo 'fi' >> $bashrc
|
||||
}
|
||||
|
||||
## EXECUTION ##
|
||||
echo "### Creation Folders ###"
|
||||
createdir
|
||||
echo "### Adding brc-script for .bashrc ###"
|
||||
modular-bashrc
|
||||
echo [ brc-script installed ]
|
||||
|
||||
echo "##################################"
|
||||
echo " Small Introduction "
|
||||
echo "##################################"
|
||||
echo ""
|
||||
echo "You can handle you script by adding in the $avfolder."
|
||||
echo "Make sure that all the the script that you are adding are added in a function, otherwise their will be loaded at each open of the bash cli."
|
||||
echo "You can start to handle all the script by writing the command brc-script, also you can refresh the bash with the command refresh-brc."
|
||||
echo "You can start to create your own script by use the 'brc-script -c' command"
|
||||
echo "To enable an available script (after you copied or created one in the scripts-available) by using 'brc-script -e' and the the index command that you need"
|
||||
echo "You can also modify the existing script by the 'brc-script -m' command."
|
||||
echo ""
|
||||
echo "##################################"
|
||||
echo " Thanks for using this script. "
|
||||
echo "##################################"
|
||||
echo " Visit my website www.simolinuxdesign.org to discover more plugin that i created!
|
||||
|
||||
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)\$ "'
|
||||
187
installer/02_bashboard.sh
Normal file
187
installer/02_bashboard.sh
Normal file
@@ -0,0 +1,187 @@
|
||||
############# 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.
|
||||
LOCAL_CACHE=1 # Change this value to 1 if you want to create the local cache in the ~/.bashrc.d/.dashboard_cache.
|
||||
UI_SHOWS=1 # Change to 1 if cockpit has been installed. This will shows the IP and port Link.
|
||||
|
||||
|
||||
|
||||
|
||||
#### Colors ####
|
||||
GREEN="\e[32m"
|
||||
YELLOW="\e[33m"
|
||||
RED="\e[31m"
|
||||
CYAN="\e[36m"
|
||||
BOLD="\e[1m"
|
||||
NC="\e[0m" # reset
|
||||
|
||||
|
||||
#### Cache ####
|
||||
if [ $LOCAL_CACHE -ne 1 ]; then
|
||||
CACHE_DIR="/tmp/.dashboard_cache"
|
||||
else
|
||||
CACHE_DIR="/home/$(whoami)/.bashrc.d/.dashboard_cache"
|
||||
fi
|
||||
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?)"
|
||||
if [ $UI_SHOWS -eq 1 ]; then echo "🌐 Web UI: NOT AVAILABLE"; fi
|
||||
else
|
||||
echo "🏠 Local IP: $LOCAL_IPS"
|
||||
if [ $UI_SHOWS -eq 1 ]; then echo "🌐 Web UI: http://$PRIMARY_IP:9090"; fi
|
||||
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}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
if [[ $- == *i* ]]; then
|
||||
dashboard_fast
|
||||
fi
|
||||
@@ -13,4 +13,3 @@ if [ -d ~/.bashrc.d ]; then
|
||||
unset file
|
||||
|
||||
fi
|
||||
|
||||
236
installer/brc-script-install.sh
Normal file → Executable file
236
installer/brc-script-install.sh
Normal file → Executable file
@@ -1,81 +1,181 @@
|
||||
#!/bin/bash
|
||||
home="/home/$(whoami)"
|
||||
|
||||
clear
|
||||
current_user="$(whoami)"
|
||||
selected_user=""
|
||||
|
||||
pause() {
|
||||
read -rp "Press Enter to continue..."
|
||||
}
|
||||
|
||||
debmess(){
|
||||
$debdescription="$1"
|
||||
echo "DEBUG MESSAGE: $debdescription"
|
||||
echo "Press enter to continue..."
|
||||
read debmess
|
||||
}
|
||||
|
||||
select_user() {
|
||||
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 "---------------------------------------------"
|
||||
echo "Install for current user ($current_user)?"
|
||||
echo "---------------------------------------------"
|
||||
echo " y - yes"
|
||||
echo " n - choose another user"
|
||||
echo " q - exit"
|
||||
echo " default - yes"
|
||||
echo "---------------------------------------------"
|
||||
|
||||
read -rp "Choice: " choice
|
||||
|
||||
case "$choice" in
|
||||
n)
|
||||
select_user
|
||||
break
|
||||
;;
|
||||
q)
|
||||
echo "Exiting..."
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
read -rp "Confirm current user '$current_user'? (y/N): " confirm
|
||||
if [[ "$confirm" == "y" ]]; then
|
||||
selected_user="$current_user"
|
||||
break
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
clear
|
||||
done
|
||||
|
||||
# ========================
|
||||
# VARIABLES
|
||||
# ========================
|
||||
home="/home/$selected_user"
|
||||
bashrc="$home/.bashrc"
|
||||
mainfolder="$home/.bashrc.d/"
|
||||
neededfold="${mainfolder}scripts-needed"
|
||||
avfolder="${mainfolder}scripts-available"
|
||||
enfolder="${mainfolder}scripts-enabled"
|
||||
rmfolder="${mainfolder}scripts-removed"
|
||||
|
||||
## FUNCTIONS ##
|
||||
createdir(){
|
||||
if [ ! -d "$mainfolder" ]; then
|
||||
mkdir $mainfolder
|
||||
echo "[ Created $mainfolder ]"
|
||||
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 ]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ========================
|
||||
# COPY NEEDED SCRIPTS
|
||||
# ========================
|
||||
needed_to_copy="$script_dir/scripts-needed"
|
||||
cp -r $needed_to_copy $mainfolder
|
||||
echo "[ Main logic scripts 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
|
||||
echo " -> WARNING: $script not found"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "$neededfold" ]; then
|
||||
mkdir $neededfold
|
||||
echo "[ Created $neededfold ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$avfolder" ]; then
|
||||
mkdir $avfolder
|
||||
echo "[ Created $avfolder ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$enfolder" ]; then
|
||||
mkdir $enfolder
|
||||
echo "[ Created $enfolder ]"
|
||||
fi
|
||||
|
||||
if [ ! -d "$rmfolder" ]; then
|
||||
mkdir $rmfolder
|
||||
echo "[ Created $rmfolder ]"
|
||||
fi
|
||||
}
|
||||
|
||||
modular-bashrc(){
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-needed' >> $bashrc
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-enabled' >> $bashrc
|
||||
echo 'mkdir -p ~/.bashrc.d/scripts-available' >> $bashrc
|
||||
echo 'if [ -d ~/.bashrc.d ]; then' >> $bashrc
|
||||
echo ' for needed in ~/.bashrc.d/scripts-needed/*.sh; do' >> $bashrc
|
||||
echo ' [ -r "$needed" ] && source "$needed"' >> $bashrc
|
||||
echo ' done' >> $bashrc
|
||||
echo ' unset needed' >> $bashrc
|
||||
echo ' for file in ~/.bashrc.d/scripts-enabled/*.sh; do' >> $bashrc
|
||||
echo ' [ -r "$file" ] && source "$file"' >> $bashrc
|
||||
echo ' done' >> $bashrc
|
||||
echo ' unset file' >> $bashrc
|
||||
echo 'fi' >> $bashrc
|
||||
}
|
||||
|
||||
copy-brc() {
|
||||
cp -r brc-script.sh ../scripts-needed/
|
||||
chmod 750 -R ../scripts-needed/brc-script.sh
|
||||
}
|
||||
|
||||
## EXECUTION ##
|
||||
echo "### Creation Folders ###"
|
||||
createdir
|
||||
echo "### Adding brc-script for .bashrc ###"
|
||||
modular-bashrc
|
||||
echo [ brc-script installed ]
|
||||
# ========================
|
||||
# APPLY CHANGES
|
||||
# ========================
|
||||
# shellcheck disable=SC1090
|
||||
source "$bashrc"
|
||||
echo "[ Bashrc reloaded ]"
|
||||
|
||||
# ========================
|
||||
# FINAL MESSAGE
|
||||
# ========================
|
||||
clear
|
||||
echo "##################################"
|
||||
echo " Small Introduction "
|
||||
echo " Installation Done "
|
||||
echo "##################################"
|
||||
echo ""
|
||||
echo "You can handle you script by adding in the $avfolder."
|
||||
echo "Make sure that all the the script that you are adding are added in a function, otherwise their will be loaded at each open of the bash cli."
|
||||
echo "You can start to handle all the script by writing the command brc-script, also you can refresh the bash with the command refresh-brc."
|
||||
echo "You can start to create your own script by use the 'brc-script -c' command"
|
||||
echo "To enable an available script (after you copied or created one in the scripts-available) by using 'brc-script -e' and the the index command that you need"
|
||||
echo "You can also modify the existing script by the 'brc-script -m' command."
|
||||
echo "Scripts available in:"
|
||||
echo " $availablefolder"
|
||||
echo ""
|
||||
echo "Use commands:"
|
||||
echo " brc-script -> manage scripts"
|
||||
echo " refresh-brc -> reload config"
|
||||
echo ""
|
||||
echo "##################################"
|
||||
echo " Thanks for using this script. "
|
||||
echo " Thanks for using this script! "
|
||||
echo "##################################"
|
||||
echo " Visit my website www.simolinuxdesign.org to discover more plugin that i created!
|
||||
|
||||
pause
|
||||
@@ -1,338 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
###############
|
||||
### OPTIONS ###
|
||||
###############
|
||||
editor="vim"
|
||||
|
||||
#################
|
||||
### VARIABLES ###
|
||||
#################
|
||||
home_folder="$HOME/"
|
||||
available_scripts="${home_folder}.bashrc.d/scripts-available/"
|
||||
enabled_scripts="${home_folder}.bashrc.d/scripts-enabled/"
|
||||
needed_scripts="${home_folder}.bashrc.d/scripts-needed"
|
||||
bin_folder="${home_folder}.bashrc.d/scripts-removed/"
|
||||
bashrc="${home_folder}.bashrc"
|
||||
|
||||
#################
|
||||
### FUNCTIONS ###
|
||||
#################
|
||||
|
||||
# Refresh Bash #
|
||||
refresh-brc(){
|
||||
if [ "$1" == "-dis" ]; then
|
||||
echo "------------------------------------"
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
echo "You can't use the old commands from now!"
|
||||
echo "------------------------------------"
|
||||
elif [ "$1" == "-en" ]; then
|
||||
echo "------------------------------------"
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
echo "------------------------------------"
|
||||
echo "You can you the new commands from now!"
|
||||
echo "------------------------------------"
|
||||
else
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
fi
|
||||
source "$bashrc"
|
||||
}
|
||||
|
||||
|
||||
createscript() {
|
||||
echo "------------------------------------"
|
||||
echo " Creation New Scripts: "
|
||||
echo "------------------------------------"
|
||||
echo "Name of the script: "
|
||||
read namenewscript
|
||||
if [ -f "${available_scripts}$namenewscript" ]; then
|
||||
echo "Script already exists!"
|
||||
else
|
||||
newscriptav="${available_scripts}$namenewscript.sh"
|
||||
|
||||
### INITIALIZZATION NEW SCRIPT ###
|
||||
touch $newscriptav
|
||||
echo "#!/bin/bash" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### OPTIONS ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### VARIABLES ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### FUNCTIONS ###" >> $newscriptav
|
||||
echo "${namenewscript}() {" >> $newscriptav
|
||||
echo "# Add your code here!" >> $newscriptav
|
||||
echo 'echo "This is the new script"' >> $newscriptav
|
||||
echo "}" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### EXECUTE ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
### END NEW SCRIPT ###
|
||||
|
||||
vim "$newscriptav"
|
||||
echo "------------------------------------"
|
||||
echo " Script $namenewscript created!"
|
||||
echo " Do you want to enable it?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | yes "
|
||||
echo " 2 | no "
|
||||
echo " Def | no "
|
||||
echo "------------------------------------"
|
||||
read answer
|
||||
if [ "$answer" -eq 1 ]; then
|
||||
ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh"
|
||||
refresh-brc -en
|
||||
else
|
||||
echo "Script not enabled!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
listitem() {
|
||||
index=0
|
||||
for i in $(ls "$available_scripts"); do
|
||||
inotext=${i:0:-3}
|
||||
(( index ++ ))
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
echo "$index) - $inotext"
|
||||
else
|
||||
echo "$index) $inotext"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
managescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Select the index: "
|
||||
echo "------------------------------------"
|
||||
read manageindex
|
||||
index2=1
|
||||
for i in $(ls "$available_scripts"); do
|
||||
if [ "$manageindex" == "$index2" ]; then
|
||||
# DISABLE WITH NUMBER #
|
||||
if [ "$1" == "--disable" ]; then
|
||||
if [ ! -f "${enabled_scripts}$i" ]; then
|
||||
echo "Script not enabled!"
|
||||
else
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "[ Scripts $inoext Disabled ]"
|
||||
refresh-brc -dis
|
||||
fi
|
||||
# ENABLE WITH NUMBER #
|
||||
elif [ "$1" == "--enable" ]; then
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
echo "Script already enabled!"
|
||||
else
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "------------------------------------"
|
||||
echo "[ Scripts $inoext Enabled ]"
|
||||
refresh-brc -en
|
||||
fi
|
||||
|
||||
# MODIFY WITH NUMBER #
|
||||
elif [ "$1" == "--modify" ]; then
|
||||
if [ "$editor" == "vim" ]; then
|
||||
vim "$available_scripts$i"
|
||||
elif [ "$editor" == "nano" ]; then
|
||||
nano "$available_scripts$i"
|
||||
else
|
||||
echo "------------"
|
||||
echo " 1 - nano "
|
||||
echo " 2 - vim "
|
||||
echo " def - vim "
|
||||
echo "------------"
|
||||
read ched
|
||||
if [ "$ched" == "1" ]; then
|
||||
nano "$available_scripts$i"
|
||||
else
|
||||
vim "$available_scripts$i"
|
||||
fi
|
||||
fi
|
||||
clear
|
||||
echo "------------------------------------"
|
||||
echo "Would you like to rename the script?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | yes "
|
||||
echo " 2 | no "
|
||||
echo " default | no "
|
||||
echo "------------------------------------"
|
||||
read renscr
|
||||
if [ $renscr == "1" ]; then
|
||||
clear
|
||||
countloop=0
|
||||
while [ $countloop -lt 1 ]; do
|
||||
echo "------------------------------------"
|
||||
echo "Insert new name:"
|
||||
read renamenow
|
||||
echo "------------------------------------"
|
||||
echo "Is the name correct? "
|
||||
echo "------------------------------------"
|
||||
echo " 1 | no "
|
||||
echo " 0 | yes "
|
||||
echo " default | yes "
|
||||
echo "------------------------------------"
|
||||
read confirm
|
||||
if [ "$confirm" == "1" ]; then
|
||||
countloop=0
|
||||
clear
|
||||
echo "------------------------------------"
|
||||
echo "Rename again the file:"
|
||||
else
|
||||
wasenabled=0
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
unlink "$enabled_scripts$i"
|
||||
echo "[ Temporary Disabled Script ]"
|
||||
wasenabled=1
|
||||
fi
|
||||
mv "$available_scripts$i" "${available_scripts}$renamenow.sh"
|
||||
echo "[ Script $i renamed to $renamenow.sh ]"
|
||||
if [ "$wasenabled" -eq 1 ]; then
|
||||
ln -sf "${available_scripts}$renamenow.sh" "${enabled_scripts}$renamenow.sh"
|
||||
echo "[ Script Enabled Again ]"
|
||||
fi
|
||||
countloop=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
refresh-brc -en
|
||||
# REMOVE SCRIPT #
|
||||
elif [ "$1" == "--remove" ]; then
|
||||
if [ ! -d "$bin_folder" ]; then
|
||||
mkdir $bin_folder
|
||||
fi
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
unlink "${enabled_scripts}$i"
|
||||
echo "[ Script $i unabled! ]"
|
||||
fi
|
||||
removed_data="$i-`date +%F`_`date +%T`"
|
||||
mv "${available_scripts}$i" "${bin_folder}$removed_data"
|
||||
echo "[ Script $i removed! ] "
|
||||
echo "You can find it in the folder: "
|
||||
echo "'$bin_folder' "
|
||||
echo "------------------------------------"
|
||||
refresh-brc
|
||||
fi
|
||||
|
||||
break
|
||||
fi
|
||||
((index2++))
|
||||
done
|
||||
}
|
||||
|
||||
removescript(){
|
||||
echo "------------------------------------"
|
||||
echo " Remove Script "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --remove
|
||||
}
|
||||
|
||||
enablescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Enable Scripts "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --enable
|
||||
}
|
||||
|
||||
enableallscript() {
|
||||
for i in $(ls "$available_scripts"); do
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "enabled $inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
echo "[ All available scripts enabled ]"
|
||||
refresh-brc -en
|
||||
}
|
||||
|
||||
|
||||
disablescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Disable Scripts "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --disable
|
||||
}
|
||||
|
||||
|
||||
disableallscript() {
|
||||
# Disabilita tutti gli script
|
||||
for i in $(ls "$enabled_scripts"); do
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "disabled $inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
echo "[ All Scripts Disabled ]"
|
||||
refresh-brc -dis
|
||||
}
|
||||
|
||||
#################
|
||||
### EXECUTION ###
|
||||
#################
|
||||
|
||||
# Main Script #
|
||||
brc-script() {
|
||||
### ENABLE SCRIPTS ###
|
||||
if [ "$1" == "-e" ]; then
|
||||
enablescript
|
||||
|
||||
### ENABLE ALL SCRIPTS ###
|
||||
elif [ "$1" == "-ea" ]; then
|
||||
enableallscript
|
||||
|
||||
### DISABLE SCRIPT ###
|
||||
elif [ "$1" == "-d" ]; then
|
||||
disablescript
|
||||
|
||||
### DISABLE ALL SCRIPTS ###
|
||||
elif [ "$1" == "-da" ]; then
|
||||
disableallscript
|
||||
|
||||
### SCRIPTS LIST ###
|
||||
elif [ "$1" == "-l" ]; then
|
||||
echo "------------------------------------"
|
||||
echo " Scripts List "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
echo "------------------------------------"
|
||||
echo " The script preceded by the"
|
||||
echo " '-' character is active. "
|
||||
echo "------------------------------------"
|
||||
|
||||
### MODIFY SCRIPTS ###
|
||||
elif [ "$1" == "-m" ]; then
|
||||
echo "###### MODIFY SCRIPTS #######"
|
||||
listitem
|
||||
managescript --modify
|
||||
|
||||
### CREATE NEW SCRIPT ###
|
||||
elif [ "$1" == "-c" ]; then
|
||||
createscript
|
||||
|
||||
### REMOVE SCRIPT ###
|
||||
elif [ "$1" == "-r" ]; then
|
||||
removescript
|
||||
|
||||
### COMMAND LISTS ###
|
||||
else
|
||||
echo "-----------------------------"
|
||||
echo " List of brc-scripts command "
|
||||
echo "-----------------------------"
|
||||
echo " -c | Create New Script "
|
||||
echo " -m | Modify Script "
|
||||
echo " -l | Scripts List "
|
||||
echo " -e | Enable Scripts "
|
||||
echo " -d | Disable Scripts "
|
||||
echo " -da | Disable All Scripts "
|
||||
echo " -ea | Enable All Scripts "
|
||||
echo " -r | Remove Script "
|
||||
echo "-----------------------------"
|
||||
fi
|
||||
}
|
||||
365
installer/scripts-needed/brc-script.sh
Executable file
365
installer/scripts-needed/brc-script.sh
Executable file
@@ -0,0 +1,365 @@
|
||||
#!/bin/bash
|
||||
|
||||
###############
|
||||
### OPTIONS ###
|
||||
###############
|
||||
editor="vim"
|
||||
|
||||
#################
|
||||
### VARIABLES ###
|
||||
#################
|
||||
home_folder="$HOME/"
|
||||
available_scripts="${home_folder}.bashrc.d/scripts-available/"
|
||||
enabled_scripts="${home_folder}.bashrc.d/scripts-enabled/"
|
||||
needed_scripts="${home_folder}.bashrc.d/scripts-needed"
|
||||
bin_folder="${home_folder}.bashrc.d/scripts-removed/"
|
||||
bashrc="${home_folder}.bashrc"
|
||||
|
||||
#################
|
||||
### FUNCTIONS ###
|
||||
#################
|
||||
|
||||
# Refresh Bash #
|
||||
refresh-brc(){
|
||||
if [ "$1" == "-dis" ]; then
|
||||
echo "------------------------------------"
|
||||
ccecho -t bblue "[ Bashrc Refreshed ]"
|
||||
echo "You can't use the old commands from now!"
|
||||
echo "------------------------------------"
|
||||
elif [ "$1" == "-en" ]; then
|
||||
echo "------------------------------------"
|
||||
ccecho -t bblue "[ Bashrc Refreshed ]"
|
||||
echo "------------------------------------"
|
||||
ccecho -t bgreen -s bold "You can you the new commands from now!"
|
||||
echo "------------------------------------"
|
||||
else
|
||||
ccecho -t bblue "[ Bashrc Refreshed ]"
|
||||
fi
|
||||
source "$bashrc"
|
||||
}
|
||||
|
||||
|
||||
createscript() {
|
||||
echo "------------------------------------"
|
||||
echo " Creation New Scripts: "
|
||||
echo "------------------------------------"
|
||||
echo "Name of the script: "
|
||||
read namenewscript
|
||||
if [ -f "${available_scripts}$namenewscript" ]; then
|
||||
ccecho -t byellow "Script already exists!"
|
||||
else
|
||||
newscriptav="${available_scripts}$namenewscript.sh"
|
||||
|
||||
### INITIALIZZATION NEW SCRIPT ###
|
||||
touch $newscriptav
|
||||
echo "#!/bin/bash" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### OPTIONS ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### VARIABLES ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### FUNCTIONS ###" >> $newscriptav
|
||||
echo "${namenewscript}() {" >> $newscriptav
|
||||
echo "# Add your code here!" >> $newscriptav
|
||||
echo 'echo "This is the new script"' >> $newscriptav
|
||||
echo "}" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### EXECUTE ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
### END NEW SCRIPT ###
|
||||
|
||||
vim "$newscriptav"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "------------------------------------"
|
||||
echo " Editor aborted!"
|
||||
echo " Continue or remove $namenewscript?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | Continue "
|
||||
echo " 2 | Abort "
|
||||
echo " Def | Continue "
|
||||
echo "------------------------------------"
|
||||
read answer
|
||||
if [ "${answer}x" = "2x" ]; then
|
||||
rm "$newscriptav"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
echo "------------------------------------"
|
||||
echo " Script $namenewscript created!"
|
||||
echo " Do you want to enable it?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | yes "
|
||||
echo " 2 | no "
|
||||
echo " Def | no "
|
||||
echo "------------------------------------"
|
||||
read answer
|
||||
if [ "$answer" -eq 1 ]; then
|
||||
ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh"
|
||||
refresh-brc -en
|
||||
else
|
||||
ccecho -t byellow "Script not enabled!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
listitem() {
|
||||
index=0
|
||||
for i in $(ls "$available_scripts"); do
|
||||
inotext=${i:0:-3}
|
||||
(( index ++ ))
|
||||
enabled=""
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
enabled='-'
|
||||
fi
|
||||
if [ "$enabled" == "-" ]; then
|
||||
printf "%5d | %1s %s\n" "$index" "$( ccecho -t blue -s bold $enabled)" "$( ccecho -t green $inotext)"
|
||||
else
|
||||
printf "%5d | %1s %s\n" "$index" "$enabled" "$( ccecho -t yellow $inotext)"
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
managescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Select the index: "
|
||||
echo "------------------------------------"
|
||||
read manageindex
|
||||
index2=1
|
||||
for i in $(ls "$available_scripts"); do
|
||||
if [ "$manageindex" == "$index2" ]; then
|
||||
# DISABLE WITH NUMBER #
|
||||
if [ "$1" == "--disable" ]; then
|
||||
if [ ! -f "${enabled_scripts}$i" ]; then
|
||||
ccecho -t byellow "Script not enabled!"
|
||||
else
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
ccecho -t bmagenta -s bold "[ Scripts $inoext Disabled ]"
|
||||
refresh-brc -dis
|
||||
fi
|
||||
# ENABLE WITH NUMBER #
|
||||
elif [ "$1" == "--enable" ]; then
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
ccecho -t bblue "Script already enabled!"
|
||||
else
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "------------------------------------"
|
||||
ccecho -t bgreen -s bold "[ Scripts $inoext Enabled ]"
|
||||
refresh-brc -en
|
||||
fi
|
||||
|
||||
# MODIFY WITH NUMBER #
|
||||
elif [ "$1" == "--modify" ]; then
|
||||
if [ "$editor" == "vim" ]; then
|
||||
vim "$available_scripts$i"
|
||||
elif [ "$editor" == "nano" ]; then
|
||||
nano "$available_scripts$i"
|
||||
else
|
||||
echo "------------"
|
||||
echo " 1 - nano "
|
||||
echo " 2 - vim "
|
||||
echo " def - vim "
|
||||
echo "------------"
|
||||
read ched
|
||||
if [ "$ched" == "1" ]; then
|
||||
nano "$available_scripts$i"
|
||||
else
|
||||
vim "$available_scripts$i"
|
||||
fi
|
||||
fi
|
||||
clear
|
||||
echo "------------------------------------"
|
||||
echo "Would you like to rename the script?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | yes "
|
||||
echo " 2 | no "
|
||||
echo " default | no "
|
||||
echo "------------------------------------"
|
||||
read renscr
|
||||
if [ $renscr == "1" ]; then
|
||||
clear
|
||||
countloop=0
|
||||
while [ $countloop -lt 1 ]; do
|
||||
echo "------------------------------------"
|
||||
echo "Insert new name:"
|
||||
read renamenow
|
||||
echo "------------------------------------"
|
||||
echo "Is the name correct? "
|
||||
echo "------------------------------------"
|
||||
echo " 1 | no "
|
||||
echo " 0 | yes "
|
||||
echo " default | yes "
|
||||
echo "------------------------------------"
|
||||
read confirm
|
||||
if [ "$confirm" == "1" ]; then
|
||||
countloop=0
|
||||
clear
|
||||
echo "------------------------------------"
|
||||
echo "Rename again the file:"
|
||||
else
|
||||
wasenabled=0
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
unlink "$enabled_scripts$i"
|
||||
ccecho -t byellow "[ Temporary Disabled Script ]"
|
||||
wasenabled=1
|
||||
fi
|
||||
mv "$available_scripts$i" "${available_scripts}$renamenow.sh"
|
||||
ccecho -t blue "[ Script $i renamed to $renamenow.sh ]"
|
||||
if [ "$wasenabled" -eq 1 ]; then
|
||||
ln -sf "${available_scripts}$renamenow.sh" "${enabled_scripts}$renamenow.sh"
|
||||
ccecho -t bgreen "[ Script Enabled Again ]"
|
||||
fi
|
||||
countloop=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
refresh-brc -en
|
||||
# REMOVE SCRIPT #
|
||||
elif [ "$1" == "--remove" ]; then
|
||||
if [ ! -d "$bin_folder" ]; then
|
||||
mkdir $bin_folder
|
||||
fi
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
unlink "${enabled_scripts}$i"
|
||||
ccecho -t yellow "[ Script $i unabled! ]"
|
||||
fi
|
||||
removed_data="$i-`date +%F`_`date +%T`"
|
||||
mv "${available_scripts}$i" "${bin_folder}$removed_data"
|
||||
ccecho -t bmagenta "[ Script $i removed! ] "
|
||||
echo "You can find it in the folder: "
|
||||
echo "'$bin_folder' "
|
||||
echo "------------------------------------"
|
||||
refresh-brc
|
||||
fi
|
||||
|
||||
break
|
||||
fi
|
||||
((index2++))
|
||||
done
|
||||
}
|
||||
|
||||
removescript(){
|
||||
echo "------------------------------------"
|
||||
echo " Remove Script "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --remove
|
||||
}
|
||||
|
||||
enablescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Enable Scripts "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --enable
|
||||
}
|
||||
|
||||
enableallscript() {
|
||||
echo "------------------------------------"
|
||||
echo " Enable All Scripts "
|
||||
echo "------------------------------------"
|
||||
for i in $(ls "$available_scripts"); do
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo -n "enabled " && ccecho -t green -s underline "$inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
ccecho -t bgreen -s bold "[ All available scripts enabled ]"
|
||||
refresh-brc -en
|
||||
}
|
||||
|
||||
|
||||
disablescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Disable Scripts "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --disable
|
||||
}
|
||||
|
||||
|
||||
disableallscript() {
|
||||
echo "------------------------------------"
|
||||
echo " Disable All Enabled Scripts "
|
||||
echo "------------------------------------"
|
||||
# Disabilita tutti gli script
|
||||
for i in $(ls "$enabled_scripts"); do
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo -n "disabled " && ccecho -t red -s underline "$inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
ccecho -t bmagenta -s bold "[ All Scripts Disabled ]"
|
||||
refresh-brc -dis
|
||||
}
|
||||
|
||||
#################
|
||||
### EXECUTION ###
|
||||
#################
|
||||
|
||||
# Main Script #
|
||||
brc-script() {
|
||||
### ENABLE SCRIPTS ###
|
||||
if [ "$1" == "-e" ]; then
|
||||
enablescript
|
||||
|
||||
### ENABLE ALL SCRIPTS ###
|
||||
elif [ "$1" == "-ea" ]; then
|
||||
enableallscript
|
||||
|
||||
### DISABLE SCRIPT ###
|
||||
elif [ "$1" == "-d" ]; then
|
||||
disablescript
|
||||
|
||||
### DISABLE ALL SCRIPTS ###
|
||||
elif [ "$1" == "-da" ]; then
|
||||
disableallscript
|
||||
|
||||
### SCRIPTS LIST ###
|
||||
elif [ "$1" == "-l" ]; then
|
||||
echo "------------------------------------"
|
||||
echo " Scripts List "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
echo "------------------------------------"
|
||||
echo " The script preceded by the"
|
||||
echo " '-' character is active. "
|
||||
echo "------------------------------------"
|
||||
|
||||
### MODIFY SCRIPTS ###
|
||||
elif [ "$1" == "-m" ]; then
|
||||
echo "###### MODIFY SCRIPTS #######"
|
||||
listitem
|
||||
managescript --modify
|
||||
|
||||
### CREATE NEW SCRIPT ###
|
||||
elif [ "$1" == "-c" ]; then
|
||||
createscript
|
||||
|
||||
### REMOVE SCRIPT ###
|
||||
elif [ "$1" == "-r" ]; then
|
||||
removescript
|
||||
|
||||
### COMMAND LISTS ###
|
||||
else
|
||||
echo "-----------------------------"
|
||||
echo " List of brc-scripts command "
|
||||
echo "-----------------------------"
|
||||
echo " -c | Create New Script "
|
||||
echo " -m | Modify Script "
|
||||
echo " -l | Scripts List "
|
||||
echo " -e | Enable Scripts "
|
||||
echo " -d | Disable Scripts "
|
||||
echo " -da | Disable All Scripts "
|
||||
echo " -ea | Enable All Scripts "
|
||||
echo " -r | Remove Script "
|
||||
echo "-----------------------------"
|
||||
fi
|
||||
}
|
||||
|
||||
51
installer/scripts-needed/ccecho.sh
Normal file
51
installer/scripts-needed/ccecho.sh
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
ccecho() {
|
||||
local text_color=""
|
||||
local bg_color=""
|
||||
local style=""
|
||||
local msg=""
|
||||
|
||||
# Color and Styles in ANSI code
|
||||
declare -A COLORS=(
|
||||
[black]=30 [red]=31 [green]=32 [yellow]=33 [blue]=34
|
||||
[magenta]=35 [cyan]=36 [white]=37
|
||||
[bblack]=90 [bred]=91 [bgreen]=92 [byellow]=93
|
||||
[bblue]=94 [bmagenta]=95 [bcyan]=96 [bwhite]=97
|
||||
)
|
||||
|
||||
declare -A BGCOLORS=(
|
||||
[black]=40 [red]=41 [green]=42 [yellow]=43 [blue]=44
|
||||
[magenta]=45 [cyan]=46 [white]=47
|
||||
[bblack]=100 [bred]=101 [bgreen]=102 [byellow]=103
|
||||
[bblue]=104 [bmagenta]=105 [bcyan]=106 [bwhite]=107
|
||||
)
|
||||
|
||||
declare -A STYLES=(
|
||||
[bold]=1 [dim]=2 [italic]=3 [underline]=4
|
||||
[blink]=5 [reverse]=7 [hidden]=8 [strike]=9
|
||||
)
|
||||
|
||||
# Parsing options
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-t|--text) text_color=${COLORS[$2]}; shift 2 ;;
|
||||
-b|--bg) bg_color=${BGCOLORS[$2]}; shift 2 ;;
|
||||
-s|--style) style=${STYLES[$2]}; shift 2 ;;
|
||||
*) msg+="$1 "; shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
local sequence=""
|
||||
[[ -n "$style" ]] && sequence+="${style};"
|
||||
[[ -n "$text_color" ]] && sequence+="${text_color};"
|
||||
[[ -n "$bg_color" ]] && sequence+="${bg_color};"
|
||||
|
||||
if [[ -n "$sequence" ]]; then
|
||||
sequence="${sequence%;}" # remove the last ";"
|
||||
echo -e "\e[${sequence}m${msg}\e[0m"
|
||||
else
|
||||
echo "$msg"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
###############
|
||||
### OPTIONS ###
|
||||
###############
|
||||
editor="vim"
|
||||
|
||||
#################
|
||||
### VARIABLES ###
|
||||
#################
|
||||
home_folder="$HOME/"
|
||||
available_scripts="${home_folder}.bashrc.d/scripts-available/"
|
||||
enabled_scripts="${home_folder}.bashrc.d/scripts-enabled/"
|
||||
needed_scripts="${home_folder}.bashrc.d/scripts-needed"
|
||||
bin_folder="${home_folder}.bashrc.d/scripts-removed/"
|
||||
bashrc="${home_folder}.bashrc"
|
||||
|
||||
#################
|
||||
### FUNCTIONS ###
|
||||
#################
|
||||
|
||||
# Refresh Bash #
|
||||
refresh-brc(){
|
||||
if [ "$1" == "-dis" ]; then
|
||||
echo "------------------------------------"
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
echo "You can't use the old commands from now!"
|
||||
echo "------------------------------------"
|
||||
elif [ "$1" == "-en" ]; then
|
||||
echo "------------------------------------"
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
echo "------------------------------------"
|
||||
echo "You can you the new commands from now!"
|
||||
echo "------------------------------------"
|
||||
else
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
fi
|
||||
source "$bashrc"
|
||||
}
|
||||
|
||||
|
||||
createscript() {
|
||||
echo "------------------------------------"
|
||||
echo " Creation New Scripts: "
|
||||
echo "------------------------------------"
|
||||
echo "Name of the script: "
|
||||
read namenewscript
|
||||
if [ -f "${available_scripts}$namenewscript" ]; then
|
||||
echo "Script already exists!"
|
||||
else
|
||||
newscriptav="${available_scripts}$namenewscript.sh"
|
||||
|
||||
### INITIALIZZATION NEW SCRIPT ###
|
||||
touch $newscriptav
|
||||
echo "#!/bin/bash" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### OPTIONS ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### VARIABLES ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### FUNCTIONS ###" >> $newscriptav
|
||||
echo "${namenewscript}() {" >> $newscriptav
|
||||
echo "# Add your code here!" >> $newscriptav
|
||||
echo 'echo "This is the new script"' >> $newscriptav
|
||||
echo "}" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "### EXECUTE ###" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
echo "" >> $newscriptav
|
||||
### END NEW SCRIPT ###
|
||||
|
||||
vim "$newscriptav"
|
||||
echo "------------------------------------"
|
||||
echo " Script $namenewscript created!"
|
||||
echo " Do you want to enable it?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | yes "
|
||||
echo " 2 | no "
|
||||
echo " Def | no "
|
||||
echo "------------------------------------"
|
||||
read answer
|
||||
if [ "$answer" -eq 1 ]; then
|
||||
ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh"
|
||||
refresh-brc -en
|
||||
else
|
||||
echo "Script not enabled!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
listitem() {
|
||||
index=0
|
||||
for i in $(ls "$available_scripts"); do
|
||||
inotext=${i:0:-3}
|
||||
(( index ++ ))
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
echo "$index) - $inotext"
|
||||
else
|
||||
echo "$index) $inotext"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
managescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Select the index: "
|
||||
echo "------------------------------------"
|
||||
read manageindex
|
||||
index2=1
|
||||
for i in $(ls "$available_scripts"); do
|
||||
if [ "$manageindex" == "$index2" ]; then
|
||||
# DISABLE WITH NUMBER #
|
||||
if [ "$1" == "--disable" ]; then
|
||||
if [ ! -f "${enabled_scripts}$i" ]; then
|
||||
echo "Script not enabled!"
|
||||
else
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "[ Scripts $inoext Disabled ]"
|
||||
refresh-brc -dis
|
||||
fi
|
||||
# ENABLE WITH NUMBER #
|
||||
elif [ "$1" == "--enable" ]; then
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
echo "Script already enabled!"
|
||||
else
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "------------------------------------"
|
||||
echo "[ Scripts $inoext Enabled ]"
|
||||
refresh-brc -en
|
||||
fi
|
||||
|
||||
# MODIFY WITH NUMBER #
|
||||
elif [ "$1" == "--modify" ]; then
|
||||
if [ "$editor" == "vim" ]; then
|
||||
vim "$available_scripts$i"
|
||||
elif [ "$editor" == "nano" ]; then
|
||||
nano "$available_scripts$i"
|
||||
else
|
||||
echo "------------"
|
||||
echo " 1 - nano "
|
||||
echo " 2 - vim "
|
||||
echo " def - vim "
|
||||
echo "------------"
|
||||
read ched
|
||||
if [ "$ched" == "1" ]; then
|
||||
nano "$available_scripts$i"
|
||||
else
|
||||
vim "$available_scripts$i"
|
||||
fi
|
||||
fi
|
||||
clear
|
||||
echo "------------------------------------"
|
||||
echo "Would you like to rename the script?"
|
||||
echo "------------------------------------"
|
||||
echo " 1 | yes "
|
||||
echo " 2 | no "
|
||||
echo " default | no "
|
||||
echo "------------------------------------"
|
||||
read renscr
|
||||
if [ $renscr == "1" ]; then
|
||||
clear
|
||||
countloop=0
|
||||
while [ $countloop -lt 1 ]; do
|
||||
echo "------------------------------------"
|
||||
echo "Insert new name:"
|
||||
read renamenow
|
||||
echo "------------------------------------"
|
||||
echo "Is the name correct? "
|
||||
echo "------------------------------------"
|
||||
echo " 1 | no "
|
||||
echo " 0 | yes "
|
||||
echo " default | yes "
|
||||
echo "------------------------------------"
|
||||
read confirm
|
||||
if [ "$confirm" == "1" ]; then
|
||||
countloop=0
|
||||
clear
|
||||
echo "------------------------------------"
|
||||
echo "Rename again the file:"
|
||||
else
|
||||
wasenabled=0
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
unlink "$enabled_scripts$i"
|
||||
echo "[ Temporary Disabled Script ]"
|
||||
wasenabled=1
|
||||
fi
|
||||
mv "$available_scripts$i" "${available_scripts}$renamenow.sh"
|
||||
echo "[ Script $i renamed to $renamenow.sh ]"
|
||||
if [ "$wasenabled" -eq 1 ]; then
|
||||
ln -sf "${available_scripts}$renamenow.sh" "${enabled_scripts}$renamenow.sh"
|
||||
echo "[ Script Enabled Again ]"
|
||||
fi
|
||||
countloop=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
refresh-brc -en
|
||||
# REMOVE SCRIPT #
|
||||
elif [ "$1" == "--remove" ]; then
|
||||
if [ ! -d "$bin_folder" ]; then
|
||||
mkdir $bin_folder
|
||||
fi
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
unlink "${enabled_scripts}$i"
|
||||
echo "[ Script $i unabled! ]"
|
||||
fi
|
||||
removed_data="$i-`date +%F`_`date +%T`"
|
||||
mv "${available_scripts}$i" "${bin_folder}$removed_data"
|
||||
echo "[ Script $i removed! ] "
|
||||
echo "You can find it in the folder: "
|
||||
echo "'$bin_folder' "
|
||||
echo "------------------------------------"
|
||||
refresh-brc
|
||||
fi
|
||||
|
||||
break
|
||||
fi
|
||||
((index2++))
|
||||
done
|
||||
}
|
||||
|
||||
removescript(){
|
||||
echo "------------------------------------"
|
||||
echo " Remove Script "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --remove
|
||||
}
|
||||
|
||||
enablescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Enable Scripts "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --enable
|
||||
}
|
||||
|
||||
enableallscript() {
|
||||
for i in $(ls "$available_scripts"); do
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "enabled $inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
echo "[ All available scripts enabled ]"
|
||||
refresh-brc -en
|
||||
}
|
||||
|
||||
|
||||
disablescript() {
|
||||
echo "------------------------------------"
|
||||
echo " Disable Scripts "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
managescript --disable
|
||||
}
|
||||
|
||||
|
||||
disableallscript() {
|
||||
# Disabilita tutti gli script
|
||||
for i in $(ls "$enabled_scripts"); do
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "disabled $inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
echo "[ All Scripts Disabled ]"
|
||||
refresh-brc -dis
|
||||
}
|
||||
|
||||
#################
|
||||
### EXECUTION ###
|
||||
#################
|
||||
|
||||
# Main Script #
|
||||
brc-script() {
|
||||
### ENABLE SCRIPTS ###
|
||||
if [ "$1" == "-e" ]; then
|
||||
enablescript
|
||||
|
||||
### ENABLE ALL SCRIPTS ###
|
||||
elif [ "$1" == "-ea" ]; then
|
||||
enableallscript
|
||||
|
||||
### DISABLE SCRIPT ###
|
||||
elif [ "$1" == "-d" ]; then
|
||||
disablescript
|
||||
|
||||
### DISABLE ALL SCRIPTS ###
|
||||
elif [ "$1" == "-da" ]; then
|
||||
disableallscript
|
||||
|
||||
### SCRIPTS LIST ###
|
||||
elif [ "$1" == "-l" ]; then
|
||||
echo "------------------------------------"
|
||||
echo " Scripts List "
|
||||
echo "------------------------------------"
|
||||
listitem
|
||||
echo "------------------------------------"
|
||||
echo " The script preceded by the"
|
||||
echo " '-' character is active. "
|
||||
echo "------------------------------------"
|
||||
|
||||
### MODIFY SCRIPTS ###
|
||||
elif [ "$1" == "-m" ]; then
|
||||
echo "###### MODIFY SCRIPTS #######"
|
||||
listitem
|
||||
managescript --modify
|
||||
|
||||
### CREATE NEW SCRIPT ###
|
||||
elif [ "$1" == "-c" ]; then
|
||||
createscript
|
||||
|
||||
### REMOVE SCRIPT ###
|
||||
elif [ "$1" == "-r" ]; then
|
||||
removescript
|
||||
|
||||
### COMMAND LISTS ###
|
||||
else
|
||||
echo "-----------------------------"
|
||||
echo " List of brc-scripts command "
|
||||
echo "-----------------------------"
|
||||
echo " -c | Create New Script "
|
||||
echo " -m | Modify Script "
|
||||
echo " -l | Scripts List "
|
||||
echo " -e | Enable Scripts "
|
||||
echo " -d | Disable Scripts "
|
||||
echo " -da | Disable All Scripts "
|
||||
echo " -ea | Enable All Scripts "
|
||||
echo " -r | Remove Script "
|
||||
echo "-----------------------------"
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user