Verified Commit 01adbec6 authored by Felix Eckhofer's avatar Felix Eckhofer 🤹🏼
Browse files

Merge branch 'master' into deploy

* master: (24 commits)
  Fix whitespaces
  Ignore some errors on user input
  Add english.dic
  Fix script on ubuntu pre-xenial
  Use updated paths for xenial
  Add note about updating initramfs and grub
  Make output more readable
  Also update ubuntu-text theme just in case
  Add paint-it-black.sh
  Add simple README for randomize-mac
  Automatically use all network interfaces
  Finish lines with a dot
  Move randomize-mac out of scripts directory
  Add warning about potentially re-used mac address
  Log to syslog instead of mail
  Only check for interface state when it exists
  Don't run if the interface has vanished
  Add a note about the scripts directory
  Add randomize-mac
  add missing +x bit
  ...
parents 1d985ba5 1f9f6a64
...@@ -19,6 +19,10 @@ A repository of tools I wrote at some point but aren't deemed worthy of their ow ...@@ -19,6 +19,10 @@ A repository of tools I wrote at some point but aren't deemed worthy of their ow
Currently no online demo, sorry. Currently no online demo, sorry.
* **scripts**
A collection of scripts i consider useful enough to the general public.
[![Flattr this](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=dxbi&url=https://github.com/tribut/tools&title=tribut/tools%20on%20GitHub&description=Some%20tools%20I%20wrote%20over%20the%20years%20and%20that%20don%27t%20deserve%20a%20repository%20of%20their%20own&tags=github,repository&category=software) [![Flattr this](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=dxbi&url=https://github.com/tribut/tools&title=tribut/tools%20on%20GitHub&description=Some%20tools%20I%20wrote%20over%20the%20years%20and%20that%20don%27t%20deserve%20a%20repository%20of%20their%20own&tags=github,repository&category=software)
## Legal ## Legal
......
...@@ -11,6 +11,10 @@ Im Unterverzeichnis `data` sind die entsprechenden Rohdaten. ...@@ -11,6 +11,10 @@ Im Unterverzeichnis `data` sind die entsprechenden Rohdaten.
[Wikipedia](http://de.wikipedia.org/wiki/Liste_der_Kfz-Kennzeichen_in_Deutschland) ([CC BY-SA](http://creativecommons.org/licenses/by-sa/3.0/)) [Wikipedia](http://de.wikipedia.org/wiki/Liste_der_Kfz-Kennzeichen_in_Deutschland) ([CC BY-SA](http://creativecommons.org/licenses/by-sa/3.0/))
* **english** Englische Wörter
[TU Chemnitz](http://dict.tu-chemnitz.de/doc/faq.en.html#download) ([GPLv2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html))
* **gemeinden** Deutsche politisch selbständige Gemeinden * **gemeinden** Deutsche politisch selbständige Gemeinden
[Statistisches Bundesamt](https://www.destatis.de/DE/ZahlenFakten/LaenderRegionen/Regionales/Gemeindeverzeichnis/Administrativ/AdministrativeUebersicht.html) *("Vervielfältigung und Verbreitung, auch auszugsweise, mit Quellenangabe gestattet.")* [Statistisches Bundesamt](https://www.destatis.de/DE/ZahlenFakten/LaenderRegionen/Regionales/Gemeindeverzeichnis/Administrativ/AdministrativeUebersicht.html) *("Vervielfältigung und Verbreitung, auch auszugsweise, mit Quellenangabe gestattet.")*
......
#!/bin/sh
curl -f -s http://ftp.tu-chemnitz.de/pub/Local/urz/ding/de-en/de-en.txt.gz |
gzip -d | # uncompress
sed -r 's#.*:: ##; # delete german
/^#.*/d; # delete comments
s/ ?[;|] ?/\
/g; # split alternative forms into seperate lines
s# ?[([{].*##; # delete annotations and metadata
/ [^ ]/d; # delete composite phrases
/\.\.\.$/d; # delete word-parts
s# $##; # delete trailing white space
' |
tr 'a-zöäü' 'A-ZÖÄÜ' |
sort -u
...@@ -25,6 +25,7 @@ $dictfiles = array( // wörterbuchdateien ...@@ -25,6 +25,7 @@ $dictfiles = array( // wörterbuchdateien
"Deutsche Wörter" => "german.dic", "Deutsche Wörter" => "german.dic",
"Deutsche Städte" => "staedte.dic", "Deutsche Städte" => "staedte.dic",
"Deutsche Städte und Gemeinden" => "gemeinden.dic", "Deutsche Städte und Gemeinden" => "gemeinden.dic",
"Englische Wörter" => "english.dic",
"KFZ-Kennzeichen Deutschland" => "kfz.dic", "KFZ-Kennzeichen Deutschland" => "kfz.dic",
"Automarken" => "autos.dic", "Automarken" => "autos.dic",
"Tiere" => "tiere.dic" "Tiere" => "tiere.dic"
...@@ -68,7 +69,7 @@ if (isset($_REQUEST['width_min'])) { ...@@ -68,7 +69,7 @@ if (isset($_REQUEST['width_min'])) {
if ($user_width_min < $max_width && $user_width_min >= $min_width) { if ($user_width_min < $max_width && $user_width_min >= $min_width) {
$width_min = $user_width_min; $width_min = $user_width_min;
} }
if ($width_min >= $width) { if (@$width_min >= $width) {
$width = $width_min + 1; $width = $width_min + 1;
} }
} }
...@@ -145,7 +146,7 @@ if ($width_mode == 1) { // "zwischen" ...@@ -145,7 +146,7 @@ if ($width_mode == 1) { // "zwischen"
<select name="width_min" onchange="javascript:document.forms[0].submit()"> <select name="width_min" onchange="javascript:document.forms[0].submit()">
<?php <?php
for ($i = $min_width; $i <= $max_width; $i++) { for ($i = $min_width; $i <= $max_width; $i++) {
echo '<option value="'.$i.'" '.($width_min==$i?'selected':'').'>'.$i.'</option>'; echo '<option value="'.$i.'" '.(@$width_min==$i?'selected':'').'>'.$i.'</option>';
} }
?> ?>
</select> </select>
...@@ -185,7 +186,7 @@ foreach ($dictfiles as $name => $file) { ...@@ -185,7 +186,7 @@ foreach ($dictfiles as $name => $file) {
<form method="post" action="<?php echo str_replace('"', '', $_SERVER['REQUEST_URI']); ?>#result"> <form method="post" action="<?php echo str_replace('"', '', $_SERVER['REQUEST_URI']); ?>#result">
<input type="hidden" name="width" value="<?php echo $width; ?>"> <input type="hidden" name="width" value="<?php echo $width; ?>">
<input type="hidden" name="width_min" value="<?php echo $width_min; ?>"> <input type="hidden" name="width_min" value="<?php echo @$width_min; ?>">
<input type="hidden" name="width_mode" value="<?php echo $width_mode; ?>"> <input type="hidden" name="width_mode" value="<?php echo $width_mode; ?>">
<input type="hidden" name="dict" value="<?php echo $dict; ?>"> <input type="hidden" name="dict" value="<?php echo $dict; ?>">
...@@ -197,7 +198,7 @@ foreach ($dictfiles as $name => $file) { ...@@ -197,7 +198,7 @@ foreach ($dictfiles as $name => $file) {
$field = 0; $field = 0;
for ($i = 0; $i < $width; $i++) { for ($i = 0; $i < $width; $i++) {
$formfield = 'preset' . $i; $formfield = 'preset' . $i;
$fielddata = str_replace('"', '', $_REQUEST[$formfield]); @$fielddata = str_replace('"', '', $_REQUEST[$formfield]);
echo '<input id="field'.++$field.'" onKeyUp="advance('.$field.','.($field+1).')" type="text" name="' . $formfield . '" size="5" maxlength="1" value="'.(isset($_REQUEST['reset'])?'':$fielddata).'" >'; echo '<input id="field'.++$field.'" onKeyUp="advance('.$field.','.($field+1).')" type="text" name="' . $formfield . '" size="5" maxlength="1" value="'.(isset($_REQUEST['reset'])?'':$fielddata).'" >';
} }
...@@ -213,7 +214,7 @@ echo "<br>\n"; ...@@ -213,7 +214,7 @@ echo "<br>\n";
for ($i = 0; $i < $height; $i++) { for ($i = 0; $i < $height; $i++) {
for ($j = 0; $j < $width; $j++) { for ($j = 0; $j < $width; $j++) {
$formfield = 'value' . $i . $j; $formfield = 'value' . $i . $j;
$fielddata = str_replace('"', '', $_REQUEST[$formfield]); @$fielddata = str_replace('"', '', $_REQUEST[$formfield]);
echo '<input id="field'.++$field.'" onKeyUp="advance('.$field.','.($field+1).')" type="text" name="' . $formfield . '" size="5" maxlength="1" value="'.(isset($_REQUEST['reset'])?'':$fielddata).'" >'; echo '<input id="field'.++$field.'" onKeyUp="advance('.$field.','.($field+1).')" type="text" name="' . $formfield . '" size="5" maxlength="1" value="'.(isset($_REQUEST['reset'])?'':$fielddata).'" >';
} }
...@@ -226,7 +227,7 @@ for ($i = 0; $i < $height; $i++) { ...@@ -226,7 +227,7 @@ for ($i = 0; $i < $height; $i++) {
<legend>Zulässige Buchstaben</legend> <legend>Zulässige Buchstaben</legend>
<p>Wenn das Feld ausgefüllt wird, werden nur Worte gesucht, die sich aus den <em>Buchstaben der Eingabe bilden lassen</em>.</p> <p>Wenn das Feld ausgefüllt wird, werden nur Worte gesucht, die sich aus den <em>Buchstaben der Eingabe bilden lassen</em>.</p>
<p>Wird hier also zum Beipiel "Brocken" eingegeben, lässt sich daraus BOCK bilden, nicht aber ECKE oder BRATEN).</p> <p>Wird hier also zum Beipiel "Brocken" eingegeben, lässt sich daraus BOCK bilden, nicht aber ECKE oder BRATEN).</p>
<input type="text" name="buildfrom" size="20" value="<?php echo str_replace('"','',$_REQUEST['buildfrom']) ?>"> <input type="text" name="buildfrom" size="20" value="<?php echo @str_replace('"','',$_REQUEST['buildfrom']) ?>">
</fieldset> </fieldset>
<input name="go" type="submit" value="Anzeigen"> <input name="go" type="submit" value="Anzeigen">
...@@ -326,4 +327,3 @@ echo '</tt></div>'; ...@@ -326,4 +327,3 @@ echo '</tt></div>';
</body> </body>
</html> </html>
# Randomize MAC automatically on Ubuntu systems
This directory contains
* **if-post-down.d/randomize-mac** a shell script to randomize an interface's mac address using macchanger, possibly shutting down the interface first (for wifi cards that generally are up for scanning) while logging the result to syslog. This script is compatible with NetworkMangager's post-down hook.
* **init/randomize-mac.conf** an upstart job to randomize the MAC address of all interfaces on system startup using said script
Please see the comments in the respective files for more information.
#!/bin/sh
# temporarily shut down an interface and randomize the mac,
# requires the macchanger tool.
#
# place in /etc/network/if-post-down.d to renew the mac everytime
# a network interface is brought down (recent versions of
# NetworkManager no longer support if-pre-up.d)
#
# Note that this will fail for wifi if you immediately connect
# to another network instead of explicitly disconnecting from the
# current one. In this case the MAC set before network-manager
# started might be re-used (see init/randomize-mac.conf)!
#
# felix@tribut.de
LOGFILE="`mktemp`"
IFSTATE="`ip addr show dev \"$IFACE\" 2>>\"$LOGFILE\"`"
if [ -n "$IFSTATE" ]; then
FAILED="0"
PRESTATE="`ip addr show dev \"$IFACE\" up 2>>\"$LOGFILE\"`"
[ -n "$PRESTATE" ] && ip link set dev "$IFACE" down >>"$LOGFILE" 2>&1
macchanger -A "$IFACE" >>"$LOGFILE" 2>&1 || FAILED=1
[ -n "$PRESTATE" ] && ip link set dev "$IFACE" up >>"$LOGFILE" 2>&1
if [ "$FAILED" = "1" ]; then
echo "ERROR while trying to randomize MAC for $IFACE" | cat - "$LOGFILE" | logger -t randomize-mac -p user.err
else
echo "MAC successfully randomized for $IFACE" | logger -t randomize-mac -p user.notice
fi
else
echo "Interface $IFACE does not exist, skipping..." | logger -t randomize-mac -p user.info
fi
rm -f "$LOGFILE"
# upstart script to run randomize-mac for a list of interfaces.
# place in /etc/init.
# felix@tribut.de
description "Randomize MAC address on boot"
start on starting network-manager
pre-start script
export IFACE
for IFACE in `ls -1 /sys/class/net | grep -v ^lo$`; do
/etc/network/if-post-down.d/randomize-mac
done
end script
#!/bin/bash
# ################################################# #
# duply-do-backup #
# #
# this script is meant to be called from cron and #
# first starts a backup and then a purge using #
# duply. it will not generate any output if all #
# works smoothly. if anything goes wrong, the #
# full log is displayed. #
# felix@eckhofer.com #
# ################################################# #
LOGFILE="`mktemp`"
PROFILE="$1"
PROFILEPATH="/etc/duply/$PROFILE"
export RSYNC_RSH='ssh -oBatchMode=yes -oLogLevel=Error' # avoid printing ssh banner
function exit_error() {
[ -z "$@" ] || echo "$@"
rm -f "$LOGFILE"
exit 1
}
if [ -z "$PROFILE" ]; then
exit_error "usage: `basename $0` backup-profile"
fi
if [ ! -d "$PROFILEPATH" ]; then
exit_error "profile not found."
fi
echo "### Backing up ###" >> "$LOGFILE"
if ! duply "$PROFILE" backup >> "$LOGFILE"
then
cat "$LOGFILE"
exit_error
fi
echo "### Cleaning up ###" >> "$LOGFILE"
if ! duply "$PROFILE" purge-full --force >> "$LOGFILE"
then
cat "$LOGFILE"
exit_error
fi
rm "$LOGFILE"
#!/bin/sh
# convert sha1 oder sha256 certificate fingerprint in hex
# to format used by chrome://net-internals for pinning
# -- felix@tribut.de
digest="$@"
[ -z "$digest" ] && read digest
stripped="`echo -n \"$digest\" | tr -d ': \n'`"
length="`echo -n $stripped | wc -c`"
case "$length" in
40)
type="sha1"
;;
64)
type="sha256"
;;
*)
echo "Length of digest doesn't match with any supported digest (given: $length)." >&2
echo "Please call me with hex digest as parameter or piped via stdin." >&2
exit 1
;;
esac
echo "$type/`echo \"$digest\" | xxd -r -p | base64`"
#!/bin/sh
# set the background color in the default ubuntu bootsplash and grub
# themes to black. i like a lot of things about the default ubuntu look
# and feel but that weird purple certainly is not among those.
# -- felix@tribut.de
notice() {
echo "$@" >&2
}
sedfilter() {
SOURCE="$1"
FILTER="$2"
[ -w "$SOURCE" ] || { notice "$SOURCE not writeable"; return 1; }
TEMPFILE="`mktemp`"
cp "$SOURCE" "$TEMPFILE" && sed -r "$FILTER" < "$TEMPFILE" > "$SOURCE"
RETCODE="$?"
if [ 0 -eq "$RETCODE" ]; then
notice "$SOURCE: done, the changes are as follows:"
diff -u "$TEMPFILE" "$SOURCE" >&2
fi
rm -f "$TEMPFILE"
return "$RETCODE"
}
THEMEDIR="/usr/share/plymouth/themes" # xenial and up
[ -f "$THEMEDIR/ubuntu-logo/ubuntu-logo.grub" ] || THEMEDIR="/lib/plymouth/themes" # until wily
sedfilter \
"$THEMEDIR/ubuntu-logo/ubuntu-logo.grub" \
's/background_color [0-9]+,[0-9]+,[0-9]+/background_color 0,0,0/'
sedfilter \
"$THEMEDIR/ubuntu-logo/ubuntu-logo.script" \
's/^(Window.SetBackground(Top|Bottom)Color ?)\(0\.[0-9]{1,2}, 0\.[0-9]{1,2}, 0\.[0-9]{1,2}\)/\1(0.00, 0.00, 0.00)/'
sedfilter \
"$THEMEDIR/ubuntu-text/ubuntu-text.plymouth" \
's/^black=0x[a-fA-F0-9]{6}/black=0x000000/'
notice "You may want to run 'update-initramfs -u -k all && update-grub' now :)"
#!/usr/bin/perl
# add timestamp to stdin (for long-running commands or with tail), e.g.
# tail -f logfile | timestamp.pl
use POSIX qw(strftime);
while (<>) {
my $date = strftime "[%Y-%m-%d %H:%M:%S]", localtime;
print "$date $_";
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment