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

80 lines
2.1 KiB
Bash
Raw Normal View History

# attach/create toolbx container with default or specified name.
2023-10-30 03:49:10 +03:00
# usage: tb [NAME]
tba()
2023-08-08 16:24:15 +03:00
{
2023-10-31 21:36:17 +03:00
local name="${1}"
2023-08-08 16:24:15 +03:00
# set default name.
2023-10-31 21:36:17 +03:00
if [[ "${name}" = "" ]]; then
2023-10-30 03:49:10 +03:00
name="main"
2023-08-08 16:24:15 +03:00
fi
# start container or run command inside it if specified.
2023-10-31 21:36:17 +03:00
if [[ "${2}" = "" ]]; then
2023-08-08 16:24:15 +03:00
# set hostname.
2023-10-31 21:36:17 +03:00
toolbox --container "${name}" run sudo hostname "${HOSTNAME}-${name}"
2023-08-08 16:24:15 +03:00
# try to enter or create if failed.
2023-10-31 21:36:17 +03:00
toolbox enter "${name}" || {
2023-08-08 16:24:15 +03:00
# create container.
2023-10-31 21:36:17 +03:00
toolbox create "${name}"
2023-08-08 16:24:15 +03:00
# initialize container.
2023-10-31 21:36:17 +03:00
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
2023-08-08 16:24:15 +03:00
# enter container, finally.
2023-10-31 21:36:17 +03:00
toolbox enter "${name}"
2023-08-08 16:24:15 +03:00
}
else
# set hostname.
2023-10-31 21:36:17 +03:00
toolbox --container "${name}" run sudo hostname "${HOSTNAME}-${name}"
2023-08-08 16:24:15 +03:00
# run command inside container.
2023-10-31 21:36:17 +03:00
toolbox --container "${name}" run ${@:2}
2023-08-08 16:24:15 +03:00
fi
}
# remove toolbx container with default or specified name.
2023-10-30 03:49:10 +03:00
# usage: tbk [NAME]
2023-08-08 16:24:15 +03:00
tbk()
{
2023-10-31 21:36:17 +03:00
local name="${1}"
2023-08-08 16:24:15 +03:00
# set default name.
2023-10-31 21:36:17 +03:00
if [[ "${name}" = "" ]]; then
2023-10-30 03:49:10 +03:00
name="main"
2023-08-08 16:24:15 +03:00
fi
# stop and remove podman container.
2023-10-31 21:36:17 +03:00
podman stop "${name}" > /dev/null && podman rm "${name}" > /dev/null
2023-08-08 16:24:15 +03:00
}
# install rpm-fusion repository.
2023-10-30 03:49:10 +03:00
# usage: tb_rpmfusion [NAME]
2023-08-08 16:24:15 +03:00
tb_rpmfusion()
{
2023-10-31 21:36:17 +03:00
local name="${1}"
2023-08-08 16:24:15 +03:00
# set default name.
2023-10-31 21:36:17 +03:00
if [[ "${name}" = "" ]]; then
2023-10-30 03:49:10 +03:00
name="main"
2023-08-08 16:24:15 +03:00
fi
# run dnf inside container.
2023-10-31 21:36:17 +03:00
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
}
# list all containers.
2023-10-23 03:31:00 +03:00
alias tbl="toolbox list -c"
# autocomplete.
_tb_containers()
{
2023-10-30 03:49:10 +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