|
| 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 | +export LANG=C |
| 12 | + |
| 13 | +# ---------------------------------------------------------------------- |
| 14 | +function usage() { |
| 15 | + cat <<EOF |
| 16 | +NAME |
| 17 | + $program - Make a tarball of the MySQL database files and upload it. |
| 18 | +
|
| 19 | +SYNOPSIS |
| 20 | + $program [OPTIONS] |
| 21 | +
|
| 22 | +DESCRIPTION |
| 23 | +
|
| 24 | + This script creates a compressed tarball from the MySQL database files |
| 25 | + on disk, and uploads it to the ietf datatracker developer area on |
| 26 | + www.ietf.org. |
| 27 | +
|
| 28 | + It is intended to be used with the docker datatracker environment, after |
| 29 | + you have set up the database with docker/setupdb, started the docker |
| 30 | + image with docker/run, and updated the database with docker/updatedb. |
| 31 | +
|
| 32 | + To use it, exit from the docker container, to make sure that mysqldb |
| 33 | + isn't running and all the files consistent and available for copy. Then |
| 34 | + run docker/$program outside the docker container. You need to have ssh |
| 35 | + access to www.ietf.org in order for the scp command to succeed. |
| 36 | +
|
| 37 | +EOF |
| 38 | + echo -e "OPTIONS" |
| 39 | + if [ "$(uname)" = "Linux" ]; then |
| 40 | + 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/' |
| 41 | + else |
| 42 | + egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | sed 's/\|.*\$2[^#]*#/ /'| sed -E 's/\|.*\)[^#]*#/ /' |
| 43 | + fi |
| 44 | + cat <<EOF |
| 45 | +
|
| 46 | +FILES |
| 47 | +
|
| 48 | +AUTHOR |
| 49 | + Written by Henrik Levkowetz, <henrik@levkowetz.com> |
| 50 | +
|
| 51 | +COPYRIGHT |
| 52 | +
|
| 53 | + Copyright (c) 2016 IETF Trust and the persons identified as authors of |
| 54 | + the code. All rights reserved. License 'Simplified BSD', as specified |
| 55 | + in http://opensource.org/licenses/BSD-3-Clause. |
| 56 | + |
| 57 | +EOF |
| 58 | + |
| 59 | +} |
| 60 | + |
| 61 | +# ---------------------------------------------------------------------- |
| 62 | +function die() { |
| 63 | + echo -e "\n$program: error: $*" >&2 |
| 64 | + exit 1 |
| 65 | +} |
| 66 | + |
| 67 | +function note() { |
| 68 | + if [ -n "$VERBOSE" ]; then echo -e "$*"; fi |
| 69 | +} |
| 70 | + |
| 71 | +# ---------------------------------------------------------------------- |
| 72 | +function version() { |
| 73 | + echo -e "$program $version" |
| 74 | +} |
| 75 | + |
| 76 | +# ---------------------------------------------------------------------- |
| 77 | +trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR |
| 78 | + |
| 79 | + |
| 80 | +# ---------------------------------------------------------------------- |
| 81 | +# Option parsing |
| 82 | + |
| 83 | +# Options |
| 84 | +shortopts=hvV |
| 85 | +longopts=help,verbose,version |
| 86 | + |
| 87 | +# Default values |
| 88 | + |
| 89 | +if [ "$(uname)" = "Linux" ]; then |
| 90 | + args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@") |
| 91 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 92 | + eval set -- "$args" |
| 93 | + sed="sed -r" |
| 94 | +else |
| 95 | + # Darwin, BSDs |
| 96 | + args=$(getopt -o$shortopts $SV $*) |
| 97 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 98 | + set -- $args |
| 99 | + sed="sed -E" |
| 100 | +fi |
| 101 | + |
| 102 | +while true ; do |
| 103 | + case "$1" in |
| 104 | + -h| --help) usage; exit;; # Show this help, then exit |
| 105 | + -v| --verbose) VERBOSE=1;; # Be more talkative |
| 106 | + -V| --version) version; exit;; # Show program version, then exit |
| 107 | + --) shift; break;; |
| 108 | + *) die "Internal error, inconsistent option specification: '$1'";; |
| 109 | + esac |
| 110 | + shift |
| 111 | +done |
| 112 | + |
| 113 | +# ---------------------------------------------------------------------- |
| 114 | +# The program itself |
| 115 | + |
| 116 | +if [ -e "/.dockerenv" -o -n "$(grep '/docker/' /proc/self/cgroup)" ]; then |
| 117 | + die "It looks as if you're running inside docker -- please quit docker first." |
| 118 | +fi |
| 119 | + |
| 120 | +cd $progdir/../data/ \ |
| 121 | + && note "Building tarfile ..." \ |
| 122 | + && tar cjf ietf_utf8.bin.tar.bz2 mysql \ |
| 123 | + && note "Copying tarfile to ietfa.amsl.com ..." \ |
| 124 | + && scp ietf_utf8.bin.tar.bz2 ietfa.amsl.com:/a/www/www6s/lib/dt/sprint/ |
0 commit comments