File: aminer_install.sh

package info (click to toggle)
logdata-anomaly-miner 2.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,612 kB
  • sloc: python: 48,247; sh: 4,863; xml: 1,666; makefile: 23
file content (113 lines) | stat: -rwxr-xr-x 2,554 bytes parent folder | download
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
#!/bin/bash

# if set to 1 this installer will delete the
# source directory after installation
DELDIR=1
BRANCH="main"
URL="https://github.com/ait-aecid/logdata-anomaly-miner.git"
AMINERDST=`mktemp -d`
AMINERSRC="0"
DISON=0

help() {
	echo "Usage: $0 [-h] [-b BRANCH] [-u GITURL] [-s LOCAL_GITREPO_PATH] [-d DIRECTORY]" 1>&2
}


while getopts "hb:u:s:d:" options; do
	case "${options}" in
		b)
			BRANCH=${OPTARG}
			;;
		h)
			help
			exit 1
			;;
		u)
			URL=${OPTARG}
			;;
		s)
			AMINERSRC=${OPTARG}
			DELDIR=0
			if [ ! -d $AMINERSRC ]
			then
				echo "Local Git-Repository $AMINERSRC does not exist."
				exit 1
			fi
			;;
		d)
			DISON=1
			AMINERDST=${OPTARG}
			if [ -d $AMINERDST ]
			then
				echo "This directory($AMINERDST) already exists. Please remove it first"
				exit 1
			fi
			DELDIR=0
			;;
		:)
			echo "$0: Must supply an argument to -$OPTARG." >&2
			exit 1
			;;
	esac
done

which sudo > /dev/null
if [ $? -ne 0 ]
then
	echo "Please install and configure sudo first"
	exit 1
fi

if [ -e /etc/debian_version ]; then
	sudo /usr/bin/apt-get update
	sudo DEBIAN_FRONTEND=nointeractive /usr/bin/apt-get install -y -q ansible git
elif [ -e /etc/fedora-release ] || [ -e /etc/redhat-release ]; then
	sudo dnf install -y ansible git
else
	echo "Currently only Debian and Fedora based distributions are supported."
	echo "More specifically this includes Debian Buster, Debian Bullseye, Debian Bookworm, Ubuntu 20, Ubuntu 22, Ubuntu 24, Fedora, and RedHat."
	echo "If you decide to install the AMiner on another system, please add **--extra-vars \"ansible_distribution == '$DIST' ansible_distribution_major_version == '$VER'\"**."
	echo "Choose the best-fitting related distribution of the supported ones for $DIST and $VER."
	exit 1
fi

if [ "$AMINERSRC" = "0" ]
then
	git clone -b $BRANCH $URL $AMINERDST
else
	if [ $DISON -eq 1 ]
	then
		cp -rap $AMINERSRC $AMINERDST
	else
		AMINERDST=$AMINERSRC
	fi
fi

cd $AMINERDST
test -d roles || mkdir roles
git clone -b $BRANCH https://github.com/ait-aecid/aminer-ansible roles/aminer


cat > playbook.yml << EOF
- hosts: localhost
  vars:
         aminer_gitrepo: False
         # We assume that we cloned the aminer to /home/developer/aminer
         aminer_repopath: "${AMINERDST}"
  roles:
         - aminer
EOF

# Use this command to deploy the aminer-files
# You can add your changes in the aminer-directory
# and repeatedly execute this command to deploy
# your changes
sudo ansible-playbook playbook.yml

if [ $DELDIR -eq 1 ]
then
	test -d $AMINERDST && rm -rf $AMINERDST
fi

exit 0