-
Notifications
You must be signed in to change notification settings - Fork 11
/
fsl-packages-sync.py
executable file
·89 lines (77 loc) · 2.54 KB
/
fsl-packages-sync.py
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
#!/usr/bin/python3
#
# fsl-packages-sync - A helper script to sync the Fedora Security Lab package
# list with the origin list from https://fedorahosted.org/security-spin/
#
# Copyright (c) 2013-2022 Fabian Affolter <[email protected]>
#
# All rights reserved.
#
# 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 program; if not, write to the Free Software
# Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import requests
import operator
import itertools
import datetime
import sys
import os
try:
import git
except ImportError:
print("Please install GitPython -> sudo dnf -y install python3-GitPython")
try:
import yaml
except ImportError:
print("Please install PyYAML -> sudo dnf -y install PyYAML")
repo = git.Repo(os.getcwd())
def playbook_sync():
"""Generate a Ansible playbook for the installation."""
pkg_file = requests.get(
'https://pagure.io/security-lab/raw/master/f/pkglist.yaml')
pkgslist = yaml.safe_load(pkg_file.text)
part1 = """# This playbook install packages for the Fedora Security Lab.
#
# Copyright (c) 2013-2020 Fabian Affolter <[email protected]>
#
# Licensed under CC BY 3.0. All rights reserved.
#
# Synced at {}
#
---
- hosts: fsl_hosts
user: root
tasks:
- name: install $item
dnf: pkg=$item state=installed
with_items:\n""".format(datetime.date.today())
# Split list of packages into eincluded and excluded packages
sorted_pkgslist = sorted(pkgslist, key=operator.itemgetter('pkg'))
# Write the playbook files
fileOut = open('fsl.yml', 'w')
fileOut.write(part1)
for pkg in sorted_pkgslist:
fileOut.write(' - %s\n' % pkg['pkg'])
fileOut.close()
# Commit the changed file to the repository
repo.git.add('fsl.yml')
repo.git.commit(
m="Synced playbook with origin from https://pagure.io/security-lab")
repo.git.push()
# Remove the pkglist.yaml file
os.remove('pkglist.yaml')
if __name__ == '__main__':
"""Run the script."""
playbook_sync()