Merge branch 'master' of waschsauger.bl0rg.net:dirty-helpers
This commit is contained in:
commit
ff88888282
16 changed files with 256 additions and 10 deletions
3
XXX
Executable file
3
XXX
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# List XXXs, FIXMEs and TODOs in files
|
||||||
|
ag '^(?!.*mktemp).*XXX|FIXME|TODO' "$@"
|
22
b64-image
Executable file
22
b64-image
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# Convert an image to CSS/HTML base64 foo
|
||||||
|
|
||||||
|
from __future__ import division, print_function
|
||||||
|
import base64
|
||||||
|
import magic
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if not hasattr(magic, "from_file"):
|
||||||
|
print("wrong magic module installed? try pip install python-magic")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if len(sys.argv[1:]) == 0:
|
||||||
|
print("Usage: " + sys.argv[0] + " IMAGE.PNG ...")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for filename in sys.argv[1:]:
|
||||||
|
mimetype = magic.from_file(filename, mime=True)
|
||||||
|
with open(filename, "rb") as f:
|
||||||
|
encoded = base64.b64encode(f.read())
|
||||||
|
print("url(data:{};base64,{})".format(mimetype, encoded))
|
40
check-java-versions
Executable file
40
check-java-versions
Executable file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/python2
|
||||||
|
# Check Java versions against the newest one installed
|
||||||
|
#
|
||||||
|
# This assumes that there's OpenJDK installed and kept up to date.
|
||||||
|
|
||||||
|
from __future__ import division, print_function
|
||||||
|
from distutils.version import LooseVersion
|
||||||
|
from subprocess import check_output
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def is_java(package):
|
||||||
|
filelist = check_output(['rpm', '-ql', package])
|
||||||
|
return re.search(r'bin/java$', filelist, re.MULTILINE)
|
||||||
|
|
||||||
|
|
||||||
|
def package_version(package):
|
||||||
|
version_query = ['rpm', '--queryformat', '%{VERSION}', '-q']
|
||||||
|
version_query.append(package)
|
||||||
|
|
||||||
|
version = check_output(version_query)
|
||||||
|
|
||||||
|
version = re.sub('_', '.', version)
|
||||||
|
return version
|
||||||
|
|
||||||
|
|
||||||
|
def java_packages():
|
||||||
|
all_packages = check_output(['rpm', '-qa']).split('\n')
|
||||||
|
packages = [package
|
||||||
|
for package in all_packages
|
||||||
|
if re.search(r'jdk|jre', package)]
|
||||||
|
return [package for package in packages if is_java(package)]
|
||||||
|
|
||||||
|
|
||||||
|
versions = [LooseVersion(package_version(package))
|
||||||
|
for package in java_packages()]
|
||||||
|
wanted_version = max(versions)
|
||||||
|
old_versions = [version for version in versions if version < wanted_version]
|
||||||
|
|
||||||
|
print('Too old:', old_versions)
|
13
connections-without-ipv6-privacy
Executable file
13
connections-without-ipv6-privacy
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# list all redhat/networkmanager connections without ipv6 privacy
|
||||||
|
set -e
|
||||||
|
cd /etc/sysconfig/network-scripts
|
||||||
|
for c in ifcfg-*; do
|
||||||
|
if [ "$c" == "ifcfg-lo" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -q IPV6_PRIVACY=rfc3041 $c; then
|
||||||
|
echo $c
|
||||||
|
fi
|
||||||
|
done
|
34
dbus-discover
Executable file
34
dbus-discover
Executable file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Discover DBUS session bus
|
||||||
|
# Source: can't remember where this from...
|
||||||
|
|
||||||
|
# Remember to run this script using the command "source ./filename.sh"
|
||||||
|
|
||||||
|
# Search these processes for the session variable
|
||||||
|
# (they are run as the current user and have the DBUS session variable set)
|
||||||
|
compatiblePrograms=( nautilus kdeinit kded4 pulseaudio trackerd )
|
||||||
|
|
||||||
|
# Attempt to get a program pid
|
||||||
|
for index in ${compatiblePrograms[@]}; do
|
||||||
|
PID=$(pidof -s ${index})
|
||||||
|
if [[ "${PID}" != "" ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ "${PID}" == "" ]]; then
|
||||||
|
echo "Could not detect active login session"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
|
||||||
|
if [[ "${QUERY_ENVIRON}" != "" ]]; then
|
||||||
|
export DBUS_SESSION_BUS_ADDRESS="${QUERY_ENVIRON}"
|
||||||
|
echo "Connected to session:"
|
||||||
|
echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
|
||||||
|
else
|
||||||
|
echo "Could not find dbus session ID in user environment."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Fix wrong "Flash outdated" error message by Firefox
|
# Fix wrong "Flash outdated" error message by Firefox
|
||||||
killall firefox
|
killall firefox
|
||||||
rm .mozilla/firefox/*.default/pluginreg.dat
|
rm .mozilla/firefox/*.default*/pluginreg.dat
|
||||||
firefox
|
firefox
|
||||||
|
|
12
gen-yum
12
gen-yum
|
@ -13,12 +13,16 @@ for base_dir in $BASE_DIRS; do
|
||||||
echo "== $YUM"
|
echo "== $YUM"
|
||||||
cd $YUM
|
cd $YUM
|
||||||
|
|
||||||
# Check for unsigned RPMs
|
# Fix permissions
|
||||||
unsigned=`rpm --checksig *.rpm | egrep -v ': .*pgp'` || true
|
chmod a+r *.rpm
|
||||||
|
chcon -t svirt_sandbox_file_t *.rpm
|
||||||
|
|
||||||
|
# Sign unsigned RPMs
|
||||||
|
unsigned=`rpm --checksig *.rpm | egrep -v ': .*pgp' | sed 's#:.*##'` || true
|
||||||
if [ ${#unsigned} != 0 ]; then
|
if [ ${#unsigned} != 0 ]; then
|
||||||
echo "Unsigned packages:"
|
echo "Unsigned packages:"
|
||||||
echo "$unsigned"
|
echo "$unsigned"
|
||||||
exit 1
|
rpmsign --addsign $unsigned
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create and sign repodata
|
# Create and sign repodata
|
||||||
|
@ -26,7 +30,7 @@ for base_dir in $BASE_DIRS; do
|
||||||
if [ ! -e repodata/repomd.xml.asc \
|
if [ ! -e repodata/repomd.xml.asc \
|
||||||
-o repodata/repomd.xml.asc -ot repodata/repomd.xml ]; then
|
-o repodata/repomd.xml.asc -ot repodata/repomd.xml ]; then
|
||||||
rm -f repodata/repomd.xml.asc
|
rm -f repodata/repomd.xml.asc
|
||||||
gpg -u $GPG_KEY --detach-sign --armor repodata/repomd.xml
|
gpg2 -u $GPG_KEY --detach-sign --armor repodata/repomd.xml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -15,6 +15,8 @@ import subprocess
|
||||||
|
|
||||||
def git_directories(startdir):
|
def git_directories(startdir):
|
||||||
for dirpath, dirnames, _ in os.walk(startdir):
|
for dirpath, dirnames, _ in os.walk(startdir):
|
||||||
|
if '.sync' in dirpath:
|
||||||
|
continue
|
||||||
if set(['info', 'objects', 'refs']).issubset(set(dirnames)):
|
if set(['info', 'objects', 'refs']).issubset(set(dirnames)):
|
||||||
yield dirpath
|
yield dirpath
|
||||||
|
|
||||||
|
|
19
libvirt-check-trim.py → libvirt-check-trim
Normal file → Executable file
19
libvirt-check-trim.py → libvirt-check-trim
Normal file → Executable file
|
@ -1,9 +1,13 @@
|
||||||
|
#!/usr/bin/python
|
||||||
# Check if all libvirt domains are prepared for TRIM/fstrim
|
# Check if all libvirt domains are prepared for TRIM/fstrim
|
||||||
|
# (for use on qcow2 images or thin provisioned volumes)
|
||||||
|
|
||||||
from __future__ import division, print_function
|
from __future__ import division, print_function
|
||||||
|
|
||||||
|
from distutils.version import LooseVersion
|
||||||
from lxml import objectify
|
from lxml import objectify
|
||||||
import libvirt
|
import libvirt
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,18 +16,27 @@ if not conn:
|
||||||
print('Failed to open connection to the hypervisor!')
|
print('Failed to open connection to the hypervisor!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not hasattr(conn, "listAllDomains"):
|
||||||
|
print('connection does not have listAllDomains(), is python-libvirt too old?')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
for domain in conn.listAllDomains():
|
for domain in conn.listAllDomains():
|
||||||
print('== {}'.format(domain.name()))
|
print('== {}'.format(domain.name()))
|
||||||
|
|
||||||
xml = domain.XMLDesc()
|
xml = domain.XMLDesc()
|
||||||
tree = objectify.fromstring(xml)
|
tree = objectify.fromstring(xml)
|
||||||
|
|
||||||
|
# machine type version should be >= 2.1 if i440fx
|
||||||
machine = tree.os.type.get('machine')
|
machine = tree.os.type.get('machine')
|
||||||
if machine < 'pc-i440fx-2.1':
|
matches = re.match('^pc-(?:i440fx-)?([0-9.]*)', machine)
|
||||||
print('machine should be at least pc-i440fx-2.1')
|
if matches:
|
||||||
# Might want to check qemu-system-x86_64 -M help for supported
|
i440_version = matches.group(1)
|
||||||
|
if LooseVersion(i440_version) < LooseVersion('2.1'):
|
||||||
|
print('machine type (version) should be at least pc-i440fx-2.1')
|
||||||
|
# Might want to check "qemu-system-x86_64 -M help" for supported
|
||||||
# machines.
|
# machines.
|
||||||
|
|
||||||
|
# no disks, no need to check
|
||||||
if not hasattr(tree.devices, 'disk'):
|
if not hasattr(tree.devices, 'disk'):
|
||||||
print('(has no disks)')
|
print('(has no disks)')
|
||||||
continue
|
continue
|
19
libvirt-restart-running
Executable file
19
libvirt-restart-running
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# Restart all running libvirt domains
|
||||||
|
|
||||||
|
from __future__ import division, print_function
|
||||||
|
|
||||||
|
import libvirt
|
||||||
|
import sys
|
||||||
|
|
||||||
|
conn = libvirt.open('qemu:///system')
|
||||||
|
if not conn:
|
||||||
|
print('Failed to open connection to the hypervisor!')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for domain in conn.listAllDomains():
|
||||||
|
name = domain.name()
|
||||||
|
if domain.isActive():
|
||||||
|
print('Restarting {}...'.format(name))
|
||||||
|
domain.destroyFlags(flags=libvirt.VIR_DOMAIN_DESTROY_GRACEFUL)
|
||||||
|
domain.create()
|
6
list-firefox-bookmarks
Executable file
6
list-firefox-bookmarks
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# List Firefox bookmarks
|
||||||
|
places=~/.mozilla/firefox/*default*/places.sqlite
|
||||||
|
|
||||||
|
# tags are parents with their parent = 4, so these have to be filtered
|
||||||
|
sqlite3 $places "select pl.url, b.title from moz_bookmarks as b join moz_bookmarks as pa on b.parent=pa.id join moz_places as pl on b.fk=pl.id where pa.parent != 4"
|
11
maildir-zero
11
maildir-zero
|
@ -67,8 +67,15 @@ else:
|
||||||
key = lambda i: i[0]
|
key = lambda i: i[0]
|
||||||
reverse = False
|
reverse = False
|
||||||
|
|
||||||
length_name = max(len(name) for name in counts.keys())
|
try:
|
||||||
length_count = max(len(str(count)) for count in counts.values())
|
length_name = max(len(name) for name in counts.keys())
|
||||||
|
except:
|
||||||
|
length_name = len('Total')
|
||||||
|
try:
|
||||||
|
length_count = max(len(str(count)) for count in counts.values())
|
||||||
|
except:
|
||||||
|
length_count = 3
|
||||||
|
|
||||||
for name, count in sorted(counts.items(), key=key, reverse=reverse):
|
for name, count in sorted(counts.items(), key=key, reverse=reverse):
|
||||||
print('{0:{1}}\t{2:{3}d}'.format(name, length_name, count, length_count))
|
print('{0:{1}}\t{2:{3}d}'.format(name, length_name, count, length_count))
|
||||||
|
|
||||||
|
|
8
saubermann-common
Executable file
8
saubermann-common
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# check for common problems + junk
|
||||||
|
|
||||||
|
echo "== Dangling symlinks in /etc"
|
||||||
|
symlinks -r /etc | grep ^dangling | egrep -v 'blkid.tab|/var/log/dropbear'
|
||||||
|
|
||||||
|
echo "== Trashes"
|
||||||
|
du -s /home/*/.local/share/Trash | awk '{ if ($1 > 100000) { print } }'
|
16
saubermann-dpkg
Executable file
16
saubermann-dpkg
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# check for things not installed via dpkg/apt and other junk
|
||||||
|
|
||||||
|
saubermann-common
|
||||||
|
|
||||||
|
echo "== Packages not in installed state"
|
||||||
|
dpkg -l | egrep -v "^(ii|Desired|\||\+)"
|
||||||
|
|
||||||
|
echo "== Orphan packages"
|
||||||
|
deborphan | egrep -v 'libc6-i686|lib.*-ruby$|opensync|gstreamer0.10-plugins.*|libtime-modules-perl|vpim|gnome-session-fallback|.*-globalmenu|gcalctool|clive|unity-scope'
|
||||||
|
|
||||||
|
echo "== *.dpkg in /etc"
|
||||||
|
find /etc -name "*.dpkg-*" -or -name "*.ucf-*"
|
||||||
|
|
||||||
|
echo "== Orphan packages according to aptitude"
|
||||||
|
aptitude search "~o"
|
28
saubermann-rpm
Executable file
28
saubermann-rpm
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# check for things not installed via RPM and other junk
|
||||||
|
|
||||||
|
saubermann-common
|
||||||
|
|
||||||
|
echo "== should be installed via RPM or pip install --user:"
|
||||||
|
for site_packages in /usr/lib/python2.7/site-packages/; do
|
||||||
|
rpm -qf $site_packages/*.egg-info 2>&1 | grep "not owned"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "== /usr/local"
|
||||||
|
find /usr/local/ -type f \
|
||||||
|
-and -not -name mimeinfo.cache \
|
||||||
|
-and -not -name defaults.list \
|
||||||
|
-print0 | xargs -0 rpm -qf 2>&1 | grep "not owned"
|
||||||
|
|
||||||
|
echo "== /usr/bin etc."
|
||||||
|
find /usr/bin /usr/sbin /usr/lib -type f \
|
||||||
|
\( \
|
||||||
|
-path '/usr/lib/modules/*/modules.*' -prune \
|
||||||
|
-or -path '*/__pycache__/*.py?' -prune \
|
||||||
|
-or -print0 \
|
||||||
|
\) | xargs -0 rpm -qf 2>&1 | grep "not owned"
|
||||||
|
|
||||||
|
echo "== *.rpmnew etc."
|
||||||
|
find /etc/ /usr/ \
|
||||||
|
-path '/usr/share/eclipse/dropins' -prune \
|
||||||
|
-or -name "*.rpm*" -and -not -name "*.rpm"
|
31
search-nulls
Executable file
31
search-nulls
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
"""Find files starting with null bytes"""
|
||||||
|
|
||||||
|
from __future__ import division, print_function
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='Find files starting with null bytes')
|
||||||
|
parser.add_argument(
|
||||||
|
'directories', metavar='dir', default=['.'], nargs='*',
|
||||||
|
type=str, help='directory to be searched')
|
||||||
|
parser.add_argument(
|
||||||
|
'-n', dest='nullbytes', default=16,
|
||||||
|
type=int, help='number of null bytes')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
for directory in args.directories:
|
||||||
|
for dirpath, _, filenames in os.walk(directory):
|
||||||
|
for filename in filenames:
|
||||||
|
filename = os.path.join(dirpath, filename)
|
||||||
|
|
||||||
|
if not os.path.isfile(filename):
|
||||||
|
continue
|
||||||
|
|
||||||
|
with open(filename, 'rb') as f:
|
||||||
|
firstbytes = f.read(args.nullbytes)
|
||||||
|
if firstbytes == b'\0'*args.nullbytes:
|
||||||
|
print(filename)
|
Loading…
Add table
Add a link
Reference in a new issue