script v0.1

This commit is contained in:
valere
2025-09-25 07:35:52 +02:00
parent 21aa417aa6
commit f188344fa6
7 changed files with 404 additions and 0 deletions

View File

View File

@@ -0,0 +1,9 @@
[Desktop Entry]
Name=Android WiFi
Comment=Mirror and control Android devices over Wi-Fi
Exec=/home/valere/.local/bin/android-wifi.sh
Icon=/home/valere/.local/share/icons/android-wifi.svg
Terminal=false
Type=Application
Categories=Utility;
StartupNotify=true

View File

@@ -0,0 +1,66 @@
#!/bin/sh
LOG=/tmp/android-wifi.log
echo "===== $(date) =====" >> "$LOG"
# Vérifier adb
if ! command -v adb >/dev/null 2>&1; then
echo "adb non trouvé dans le PATH" >> "$LOG"
exit 1
fi
# Vérifier scrcpy
if ! command -v scrcpy >/dev/null 2>&1; then
echo "scrcpy non trouvé dans le PATH" >> "$LOG"
exit 1
fi
# Chercher device TCP existant
TCP_DEVICE=$(adb devices | awk '$1 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:5555$/ {print $1}')
if [ -n "$TCP_DEVICE" ]; then
# Device Wi-Fi déjà actif
echo "Device TCP déjà actif: $TCP_DEVICE" >> "$LOG"
IP="$TCP_DEVICE"
else
# Récupérer un device USB
USB_ID=$(adb devices | awk 'NR>1 && $2=="device" && $1 !~ /:/ {print $1; exit}')
if [ -z "$USB_ID" ]; then
echo "Aucun device USB détecté" >> "$LOG"
exit 1
fi
echo "Device USB détecté: $USB_ID" >> "$LOG"
# Récupérer IP via USB
IP=$(adb -s "$USB_ID" shell ip addr show wlan0 2>>"$LOG" | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)
if [ -z "$IP" ]; then
echo "Impossible de récupérer l'IP du téléphone (wlan0 introuvable)" >> "$LOG"
exit 1
fi
echo "IP détectée: $IP" >> "$LOG"
# Passer en mode TCP
echo "[+] Passage en mode TCP 5555" >> "$LOG"
adb -s "$USB_ID" tcpip 5555 >> "$LOG" 2>&1
# Connexion Wi-Fi
echo "[+] Connexion à $IP:5555" >> "$LOG"
adb connect "$IP:5555" >> "$LOG" 2>&1
# Déconnecter USB pour éviter conflit multiple devices
echo "[+] Déconnexion du device USB $USB_ID" >> "$LOG"
adb disconnect "$USB_ID" >> "$LOG" 2>&1
fi
# Attendre que le device TCP soit prêt
echo "[+] Attente du device TCP $IP" >> "$LOG"
while ! adb devices | grep -q "$IP.*device"; do
sleep 1
done
echo "[+] Device TCP prêt" >> "$LOG"
# Lancer scrcpy
echo "[+] Lancement de scrcpy sur $IP" >> "$LOG"
scrcpy -s "$IP" >> "$LOG" 2>&1
echo "[✓] Fin du script" >> "$LOG"

View File

