/usr/share/kea-admin/scripts/admin-utils.sh is in kea-admin 1.0.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | # Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# This is an utility script that is being included by other scripts.
# There are two ways of calling this method.
# mysql_execute SQL_QUERY - This call is simpler, but requires db_user,
# db_password and db_name variables to be set.
# mysql_execute SQL_QUERY PARAM1 PARAM2 .. PARAMN - Additional parameters
# may be specified. They are passed directly to mysql. This one is
# more convenient to use if the script didn't parse db_user db_password
# and db_name.
#
# It returns the mysql command exit status to the caller as $?
mysql_execute() {
QUERY=$1
shift
if [ $# -gt 1 ]; then
mysql -N -B $* -e "${QUERY}"
retcode=$?
else
mysql -N -B --user=$db_user --password=$db_password -e "${QUERY}" $db_name
retcode="$?"
fi
return $retcode
}
mysql_version() {
mysql_execute "SELECT CONCAT(version,\".\",minor) FROM schema_version" "$@"
return $?
}
# Submits given SQL text to PostgreSQL
# There are two ways of calling this method.
# pgsql_execute SQL_QUERY - This call is simpler, but requires db_user,
# db_password and db_name variables to be set.
# pgsql_execute SQL_QUERY PARAM1 PARAM2 .. PARAMN - Additional parameters
# may be specified. They are passed directly to pgsql. This one is
# more convenient to use if the script didn't parse db_user db_password
# and db_name.
#
# It returns the pgsql command exit status to the caller as $?
pgsql_execute() {
QUERY=$1
shift
if [ $# -gt 0 ]; then
echo $QUERY | psql --set ON_ERROR_STOP=1 -A -t -q $*
retcode=$?
else
export PGPASSWORD=$db_password
echo $QUERY | psql --set ON_ERROR_STOP=1 -A -t -q -U $db_user -d $db_name
retcode=$?
fi
return $retcode
}
# Submits SQL in a given file to PostgreSQL
# There are two ways of calling this method.
# pgsql_execute SQL_FILE - This call is simpler, but requires db_user,
# db_password and db_name variables to be set.
# pgsql_execute SQL_FILE PARAM1 PARAM2 .. PARAMN - Additional parameters
# may be specified. They are passed directly to pgsql. This one is
# more convenient to use if the script didn't parse db_user db_password
# and db_name.
#
# It returns the pgsql command exit status to the caller as $?
pgsql_execute_script() {
file=$1
shift
if [ $# -gt 0 ]; then
psql --set ON_ERROR_STOP=1 -A -t -q -f $file $*
retcode=$?
else
export PGPASSWORD=$db_password
psql --set ON_ERROR_STOP=1 -A -t -q -U $db_user -d $db_name -f $file
retcode=$?
fi
return $retcode
}
pgsql_version() {
pgsql_execute "SELECT version || '.' || minor FROM schema_version" "$@"
return $?
}
|