84 lines
1.5 KiB
Bash
Executable File
84 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
|
|
log() {
|
|
printf '[mice-launcher] %s\n' "$*"
|
|
}
|
|
|
|
find_game_dir() {
|
|
for candidate in \
|
|
"$SCRIPT_DIR/mice" \
|
|
"$SCRIPT_DIR" \
|
|
/mnt/mmc/ports/mice \
|
|
/roms/ports/mice \
|
|
"$HOME/mice-current" \
|
|
/root/mice \
|
|
"$HOME/mice"; do
|
|
if [ -f "$candidate/rats.py" ]; then
|
|
printf '%s\n' "$candidate"
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
find_python() {
|
|
for candidate in \
|
|
"$GAMEDIR/.venv/bin/python" \
|
|
"$HOME/miniconda3/bin/python" \
|
|
/root/miniconda3/bin/python \
|
|
/usr/bin/python3 \
|
|
/usr/bin/python; do
|
|
if [ -x "$candidate" ]; then
|
|
printf '%s\n' "$candidate"
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
detect_keybindings_profile() {
|
|
if [ -f /opt/muos/device/current/config.ini ]; then
|
|
board_name=$(sed -n 's/^name = //p' /opt/muos/device/current/config.ini | head -n 1 | tr '[:upper:]' '[:lower:]')
|
|
case "$board_name" in
|
|
*rg40xx*)
|
|
printf 'rg40xx\n'
|
|
return 0
|
|
;;
|
|
*r36s*)
|
|
printf 'r36s\n'
|
|
return 0
|
|
;;
|
|
esac
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
GAMEDIR=$(find_game_dir)
|
|
PYTHONBIN=$(find_python)
|
|
|
|
mkdir -p "$GAMEDIR/logs"
|
|
LOGFILE="$GAMEDIR/logs/launcher.log"
|
|
exec >>"$LOGFILE" 2>&1
|
|
|
|
log "script_dir=$SCRIPT_DIR"
|
|
log "game_dir=$GAMEDIR"
|
|
log "python=$PYTHONBIN"
|
|
|
|
export MICE_PROJECT_ROOT="$GAMEDIR"
|
|
|
|
if [ -z "${MICE_KEYBINDINGS_PROFILE:-}" ]; then
|
|
MICE_KEYBINDINGS_PROFILE=$(detect_keybindings_profile || true)
|
|
export MICE_KEYBINDINGS_PROFILE
|
|
fi
|
|
|
|
if [ -n "${MICE_KEYBINDINGS_PROFILE:-}" ]; then
|
|
log "keybindings_profile=$MICE_KEYBINDINGS_PROFILE"
|
|
fi
|
|
|
|
cd "$GAMEDIR"
|
|
exec "$PYTHONBIN" rats.py
|