first release
This commit is contained in:
parent
f26ce6ca46
commit
949471915c
40
.drone.yml
Normal file
40
.drone.yml
Normal file
@ -0,0 +1,40 @@
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: registry.libreschool.org/libreschool-automation/ubuntu-build:16.04
|
||||
commands:
|
||||
- debuild -i -us -uc
|
||||
- mkdir out && mv ../*.deb out/
|
||||
pull: always
|
||||
when:
|
||||
event: [ push, tag ]
|
||||
|
||||
- name: sign
|
||||
image: registry.libreschool.org/libreschool-automation/deb-sign:latest
|
||||
settings:
|
||||
files: out/*.deb
|
||||
gpg_key:
|
||||
from_secret: gpg_key
|
||||
passphrase:
|
||||
from_secret: passphrase
|
||||
pull: always
|
||||
when:
|
||||
event: tag
|
||||
|
||||
- name: gitea_release
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
files: out/*.deb
|
||||
checksum:
|
||||
- md5
|
||||
- sha1
|
||||
- sha256
|
||||
- sha512
|
||||
api_key:
|
||||
from_secret: gitea_token
|
||||
base_url: https://git.libreschool.org
|
||||
file_exists: skip
|
||||
when:
|
||||
event: tag
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
debian/libreschool-client.substvars
|
||||
debian/libreschool-client.debhelper.log
|
||||
debian/debhelper-build-stamp
|
||||
debian/libreschool-client/
|
||||
debian/.debhelper
|
||||
*.deb
|
3
conf/libreschool-client.conf
Normal file
3
conf/libreschool-client.conf
Normal file
@ -0,0 +1,3 @@
|
||||
[client]
|
||||
|
||||
[server]
|
2
cron/libreschool-client
Normal file
2
cron/libreschool-client
Normal file
@ -0,0 +1,2 @@
|
||||
*/5 * * * * root /usr/sbin/libreschool-client
|
||||
@reboot root /usr/sbin/libreschool-client
|
5
debian/changelog
vendored
Normal file
5
debian/changelog
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
libreschool-client (1.0.0) UNRELEASED; urgency=medium
|
||||
|
||||
* Initial release.
|
||||
|
||||
-- paolo <paolo@asperti.com> Thu, 12 Oct 2017 22:00:00 +0200
|
1
debian/compat
vendored
Normal file
1
debian/compat
vendored
Normal file
@ -0,0 +1 @@
|
||||
9
|
13
debian/control
vendored
Normal file
13
debian/control
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
Source: libreschool-client
|
||||
Section: admin
|
||||
Priority: optional
|
||||
Maintainer: LibreSchool <info@libreschool.org>
|
||||
Build-Depends: debhelper (>= 9), pkg-config
|
||||
Standards-Version: 3.9.7
|
||||
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}
|
||||
Description: LibreSchool management client
|
||||
Managed by a LibreSchool server.
|
27
debian/copyright
vendored
Normal file
27
debian/copyright
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: Doraemon Client
|
||||
Source: https://github.com/bglug-it/doraemon-client
|
||||
|
||||
Files: *
|
||||
Copyright: Copyright 2017 BGLug <info@bglug.it>
|
||||
License: GPL-2+
|
||||
This program is free software; you can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
.
|
||||
This program 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 General Public License for more
|
||||
details.
|
||||
.
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this package; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
Boston, MA 02110-1301 USA
|
||||
.
|
||||
On Debian systems, the full text of the GNU General Public
|
||||
License version 2 can be found in the file
|
||||
`/usr/share/common-licenses/GPL-2'.
|
2
debian/files
vendored
Normal file
2
debian/files
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
libreschool-client_1.0.0_all.deb admin optional
|
||||
libreschool-client_1.0.0_amd64.buildinfo admin optional
|
3
debian/libreschool-client.install
vendored
Normal file
3
debian/libreschool-client.install
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
libreschool-client usr/sbin
|
||||
cron/libreschool-client etc/cron.d
|
||||
conf/libreschool-client.conf etc/libreschool-client
|
4
debian/rules
vendored
Executable file
4
debian/rules
vendored
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
%:
|
||||
dh $@
|
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
@ -0,0 +1 @@
|
||||
3.0 (native)
|
113
libreschool-client
Executable file
113
libreschool-client
Executable file
@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import configparser
|
||||
import uuid
|
||||
import re
|
||||
import os
|
||||
import socket, struct
|
||||
import requests
|
||||
import sys
|
||||
import socket
|
||||
import fileinput
|
||||
import json
|
||||
|
||||
def get_default_gateway_linux():
|
||||
"""Read the default gateway directly from /proc."""
|
||||
with open("/proc/net/route") as fh:
|
||||
for line in fh:
|
||||
fields = line.strip().split()
|
||||
if fields[1] != '00000000' or not int(fields[3], 16) & 2:
|
||||
continue
|
||||
|
||||
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):
|
||||
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()
|
||||
config.read('/etc/libreschool-client/libreschool-client.conf')
|
||||
|
||||
# check for client section
|
||||
# and create it if non-existamt
|
||||
if not 'client' in config:
|
||||
config['client'] = {}
|
||||
|
||||
# generate client uuid if not set
|
||||
if not 'uuid' in config['client']:
|
||||
config['client']['uuid'] = str(uuid.uuid4())
|
||||
|
||||
# if uuid is not in the correct format, generate another
|
||||
match = re.search(r'^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$', config['client']['uuid'], re.M | re.I)
|
||||
if not match:
|
||||
config['client']['uuid'] = str(uuid.uuid4())
|
||||
|
||||
# check for server section
|
||||
# and create it if non-existamt
|
||||
if not 'server' in config:
|
||||
config['server'] = {}
|
||||
|
||||
# generate server ping url if not set
|
||||
if not 'ping_url' in config['server']:
|
||||
config['server']['ping_url'] = 'http://' + get_default_gateway_linux() + ':3000/ping'
|
||||
|
||||
# update config
|
||||
update_config_file(config)
|
||||
|
||||
|
||||
data = {
|
||||
'client_uuid': config['client']['uuid'],
|
||||
'hostname': socket.gethostname(),
|
||||
'last_config': config['server'].get('last_config','0')
|
||||
}
|
||||
|
||||
# if server uuid is set
|
||||
if 'uuid' in config['server']:
|
||||
# and is in the correct format
|
||||
match = re.search(r'^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$', config['server']['uuid'], re.M | re.I)
|
||||
if match:
|
||||
# add it to the request
|
||||
data['server_uuid']=config['server']['uuid']
|
||||
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json; charset=UTF-8'
|
||||
}
|
||||
try:
|
||||
r = requests.post(config['server']['ping_url'], data=json.dumps(data), headers=headers, timeout=5)
|
||||
except requests.exceptions.RequestException as e:
|
||||
print e
|
||||
sys.exit(1)
|
||||
|
||||
resp = r.json()
|
||||
|
||||
if 'error' in resp:
|
||||
print resp['error']
|
||||
sys.exit(1)
|
||||
|
||||
if not 'uuid' in config['server']:
|
||||
if 'server_uuid' in resp:
|
||||
config['server']['uuid'] = resp['server_uuid']
|
||||
update_config_file(config)
|
||||
|
||||
if not 'ping_url' in config['server']:
|
||||
if 'ping_url' in resp:
|
||||
config['server']['ping_url'] = resp['ping_url']
|
||||
update_config_file(config)
|
||||
|
||||
if 'hostname' in resp and 'domainname' in resp:
|
||||
if not data['hostname'] == resp['hostname']:
|
||||
set_new_hostname(resp['hostname'],resp['domainname'],data['hostname'])
|
Loading…
x
Reference in New Issue
Block a user