-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·52 lines (40 loc) · 1.12 KB
/
install.sh
File metadata and controls
executable file
·52 lines (40 loc) · 1.12 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
#!/bin/sh
set -eu
INSTALL_DIR="${INSTALL_DIR:-${HOME}/.local/bin}"
RAW_BASE_URL="${RAW_BASE_URL:-https://raw.githubusercontent.com/PSPDFKit/pdf-to-markdown/main}"
TARGET="$INSTALL_DIR/pdf-to-markdown"
TMP_FILE="$(mktemp "${TMPDIR:-/tmp}/pdf-to-markdown-install.XXXXXX")"
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
cleanup() {
rm -f "$TMP_FILE"
}
trap cleanup EXIT INT TERM HUP
download() {
url="$1"
destination="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$destination"
return 0
fi
if command -v wget >/dev/null 2>&1; then
wget -q -O "$destination" "$url"
return 0
fi
echo "install.sh requires curl or wget" >&2
exit 1
}
mkdir -p "$INSTALL_DIR"
if [ -f "$SCRIPT_DIR/bin/pdf-to-markdown" ]; then
cp "$SCRIPT_DIR/bin/pdf-to-markdown" "$TMP_FILE"
else
download "$RAW_BASE_URL/bin/pdf-to-markdown" "$TMP_FILE"
fi
chmod 0755 "$TMP_FILE"
mv "$TMP_FILE" "$TARGET"
printf 'Installed pdf-to-markdown to %s\n' "$TARGET"
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
printf 'Add %s to PATH if it is not already available in your shell.\n' "$INSTALL_DIR"
;;
esac