From 08760f55d5782f852b1bdcbed093fea2b3cbcf67 Mon Sep 17 00:00:00 2001
From: Jacob Appelbaum <jacob@appelbaum.net>
Date: Thu, 24 Jul 2014 22:48:04 +0000
Subject: [PATCH] A simple mirror check script

---
 check_mirrors/README           |    6 +++
 check_mirrors/check_mirrors.sh |   91 ++++++++++++++++++++++++++++++++++++++++
 check_mirrors/mirror-list.txt  |   22 ++++++++++
 3 files changed, 119 insertions(+)
 create mode 100644 check_mirrors/README
 create mode 100755 check_mirrors/check_mirrors.sh
 create mode 100644 check_mirrors/mirror-list.txt

diff --git a/check_mirrors/README b/check_mirrors/README
new file mode 100644
index 0000000..feda4e5
--- /dev/null
+++ b/check_mirrors/README
@@ -0,0 +1,6 @@
+check_mirrors.sh is a small program to run in a cronjob
+
+mirror-list.txt is created by running the following command:
+
+  host dl.amnesia.boum.org|cut -d\  -f4 |sort|uniq >> mirror-list.txt
+ 
diff --git a/check_mirrors/check_mirrors.sh b/check_mirrors/check_mirrors.sh
new file mode 100755
index 0000000..bd142c6
--- /dev/null
+++ b/check_mirrors/check_mirrors.sh
@@ -0,0 +1,91 @@
+#!/bin/bash
+#
+# A quick and simple Tails mirror checking script
+#
+# Copyright 2014, Jacob Appelbaum <jacob@torproject.org>
+# This program is Free Software and is released under the same license as the
+# Tails project.
+#
+
+version="1.1";
+default_vhost="dl.amnesia.boum.org";
+
+mirror_list="`cat mirror-list.txt`"; # TOCTOU
+mirror_count="`wc -l mirror-list.txt | cut -f1 -d\  `"; # TOCTOU
+
+#Tails GnuPG signing key-id
+tails_key="0D24B36AA9A2A651787876451202821CBE2CD9C1";
+
+user_agent="Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0";
+
+default_path="/tails/stable/tails-i386-$version/";
+default_iso="tails-i386-$version.iso";
+default_sig="$default_iso.sig";
+
+# Make a temporary directory
+temp_dir=`mktemp -d /tmp/mirror_check_XXXXXX`;
+cd $temp_dir;
+
+if [ ! -d $temp_dir ]; then
+  echo "Unable to create $temp_dir";
+  exit 1;
+fi
+
+# Check if we have the Tails GnuPG signing key
+gpg --fingerprint $tails_key > /dev/null 2>&1;
+if [ $? == 2 ]; then
+  echo "Tails key-id $tails_key not found, fetch it please!";
+  echo "gpg --recv-key $tails_key;";
+  exit 2;
+fi
+
+echo;
+echo "Mirror health report for Tails version $version run on `date -R`.";
+echo "We are checking $mirror_count mirrors for Tails $version.";
+echo;
+
+# Fetch all files
+for mirror in $mirror_list
+do
+  echo;
+  iso="$mirror$default_path";
+  sig="$mirror$default_path$default_sig";
+
+  echo "Fetching Tails $version ISO from $mirror:";
+  curl --user-agent "$user_agent" -s -H "Host: $default_vhost" \
+       -o $mirror.iso $mirror$default_path$default_iso;
+  if [ $? != 0 ]; then
+    echo "curl for $iso on $mirror failed with error code: $?";
+    break;
+  fi
+  echo "$mirror.iso     file size: `ls -l $mirror.iso | cut -f5 -d\ `";
+  echo "$mirror.iso sha256sum: `sha256sum $mirror.iso | cut -f1 -d\ `";
+  echo;
+  echo "Fetching Tails GnuPG signature from $mirror:";
+  curl --user-agent "$user_agent" -s -H "Host: $default_vhost" \
+       -o $mirror.iso.sig $mirror$default_path$default_sig;
+  if [ $? != 0 ]; then
+    echo "curl for $sig on $mirror failed with error code: $?";
+    break;
+  fi
+
+  echo "$mirror.iso.sig file size: `ls -l $mirror.iso | cut -f5 -d\ `";
+  echo "$mirror.iso.sig sha256sum: `sha256sum $mirror.iso.sig | cut -f1 -d\ `";
+  
+  echo;
+  echo "gpg --verify $mirror.iso.sig $mirror.iso reports:";
+  gpg --verify $mirror.iso.sig $mirror.iso;
+  echo;
+done
+
+echo;
+cd /tmp;
+if [ -d $temp_dir ]; then
+  echo "Mirror files are stored in $temp_dir";
+  echo "Clean up the system like so:";
+  echo "rm -r $temp_dir";
+  echo;
+fi
+echo;
+
+exit 0;
diff --git a/check_mirrors/mirror-list.txt b/check_mirrors/mirror-list.txt
new file mode 100644
index 0000000..cf2d354
--- /dev/null
+++ b/check_mirrors/mirror-list.txt
@@ -0,0 +1,22 @@
+83.212.104.246
+85.214.248.55
+86.59.119.84
+93.95.226.146
+95.141.34.162
+158.36.190.173
+176.9.38.37
+176.9.53.178
+176.31.122.216
+178.33.253.203
+185.10.49.203
+192.42.116.116
+192.99.131.144
+198.199.103.96
+212.192.64.234
+5.135.162.176
+62.133.199.171
+62.201.161.88
+69.164.206.15
+77.70.69.9
+78.47.150.61
+80.90.43.162
-- 
1.7.10.4

