Files
coreapp-dev/uninstall.sh
T
davidandClaude Opus 5.5 1108060432 coreapp: make, deploy and test apps on the Core in the VM
Apps are folders in Federated Core's generic services format (service,
docker-compose.yml.in, env.in, install, uninstall, icon.png) plus their
own Dockerfile. coreapp new scaffolds one from templates/app with an
address in 192.168.200.x; deploy builds the image, copies it to the Core
over SSH, installs it with installapp (and starts it, since the Core's
start only knows its own apps) or updates it keeping .env; check, status,
logs, shell and remove work on the Core.

Apps in development aren't registered with Federated's monitoring: deploy
drops MONITOR from the Core's copy of service. installapp/uninstallapp
traces go to private logs, not the terminal.

update.sh installs docker and docker-buildx and links coreapp into
~/.local/bin. PLAN.md: how the Core runs apps, and corrected evidence for
the Core's timers running their jobs at every boot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 11:54:25 -07:00

92 lines
3.3 KiB
Bash

#!/bin/bash
#
# Purpose : Remove what coreapp-dev set up. CoreDesktop's `sibling remove`
# only deletes the clone, so run this first:
# bash ~/.local/share/siblings/coreapp-dev/uninstall.sh
# Asks before deleting VMs, the downloaded image or keys. Keeps
# libvirt, QEMU and libvirt's default network, which other VMs may
# use. Safe to re-run.
set -e
URI="qemu:///system"
NETWORK=coreapp
BRIDGE=virbr-coreapp
HOOK=/etc/libvirt/hooks/network.d/coreapp-dev
DATA="$HOME/.local/share/coreapp-dev"
CONFIG="$HOME/.config/coreapp-dev"
ask() {
# $1: question. Yes only if answered y; no when not run in a terminal.
local answer=n
[ -t 0 ] && read -r -p "$1 [y/N] " answer
[[ "$answer" =~ ^[Yy] ]]
}
v() { sudo virsh -c "$URI" "$@"; }
# VMs attached to the coreapp network
vms=()
if command -v virsh > /dev/null && v net-info "$NETWORK" &> /dev/null; then
while read -r name; do
[ -n "$name" ] || continue
if v domiflist "$name" 2> /dev/null | awk '{print $3}' | grep -qx "$NETWORK"; then
vms+=("$name")
fi
done < <(v list --all --name)
fi
if [ ${#vms[@]} -gt 0 ]; then
echo "These VMs use coreapp-dev's network: ${vms[*]}"
echo "If a Federated Core was provisioned on one, delete that Core in the"
echo "dashboard before you put another machine behind the same public IP."
if ask "Delete these VMs and their disks?"; then
for name in "${vms[@]}"; do
if [ "$(v domstate "$name")" = running ]; then v destroy "$name" > /dev/null; fi
disks=$(v domblklist "$name" --details | awk '$2 == "disk" {print $4}')
v undefine "$name" --nvram > /dev/null 2>&1 || v undefine "$name" > /dev/null
for disk in $disks; do v vol-delete "$disk" > /dev/null 2>&1 || true; done
echo "Deleted VM $name."
done
else
echo "Kept them, so the network stays too. Delete them with coreapp-vm delete"
echo "<name> and run this again."
exit 1
fi
fi
rm -f "$HOME/.local/bin/coreapp-vm" "$HOME/.local/bin/coreapp"
if command -v virsh > /dev/null && v net-info "$NETWORK" &> /dev/null; then
echo "Removing coreapp-dev's VM network..."
# Stopping it runs the hook, which removes its NAT and firewall rules
v net-destroy "$NETWORK" > /dev/null 2>&1 || true
v net-undefine "$NETWORK" > /dev/null
fi
if sudo test -e "$HOOK"; then
echo "Removing coreapp-dev's libvirt network hook..."
sudo rm -f "$HOOK"
fi
# The ufw rules update.sh added for the coreapp bridge (virbr0's stay, for
# libvirt's default network)
if command -v ufw > /dev/null && grep -qs "in_$BRIDGE" /etc/ufw/user.rules; then
echo "Removing coreapp-dev's ufw rules for $BRIDGE..."
sudo ufw delete allow in on "$BRIDGE" to any port 67 proto udp > /dev/null || true
sudo ufw delete allow in on "$BRIDGE" to any port 53 > /dev/null || true
sudo ufw route delete allow in on "$BRIDGE" > /dev/null || true
fi
if [ -d "$DATA" ] && ask "Delete the CoreServer image and coreapp-dev's SSH key in $DATA?"; then
rm -rf "$DATA"
elif [ -d "$DATA" ]; then
echo "Kept $DATA"
fi
if [ -d "$CONFIG" ] && ask "Delete coreapp-dev's settings (the dashboard's SSH key) in $CONFIG?"; then
rm -rf "$CONFIG"
elif [ -d "$CONFIG" ]; then
echo "Kept $CONFIG"
fi
echo "coreapp-dev removed. libvirt and QEMU are still installed; remove them"
echo "with pacman if nothing else uses them. Then: sibling remove coreapp-dev"