forked from linuxautomations/sonarqube
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
123 lines (107 loc) · 4.49 KB
/
install.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
120
121
122
123
#!/bin/bash
## Source Common Functions
curl -s "https://raw.githubusercontent.com/linuxautomations/scripts/master/common-functions.sh" >/tmp/common-functions.sh
#source /root/scripts/common-functions.sh
source /tmp/common-functions.sh
## Checking Root User or not.
CheckRoot
## Checking SELINUX Enabled or not.
CheckSELinux
## Checking Firewall on the Server.
CheckFirewall
which java &>/dev/null
if [ $? -ne 0 ]; then
## Downloading Java
#DownloadJava 8
## Installing Java
#yum install /opt/jdk* -y &>/dev/null
yum install java -y &>/dev/null
if [ $? -eq 0 ]; then
success "JAVA Installed Successfully"
else
error "JAVA Installation Failure!"
exit 1
fi
else
success "Java already Installed"
fi
## Downloading MYSQL Repositories and MySQL Server
yum install https://kojipkgs.fedoraproject.org/packages/python-html2text/2016.9.19/1.el7/noarch/python2-html2text-2016.9.19-1.el7.noarch.rpm -y &>/dev/null
MYSQLRPM=$(curl -s http://repo.mysql.com/ | html2text | grep el7 | grep mysql57| tail -1 | sed -e 's/(/ /g' -e 's/)/ /g' | xargs -n1 | grep ^mysql)
MYSQLURL="http://repo.mysql.com/$MYSQLRPM"
if [ ! -f /etc/yum.repos.d/mysql-community.repo ]; then
yum install $MYSQLURL -y &>/dev/null
if [ $? -eq 0 ]; then
success "Successfully Configured MySQL Repositories"
else
error "Error in Configuring MySQL Repositories"
exit 1
fi
else
warning "MySQL Repositories are already Configured"
fi
## Installing MySQL Server
yum install mysql-server -y &>/dev/null
if [ $? -eq 0 ]; then
success "Successfully Installed MySQL Server"
else
error "Error in Installing MySQL Server"
exit 1
fi
## Set Root Password and reset it
sed -i -e '/query_cache_size/ d' -e '$ a query_cache_size = 15M' /etc/my.cnf
systemctl enable mysqld &>/dev/null
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
systemctl restart mysqld
mysql -e "use mysql;update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';"
systemctl unset-environment MYSQLD_OPTS
systemctl restart mysqld
mysql --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@$$w0rD'"
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
systemctl restart mysqld
mysql -e "use mysql;update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';"
systemctl unset-environment MYSQLD_OPTS
systemctl restart mysqld
mysql -e "grant all privileges on sonarqube.* to 'sonarqube'@'localhost' identified by 'password';" &>/dev/null
mysql -e 'uninstall plugin validate_password;' &>/dev/null
## Creating DB and User access
wget https://raw.githubusercontent.com/linuxautomations/sonarqube/master/sonarqube.sql -O /tmp/sonarqube.sql &>/dev/null
mysql </tmp/sonarqube.sql
if [ $? -eq 0 ]; then
success "Successfully Created DB and User access"
else
error "Failed to create DB and User access"
exit 1
fi
## Downloading SonarQube
#VER=$(curl -s https://sonarsource.bintray.com/Distribution/sonarqube/ | tail -n 10 | awk -F '[<,>]' '{print $5}' | grep zip$ |tail -1)
#URL="https://sonarsource.bintray.com/Distribution/sonarqube/$VER"
URL=$(curl https://www.sonarqube.org/downloads/ | grep zip | grep dl_page | grep btn-primary | tail -1 | awk -F \" '{print $2}')
TFILE="/opt/$(echo $URL |awk -F / '{print $NF}')"
TDIR=$(echo $TFILE|sed -e 's/.zip//')
rm -rf /opt/sonarqube
wget $URL -O $TFILE &>/dev/null
cd /opt
unzip $VER &>/dev/null
mv $TDIR sonarqube
if [ $? -eq 0 ]; then
success "Successfully Downloaded and Extracted SonarQube"
else
error "Error in Downlading and Extracting SonarQube"
exit 1
fi
## Configure SonarQube
sed -i -e '/^sonar.jdbc.username/ d' -e '/^sonar.jdbc.password/ d' -e '/^sonar.jdbc.url/ d' -e '/^sonar.web.host/ d' -e '/^sonar.web.port/ d' /opt/sonarqube/conf/sonar.properties
sed -i -e '/#sonar.jdbc.username/ a sonar.jdbc.username=sonarqube' -e '/#sonar.jdbc.password/ a sonar.jdbc.password=password' -e '/InnoDB/ a sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance' -e '/#sonar.web.host/ a sonar.web.host=0.0.0.0' /opt/sonarqube/conf/sonar.properties
useradd sonar
chown sonar:sonar /opt/sonarqube -R
sed -i -e '/^#RUN_AS_USER/ c RUN_AS_USER=sonar' /opt/sonarqube/bin/linux-x86-64/sonar.sh
ln -s /opt/sonarqube/bin/linux-x86-64/sonar.sh /etc/init.d/sonar
systemctl enable sonar &>/dev/null
systemctl start sonar &>/dev/null
if [ $? -eq 0 ]; then
success "Configured and Started SonarQube Successfully"
else
error "SonarQube Startup Failed"
exit 1
fi