79 lines
2.0 KiB
Bash
79 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SILENT=false
|
|
LOG_PREFIX="[adb-music-sync]"
|
|
|
|
PYTHON_SCRIPT="$HOME/.linux-env/adb-music-sync/adb-music-sync.py"
|
|
INSTALL_TARGET="$HOME/.local/bin/adb-music-sync.py"
|
|
AUTOSTART_DIR="$HOME/.config/autostart"
|
|
AUTOSTART_FILE="$AUTOSTART_DIR/adb-music-sync.desktop"
|
|
|
|
log() {
|
|
if [ "$SILENT" = true ]; then return; fi
|
|
echo "$LOG_PREFIX $*"
|
|
}
|
|
|
|
check_and_install_deps() {
|
|
# Minimal dependency: adb
|
|
if ! command -v adb >/dev/null 2>&1; then
|
|
if command -v apt >/dev/null 2>&1; then
|
|
log "[+] Installation d'adb (apt) ..."
|
|
sudo apt update -y && sudo apt install -y adb
|
|
elif command -v dnf >/dev/null 2>&1; then
|
|
log "[+] Installation d'adb (dnf) ..."
|
|
sudo dnf install -y android-tools
|
|
elif command -v pacman >/dev/null 2>&1; then
|
|
log "[+] Installation d'adb (pacman) ..."
|
|
sudo pacman -Sy --noconfirm android-tools
|
|
else
|
|
log "[!] adb introuvable et gestionnaire de paquets inconnu. Installez adb manuellement."
|
|
fi
|
|
fi
|
|
}
|
|
|
|
install_script() {
|
|
check_and_install_deps
|
|
|
|
log "[+] Copie du script Python..."
|
|
mkdir -p "$(dirname "$INSTALL_TARGET")"
|
|
cp "$PYTHON_SCRIPT" "$INSTALL_TARGET"
|
|
chmod +x "$INSTALL_TARGET"
|
|
|
|
log "[+] Création du fichier autostart..."
|
|
mkdir -p "$AUTOSTART_DIR"
|
|
cat > "$AUTOSTART_FILE" <<EOF
|
|
[Desktop Entry]
|
|
Type=Application
|
|
Exec=$INSTALL_TARGET
|
|
Hidden=false
|
|
NoDisplay=false
|
|
X-GNOME-Autostart-enabled=true
|
|
Name=ADB Music Sync
|
|
Comment=Lance la synchronisation de ~5GiB de musique vers l'AGM M7 à la connexion ADB
|
|
EOF
|
|
|
|
log "[✓] Installation terminée. Le script se lancera automatiquement à l'ouverture de session."
|
|
}
|
|
|
|
uninstall_script() {
|
|
log "[+] Suppression du script Python et autostart..."
|
|
rm -f "$INSTALL_TARGET"
|
|
rm -f "$AUTOSTART_FILE"
|
|
log "[✓] Désinstallation terminée."
|
|
}
|
|
|
|
case "${1:-}" in
|
|
uninstall)
|
|
uninstall_script
|
|
;;
|
|
silent)
|
|
SILENT=true
|
|
uninstall_script &>/dev/null || true
|
|
install_script &>/dev/null
|
|
;;
|
|
*)
|
|
install_script
|
|
;;
|
|
esac
|