Skip to content

Commit

Permalink
fix: improve ujust bluefin-cli (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2Giles authored Jan 30, 2024
1 parent 2bedbb1 commit c64c8fb
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 74 deletions.
7 changes: 2 additions & 5 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ COPY etc/yum.repos.d/ /etc/yum.repos.d/
COPY packages.json /tmp/packages.json
COPY build.sh /tmp/build.sh
COPY image-info.sh /tmp/image-info.sh
COPY fetch-quadlets.sh /tmp/fetch-quadlets.sh
# Copy ublue-update.toml to tmp first, to avoid being overwritten.
COPY usr/etc/ublue-update/ublue-update.toml /tmp/ublue-update.toml

Expand Down Expand Up @@ -77,17 +78,13 @@ RUN curl -Lo /tmp/starship.tar.gz "https://github.com/starship/starship/releases
RUN wget https://copr.fedorainfracloud.org/coprs/ublue-os/staging/repo/fedora-"${FEDORA_MAJOR_VERSION}"/ublue-os-staging-fedora-"${FEDORA_MAJOR_VERSION}".repo -O /etc/yum.repos.d/ublue-os-staging-fedora-"${FEDORA_MAJOR_VERSION}".repo && \
/tmp/build.sh && \
/tmp/image-info.sh && \
/tmp/fetch-quadlets.sh && \
pip install --prefix=/usr yafti && \
pip install --prefix=/usr topgrade && \
rpm-ostree install ublue-update && \
mkdir -p /usr/etc/flatpak/remotes.d && \
wget -q https://dl.flathub.org/repo/flathub.flatpakrepo -P /usr/etc/flatpak/remotes.d && \
cp /tmp/ublue-update.toml /usr/etc/ublue-update/ublue-update.toml && \
mkdir -p /usr/etc/containers/systemd/users && \
wget -q https://raw.githubusercontent.com/ublue-os/toolboxes/main/quadlets/bluefin-cli/bluefin-cli.container -P /usr/etc/containers/systemd/users && \
printf "\n\n[Install]\nWantedBy=bluefin-cli.target" >> /usr/etc/containers/systemd/users/bluefin-cli.container && \
sed -i '/AutoUpdate.*/ s/^#*/#/' /usr/etc/containers/systemd/users/bluefin-cli.container && \
sed -i 's/ContainerName=bluefin/ContainerName=bluefin-cli/' /usr/etc/containers/systemd/users/bluefin-cli.container && \
if [[ "${FEDORA_MAJOR_VERSION}" -ge "39" ]]; then \
systemctl enable tuned.service \
; fi && \
Expand Down
82 changes: 82 additions & 0 deletions fetch-quadlets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

set -oue pipefail

# Make Directory
mkdir -p /usr/etc/containers/systemd/users

# bluefin-cli
wget --output-document="/usr/etc/containers/systemd/users/bluefin-cli.container" --quiet https://raw.githubusercontent.com/ublue-os/toolboxes/main/quadlets/bluefin-cli/bluefin-cli.container
printf "\n\n[Install]\nWantedBy=bluefin-cli.target" >> /usr/etc/containers/systemd/users/bluefin-cli.container
sed -i '/AutoUpdate.*/ s/^#*/#/' /usr/etc/containers/systemd/users/bluefin-cli.container
sed -i 's/ContainerName=bluefin/ContainerName=bluefin-cli/' /usr/etc/containers/systemd/users/bluefin-cli.container

# bluefin-dx-cli
wget --output-document="/usr/etc/containers/systemd/users/bluefin-dx-cli.container" --quiet https://raw.githubusercontent.com/ublue-os/toolboxes/main/quadlets/bluefin-cli/bluefin-dx-cli.container
printf "\n\n[Install]\nWantedBy=bluefin-dx-cli.target" >> /usr/etc/containers/systemd/users/bluefin-cli.container
sed -i '/AutoUpdate.*/ s/^#*/#/' /usr/etc/containers/systemd/users/bluefin-dx-cli.container
sed -i 's/ContainerName=bluefin/ContainerName=bluefin-dx-cli/' /usr/etc/containers/systemd/users/bluefin-dx-cli.container

# fedora-toolbox
wget --output-document="/usr/etc/containers/systemd/users/fedora-toolbox.container" --quiet https://raw.githubusercontent.com/ublue-os/toolboxes/main/quadlets/fedora-toolbox/fedora-distrobox-quadlet.container
printf "\n\n[Install]\nWantedBy=fedora-toolbox.target" >> /usr/etc/containers/systemd/users/fedora-toolbox.container
sed -i '/AutoUpdate.*/ s/^#*/#/' /usr/etc/containers/systemd/users/fedora-toolbox.container
sed -i 's/ContainerName=fedora-distrobox-quadlet/ContainerName=fedora-toolbox/' /usr/etc/containers/systemd/users/fedora-toolbox.container

# ubuntu-toolbox
wget --output-document="/usr/etc/containers/systemd/users/ubuntu-toolbox.container" --quiet https://raw.githubusercontent.com/ublue-os/toolboxes/main/quadlets/ubuntu-toolbox/ubuntu-distrobox-quadlet.container
printf "\n\n[Install]\nWantedBy=ubuntu-toolbox.target" >> /usr/etc/containers/systemd/users/ubuntu-toolbox.container
sed -i '/AutoUpdate.*/ s/^#*/#/' /usr/etc/containers/systemd/users/ubuntu-toolbox.container
sed -i 's/ContainerName=ubuntu-distrobox-quadlet/ContainerName=ubuntu-toolbox/' /usr/etc/containers/systemd/users/ubuntu-toolbox.container

# wolfi-toolbox
wget --output-document="/usr/etc/containers/systemd/users/wolfi-toolbox.container" --quiet https://raw.githubusercontent.com/ublue-os/toolboxes/main/quadlets/wolfi-toolbox/wolfi-distrobox-quadlet.container
printf "\n\n[Install]\nWantedBy=wolfi-toolbox.target" >> /usr/etc/containers/systemd/users/wolfi-toolbox.container
sed -i '/AutoUpdate.*/ s/^#*/#/' /usr/etc/containers/systemd/users/wolfi-toolbox.container
sed -i 's/ContainerName=wolfi-quadlet/ContainerName=wolfi-toolbox/' /usr/etc/containers/systemd/users/wolfi-toolbox.container

# wolfi-dx-toolbox
wget --output-document="/usr/etc/containers/systemd/users/wolfi-dx-toolbox.container" --quiet https://raw.githubusercontent.com/ublue-os/toolboxes/main/quadlets/wolfi-toolbox/wolfi-dx-distrobox-quadlet.container
printf "\n\n[Install]\nWantedBy=wolfi-dx-toolbox.target" >> /usr/etc/containers/systemd/users/wolfi-dx-toolbox.container
sed -i '/AutoUpdate.*/ s/^#*/#/' /usr/etc/containers/systemd/users/wolfi-dx-toolbox.container
sed -i 's/ContainerName=wolfi-quadlet/ContainerName=wolfi-dx-toolbox/' /usr/etc/containers/systemd/users/wolfi-dx-toolbox.container

# Make systemd targets and restart services for topgrade
mkdir -p /usr/lib/systemd/user
mkdir -p /usr/share/ublue-os/bluefin-cli
QUADLET_TARGETS=(
"bluefin-cli"
"bluefin-dx-cli"
"fedora-toolbox"
"ubuntu-toolbox"
"wolfi-toolbox"
"wolfi-dx-toolbox"
)
for i in "${QUADLET_TARGETS[@]}"
do
cat > "/usr/lib/systemd/user/${i}.target" <<EOF
[Unit]
Description=${i}"target for ${i} quadlet
[Install]
WantedBy=default.target
EOF
cat > "/usr/lib/systemd/user/${i}-update.service" <<EOF
[Unit]
Description=Restart ${i}.service to rebuild container
[Service]
Type=oneshot
ExecStart=-/usr/bin/podman pull ghcr.io/ublue-os/${i}:latest
ExecStart=-/usr/bin/systemctl --user restart ${i}.service
EOF

cat > "/usr/share/ublue-os/bluefin-cli/${i}.sh" <<EOF
#!/bin/sh
if test ! -f "/run/user/\${UID}/container-entry" && test -n "\$PS1" && test \$(podman ps --all --filter name=$i | grep -q " $i\$") && test ! -f "/run/.containerenv"; then
touch "/run/user/\${UID}/container-entry"
exec /usr/bin/distrobox-enter $i
fi
EOF
done
58 changes: 1 addition & 57 deletions just/custom.just
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,7 @@ benchmark:

# Configure bluefin-cli Terminal Experience
bluefin-cli:
#!/usr/bin/bash
source /usr/lib/ujust/ujust.sh
printf "Set Up bluefin-cli\n"
printf "Would you like to use Host Terminal or Container as default Terminal?\n"
TERMINAL_CHOICE=$(Choose Host Container)
if test "$TERMINAL_CHOICE" = "Container"; then
printf "You have chosen Container.\nWould you like to use quadlets to manage your container?\n"
MANAGEMENT_CHOICE=$(Choose Quadlet Distrobox)
else
printf "You have chosen to use Host Terminal. Would you like to setup Bluefin-cli container?\n"
MANAGEMENT_CHOICE=$(Choose Quadlet Distrobox No)
fi
if /usr/bin/systemctl is-enabled --quiet bluefin-cli.target; then
printf "Bluefin quadlet is already enabled, would you like to disable it?\n"
DISABLE=$(Choose Yes No)
if test "$DISABLE" = "No"; then
printf "Not Disabling existing container quadlet.\n"
printf "Finished Bluefin-CLI setup, rerun with ujust bluefin-cli to reconfigure\n"
printf "Exiting...\n"
exit 0
elif test "$DISABLE" = "Yes"; then
printf "Disabling Bluefin-CLI\n"
/usr/bin/systemctl --user disable --now bluefin-cli.target
/usr/bin/systemctl --user stop bluefin-cli.service
fi
fi
if /usr/bin/env DBX_CONTAINER_MANAGER="podman" /usr/bin/distrobox-list | grep -qE "^| bluefin-cli .*"; then
printf "You already have a container named bluefin-cli. Would you like to destroy it?\n"
REBUILD=$(Choose Yes No)
if test "$REBUILD" = "No"; then
printf "Not replacing existing container.\n"
printf "Finished Bluefin-CLI setup, rerun with ujust bluefin-cli to reconfigure\n"
printf "Exiting...\n"
exit 0
elif test "$REBUILD" = "Yes"; then
printf "Destroying existing bluefin-cli container\n"
/usr/bin/env DBX_CONTAINER_MANAGER="podman" /usr/bin/distrobox-rm -f bluefin-cli
fi
fi
if test "$MANAGEMENT_CHOICE" = "Quadlet"; then
/usr/bin/systemctl --user enable --now bluefin-cli.target
/usr/bin/systemctl --user start bluefin-cli.service
elif test "$MANAGEMENT_CHOICE" = "Distrobox"; then
/usr/bin/env DBX_CONTAINER_MANAGER="podman" /usr/bin/distrobox-create --nvidia Y --image ghcr.io/ublue-os/bluefin-cli:latest -n bluefin-cli --no-entry --pull
/usr/bin/env DBX_CONTAINER_MANAGER="podman" /usr/bin/distrobox-enter bluefin-cli -- bash -l -c "exit"
else
printf "You have chosen none.\n"
printf "Finished Bluefin-CLI setup, rerun with ujust bluefin-cli to reconfigure\n"
printf "Exiting...\n"
exit 0
fi
if test "$TERMINAL_CHOICE" = "Container"; then
printf "Setting first terminal be Container for bash using ~/.bashrc.d\n"
printf "Enter into container using prompt's menu after first entry\n"
ln -sf /usr/share/ublue-os/bluefin-cli/bluefin-cli.sh ~/.bashrc.d/zz-container.sh
fi
printf "Finished Bluefin-CLI setup, rerun with ujust bluefin-cli to reconfigure\n"
/usr/libexec/bluefin-cli.sh

# Enable Cockpit for web-based system management | https://cockpit-project.org/
cockpit:
Expand Down
7 changes: 0 additions & 7 deletions usr/lib/systemd/user/bluefin-cli-update.service

This file was deleted.

5 changes: 0 additions & 5 deletions usr/lib/systemd/user/bluefin-cli.target

This file was deleted.

Loading

0 comments on commit c64c8fb

Please sign in to comment.