-
Notifications
You must be signed in to change notification settings - Fork 0
/
step.sh
50 lines (40 loc) · 1.49 KB
/
step.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
#!/bin/bash
set -e
REQUIRED_VERSION=${version}
SSH_KEY_FILE_URL=${ssh_key_file}
SSH_KEY_PASSPHRASE=${ssh_key_passphrase}
# Download and install the ssh key for Guardsquare access given url and passphrase are defined
if [ -n "$SSH_KEY_FILE_URL" ] && [ -n "$SSH_KEY_PASSPHRASE" ]; then
curl $SSH_KEY_FILE_URL -o "protected_ixguard_key"
chmod 600 ./protected_ixguard_key
eval "$(ssh-agent -s)"
expect <<EOF
set timeout -1
spawn ssh-add "./protected_ixguard_key"
expect "Enter passphrase for"
send "$SSH_KEY_PASSPHRASE\r"
expect eof
EOF
else
echo "SSH key for iXGuard access is missing."
exit 1
fi
# Check if desired version of ixguard, otherwise use default
if [ -z "$REQUIRED_VERSION" ]; then
echo "No version set. Selecting default version 4.12.6"
REQUIRED_VERSION="4.12.6"
fi
if ! command -v ixguard >/dev/null 2>&1 || [[ "$(ixguard --version)" != *"$REQUIRED_VERSION"* ]]; then
echo "iXGuard not found or incorrect version. Installing version $REQUIRED_VERSION..."
if ! command -v guardsquare >/dev/null 2>&1; then
echo "Downloading guardsquare..."
# Download and install guardsquare CLI
curl https://downloads.guardsquare.com/cli/latest_macos_amd64 -sL | tar -x && sudo mv -i guardsquare /usr/local/bin/
fi
# Download and install ixguard package
guardsquare download --ssh-agent ixguard@$REQUIRED_VERSION -o ixguard.pkg
sudo installer -pkg ixguard.pkg -target /
else
echo "iXGuard $REQUIRED_VERSION is already installed."
fi
exit 0