|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +version=0.10 |
| 4 | +program=${0##*/} |
| 5 | +progdir=${0%/*} |
| 6 | +if [ "$progdir" = "$program" ]; then progdir="."; fi |
| 7 | +if [ "$progdir" = "." ]; then progdir="$PWD"; fi |
| 8 | +parent=$(dirname $progdir) |
| 9 | +if [ "$parent" = "." ]; then parent="$PWD"; fi |
| 10 | + |
| 11 | +# ---------------------------------------------------------------------- |
| 12 | +function usage() { |
| 13 | + cat <<EOF |
| 14 | +NAME |
| 15 | + $program - Set up a local copy of the IETF database MySQL files |
| 16 | +
|
| 17 | +SYNOPSIS |
| 18 | + $program [OPTIONS] ARGS |
| 19 | +
|
| 20 | +DESCRIPTION |
| 21 | +
|
| 22 | + This script downloads a prebuilt copy of the IETF database MySQL |
| 23 | + files, ready for mapping into the /var/lib/mysql/ directory of the |
| 24 | + ietf/database-environment Docker image. |
| 25 | +
|
| 26 | +EOF |
| 27 | + echo -e "OPTIONS" |
| 28 | + if [ "$(uname)" = "Linux" ]; then |
| 29 | + egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | tr -s "\t|" "\t," | sed -r -e 's/\)[ \t]+([A-Z]+)=\$2[^#]*#/=\1\t/' -e 's/\)[^#]*#/\t/' |
| 30 | + else |
| 31 | + egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | sed 's/\|.*\$2[^#]*#/ /'| sed -E 's/\|.*\)[^#]*#/ /' |
| 32 | + fi |
| 33 | + cat <<EOF |
| 34 | +
|
| 35 | +FILES |
| 36 | +
|
| 37 | +AUTHOR |
| 38 | + Written by Henrik Levkowetz, <henrik@levkowetz.com> |
| 39 | +
|
| 40 | +COPYRIGHT |
| 41 | +
|
| 42 | + Copyright (c) 2015 IETF Trust and the persons identified as authors of |
| 43 | + the code. All rights reserved. License 'Simplified BSD', as specified |
| 44 | + in http://opensource.org/licenses/BSD-3-Clause. |
| 45 | + |
| 46 | +EOF |
| 47 | + |
| 48 | +} |
| 49 | + |
| 50 | +# ---------------------------------------------------------------------- |
| 51 | +function die() { |
| 52 | + echo -e "\n$program: error: $*" >&2 |
| 53 | + exit 1 |
| 54 | +} |
| 55 | + |
| 56 | +function note() { |
| 57 | + if [ -n "$VERBOSE" ]; then echo -e "$*"; fi |
| 58 | +} |
| 59 | + |
| 60 | +# ---------------------------------------------------------------------- |
| 61 | +function version() { |
| 62 | + echo -e "$program $version" |
| 63 | +} |
| 64 | + |
| 65 | +# ---------------------------------------------------------------------- |
| 66 | +trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR |
| 67 | + |
| 68 | + |
| 69 | +# ---------------------------------------------------------------------- |
| 70 | +# Option parsing |
| 71 | + |
| 72 | +# Options |
| 73 | +shortopts=hvV |
| 74 | +longopts=help,verbose,version |
| 75 | + |
| 76 | +if [ "$(uname)" = "Linux" ]; then |
| 77 | + args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@") |
| 78 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 79 | + eval set -- "$args" |
| 80 | + sed="sed -r" |
| 81 | +else |
| 82 | + # Darwin, BSDs |
| 83 | + args=$(getopt -o$shortopts $SV $*) |
| 84 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 85 | + set -- $args |
| 86 | + sed="sed -E" |
| 87 | +fi |
| 88 | + |
| 89 | +while true ; do |
| 90 | + case "$1" in |
| 91 | + -h| --help) usage; exit;; # Show this help, then exit |
| 92 | + -v| --verbose) VERBOSE=1;; # Be more talkative |
| 93 | + -V| --version) version; exit;; # Show program version, then exit |
| 94 | + --) shift; break;; |
| 95 | + *) die "Internal error, inconsistent option specification: '$1'";; |
| 96 | + esac |
| 97 | + shift |
| 98 | +done |
| 99 | + |
| 100 | +# ---------------------------------------------------------------------- |
| 101 | +# The program itself |
| 102 | + |
| 103 | +[ -n "$MYSQLDIR" ] || MYSQLDIR=$parent/data/mysql |
| 104 | +[ -n "$URL"] || URL=https://www.ietf.org/lib/dt/sprint/ietf_utf8.bin.tar.bz2 |
| 105 | + |
| 106 | +cd $(dirname $MYSQLDIR) |
| 107 | +wget -N $URL && tar xjf ietf_utf8.bin.tar.bz2 && chmod -R go+rwX mysql |
| 108 | + |
0 commit comments