Compare commits

...

2 Commits

Author SHA1 Message Date
Paolo Asperti 78068d2ffa
python3 migration (because of 20.04)
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2020-04-24 11:25:09 +02:00
Paolo Asperti 30941d369e
version bump
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
- added inventory check
- supporto for ubuntu 20.04
2020-04-06 22:32:50 +02:00
4 changed files with 38 additions and 11 deletions

View File

@ -1,2 +1,3 @@
*/5 * * * * root /usr/sbin/libreschool-client
15 */2 * * * root /usr/sbin/libreschool-client --with-inventory
@reboot root /usr/sbin/libreschool-client

13
debian/changelog vendored
View File

@ -1,3 +1,16 @@
libreschool-client (1.0.2) UNRELEASED; urgency=medium
* Migration to python3
-- paolo <paolo@asperti.com> Mon, 24 Apr 2020 22:00:00 +0200
libreschool-client (1.0.1) UNRELEASED; urgency=medium
* Support for ubuntu 20.04
* Added inventory check
-- paolo <paolo@asperti.com> Mon, 6 Apr 2020 22:00:00 +0200
libreschool-client (1.0.0) UNRELEASED; urgency=medium
* Initial release.

2
debian/control vendored
View File

@ -8,6 +8,6 @@ Homepage: https://git.libreschool.org/LibreSchool/libreschool-client
Package: libreschool-client
Architecture: all
Depends: python, python-configparser, python-requests, openssh-server, ${shlibs:Depends}, ${misc:Depends}
Depends: python3, python-configparser, python3-requests, python3-psutil, openssh-server, ${shlibs:Depends}, ${misc:Depends}
Description: LibreSchool management client
Managed by a LibreSchool server.

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import configparser
import uuid
@ -10,6 +10,8 @@ import sys
import socket
import fileinput
import json
import lsb_release
import psutil
def get_default_gateway_linux():
"""Read the default gateway directly from /proc."""
@ -22,20 +24,19 @@ def get_default_gateway_linux():
return socket.inet_ntoa(struct.pack("<L", int(fields[2], 16)))
def update_config_file(config):
# update config
with open('/etc/libreschool-client/libreschool-client.conf', 'w') as configfile:
config.write(configfile)
def set_new_hostname(hostname, domainname, oldhostname):
if os.path.isfile('/etc/hosts'):
f1=open('/etc/hosts','r').read()
m1=f1.replace(oldhostname,hostname)
m2=m1.replace(oldhostname+'.'+domainname, hostname+'.'+domainname)
f2=open('/etc/hosts','w')
f2.write(m2)
os.system("hostname -b "+hostname)
with open('/etc/hostname', 'w') as hostnamefile:
hostnamefile.write(hostname)
if not os.path.isfile('/etc/hosts'):
f1=open('/etc/hosts','r').read()
m=f1.replace(oldhostname,hostname)
m=m.replace(oldhostname+'.'+domainname, hostname+'.'+domainname)
f2=open('/etc/hosts','w')
f2.write(m)
return
config = configparser.ConfigParser()
@ -74,6 +75,18 @@ data = {
'last_config': config['server'].get('last_config','0')
}
if '--with-inventory' in sys.argv:
cpu = "Unknown"
with open("/proc/cpuinfo") as fh:
for line in fh:
fields = line.strip().split()
if "model name" in line:
cpu = re.sub( ".*model name.*:\s*", "", line, 1)
data['cpu'] = cpu
data['ram'] = int(psutil.virtual_memory().total / 1024)
distinfo = lsb_release.get_distro_information()
data['distro'] = distinfo.get('DESCRIPTION', 'n/a')
# if server uuid is set
if 'uuid' in config['server']:
# and is in the correct format
@ -89,13 +102,13 @@ headers = {
try:
r = requests.post(config['server']['ping_url'], data=json.dumps(data), headers=headers, timeout=5)
except requests.exceptions.RequestException as e:
print e
print(e)
sys.exit(1)
resp = r.json()
if 'error' in resp:
print resp['error']
print(resp['error'])
sys.exit(1)
if not 'uuid' in config['server']: