--- /dev/null
+#!/bin/sh
+
+# 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 bet.
+# 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.
+mysql_execute() {
+ if [ $# -gt 1 ]; then
+ QUERY=$1
+ shift
+ _RESULT=`echo $QUERY | mysql -N -B $@ | sed "s/\t/./g"`
+ else
+ _RESULT=`mysql -N -B --user=$db_user --password=$db_password -e "${1}" $db_name | sed "s/\t/./g"`
+ fi
+}
+
+mysql_version() {
+ mysql_execute "SELECT version,minor FROM schema_version" "$@"
+}
+
+mysql_version_print() {
+ mysql_version "$@"
+ printf "%s" $_RESULT
+}
\ No newline at end of file
db_password="keatest"
db_name="keatest"
+. ./admin-utils.sh
+
usage() {
printf "kea-admin @PACKAGE_VERSION@\n"
printf "\n"
done
}
-mysql_execute() {
- RESULT=`mysql -N -B --user=$db_user --password=$db_password -e "${1}" $db_name | sed "s/\t/./g"`
- printf ${RESULT}
-}
### Functions that implement database initialization commands
-init_memfile() {
+memfile_init() {
log_error "NOT IMPLEMENTED"
exit 1
}
-init_mysql() {
+mysql_init() {
log_error "NOT IMPLEMENTED"
exit 1
}
-init_pgsql() {
+pgsql_init() {
log_error "NOT IMPLEMENTED"
exit 1
}
### Functions that implement database version checking commands
-version_memfile() {
+memfile_version() {
log_error "NOT IMPLEMENTED"
exit 1
}
-version_mysql() {
- MYSQL_VERSION=$(mysql_execute "SELECT version,minor FROM schema_version")
- echo $MYSQL_VERSION
-}
-
-version_pgsql() {
+pgsql_version() {
log_error "NOT IMPLEMENTED"
exit 1
}
### Functions used for upgrade
-upgrade_memfile() {
+memfile_upgrade() {
log_error "NOT IMPLEMENTED"
exit 1
}
-upgrade_mysql() {
+mysql_upgrade() {
printf "Version reported before upgrade: "
- version_mysql
+ mysql_version_print
+ printf "\n"
# Check if the scripts directory exists at all.
if [ ! -d ${scripts_dir}/mysql ]; then
fi
# Check if there are any files in it
- num_files=`ls -1 ${scripts_dir}/mysql | wc -l &> /dev/null`
+ num_files=`ls -1 ${scripts_dir}/mysql/upgrade*.sh | wc -l &> /dev/null`
if [ $num_files -eq 0 ]; then
- log_error "No scripts in ${scripts_dir}/mysql or the directory is not readable"
+ log_error "No scripts in ${scripts_dir}/mysql or the directory is not readable or does not have any upgrade* scripts."
exit 1
fi
- for script in ${scripts_dir}/mysql/*
+ for script in ${scripts_dir}/mysql/upgrade*.sh
do
echo "Processing $script file..."
sh ${script} --user=${db_user} --password=${db_password} ${db_name}
done
printf "Version reported after upgrade: "
- version_mysql
+ mysql_version_print
+ printf "\n"
}
-upgrade_pgsql() {
+pgsql_upgrade() {
log_error "NOT IMPLEMENTED"
}
init)
case ${backend} in
memfile)
- init_memfile
+ memfile_init
;;
mysql)
- init_mysql
+ mysql_init
;;
pgsql)
- init_pgsql
+ pgsql_init
;;
esac
;;
version)
case ${backend} in
memfile)
- version_memfile
+ memfile_version
;;
mysql)
- version_mysql
+ mysql_version
;;
pgsql)
- version_pgsql
+ pgsql_version
;;
esac
;;
upgrade)
case ${backend} in
memfile)
- upgrade_memfile
+ memfile_upgrade
;;
mysql)
- upgrade_mysql
+ mysql_upgrade
;;
pgsql)
- upgrade_pgsql
+ pgsql_upgrade
;;
esac
;;
+#!/bin/sh
+
+# Import common library.
+. /home/thomson/devel/kea/src/bin/admin/admin-utils.sh
+
+mysql_version "$@"
+VERSION=$_RESULT
+
+if [ "$VERSION" != "1.0" ]; then
+ printf "This script upgrades 1.0 to 2.0. Reported version is $VERSION. Skipping upgrade.\n"
+ exit 0
+fi
+
mysql "$@" <<EOF
ALTER TABLE lease6
ADD COLUMN hwaddr varbinary(2),
UPDATE schema_version SET version="2", minor="0";
EOF
+
+RESULT=$?
+
+exit $?