@@ -0,0 +1,16 @@
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" version="1.1">
<path style="opacity:0.2" d="m 16.846877,12 c -1.116351,0 -2.227419,0.912229 -2.015075,2 l 3.122973,16 -5.596557,11.109375 C 11.959876,41.871734 11.885244,42.336988 12.177176,43 c 0.278672,0.632897 0.998812,1 1.747448,1 H 24 34.075375 c 0.748637,0 1.468777,-0.367103 1.747448,-1 0.291932,-0.663012 0.217302,-1.128266 -0.181041,-1.890625 L 30.045225,30 33.168198,14 c 0.212344,-1.087771 -0.898724,-2 -2.015075,-2 H 24 Z"/>
<path style="fill:#cccccc" d="m 16.846877,11 c -1.116351,0 -2.227419,0.912229 -2.015075,2 l 3.122973,16 -5.596557,11.109375 C 11.959876,40.871734 11.885244,41.336988 12.177176,42 c 0.278672,0.632897 0.998812,1 1.747448,1 H 24 34.075375 c 0.748637,0 1.468777,-0.367103 1.747448,-1 0.291932,-0.663012 0.217302,-1.128266 -0.181041,-1.890625 L 30.045225,29 33.168198,13 c 0.212344,-1.087771 -0.898724,-2 -2.015075,-2 H 24 Z"/>
<rect style="opacity:0.2" width="40" height="32" x="4" y="6" rx="2" ry="2"/>
<path style="fill:#e4e4e4" d="m 4,33 v 2 c 0,1.108 0.892,2 2,2 h 36 c 1.108,0 2,-0.892 2,-2 v -2 z"/>
<path style="opacity:0.1" d="m 11.494141,15 a 1.5,1.5 0 0 0 -0.832032,0.255859 1.5,1.5 0 0 0 -0.40625,2.082032 l 3.13086,4.654297 C 10.404945,24.606192 8.4012371,28.299159 8.0019531,32.460938 7.9284599,34.000879 9.5546875,34 9.5546875,34 H 38.40625 c 0,0 1.672856,-3.38e-4 1.591797,-1.617188 -0.416529,-4.131451 -2.415618,-7.796833 -5.380859,-10.394531 l 3.126953,-4.65039 a 1.5,1.5 0 0 0 -0.40625,-2.082032 1.5,1.5 0 0 0 -1.125,-0.228515 1.5,1.5 0 0 0 -0.957032,0.634765 l -3.072265,4.566407 C 29.78649,18.814887 26.990024,18 24.001953,18 c -2.989385,0 -5.786177,0.815488 -8.183594,2.230469 l -3.074218,-4.56836 A 1.5,1.5 0 0 0 11.787109,15.027344 1.5,1.5 0 0 0 11.494141,15 Z"/>
<path style="fill:#077063" d="M 6,5 C 4.892,5 4,5.892 4,7 V 33 H 44 V 7 C 44,5.892 43.108,5 42,5 Z"/>
<path style="opacity:0.1;fill:#ffffff" d="M 6,5 C 4.892,5 4,5.892 4,7 V 8 C 4,6.892 4.892,6 6,6 h 36 c 1.108,0 2,0.892 2,2 V 7 C 44,5.892 43.108,5 42,5 Z"/>
<path style="fill:none;stroke:#30dd81;stroke-width:3;stroke-linecap:round" d="M 15.1998,21.000026 11.5,15.5"/>
<path style="fill:none;stroke:#30dd81;stroke-width:3;stroke-linecap:round" d="M 32.799764,21.000026 36.5,15.5"/>
<path style="fill:#30dd81" d="m 24.002386,17.000034 c -8.355868,0 -15.2214979,6.346843 -15.9999669,14.460906 C 7.9289259,33.000882 9.5544999,33 9.5544999,33 H 38.406003 c 0,0 1.672201,-3.35e-4 1.591142,-1.617185 C 39.182807,23.305596 32.331836,17.000034 24.002386,17.000034 Z"/>
<path style="opacity:0.2" d="m 16,25 a 1.9999959,1.9999959 0 0 0 -2,2 1.9999959,1.9999959 0 0 0 2,2 1.9999959,1.9999959 0 0 0 2,-2 1.9999959,1.9999959 0 0 0 -2,-2 z m 16,0 a 1.9999959,1.9999959 0 0 0 -2,2 1.9999959,1.9999959 0 0 0 2,2 1.9999959,1.9999959 0 0 0 2,-2 1.9999959,1.9999959 0 0 0 -2,-2 z"/>
<path style="fill:#ffffff" d="M 15.999996,24.000008 A 1.9999959,1.9999959 0 0 1 17.999992,26.000004 1.9999959,1.9999959 0 0 1 15.999996,28 1.9999959,1.9999959 0 0 1 14,26.000004 1.9999959,1.9999959 0 0 1 15.999996,24.000008 Z"/>
<path style="fill:#ffffff" d="M 31.999996,24.000008 A 1.9999959,1.9999959 0 0 1 33.999991,26.000004 1.9999959,1.9999959 0 0 1 31.999996,28 1.9999959,1.9999959 0 0 1 30,26.000004 1.9999959,1.9999959 0 0 1 31.999996,24.000008 Z"/>
<path style="fill:#ffffff;opacity:0.2" d="M 11.494141 14 A 1.5 1.5 0 0 0 10.662109 14.255859 A 1.5 1.5 0 0 0 10.115234 16.001953 A 1.5 1.5 0 0 1 10.662109 15.255859 A 1.5 1.5 0 0 1 11.494141 15 A 1.5 1.5 0 0 1 11.787109 15.027344 A 1.5 1.5 0 0 1 12.744141 15.662109 L 15.818359 20.230469 C 18.215776 18.815488 21.012568 18 24.001953 18 C 26.990024 18 29.78649 18.814887 32.183594 20.228516 L 35.255859 15.662109 A 1.5 1.5 0 0 1 36.212891 15.027344 A 1.5 1.5 0 0 1 37.337891 15.255859 A 1.5 1.5 0 0 1 37.910156 16.001953 A 1.5 1.5 0 0 0 37.337891 14.255859 A 1.5 1.5 0 0 0 36.212891 14.027344 A 1.5 1.5 0 0 0 35.255859 14.662109 L 32.183594 19.228516 C 29.78649 17.814887 26.990024 17 24.001953 17 C 21.012568 17 18.215776 17.815488 15.818359 19.230469 L 12.744141 14.662109 A 1.5 1.5 0 0 0 11.787109 14.027344 A 1.5 1.5 0 0 0 11.494141 14 z M 35.033203 21.369141 L 34.617188 21.988281 C 37.477056 24.493668 39.433905 27.993356 39.943359 31.945312 C 39.986866 31.783283 40.008864 31.598575 39.998047 31.382812 C 39.601372 27.448291 37.768055 23.938648 35.033203 21.369141 z M 12.970703 21.373047 C 10.220358 23.959215 8.3822757 27.496796 8.0019531 31.460938 C 7.9920657 31.668114 8.0150508 31.844846 8.0585938 32 C 8.5570234 28.027243 10.515755 24.509049 13.386719 21.992188 L 12.970703 21.373047 z"/>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -0,0 +1,154 @@
#!/bin/bash
set -e
SERVICE_NAME="gamecube-pad.service"
SERVICE_PATH="/etc/systemd/system/$SERVICE_NAME"
PYTHON_SCRIPT="/home/$USER/.local/bin/gamecube-pad.py"
install_service() {
echo "[+] Installation des dépendances..."
sudo apt update
sudo apt install -y python3-evdev python3-uinput xdotool wmctrl
echo "[+] Création du script Python watcher..."
cat > "$PYTHON_SCRIPT" <<'EOF'
#!/usr/bin/env python3
import evdev
import uinput
import subprocess
import time
DEVICE_NAMES = ["8BitDo NGC Modkit"]
AXIS_MAP = {
"ABS_X": ("KEY_LEFT", "KEY_RIGHT"),
"ABS_Y": ("KEY_UP", "KEY_DOWN")
}
BUTTON_MAP = {
"304": "KEY_ENTER",
"305": "KEY_ESC",
"311": "KEY_LEFTALT",
"308": "KEY_TAB",
"310": "KEY_LEFTCTRL",
"307": "KEY_LEFTSHIFT",
"314": "KEY_T"
}
THRESHOLD = 100
DOLPHIN_NAME = "Dolphin"
events = [
uinput.KEY_UP, uinput.KEY_DOWN, uinput.KEY_LEFT, uinput.KEY_RIGHT,
uinput.KEY_ENTER, uinput.KEY_ESC, uinput.KEY_LEFTALT, uinput.KEY_TAB,
uinput.KEY_LEFTCTRL, uinput.KEY_LEFTSHIFT, uinput.KEY_T
]
keyboard = uinput.Device(events)
def find_device():
devices = []
for path in evdev.list_devices():
try:
dev = evdev.InputDevice(path)
devices.append((path, dev.name))
except Exception:
continue
for path, name in devices:
if any(dn in name for dn in DEVICE_NAMES):
return path
return None
def handle_device(dev_path):
dev = evdev.InputDevice(dev_path)
abs_center = {axis: dev.absinfo(axis).value for axis in (evdev.ecodes.ABS_X, evdev.ecodes.ABS_Y)}
try:
for event in dev.read_loop():
if event.type == evdev.ecodes.EV_KEY:
key_code = str(event.code)
if key_code in BUTTON_MAP:
keyboard.emit(getattr(uinput, BUTTON_MAP[key_code]), event.value)
if event.type == evdev.ecodes.EV_ABS:
axis = evdev.ecodes.ABS[event.code]
val = event.value
neg_key, pos_key = AXIS_MAP.get(axis, (None, None))
if neg_key and pos_key:
keyboard.emit(getattr(uinput, neg_key), int(val < abs_center[event.code]-THRESHOLD))
keyboard.emit(getattr(uinput, pos_key), int(val > abs_center[event.code]+THRESHOLD))
except OSError:
dev.close()
raise
def main():
connected = False
while True:
dev_path = find_device()
if dev_path and not connected:
print(f"[+] Manette connectée: {dev_path}")
connected = True
try:
subprocess.Popen(["flatpak", "run", "org.DolphinEmu.dolphin-emu"]) # ou juste ["ma_commande"] si pas d'arguments
except Exception as e:
print(f"[!] Impossible de lancer la commande: {e}")
try:
handle_device(dev_path)
except OSError:
print("[-] Manette déconnectée")
connected = False
try:
subprocess.Popen(["flatpak", "kill", "org.DolphinEmu.dolphin-emu"]) # ou juste ["ma_commande"] si pas d'arguments
except Exception as e:
print(f"[!] Impossible de lancer la commande: {e}")
elif not dev_path and connected:
print("[-] Manette déconnectée")
connected = False
time.sleep(1)
if __name__=="__main__":
main()
EOF
chmod +x "$PYTHON_SCRIPT"
echo "[+] Création du service systemd..."
sudo tee "$SERVICE_PATH" > /dev/null <<EOF
[Unit]
Description=Pad Dolphin Watcher Service
After=graphical.target
[Service]
ExecStart=/usr/bin/python3 $PYTHON_SCRIPT
WorkingDirectory=/home/$USER
Restart=always
RestartSec=3
User=$USER
Group=$USER
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=default.target
EOF
echo "[+] Activation du service..."
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl restart "$SERVICE_NAME"
echo "[✓] Installation terminée. Consulte les logs avec : journalctl -u $SERVICE_NAME -f"
}
uninstall_service() {
echo "[+] Arrêt et suppression du service..."
sudo systemctl stop "$SERVICE_NAME" || true
sudo systemctl disable "$SERVICE_NAME" || true
sudo rm -f "$SERVICE_PATH"
sudo systemctl daemon-reload
rm -f "$PYTHON_SCRIPT"
echo "[✓] Désinstallation terminée."
}
case "$1" in
uninstall)
uninstall_service
;;
*)
install_service
;;
esac

