-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·101 lines (88 loc) · 2.58 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·101 lines (88 loc) · 2.58 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
#!/usr/bin/env bash
set -euo pipefail
REPO_URL="https://github.com/JSap0914/linkedin-automation.git"
INSTALL_DIR="${LINKEDIN_AUTOREPLY_HOME:-$HOME/.linkedin-automation}"
BIN_DIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
SKIP_INIT=0
for arg in "$@"; do
case "$arg" in
--skip-init) SKIP_INIT=1 ;;
*) echo "Unknown argument: $arg" >&2; exit 1 ;;
esac
done
pick_python() {
# Accept any Python >=3.11, prefer newer explicit versions first.
for bin in python3.14 python3.13 python3.12 python3.11 python3 python; do
if command -v "$bin" >/dev/null 2>&1; then
if "$bin" - <<'PY' >/dev/null 2>&1
import sys
raise SystemExit(0 if sys.version_info >= (3, 11) else 1)
PY
then
echo "$bin"
return 0
fi
fi
done
return 1
}
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
require_cmd git
PYTHON_BIN="$(pick_python || true)"
if [ -z "$PYTHON_BIN" ]; then
echo "Python 3.11+ is required." >&2
exit 1
fi
if [ -d "$INSTALL_DIR/.git" ]; then
if [ -n "$(git -C "$INSTALL_DIR" status --porcelain)" ]; then
echo "Existing install at $INSTALL_DIR has uncommitted changes." >&2
echo "Commit/stash them or remove the directory first." >&2
exit 1
fi
git -C "$INSTALL_DIR" pull --ff-only origin main
elif [ -e "$INSTALL_DIR" ]; then
echo "$INSTALL_DIR exists but is not a git checkout." >&2
exit 1
else
git clone "$REPO_URL" "$INSTALL_DIR"
fi
"$PYTHON_BIN" -m venv "$INSTALL_DIR/.venv"
"$INSTALL_DIR/.venv/bin/python" -m pip install -e "$INSTALL_DIR[dev]"
"$INSTALL_DIR/.venv/bin/scrapling" install
mkdir -p "$BIN_DIR"
cat > "$BIN_DIR/linkedin-autoreply" <<'WRAP'
#!/usr/bin/env bash
set -euo pipefail
export LINKEDIN_AUTOREPLY_HOME="__INSTALL_DIR__"
cd "__INSTALL_DIR__"
exec "__INSTALL_DIR__/.venv/bin/linkedin-autoreply" "$@"
WRAP
"$PYTHON_BIN" - <<'PY' "$BIN_DIR/linkedin-autoreply" "$INSTALL_DIR"
from pathlib import Path
import sys
path = Path(sys.argv[1])
install_dir = sys.argv[2]
path.write_text(path.read_text().replace("__INSTALL_DIR__", install_dir))
PY
chmod +x "$BIN_DIR/linkedin-autoreply"
printf '%s\n' "$(git -C "$INSTALL_DIR" rev-parse HEAD)" > "$INSTALL_DIR/.installer_version"
date -u +%Y-%m-%dT%H:%M:%SZ > "$INSTALL_DIR/.installer_ts"
case ":$PATH:" in
*":$BIN_DIR:"*) ;;
*)
echo
echo "$BIN_DIR is not on your PATH. Add one of these lines:"
echo " export PATH=\"$BIN_DIR:\$PATH\""
echo
;;
esac
if [ "$SKIP_INIT" -eq 1 ]; then
echo "Install complete. Run '$BIN_DIR/linkedin-autoreply init' when ready."
exit 0
fi
exec "$BIN_DIR/linkedin-autoreply" init