-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-cli.sh
executable file
·119 lines (101 loc) · 3.77 KB
/
install-cli.sh
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
#!/bin/bash
# Installation script for Openconnect-RS CLI
# This script will download the Openconnect-RS CLI and vpnc-script and install them in $HOME/.oidcvpn/bin
# It will also add $HOME/.oidcvpn/bin to PATH
# Usage:
# curl -s -L URL_TO_SCRIPT_HERE | sh
COLOR_PRIMARY="\033[0;34m"
COLOR_WARN="\033[1;33m"
COLOR_SUCCESS="\033[0;32m"
COLOR_FAILURE="\033[0;31m"
COLOR_RESET="\033[0m"
TAG="v0.1.5"
echo ""
echo "=================================="
echo ""
echo -e "${COLOR_PRIMARY}Installing Openconnect-RS CLI${COLOR_RESET}"
echo ""
echo ""
echo -e "This script will download the Openconnect CLI and vpnc-script and install them in $HOME/.oidcvpn/bin"
echo -e "${COLOR_WARN}WARNING: Openconnect-RS CLI has the same installed binary name as the original Openconnect CLI."
echo -e "Please remove the original Openconnect CLI if you wish to use Openconnect-RS CLI.${COLOR_RESET}"
echo ""
echo "=================================="
echo ""
# shut down if openconnect is running
if pgrep -x "openconnect" > /dev/null
then
echo "Openconnect is running. Please shut it down before installing Openconnect-RS CLI"
exit 1
fi
CLI_DOWNLOAD_URL=""
VPNC_SCRIPT_URL="https://gitlab.com/openconnect/vpnc-scripts/raw/master/vpnc-script"
# detect os
if [[ "$OSTYPE" = "darwin"* ]]; then
# detect arch
if [[ "$HOSTTYPE" = "x86_64" ]]; then
# install macos cli
CLI_DOWNLOAD_URL="https://github.com/hlhr202/Openconnect-RS/releases/download/${TAG}/openconnect-cli_osx-x86_64"
elif [[ "$HOSTTYPE" = "arm64" ]]; then
# install macos cli
CLI_DOWNLOAD_URL="https://github.com/hlhr202/Openconnect-RS/releases/download/${TAG}/openconnect-cli_osx-aarch64"
else
echo -e "${COLOR_FAILURE}unsupported arch${COLOR_RESET}"
exit 1
fi
elif [[ "$OSTYPE" = "linux-gnu" ]]; then
if [[ "$HOSTTYPE" = "x86_64" ]]; then
CLI_DOWNLOAD_URL="https://github.com/hlhr202/Openconnect-RS/releases/download/${TAG}/openconnect-cli_linux-x86_64"
else
echo -e "${COLOR_FAILURE}unsupported arch${COLOR_RESET}"
exit 1
fi
else
echo -e "${COLOR_FAILURE}unsupported os${COLOR_RESET}"
exit 1
fi
# check if .oidcvpn/bin folder exists under home directory
if [[ ! -d "$HOME/.oidcvpn/bin" ]]; then
mkdir -p $HOME/.oidcvpn/bin
fi
# download cli
echo -e "${COLOR_PRIMARY}Downloading cli${COLOR_RESET}"
echo ""
curl -L $CLI_DOWNLOAD_URL >$HOME/.oidcvpn/bin/openconnect
chmod +x $HOME/.oidcvpn/bin/openconnect
echo ""
echo "=================================="
echo ""
# download vpnc-script
echo -e "${COLOR_PRIMARY}Downloading vpnc-script${COLOR_RESET}"
echo ""
curl -L $VPNC_SCRIPT_URL >$HOME/.oidcvpn/bin/vpnc-script
chmod +x $HOME/.oidcvpn/bin/vpnc-script
echo ""
echo "=================================="
echo ""
# add .oidcvpn/bin to PATH
echo -e "${COLOR_PRIMARY}Adding .oidcvpn/bin to PATH${COLOR_RESET}"
echo ""
if [[ ":$PATH:" != *":$HOME/.oidcvpn/bin:"* ]]; then
echo "Adding .oidcvpn/bin to PATH"
# check if .bashrc or .bash_profile exists
if [[ -f "$HOME/.bashrc" ]]; then
echo "export PATH=\$PATH:$HOME/.oidcvpn/bin" >>$HOME/.bashrc
echo "Run source $HOME/.bashrc to apply changes"
elif [[ -f "$HOME/.bash_profile" ]]; then
echo "export PATH=\$PATH:$HOME/.oidcvpn/bin" >>$HOME/.bash_profile
echo "Run source $HOME/.bash_profile to apply changes"
fi
# check if .zshrc exists
if [[ -f "$HOME/.zshrc" ]]; then
echo "export PATH=\$PATH:$HOME/.oidcvpn/bin" >>$HOME/.zshrc
echo "Run source $HOME/.zshrc to apply changes"
fi
fi
echo "If you are using shell other than bash or zsh, please add the following line to your shell profile:"
echo "export PATH=\$PATH:$HOME/.oidcvpn/bin"
echo ""
echo "=================================="
echo ""
echo -e "${COLOR_SUCCESS}Installation complete!${COLOR_RESET}"