wip
This commit is contained in:
parent
03138fb32b
commit
59cb2cade8
1 changed files with 119 additions and 11 deletions
130
README.md
130
README.md
|
@ -23,9 +23,20 @@ So now that you have imported the [distros.sh](distros.sh) script, you can run s
|
|||
|
||||
### `distro-variables`
|
||||
|
||||
There are most of the big linux distros as a variable which contains boolean values.
|
||||
There are most of the big linux distros as a variable which contains boolean values. </br>
|
||||
Also there is a 'distros' variable, containing the fancy distro name. More
|
||||
|
||||
For example, you can run things like..
|
||||
| variable | values |
|
||||
| --------- | ----------------------------------------------------------------------- |
|
||||
| $distros | One value of `arch`, `debian`, `ubuntu`, `fedora`, `opensuse`, `alpine` |
|
||||
| $arch | boolean - `true/false` |
|
||||
| $debian | boolean - `true/false` |
|
||||
| $ubuntu | boolean - `true/false` |
|
||||
| $fedora | boolean - `true/false` |
|
||||
| $opensuse | boolean - `true/false` |
|
||||
| $alpine | boolean - `true/false` |
|
||||
|
||||
Some really simple examples
|
||||
|
||||
```bash
|
||||
if $arch; then
|
||||
|
@ -51,12 +62,109 @@ case "$distros" in
|
|||
esac
|
||||
```
|
||||
|
||||
| variable | values |
|
||||
| --------- | ----------------------------------------------------------------------- |
|
||||
| $arch | boolean: `true`/`false` |
|
||||
| $debian | boolean: `true`/`false` |
|
||||
| $ubuntu | boolean: `true`/`false` |
|
||||
| $fedora | boolean: `true`/`false` |
|
||||
| $opensuse | boolean: `true`/`false` |
|
||||
| $alpine | boolean: `true`/`false` |
|
||||
| $distros | One value of `arch`, `debian`, `ubuntu`, `fedora`, `opensuse`, `alpine` |
|
||||
---
|
||||
|
||||
### **Package managing functions**
|
||||
|
||||
There are two big functions here to mention:
|
||||
|
||||
- **\_install()**
|
||||
- **\_checkAndInstall()**
|
||||
|
||||
#### **\_install()**
|
||||
|
||||
You can simply install a package with the respected packagemanager.
|
||||
|
||||
On arch, it will install with either paru, yay or pacman (in this order) </br>
|
||||
On debian/ubuntu, it will install with either nala or apt-get (in this order)
|
||||
|
||||
Fedora, opensuse and alpine will always use their respected packagemanager
|
||||
|
||||
**Usage:**
|
||||
|
||||
```bash
|
||||
_install curl
|
||||
```
|
||||
|
||||
> Will install curl
|
||||
|
||||
```bash
|
||||
deps=(curl bash git zoxide)
|
||||
|
||||
_install "${deps[@]}"
|
||||
```
|
||||
|
||||
> Will install everything in the `deps` array, but it will install it in one go!
|
||||
|
||||
#### **\_checkAndInstall()**
|
||||
|
||||
If you have many packages being installed, you may want to check if they are installed first, and then install them one by one via an array. You can do this easily with the `checkAndInstall` function. Just pass in an array like `${array[@]}` and it will auto check and install the packages in the array list one by one.
|
||||
|
||||
```bash
|
||||
deps=(git wget curl vim zsh)
|
||||
checkAndInstall "${deps[@]}"
|
||||
```
|
||||
|
||||
> This will install the packages one by one, it will basically do..
|
||||
>
|
||||
> ```bash
|
||||
> for pkg in "${deps[@]}"; do
|
||||
> if ! command_exists $pkg; then
|
||||
> _install $pkg
|
||||
> else
|
||||
> echo "$pkg is already installed"
|
||||
> fi
|
||||
> done
|
||||
> ```
|
||||
|
||||
_**BONUS:**_
|
||||
|
||||
Since bash v5, you can define declared arrays. Which will make dependency installation for various systems extremely easy:
|
||||
|
||||
This is a snippet which i often use with this script sourced..:
|
||||
|
||||
```
|
||||
# INFO:
|
||||
# ╭─────────────────────────────────────────────────────────────────────────╮
|
||||
# │ You can define dependencies for various linux distros here. It will │
|
||||
# │ automagically be pulled via the $pkgArray[$distro] variable │
|
||||
# ╰─────────────────────────────────────────────────────────────────────────╯
|
||||
|
||||
genericDeps=(virt-manager)
|
||||
|
||||
depsDebian=(qemu-system libvirt-dev libvirt-glib-1.0-dev)
|
||||
depsFedora=(qemu libvirt)
|
||||
depsOpensuse=(qemu libvirt)
|
||||
depsArch=(qemu-full libvirt)
|
||||
depsAlpine=()
|
||||
|
||||
declare -A deps=(
|
||||
[debian]="depsDebian"
|
||||
[ubuntu]="depsUbuntu"
|
||||
[fedora]="depsFedora"
|
||||
[opensuse]="depsOpensuse"
|
||||
[arch]="depsArch"
|
||||
[alpine]="depsAlpine"
|
||||
)
|
||||
|
||||
# INFO:
|
||||
# ╭────────────────────────────────────────────────────────────────╮
|
||||
# │ This variable stores the packages you provided for each distro │
|
||||
# ╰────────────────────────────────────────────────────────────────╯
|
||||
declare -n pkgArray="${deps[$distro]}"
|
||||
|
||||
case "$distro" in
|
||||
debian | ubuntu | arch | fedora | opensuse)
|
||||
echo_info "Installing generic dependencies.."
|
||||
checkAndInstall "${genericDeps[@]}"
|
||||
|
||||
echo_info "Installing special dependencies.."
|
||||
checkAndInstall "${pkgArray[@]}"
|
||||
;;
|
||||
*)
|
||||
echo_error "There are no dependencies to install for $distro"
|
||||
return 69
|
||||
;;
|
||||
esac
|
||||
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue