1
0
mirror of https://github.com/QSCTech/zjunet.git synced 2026-01-22 11:44:48 +08:00

Update building scripts

This commit is contained in:
Wu Yufei 2020-11-12 19:46:10 +08:00
parent a294ecaed0
commit c44a4105d4
No known key found for this signature in database
GPG Key ID: 226E1C0EDF292D66
4 changed files with 105 additions and 22 deletions

101
build/changelog.py Executable file
View File

@ -0,0 +1,101 @@
#!/usr/bin/env python3
import os
import sys
import json
import urllib3
import base64
import datetime
def get_time(s):
if 'fromisoformat' in dir(datetime.datetime):
return datetime.datetime.fromisoformat(s)
else:
return __import__('dateutil.parser').parser.parse(s)
http = urllib3.PoolManager()
GITHUB_AUTH = None
tok = os.getenv('GITHUB_TOKEN')
usn = os.getenv('GITHUB_USERNAME')
psw = os.getenv('GITHUB_PASSWORD')
if tok is not None:
GITHUB_AUTH = 'token {}'.format(tok)
elif usn is not None and psw is not None:
GITHUB_AUTH = 'Basic {}'.format(base64.b64encode('{}:{}'.format(usn, psw).encode('utf-8')).decode('utf-8'))
def get(url):
headers = {
'Accept': 'application/vnd.github.v3+json',
'User-Agent': 'zjunet-build-agent/0.1',
}
if GITHUB_AUTH is not None:
headers['Authorization'] = GITHUB_AUTH
r = http.request('GET', url, headers=headers)
assert r.status // 100 == 2, 'HTTP Status {} != 2xx while requesting {}'.format(r.status, url)
if r.status != 200:
print('WARNING: HTTP {} while requesting {}'.format(r.status, url))
return r.data
def api_get(url):
return json.loads(get('https://api.github.com/' + url))
author_cache = {}
def get_author(name):
if name in author_cache:
return author_cache[name]
print('Reading data for {}'.format(name), end=' : ', flush=True, file=sys.stderr)
data = api_get('users/{}'.format(name))
data = {
'name': data['name'],
'email': data['email'],
}
author_cache[name] = data
print('{} <{}>'.format(data['name'], data['email']), flush=True, file=sys.stderr)
return data
def get_changelog(owner, name):
print('Reading releases of {} in {}'.format(owner, name), flush=True, file=sys.stderr)
releases = api_get('repos/{}/{}/releases'.format(owner, name))
releases = filter(lambda v: not v['draft'] and not v['prerelease'], releases)
data = []
for rel in releases:
name = rel['name'] or rel['tag_name']
item = {
'time': get_time(rel['published_at']),
'name': name,
'version': name[name.rfind('v') + 1:].split(','),
'author': get_author(rel['author']['login']),
'changes': None,
}
tbody = rel['body'].strip()
if tbody != '':
if tbody[0] != '-' and '\n' not in tbody:
item['changes'] = '- ' + tbody
else:
item['changes'] = tbody
data.append(item)
return ChangeLog(data)
class ChangeLog:
def __init__(self, data):
self.raw = data
def rpm(self):
rel = '%changelog\n'
for item in self.raw:
rel += '* {} {} <{}> - {}\n'.format(item['time'].strftime('%a %b %d %Y'), item['author']['name'], item['author']['email'], '.'.join(item['version']))
if item['changes'] is not None:
rel += item['changes'] + '\n'
return rel
available_formats = dir(ChangeLog)
if len(sys.argv) != 2:
print('Usage: {} <format>\nAvailable formats: {}'.format(sys.argv[0], ','.join(ChangeLog)))
else:
changelog = get_changelog('QSCTech', 'zjunet')
if hasattr(changelog, sys.argv[1]):
print(getattr(changelog, sys.argv[1])())
else:
print('Invalid format {}\nAvailable formats: {}'.format())

View File

@ -36,7 +36,7 @@ Version: $VERSION
Section: net Section: net
Priority: optional Priority: optional
Architecture: all Architecture: all
Depends: xl2tpd (>= 1.3.1), curl, dnsutils Depends: xl2tpd (>= 1.3.7), curl, dnsutils
Maintainer: Tespent <me@tespent.cn> Maintainer: Tespent <me@tespent.cn>
Description: Command Line Scripts for ZJU Description: Command Line Scripts for ZJU
This script provides a VPN / WLAN / NEXTHOP for ZJUer. This script provides a VPN / WLAN / NEXTHOP for ZJUer.

View File

@ -26,7 +26,7 @@ Version: $VERSION
Section: net Section: net
Priority: optional Priority: optional
Architecture: all Architecture: all
Depends: xl2tpd (>= 1.3.1), curl, bind-dig Depends: xl2tpd (>= 1.3.7), curl, bind-dig
Maintainer: Tespent <me@tespent.cn> Maintainer: Tespent <me@tespent.cn>
Description: Command Line Scripts for ZJU Description: Command Line Scripts for ZJU
This script provides a VPN / WLAN / NEXTHOP for ZJUer. This script provides a VPN / WLAN / NEXTHOP for ZJUer.

View File

@ -13,7 +13,7 @@ echo "Group: Applications/Internet" >> zjunet.spec
echo "URL: https://github.com/QSCTech/zjunet/" >> zjunet.spec echo "URL: https://github.com/QSCTech/zjunet/" >> zjunet.spec
echo "Vendor: Qiu Shi Chao Website of Zhejiang University" >> zjunet.spec echo "Vendor: Qiu Shi Chao Website of Zhejiang University" >> zjunet.spec
echo "Packager: Tespent <me@tespent.cn>" >> zjunet.spec echo "Packager: Tespent <me@tespent.cn>" >> zjunet.spec
echo "Requires: xl2tpd >= 1.3.1, curl, bind-utils" >> zjunet.spec echo "Requires: xl2tpd >= 1.3.7, curl, bind-utils" >> zjunet.spec
echo "BuildRoot: %{_builddir}/%{name}-root" >> zjunet.spec echo "BuildRoot: %{_builddir}/%{name}-root" >> zjunet.spec
echo "Source: %{name}-%{version}.tar.gz" >> zjunet.spec echo "Source: %{name}-%{version}.tar.gz" >> zjunet.spec
echo "BuildArch: noarch" >> zjunet.spec echo "BuildArch: noarch" >> zjunet.spec
@ -63,23 +63,5 @@ echo "" >> zjunet.spec
echo "%post" >> zjunet.spec echo "%post" >> zjunet.spec
echo "/usr/share/zjunet/zjunet-postinst || true" >> zjunet.spec echo "/usr/share/zjunet/zjunet-postinst || true" >> zjunet.spec
echo "" >> zjunet.spec echo "" >> zjunet.spec
echo "%changelog" >> zjunet.spec ../changelog.py rpm >> zjunet.spec
echo "* Sun Feb 08 2015 Senorsen <sen@senorsen.com> - 0.2.4" >> zjunet.spec
echo "- Genrate debian and opkg packages using fakeroot (in case of wrong uid)" >> zjunet.spec
echo "- Replace test IP with a more stable one" >> zjunet.spec
echo "* Sun Nov 23 2014 Zeno Zeng <zenoofzeng@gmail.com> - 0.2.3" >> zjunet.spec
echo "- build.sh & zjunet.sh now share lib/version" >> zjunet.spec
echo "- fork when calling xl2tpd-control" >> zjunet.spec
echo "* Sat Nov 22 2014 Senorsen <sen@senorsen.com> - 0.2.2" >> zjunet.spec
echo "- P-t-P server address issues" >> zjunet.spec
echo "- comment typo fixed" >> zjunet.spec
echo "* Wed Nov 12 2014 Zeno Zeng <zenoofzeng@gmail.com> - 0.2.1" >> zjunet.spec
echo "- xqyww123 fixed the compatibility with systemd" >> zjunet.spec
echo "- chaosink fixed the string escape problem in user.sh" >> zjunet.spec
echo "* Wed Oct 15 2014 Zeno Zeng <zenoofzeng@gmail.com> - 0.2.0" >> zjunet.spec
echo "- Use xl2tpd.conf, abandon \$HOME/.zjunet/" >> zjunet.spec
echo "- Setup route after connect / disconnect wlan" >> zjunet.spec
echo "* Mon Oct 13 2014 Zeno Zeng <zenoofzeng@gmail.com> - 0.1.2" >> zjunet.spec
echo "* Thu Oct 02 2014 Zeno Zeng <zenoofzeng@gmail.com> - 0.1.0" >> zjunet.spec
echo "- Initial version of the package" >> zjunet.spec