forked from dylan-sutton-chavez/edge-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
106 lines (87 loc) · 3.72 KB
/
install.sh
File metadata and controls
106 lines (87 loc) · 3.72 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
#!/usr/bin/env bash
# Re-run this script any time to upgrade.
set -e
BASE="${EDGE_INSTALL_BASE:-https://cdn.edgepython.com/cli}"
INSTALL_DIR="${EDGE_INSTALL_DIR:-$HOME/.local/bin}"
# Bundle a pinned chrome-headless-shell in ~/.cache/edge (same as Puppeteer approach); Chromium isn't in AL2/AL2023/RHEL repos and ID_LIKE distro detection is unreliable.
CHROME_DIR="${EDGE_CHROME_DIR:-$HOME/.cache/edge}"
CHROME_BUILD="${EDGE_CHROME_BUILD:-131.0.6778.85}"
case "$(uname -s)" in
Linux) os="unknown-linux-musl" ;;
Darwin) os="apple-darwin" ;;
*) echo "unsupported OS: $(uname -s)" >&2; exit 1 ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*) echo "unsupported arch: $(uname -m)" >&2; exit 1 ;;
esac
target="${arch}-${os}"
case "$target" in
x86_64-unknown-linux-musl|aarch64-unknown-linux-musl|x86_64-apple-darwin|aarch64-apple-darwin) ;;
*) echo "no prebuilt for $target yet; build from source with 'cargo install --path cli'" >&2; exit 1 ;;
esac
# Map our target to the chrome-for-testing platform folder name.
case "$target" in
x86_64-unknown-linux-musl) chrome_platform="linux64" ;;
aarch64-unknown-linux-musl) chrome_platform="" ;; # no headless-shell build for linux-arm64
x86_64-apple-darwin) chrome_platform="mac-x64" ;;
aarch64-apple-darwin) chrome_platform="mac-arm64" ;;
esac
CHROME_BIN="$CHROME_DIR/chrome-headless-shell-${chrome_platform}/chrome-headless-shell"
# True if a Chrome/Chromium-flavored binary the engine accepts is already reachable.
have_browser() {
[ -n "${EDGE_CHROME_PATH:-}" ] && [ -x "${EDGE_CHROME_PATH}" ] && return 0
[ -n "$chrome_platform" ] && [ -x "$CHROME_BIN" ] && return 0
command -v chromium >/dev/null 2>&1 \
|| command -v chromium-browser >/dev/null 2>&1 \
|| command -v google-chrome >/dev/null 2>&1 \
|| command -v microsoft-edge >/dev/null 2>&1
}
# Download a pinned chrome-headless-shell zip from Google's chrome-for-testing CDN.
install_browser() {
if [ -z "$chrome_platform" ]; then
echo "no chrome-headless-shell build for $target; install Chrome/Chromium manually and set EDGE_CHROME_PATH" >&2
exit 1
fi
if ! command -v unzip >/dev/null 2>&1; then
echo "unzip is required to extract chrome-headless-shell; install it (apt/dnf/yum/pacman/apk/brew install unzip) and re-run" >&2
exit 1
fi
echo "no Chromium-flavored browser found; downloading chrome-headless-shell ${CHROME_BUILD} (${chrome_platform})..."
local url="https://storage.googleapis.com/chrome-for-testing-public/${CHROME_BUILD}/${chrome_platform}/chrome-headless-shell-${chrome_platform}.zip"
local tmp
tmp="$(mktemp "${TMPDIR:-/tmp}/edge-chs.XXXXXX.zip")"
mkdir -p "$CHROME_DIR"
curl -fsSL "$url" -o "$tmp"
unzip -q -o "$tmp" -d "$CHROME_DIR"
rm -f "$tmp"
chmod +x "$CHROME_BIN"
echo "installed: $CHROME_BIN"
}
mkdir -p "$INSTALL_DIR"
curl -fsSL "${BASE}/edge-${target}.tar.gz" | tar -xz -C "$INSTALL_DIR" edge
chmod +x "$INSTALL_DIR/edge"
if ! have_browser; then
install_browser
fi
case "$(basename "${SHELL:-bash}")" in
bash) rc="$HOME/.bashrc" ;;
zsh) rc="$HOME/.zshrc" ;;
*) rc="" ;;
esac
# Persist EDGE_CHROME_PATH so the CLI finds the bundled headless shell across shells.
if [ -n "$rc" ] && [ -n "$chrome_platform" ] && [ -x "$CHROME_BIN" ] && ! grep -qs 'EDGE_CHROME_PATH=' "$rc" 2>/dev/null; then
printf '\nexport EDGE_CHROME_PATH="%s"\n' "$CHROME_BIN" >> "$rc"
echo "added EDGE_CHROME_PATH to $rc"
fi
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
if [ -n "$rc" ] && ! grep -qs "$INSTALL_DIR" "$rc" 2>/dev/null; then
printf '\nexport PATH="%s:$PATH"\n' "$INSTALL_DIR" >> "$rc"
echo "added $INSTALL_DIR to PATH in $rc; run 'source $rc' or open a new shell"
fi
;;
esac
"$INSTALL_DIR/edge" --version