Tim Landscheidt has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/340009 )
Change subject: Import sql from operations/puppet ...................................................................... Import sql from operations/puppet As this change introduces a difference in the binary packages, it adds the suffix "~precise+1" to the upstream version. Change-Id: I159b49371a995ca32e1d37bc69d17308d10d8164 --- M debian/changelog M debian/control M debian/misctools.install M misctools/Makefile.am A misctools/sql 5 files changed, 126 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs refs/changes/09/340009/1 diff --git a/debian/changelog b/debian/changelog index 379ff65..79d7aaa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,12 +1,13 @@ -toollabs (1.19~dev) precise; urgency=medium +toollabs (1.19~precise+1~dev) precise; urgency=medium * Remove toolwatcher * Do not hardcore database hosts in list-user-databases * State dependency on python * Set target distribution to Ubuntu Trusty * Set target distribution for branch ubuntu/precise to Ubuntu Precise + * Import sql from operations/puppet - -- Tim Landscheidt <t...@tim-landscheidt.de> Sun, 26 Feb 2017 02:49:21 +0000 + -- Tim Landscheidt <t...@tim-landscheidt.de> Sun, 26 Feb 2017 21:27:04 +0000 toollabs (1.18) unstable; urgency=medium diff --git a/debian/control b/debian/control index ee2e5c8..fa8b889 100644 --- a/debian/control +++ b/debian/control @@ -15,7 +15,7 @@ Package: misctools Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, ${python:Depends}, - python, python-mysql.connector + mysql-client-core-5.5, python, python-mysql.connector Description: Miscellaneous Labs-specific tools Miscellaneous Labs-specific Tools used on Tool Labs diff --git a/debian/misctools.install b/debian/misctools.install index 8480b2b..924a3f9 100644 --- a/debian/misctools.install +++ b/debian/misctools.install @@ -1,4 +1,5 @@ usr/bin/become usr/bin/list-user-databases +usr/bin/sql usr/bin/take usr/bin/setup-tomcat diff --git a/misctools/Makefile.am b/misctools/Makefile.am index 4d2ee2b..1d9c38a 100644 --- a/misctools/Makefile.am +++ b/misctools/Makefile.am @@ -1,2 +1,2 @@ man_MANS = become.1 list-user-databases.1 -bin_SCRIPTS = become list-user-databases setup-tomcat +bin_SCRIPTS = become list-user-databases setup-tomcat sql diff --git a/misctools/sql b/misctools/sql new file mode 100755 index 0000000..65f5314 --- /dev/null +++ b/misctools/sql @@ -0,0 +1,120 @@ +#!/bin/bash + +# this tool allow you to connect quickly to sql database +# it should work for all newbies + +verbose=0 + +function Log { +if [ $verbose -eq 1 ];then + echo "$1" +fi +} + +if [ $# -lt 1 ];then + echo "Usage: \"sql <database name|wiki name> [-vh]\" type sql --help for more help" + exit 0 +fi + +if [ "$1" = "-h" ] || [ "$1" == "--help" ];then + echo "Usage: sql <database>[_p] [-vh] [command(s)]" + echo + echo "This tool allows you to easily open a connection to sql database without having to provide the credentials or a database host server" + echo "Example: sql frwiki_p" + echo + echo "Parameters:" + echo " -v: verbose - produce various information about the resolution of db" + echo + echo "Report bugs to phabricator: https://phabricator.wikimedia.org" + exit 0 +fi + +for i +do + if [ "$i" = "-v" ] || [ "$i" = "--verbose" ] + then + verbose=1 + fi +done + +if [ ! -f ~/replica.my.cnf ] && [ ! -f ~/.my.cnf ] +then + Log "WARNING: There is no configuration file for mysql to use, you will probably be unable to access the database" +fi + +param="" +# check if the user has a replica file +if [ -f ~/replica.my.cnf ];then + param=" --defaults-file=~/replica.my.cnf" +else + if [ ! -f ~/.my.cnf ];then + param=" -p" + fi +fi + +server="enwiki.labsdb" +db="enwiki_p" + +case "$1" in + "en" | "enwiki" | "enwiki_p") + server="enwiki.labsdb" + db="enwiki_p" + ;; + "de" | "dewiki" | "dewiki_p") + server="dewiki.labsdb" + db="dewiki_p" + ;; + "fr" | "frwiki" | "frwiki_p") + server="frwiki.labsdb" + db="frwiki_p" + ;; + "cs" | "cswiki" | "cswiki_p") + server="cswiki.labsdb" + db="cswiki_p" + ;; + "commons" | "commonswiki" | "commonswiki_p") + server="commonswiki.labsdb" + db="commonswiki_p" + ;; + "wikidata" | "wikidatawiki" | "wikidatawiki_p") + server="wikidatawiki.labsdb" + db="wikidatawiki_p" + ;; + "meta" | "meta_p") + # Not to confuse with metawiki[_p] + # https://wikitech.wikimedia.org/wiki/Nova_Resource:Tools/Help#Metadata_database + server="s7.labsdb" + db="meta_p" + ;; + "local") + server=tools-db + db="" + if [ -f ~/.my.cnf ];then + param="" + fi + ;; + *) + # we don't know what the database is so we check if it exist first + Log "This database name is not known by sql script, fallback to dblist resolution" + db="${1%_p}_p" + server="${db%_p}.labsdb" + if getent hosts -- "$server" > /dev/null + then + Log "Resolved to $server $db" + else + echo "Could not find requested database" + if [ "$db" != "$1" ]; then + echo 'Make sure to ask for a db in format of <wiki>_p' + fi + exit 1 + fi + ;; +esac + +shift +Log "Connecting to $server" +if [ $# -lt 1 ]; then + exec mysql $param -h $server $db "$@" +else + echo "$@" | mysql $param -h $server $db +fi -- To view, visit https://gerrit.wikimedia.org/r/340009 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I159b49371a995ca32e1d37bc69d17308d10d8164 Gerrit-PatchSet: 1 Gerrit-Project: labs/toollabs Gerrit-Branch: ubuntu/precise Gerrit-Owner: Tim Landscheidt <t...@tim-landscheidt.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits