-
Notifications
You must be signed in to change notification settings - Fork 2
/
fia-installer-4l.sh
374 lines (311 loc) · 11.9 KB
/
fia-installer-4l.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/bin/bash
# Fusioninventory agent installer for GNU/Linux
# fia-installer-4l.sh
#
# Copyright (C) 2018-2020 by TICgal
#
# https://github.com/ticgal/fia-installer-4l
#
# ------------------------------------------------------------------------
#
# LICENSE
#
# This file is part of the Fusioninventory agent installer for GNU/Linux project.
#
# Fusioninventory agent installer for GNU/Linux is free software: you can
# redistribute it and/or modify it under the terms of the GNU Affero General
# Public License as published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.
#
# Fusioninventory agent installer for GNU/Linux is distributed in the hope
# that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Notifications plugin. If not, see <http://www.gnu.org/licenses/>.
#
# ------------------------------------------------------------------------
#
# @package Fusioninventory Agent Installer for GNU/Linux
# @author TICgal
# @copyright Copyright (c) 2018-2020 TICgal
# @license AGPL License 3.0 or (at your option) any later version
# http://www.gnu.org/licenses/agpl-3.0-standalone.html
# @link https://github.com/ticgal/fia-installer-4l
# @link https://tic.gal/en/project/fusioninventory-agent-installer-for-gnu-linux/
#/
#Will install optional modules in modern distributions
#Old ones will only install localinventory
#BTN error handling
set -e -o pipefail -u #
#################################
# #
# Review settings #
# #
#################################
#Install only agent or agent with all modules
#Space separated modules
#0="fusioninventory-agent_"
#1="fusioninventory-agent-task-network_"
#2="fusioninventory-agent-task-deploy_"
#3="fusioninventory-agent-task-esx_"
#4="fusioninventory-agent-task-collect_"
#
#Agent only
#fiainstallmodules=(0)
#All modules
#fiainstallmodules=(0 1 2 3 4)
fiainstallmodules=(0)
#Just for upgrades
#If you want to get a new agent id set to 1.
resetagent=0
#Fusioninventory agent version (Debian derivatives only)
fiaver='2.6-1'
#Config file name
client='TICgal'
#GLPi Tag
fiatag=''
#Fusioninventory server
#fiaglpiserver='https://glpiserver/plugins/fusioninventory/'
fiaglpiserver=''
#Debug
#(0,1,2,3)
fiadebug='1'
#no-SSL-Check
#(0,1)
fianosslcheck='1'
#logger
#(stderr,file,syslog)
fialogger='file'
#no-category
#(antivirus battery controller cpu drive environment input licenseinfo local_group local_user
#lvm memory modem monitor network port printer process remote_mgmt slot software sound storage usb user
# video virtualmachine)
fianocategory='printer'
#There are 3 more "hardcoded" parameters
#1.Creates a local inventory on /tmp
#2.Defaults log file to /var/log/fusioninventory.log file
#3.Enables coloured terminal
#################################
#################################
# #
# Do not edit under this line #
# #
#################################
#################################
#FIA config path
fiacfg='/etc/fusioninventory/conf.d/'
#Check if script is run as root.
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
#If no server is set exit
if [ -z "$fiaglpiserver" ]; then
echo "You need to setup at least a GLPI-Fusioninventory server!!!"
exit 1
fi
#Check OS
if [[ -r /etc/os-release ]]; then
. /etc/os-release
if [[ -n $ID ]]; then
echo Detected OS: "$ID" "$VERSION_ID"
fi
if [[ $ID =~ ^(centos|fedora|ol)$ ]]; then
###########
# CentOS #
###########
#Enable EPEL repository if not enabled
if ! rpm -q --quiet epel-release; then
if [[ $VERSION_ID = 8 ]]; then
dnf -y install epel-release
dnf -y config-manager --set-enabled PowerTools
elif [[ $VERSION_ID = 7 ]]; then
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
elif [[ $VERSION_ID = 6 ]]; then
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
fi
fi
# CENTOS 6 - 7 common dependencies and installation
if [[ $VERSION_ID = 6 || $VERSION_ID = 7 ]]; then
#Enable copr
yum -y install yum-plugin-copr
yum -y copr enable trasher/fusioninventory-agent
#Install modules
for i in "${fiainstallmodules[@]}"
do
#Agent is installed always
yum install -y fusioninventory-agent
#Which modules
case $i in
1)
yum install -y fusioninventory-agent-task-network*
;;
2)
yum install -y fusioninventory-agent-task-deploy*
;;
3)
yum install -y fusioninventory-agent-task-esx*
;;
4)
yum install -y fusioninventory-agent-task-collect*
;;
esac
done
fi
#Centos 8
if [[ $VERSION_ID = 8 ]]; then
dnf -y --enablerepo=epel-testing install fusioninventory-agent fusioninventory-agent-task-inventory
#Install modules
for i in "${fiainstallmodules[@]}"
do
#Which modules
case $i in
1)
dnf install -y fusioninventory-agent-task-network*
;;
2)
#dnf install -y fusioninventory-agent-task-deploy*
echo "Deploy is not available due to missing Perl dependency."
;;
3)
dnf install -y fusioninventory-agent-task-esx*
;;
4)
dnf install -y fusioninventory-agent-task-collect*
;;
esac
done
fi
#Not installed?
#fusioninventory-agent-cron.x86_64 : Cron for FusionInventory agent
#fusioninventory-agent-task-inventory.x86_64 : Inventory task for FusionInventory
# Enable and start service
if [[ $VERSION_ID = 7 || $VERSION_ID = 8 ]]; then
systemctl enable fusioninventory-agent
systemctl start fusioninventory-agent
elif [[ $VERSION_ID = 6 ]]; then
chkconfig fusioninventory-agent on
service fusioninventory-agent start
fi
###########
# /CentOS #
###########
elif [[ $ID =~ ^(debian|ubuntu)$ ]]; then
##########
# Debian #
##########
#Common#
#Update repositories
apt-get update
#Check if old manual version install exists
if [ -f /usr/local/etc/fusioninventory/agent.cfg ]; then
rm -rf /usr/local/bin/fusioninventory-* /usr/local/share/fusioninventory \
/usr/local/share/fusioninventory/lib /usr/local/var/fusioninventory \
/usr/local/etc/fusioninventory
hash -r
hash fusioninventory-agent
fi
#Reset agent if set on setup
if [ $resetagent = 1 ]; then
rm -rf /var/lib/fusioninventory-agent/
fi
#Recent Debian derivatives
if { [ "$ID" = "debian" ] && [ "$VERSION_ID" -ge 8 ]; } || \
{ [ "$ID" = "ubuntu" ] && [ "${VERSION_ID:0:2}" -ge 16 ]; }; then
#Debianrepository
fiarepository='https://github.com/fusioninventory/fusioninventory-agent/releases/download/'${fiaver%-*}'/'
#FIA modules
fiamodule[0]="fusioninventory-agent_"
fiamodule[1]="fusioninventory-agent-task-network_"
fiamodule[2]="fusioninventory-agent-task-deploy_"
fiamodule[3]="fusioninventory-agent-task-esx_"
fiamodule[4]="fusioninventory-agent-task-collect_"
#Remove previously downloaded deb files
rm -f ./*glob*.deb
#Just in case add-apt-repository is not installed
apt-get install -y software-properties-common
#Add universe repository. Needed for Ubuntu installs.
if [ "$ID" = "ubuntu" ]; then
add-apt-repository universe
fi
#fusioninventory-agent dependencies
apt-get install -y dmidecode hwdata ucf hdparm perl libuniversal-require-perl libwww-perl \
libparse-edid-perl libproc-daemon-perl libfile-which-perl libxml-treepp-perl libyaml-perl \
libnet-cups-perl libnet-ip-perl libdigest-sha-perl libsocket-getaddrinfo-perl \
libtext-template-perl libxml-xpath-perl libyaml-tiny-perl
#Debian 10 missing path issue workaround
if { [ "$ID" = "debian" ] && [ "$VERSION_ID" = 10 ]; }; then
export PATH=/sbin:$PATH
fi
#Install package
rm -f fusioninventory*.deb
for i in "${fiainstallmodules[@]}"
do
#Dependencies for fusioninventory-agent-task-network
if [[ $i = 1 ]]; then
apt-get install -y nmap libnet-snmp-perl libcrypt-des-perl libnet-nbname-perl \
libdigest-hmac-perl
fi
#Dependencies for fusioninventory-agent-task-deploy
if [[ $i = 2 ]]; then
apt-get install -y libfile-copy-recursive-perl libparallel-forkmanager-perl
fi
#Download and install packages
tempdeb="${fiamodule[$i]}${fiaver}_all.deb"
wget -q ${fiarepository}${tempdeb}
dpkg -i --force-confnew ${tempdeb}
#Clean up#
rm ${tempdeb}
done
fi
#Debian 7
elif [[ -r /etc/debian-version ]]; then
debianversion=$(</etc/debian-version)
if [[ ${debianversion:0:1} -eq "7" ]]; then
echo "deb http://httpredir.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list
apt-get update
apt-get -y install -t wheezy-backports fusioninventory-agent
fi
#Enabling and starting service
systemctl enable fusioninventory-agent
systemctl start fusioninventory-agent
###########
# /Debian #
###########
else
echo "Running ID=$ID, VERSION=$VERSION. Not currently supported."
echo "Please open an issue at github: https://github.com/ticgal/fia-installer-4l"
exit 2
fi
else
echo "Not running a distribution with /etc/os-release available"
exit 3
fi
#Creates a config file
#Config file
{
echo "#Added by fia-installer-4l.sh"
echo "#TICgal https://tic.gal"
echo "#$(date)"
echo "server = " "$fiaglpiserver"
echo "tag = " "$fiatag"
echo "debug = " "$fiadebug"
echo "no-ssl-check = " "$fianosslcheck"
echo "no-category = " "$fianocategory"
echo "logger = " "$fialogger"
echo "local = /tmp"
echo "logfile = /var/log/fusioninventory.log"
echo "color = 1"
} > $fiacfg$client.cfg
#Check version
fusioninventory-agent -v
#Start Agent
systemctl restart fusioninventory-agent
#Run inmediate inventory
pkill -USR1 -f -P 1 fusioninventory-agent
#Make sure an inventory is launched (sometimes it fails, needs debugging)
fusioninventory-agent
#Check if fusion is running (if more debugging is needed, uncomment)
#tail -f /var/log/fusioninventory.log