72 lines
2.1 KiB
Bash
72 lines
2.1 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Purpose : coredesktop-dev try: run the working copy's code as if it were the
|
|
# deployed CoreDesktop, in a throwaway home with its own session
|
|
|
|
try_usage() {
|
|
cat << EOF
|
|
Usage: coredesktop-dev try [--keep] [command...]
|
|
|
|
Runs command (or a shell) with a throwaway HOME where
|
|
~/.local/share/coredesktop is the working copy, and update, configure, version
|
|
etc. in ~/.local/bin are the working copy's. It gets its own XDG_RUNTIME_DIR
|
|
and D-Bus session, and no display, so it can't touch your desktop session.
|
|
|
|
sudo, yay, pacman and systemctl still change this machine.
|
|
|
|
--keep Keep the throwaway folder afterwards, and print where it is
|
|
|
|
Example: coredesktop-dev try configure --list
|
|
EOF
|
|
}
|
|
|
|
TRY_COMMANDS=(update refresh sibling version configure audit)
|
|
|
|
cmd_try() {
|
|
local keep=0
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
-h | --help) try_usage; return 0 ;;
|
|
--keep) keep=1; shift ;;
|
|
--) shift; break ;;
|
|
*) break ;;
|
|
esac
|
|
done
|
|
require_working_copy
|
|
|
|
local tmp home runtime cmd status
|
|
tmp="$(mktemp -d "${TMPDIR:-/tmp}/coredesktop-dev-try.XXXXXX")" || return 1
|
|
home="$tmp/home"
|
|
runtime="$tmp/runtime"
|
|
mkdir -p "$home/.local/share" "$home/.local/bin" "$home/.local/state" \
|
|
"$home/.config" "$home/.cache"
|
|
mkdir -m 700 "$runtime"
|
|
|
|
ln -s "$WORKING_COPY" "$home/.local/share/coredesktop"
|
|
for cmd in "${TRY_COMMANDS[@]}"; do
|
|
ln -s "$WORKING_COPY/$cmd" "$home/.local/bin/$cmd"
|
|
done
|
|
|
|
echo "coredesktop-dev try: HOME is $home, with the working copy as CoreDesktop." >&2
|
|
echo "Careful: sudo, yay, pacman and systemctl still change this machine." >&2
|
|
|
|
(( $# > 0 )) || set -- bash
|
|
env -u DISPLAY -u WAYLAND_DISPLAY -u DBUS_SESSION_BUS_ADDRESS -u SSH_AUTH_SOCK \
|
|
HOME="$home" \
|
|
XDG_CONFIG_HOME="$home/.config" \
|
|
XDG_DATA_HOME="$home/.local/share" \
|
|
XDG_STATE_HOME="$home/.local/state" \
|
|
XDG_CACHE_HOME="$home/.cache" \
|
|
XDG_RUNTIME_DIR="$runtime" \
|
|
PATH="$home/.local/bin:$PATH" \
|
|
dbus-run-session -- "$@"
|
|
status=$?
|
|
|
|
if (( keep )); then
|
|
echo "Kept $tmp" >&2
|
|
else
|
|
rm -rf "$tmp"
|
|
fi
|
|
return $status
|
|
}
|