Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·152 lines (138 loc) · 5.17 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·152 lines (138 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
# PadPilot installer: dependencies, uinput permissions, launchers, service.
# Safe to re-run. Nothing here needs the project to live in a particular place.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
UNIT_DIR="${HOME}/.config/systemd/user"
# System install by default, so PadPilot keeps working if this checkout is
# moved or deleted. --user installs into ~/.local instead and needs no sudo,
# but then the program runs from wherever this directory happens to live.
MODE=system
PREFIX=/usr/local
for arg in "$@"; do
case "$arg" in
--system) MODE=system ;;
--user) MODE=user ;;
--prefix=*) PREFIX="${arg#*=}" ;;
-h|--help)
cat <<'USAGE'
PadPilot installer
./install.sh install to /usr/local (default)
./install.sh --user install to ~/.local, no sudo
./install.sh --prefix=/usr install somewhere else
USAGE
echo " --system install to \$PREFIX (default, needs sudo)"
echo " --user install to ~/.local, no sudo"
echo " --prefix=PATH where --system installs (default /usr/local)"
exit 0 ;;
*) echo "unknown option: $arg" >&2; exit 2 ;;
esac
done
if [[ $MODE == system ]]; then
LIB_DIR="$PREFIX/lib/padpilot"
BIN_DIR="$PREFIX/bin"
APP_DIR="$PREFIX/share/applications"
# only escalate when the prefix actually needs it
if [[ -w "$PREFIX" || ( ! -e "$PREFIX" && -w "$(dirname "$PREFIX")" ) ]]; then
AS_ROOT=""
else
AS_ROOT=sudo
fi
else
LIB_DIR="$HERE"
BIN_DIR="${HOME}/.local/bin"
APP_DIR="${HOME}/.local/share/applications"
AS_ROOT=""
fi
say() { printf '\n\033[1m%s\033[0m\n' "$*"; }
have() { command -v "$1" >/dev/null 2>&1; }
say "1/5 Dependencies"
missing=()
python3 -c 'import evdev' 2>/dev/null || missing+=(python3-evdev)
python3 -c 'import pygame' 2>/dev/null || missing+=(python3-pygame)
python3 -c 'import gi' 2>/dev/null || missing+=(python3-gi)
python3 -c 'import gi; gi.require_version("Gtk","3.0")' 2>/dev/null || missing+=(gir1.2-gtk-3.0)
have xprop || missing+=(x11-utils)
if ((${#missing[@]})); then
echo "installing: ${missing[*]}"
if have apt-get; then
sudo apt-get install -y "${missing[@]}"
else
echo "Install these with your package manager, then re-run: ${missing[*]}" >&2
exit 1
fi
else
echo "all present"
fi
say "2/5 uinput (the virtual keyboard and mouse)"
if [[ ! -e /dev/uinput ]]; then
sudo modprobe uinput
fi
echo uinput | sudo tee /etc/modules-load.d/uinput.conf >/dev/null
sudo tee /etc/udev/rules.d/99-uinput.rules >/dev/null <<'RULE'
KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
RULE
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=uinput || true
if ! id -nG "$USER" | tr ' ' '\n' | grep -qx input; then
sudo usermod -aG input "$USER"
NEEDS_RELOGIN=1
fi
[[ -w /dev/uinput ]] || NEEDS_RELOGIN=1
say "3/5 Program files"
EXEC_BIN="$BIN_DIR/padpilot"
if [[ $MODE == system ]]; then
$AS_ROOT mkdir -p "$LIB_DIR" "$BIN_DIR" "$APP_DIR"
# ship the same tree layout the code expects: bin/, padpilot/, systemd/
$AS_ROOT rm -rf "$LIB_DIR/padpilot" "$LIB_DIR/bin" "$LIB_DIR/systemd"
$AS_ROOT cp -r "$HERE/padpilot" "$HERE/bin" "$HERE/systemd" "$LIB_DIR/"
$AS_ROOT cp "$HERE/README.md" "$HERE/LICENSE" "$HERE/SPEC.md" "$LIB_DIR/" 2>/dev/null || true
$AS_ROOT rm -rf "$LIB_DIR/padpilot/__pycache__"
$AS_ROOT ln -sf "$LIB_DIR/bin/padpilot" "$BIN_DIR/padpilot"
$AS_ROOT ln -sf "$LIB_DIR/bin/padpilot-gui" "$BIN_DIR/padpilot-gui"
echo "installed to $LIB_DIR, launchers in $BIN_DIR"
else
mkdir -p "$BIN_DIR" "$APP_DIR"
ln -sf "$HERE/bin/padpilot" "$BIN_DIR/padpilot"
ln -sf "$HERE/bin/padpilot-gui" "$BIN_DIR/padpilot-gui"
echo "linked to this directory: $HERE"
fi
$AS_ROOT tee "$APP_DIR/padpilot.desktop" >/dev/null <<DESKTOP
[Desktop Entry]
Type=Application
Name=PadPilot
Comment=Use a gamepad as keyboard and mouse
Exec=$BIN_DIR/padpilot-gui
Icon=input-gaming
Terminal=false
Categories=Utility;Settings;
DESKTOP
$AS_ROOT update-desktop-database "$APP_DIR" 2>/dev/null || true
echo "padpilot and padpilot-gui -> $BIN_DIR"
case ":$PATH:" in
*":$BIN_DIR:"*) ;;
*) echo "NOTE: $BIN_DIR is not on your PATH" ;;
esac
say "4/5 Background service"
mkdir -p "$UNIT_DIR"
sed "s|__PADPILOT_BIN__|$EXEC_BIN|g" "$HERE/systemd/padpilot.service" \
> "$UNIT_DIR/padpilot.service"
# a user unit even for a system install: it needs your session and display
systemctl --user daemon-reload
systemctl --user enable padpilot.service >/dev/null
echo "enabled; starts with your graphical session"
say "5/5 Check"
"$EXEC_BIN" doctor || true
if [[ -n "${NEEDS_RELOGIN:-}" ]]; then
cat <<'MSG'
==> Log out and back in before first use.
Your user was just added to the "input" group, and that only takes
effect in a new session. After logging back in:
systemctl --user start padpilot
padpilot devices # then calibrate if buttons are wrong
MSG
else
systemctl --user start padpilot.service || true
echo
echo "Running. Launch the GUI from your app menu (PadPilot) or: padpilot-gui"
fi