diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-06-05 12:48:12 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-06-05 12:48:12 +1200 |
commit | 384e86dcea4073485c8dd02dbc73eda0e4bb9144 (patch) | |
tree | a1e50906cfc3db395883a3d1ec3278cb7a3f0878 /scripts | |
parent | 0f52e3f3e38cb67f18a49474e1d036b2db08dac7 (diff) | |
download | liw-automation-384e86dcea4073485c8dd02dbc73eda0e4bb9144.tar.gz |
Move scripts to a subdirectory. Install everything in there.
This makes it harder to forget to update liw-automation.install
when a new script is added.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/build-journal | 6 | ||||
-rwxr-xr-x | scripts/g | 3 | ||||
-rwxr-xr-x | scripts/journal-note | 46 | ||||
-rwxr-xr-x | scripts/liw-vm-clone | 87 | ||||
-rwxr-xr-x | scripts/missing-journal-person-create | 28 | ||||
-rwxr-xr-x | scripts/missing-journal-tag-create | 20 | ||||
-rwxr-xr-x | scripts/sync-to-pieni | 21 | ||||
-rwxr-xr-x | scripts/world-dates | 27 |
8 files changed, 238 insertions, 0 deletions
diff --git a/scripts/build-journal b/scripts/build-journal new file mode 100644 index 0000000..cf12f3f --- /dev/null +++ b/scripts/build-journal @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e + +ikiwiki --setup $HOME/Journal/ikiwiki.setup + diff --git a/scripts/g b/scripts/g new file mode 100755 index 0000000..73a5f63 --- /dev/null +++ b/scripts/g @@ -0,0 +1,3 @@ +#!/bin/sh + +gedit --new-window "$@" diff --git a/scripts/journal-note b/scripts/journal-note new file mode 100755 index 0000000..f91a07b --- /dev/null +++ b/scripts/journal-note @@ -0,0 +1,46 @@ +#!/bin/sh + +set -e + +if [ "$#" != 1 ] +then + echo "Usage: $0 title" + exit 1 +fi + +title="$1" +temp="$(mktemp --tmpdir=$HOME/Journal)" + +cat << eof > "$temp" +[[!meta title="$title"]] +[[!tag ]] +[[!meta date="$(date +%Y-%m-%dT%H:%M)"]] + +eof + +checksum="$(mktemp)" +md5sum "$temp" > "$checksum" +vi "$temp" +if md5sum --status -c "$checksum" +then + echo "No change to note, aborting." + rm "$temp" "$checksum" + exit 1 +fi + +cat << eof >> "$temp" + +[[!meta done="$(date +%Y-%m-%dT%H:%M)"]] +eof + +cd "$HOME/Journal/src" +filename="notes/$(date +%Y-%m-%d-%H:%M.mdwn)" +if [ -e "$filename" ] +then + filename="notes/$(date +%Y-%m-%d-%H:%M:%S.mdwn)" +fi +cp "$temp" "$filename" +bzr add "$filename" +bzr commit -m "New note" "$filename" +ikiwiki --setup ../ikiwiki.setup --refresh +rm "$temp" "$checksum" diff --git a/scripts/liw-vm-clone b/scripts/liw-vm-clone new file mode 100755 index 0000000..fc5b40d --- /dev/null +++ b/scripts/liw-vm-clone @@ -0,0 +1,87 @@ +#!/bin/sh + +set -e + +die() +{ + printf -- "%s\n" "$*" 1>&2 + exit 1 +} + + +clone() +{ + local oldname="$1" + local newname="$2" + local img="$3" + + if [ -e "$img" ] + then + echo "Image file $img already exists. Skipping clone." + else + echo "Cloning $oldname to $newname" + virt-clone --connect qemu:///system -o "$oldname" -n "$newname" \ + -f "$img" + chmod 770 "$img" + fi +} + + +fixup() +{ + local oldname="$1" + local mountpt="$2" + + if grep -x -e "$oldname" "$mountpt/etc/hostname" > /dev/null + then + echo "fixing up /etc/hostname on $oldname" + sed -i "s/$oldname/$newname/g" "$mountpt/etc/hostname" + + echo "fixing up /etc/hosts on $oldname" + sed -i "s/$oldname/$newname/g" "$mountpt/etc/hosts" + + echo "removing udev's persistent net rule" + rm -f "$mountpt/etc/udev/rules.d/70-persistent-net.rules" + else + echo "EEEK! /etc/hostname does not match $oldname" + echo "Not touching this filesystem." + echo "/etc/hostname is:" + cat $mountpt/etc/hostname + fi +} + + +[ $# = 2 ] || die "Usage: $0 oldname newname" +oldname="$1" +newname="$2" +img="/srv/vm/$newname.img" + +clone "$oldname" "$newname" "$img" + +mountpt=$(mktemp -d) +tempfile=$(mktemp) +kpartx -av "$img" > "$tempfile" +sleep 2 # FIXME: for some reasons things are not immediate + +sed 's/.*(\(.*\)).*/\1/' "$tempfile" | +while read pair +do + dev="/dev/block/$pair" + if pvdisplay "$dev" > /dev/null 2>&1 + then + vg=$(pvdisplay "$dev" | awk '/^ VG Name/ { print $NF }') + vgchange -ay "$vg" > /dev/null + for lv in "/dev/$vg"/* + do + if mount "$lv" "$mountpt" 2> /dev/null && [ -e "$mountpt/etc" ] + then + fixup "$oldname" "$mountpt" + umount "$mountpt" + fi + done + vgchange -an "$vg" > /dev/null + fi +done +kpartx -d "$img" > /dev/null +rm -f "$tempfile" +rmdir "$mountpt" diff --git a/scripts/missing-journal-person-create b/scripts/missing-journal-person-create new file mode 100755 index 0000000..9468cfa --- /dev/null +++ b/scripts/missing-journal-person-create @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +open(INPUT, "<", "/srv/http/journal/index.html"); +while (<INPUT>) { + if (/^<li><span class="createlink">.*page=people%2F([^&]*).*\n$/) { + s//$1/; + my $basename = $_; + my @names = split /\./, $_; + my @Names = map ucfirst, @names; + my $family = shift @Names; + my $given = join ' ', @Names; + my $realname = "$family, $given"; + my $pathname = "/home/liw/Journal/src/people/$basename.mdwn"; + if (!-e $pathname) { + print "$realname\n"; + open(OUTPUT, ">", $pathname); + print OUTPUT "[[!meta title=\"$realname\"]]\n\n"; + print OUTPUT "[[!inline feeds=no "; + print OUTPUT "pages=\"notes/* and !notes/*/* and "; + print OUTPUT "link(people/$basename)\"]]\n"; + close(OUTPUT); + } + } +} + diff --git a/scripts/missing-journal-tag-create b/scripts/missing-journal-tag-create new file mode 100755 index 0000000..7e7d3d1 --- /dev/null +++ b/scripts/missing-journal-tag-create @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +open(INPUT, "<", "/srv/http/journal/index.html"); +while (<INPUT>) { + if (/^<li><span class="createlink">.*page=%2Ftag%2F([^&]*)&from=notes%2F.*\n$/) { + s//$1/; + my $tag = $_; + my $pathname = "/home/liw/Journal/src/tag/$tag.mdwn"; + if (!-e $pathname) { + print "$tag\n"; + open(OUTPUT, ">", $pathname); + print OUTPUT "[[!inline archive=yes pages=\"link(tag/$tag)\"]]\n"; + close(OUTPUT); + } + } +} + diff --git a/scripts/sync-to-pieni b/scripts/sync-to-pieni new file mode 100755 index 0000000..84facfa --- /dev/null +++ b/scripts/sync-to-pieni @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +for dir in $HOME/GTD $HOME/Journal/src $HOME/checklists $HOME/Templates +do + echo "$dir" + ( + set -e + cd "$dir" + if ! bzr diff > /dev/null + then + bzr commit --quiet -m 'commit from sync-to-pieni' + fi + bzr merge --pull + bzr push + ) + echo +done + + diff --git a/scripts/world-dates b/scripts/world-dates new file mode 100755 index 0000000..c6793e6 --- /dev/null +++ b/scripts/world-dates @@ -0,0 +1,27 @@ +#!/bin/sh + +timezones=" + US/Pacific + Europe/London + UTC + Europe/Helsinki + Asia/Tokyo + Australia/Brisbane + Pacific/Auckland + " + +w=0 +for tz in $timezones +do + len=$(echo -n $tz | wc -c) + if [ $len -gt $w ] + then + w=$len + fi +done + +for tz in $timezones +do + printf "%${w}s -- %s\n" $tz \ + "$(LC_ALL=C TZ=$tz date +'%a %Y-%m-%d %H:%M')" +done |