#!/bin/sh # update-queue-password -- a script to update db password and config file # Copyright (C) 2008, Laurent Mazet # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ # Changelog: # - 0.1.2 # * read configuration file in /etc and in home directory # - 0.1.0 # * initial version # Potential bugs: ## constant values version=0.1.0 mycnf=$HOME/.my.cnf ## read configuration file [ -f /etc/${progname}rc ] && source /etc/${progname}rc [ -f $HOME/.${progname}rc ] && source $HOME/.${progname}rc ## variables : ${quser=queue} ## check user if [ $quser != "$(id -un)" ]; then echo "error: only $quser can update password" >&2 exit 1 fi ## check arguments progname=$(basename $0) case "$1" in -h|--help) ## help message echo "usage: $progname -h|--help $progname -v|--version $progname " exit 0 ;; -v|--version) ## show version echo "$progname version $version" >&2 exit 0 ;; *) if [ $# -ne 1 ]; then ## incorrect argument echo "usage: $progname -h" >&2 exit 1 fi password=$1 ;; esac # update password in databse echo -n "Connection to MySQL server as root. " mysql --no-defaults -u root -p -e \ "set password for '$quser'@'%' =password('$password');" || \ exit 1 echo "* Database password updated" # create configuration file for node autoconnection cat >$mycnf <