This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.config/bash/module/Toolbx.sh

81 lines
2.2 KiB
Bash
Raw Normal View History

2023-12-07 04:02:47 +03:00
# Attach/create toolbx container with specified name.
2023-12-07 05:11:26 +03:00
# By default uses `main` name.
2023-12-07 04:02:47 +03:00
# Usage: tba [NAME]
2023-12-07 01:44:42 +03:00
function tba() {
2023-12-05 21:50:45 +03:00
local name="${1}"
# set default name.
if [[ "${name}" = "" ]]; then
name="main"
fi
2023-08-08 16:24:15 +03:00
2023-12-05 21:50:45 +03:00
# start container or run command inside it if specified.
if [[ "${2}" = "" ]]; then
# set hostname.
toolbox --container "${name}" run sudo hostname "${HOSTNAME}-${name}"
# try to enter or create if failed.
toolbox enter "${name}" || {
# create container.
toolbox create "${name}"
# initialize container.
toolbox --container "${name}" run sudo hostname "${HOSTNAME}-${name}"
# toolbox --container "$name" run sudo rm /root/.bashrc
# toolbox --container "$name" run sudo ln -s $HOME/.linux /root/.linux
# toolbox --container "$name" run sudo ln -s /root/.linux/bash/bashrc.sh /root/.bashrc
# enter container, finally.
toolbox enter "${name}"
}
else
# set hostname.
toolbox --container "${name}" run sudo hostname "${HOSTNAME}-${name}"
# run command inside container.
toolbox --container "${name}" run ${@:2}
fi
2023-08-08 16:24:15 +03:00
}
2023-12-07 04:02:47 +03:00
# Remove toolbx container with specified name.
2023-12-07 05:11:26 +03:00
# By default uses `main` name.
2023-12-07 04:02:47 +03:00
# Usage: tbk [NAME]
2023-12-07 01:44:42 +03:00
function tbk() {
2023-12-05 21:50:45 +03:00
local name="${1}"
# set default name.
if [[ "${name}" = "" ]]; then
name="main"
fi
2023-08-08 16:24:15 +03:00
2023-12-05 21:50:45 +03:00
# stop and remove podman container.
podman stop "${name}" > /dev/null && podman rm "${name}" > /dev/null
2023-08-08 16:24:15 +03:00
}
2023-12-07 04:02:47 +03:00
# Install rpm-fusion repository into container with specified name.
2023-12-07 05:11:26 +03:00
# By default uses `main` name.
2023-12-07 04:02:47 +03:00
# Usage: tb_rpmfusion [NAME]
2023-12-07 01:44:42 +03:00
function tb_rpmfusion() {
2023-12-05 21:50:45 +03:00
local name="${1}"
# set default name.
if [[ "${name}" = "" ]]; then
name="main"
fi
# run dnf inside container.
toolbox --container "${name}" run sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
2023-08-08 16:24:15 +03:00
}
2023-12-07 04:02:47 +03:00
# List all available containers.
2023-12-07 01:44:42 +03:00
function tbl() {
2023-12-07 00:42:06 +03:00
toolbox list -c
}
2023-10-23 03:31:00 +03:00
2023-12-07 04:02:47 +03:00
# Autocomplete with available containers.
2023-12-07 01:44:42 +03:00
function _tb_containers() {
2023-12-05 21:50:45 +03:00
_autocomplete_first "$(toolbox list -c | sed -e '1d' | awk '{ print $2 }')"
2023-10-23 03:31:00 +03:00
}
complete -F _tb_containers tba tbk tb_rpmfusion