mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 22:47:02 +01:00
i3 config was filed under periodic_background, which it never was. It is now linux_configuration/i3/ (config + installer) and linux_configuration/i3blocks/ (the status scripts), both at depth 2. misc/testsAndMisc-bash/ was a directory named after the repo it already lived in, so its contents moved up to misc/. Its stray .gitignore came along, keeping the media rules working from the new location; its .vscode/tasks.json did not, because it invoked Bash/transcribe.sh, a path this repo dropped long ago. Most of this commit is the references the previous flatten missed. Its regex skipped anything with a variable prefix, which left 16 files -- including check_and_enable_services.sh and install_core_system.sh, the orchestrators -- still naming $CONFIG_DIR/scripts/periodic_background/... It had also rewritten three i3 paths into scripts/i3blocks/, a directory that has never existed; the i3blocks suites caught that by failing. 13 more symlinks broke on the i3 move. Repointed, and cpu_monitor/volume/ disk were run again to confirm the bar still reports. Depth 139 -> 104. Roughly 47 of the remainder sit in digital_wellbeing and hosts, still deferred. The rest encode real structure -- a C project, Python package directories, artgate's routes/styles, systemd unit dirs -- so flattening them further would destroy information rather than taxonomy. Verified: 1798 tests at 100%, both i3blocks suites pass, the shell coverage gate is clean, and the relocated media rules still ignore what they should while test_fw.srt stays tracked. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
237 lines
6.6 KiB
Bash
Executable File
237 lines
6.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Fix Unity Hub login on Linux (Arch/XFCE) by ensuring the unityhub:// URL scheme
|
|
# is correctly registered and handled. This script:
|
|
# - Detects Unity Hub installation type (Native, Flatpak, AppImage)
|
|
# - Creates a local desktop entry to handle x-scheme-handler/unityhub (and unity)
|
|
# - Registers the handler using xdg-mime and updates desktop database
|
|
# - Optionally installs required tools (xdg-utils, desktop-file-utils, portals)
|
|
# - Optionally tests the handler by opening a unityhub:// link
|
|
#
|
|
# Usage:
|
|
# bash Bash/fix_unity.sh # Run fix (no deps install, no test)
|
|
# bash Bash/fix_unity.sh -y # Auto-install deps (Arch) if missing
|
|
# bash Bash/fix_unity.sh --test # Also launches a test unityhub:// link
|
|
# bash Bash/fix_unity.sh -y --test # Install deps and run test
|
|
#
|
|
# Notes:
|
|
# - For Flatpak installs, Exec uses: flatpak run com.unity.UnityHub %U
|
|
# - For native installs, Exec uses the unityhub binary path with %U
|
|
# - Chromium/Thorium may prompt to "Open xdg-open" after web login—allow it.
|
|
|
|
set -euo pipefail
|
|
IFS=$'\n\t'
|
|
|
|
SCRIPT_NAME="$(basename "$0")"
|
|
|
|
# Source common library for log functions
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
# shellcheck source=../lib/common.sh
|
|
source "$SCRIPT_DIR/../lib/common.sh"
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
${SCRIPT_NAME} - Fix Unity Hub sign-in by registering unityhub:// URL handler
|
|
|
|
Options:
|
|
-y, --yes Auto-install required packages on Arch (sudo pacman)
|
|
--test After setup, open a test link: unityhub://v1/editor-signin
|
|
-h, --help Show this help
|
|
|
|
This script creates ~/.local/share/applications/unityhub-url-handler.desktop
|
|
and sets it as the default handler for x-scheme-handler/unityhub (and unity).
|
|
EOF
|
|
}
|
|
|
|
AUTO_INSTALL=false
|
|
RUN_TEST=false
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-y | --yes)
|
|
AUTO_INSTALL=true
|
|
shift
|
|
;;
|
|
--test)
|
|
RUN_TEST=true
|
|
shift
|
|
;;
|
|
-h | --help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
log_error "Unknown argument: $1"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
require_cmd() {
|
|
if ! command -v "$1" >/dev/null 2>&1; then
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
ensure_deps_arch() {
|
|
# Best-effort install for Arch-based systems
|
|
if [[ $AUTO_INSTALL != true ]]; then
|
|
log_warn "Skipping package installation (use -y to auto-install)."
|
|
return 0
|
|
fi
|
|
if ! require_cmd pacman; then
|
|
log_warn "Not an Arch-based system (pacman not found). Skipping auto-install."
|
|
return 0
|
|
fi
|
|
local pkgs=(xdg-utils desktop-file-utils xdg-desktop-portal xdg-desktop-portal-gtk)
|
|
log_info "Installing/ensuring packages: ${pkgs[*]}"
|
|
if ! require_cmd sudo; then
|
|
log_warn "sudo not found; attempting pacman directly (may fail)."
|
|
sudo_cmd=""
|
|
else
|
|
sudo_cmd="sudo"
|
|
fi
|
|
# Use --needed to avoid reinstalling
|
|
set +e
|
|
$sudo_cmd pacman -S --needed --noconfirm "${pkgs[@]}"
|
|
local rc=$?
|
|
set -e
|
|
if [[ $rc -ne 0 ]]; then
|
|
log_warn "Package install may have failed or been partial. Continuing anyway."
|
|
else
|
|
log_ok "Dependencies installed/verified."
|
|
fi
|
|
}
|
|
|
|
DESKTOP_DIR="$HOME/.local/share/applications"
|
|
mkdir -p "$DESKTOP_DIR"
|
|
|
|
detect_unityhub() {
|
|
# Outputs: INSTALL_TYPE (FLATPAK|NATIVE|APPIMAGE|UNKNOWN) and EXEC_CMD
|
|
local install_type="UNKNOWN" exec_cmd=""
|
|
|
|
# 1) Flatpak
|
|
if command -v flatpak >/dev/null 2>&1; then
|
|
if flatpak info com.unity.UnityHub >/dev/null 2>&1; then
|
|
install_type="FLATPAK"
|
|
exec_cmd="flatpak run com.unity.UnityHub %U"
|
|
echo "$install_type|$exec_cmd"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
# 2) Native binary in PATH
|
|
if command -v unityhub >/dev/null 2>&1; then
|
|
local path
|
|
path="$(command -v unityhub)"
|
|
install_type="NATIVE"
|
|
exec_cmd="$path %U"
|
|
echo "$install_type|$exec_cmd"
|
|
return 0
|
|
fi
|
|
|
|
# 3) Search desktop files for Unity Hub Exec
|
|
local search_dirs=(
|
|
"$HOME/.local/share/applications"
|
|
"/usr/share/applications"
|
|
"/var/lib/flatpak/exports/share/applications"
|
|
"$HOME/.local/share/flatpak/exports/share/applications"
|
|
)
|
|
local found_exec=""
|
|
for d in "${search_dirs[@]}"; do
|
|
[[ -d $d ]] || continue
|
|
# prefer official naming when present
|
|
local f
|
|
for f in "$d"/*.desktop; do
|
|
[[ -e $f ]] || continue
|
|
if grep -qiE '^(Name|Comment)=.*Unity Hub' "$f" 2>/dev/null ||
|
|
grep -qiE 'Exec=.*unityhub' "$f" 2>/dev/null; then
|
|
local exec_line
|
|
exec_line="$(grep -iE '^Exec=' "$f" | head -n1 | sed 's/^Exec=//')"
|
|
if [[ -n $exec_line ]]; then
|
|
found_exec="$exec_line"
|
|
break 2
|
|
fi
|
|
fi
|
|
done
|
|
done
|
|
|
|
if [[ -n $found_exec ]]; then
|
|
# Normalize: ensure %U present
|
|
if [[ $found_exec != *"%U"* && $found_exec != *"%u"* ]]; then
|
|
found_exec+=" %U"
|
|
fi
|
|
if [[ $found_exec == flatpak* ]]; then
|
|
install_type="FLATPAK"
|
|
elif [[ $found_exec == *AppImage* || $found_exec == *appimage* ]]; then
|
|
install_type="APPIMAGE"
|
|
else
|
|
install_type="NATIVE"
|
|
fi
|
|
echo "$install_type|$found_exec"
|
|
return 0
|
|
fi
|
|
|
|
# 4) Try common AppImage locations
|
|
local ai_candidates=(
|
|
"$HOME/Applications/UnityHub*.AppImage"
|
|
"$HOME/.local/bin/UnityHub*.AppImage"
|
|
"/opt/UnityHub*/UnityHub*.AppImage"
|
|
)
|
|
local ai
|
|
for ai in "${ai_candidates[@]}"; do
|
|
for p in $ai; do
|
|
if [[ -f $p && -x $p ]]; then
|
|
install_type="APPIMAGE"
|
|
exec_cmd="$p %U"
|
|
echo "$install_type|$exec_cmd"
|
|
return 0
|
|
fi
|
|
done
|
|
done
|
|
|
|
echo "$install_type|$exec_cmd"
|
|
}
|
|
|
|
# shellcheck source=lib/unity_handler.sh
|
|
source "$SCRIPT_DIR/lib/unity_handler.sh"
|
|
|
|
main() {
|
|
log_info "Ensuring required tools (optional)."
|
|
ensure_deps_arch
|
|
|
|
log_info "Detecting Unity Hub installation..."
|
|
IFS='|' read -r install_type exec_cmd < <(detect_unityhub)
|
|
log_info "Detected type: $install_type"
|
|
if [[ -z ${exec_cmd:-} ]]; then
|
|
log_warn "Could not find Unity Hub executable automatically."
|
|
log_warn "- If using Flatpak: install with 'flatpak install flathub com.unity.UnityHub'"
|
|
log_warn "- If native (AUR): ensure 'unityhub' is in PATH"
|
|
log_warn "- If AppImage: place it in ~/Applications and make it executable"
|
|
log_error "Aborting—no Exec command available to create handler."
|
|
exit 2
|
|
fi
|
|
log_info "Using Exec: $exec_cmd"
|
|
|
|
local desktop_file
|
|
desktop_file="$(create_handler_desktop "$exec_cmd")"
|
|
|
|
register_mime_handler "$desktop_file"
|
|
verify_registration "$desktop_file"
|
|
|
|
cat <<'NOTE'
|
|
---
|
|
Next steps:
|
|
- Sign in from Unity Hub. When the browser finishes, ALLOW the prompt to open xdg-open/Unity Hub.
|
|
- If Thorium suppresses the external protocol prompt, try once with Firefox/Chromium to confirm.
|
|
---
|
|
NOTE
|
|
|
|
maybe_test_open
|
|
|
|
log_ok "Done. If login still fails, check the Hub's logs and share the outputs of:\n which unityhub || true\n flatpak info com.unity.UnityHub 2>/dev/null | sed -n '1,5p' || true\n xdg-mime query default x-scheme-handler/unityhub\n grep -R \"x-scheme-handler/unityhub\" ~/.local/share/applications /usr/share/applications 2>/dev/null | head -n 10"
|
|
}
|
|
|
|
main "$@"
|