forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomby-install-or-upgrade.sh
More file actions
executable file
·98 lines (77 loc) · 2.86 KB
/
comby-install-or-upgrade.sh
File metadata and controls
executable file
·98 lines (77 loc) · 2.86 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
#!/usr/bin/env bash
# This function installs the comby dependency for cmd/searcher and
# cmd/replacer. The CI pipeline calls this script to install or upgrade comby
# for tests or development environments.
REQUIRE_VERSION="0.14.1"
RELEASE_VERSION=$REQUIRE_VERSION
RELEASE_TAG=$REQUIRE_VERSION
RELEASE_URL="https://github.com/comby-tools/comby/releases"
INSTALL_DIR=/usr/local/bin
function ctrl_c() {
rm -f $TMP/$RELEASE_BIN &> /dev/null
printf "[-] Installation cancelled. Please see https://github.com/comby-tools/comby/releases if you prefer to install manually.\n"
exit 1
}
trap ctrl_c INT
EXISTS=$(command -v comby || echo)
# Exit if comby exists with the desired version.
if [ "$EXISTS" ] && [ $(comby -version) == "$REQUIRE_VERSION" ]; then
exit 0
fi
if [ -n "$EXISTS" ]; then
INSTALL_DIR=$(dirname $EXISTS)
fi
if [ ! -d "$INSTALL_DIR" ]; then
printf "$INSTALL_DIR does not exist. Please download the binary from ${RELEASE_URL} and install it manually.\n"
exit 1
fi
TMP=${TMPDIR:-/tmp}
ARCH=$(uname -m || echo)
case "$ARCH" in
x86_64|amd64) ARCH="x86_64";;
*) ARCH="OTHER"
esac
OS=$(uname -s || echo)
if [ "$OS" = "Darwin" ]; then
OS=macos
fi
RELEASE_BIN="comby-${RELEASE_TAG}-${ARCH}-${OS}"
RELEASE_URL="https://github.com/comby-tools/comby/releases/download/${RELEASE_TAG}/${RELEASE_BIN}"
if [ ! -e "$TMP/$RELEASE_BIN" ]; then
printf "[+] Downloading comby $RELEASE_VERSION\n"
SUCCESS=$(curl -s -L -o "$TMP/$RELEASE_BIN" "$RELEASE_URL" --write-out "%{http_code}")
if [ "$SUCCESS" == "404" ]; then
printf "[-] No binary release available for your system.\n"
rm -f $TMP/$RELEASE_BIN
exit 1
fi
printf "[+] Download complete.\n"
fi
chmod 755 "$TMP/$RELEASE_BIN"
echo "[+] Installing comby to $INSTALL_DIR"
if [ ! $OS == "macos" ]; then
printf "[*] To install comby to $INSTALL_DIR requires sudo access. Please type the sudo password in the prompt below.\n"
sudo cp "$TMP/$RELEASE_BIN" "$INSTALL_DIR/comby"
else
cp "$TMP/$RELEASE_BIN" "$INSTALL_DIR/comby"
fi
SUCCESS_IN_PATH=$(command -v comby || echo notinpath)
if [ $SUCCESS_IN_PATH == "notinpath" ]; then
printf "[*] Comby is not in your PATH. You should add $INSTALL_DIR to your PATH.\n"
rm -f $TMP/$RELEASE_BIN
exit 1
fi
CHECK=$(printf 'printf("hello world!\\\n");' | $INSTALL_DIR/comby 'printf("hello :[1]!\\n");' 'printf("hello comby!\\n");' .c -stdin || echo broken)
if [ "$CHECK" == "broken" ]; then
printf "[-] comby did not install correctly.\n"
printf "[-] My guess is that you need to install the pcre library on your system. Try:\n"
if [ $OS == "macos" ]; then
printf "[*] brew install comby\n"
else
printf "[*] sudo apt-get install libpcre3-dev && bash <(curl -sL get.comby.dev)\n"
fi
rm -f $TMP/$RELEASE_BIN
exit 1
fi
rm -f $TMP/$RELEASE_BIN
printf "[+] comby upgraded to $REQUIRE_VERSION\n"