From 6f1531c75354c235b251765731c1ec304a1e9bb4 Mon Sep 17 00:00:00 2001 From: m2Giles <69128853+m2Giles@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:05:56 -0500 Subject: [PATCH 1/2] feat: brew state via bind mount fix: colors for bluefin-cli feat: distrobox-host-exec if command not found. chore: update readme. chore: update readme --- README.md | 4 +- quadlets/bluefin-cli/bluefin-cli.container | 3 +- quadlets/bluefin-cli/bluefin-cli.volume | 1 - systemd/bluefin-cli/bluefin-cli-Cellar.volume | 1 - .../bluefin-cli/Containerfile.bluefin-cli | 2 +- toolboxes/bluefin-cli/files/etc/bashrc | 54 +++++++++++++++++++ .../profile.d/00-bluefin-cli-brew-firstrun.sh | 40 ++++++++++++++ .../files/etc/profile.d/bash_completion.sh | 20 +++++++ .../profile.d/bluefin-cli-brew-firstrun.sh | 14 ----- .../bluefin-cli/files/etc/profile.d/colors.sh | 13 +++++ .../profile.d/command-not-found-host-exec.sh | 13 +++++ .../files/etc/profile.d/zz-profile_sourced.sh | 3 ++ toolboxes/bluefin-cli/files/etc/starship.toml | 21 ++++++++ .../bluefin-cli/files/root/.bash_profile | 3 ++ toolboxes/bluefin-cli/files/root/.bashrc | 3 ++ toolboxes/bluefin-cli/packages.bluefin-cli | 1 - 16 files changed, 174 insertions(+), 22 deletions(-) delete mode 100644 quadlets/bluefin-cli/bluefin-cli.volume delete mode 100644 systemd/bluefin-cli/bluefin-cli-Cellar.volume create mode 100644 toolboxes/bluefin-cli/files/etc/bashrc create mode 100644 toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh create mode 100644 toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh delete mode 100644 toolboxes/bluefin-cli/files/etc/profile.d/bluefin-cli-brew-firstrun.sh create mode 100644 toolboxes/bluefin-cli/files/etc/profile.d/colors.sh create mode 100644 toolboxes/bluefin-cli/files/etc/profile.d/command-not-found-host-exec.sh create mode 100644 toolboxes/bluefin-cli/files/etc/profile.d/zz-profile_sourced.sh create mode 100644 toolboxes/bluefin-cli/files/etc/starship.toml create mode 100644 toolboxes/bluefin-cli/files/root/.bash_profile create mode 100644 toolboxes/bluefin-cli/files/root/.bashrc diff --git a/README.md b/README.md index 79a7556..e6619fe 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Podman supports starting containers via a systemd generator. Quadlets replaced t Inside the quadlets directory are example quadlets for ubuntu, fedora, wolfi, and bluefin-cli. Distrobox and Toolbox provide a convenient way to integrate the containers into your host. For both ubuntu and fedora you can use either toolbox or distrobox. Wolfi and bluefin-cli are currently only compatible with distrobox. The quadlets mimic the create and enter commands to setup the container. You can use these by copying them to `~/.config/containers/systemd`. When using the prompt terminal, they will appear in the menu as available containers. The `Exec=` line of the distrobox quadlets can be modified to include additional packages. -To get automatic updates you will need to enable `podman-auto-update.timer` which by default will auto-update at midnight. +To get automatic updates you will need to enable `podman-auto-update.timer` which by default will auto-update at midnight. Quadlets support creating volumes using a `.volume` unit. These volumes can be accessed by other containers by prepending the name of `.volume` with `systemd`. ### Systemd one-shots An alternative method for having automatic toolbox startup is to leverage systemd one-shot services and distrobox assemble commands. @@ -18,7 +18,7 @@ Distrobox assemble enables the user to declare a setup without going through the To utilize these, place the user service file in `~/.config/systemd/user` and make sure the assemble file is in place. The ones inside the repo are set to replace the existing container of the same to behave similar to the quadlet. Again you can access `.volume` by using the name of the volume unit prepended with `systemd`. ### Bluefin-CLI -Bluefin-cli is built from our wolfi-toolbox. It has `linuxbrew` configured to work and have your `linuxbrew` packages preserved between container rebuilds. This works by using a podman volume to store your installed packages. Updates to brew itself happen automatically with container rebuilds while you manage when to update your brew packages. Quadlets support creating volumes using a `.volume` unit. These volumes can be accessed by other containers by prepending the name of `.volume` with `systemd`. +Bluefin-cli is built from our wolfi-toolbox. It has `linuxbrew` configured to work and have your `linuxbrew` packages preserved between container rebuilds. This works by bind mounting a directory from your `$HOME`. Updates to brew itself happen automatically with container rebuilds while you manage when to update your brew packages. # Stats diff --git a/quadlets/bluefin-cli/bluefin-cli.container b/quadlets/bluefin-cli/bluefin-cli.container index a97714f..277dd3e 100644 --- a/quadlets/bluefin-cli/bluefin-cli.container +++ b/quadlets/bluefin-cli/bluefin-cli.container @@ -37,5 +37,4 @@ Volume=/var/log/journal Volume=/var/home/%u:/var/home/%u:rslave Volume=%t:%t:rslave Volume=/etc/hosts:/etc/hosts:ro -Volume=/etc/resolv.conf:/etc/resolv.conf:ro -Volume=bluefin-cli.volume:/home/linuxbrew \ No newline at end of file +Volume=/etc/resolv.conf:/etc/resolv.conf:ro \ No newline at end of file diff --git a/quadlets/bluefin-cli/bluefin-cli.volume b/quadlets/bluefin-cli/bluefin-cli.volume deleted file mode 100644 index a153d05..0000000 --- a/quadlets/bluefin-cli/bluefin-cli.volume +++ /dev/null @@ -1 +0,0 @@ -[Volume] \ No newline at end of file diff --git a/systemd/bluefin-cli/bluefin-cli-Cellar.volume b/systemd/bluefin-cli/bluefin-cli-Cellar.volume deleted file mode 100644 index a153d05..0000000 --- a/systemd/bluefin-cli/bluefin-cli-Cellar.volume +++ /dev/null @@ -1 +0,0 @@ -[Volume] \ No newline at end of file diff --git a/toolboxes/bluefin-cli/Containerfile.bluefin-cli b/toolboxes/bluefin-cli/Containerfile.bluefin-cli index baff8b5..ea74e90 100644 --- a/toolboxes/bluefin-cli/Containerfile.bluefin-cli +++ b/toolboxes/bluefin-cli/Containerfile.bluefin-cli @@ -6,7 +6,7 @@ LABEL com.github.containers.toolbox="true" \ maintainer="jorge.castro@gmail.com" COPY ./toolboxes/bluefin-cli/packages.bluefin-cli /toolbox-packages -COPY ./toolboxes/bluefin-cli/files/etc /etc +COPY ./toolboxes/bluefin-cli/files / # Update image, Install Packages, and move /home/linuxbrew RUN apk update && \ diff --git a/toolboxes/bluefin-cli/files/etc/bashrc b/toolboxes/bluefin-cli/files/etc/bashrc new file mode 100644 index 0000000..21df2e1 --- /dev/null +++ b/toolboxes/bluefin-cli/files/etc/bashrc @@ -0,0 +1,54 @@ +# /etc/bashrc + +# System wide functions and aliases +# Environment stuff goes in /etc/profile + +# It's NOT a good idea to change this file unless you know what you +# are doing. It's much better to create a custom.sh shell script in +# /etc/profile.d/ to make custom changes to your environment, as this +# will prevent the need for merging in future updates. + +# Prevent doublesourcing +if [ -z "$PROFILESOURCED" ] && [ "$PS1" ]; then + PROFILESOURCED="Y" +fi + +if [ -z "$BASHRCSOURCED" ]; then + BASHRCSOURCED="Y" + + # are we an interactive shell? + if [ "$PS1" ]; then + if [ -z "$PROMPT_COMMAND" ]; then + case $TERM in + xterm*) + PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"' + ;; + screen*) + PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"' + ;; + *) + [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default + ;; + esac + fi + # Turn on parallel history + shopt -s histappend + # Turn on checkwinsize + shopt -s checkwinsize + [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ " + # You might want to have e.g. tty in prompt (e.g. more virtual machines) + # and console windows + # If you want to do so, just add e.g. + # if [ "$PS1" ]; then + # PS1="[\u@\h:\l \W]\\$ " + # fi + # to your custom modification shell script in /etc/profile.d/ directory + fi + STARSHIP_CONFIG=/etc/starship.toml + export STARSHIP_CONFIG + eval "$(starship init $SHELL)" +fi + + +# vim:ts=4:sw=4 + diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh b/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh new file mode 100644 index 0000000..0ad8d4d --- /dev/null +++ b/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh @@ -0,0 +1,40 @@ +if test "$(id -u)" -gt "0"; then + green=$'\033[32m' + bold=$'\033[1m' + normal=$'\033[0m' + if test ! -f /etc/linuxbrew.firstrun; then + printf "\nBluefin-CLI First Run Setup\n\n" + printf "Setting up sudo for ${bold}${USER}${normal}...\t\t\t " + su-exec root chmod +r /etc/sudoers + if grep -qv "${UID}" /etc/sudoers; then + echo "#${UID} ALL = (root) NOPASSWD:ALL" | su-exec root tee -a /etc/sudoers > /dev/null + fi + su-exec root chmod 600 /etc/sudoers + printf "${green}[ OK ]${normal}\n" + fi + + if test ! -d /home/linuxbrew/.linuxbrew && test ! -d /usr/local/share/bash-completion; then + printf "Setting up Linuxbrew...\t\t\t\t " + if test ! -d "${XDG_DATA_HOME:-$HOME/.local/share}"/bluefin-cli; then + mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"/bluefin-cli + fi + if test ! -d /home/linuxbrew; then + su-exec root mkdir -p /home/linuxbrew + fi + if test ! -d /home/linuxbrew/.linuxbrew; then + su-exec root mount --bind "${XDG_DATA_HOME:-$HOME/.local/share}"/bluefin-cli /home/linuxbrew + su-exec root cp -R /home/homebrew/.linuxbrew /home/linuxbrew/ + su-exec root chown -R $UID /home/linuxbrew + fi + printf "${green}[ OK ]${normal}\n" + su-exec root mkdir -p /usr/local/share/bash-completion + if test ! -d /usr/loca/share/bash-completion/completions; then + su-exec root mount --bind /run/host/usr/share/bash-completion /usr/local/share/bash-completion + fi + fi + + if test ! -f /etc/linuxbrew.firstrun; then + su-exec root touch /etc/linuxbrew.firstrun + printf "\nBluefin-CLI first run complete!\n\n" + fi +fi \ No newline at end of file diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh b/toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh new file mode 100644 index 0000000..684a3dc --- /dev/null +++ b/toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh @@ -0,0 +1,20 @@ +# shellcheck shell=sh disable=SC1091,SC2039,SC2166 +# Check for interactive bash and that we haven't already been sourced. +if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BASH_COMPLETION_VERSINFO-}" = x ]; then + + # Check for recent enough version of bash. + if [ "${BASH_VERSINFO[0]}" -gt 4 ] || + [ "${BASH_VERSINFO[0]}" -eq 4 -a "${BASH_VERSINFO[1]}" -ge 2 ]; then + [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && + . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" + if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then + # Source completion code. + . /usr/share/bash-completion/bash_completion + fi + if shopt -q progcomp && [ -r /usr/local/share/bash-completion/bash_completion ]; then + # Source completion code. + . /usr/local/share/bash-completion/bash_completion + fi + fi + +fi diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/bluefin-cli-brew-firstrun.sh b/toolboxes/bluefin-cli/files/etc/profile.d/bluefin-cli-brew-firstrun.sh deleted file mode 100644 index 686592e..0000000 --- a/toolboxes/bluefin-cli/files/etc/profile.d/bluefin-cli-brew-firstrun.sh +++ /dev/null @@ -1,14 +0,0 @@ -if test "$(id -u)" -gt "0" && test ! -f /etc/linuxbrew.firstrun; then - echo "First Run Setup" - if test ! -d /home/linuxbrew; then - su-exec root mv /home/homebrew /home/linuxbrew - else - echo "Getting newest repo version of brew" - su-exec root cp -R /home/homebrew/.linuxbrew /home/linuxbrew/ - fi - echo "Making sure linuxbrew is owned by ${USER}" - su-exec root chown -R $UID /home/linuxbrew - echo "Setting up sudo for ${USER}" - echo "#${UID} ALL = (root) NOPASSWD:ALL" | su-exec root tee -a /etc/sudoers > /dev/null - su-exec root touch /etc/linuxbrew.firstrun -fi diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/colors.sh b/toolboxes/bluefin-cli/files/etc/profile.d/colors.sh new file mode 100644 index 0000000..0b1a297 --- /dev/null +++ b/toolboxes/bluefin-cli/files/etc/profile.d/colors.sh @@ -0,0 +1,13 @@ +# LS Colors via Eza +alias ll='eza -l --icons=auto --group-directories-first' 2>/dev/null +alias l.='eza -d .*' 2>/dev/null +alias ls='eza' 2>/dev/null +alias l1='eza -1' + +# Grep Colors +alias grep='grep --color=auto' 2>/dev/null +alias egrep='grep -E --color=auto' 2>/dev/null +alias fgrep='grep -F --color=auto' 2>/dev/null +alias xzgrep='xzgrep --color=auto' 2>/dev/null +alias xzegrep='xzegrep --color=auto' 2>/dev/null +alias xzfgrep='xzfgrep --color=auto' 2>/dev/null \ No newline at end of file diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/command-not-found-host-exec.sh b/toolboxes/bluefin-cli/files/etc/profile.d/command-not-found-host-exec.sh new file mode 100644 index 0000000..0a98fc4 --- /dev/null +++ b/toolboxes/bluefin-cli/files/etc/profile.d/command-not-found-host-exec.sh @@ -0,0 +1,13 @@ +command_not_found_handle() { +# don't run if not in a container + if [ ! -e /run/.containerenv ] && [ ! -e /.dockerenv ]; then + exit 127 + fi + + distrobox-host-exec "${@}" +} +if [ -n "${ZSH_VERSION-}" ]; then + command_not_found_handler() { + command_not_found_handle "$@" + } +fi diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/zz-profile_sourced.sh b/toolboxes/bluefin-cli/files/etc/profile.d/zz-profile_sourced.sh new file mode 100644 index 0000000..e08c3d3 --- /dev/null +++ b/toolboxes/bluefin-cli/files/etc/profile.d/zz-profile_sourced.sh @@ -0,0 +1,3 @@ +if [ -z "$PROFILESOURCED" ] && [ "$PS1" ]; then + PROFILESOURCED="Y" +fi diff --git a/toolboxes/bluefin-cli/files/etc/starship.toml b/toolboxes/bluefin-cli/files/etc/starship.toml new file mode 100644 index 0000000..9be3695 --- /dev/null +++ b/toolboxes/bluefin-cli/files/etc/starship.toml @@ -0,0 +1,21 @@ +[character] +success_symbol = '[\$](bold green dimmed)' +error_symbol = '[\$](bold red)' + +[container] +symbol='📦' +format='[$symbol](bold green dimmed) ' + +[directory] +style = 'bold cyan dimmed' + +[hostname] +ssh_only = false +style = 'green bold dimmed' +format = '[$ssh_symbol$hostname]($style) ' + +[username] +style_user = 'green bold dimmed' +style_root = 'red bold' +format = '[$user]($style)@' +show_always = true diff --git a/toolboxes/bluefin-cli/files/root/.bash_profile b/toolboxes/bluefin-cli/files/root/.bash_profile new file mode 100644 index 0000000..a459ace --- /dev/null +++ b/toolboxes/bluefin-cli/files/root/.bash_profile @@ -0,0 +1,3 @@ +if [ -f ~/.bashrc ]; then + . ~/.bashrc +fi \ No newline at end of file diff --git a/toolboxes/bluefin-cli/files/root/.bashrc b/toolboxes/bluefin-cli/files/root/.bashrc new file mode 100644 index 0000000..2782dcd --- /dev/null +++ b/toolboxes/bluefin-cli/files/root/.bashrc @@ -0,0 +1,3 @@ +if [ -f /etc/bashrc ]; then + . /etc/bashrc +fi \ No newline at end of file diff --git a/toolboxes/bluefin-cli/packages.bluefin-cli b/toolboxes/bluefin-cli/packages.bluefin-cli index c1a83e7..b543cb9 100644 --- a/toolboxes/bluefin-cli/packages.bluefin-cli +++ b/toolboxes/bluefin-cli/packages.bluefin-cli @@ -1,5 +1,4 @@ brew -command-not-found cosign eza git From c56a11735e788d51d9a836d78d1fc492798da47d Mon Sep 17 00:00:00 2001 From: m2Giles <69128853+m2Giles@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:05:56 -0500 Subject: [PATCH 2/2] feat: brew state via bind mount fix: colors for bluefin-cli feat: distrobox-host-exec if command not found. chore: update readme. chore: update readme fix: sudo set for user --- .../files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh b/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh index 0ad8d4d..f943b73 100644 --- a/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh +++ b/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh @@ -5,11 +5,7 @@ if test "$(id -u)" -gt "0"; then if test ! -f /etc/linuxbrew.firstrun; then printf "\nBluefin-CLI First Run Setup\n\n" printf "Setting up sudo for ${bold}${USER}${normal}...\t\t\t " - su-exec root chmod +r /etc/sudoers - if grep -qv "${UID}" /etc/sudoers; then - echo "#${UID} ALL = (root) NOPASSWD:ALL" | su-exec root tee -a /etc/sudoers > /dev/null - fi - su-exec root chmod 600 /etc/sudoers + echo "#${UID} ALL = (root) NOPASSWD:ALL" | su-exec root tee -a /etc/sudoers > /dev/null printf "${green}[ OK ]${normal}\n" fi