View File

@@ -0,0 +1,149 @@
#!/bin/bash
set -e
PYTHON_SCRIPT="$HOME/.local/bin/gamecube-pad.py"
SERVICE_DIR="$HOME/.config/systemd/user"
SERVICE_FILE="$SERVICE_DIR/gamecube-pad.service"
install_service() {
echo "[+] Installation des dépendances..."
sudo apt update
sudo apt install -y python3-evdev python3-uinput xdotool wmctrl flatpak
echo "[+] Création du script Python watcher..."
mkdir -p "$(dirname "$PYTHON_SCRIPT")"
cat > "$PYTHON_SCRIPT" <<'EOF'
#!/usr/bin/env python3
import evdev
import uinput
import subprocess
import time
import os
DEVICE_NAMES = ["8BitDo NGC Modkit"]
BUTTON_MAP = {
"304": "KEY_ENTER",
"305": "KEY_ESC",
"311": "KEY_LEFTALT",
"307": "KEY_RIGHT",
"308": "KEY_LEFT",
}
events = [
uinput.KEY_LEFT, uinput.KEY_RIGHT,
uinput.KEY_ENTER, uinput.KEY_ESC, uinput.KEY_LEFTALT
]
keyboard = uinput.Device(events)
def find_device():
for path in evdev.list_devices():
try:
dev = evdev.InputDevice(path)
if any(dn in dev.name for dn in DEVICE_NAMES):
return path
except Exception:
continue
return None
def is_dolphin_running():
try:
output = subprocess.check_output(
["flatpak", "ps", "--columns=name"]
).decode()
return "org.DolphinEmu.dolphin-emu" in output
except Exception:
return False
def handle_device(dev_path):
dev = evdev.InputDevice(dev_path)
try:
for event in dev.read_loop():
if event.type == evdev.ecodes.EV_KEY:
key_code = str(event.code)
if key_code in BUTTON_MAP:
keyboard.emit(getattr(uinput, BUTTON_MAP[key_code]), event.value)
except OSError:
dev.close()
raise
def main():
connected = False
time.sleep(5) # délai pour que uinput et le serveur graphique soient prêts
while True:
dev_path = find_device()
if dev_path and not connected:
print(f"[+] Manette connectée: {dev_path}")
connected = True
if not is_dolphin_running():
try:
subprocess.Popen(["flatpak", "run", "org.DolphinEmu.dolphin-emu"])
except Exception as e:
print(f"[!] Impossible de lancer Dolphin: {e}")
try:
handle_device(dev_path)
except OSError:
print("[-] Manette déconnectée")
connected = False
try:
subprocess.Popen(["flatpak", "kill", "org.DolphinEmu.dolphin-emu"])
except Exception as e:
print(f"[!] Impossible de tuer Dolphin: {e}")
elif not dev_path and connected:
print("[-] Manette déconnectée")
connected = False
time.sleep(1)
if __name__ == "__main__":
main()
EOF
chmod +x "$PYTHON_SCRIPT"
echo "[+] Création du service systemd utilisateur..."
mkdir -p "$SERVICE_DIR"
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=Pad Dolphin Watcher Service (User)
After=graphical.target dev-uinput.device
[Service]
ExecStartPre=/bin/sleep 10
ExecStart=$PYTHON_SCRIPT
WorkingDirectory=$HOME
Restart=always
RestartSec=3
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=default.target
EOF
echo "[+] Activation du service utilisateur..."
systemctl --user daemon-reload
systemctl --user enable gamecube-pad.service
systemctl --user start gamecube-pad.service
echo "[✓] Installation terminée."
echo "Consulte les logs avec : journalctl --user-unit gamecube-pad.service -f"
}
uninstall_service() {
echo "[+] Arrêt et suppression du service utilisateur..."
systemctl --user stop gamecube-pad.service || true
systemctl --user disable gamecube-pad.service || true
rm -f "$SERVICE_FILE"
rm -f "$PYTHON_SCRIPT"
systemctl --user daemon-reload
echo "[✓] Désinstallation terminée."
}
case "$1" in
uninstall)
uninstall_service
;;
*)
install_service
;;
esac

10
install.sh Executable file
View File

@@ -0,0 +1,10 @@
# desktop apps
cp ./applications/*/*.desktop ~/.local/share/applications/
cp ./applications/*/*.sh ~/.local/bin/
cp ./applications/*/*.svg ~/.local/share/icons/
chmod +x ~/.local/share/applications/*.desktop
chmod +x ~/.local/bin/*.sh
update-desktop-database ~/.local/share/applications/
# gtk-update-icon-cache ~/.local/share/icons/ # inutile sauf si tu fais un vrai thème dicônes