Sunday, June 15, 2025

Getting rtcwake working on Bluefin

#!/bin/bash
# User systemd setup for auto suspend/wake on Bluefin

#Please run these two commands manually:

#1. First, create the sudo rule:
echo "$(whoami) ALL=(ALL) NOPASSWD: /usr/bin/rtcwake" | sudo tee /etc/sudoers.d/rtcwake-nopasswd
#bash
#2. Then set the correct permissions:
sudo chmod 440 /etc/sudoers.d/rtcwake-nopasswd
#bash
#After you've run those commands, we can test if passwordless sudo works:
sudo rtcwake -m show
#❯ sudo rtcwake -m show
#alarm: off

# Create user service directory

mkdir -p ~/.config/systemd/user

# Create helper script for suspend + rtcwake
mkdir -p ~/bin
cat > ~/bin/rtc-suspend.sh << 'EOF'
#!/bin/bash
# Helper script to suspend and set RTC wake time
# Usage: rtc-suspend.sh "wake_time_description"

if [ $# -ne 1 ]; then
echo "Usage: $0 'wake_time_description'"
echo "Example: $0 '15:00 today'"
exit 1
fi

wake_time="$1"
wake_timestamp=$(date -d "$wake_time" +%s)

if [ $? -ne 0 ]; then
echo "Error: Invalid time format '$wake_time'"
exit 1
fi

echo "Setting RTC wake for: $(date -d @$wake_timestamp)"

# Set the RTC wake time first (before suspend)
sudo rtcwake -m no -t $wake_timestamp

if [ $? -eq 0 ]; then
echo "RTC wake time set successfully"
# Small delay then suspend
sleep 2
systemctl suspend
else
echo "Error: Failed to set RTC wake time"
exit 1
fi
EOF

chmod +x ~/bin/rtc-suspend.sh

# Create the morning suspend service (9 AM - 3 PM)
cat > ~/.config/systemd/user/morning-suspend.service << 'EOF'
[Unit]
Description=Suspend system at 9 AM until 3 PM
After=graphical-session.target

[Service]
Type=oneshot
Environment=PATH=/usr/local/bin:/usr/bin:/bin:%h/bin
ExecStart=%h/bin/rtc-suspend.sh "15:00 today"
Restart=no

[Install]
WantedBy=default.target
EOF

# Create the evening suspend service (9 PM - 5 AM)
cat > ~/.config/systemd/user/evening-suspend.service << 'EOF'
[Unit]
Description=Suspend system at 9 PM until 5 AM tomorrow
After=graphical-session.target

[Service]
Type=oneshot
Environment=PATH=/usr/local/bin:/usr/bin:/bin:%h/bin
ExecStart=%h/bin/rtc-suspend.sh "05:00 tomorrow"
Restart=no

[Install]
WantedBy=default.target
EOF

# Create timer for 9 AM suspend
cat > ~/.config/systemd/user/morning-suspend.timer << 'EOF'
[Unit]
Description=Trigger morning suspend at 9 AM
Requires=morning-suspend.service

[Timer]
OnCalendar=*-*-* 09:00:00
Persistent=true
AccuracySec=1min

[Install]
WantedBy=timers.target
EOF

# Create timer for 9 PM suspend
cat > ~/.config/systemd/user/evening-suspend.timer << 'EOF'
[Unit]
Description=Trigger evening suspend at 9 PM
Requires=evening-suspend.service

[Timer]
OnCalendar=*-*-* 21:00:00
Persistent=true
AccuracySec=1min

[Install]
WantedBy=timers.target
EOF

echo "Setting up user systemd services..."

# Reload user systemd daemon
systemctl --user daemon-reload

# Enable the services
systemctl --user enable morning-suspend.timer
systemctl --user enable evening-suspend.timer
#systemctl --user enable wake-notification.service

# Start the timers
systemctl --user start morning-suspend.timer
systemctl --user start evening-suspend.timer

# Enable lingering so services run when not logged in
sudo loginctl enable-linger $USER

echo ""
echo "=== SETUP COMPLETE ==="
echo ""
echo "Your system will now:"
echo " • Suspend at 9:00 AM and wake at 3:00 PM"
echo " • Suspend at 9:00 PM and wake at 5:00 AM"
echo ""
echo "Active hours:"
echo " • 5:00 AM - 9:00 AM (4 hours)"
echo " • 3:00 PM - 9:00 PM (6 hours)"
echo ""
echo "=== TESTING ==="
echo "Test your RTC wake capability first:"
echo " sudo rtcwake -m mem -s 30 # 30-second test"
echo ""
echo "Test the helper script:"
echo " ~/bin/rtc-suspend.sh '$(date -d '+2 minutes' +'%H:%M today')'"
echo ""
echo "=== MONITORING ==="
echo "Check timer status:"
echo " systemctl --user list-timers"
echo ""
echo "View service logs:"
echo " journalctl --user -u morning-suspend.service"
echo " journalctl --user -u evening-suspend.service"
echo ""
echo "=== CONTROL ==="
echo "Disable (stop automatic suspend):"
echo " systemctl --user stop morning-suspend.timer evening-suspend.timer"
echo " systemctl --user disable morning-suspend.timer evening-suspend.timer"
echo ""
echo "Re-enable:"
echo " systemctl --user enable morning-suspend.timer evening-suspend.timer"
echo " systemctl --user start morning-suspend.timer evening-suspend.timer"
echo ""
echo "=== TROUBLESHOOTING ==="
echo "If suspend doesn't work, check:"
echo " 1. Your user can suspend: 'systemctl suspend'"
echo " 2. RTC wake works: 'sudo rtcwake -m mem -s 30'"
echo " 3. User lingering is enabled: 'loginctl show-user $USER'"
echo ""
echo "Common issues on Bluefin:"
echo " • May need to add user to 'wheel' group for suspend permissions"
echo " • Some hardware doesn't support RTC wake from suspend"
echo " • Check BIOS/UEFI settings for wake-on-RTC support"



Monday, June 2, 2025

Export existing distrobox environment to another machine

 

On the Source Machine (Exporting)

see also: https://www.perplexity.ai/search/detailed-instructions-on-how-t-g5vpRZiUSx6L6aE6fk.5og#0

1. List Your Distroboxes

First, identify which distrobox you want to export:

bash
distrobox list

2. Stop the Distrobox

Stop the container you want to export (replace mydevbox with your container name):

bash
distrobox stop mydevbox

3. Export the Container

Use podman to export the container as a tar archive:

bash
podman export mydevbox > mydevbox-export.tar

4. Save the Distrobox Configuration

Export the distrobox configuration to recreate it with the same settings:

bash
distrobox generate-entry mydevbox > mydevbox-config.desktop

Alternatively, note down the original creation command. You can find this information with:

bash
podman inspect mydevbox | grep -A 20 "Labels"

Transferring Files

Transfer both files to your target machine using your preferred method:

Via SCP:

bash
scp mydevbox-export.tar mydevbox-config.desktop user@target-machine:~/

Via USB drive, network share, or cloud storage: Simply copy both files to your transfer medium.

On the Target Machine (Importing)

1. Import the Container Image

Import the tar file as a new container image:

bash
podman import mydevbox-export.tar mydevbox:latest

2. Recreate the Distrobox

Create a new distrobox using the imported image. If you have the original creation command, use that. Otherwise, create it with basic settings:

bash
distrobox create --name mydevbox --image mydevbox:latest

If you need specific options (like additional volumes, environment variables, etc.), add them:

bash
distrobox create --name mydevbox --image mydevbox:latest \
  --additional-packages "package1 package2" \
  --volume /host/path:/container/path \
  --nvidia  # if you need GPU access

3. Enter and Verify

Enter the distrobox to verify everything transferred correctly:

bash
distrobox enter mydevbox

Check that your development tools, configurations, and files are present.

Alternative Method: Using Distrobox Assemble

For a more automated approach, you can create an assemble configuration file:

1. Create a Configuration File

On the source machine, create a YAML file describing your setup:

yaml
# mydevbox-assemble.yml
container_name: mydevbox
image: registry.fedoraproject.org/fedora-toolbox:38
additional_packages:
  - git
  - nodejs
  - python3-pip
  - vim
init_hooks:
  - "pip install --user some-package"
  - "npm install -g some-global-package"

2. Transfer and Apply

Transfer this file to the target machine and run:

bash
distrobox assemble create --file mydevbox-assemble.yml

Important Notes

  • Home Directory Integration: Distrobox automatically mounts your home directory, so personal files and configs in ~/ will be available immediately on the new machine.
  • Host Integration: Applications installed in the distrobox and integrated with the host (using distrobox-export) will need to be re-exported on the new machine.
  • System Dependencies: Ensure both machines have the same version of distrobox and podman for best compatibility.
  • Storage Space: The exported tar file can be quite large depending on your container's contents. Clean up unnecessary files before export if space is a concern.

This method preserves your entire development environment including installed packages, configurations, and any custom setups within the container.

Getting rtcwake working on Bluefin

#!/bin/bash # User systemd setup for auto suspend/wake on Bluefin #Please run these two commands manually: #1. First, create the sudo rule: ...