first commit
This commit is contained in:
+113
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : coredesktop-dev doctor: check this machine is set up to work on
|
||||
# CoreDesktop. Read-only.
|
||||
|
||||
doctor_usage() {
|
||||
cat << EOF
|
||||
Usage: coredesktop-dev doctor
|
||||
|
||||
Checks the tools are installed, the working copy is set up, and the deployed
|
||||
copy (~/.local/share/coredesktop) can still update. Exits 1 if anything needs
|
||||
fixing.
|
||||
EOF
|
||||
}
|
||||
|
||||
PROBLEMS=0
|
||||
|
||||
ok() {
|
||||
echo "ok $1"
|
||||
}
|
||||
|
||||
problem() {
|
||||
echo "PROBLEM $1"
|
||||
shift
|
||||
local line
|
||||
for line in "$@"; do
|
||||
echo " $line"
|
||||
done
|
||||
PROBLEMS=1
|
||||
}
|
||||
|
||||
note() {
|
||||
echo "note $1"
|
||||
}
|
||||
|
||||
cmd_doctor() {
|
||||
case "${1:-}" in
|
||||
-h | --help) doctor_usage; return 0 ;;
|
||||
"") ;;
|
||||
*) doctor_usage >&2; return 1 ;;
|
||||
esac
|
||||
|
||||
local tool missing=()
|
||||
for tool in shellcheck bats tea qemu-system-x86_64 qemu-img xorriso; do
|
||||
command -v "$tool" &> /dev/null || missing+=("$tool")
|
||||
done
|
||||
if (( ${#missing[@]} == 0 )); then
|
||||
ok "shellcheck, bats, tea, QEMU and xorriso are installed"
|
||||
else
|
||||
problem "not installed: ${missing[*]}" "fix: bash $(sibling_dir)/update.sh"
|
||||
fi
|
||||
|
||||
if [ -r /dev/kvm ] && [ -w /dev/kvm ]; then
|
||||
ok "KVM is available for the smoketest's virtual machines"
|
||||
else
|
||||
problem "can't use /dev/kvm, so the smoketest can't run VMs" \
|
||||
"fix: turn on virtualization (VT-x/AMD-V) in the firmware settings"
|
||||
fi
|
||||
|
||||
load_config
|
||||
if [ -z "$WORKING_COPY" ]; then
|
||||
problem "no working copy is set" "fix: bash $(sibling_dir)/install.sh"
|
||||
elif is_coredesktop_clone "$WORKING_COPY"; then
|
||||
ok "working copy: $WORKING_COPY"
|
||||
else
|
||||
problem "the working copy, $WORKING_COPY, isn't a clone of CoreDesktop" \
|
||||
"fix: bash $(sibling_dir)/install.sh"
|
||||
fi
|
||||
|
||||
doctor_deployed
|
||||
|
||||
if [ -n "${COREDESKTOP_DEV_VIA_FLATPAK:-}" ] || in_flatpak; then
|
||||
note "you ran this in a Flatpak, which has no pacman, systemctl or host /tmp;
|
||||
coredesktop-dev runs itself on the host for you (flatpak-spawn --host)"
|
||||
fi
|
||||
|
||||
if [ -n "$WORKING_COPY" ] && hook_is_ours "$(hook_path)"; then
|
||||
ok "the pre-push hook is installed"
|
||||
else
|
||||
note "the pre-push hook isn't installed (coredesktop-dev hooks install)"
|
||||
fi
|
||||
|
||||
return $PROBLEMS
|
||||
}
|
||||
|
||||
doctor_deployed() {
|
||||
if ! git -C "$COREDESKTOP" rev-parse --git-dir &> /dev/null; then
|
||||
problem "CoreDesktop isn't installed in $COREDESKTOP"
|
||||
return
|
||||
fi
|
||||
|
||||
local changes
|
||||
changes="$(git -C "$COREDESKTOP" status --porcelain --untracked-files=no)"
|
||||
if [ -z "$changes" ]; then
|
||||
ok "the deployed copy has no local changes"
|
||||
else
|
||||
problem "the deployed copy has local changes, so update can't pull:" \
|
||||
"${changes//$'\n'/$'\n' }" \
|
||||
"fix: coredesktop-dev deployed restore"
|
||||
fi
|
||||
|
||||
if ! GIT_TERMINAL_PROMPT=0 timeout 30 git -C "$COREDESKTOP" fetch --quiet &> /dev/null; then
|
||||
problem "couldn't reach the deployed copy's upstream to check it can update"
|
||||
elif git -C "$COREDESKTOP" merge-base --is-ancestor HEAD '@{upstream}' 2> /dev/null; then
|
||||
ok "the deployed copy can fast-forward to its upstream"
|
||||
else
|
||||
problem "the deployed copy has commits its upstream doesn't, so update's pull will fail" \
|
||||
"see: git -C $COREDESKTOP log @{upstream}..HEAD"
|
||||
fi
|
||||
}
|
||||
|
||||
# hooks.sh has hook_path and hook_is_ours
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/hooks.sh"
|
||||
Reference in New Issue
Block a user