summaryrefslogtreecommitdiff
path: root/install.sh
blob: c83fb3b8956a4a44b488e3d5c8b106d7d03f9f29 (plain)
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
#!/usr/bin/env bash
MAILTO=${MAILTO:-markus@nordu.net}
CROND_FILE=/etc/cron.d/cf-replace
SSH_KEYS_PATH=/usr/local/bin/ssh-keys.sh
SSH_URL="https://code.nordu.net/?p=cf-replace.git;a=blob_plain;f=ssh-keys.sh;hb=HEAD"
CROND_URL="https://code.nordu.net/?p=cf-replace.git;a=blob_plain;f=cf-replace;hb=HEAD"

if ! grep -q -i ubuntu /etc/lsb-release; then
  echo "Not installing, this is not an Ubuntu machine"
  exit 1
fi
if [ -d /var/cache/cosmos/ ]; then
  echo "Not installing, machine is running cosmos"
  exit 1
fi  

if ! which ldapsearch >> /dev/null; then
  if ! apt-get install -y -qq ldap-utils >> /dev/null; then
    echo "Failed to install ldap-utils"
    exit 1
  fi
fi

if ! ldapsearch -o nettimeout=2 -o ldif-wrap=no -LLL -x -H "ldaps://ldap.nordu.net" -b "ou=people,dc=nordu,dc=net" "(uid=markus)" uid >> /dev/null; then
  echo "Failed to perform ldapsearch"
  exit 1
fi

if ! curl -s --show-error "$SSH_URL" > "$SSH_KEYS_PATH"; then
  echo "Failed to get ssh-keys.sh file"
  exit 1
fi

if [ ! -f /opt/cf-repalce-ignore ]; then
  echo "ndn-eduix nunoc" > /opt/cf-repalce-ignore
fi

chmod +x "$SSH_KEYS_PATH"

if ! curl -s --show-error "$CROND_URL" > "$CROND_FILE"; then
  echo "Failed to get cf-replace cron file" 
  test -f "$CROND_FILE" && rm "$CROND_FILE"
  exit 1
fi
sed -i -e "/MAILTO/ s/markus@nordu.net/$MAILTO/" "$CROND_FILE"
echo "cf-replace has been installed to $CROND_FILE"

if which cf-agent >> /dev/null; then
  apt-get purge -y -qq cfengine-nova
  pkill cf-
  echo "Uninstalled cfengine"
fi