coreapp-vm command, uninstall.sh, stale-system check
- bin/coreapp-vm replaces scripts/create-coreserver-vm.sh: create (downloads and checks the CoreServer image when it's missing, resumes an interrupted download), list, ip, ssh (own known_hosts), start, stop, delete (asks for the name). update.sh symlinks it into ~/.local/bin. - uninstall.sh removes coreapp-vm, the coreapp network, its hook and ufw rules; asks before deleting VMs, the image and keys. - install.sh runs CoreDesktop's update first when the system wasn't upgraded in the last day, as `sibling add` does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
#!/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"
|
||||
|
||||
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"
|
||||
Reference in New Issue
Block a user