Last active
June 26, 2025 16:04
-
-
Save cmrfrd/76d96acbb4232cce17fe08fb53d9ded0 to your computer and use it in GitHub Desktop.
bootyeet.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Boot a local ubuntu VM auto installed with yeet | |
# Learn more about yeet: yeet.cx | |
# | |
YEET_KEY="..." | |
echo "boot2yeet starting..." | |
if [ ! -f ./id_rsa.pub ]; then | |
echo "Generating SSH key..." | |
ssh-keygen -t rsa -b 2048 -f ./id_rsa -N "" | |
fi | |
echo "creating user-data..." | |
PUBKEY=$(cat ./id_rsa.pub) | |
cat > user-data << EOF | |
#cloud-config | |
ssh_pwauth: false | |
users: | |
- name: ubuntu | |
sudo: ALL=(ALL) NOPASSWD:ALL | |
groups: [sudo, adm, systemd-journal] | |
ssh_authorized_keys: | |
- $PUBKEY | |
runcmd: | |
- echo "Starting runcmd execution..." | |
- sudo apt-get update | |
- echo "apt-get update completed" | |
- curl -fsSL https://yeet.cx | sh | |
- echo "yeet installation completed" | |
- | | |
echo "Creating yeetd environment file..." | |
# Create yeetd environment file with flags | |
cat > /etc/default/yeetd << EOL | |
FLAGS="--key $YEET_KEY" | |
EOL | |
echo "yeetd environment file created" | |
- | | |
echo "Restarting yeetd service..." | |
# Restart yeetd to pick up the new flags | |
systemctl restart yeetd | |
echo "yeetd service restarted" | |
- echo "Creating yeet shutdown service..." | |
- | | |
cat > /etc/systemd/system/yeet-logout.service << 'EOF' | |
[Unit] | |
Description=Yeet logout on shutdown | |
DefaultDependencies=false | |
Before=shutdown.target reboot.target halt.target | |
After=yeetd.service | |
Requires=yeetd.service | |
PartOf=yeetd.service | |
[Service] | |
Type=oneshot | |
User=root | |
ExecStart=/bin/true | |
ExecStop=/bin/bash -c '/usr/bin/yeet logout --delete-host && echo "success" || echo "fail"' | |
TimeoutStopSec=30 | |
RemainAfterExit=yes | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
- systemctl daemon-reload | |
- systemctl status yeet-logout.service | |
- systemctl enable yeet-logout.service | |
- echo "yeet-logout service created and enabled" | |
EOF | |
echo "instance-id: yeet-vm" > meta-data | |
echo "creating seed img..." | |
nix shell --impure nixpkgs#cloud-utils --command cloud-localds seed.img user-data meta-data | |
# download img from https://cloud-images.ubuntu.com/releases/oracular/release/ | |
IMG_FILE="ubuntu-24.10-server-cloudimg-amd64.img" | |
if [ ! -f "$IMG_FILE" ]; then | |
echo "Downloading Ubuntu cloud image..." | |
wget "https://cloud-images.ubuntu.com/releases/24.10/release/$IMG_FILE" | |
fi | |
# Boot the VM with cloud-init | |
echo "starting vm..." | |
nix shell --impure nixpkgs#qemu --command qemu-img resize $IMG_FILE 4G | |
nix shell --impure nixpkgs#qemu --command qemu-system-x86_64 \ | |
-enable-kvm \ | |
-m 2048 \ | |
-cpu host \ | |
-smp 2 \ | |
-drive file=$IMG_FILE,format=qcow2,if=virtio \ | |
-drive file=seed.img,format=raw,if=virtio,readonly=on \ | |
-netdev user,id=net0,hostfwd=tcp::2222-:22 \ | |
-device virtio-net-pci,netdev=net0 \ | |
-nographic \ | |
-serial mon:stdio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment