Misc scripts fixes:
- Make genstatusconf ignore non-exozyme-hosted sites - Fix shellcheck errors - Format Python scripts with black - Rewrite sysusers in bash to parse systemd-sysusers --tldr
This commit is contained in:
parent
601493df7a
commit
4396f94dcc
4 changed files with 51 additions and 52 deletions
|
@ -1,54 +1,52 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Generate the status config based on the exozyme explore page
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
deny = {
|
||||
'Status', # Make sure we don't include the status page itself!!
|
||||
'exolinux',
|
||||
'Recursion',
|
||||
'Unicode Visualizer',
|
||||
'69!=',
|
||||
'April Gools',
|
||||
'Diagonal Scroll',
|
||||
'flexozyme',
|
||||
'Multiple Pendulum Animation',
|
||||
'Dumb Physics Engine',
|
||||
'Hex Color Clock',
|
||||
'blank'
|
||||
}
|
||||
from re import search
|
||||
from socket import getaddrinfo
|
||||
from sys import argv
|
||||
|
||||
|
||||
tld = "exozy.me"
|
||||
ip = getaddrinfo(tld, 443)[0][4][0]
|
||||
rules = {
|
||||
'PixivFE': 'about',
|
||||
'LiteXiv': 'main.css',
|
||||
'Priviblur': 'priviblur/licences',
|
||||
'Redlib': 'info',
|
||||
"Status": None, # Make sure we don't include the status page itself!!
|
||||
"PixivFE": "about",
|
||||
"LiteXiv": "main.css",
|
||||
"Priviblur": "priviblur/licences",
|
||||
"Redlib": "info",
|
||||
}
|
||||
|
||||
|
||||
sites = []
|
||||
with open('/srv/http/www/explore.html') as f:
|
||||
with open("/srv/http/www/explore.html") as f:
|
||||
for l in f.readlines():
|
||||
m = re.search('<td><a href="https://(.*)">(.*)</a></td>', l)
|
||||
if m is not None and m.groups()[1] not in deny:
|
||||
if m.groups()[1] in rules:
|
||||
sites.append((f'{m.groups()[0]}/{rules[m.groups()[1]]}', m.groups()[1]))
|
||||
else:
|
||||
sites.append(m.groups())
|
||||
m = search('<td><a href="https://(.*)">(.*)</a></td>', l)
|
||||
if m is None:
|
||||
continue
|
||||
x = m.groups()
|
||||
if not x[0].endswith(tld) and getaddrinfo(x[0], 443)[0][4][0] != ip:
|
||||
continue
|
||||
if x[1] in rules:
|
||||
if rules[x[1]]:
|
||||
sites.append((f"{x[0]}/{rules[x[1]]}", x[1]))
|
||||
else:
|
||||
sites.append(x)
|
||||
|
||||
|
||||
newconf = []
|
||||
with open(sys.argv[1]) as f:
|
||||
with open(argv[1]) as f:
|
||||
for l in f.readlines():
|
||||
if 'description = ' not in l:
|
||||
if "description = " not in l:
|
||||
newconf.append(l)
|
||||
if l == 'service = [\n':
|
||||
newconf += list(map(lambda m: f' {{ description = "{m[1]}", url = "https://{m[0]}" }},\n', sites))
|
||||
if l == "service = [\n":
|
||||
newconf += list(
|
||||
map(
|
||||
lambda x: f' {{ description = "{x[1]}", url = "https://{x[0]}" }},\n',
|
||||
sites,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
with open(sys.argv[1], 'w') as f:
|
||||
f.write(''.join(newconf))
|
||||
with open(argv[1], "w") as f:
|
||||
f.write("".join(newconf))
|
||||
|
|
2
nmpubip
2
nmpubip
|
@ -4,7 +4,7 @@
|
|||
# Designed to be used with https://github.com/ddclient/ddclient
|
||||
|
||||
# Check if IPv4 or IPv6
|
||||
if [[ "$1" =~ "." ]]; then
|
||||
if [[ "$1" =~ \. ]]; then
|
||||
nmcli con mod 'Wired connection 1' ipv4.addresses "$1"
|
||||
systemctl restart NetworkManager
|
||||
fi
|
||||
|
|
20
pacplot
20
pacplot
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Graph the number of installed packages over time by parsing /var/log/pacman.log
|
||||
|
||||
|
@ -6,33 +6,33 @@ from datetime import datetime
|
|||
from matplotlib import pyplot as plt
|
||||
|
||||
|
||||
with open('/var/log/pacman.log', 'r') as f:
|
||||
with open("/var/log/pacman.log", "r") as f:
|
||||
cnt = 0
|
||||
installed = 0
|
||||
removed = 0
|
||||
x = []
|
||||
y = []
|
||||
for line in f.readlines():
|
||||
if '[ALPM]' not in line or 'warning' in line:
|
||||
if "[ALPM]" not in line or "warning" in line:
|
||||
# Ignore operations
|
||||
continue
|
||||
|
||||
if ' installed' in line:
|
||||
if " installed" in line:
|
||||
cnt += 1
|
||||
installed += 1
|
||||
elif 'removed' in line:
|
||||
elif "removed" in line:
|
||||
cnt -= 1
|
||||
removed += 1
|
||||
else:
|
||||
continue
|
||||
|
||||
x.append(datetime.fromisoformat(line[1:23] + ':00'))
|
||||
x.append(datetime.fromisoformat(line[1:23] + ":00"))
|
||||
y.append(cnt)
|
||||
|
||||
|
||||
print('Currently installed packages:', cnt)
|
||||
print('Total installed packages:', installed)
|
||||
print('Total removed packages:', removed)
|
||||
print("Currently installed packages:", cnt)
|
||||
print("Total installed packages:", installed)
|
||||
print("Total removed packages:", removed)
|
||||
plt.plot(x, y)
|
||||
plt.savefig('pac.png')
|
||||
plt.savefig("pac.png")
|
||||
plt.show()
|
||||
|
|
11
sysusers
11
sysusers
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/fish
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Compare /etc/passwd and /usr/lib/sysusers.d to find unneeded users
|
||||
# Compare /etc/{passwd,group} and sysusers to find unneeded users and groups
|
||||
|
||||
for i in (cat /etc/passwd /etc/group | cut -d: -f1)
|
||||
echo -n "$i "; grep -or $i /usr/lib/sysusers.d | wc -l
|
||||
end
|
||||
echo "Unused users:"
|
||||
diff --color <(awk -F: '$3 < 1000 {print $1}' /etc/passwd | sort) <(systemd-sysusers --tldr | awk '$1 == "u" {print $2}' | sort)
|
||||
echo "Unused groups:"
|
||||
diff --color <(awk -F: '$3 < 1000 {print $1}' /etc/group | sort) <(systemd-sysusers --tldr | awk '$1 == "u" || $1 == "g" {print $2}' | sort | uniq)
|
||||
|
|
Loading…
Reference in a new issue