Skip to content

Commit

Permalink
fix: make sure quadlet is running before launching via shortcut (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2Giles authored Apr 21, 2024
1 parent 1598ede commit c520f2c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
41 changes: 4 additions & 37 deletions build_files/base/fetch-quadlets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,30 @@ 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
cat /usr/share/ublue-os/bluefin-cli/ptyxis-integration >> /usr/etc/containers/systemd/users/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
cat /usr/share/ublue-os/bluefin-cli/ptyxis-integration >> /usr/etc/containers/systemd/users/bluefin-dx-cli.container
printf "\n\n[Install]\nWantedBy=bluefin-dx-cli.target" >> /usr/etc/containers/systemd/users/bluefin-dx-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
cat /usr/share/ublue-os/bluefin-cli/ptyxis-integration >> /usr/etc/containers/systemd/users/fedora-toolbox.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
cat /usr/share/ublue-os/bluefin-cli/ptyxis-integration >> /usr/etc/containers/systemd/users/ubuntu-toolbox.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
cat /usr/share/ublue-os/bluefin-cli/ptyxis-integration >> /usr/etc/containers/systemd/users/wolfi-toolbox.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
cat /usr/share/ublue-os/bluefin-cli/ptyxis-integration >> /usr/etc/containers/systemd/users/wolfi-dx-toolbox.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
# Make systemd targets
mkdir -p /usr/lib/systemd/user
mkdir -p /usr/share/ublue-os/bluefin-cli
QUADLET_TARGETS=(
"bluefin-cli"
"bluefin-dx-cli"
Expand All @@ -67,22 +48,8 @@ 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 -n "\$PS1" && test ! -f "/run/.containerenv" && test ! -f "/run/user/\${UID}/container-entry" && test \$(podman ps --all --filter name=$i | grep -q " $i\$") ; then
touch "/run/user/\${UID}/container-entry"
exec /usr/bin/distrobox-enter $i
fi
EOF
# Add ptyxis integration and have autostart tied to systemd targets
cat /usr/share/ublue-os/bluefin-cli/ptyxis-integration >> /usr/etc/containers/systemd/users/"$i".container
printf "\n\n[Install]\nWantedBy=%s.target" "$i" >> /usr/etc/containers/systemd/users/"$i".container
done
3 changes: 2 additions & 1 deletion build_files/base/systemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ systemctl enable dconf-update.service
systemctl --global enable ublue-flatpak-manager.service
systemctl enable ublue-update.timer
systemctl enable ublue-system-setup.service
systemctl --global enable ublue-user-setup.service
systemctl --global enable ublue-user-setup.service
systemctl --global enable podman-auto-update.timer
47 changes: 47 additions & 0 deletions system_files/shared/usr/libexec/distrobox-quadlet-ptyxis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/bash
# shellcheck disable=SC1091,SC2154
# Shellcheck SC1091 => sourcing /usr/share/ublue-os/bluefin-cli/known-containers
# Shellcheck SC2154 => known containers Associative Array declared in above source

# Container Name and Target Name for Quadlet
name=$1

# Source Known Containers used with ptyxis profiles
. /usr/share/ublue-os/bluefin-cli/known-containers
if test -z "${known_container[$name]}"; then
notify-send "Unknown Container $name... Bailing Out..."
exit 1
fi

# Host isn't a container.
if test "${name}" == "Host"; then

# Start Ptyxis
ptyxis --tab-with-profile="${known_container[$name]}" --new-window

else

# Check if quadlet target is enabled
if ! eval systemctl --user --quiet is-enabled "${name}".target; then
notify-send "${name} quadlet not enabled... enabling"
systemctl --user enable --now "${name}".target
fi

# Check if quadlet is running
if ! eval systemctl --user --quiet is-active "${name}".service; then
notify-send "${name} quadlet not running... this may take awhile to start"
systemctl --user restart "${name}".service
# Give the Quadlet a second to startup
sleep 1
fi

# Final Check... If the container doesn't exist bail out.
if ! grep -q "${name}" <<< "$(podman ps -a --no-trunc --format "{{.Names}}")"; then
notify-send "${name} not created properly... Bailing Out..."
exit 1
fi

# Start Ptyxis
ptyxis --tab-with-profile="${known_container[$name]}" --new-window
fi

8 changes: 4 additions & 4 deletions system_files/silverblue/usr/etc/dconf/db/local.d/01-ublue
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ min-alpha=0.5

[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0]
binding='<Control><Alt>t'
command='ptyxis --tab-with-profile=2871e8027773ae74d6c87a5f659bbc74 --new-window'
command='/usr/libexec/distrobox-quadlet-ptyxis.sh Host'
name='Host Ptyxis'

[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1]
binding='<Control><Alt>u'
command='ptyxis --tab-with-profile=4741cb2eb3614750b79edc5c4b8c08b3 --new-window'
command='/usr/libexec/distrobox-quadlet-ptyxis.sh ubuntu-toolbox'
name='Ubuntu Ptyxis'

[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2]
Expand All @@ -74,12 +74,12 @@ name='mission-center'

[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3]
binding='<Control><Alt>Return'
command="ptyxis --new-window"
command='/usr/libexec/distrobox-quadlet-ptyxis.sh bluefin-cli'
name='Bluefin Ptyxis'

[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4]
binding='<Control><Alt>f'
command="ptyxis --tab-with-profile=d6fe45489ed74fada5d95d715449ce7e --new-window"
command='/usr/libexec/distrobox-quadlet-ptyxis.sh fedora-toolbox'
name='Fedora Ptyxis'

[org/gnome/settings-daemon/plugins/media-keys]
Expand Down

0 comments on commit c520f2c

Please sign in to comment.