forked from vaamonde/ocsinventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-pos_ocs_server.sh
202 lines (166 loc) · 7.14 KB
/
04-pos_ocs_server.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#! / bin / bash
# Author: Robson Vaamonde
# Site: www.procedimentosemti.com.br
# Facebook: facebook.com/ProcedimentosEmTI
# Facebook: facebook.com/BoraParaPratica
# YouTube: youtube.com/BoraParaPratica
# Date created: 18/06/2017
# Updated Date: 06/13/2019
# Version: 0.4
# Tested and approved for Ubuntu Server 16.04 LTS x64 version
# Kernel> = 4.4.x
#
# OCS Inventory Server Post-Installation
#
# Using the command: sudo -i to run the script
#
# Parameter Configuration File
source 00-parametros.sh
#
# Path to script log
LOG = $ VARLOGPATH / $ LOGSCRIPT
#
if [ " $ USER " == " 0 " ]
then
if [ " $ UBUNTU " == " 16.04 " ]
then
if [ " $ KERNEL " == " 4.4 " ]
then
clear
echo -e " User is ` whoami ` continuing to run the $ LOGSCRIPT "
# Exporting the Debian Frontend Noninteractive Variable to Not Request User Interaction
export DEBIAN_FRONTEND = noninteractive
echo
echo ================================================= =========== >> $ LOG
echo -e " Changing the MySQL ocs user password, press <Enter> to continue "
read
# Changing the ocs user password using mysql command line
mysql -u $ USER -p $ PASSWORD -e " $ SETOCSPWD " mysql & >> $ LOG
echo -e " Password changed with success !!! "
sleep 2
mysql -u $ USER -p $ PASSWORD -e " $ FLUSH " mysql & >> $ LOG
echo -e " Permission changed successfully !!! "
sleep 2
echo
echo -e " Password changed successfully !!!, press <Enter> to continue "
read
sleep 2
clear
echo -e " Removing the install.php file from OCS Reports, press <Enter> to continue "
read
# Backing up the install.php file
mv -v /usr/share/ocsinventory-reports/ocsreports/install.php /usr/share/ocsinventory-reports/ocsreports/install.php.bkp & >> $ LOG
echo -e " Backup made successfully !!!! "
sleep 2
echo
echo -e " File successfully removed !!!, press <Enter> to continue "
read
sleep 2
clear
echo -e " Updating OCS Inventory Server Configuration Files "
echo
echo -e " Editing OCS Inventory Server file z-ocsinventory-server.conf, press <Enter> to continue "
read
# OCS Inventory Server Configuration File to Receive Client Updates
# Backing up the original configuration file
mv -v /etc/apache2/conf-available/z-ocsinventory-server.conf /etc/apache2/conf-available/z-ocsinventory-server.conf.bkp & >> $ LOG
echo -e " Backup made successfully !!! "
sleep 2
# Upgrading to new configuration file
cp -v conf / z-ocsinventory-server.conf / etc / apache2 / conf-available / & >> $ LOG
echo -e " Update was successful !!! "
sleep 2
# Editing the configuration file
vim /etc/apache2/conf-available/z-ocsinventory-server.conf
echo -e " File successfully edited !!!, press <Enter> to continue "
read
sleep 2
clear
echo -e " Editing OCS Inventory RestApi zz-ocsinventory-restapi.conf file, press <Enter> to continue "
read
# New OCS Inventory Server Configuration File to Receive Client Updates
# Backing up the original configuration file
mv -v /etc/apache2/conf-available/zz-ocsinventory-restapi.conf /etc/apache2/conf-available/zz-ocsinventory-restapi.conf.bkp & >> $ LOG
echo -e " Backup made successfully !!! "
sleep 2
# Upgrading to new configuration file
cp -v conf / zz-ocsinventory-restapi.conf / etc / apache2 / conf-available / & >> $ LOG
echo -e " Update was successful !!! "
sleep 2
# Editing the configuration file
vim /etc/apache2/conf-available/zz-ocsinventory-restapi.conf
echo -e " File successfully edited !!!, press <Enter> to continue "
read
sleep 2
clear
echo -e " Updating OCS Inventory Reports Configuration Files "
echo
echo -e " Editing OCS Inventory Reports file ocsinventory-reports.conf, press <Enter> to continue "
read
# OCS Inventory Reports Server Configuration File Responsible for Software Distribution and Reporting
# Backing up the original configuration file
mv -v /etc/apache2/conf-available/ocsinventory-reports.conf /etc/apache2/conf-available/ocsinventory-reports.conf.bkp & >> $ LOG
echo -e " Backup made successfully !!! "
sleep 2
# Upgrading to new configuration file
cp -v conf / ocsinventory-reports.conf / etc / apache2 / conf-available / & >> $ LOG
echo -e " Update was successful !!! "
sleep 2
# Editing the configuration file
vim /etc/apache2/conf-available/ocsinventory-reports.conf
echo -e " File successfully edited !!!, press <Enter> to continue "
read
sleep 2
clear
echo -e " Editing OCS Inventory Server DBConfig dbconfig.inc.php file, press <Enter> to continue "
read
# Configuration File for MySQL Database Connection
# Configuration of database user and password variables: database name (ocsweb) and user (ocs)
# This file will be recreated again after browser installation
# Backing up the original configuration file
mv -v /usr/share/ocsinventory-reports/ocsreports/dbconfig.inc.php /usr/share/ocsinventory-reports/ocsreports/dbconfig.inc.php.bkp & >> $ LOG
echo -e " Backup made successfully !!! "
sleep 2
# Upgrading to new configuration file
cp -v conf / dbconfig.inc.php / usr / share / ocsinventory-reports / ocsreports / & >> $ LOG
echo -e " Update was successful !!! "
sleep 2
# Editing the configuration file
vim /usr/share/ocsinventory-reports/ocsreports/dbconfig.inc.php
# Rebooting Apache2
sudo service apache2 restart
echo -e " Apache2 successfully rebooted !!! "
sleep 2
echo -e " File successfully edited !!!, press <Enter> to continue "
read
sleep 2
clear
echo ================================================= =========== >> $ LOG
echo -e " End of $ LOGSCRIPT on: ` date ` " >> $ LOG
echo -e " OCS Inventory Server Post-Installation Finish Successfully Done !!!!! "
echo
# Script to calculate the time it takes to execute ocs_server.sh
FinalDate = ` date +% s '
SOMA = ` expr $ FinalDate - $ DATAINICIAL '
RESULT = ` expr 10800 + $ SOMA `
TIME = ` date -d @ $ RESULT +% H:% M:% S`
echo -e " Time taken to execute ocs_server.sh: $ TIME "
echo -e " Press <Enter> to reboot the server: ` hostname ` "
read
sleep 2
reboot
else
echo -e " Kernel Version: $ KERNEL not approved for this script, version:> = 4.4 "
echo -e " Press <Enter> to end script "
read
fi
else
echo -e " GNU / Linux Distribution: ` lsb_release -is ` not approved for this script, version: $ UBUNTU "
echo -e " Press <Enter> to end script "
read
fi
else
echo -e " User is not ROOT, run the command with the option: sudo -i <Enter> then enter the user's password ` whoami ` "
echo -e " Press <Enter> to end script "
read
fi