Skip to content

Commit

Permalink
feat: Adds redhat version (#3)
Browse files Browse the repository at this point in the history
This version adds support for RedHat's custom update-alternatives version.

* Adds redhat version + docs
* Renames my-alternatives -> my-alternatives-debian
* Adds SPDX header to scripts
* Adds SUSE info
  • Loading branch information
TekWizely authored Nov 9, 2021
1 parent 6db7fad commit 5499123
Show file tree
Hide file tree
Showing 3 changed files with 1,892 additions and 214 deletions.
120 changes: 106 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# My-Alternatives<br/>(hacking update-alternatives to make local changes)
[![MIT license](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/tekwizely/pre-commit-golang/blob/master/LICENSE)

My-Alternatives is a light-weight wrapper over _update-alternatives_, using it to make changes to user-level configurations.
My-Alternatives is a light-weight wrapper over _update-alternatives_, offering user-level customizations.

Supports _Debian_, _SUSE_<sup>*</sup>, and _RedHat_

<sub>* for suse support, use the debian version</sub>

-----------------------
### Easy to Get Started

With my-alternatives, configuring custom alternatives is as easy as:

Expand All @@ -17,7 +24,7 @@ _home configuration example_
Your selections will be saved into your `HOME` configuration, and made active in any login shell that performs the initialization routine.
*NOTE:* You can save the initialization routine in your `.profile`
**NOTE:** You can save the initialization routine in your `.profile`
### Per-Shell Configuration
Expand All @@ -41,7 +48,6 @@ When the `HOME` configuration is the active configuration, my-alternatives impor
When a `TEMP` configuration is active, my-alternatives first tries to import from your `HOME` configuration, falling back onto the system-level configuration if the group is not present.
### Manual Import
If you want to import an alternative group into your active configuration without selecting an alternative, you can use the `import` command:
Expand All @@ -50,26 +56,36 @@ _import example_
```shell
$ my-alternatives import <name>
```
-----------
## Commands
Below are tables of the available commands for each supported OS
### Debian / SUSE
### My-Alternatives Commands
**NOTE:** _SUSE_ uses a [rebranded](https://build.opensuse.org/package/view_file/openSUSE:Leap:15.2/update-alternatives/update-alternatives-suse.patch?expand=1) version of _Debian's_ udpate-alternatives.
Below is the list of custom commands that my-alternatives implements:
Until such time as the feature set of the two versions diverges, this project will **just** maintain the _Debian_ vesion.
#### My-Alternatives-Debian Commands
Below is the list of custom commands that _my-alternatives-debian_ implements:
| Command | Description
|--------------------|------------
| `init`, `shellenv` | Prepare the current shell session for user-level alternatives.
| `init-tmp`, `tmp` | Configure the current shell session for temporary (short-lived) changes.
| `select`, `config` | Select the active alternative for group <name>. This is equivalent to `update-alternatives --config` with the adition of the auto-import logic.
| `import` | Import an alternative group <name> into the current configuration.
| `add` | Add an alternative to the group <name> within the current configuration. This is equivalent to `update-alternatives --install` but has _slightly_ different syntax. see `my-alternatives help add` for details.
| `rm-tmp` | Remove the temporary configuration from the current shell session, making the `HOME` configuration active.
| `select`, `config` | Select the active alternative for a group. This is equivalent to `update-alternatives --config` with the adition of the auto-import logic.
| `import` | Import an alternative group into the current configuration.
| `add` | Add an alternative to a group within the current configuration. This is equivalent to `update-alternatives --install` but has _slightly_ different syntax. see `my-alternatives help add` for details.
| `version` | Display my-alternatives version number.
*NOTE:* See `my-alternatives help <command>` to learn about a specific command, including additional options.
**NOTE:** See `my-alternatives help <command>` to learn about a specific command, including additional options.
### Update-Alternatives Commands
#### Debian Update-Alternatives Commands
Below is the list of commands that are implemented as pass-through to the related update-alternatives command:
Below is the list of commands that are implemented as pass-through to the related _Debian_ update-alternatives command:
| My-Alternatives Command | Update-Alternatives Command
|-------------------------|----------------------------
Expand All @@ -91,7 +107,63 @@ My-Alternatives will set the `--admindir` and `--altdir` options to point to you
All additional command-line options are passed-through, unmodified.
*NOTE:* See `update-alternatives --help` or `man update-alternatives` to learn more about the various commands and their options.
**NOTE:** See `update-alternatives --help` or `man update-alternatives` to learn more about the various commands and their options.
### RedHat
#### hacking The system
_RedHat_ has its own implementation of update-alternatives, which is slightly different from the _Debian_ version.
One **major** difference is that it does NOT support the `--query` option, meaning that there's no means of determining an anternative's full configuraiton using _just_ the tool's public API.
In order to support this version, we have to use knowledge of the system's _private_ API. Namely:
* Defaulting the "admin" directory to `/var/lib/alternatives`
* Assuming the name and format of files in the admin directory
* Defaulting the "alt" directory to `/etc/alternatives`
* Assuming the name and nature of files in the alt directory
#### My-Alternatives-RedHat Commands
Below is the list of custom commands that _my-alternatives-redhat_ implements:
| Command | Description
|--------------------|------------
| `init`, `shellenv` | Prepare the current shell session for user-level alternatives.
| `init-tmp`, `tmp` | Configure the current shell session for temporary (short-lived) changes.
| `rm-tmp` | Remove the temporary configuration from the current shell session, making the `HOME` configuration active.
| `select`, `config` | Select the active alternative for a group. This is equivalent to `update-alternatives --config` with the adition of the auto-import logic.
| `import` | Import an alternative group into the current configuration.
| `add` | Add an alternative to a group within the current configuration. This is equivalent to `update-alternatives --install` but has _slightly_ different syntax. see `my-alternatives help add` for details.
| `add-child` | Add an child to an existing alternative for a group within the current configuration. This is equivalent to `update-alternatives --add-slave` but has _slightly_ different syntax. see `my-alternatives help add-child` for details.
| `version` | Display my-alternatives version number.
**NOTE:** See `my-alternatives help <command>` to learn about a specific command, including additional options.
#### RedHat Update-Alternatives Commands
Below is the list of commands that are implemented as pass-through to the related _RedHat_ update-alternatives command:
| My-Alternatives Command | Update-Alternatives Command
|-------------------------|----------------------------
| `select`, `config` | `--config`
| `add-child` | `--add-slave`
| `rm-alt` | `--remove`
| `rm-group`, `rm-grp` | `--remove-all`
| `rm-child` | `--remove-slave`
| `display` | `--display`
| `list` | `--list`
| `set` | `--set`
| `auto` | `--auto`
| `ua-help` | `--help`
| `ua-version` | `--version`
My-Alternatives will set the `--admindir` and `--altdir` options to point to your active configuration.
All additional command-line options are passed-through, unmodified.
**NOTE:** See `update-alternatives --help` or `man update-alternatives` to learn more about the various commands and their options.
### Invoking Update-Alternatives Directly
Expand All @@ -106,7 +178,7 @@ My-Alternatives will set the `--admindir` and `--altdir` options to point to you
All additional command-line options are passed-through, unmodified.
*NOTE:* See `update-alternatives --help` or `man update-alternatives` to learn more about available commands and their options.
**NOTE:** See `update-alternatives --help` or `man update-alternatives` to learn more about available commands and their options.
-------------
## Installing
Expand All @@ -121,6 +193,19 @@ See the [Releases](https://github.com/TekWizely/my-alternatives/releases) page f
git clone git://github.com/TekWizely/my-alternatives.git
```
### Renaming the Scripts
Depending on how you acquire the files, the scripts may be named by their OS flavor, i.e:
* Debian : `my-alternatives-debian`
* RedHat : `my-alternatives-redhat`
Feel free to rename them as desired. Personally, I rename the script **AND** set up a few convenient aliases:
```shell
$ cp my-alternatives-debian ~/bin/my-alternatives
$ alias ma="my-alternatives"
$ alias mua="my-alternatives ua"
```
---------------
## Contributing
Expand All @@ -147,6 +232,8 @@ The `tekwizely/my-alternatives` project is released under the [MIT](https://open
----------------
##### Misc Notes
As of `v0.7.0`, my-alternatives has been split (and renamed) into two scripts: `my-alternatives-debian` and `my-alternatives-redhat`.
As of `v0.6.0`, my-alternatives is a complete re-write. As much as possible, commands are implemented as pass-through to _update-alternatives_, pointing to your active configuration.
My-Alternatives does not require _root / sudo_ privileges to use, as it creates and maintains user-owned configuration directories.
Expand All @@ -155,7 +242,8 @@ My-Alternatives does not require _root / sudo_ privileges to use, as it creates
- Written in _Bash_
- Requires the following system tools:
- `update-alternatives`
- `mktemp`
- `readlink` (redhat version)
- `mktemp` (debian version)
- `umask`
- `dirname`
- `basename`
Expand All @@ -171,3 +259,7 @@ My-Alternatives does not require _root / sudo_ privileges to use, as it creates
- `openSUSE Leap 15.3`
- `SUSE update-alternatives version 1.19.0.4.`
- `Bash 4.4.23(1)-release`
- CentOS
- `CentOS Linux release 8.4.2105`
- `alternatives version 1.13`
- `GNU bash, version 4.4.19(1)-release`
Loading

0 comments on commit 5499123

Please sign in to comment.