Skip to content

Commit

Permalink
feat: brew state via bind mount
Browse files Browse the repository at this point in the history
fix: colors for bluefin-cli

feat: distrobox-host-exec if command not found.

chore: update readme.

chore: update readme
  • Loading branch information
m2Giles committed Jan 21, 2024
1 parent d061ff3 commit 6f1531c
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
3 changes: 1 addition & 2 deletions quadlets/bluefin-cli/bluefin-cli.container
Original file line number Diff line number Diff line change
Expand Up @@ -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
Volume=/etc/resolv.conf:/etc/resolv.conf:ro
1 change: 0 additions & 1 deletion quadlets/bluefin-cli/bluefin-cli.volume

This file was deleted.

1 change: 0 additions & 1 deletion systemd/bluefin-cli/bluefin-cli-Cellar.volume

This file was deleted.

2 changes: 1 addition & 1 deletion toolboxes/bluefin-cli/Containerfile.bluefin-cli
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
54 changes: 54 additions & 0 deletions toolboxes/bluefin-cli/files/etc/bashrc
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

13 changes: 13 additions & 0 deletions toolboxes/bluefin-cli/files/etc/profile.d/colors.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if [ -z "$PROFILESOURCED" ] && [ "$PS1" ]; then
PROFILESOURCED="Y"
fi
21 changes: 21 additions & 0 deletions toolboxes/bluefin-cli/files/etc/starship.toml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions toolboxes/bluefin-cli/files/root/.bash_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
3 changes: 3 additions & 0 deletions toolboxes/bluefin-cli/files/root/.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
1 change: 0 additions & 1 deletion toolboxes/bluefin-cli/packages.bluefin-cli
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
brew
command-not-found
cosign
eza
git
Expand Down

0 comments on commit 6f1531c

Please sign in to comment.