Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4
PKثY[BaFlinternal/commonnuW+A### ### common bindings for dbconfig-common ### ### all variables and functions fall under the namespace "dbc_foo" and ### "_dbc_foo", depending on whether or not they are "external" ### [ "$_dbc_logfile" ] || _dbc_logfile="/var/log/dbconfig-common/dbc.log" ## ## dbc_logpart: log interal messages (without newline) ## dbc_logpart(){ printf "$* " >&2 printf "$* " >> $_dbc_logfile } ## ## dbc_logline: log interal messages ## dbc_logline(){ printf "$*.\n" >&2 printf "$*.\n" >> $_dbc_logfile } ### ### simple debugging function ### _dbc_debug(){ if [ "${dbc_debug:-}" ]; then dbc_logline "$@" fi } ## ## internal check for an installed db client package ## _dbc_detect_installed_dbtype(){ _dbc_debug "_dbc_detect_installed_dbtype() $@" # see if the dbtype is already installed. this is still not 100% accurate case "$1" in mysql) if ! which mysql >/dev/null; then return 1 fi ;; pgsql|psql) # if postgresql-client-common is installed without postgresql-client-8.x, # psql --version will exit with an error if ! which psql >/dev/null 2>&1 || \ ! psql --version >/dev/null 2>&1; then return 1 fi ;; "sqlite"|"sqlite3") if ! which $1 >/dev/null 2>&1; then return 1 fi ;; *) dbc_logline "_dbc_detect_installed_dbtype() called for unknown dbtype $@" return 1 ;; esac return 0 } ## ## internal sanity check for certain important variables ## _dbc_sanity_check(){ while [ $# -ne 0 ]; do case "$1" in "package") if [ -z "$dbc_package" ]; then dbc_error="dbconfig-common can not determine the name of the package it is configuring." dbc_logline "sanity check failed for dbc_package" return 1 fi ;; "packageconfig") if [ -z "$dbc_packageconfig" ]; then dbc_error="dbconfig-common can not determine the name of the package configuration file." dbc_logline "sanity check failed for dbc_packageconfig" return 1 fi ;; "dbtype") if [ -z "$dbc_dbtype" ]; then dbc_error="dbconfig-common can not determine the database type." dbc_logline "sanity check failed for dbc_dbtype" return 1 fi ;; "command") if [ -z "$dbc_command" ]; then dbc_error="dbconfig-common can not determine the maintainer script running it." dbc_logline "sanity check failed for dbc_command" return 1 fi ;; "dbname") if [ -z "$dbc_dbname" ]; then dbc_error="No database name specified. Have to know the name to create it." dbc_logline "sanity check failed for dbc_dbname" return 1 fi ;; "dbadmin") if [ -z "$dbc_dbadmin" ]; then dbc_error="No database administrator specified." dbc_logline "sanity check failed for dbc_dbadmin" return 1 fi ;; "dbuser") if [ -z "$dbc_dbuser" ]; then dbc_error="No database user specified." dbc_logline "sanity check failed for dbc_dbuser" return 1 fi ;; "dbpass") if [ -z "$dbc_dbpass" ]; then dbc_error="No database password specified." dbc_logline "sanity check failed for dbc_dbpass" return 1 fi ;; "mysql"|"psql"|"sqlite"|"sqlite3") if ! _dbc_detect_installed_dbtype $1; then dbc_error="No $1 client to execute. (have you installed the ${dbc_dbclientpackage:-$1} package?)" dbc_logline "sanity check failed for $1" return 1 fi ;; "createdb") if ! which createdb >/dev/null; then dbc_error="No pgsql createdb to execute. (have you installed postgresql-client?" dbc_logline "sanity check failed for createdb" return 1 fi ;; "dropdb") if ! which dropdb >/dev/null; then dbc_error="No pgsql dropdb to execute. (have you installed postgresql-client?" dbc_logline "sanity check failed for dropdb" return 1 fi ;; "createuser") if ! which createuser >/dev/null; then dbc_error="No pgsql createuser to execute. (have you installed postgresql-client?" dbc_logline "sanity check failed for createuser" return 1 fi ;; "dropuser") if ! which dropuser >/dev/null; then dbc_error="No pgsql dropuser to execute. (have you installed postgresql-client?" dbc_logline "sanity check failed for dropuser" return 1 fi ;; "pg_dump") if ! which pg_dump >/dev/null; then dbc_error="No pgsql pg_dump to execute. (have you installed postgresql-client?" dbc_logline "sanity check failed for pg_dump" return 1 fi ;; "mysqldump") if ! which mysqldump >/dev/null; then dbc_error="No mysqldump to execute. (have you installed mysql-client?" dbc_logline "sanity check failed for mysqldump" return 1 fi ;; *) dbc_error="don't know how to sanity check for $1" dbc_logline "don't know how to sanity check for $1" return 1 ;; esac shift done } dbc_mktemp(){ local tfile ttemplate if [ "${1:-}" ]; then ttemplate="$1"; else ttemplate="dbconfig-common.XXXXXX"; fi tfile=`mktemp -t "$ttemplate"` if [ ! -f "$tfile" ]; then dbc_error="error creating temporary file" dbc_logline "error creating temporary file" return 1 else echo $tfile fi } PKثY[9##internal/mysqlnuW+A### ### mysql bindings for dbconfig-common ### ### all variables and functions fall under the namespace "dbc_foo" and ### "_dbc_foo", depending on whether or not they are "external" ### # get some common functions . ${_dbc_root:-/usr/share/dbconfig-common}/internal/common ## ## pass configuration options securely to the mysql client ## _dbc_generate_mycnf(){ local mycnf l_date mycnf=`dbc_mktemp dbconfig-common_my.cnf.XXXXXX` || return 1 l_date=`date` cat << EOF > "$mycnf" # temporary my.cnf generated for usage by dbconfig-common # generated on $l_date # if you're reading this, it probably means something went wrong and # for some strange reason dbconfig-common was not able to clean up after itself. # you can safely delete this file [client] user = '${dbc_dbadmin:-}' password = '${dbc_dbadmpass:-}' host = '${dbc_dbserver:-}' port = '${dbc_dbport:-}' socket = '/var/run/mysqld/mysqld.sock' [mysqldump] user = '${dbc_dbadmin:-}' password = '${dbc_dbadmpass:-}' host = '${dbc_dbserver:-}' port = '${dbc_dbport:-}' socket = '/var/run/mysqld/mysqld.sock' EOF echo $mycnf } ## ## check that we can actually connect to the specified mysql server ## ## TODO: don't smash stdout/stderr together _dbc_mysql_check_connect(){ local constat mycnf constat="bad" mycnf=`_dbc_generate_mycnf` dbc_error=`mysql --defaults-extra-file="$mycnf" &1` && constat=good rm -f "$mycnf" if [ "$constat" = "bad" ]; then dbc_logline "$dbc_error" dbc_logline "unable to connect to mysql server" return 1 fi } ## ## execute a file with mysql commands ## ## note this is done without passing any sensitive info on the cmdline ## dbc_mysql_exec_file(){ local l_sqlfile l_retval l_error l_dbname l_errfile l_sqlfile=$1 l_errfile="`dbc_mktemp dbconfig-common_sql_exec_error.XXXXXX`" l_retval=0 if [ ! "$l_sqlfile" ]; then dbc_error="no file supplied to execute" dbc_log="no file supplied to execute" rm -f "$l_errfile" return 1 elif [ ! -f "$l_sqlfile" ]; then dbc_error="file $l_sqlfile missing" dbc_log="file $l_sqlfile missing" rm -f "$l_errfile" return 1 fi l_dbname= if [ ! "${_dbc_nodb:-}" ]; then l_dbname="$dbc_dbname" fi mycnf=`_dbc_generate_mycnf` if ! mysql --defaults-extra-file="$mycnf" $l_dbname 2>"$l_errfile" <"$l_sqlfile"; then l_retval=1 dbc_error="mysql said: `cat \"$l_errfile\"`" fi rm -f "$mycnf" "$l_errfile" return $l_retval } ## ## execute a specific mysql command ## ## note this is done without passing any sensitive info on the cmdline, ## including the mysql command itself ## dbc_mysql_exec_command(){ local statement l_sqlfile l_retval statement=$@ l_retval=0 l_sqlfile=`dbc_mktemp dbconfig-common_sqlfile.XXXXXX` cat << EOF > "$l_sqlfile" $statement EOF dbc_mysql_exec_file "$l_sqlfile" l_retval=$? rm -f "$l_sqlfile" return $l_retval } ## ## check for the existance of a specified database ## _dbc_mysql_check_database(){ local dbc_dbname local _dbc_nodb dbc_dbname=$1 _dbc_nodb="yes" dbc_mysql_exec_command "SHOW DATABASES" 2>/dev/null | grep -q "^$dbc_dbname\$" return $? } ## ## check for access for a specific user ## ## this works by checking the grants for the user, so we can verify that ## not only does the user exist, but that it should be able to connect ## dbc_mysql_check_user(){ local l_dballow l_retval _dbc_nodb if [ ! "${dbc_dballow:-}" ]; then if [ ! "${dbc_dbserver:-}" ] || [ "$dbc_dbserver" = "localhost" ]; then l_dballow=localhost else l_dballow=`hostname` fi else l_dballow="$dbc_dballow" fi if ! _dbc_nodb="yes" dbc_mysql_exec_command "SHOW GRANTS FOR '$dbc_dbuser'@'$l_dballow'" | grep -qi "GRANT .* ON \`$dbc_dbname\`"; then return 1 else return 0 fi } ### ### externally supplied functions ### ### included inline are some slightly modified / corrected comments from ### the respective original functions provided by wwwconfig-common, and ### comments of similar style for now functions ### ### all functions return non-zero on error ### dbc_mysql_createdb(){ local ret l_dbname _dbc_nodb _dbc_sanity_check dbname dbadmin mysql || return 1 _dbc_mysql_check_connect || return 1 dbc_logpart "creating database $dbc_dbname:" if _dbc_mysql_check_database "$dbc_dbname"; then dbc_logline "already exists" else _dbc_nodb="yes" dbc_mysql_exec_command "CREATE DATABASE $dbc_dbname" ret=$? _dbc_nodb="" if [ "$ret" = "0" ]; then dbc_logline "success" dbc_logpart "verifying database $dbc_dbname exists:" if ! _dbc_mysql_check_database "$dbc_dbname"; then dbc_logline "failed" return 1 else dbc_logline "success" fi else dbc_logline "failed" return 1 fi fi } # File: mysql-dropdb.sh # Needs: $dbc_dbname - the database that user should have access to. # $dbc_dbserver - the server to connect to. # $dbc_dbadmin - the administrator name. # $dbc_dbadmpass - the administrator password. # Description: drops a database. dbc_mysql_dropdb(){ _dbc_sanity_check dbname dbadmin mysql || return 1 _dbc_mysql_check_connect || return 1 dbc_logpart "dropping database $dbc_dbname:" if _dbc_mysql_check_database "$dbc_dbname"; then if dbc_mysql_exec_command "DROP DATABASE $dbc_dbname"; then dbc_logline "success" dbc_logpart "verifying database $dbc_dbname was dropped:" if _dbc_mysql_check_database "$dbc_dbname"; then dbc_logline "failed" return 1 else dbc_logline "success" fi else dbc_logline "failed" return 1 fi else dbc_logline "database does not exist" fi } # File: mysql-createuser.sh # Description: Creates or replaces a database user. # Needs: $dbc_dbuser - the user name to create (or replace). # $dbc_dballow - what hosts to allow. defaults to localhost/hostname # $dbc_dbname - the database that user should have access to. # $dbc_dbpass - the password to use. # $dbc_dbserver - the server to connect to (defaults to localhost). # $dbc_dbadmin - the administrator name. # $dbc_dbadmpass - the administrator password. dbc_mysql_createuser(){ local l_dballow l_sqlfile l_dbname l_ret _dbc_sanity_check dbuser dbname dbadmin mysql || return 1 _dbc_mysql_check_connect || return 1 if [ ! "${dbc_dballow:-}" ]; then if [ ! "${dbc_dbserver:-}" ] || [ "$dbc_dbserver" = "localhost" ]; then l_dballow=localhost else l_dballow=`hostname` fi else l_dballow="$dbc_dballow" fi dbc_logpart "granting access to database $dbc_dbname for $dbc_dbuser@$l_dballow:" l_sqlfile=`dbc_mktemp dbconfig-common.sql.XXXXXX` l_ret=0 cat << EOF > "$l_sqlfile" GRANT ALL PRIVILEGES ON \`$dbc_dbname\`.* TO \`$dbc_dbuser\`@'$l_dballow' IDENTIFIED BY '`dbc_mysql_escape_str $dbc_dbpass`'; FLUSH PRIVILEGES; EOF if dbc_mysql_check_user; then dbc_logline "already exists" else l_dbname=$dbc_dbname _dbc_nodb="yes" dbc_mysql_exec_file "$l_sqlfile" l_ret=$? _dbc_nodb="" if [ "$l_ret" = "0" ]; then dbc_logline "success" dbc_logpart "verifying access for $dbc_dbuser@$l_dballow:" if ! dbc_mysql_check_user ; then l_ret=1 dbc_logline "failed" else dbc_logline "success" fi else dbc_logline "failed" fi fi rm -f "$l_sqlfile" return $l_ret } # File: mysql-dropuser.sh # Needs: $dbc_dbuser - the user name to create (or replace). # $dbc_dballow - what hosts to allow (defaults to %). # $dbc_dbname - the database that user should have access to. # $dbc_dbserver - the server to connect to. # $dbc_dbadmin - the administrator name. # $dbc_dbadmpass - the administrator password. # Description: drops a database user. dbc_mysql_dropuser(){ local l_sqlfile l_dballow l_ret _dbc_nodb _dbc_sanity_check dbuser dbname dbadmin mysql || return 1 _dbc_mysql_check_connect || return 1 if [ ! "${dbc_dballow:-}" ]; then if [ ! "${dbc_dbserver:-}" ] || [ "$dbc_dbserver" = "localhost" ]; then l_dballow=localhost else l_dballow=`hostname` fi else l_dballow="$dbc_dballow" fi dbc_logpart "revoking access to database $dbc_dbname from $dbc_dbuser@$l_dballow:" if ! dbc_mysql_check_user; then dbc_logline "access does not exist" else l_sqlfile=`dbc_mktemp dbconfig-common.sql.XXXXXX` cat << EOF > "$l_sqlfile" REVOKE ALL PRIVILEGES ON \`$dbc_dbname\`.* FROM '$dbc_dbuser'@'$l_dballow'; FLUSH PRIVILEGES; EOF _dbc_nodb="yes" if dbc_mysql_exec_file "$l_sqlfile" 2>/dev/null; then dbc_logline "success" l_ret=0 else dbc_logline "failed" l_ret=1 fi # XXX no verification! rm -f "$l_sqlfile" return $l_ret fi } ## ## perform mysqldump ## dbc_mysql_dump(){ local mycnf dumperr db dumpfile old_umask _dbc_sanity_check dbname dbadmin mysql || return 1 _dbc_mysql_check_connect || return 1 dumpfile=$1 dumperr=0 old_umask=`umask` umask 0066 mycnf=`_dbc_generate_mycnf` dbc_error=`mysqldump --defaults-file="$mycnf" $dbc_dbname 2>&1 >"$dumpfile"` || dumperr=1 umask $old_umask rm -f "$mycnf" return $dumperr } ## ## basic installation check ## dbc_mysql_db_installed(){ which mysqld >/dev/null 2>&1 } ## ## dbc_mysql_escape_str: properly escape strings passed to mysql queries ## dbc_mysql_escape_str(){ sed -e 's,\\,\\&,g' -e "s,',\\\\&,g" << EOF $1 EOF } PKثY[nA22internal/pgsqlnuW+A### ### postgresql bindings for dbconfig-common ### ### all variables and functions fall under the namespace "dbc_foo" and ### "_dbc_foo", depending on whether or not they are "external" ### # get some common functions . /usr/share/dbconfig-common/internal/common _dbc_psql_local_username(){ # determine proper local system user as whom to run commands. # - if _dbc_asuser set and ident/localhost, # - if $dbc_dbuser exists as a system account, use it # - else ident/localhost: $dbc_dbadmin # - all others: no change (root) if [ "${_dbc_asuser:-}" ]; then if [ "${dbc_authmethod_user:-}" = "ident" ] && [ ! "${dbc_dbserver:-}" ]; then if [ "${dbc_dbuser:-}" ] && id $dbc_dbuser >/dev/null 2>&1; then echo $dbc_dbuser return 0 else dbc_logline "warning: ident method specified but local account doesn't exist" fi fi elif [ "${dbc_authmethod_admin:-}" = "ident" ] && [ ! "${dbc_dbserver:-}" ]; then echo $dbc_dbadmin return 0 fi echo root } _dbc_psql_remote_username(){ # determine proper remote user for connection requests # - if _dbc_asuser set: $dbc_dbuser # - else: $dbc_dbadmin if [ "${_dbc_asuser:-}" ]; then echo $dbc_dbuser else echo $dbc_dbadmin fi } _dbc_psql_cmd_setup(){ local localuser remoteuser remotepass localuser=`_dbc_psql_local_username` remoteuser=`_dbc_psql_remote_username` _dbc_pgsql_tmpdir=`mktemp -dt dbconfig-common.psql_home.XXXXXX` if [ $? -ne 0 ]; then return 1; fi if [ "$remoteuser" = "$dbc_dbadmin" ]; then remotepass="$dbc_dbadmpass" else remotepass="$dbc_dbpass" fi touch "${_dbc_pgsql_tmpdir}/.pgpass" chmod 600 "${_dbc_pgsql_tmpdir}/.pgpass" cat << EOF > "${_dbc_pgsql_tmpdir}/.pgpass" *:*:*:$remoteuser:$remotepass EOF if [ "$localuser" ] && [ "$localuser" != "root" ]; then chown -R "$localuser" "$_dbc_pgsql_tmpdir" fi } _dbc_psql_cmd_args(){ local extra remoteuser # if a dbserver is specified, use it if [ "$dbc_dbserver" ]; then extra="-h '$dbc_dbserver'"; # but if they specify a password, we should add the host explictly too elif [ "${_dbc_asuser:-}" ] && [ "$dbc_dbpass" ]; then extra="-h localhost"; elif [ "$dbc_dbadmpass" ]; then extra="-h localhost"; fi # add port settings if nonempty if [ "$dbc_dbport" ]; then extra="$extra -p '$dbc_dbport'"; fi # determine the database user name extra="$extra -U '`_dbc_psql_remote_username`'" echo $extra } _dbc_psql_cmd_cleanup(){ if [ "$_dbc_pgsql_tmpdir" ] && [ -d "$_dbc_pgsql_tmpdir" ]; then rm -f "${_dbc_pgsql_tmpdir}/.pgpass" rmdir "$_dbc_pgsql_tmpdir" fi } _dbc_psql(){ local extra retval PGSSLMODE localuser localuser=`_dbc_psql_local_username` PGSSLMODE="prefer" retval=0 _dbc_psql_cmd_setup if [ "${dbc_ssl:-}" ]; then PGSSLMODE="require"; fi extra=`_dbc_psql_cmd_args` _dbc_debug "su -s /bin/sh $localuser -c \"env HOME='$_dbc_pgsql_tmpdir' PGPASSFILE='$_dbc_pgsql_tmpdir/.pgpass' PGSSLMODE='$PGSSLMODE' psql --set \"ON_ERROR_STOP=1\" -q $extra $*\" 2>&1" dbc_error=`su -s /bin/sh $localuser -c "env HOME='$_dbc_pgsql_tmpdir' PGPASSFILE='$_dbc_pgsql_tmpdir/.pgpass' PGSSLMODE='$PGSSLMODE' psql --set "ON_ERROR_STOP=1" -q $extra $*" 2>&1` || retval=$? _dbc_psql_cmd_cleanup return $retval } _dbc_createdb(){ local extra extrasql retval PGSSLMODE localuser _dbc_asuser template local _dbc_nodb localuser=`_dbc_psql_local_username` PGSSLMODE="prefer" retval=0 _dbc_psql_cmd_setup if [ "${dbc_ssl:-}" ]; then PGSSLMODE="require"; fi extra=`_dbc_psql_cmd_args` if [ "${dbc_pgsql_createdb_encoding:-}" ]; then extrasql=" WITH TEMPLATE = \"template0\""; extrasql="$extrasql ENCODING = '$dbc_pgsql_createdb_encoding'"; fi _dbc_nodb="yes" _dbc_pgsql_exec_command "CREATE DATABASE \"$dbc_dbname\"${extrasql:-}" retval=$? _dbc_nodb="" _dbc_psql_cmd_cleanup return $retval } _dbc_dropdb(){ local extra retval PGSSLMODE localuser _dbc_asuser localuser=`_dbc_psql_local_username` PGSSLMODE="prefer" retval=0 _dbc_psql_cmd_setup if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi extra=`_dbc_psql_cmd_args` _dbc_debug "su -s /bin/sh $localuser -c \"env HOME='$_dbc_pgsql_tmpdir' PGPASSFILE='$_dbc_pgsql_tmpdir/.pgpass' PGSSLMODE='$PGSSLMODE' dropdb $extra $*\" 2>&1" dbc_error=`su -s /bin/sh $localuser -c "env HOME='$_dbc_pgsql_tmpdir' PGPASSFILE='$_dbc_pgsql_tmpdir/.pgpass' PGSSLMODE='$PGSSLMODE' dropdb $extra $*" 2>&1` || retval=$? _dbc_psql_cmd_cleanup return $retval } _dbc_createuser_majorversion(){ createuser --version | sed -e 's,.* ,,g' | sed -e 's,\..*,,g' } _dbc_createuser(){ local extra dbc_dbname retval PGSSLMODE localuser _dbc_asuser localuser=`_dbc_psql_local_username` PGSSLMODE="prefer" retval=0 _dbc_psql_cmd_setup if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi extra=`_dbc_psql_cmd_args` dbc_dbname="template1" _dbc_pgsql_exec_command "CREATE USER \"$dbc_dbuser\" WITH PASSWORD '`dbc_pgsql_escape_str $dbc_dbpass`'" || retval=$? _dbc_psql_cmd_cleanup return $retval } _dbc_dropuser(){ local extra retval PGSSLMODE localuser _dbc_asuser localuser=`_dbc_psql_local_username` PGSSLMODE="prefer" retval=0 _dbc_psql_cmd_setup if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi extra=`_dbc_psql_cmd_args` _dbc_debug "su -s /bin/sh $localuser -c \"env HOME='$_dbc_pgsql_tmpdir' PGPASSFILE='$_dbc_pgsql_tmpdir/.pgpass' PGSSLMODE='$PGSSLMODE' dropuser $extra $*\" 2>&1" dbc_error=`su -s /bin/sh $localuser -c "env HOME='$_dbc_pgsql_tmpdir' PGPASSFILE='$_dbc_pgsql_tmpdir/.pgpass' PGSSLMODE='$PGSSLMODE' dropuser $extra $*" 2>&1` || retval=$? _dbc_psql_cmd_cleanup return $retval } _dbc_pg_dump(){ local extra retval PGSSLMODE localuser _dbc_asuser dumpfile old_umask dumpfile=$1 localuser=`_dbc_psql_local_username` touch $dumpfile chown $localuser $dumpfile PGSSLMODE="prefer" retval=0 _dbc_psql_cmd_setup if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi old_umask=`umask` umask 0066 extra=`_dbc_psql_cmd_args` extra="-f \"$dumpfile\" $extra" _dbc_debug "su -s /bin/sh $localuser -c \"env HOME='$_dbc_pgsql_tmpdir' PGPASSFILE='$_dbc_pgsql_tmpdir/.pgpass' PGSSLMODE='$PGSSLMODE' pg_dump $extra $dbc_dbname\" 2>&1" dbc_error=`su -s /bin/sh $localuser -c "env HOME='$_dbc_pgsql_tmpdir' PGPASSFILE='$_dbc_pgsql_tmpdir/.pgpass' PGSSLMODE='$PGSSLMODE' pg_dump $extra $dbc_dbname" 2>&1` || retval=$? umask $old_umask _dbc_psql_cmd_cleanup return $retval } ## ## check that we can actually connect to the specified postgres server ## _dbc_pgsql_check_connect(){ local constat extra _dbc_asuser constat="bad" if ! _dbc_psql $extra template1 < /dev/null; then dbc_logline "unable to connect to postgresql server" return 1 fi } ## ## execute a file with pgsql commands ## ## note this is done without passing any sensitive info on the cmdline ## dbc_pgsql_exec_file(){ local l_sqlfile retval l_sqlfile=$1 if [ ! "$l_sqlfile" ]; then dbc_error="no file supplied to execute" dbc_log="no file supplied to execute" return 1 fi _dbc_psql $dbc_dbname < "$l_sqlfile" retval=$? return $retval } ## ## execute a specific pgsql command ## ## note this is done without passing any sensitive info on the cmdline, ## including the sql command itself ## _dbc_pgsql_exec_command(){ local statement l_sqlfile l_dbname retval retval=0 statement=$@ l_sqlfile=`dbc_mktemp dbconfig-common_sqlfile.XXXXXX` if [ -z "${_dbc_nodb:-}" ]; then l_dbname="$dbc_dbname" fi cat << EOF > "$l_sqlfile" $statement EOF _dbc_psql $extra ${l_dbname:-} < "$l_sqlfile" || retval=$? rm -f "$l_sqlfile" return $retval } ## ## check for the existance of a specified database ## _dbc_pgsql_check_database(){ local dbc_dbname _dbc_asuser extra dbc_dbname=$1 _dbc_psql $extra $dbc_dbname /dev/null return $? } ## ## check for access for a specific user ## ## this works by checking the grants for the user, so we can verify that ## not only does the user exist, but that it should be able to connect ## dbc_pgsql_check_user(){ local dbc_dbname l_retval _dbc_asuser extra dbc_dbname="template1" _dbc_pgsql_exec_command "ALTER USER \"$dbc_dbuser\"" l_retval=$? return $l_retval } ### ### externally supplied functions ### ### included inline are some slightly modified / corrected comments from ### the respective original functions provided by wwwconfig-common, and ### comments of similar style for now functions ### ### all functions return non-zero on error ### # File: pgsql-createdb.sh # Description: Creates a database. # Needs: $dbc_dbname # $dbc_dbadmin # Sets: $dbc_error = error message dbc_pgsql_createdb(){ _dbc_sanity_check dbname dbadmin psql dbuser createdb || return 1 _dbc_pgsql_check_connect || return 1 dbc_logpart "creating database $dbc_dbname:" if _dbc_pgsql_check_database "$dbc_dbname"; then dbc_logline "already exists" else if _dbc_createdb $dbc_dbname ; then dbc_logline "success" dbc_logpart "verifying database $dbc_dbname exists:" if ! _dbc_pgsql_check_database "$dbc_dbname"; then dbc_logline "failed" return 1 else dbc_logline "success" fi else dbc_logline "failed" return 1 fi fi } # File: pgsql-dropdb.sh # Needs: $dbc_dbname - the database that user should have access to. # $dbc_dbserver - the server to connect to. # $dbc_dbadmin - the administrator name. # $dbc_dbadmpass - the administrator password. # Description: drops a database. # Sets: $dbc_error = error message dbc_pgsql_dropdb(){ _dbc_sanity_check dbname dbadmin dropdb || return 1 _dbc_pgsql_check_connect || return 1 dbc_logpart "dropping database $dbc_dbname:" if _dbc_pgsql_check_database "$dbc_dbname"; then if _dbc_dropdb "$dbc_dbname"; then dbc_logline "success" dbc_logpart "verifying database $dbc_dbname was dropped:" if _dbc_pgsql_check_database "$dbc_dbname"; then dbc_logline "failed" else dbc_logline "success" fi else dbc_logline "does not exist" fi else dbc_logline "database does not exist" fi } # File: pgsql-createuser.sh # Description: Creates or replaces a database user. # Needs: $dbc_dbuser - the user name to create (or replace). # $dbc_dballow - what hosts to allow. defaults to localhost/hostname # $dbc_dbname - the database that user should have access to. # $dbc_dbpass - the password to use. # $dbc_dbserver - the server to connect to (defaults to localhost). # $dbc_dbadmin - the administrator name. # $dbc_dbadmpass - the administrator password. # Sets: $dbc_error = error message dbc_pgsql_createuser(){ local l_dballow dbc_dbname dbc_dbname=template1 _dbc_sanity_check dbuser dbadmin createuser || return 1 _dbc_pgsql_check_connect || return 1 if [ ! "$dbc_dballow" ]; then if [ ! "$dbc_dbserver" ] || [ "$dbc_dbserver" = "localhost" ]; then l_dballow=localhost else l_dballow=`hostname -f` fi else l_dballow="$dbc_dballow" fi dbc_logpart "creating postgres user $dbc_dbuser: " if dbc_pgsql_check_user; then dbc_logline "already exists" if [ "$dbc_dbpass" ]; then dbc_logpart "resetting password: " if _dbc_pgsql_exec_command "ALTER USER \"$dbc_dbuser\" WITH PASSWORD '$dbc_dbpass'"; then dbc_logline "success" else dbc_logline "failed" return 1 fi fi elif _dbc_createuser; then dbc_logline "success" dbc_logpart "verifying creation of user:" if ! dbc_pgsql_check_user ; then dbc_logline "failed" return 1 else dbc_logline "success" fi else dbc_logline "failed" return 1 fi } # File: pgsql-dropuser.sh # Needs: $dbc_dbuser - the user name to create (or replace). # $dbc_dballow - what hosts to allow (defaults to %). # $dbc_dbname - the database that user should have access to. # $dbc_dbserver - the server to connect to. # $dbc_dbadmin - the administrator name. # $dbc_dbadmpass - the administrator password. # Description: drops a database user. # Sets: $dbc_error = error message dbc_pgsql_dropuser(){ local l_dballow _dbc_sanity_check dbuser dbname dbadmin dropuser || return 1 _dbc_pgsql_check_connect || return 1 if [ ! "$dbc_dballow" ]; then if [ ! "$dbc_dbserver" ] || [ "$dbc_dbserver" = "localhost" ]; then l_dballow=localhost else l_dballow=`hostname -f` fi else l_dballow="$dbc_dballow" fi dbc_logpart "revoking access to database $dbc_dbname from $dbc_dbuser@$l_dballow:" if ! dbc_pgsql_check_user; then dbc_logline "access does not exist" else if _dbc_dropuser $dbc_dbuser 2>/dev/null; then dbc_logline "success" else dbc_logline "failed" fi fi } ## ## perform pg_dump ## dbc_pgsql_dump(){ local dumpfile dumpfile=$1 _dbc_sanity_check dbuser dbname dbadmin pg_dump || return 1 _dbc_pgsql_check_connect || return 1 _dbc_pg_dump $dumpfile } ## ## basic installation check ## dbc_pgsql_db_installed(){ test -n "`find /etc/init.d -name 'postgresql*'`" } ## ## dbc_pgsql_escape_str: properly escape strings passed to pgsql queries ## dbc_pgsql_escape_str(){ sed -e 's,\\,\\&,g' -e "s,',\\\\&,g" << EOF $1 EOF } PKثY[_ainternal/sqlitenuW+A### ### sqlite bindings for dbconfig-common ### ### Author: Matt Brown ### ### all variables and functions fall under the namespace "dbc_foo" and ### "_dbc_foo", depending on whether or not they are "external" ### # get some common functions . /usr/share/dbconfig-common/internal/common check_basepath_permissions(){ local line if dpkg-statoverride --list "$dbc_basepath" >/dev/null; then line=`dpkg-statoverride --list "$dbc_basepath"` c_owner=`echo $line | cut -d' ' -f1,2 | tr ' ' ':'` c_perms=`echo $line | cut -d' ' -f3` fi } ## ## execute a file with sqlite commands ## dbc_sqlite_exec_file(){ local l_sqlfile l_retval l_dbfile l_sqlfile=$1 l_dbfile="${dbc_basepath}/${dbc_dbname}" if [ ! "$l_sqlfile" ]; then dbc_error="no file supplied to execute" dbc_log="no file supplied to execute" return 1 fi l_retval=0 $dbc_sqlite_cmd "$l_dbfile" < "$l_sqlfile" || l_retval=$? return $l_retval } ## ## execute a specific sqlite command ## ## note this is done without passing any info on the cmdline, ## including the command itself ## dbc_sqlite_exec_command(){ local statement l_sqlfile l_retval statement=$@ l_retval=0 l_sqlfile=`dbc_mktemp dbconfig-common_sqlfile.XXXXXX` cat << EOF > $l_sqlfile $statement EOF dbc_sqlite_exec_file "$l_sqlfile" || l_retval=$? rm -f "$l_sqlfile" return $l_retval } ## ## check for the existance of a specified database ## _dbc_sqlite_check_database(){ local dbc_dbname l_dbfile dbc_dbname=$1 l_dbfile="${dbc_basepath}/${dbc_dbname}" if test -f "$l_dbfile"; then return 0 else return 1 fi } ## ## creates a new sqlite database file ## ## dbc_sqlite_createdb(){ local ret l_dbfile l_owner l_perms _dbc_sanity_check dbname $dbc_dbtype || return 1 l_dbfile="${dbc_basepath}/${dbc_dbname}" # Default to root:root 0640 if the maintainer hasn't hinted otherwise l_owner="root:root" l_perms="0640" if [ -n "$dbc_dbfile_owner" ]; then l_owner="$dbc_dbfile_owner"; fi if [ -n "$dbc_dbfile_perms" ]; then l_perms="$dbc_dbfile_perms"; fi dbc_logpart "creating database $dbc_dbname:" if _dbc_sqlite_check_database "$dbc_dbname"; then dbc_logline "already exists" else ret=0 if [ ! -d "${dbc_basepath}" ]; then # Create the base directory mkdir -p "${dbc_basepath}" fi # Setup permissions on the base directory to match dbfile check_basepath_permissions # Don't set permissions if admin has overriden them if [ ! -n "$c_owner" ]; then chown "$l_owner" "$dbc_basepath" fi if [ ! -n "$c_perms" ]; then chmod "$l_perms" "$dbc_basepath" # Always set execute bits on directories chmod u+x,g+x "$dbc_basepath" fi # Create the database and setup permissions dbc_sqlite_exec_command ".schema" && \ chown "$l_owner" "$l_dbfile" && \ chmod "$l_perms" "$l_dbfile" || ret=$? if [ "$ret" = "0" ]; then dbc_logline "success" dbc_logpart "verifying database $dbc_dbname exists:" if ! _dbc_sqlite_check_database "$dbc_dbname"; then dbc_logline "failed" dbc_error="Cannot find database after creation" return 1 else dbc_logline "success" fi else dbc_logline "failed" dbc_error="Failed to create database" return 1 fi fi } ## ## drops the sqlite database file by removing it from the disk ## ## dbc_sqlite_dropdb(){ _dbc_sanity_check dbname || return 1 dbc_logpart "dropping database $dbc_dbname:" if _dbc_sqlite_check_database "$dbc_dbname"; then if rm -f "${dbc_basepath}/${dbc_dbname}"; then dbc_logline "success" dbc_logpart "verifying database $dbc_dbname was dropped:" if _dbc_sqlite_check_database "$dbc_dbname"; then dbc_logline "failed" dbc_error="Database still exists after rm command" return 1 else dbc_logline "success" fi else dbc_logline "failed" dbc_error="Database removal failed" return 1 fi else dbc_logline "database does not exist" fi } ## ## basic installation check ## dbc_sqlite_db_installed(){ which sqlite >/dev/null 2>&1 } dbc_sqlite3_db_installed(){ which sqlite3 >/dev/null 2>&1 } ## ## dump a sqlite database ## dbc_sqlite_dump(){ local dumpfile ret old_umask dumpfile=$1 old_umask=`umask` _dbc_sanity_check dbname $dbc_dbtype || return 1 umask 0066 dbc_sqlite_exec_command ".dump" > "$dumpfile" ret=$? umask $old_umask return $ret } PKثY[<"GGdpkg/config.sqlite3nuW+Adbc_hardcoded_dbtype=sqlite3 . /usr/share/dbconfig-common/dpkg/config PKثY[# FFdpkg/postrm.sqlite3nuW+Adbc_hardcoded_dbtype=sqlite3 . /usr/share/dbconfig-common/dpkg/postrm PKثY[[Loo dpkg/commonnuW+A### ### common shell include for dbconfig-common aware packages. ### # usage: /usr/share/dbconfig-common/dpkg/common $package $dpkg_argv # (where $dpkg_argv is $@ as passed to the maintainer scripts) #set -x # get some internal helper functions, like _dbc_sanity_check . /usr/share/dbconfig-common/internal/common dbc_config(){ _dbc_debug "dbc_config() $@" ### ### some global variables ### dbc_share="/usr/share/dbconfig-common" dbc_package="$1" dbc_basepackage=`echo $dbc_package | cut -d_ -f1` dbc_command="$2" dbc_oldversion="$3" if ! _dbc_sanity_check package command; then dbc_install_error "determining package or command"; fi dbc_confdir="/etc/dbconfig-common" dbc_globalconfig="$dbc_confdir/config" dbc_packageconfig="$dbc_confdir/$dbc_package.conf" ### ### some internal variables ### # templates common to all database types dbc_standard_templates="database-type dbconfig-install dbconfig-upgrade dbconfig-remove dbconfig-reinstall password-confirm app-password-confirm purge upgrade-backup passwords-do-not-match install-error upgrade-error remove-error internal/reconfiguring internal/skip-preseed missing-db-package-error" # templates common to mysql database types dbc_mysql_templates="mysql/method remote/host remote/newhost mysql/app-pass mysql/admin-user mysql/admin-pass remote/port db/dbname db/app-user" # templates common to postgresql database types dbc_pgsql_templates="pgsql/method remote/host remote/newhost pgsql/app-pass pgsql/admin-user pgsql/admin-pass remote/port pgsql/authmethod-admin pgsql/authmethod-user pgsql/changeconf pgsql/manualconf db/dbname db/app-user pgsql/no-empty-passwords" # templates common to sqlite database types dbc_sqlite_templates="db/dbname db/basepath" # all dbtypes supported by dbconfig-common dbc_all_supported_dbtypes="mysql pgsql sqlite sqlite3" # database types supporting authenticated access dbc_authenticated_dbtypes="mysql pgsql" # database types supporting remote access dbc_remote_dbtypes="mysql pgsql" # database types storing files on the filesystem dbc_fs_dbtypes="sqlite sqlite3" ### ### source the pre-existing config, if it exists ### if [ -f $dbc_globalconfig ]; then . $dbc_globalconfig fi # set the priority of "remote database" related questions for # the database types that support it if [ "$dbc_remote_questions_default" = "true" ]; then dbc_remote_questions_priority="high" dbc_default_pgsql_authmethod_admin="password" else dbc_remote_questions_priority="low" dbc_default_pgsql_authmethod_admin="ident" fi dbc_set_dbtype_defaults $dbc_dbtype } dbc_set_dbtype_defaults(){ _dbc_debug "dbc_set_dbtype_defaults() $@" # if dbtype isn't set, but dbc_hardcoded_dbtype is set, set dbtype to that if [ "$dbc_hardcoded_dbtype" ]; then dbc_dbtype="$dbc_hardcoded_dbtype" fi ### ### dbtype-specific variable section ### dbc_default_basepath="" # now set some variables based on the dbtype dbc_db_installed_cmd="dbc_${dbc_dbtype}_db_installed" case $dbc_dbtype in mysql) . /usr/share/dbconfig-common/internal/mysql dbc_createuser_cmd='dbc_mysql_createuser' dbc_checkuser_cmd='dbc_mysql_check_user' dbc_createdb_cmd='dbc_mysql_createdb' dbc_dropdb_cmd='dbc_mysql_dropdb' dbc_dropuser_cmd='dbc_mysql_dropuser' dbc_sqlexec_cmd='dbc_mysql_exec_command' dbc_sqlfile_cmd='dbc_mysql_exec_file' dbc_dump_cmd='dbc_mysql_dump' dbc_register_templates="$dbc_standard_templates $dbc_mysql_templates" dbc_default_admin="root" dbc_default_dbuser=`echo $dbc_package | tr -d +. | cut -c -16`; dbc_dbvendor="MySQL" dbc_dbpackage="mysql-server" dbc_dbclientpackage="mysql-client" ;; pgsql) . /usr/share/dbconfig-common/internal/pgsql dbc_createuser_cmd='dbc_pgsql_createuser' dbc_checkuser_cmd='dbc_pgsql_check_user' dbc_createdb_cmd='dbc_pgsql_createdb' dbc_dropdb_cmd='dbc_pgsql_dropdb' dbc_dropuser_cmd='dbc_pgsql_dropuser' dbc_sqlexec_cmd='dbc_pgsql_exec_command' dbc_sqlfile_cmd='dbc_pgsql_exec_file' dbc_dump_cmd='dbc_pgsql_dump' dbc_register_templates="$dbc_standard_templates $dbc_pgsql_templates" dbc_default_admin="postgres" dbc_default_dbuser=`echo $dbc_package | tr -d +-.`; dbc_use_dbuser="false" dbc_dbvendor="PostgreSQL" dbc_dbpackage="postgresql" dbc_dbclientpackage="postgresql-client" ;; sqlite|sqlite3) . /usr/share/dbconfig-common/internal/sqlite dbc_createuser_cmd=true dbc_checkuser_cmd=true dbc_createdb_cmd='dbc_sqlite_createdb' dbc_dropdb_cmd='dbc_sqlite_dropdb' dbc_dropuser_cmd=true dbc_sqlexec_cmd='dbc_sqlite_exec_command' dbc_sqlfile_cmd='dbc_sqlite_exec_file' dbc_dump_cmd='dbc_sqlite_dump' dbc_register_templates="$dbc_standard_templates $dbc_sqlite_templates" dbc_default_admin="" dbc_default_dbuser=""; dbc_default_basepath="/var/lib/dbconfig-common/$dbc_dbtype/$dbc_package" dbc_use_dbuser="false" dbc_dbvendor="SQLite" dbc_sqlite_cmd="/usr/bin/$dbc_dbtype" dbc_dbpackage="$dbc_dbtype" dbc_dbclientpackage="$dbc_dbtype" ;; *) dbc_register_templates="$dbc_standard_templates $dbc_mysql_templates $dbc_pgsql_templates $dbc_sqlite_templates" ;; esac # but if this is a frontend-only app, reset some of the above to noops if [ "$dbc_frontend" ]; then dbc_createuser_cmd=true dbc_checkuser_cmd=true dbc_createdb_cmd=true dbc_dropdb_cmd=true dbc_dropuser_cmd=true dbc_sqlexec_cmd=true dbc_sqlfile_cmd=true dbc_dump_cmd=true fi } ### ### functions ### ### ### dump global configuration to a config file ### dbc_write_global_config(){ local tfile _dbc_debug "dbc_write_global_config() $@" tfile=`dbc_mktemp` cat << EOF > "$tfile" # dbconfig-common system-wide configuration options # dbc_remember_admin_pass: should we cache administrative passwords? # set to "true" to keep admin passwords cached in debconf dbc_remember_admin_pass='$dbc_remember_admin_pass' # dbc_remote_questions_default: will we be likely to install on remote servers? # set to "true" to raise the priority of debconf questions related to # database installation on remote servers (for database types that support this) dbc_remote_questions_default='$dbc_remote_questions_default' EOF ucf --debconf-ok "$tfile" "$dbc_globalconfig" ucfr dbconfig-common "$dbc_globalconfig" rm -f "$tfile" } dbc_read_package_config(){ _dbc_debug "dbc_read_package_config() $@" _dbc_sanity_check package packageconfig || dbc_install_error # first we set some defaults, which will be overridden by the config dbc_install=true dbc_upgrade=true if [ -f $dbc_packageconfig ]; then . $dbc_packageconfig fi # if dbserver is unset, that means localhost. if [ -z "$dbc_dbserver" ] || [ "$dbc_dbserver" = "localhost" ]; then # if the server is local, only allow connections from localhost dbc_dballow="localhost" else # otherwise, only tell the remote database to allow from us dbc_dballow=`hostname -f` fi } ### ### this function is responsible for setting all debconf values based ### on the contents of on-system config files, so that we can avoid ### the "Debconf is Not a Registry" dilemma. ### dbc_preseed_package_debconf(){ local skip_preseed _dbc_debug "dbc_preseed_package_debconf() $@" _dbc_sanity_check package || dbc_install_error # if we've pre-configured the package and are running config # for the second time via dpkg, then there is no on-disk # configuration to preseed with, and we would in fact nuke # the previous answers. so we check to avoid that. db_get $dbc_package/internal/skip-preseed && skip_preseed="$RET" db_reset $dbc_package/internal/skip-preseed if [ "$skip_preseed" = "true" ]; then dbc_read_package_debconf return 0 fi # set whether they want our help db_set $dbc_package/dbconfig-install "$dbc_install" db_set $dbc_package/dbconfig-upgrade "$dbc_upgrade" db_set $dbc_package/dbconfig-remove "$dbc_remove" # set the dbtype db_set $dbc_package/database-type "$dbc_dbtype" # the following db-specific settings always need to be preseeded unless # we specifically know we're not configuring for the given database type # # set the psql authentication method if [ -z "$dbc_dbtype" ] || [ "$dbc_dbtype" = "pgsql" ]; then if [ "$dbc_authmethod_admin" ]; then db_set $dbc_package/pgsql/authmethod-admin "$dbc_authmethod_admin" elif [ "$dbc_default_pgsql_authmethod_admin" ]; then db_set $dbc_package/pgsql/authmethod-admin "$dbc_default_pgsql_authmethod_admin" fi if [ "$dbc_authmethod_user" ]; then db_set $dbc_package/pgsql/authmethod-user "$dbc_authmethod_user" fi fi # for authenticated-only dbtypes. also catches empty (multidb) type. if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then # set app user if [ "$dbc_dbuser" ]; then db_set $dbc_package/db/app-user "$dbc_dbuser" fi # set the app user password if [ "$dbc_dbpass" ]; then db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass" fi # set the database administrator name if [ "$dbc_dbadmin" ]; then db_set $dbc_package/$dbc_dbtype/admin-user "$dbc_dbadmin" fi fi # for remote-capable dbtypes if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then # set the remote server/port if [ "$dbc_dbserver" ]; then db_set $dbc_package/remote/host "$dbc_dbserver" fi if [ "$dbc_dbport" ]; then db_set $dbc_package/remote/port "$dbc_dbport" fi fi # for fs-based dbtypes only (sqlite) if echo "$dbc_fs_dbtypes" | grep -qa "$dbc_dbtype"; then # set the directory that the database file is found in if [ "$dbc_basepath" ]; then db_set $dbc_package/db/basepath "$dbc_basepath" fi fi # set the name of the database to be created if [ "$dbc_dbname" ]; then db_set $dbc_package/db/dbname "$dbc_dbname" fi case $dbc_dbtype in "pgsql") # ident based auth doesn't need a password if [ "$dbc_authmethod_admin" != "ident" ]; then # set the database administrator pass db_set $dbc_package/pgsql/admin-pass "$dbc_dbadmpass" fi if [ "$dbc_authmethod_user" != "ident" ]; then # set the database user pass db_set $dbc_package/pgsql/app-pass "$dbc_dbpass" fi # set whether or not they want to force SSL if [ "$dbc_ssl" = "true" ]; then db_set $dbc_package/pgsql/method "tcp/ip + ssl" fi ;; esac } ### ### this function is responsible for reading in everything ### with respect to the package's configuration and dbconfig-common. ### dbc_read_package_debconf(){ _dbc_debug "dbc_read_package_debconf() $@" _dbc_sanity_check package || dbc_install_error # gracefully fetch this to support multi-dbtype packages if [ ! "$dbc_hardcoded_dbtype" ]; then db_get $dbc_package/database-type && dbc_dbtype="$RET" fi # dbconfig needs to be reloaded at this point for multi-dbtype apps dbc_set_dbtype_defaults $dbc_dbtype # get whether they want our help with various stuff db_get $dbc_package/dbconfig-install && dbc_install="$RET" db_get $dbc_package/dbconfig-upgrade && dbc_upgrade="$RET" db_get $dbc_package/dbconfig-remove && dbc_remove="$RET" # if they don't want help, then we're done and return early if [ "$dbc_install" != "true" ]; then return 0; fi # otherwise, just to make sure dbtype is set... _dbc_sanity_check dbtype || dbc_install_error if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then # get app user db_get $dbc_package/db/app-user && dbc_dbuser="$RET" # get the app user password db_get $dbc_package/$dbc_dbtype/app-pass && dbc_dbpass="$RET" # get the database administrator name db_get $dbc_package/$dbc_dbtype/admin-user && dbc_dbadmin="$RET" # get the database administrator pass db_get $dbc_package/$dbc_dbtype/admin-pass && dbc_dbadmpass="$RET" fi if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then # get the db server/port db_get $dbc_package/remote/host && dbc_dbserver="$RET" db_get $dbc_package/remote/port && dbc_dbport="$RET" fi if echo "$dbc_fs_dbtypes" | grep -qa "$dbc_dbtype"; then # get the directory that the database file is found in db_get $dbc_package/db/basepath && dbc_basepath="$RET" fi # get the name of the database to be created db_get $dbc_package/db/dbname && dbc_dbname="$RET" # a few db-specific things case $dbc_dbtype in "pgsql") # get the psql authentication method db_get $dbc_package/pgsql/authmethod-admin && dbc_authmethod_admin="$RET" db_get $dbc_package/pgsql/authmethod-user && dbc_authmethod_user="$RET" # get whether or not they want to force SSL db_get $dbc_package/pgsql/method && dbc_method="$RET" if [ "$dbc_method" = "tcp/ip + ssl" ]; then dbc_ssl="true" fi ;; esac if [ "$dbc_debug" ]; then _dbc_debug "settings determined from dbc_read_package_debconf:" _dbc_debug "\tdbc_install=$dbc_install" _dbc_debug "\tdbc_upgrade=$dbc_upgrade" _dbc_debug "\tdbc_remove=$dbc_remove" _dbc_debug "\tdbc_dbtype=$dbc_dbtype" _dbc_debug "\tdbc_dbuser=$dbc_dbuser" _dbc_debug "\tdbc_dbpass=$dbc_dbpass" _dbc_debug "\tdbc_dbadmin=$dbc_dbadmin" _dbc_debug "\tdbc_dbadmpass=$dbc_dbadmpass" _dbc_debug "\tdbc_dbserver=$dbc_dbserver" _dbc_debug "\tdbc_dbport=$dbc_dbport" _dbc_debug "\tdbc_dbname=$dbc_dbname" _dbc_debug "\tdbc_authmethod_admin=$dbc_authmethod_admin" _dbc_debug "\tdbc_authmethod_user=$dbc_authmethod_user" _dbc_debug "\tdbc_ssl=$dbc_ssl" fi } ### ### dump package configuration to a config file ### dbc_write_package_config(){ local iformat ofile tfile _dbc_debug "dbc_write_package_config() $@" _dbc_sanity_check packageconfig || dbc_install_error echo "dbconfig-common: writing config to $dbc_packageconfig" >&2 tfile=`dbc_mktemp dbconfig-package-config.XXXXXX` # a quick check if this is a multi-dbtype app if [ "$dbc_hardcoded_dbtype" ]; then dbc_dbtype="$dbc_hardcoded_dbtype" fi # and a check for ssl if [ "$dbc_method" = "tcp/ip + ssl" ]; then dbc_ssl="true" fi cat << EOF > $tfile # automatically generated by the maintainer scripts of $dbc_package # any changes you make will be preserved, though your comments # will be lost! to change your settings you should edit this # file and then run "dpkg-reconfigure $dbc_package" # dbc_install: configure database with dbconfig-common? # set to anything but "true" to opt out of assistance dbc_install='`dbc_sq_escape $dbc_install`' # dbc_upgrade: upgrade database with dbconfig-common? # set to anything but "true" to opt out of assistance dbc_upgrade='`dbc_sq_escape $dbc_upgrade`' # dbc_remove: deconfigure database with dbconfig-common? # set to anything but "true" to opt out of assistance dbc_remove='`dbc_sq_escape $dbc_remove`' # dbc_dbtype: type of underlying database to use # this exists primarily to let dbconfig-common know what database # type to use when a package supports multiple database types. # don't change this value unless you know for certain that this # package supports multiple database types dbc_dbtype='`dbc_sq_escape $dbc_dbtype`' # dbc_dbuser: database user # the name of the user who we will use to connect to the database. dbc_dbuser='`dbc_sq_escape $dbc_dbuser`' # dbc_dbpass: database user password # the password to use with the above username when connecting # to a database, if one is required dbc_dbpass='`dbc_sq_escape $dbc_dbpass`' # dbc_dbserver: database host. # leave unset to use localhost (or a more efficient local method # if it exists). dbc_dbserver='`dbc_sq_escape $dbc_dbserver`' # dbc_dbport: remote database port # leave unset to use the default. only applicable if you are # using a remote database. dbc_dbport='`dbc_sq_escape $dbc_dbport`' # dbc_dbname: name of database # this is the name of your application's database. dbc_dbname='`dbc_sq_escape $dbc_dbname`' # dbc_dbadmin: name of the administrative user # this is the administrative user that is used to create all of the above dbc_dbadmin='`dbc_sq_escape $dbc_dbadmin`' # dbc_basepath: base directory to hold database files # leave unset to use the default. only applicable if you are # using a local (filesystem based) database. dbc_basepath='`dbc_sq_escape $dbc_basepath`' ## ## postgresql specific settings. if you don't use postgresql, ## you can safely ignore all of these ## # dbc_ssl: should we require ssl? # set to "true" to require that connections use ssl dbc_ssl='`dbc_sq_escape $dbc_ssl`' # dbc_authmethod_admin: authentication method for admin # dbc_authmethod_user: authentication method for dbuser # see the section titled "AUTHENTICATION METHODS" in # /usr/share/doc/dbconfig-common/README.pgsql for more info dbc_authmethod_admin='`dbc_sq_escape $dbc_authmethod_admin`' dbc_authmethod_user='`dbc_sq_escape $dbc_authmethod_user`' ## ## end postgresql specific settings ## EOF # apps registered via webapps-common might use nested directories, so # we should make sure the directories exist mkdir -p "`dirname \"$dbc_packageconfig\"`" ucf --debconf-ok "$tfile" "$dbc_packageconfig" ucfr "$dbc_package" "$dbc_packageconfig" rm -f "$tfile" # generate the requested d-g-i config files unless it's a manual install # and we've been explicitly told to avoid doing this if [ "$dbc_install" != "true" ] && [ "$dbc_dgi_on_manual" != "true" ]; then return 0 elif [ "$dbc_generate_include" ]; then if [ "$dbc_generate_include_owner" ]; then dbc_generate_include_args="$dbc_generate_include_args -O $dbc_generate_include_owner" fi if [ "$dbc_generate_include_perms" ]; then dbc_generate_include_args="$dbc_generate_include_args -m $dbc_generate_include_perms" fi if echo $dbc_generate_include | grep -q -E "^[^:]*:"; then iformat=`echo $dbc_generate_include | cut -d: -f1` ofile=`echo $dbc_generate_include | cut -d: -f2` dbconfig-generate-include -a -f "$iformat" $dbc_generate_include_args -U "$dbc_packageconfig" "$ofile" ucfr "$dbc_package" "$dbc_packageconfig" else dbc_error="maintainer did not properly set dbc_generate_include" dbc_install_error "writing package config" fi fi } dbc_abort(){ # forget that we've seen all the debconf questions for f in $dbc_register_templates; do db_fset $dbc_package/$f seen false done echo "dbconfig-common: $dbc_package $dbc_command: aborted." >&2 dbc_postinst_cleanup return 1 } ## ## what to do if mysql-server etc are not installed ## dbc_missing_db_package_error(){ local question echo "warning: database package not installed?" >&2 question="$dbc_package/missing-db-package-error" db_fset $question seen false db_subst $question dbpackage $1 db_input critical $question || true db_go || true db_get $question _dbc_on_error_option="$RET" if [ "${DEBIAN_FRONTEND:-}" = "noninteractive" ]; then _dbc_on_error_option="ignore" fi if [ "$_dbc_on_error_option" = "abort" ]; then dbc_abort fi if [ "$_dbc_on_error_option" = "retry" ]; then # forget that we've seen all the debconf questions for f in $dbc_register_templates; do db_fset $dbc_package/$f seen false done echo "dbconfig-common: $dbc_package $dbc_command: trying again." >&2 . /usr/share/dbconfig-common/dpkg/config dbc_go $dbc_package configure $dbc_oldversion . /usr/share/dbconfig-common/dpkg/postinst dbc_go $dbc_package $dbc_command $dbc_oldversion dbc_tried_again="yes" fi } ## ## what to do when something goes wrong during install ## dbc_install_error(){ echo "error encountered $1:" >&2 echo $dbc_error >&2 if [ "$_dbc_no_act" ]; then return 0; fi db_fset $dbc_package/install-error seen false db_subst $dbc_package/install-error error $dbc_error db_input critical $dbc_package/install-error || true db_go || true db_get $dbc_package/install-error _dbc_on_error_option="$RET" if [ "${DEBIAN_FRONTEND:-}" = "noninteractive" ]; then echo "dbconfig-common: $dbc_package $dbc_command: noninteractive fail." >&2 _dbc_on_error_option="ignore" fi if [ "$_dbc_on_error_option" = "abort" ]; then dbc_abort fi if [ "$_dbc_on_error_option" = "retry" ]; then # forget that we've seen all the debconf questions for f in $dbc_register_templates; do db_fset $dbc_package/$f seen false done echo "dbconfig-common: $dbc_package $dbc_command: trying again." >&2 . /usr/share/dbconfig-common/dpkg/config dbc_go $dbc_package configure $dbc_oldversion . /usr/share/dbconfig-common/dpkg/postinst dbc_go $dbc_package $dbc_command $dbc_oldversion dbc_tried_again="yes" fi if [ "$_dbc_on_error_option" = "retry (skip questions)" ]; then echo "dbconfig-common: $dbc_package $dbc_command: trying again (skip questions)." >&2 . /usr/share/dbconfig-common/dpkg/postinst dbc_go $dbc_package $dbc_command $dbc_oldversion dbc_tried_again="yes" fi if [ "$_dbc_on_error_option" = "ignore" ]; then echo "dbconfig-common: $dbc_package $dbc_command: ignoring errors from here forwards" 2>&1 # XXX this would be better _dbc_no_act="true" dbc_checkuser_cmd=true dbc_createdb_cmd=true dbc_createuser_cmd=true dbc_dbvendor=true dbc_default_admin=true dbc_default_dbuser=true dbc_dropdb_cmd=true dbc_dropuser_cmd=true dbc_dump_cmd=true dbc_register_templates=true dbc_sqlexec_cmd=true dbc_sqlfile_cmd=true dbc_use_dbuser=true return 0 fi } ## ## what to do when something goes wrong during upgrade ## dbc_upgrade_error(){ echo "error encountered $1:" >&2 echo $dbc_error >&2 db_fset $dbc_package/upgrade-error seen false db_subst $dbc_package/upgrade-error error $dbc_error db_subst $dbc_package/upgrade-error dbfile $dbc_dumpfile db_input critical $dbc_package/upgrade-error || true db_go || true db_get $dbc_package/upgrade-error _dbc_on_error_option="$RET" if [ "$_dbc_on_error_option" = "abort" ]; then dbc_abort fi if [ "$_dbc_on_error_option" = "retry" ]; then # forget that we've seen all the debconf questions for f in $dbc_register_templates; do db_fset $dbc_package/$f seen false done echo "dbconfig-common: $dbc_package $dbc_command: retrying." >&2 . /usr/share/dbconfig-common/dpkg/config dbc_go $dbc_package configure $dbc_oldversion . /usr/share/dbconfig-common/dpkg/postinst dbc_go $dbc_package $dbc_command $dbc_oldversion dbc_tried_again="yes" fi if [ "$_dbc_on_error_option" = "retry (skip questions)" ]; then echo "dbconfig-common: $dbc_package $dbc_command: trying again." >&2 . /usr/share/dbconfig-common/dpkg/postinst dbc_go $dbc_package $dbc_command $dbc_oldversion dbc_tried_again="yes" fi } ## ## what to do when something goes wrong during remove ## dbc_remove_error(){ echo "error encountered $1:" >&2 echo $dbc_error >&2 db_fset $dbc_package/remove-error seen false db_subst $dbc_package/remove-error error $dbc_error db_input critical $dbc_package/remove-error || true db_go || true db_get $dbc_package/remove-error _dbc_on_error_option="$RET" if [ "$_dbc_on_error_option" = "abort" ]; then dbc_abort fi if [ "$_dbc_on_error_option" = "retry" ]; then # forget that we've seen all the debconf questions for f in $dbc_register_templates; do db_fset $dbc_package/$f seen false done echo "dbconfig-common: $dbc_package $dbc_command: retrying." >&2 . /usr/share/dbconfig-common/dpkg/config dbc_go $dbc_package configure $dbc_oldversion . /usr/share/dbconfig-common/dpkg/postinst dbc_go $dbc_package $dbc_command $dbc_oldversion dbc_tried_again="yes" fi } ## ## exactly what you'd think ## dbc_forget_dbadmin_password(){ _dbc_debug "dbc_forget_dbadmin_password() $@" echo dbconfig-common: flushing administrative password >&2 db_reset $dbc_package/$dbc_dbtype/admin-pass || true db_fset $dbc_package/$dbc_dbtype/admin-pass seen false || true db_reset $dbc_package/password-confirm || true db_fset $dbc_package/password-confirm seen false || true } ## ## exactly what you'd think ## dbc_forget_app_password(){ _dbc_debug "dbc_forget_app_password() $@" db_reset $dbc_package/$dbc_dbtype/app-pass || true db_fset $dbc_package/$dbc_dbtype/app-pass seen false || true db_reset $dbc_package/app-password-confirm || true db_fset $dbc_package/app-password-confirm seen false || true } ## ## exactly what you'd think ## ## usage: dbc_get_admin_pass package dbtype ## dbc_get_admin_pass(){ local have_admin_pass pass1 _dbc_debug "dbc_get_admin_pass() $@" db_fget $dbc_package/$dbc_dbtype/admin-pass seen if [ "$RET" = "true" ]; then have_admin_pass="yes" fi # make sure the passwords are the same, safely while [ ! "$have_admin_pass" ]; do # get the administrative password db_input high $dbc_package/$dbc_dbtype/admin-pass || true db_go || true db_get $dbc_package/$dbc_dbtype/admin-pass pass1="$RET" if [ "$dbc_dbtype" = "pgsql" ] && [ ! "$pass1" ]; then db_input high $dbc_package/pgsql/no-empty-passwords || true db_reset $dbc_package/$dbc_dbtype/admin-pass db_fset $dbc_package/$dbc_dbtype/admin-pass seen false db_go || true else have_admin_pass="yes" fi done db_get $dbc_package/$dbc_dbtype/admin-pass dbc_dbadmpass="$RET" } ## ## exactly what you'd think ## ## usage: dbc_get_app_pass package dbtype ## dbc_get_app_pass(){ local have_app_pass pass1 pass2 _dbc_debug "dbc_get_app_pass() $@" db_fget $dbc_package/$dbc_dbtype/app-pass seen if [ "$RET" = "true" ]; then have_app_pass="yes" db_get $dbc_package/$dbc_dbtype/app-pass dbc_dbpass="$RET" fi # make sure the passwords are the same, safely while [ ! "$have_app_pass" ]; do # forget the password-confirm question first, as it's shared db_reset $dbc_package/app-password-confirm db_fset $dbc_package/app-password-confirm seen false # get the appistrative password db_input high $dbc_package/$dbc_dbtype/app-pass || true db_go || true db_get $dbc_package/$dbc_dbtype/app-pass pass1="$RET" # get the password again, if it is not empty if [ "$pass1" ]; then db_input high $dbc_package/app-password-confirm || true db_go || true db_get $dbc_package/app-password-confirm pass2="$RET" fi # test to see if the passwords match if [ "$pass1" = "$pass2" ]; then dbc_dbpass="$pass1" have_app_pass="yes" else # tell them the passwords didn't match, loop again db_reset $dbc_package/$dbc_dbtype/app-pass db_fset $dbc_package/$dbc_dbtype/app-pass seen false db_input high $dbc_package/passwords-do-not-match || true db_go || true fi done if [ ! "$dbc_dbpass" ]; then dbc_dbpass=`env LANG=C LC_ALL=C tr -dc "[:alnum:]" < /dev/urandom | dd bs=1 count=12 2>/dev/null` db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass" db_set $dbc_package/app-password-confirm "$dbc_dbpass" fi } ## ## perform any necessary cleanup before exiting the postinst ## dbc_postinst_cleanup(){ _dbc_debug "dbc_postinst_cleanup() $@" if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then if [ "$dbc_remember_admin_pass" != "true" ]; then dbc_forget_dbadmin_password fi if [ "$dbc_remember_app_pass" != "true" ]; then dbc_forget_app_password fi fi db_reset $dbc_package/internal/skip-preseed } ## ## determine whether a db is supported by a package ## dbc_detect_supported_dbtype(){ local query_dbtype _dbc_debug "dbc_detect_supported_dbtype() $@" query_dbtype=$1 # see if the package says it's supported if echo $dbc_dbtypes | grep -qE "(^|,[[:space:]]*)$query_dbtype(\$|,)"; then return 0 fi return 1 } ## ## determine whether a db is installed on the system ## dbc_detect_installed_dbtype(){ _dbc_debug "dbc_detect_installed_dbtype() $@" _dbc_detect_installed_dbtype $@ } ### ### register all the necessary debconf templates ### dbc_register_debconf(){ local f local _dbc_debug "dbc_register_debconf() $@" for f in $dbc_register_templates; do # register the question, but bail if it doesn't (yet) exist # failure is gracefully handled elsewhere if ! db_register dbconfig-common/$f $dbc_package/$f >/dev/null 2>&1; then return 1 fi # perform some basic customizing substitutions if [ "$dbc_packagetitle" ]; then db_subst $dbc_package/$f pkg $dbc_packagetitle else db_subst $dbc_package/$f pkg $dbc_package fi if [ "$dbc_dbvendor" ]; then db_subst $dbc_package/$f dbvendor $dbc_dbvendor fi done if [ "$dbc_dbtypes" ]; then db_subst $dbc_package/database-type database_types $dbc_dbtypes fi } ### ### dbc_sq_escape: escape any single quotes present in a string ### ### this will safely escape a string which is to be stored inside ### single quotes. that is as'df -> as'\''df ### dbc_sq_escape(){ sed -e "s,','\\\\'',g" << EOF $@ EOF } PKثY[b@FFdpkg/postinst.pgsqlnuW+Adbc_hardcoded_dbtype=pgsql . /usr/share/dbconfig-common/dpkg/postinst PKثY[ M`??dpkg/frontend.postinstnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/postinst PKثY[)DDdpkg/frontend.preinst.mysqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/preinst.mysql PKثY[8fGGdpkg/preinst.sqlite3nuW+Adbc_hardcoded_dbtype=sqlite3 . /usr/share/dbconfig-common/dpkg/preinst PKثY[!BBdpkg/frontend.prerm.pgsqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/prerm.pgsql PKثY[BBdpkg/frontend.prerm.mysqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/prerm.mysql PKثY[`GGdpkg/postinst.sqlitenuW+Adbc_hardcoded_dbtype=sqlite . /usr/share/dbconfig-common/dpkg/postinst PKثY[锗FFdpkg/config.sqlitenuW+Adbc_hardcoded_dbtype=sqlite . /usr/share/dbconfig-common/dpkg/config PKثY[[==dpkg/frontend.postrmnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/postrm PKثY[^\<<dpkg/frontend.prermnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/prerm PKثY[fDDdpkg/frontend.preinst.pgsqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/preinst.pgsql PKثY[ O==dpkg/frontend.confignuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/config PKثY[RCCdpkg/prerm.pgsqlnuW+Adbc_hardcoded_dbtype=pgsql . /usr/share/dbconfig-common/dpkg/prerm PKثY[b@66 dpkg/confignuW+A### ### config hook ### dbc_go(){ local f db happy default_dbtype host newhost port oldhosts authmethod_admin do_config _preconf_list _s _t STATE iformat ifile install_question migrating userdb_prio supported_dbtypes . /usr/share/dbconfig-common/dpkg/common _dbc_debug "(config) dbc_go() $@" dbc_config $@ db_capb backup # only do this on install/reconfigure if [ "$dbc_command" != "configure" ] && [ "$dbc_command" != "reconfigure" ]; then return 0 fi ## ## register all the dbconfig-common questions ## ## note that this can fail in the case that dbconfig-common is being ## installed at the same time as the dependant package and the latter ## is preconfigured before we are (no way to avoid this without being ## in base). in this case we gracefully exit and defer to the second ## time the config script is run by dpkg in the postinst. note if that ## "hack" in dpkg ever goes away we can still work around the issue so ## i think it's fair to avoid over-complicating things in the dependency ## chain. ## if ! dbc_register_debconf; then _dbc_debug "dbconfig-common not yet setup, deferring configuration." return 0 fi # make sure debconf is up to date with on-disk configuration dbc_read_package_config dbc_preseed_package_debconf # Find out whether the database has been purged on a previous occasion. If # so, we'll have to give the user a chance to re-install it. db_get $dbc_package/purge if [ "$RET" = true ]; then dbc_command=reconfigure fi # check out if they're migrating from a non-dbc version if [ "$dbc_oldversion" ] && [ "$dbc_first_version" ] && \ dpkg --compare-versions "$dbc_first_version" gt "$dbc_oldversion"; then migrating="yes" fi # if this is a frontend app, then the user/db type questions get # a raised priority userdb_prio="low" if [ "$dbc_frontend" ]; then userdb_prio="medium" need_adminpw="false" else userdb_prio="low" fi # and if they're upgrading from any previous version, we *may* # not need to ask for an admin password. we can't tell at this # point because the upgrade files are likely not unpacked at # this point, so we will instead ask later in the postinst. if [ "$dbc_oldversion" ] && [ "$dbc_command" != "reconfigure" ]; then need_adminpw="false" fi # the first question we ask will differ depending on how we're invoked if [ "$migrating" ]; then install_question="$dbc_package/dbconfig-upgrade" elif [ "$dbc_command" = "configure" ]; then install_question="$dbc_package/dbconfig-install" else install_question="$dbc_package/dbconfig-reinstall" # if we are reconfiguring (via dpkg-reconfigure), also leave a hint # for our future postinst selves so we know we *should* run the code # that would otherwise think we were upgrading db_set $dbc_package/internal/reconfiguring true fi ## ## start new dbc upgrade section ## # if there is a previously existing version already installed # *and* the maintainer has provided the first version that used # dbconfig-common *and* this version is newer than the # previously installed version... do the dbc import stuff. if [ "$migrating" ]; then dbc_migrate fi # and start our beautiful state-machine # we start in STATE=1 (install_question) in all but one situation: # - we're installing a frontend/readonly app if [ ! "$dbc_frontend" ]; then STATE=1 else STATE=2 fi while true; do case "$STATE" in # state 1 - ask if they want our help at all 1) db_input high $install_question || true ;; # state 2 - check to see if they do. # - see if this is an upgrade newly supporting dbc # - multidb support step 1 2) db_get $install_question if [ "$RET" != "true" ]; then db_set $dbc_package/internal/skip-preseed true return 0; fi db_set $dbc_package/dbconfig-install true ## ## start multidb section ## # if the dbtype is hardcoded (using config.mysql, etc), use that if [ "$dbc_hardcoded_dbtype" ]; then dbc_dbtype=$dbc_hardcoded_dbtype # else if the package supports multiple dbtypes, help them pick one elif [ "$dbc_dbtypes" ]; then # loop through the listed dbtypes, fall back to all those available supported_dbtypes=$(echo $dbc_dbtypes | sed 's/,/ /g') for db in $supported_dbtypes $dbc_all_supported_dbtypes; do # if we're already happy, we're already done if [ "$happy" ]; then true # else, if it's supported, installed and unpacked, we're happy elif dbc_detect_supported_dbtype $db; then # if it's installed, we're happy if dbc_detect_installed_dbtype $db; then happy="yes" fi # but in any case it's be the default even if not happy default_dbtype=$db fi # otherwise, there's no default yet, which is okay done # now that we're done with that, actually do the debconf stuff # if dbc_dbtype isn't already set (from conf file) then # use the default as our best guess if [ ! "$dbc_dbtype" ]; then dbc_dbtype="$default_dbtype" fi db_set $dbc_package/database-type "$dbc_dbtype" db_input high $dbc_package/database-type || true fi ;; # state 3 - multidb support part 2, pre-seeding, get conn. method 3) if [ "$dbc_dbtypes" ]; then db_get $dbc_package/database-type && dbc_dbtype="$RET" # now that we have a dbtype, reload common to set other defaults dbc_config $@ fi # there's a bit more to do with rdbms that support authentication if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then # if these haven't been specified, use defaults if [ ! "$dbc_dbadmin" ]; then dbc_dbadmin="$dbc_default_admin"; fi if [ ! "$dbc_dbuser" ]; then dbc_dbuser="$dbc_default_dbuser" fi fi if echo "$dbc_fs_dbtypes" | grep -q "$dbc_dbtype"; then # if these haven't been specified, use defaults if [ ! "$dbc_basepath" ]; then dbc_basepath="$dbc_default_basepath"; fi fi if [ ! "$dbc_dbname" ]; then dbc_dbname=`echo $dbc_package | tr -d +-.`; fi # pre-seed any already defined values into debconf as defaults db_set $dbc_package/db/dbname "$dbc_dbname" if [ "$dbc_upgrade" ]; then db_set $dbc_package/dbconfig-upgrade "$dbc_upgrade" fi if [ "$dbc_remove" ]; then db_set $dbc_package/dbconfig-remove "$dbc_remove" fi if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then if [ "$dbc_dbuser" ]; then db_set $dbc_package/db/app-user "$dbc_dbuser" fi if [ "$dbc_dbpass" ]; then db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass" db_fset $dbc_package/$dbc_dbtype/app-pass seen true db_set $dbc_package/app-password-confirm "$dbc_dbpass" db_fset $dbc_package/app-password-confirm seen true fi if [ "$dbc_dbadmin" ]; then db_set $dbc_package/$dbc_dbtype/admin-user "$dbc_dbadmin" fi fi if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then if [ "$dbc_dbserver" ]; then db_set $dbc_package/remote/host "$dbc_dbserver" fi if [ "$dbc_dbport" ]; then db_set $dbc_package/remote/port "$dbc_dbport" fi if [ "$dbc_ssl" = "true" ] && [ "$dbc_dbtype" = "pgsql" ]; then db_set $dbc_package/pgsql/method "tcp/ip + ssl" fi db_input $dbc_remote_questions_priority $dbc_package/$dbc_dbtype/method || true fi if echo "$dbc_fs_dbtypes" | grep -q "$dbc_dbtype"; then # if these haven't been specified, use defaults if [ "$dbc_basepath" ]; then db_set $dbc_package/db/basepath "$dbc_basepath" fi fi ;; # state 4 - do stuff based on the connection method 4) db_get $dbc_package/$dbc_dbtype/method && dbc_method="$RET" if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then # if package/method == tcp/ip or tcp/ip + ssl if [ "$dbc_method" != "unix socket" ]; then # look at the hosts used in any other dbconfig-using # package, and create a list of hosts. _preconf_list=` ( for f in /etc/dbconfig-common/*.conf; do test -f $f || continue eval \`dbconfig-generate-include --dbserver=_s $f | grep -v '^#'\` [ "$_s" ] && echo $_s done ) | sort | uniq` # turn the list into a comma separated list if it exists # and then substitute it into the list of available hosts if [ "$_preconf_list" ]; then _preconf_list=`echo $_preconf_list | sed -e 's/ /, /g'` _preconf_list="new host, $_preconf_list" db_subst $dbc_package/remote/host hosts "$_preconf_list" # and then ask them for one db_input high $dbc_package/remote/host || true fi # but if it is unix socket, forget all the host stuff else db_reset $dbc_package/remote/host || true db_reset $dbc_package/remote/newhost || true db_reset $dbc_package/remote/port || true fi fi ;; # state 5 - get host / port info if necessary 5) if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then if [ "$dbc_method" != "unix socket" ]; then if [ "$_preconf_list" ]; then db_get $dbc_package/remote/host host=$RET fi # if they've chosen "new host" or the host list was empty if [ ! "$host" ] || [ "$host" = "new host" ]; then # prompt them for a new hostname db_input high $dbc_package/remote/newhost || true fi fi fi ;; # state 6 - do stuff based on host/port selection 6) if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then if [ "$dbc_method" != "unix socket" ]; then if [ ! "$host" ] || [ "$host" = "new host" ]; then db_get $dbc_package/remote/newhost newhost="$RET" # add the new host to the existing list of hosts db_metaget $dbc_package/remote/host choices oldhosts="$RET" db_subst $dbc_package/remote/host hosts "$oldhosts, $newhost" db_set $dbc_package/remote/host "$newhost" db_fset $dbc_package/remote/host seen true else # set the "newhost" to the selected host, because # the second time through the configure script we'll # need this set db_set $dbc_package/remote/newhost "$host" fi # on what port? db_input $dbc_remote_questions_priority $dbc_package/remote/port || true fi fi ;; # state 7 - pgsql specific auth stuff, part 1 7) if [ "$dbc_dbtype" = "pgsql" ] && [ ! "$dbc_frontend" ]; then # postgresql provides multiple auth types, and ssl # get the admin auth method db_input low $dbc_package/pgsql/authmethod-admin || true fi ;; # state 8 - pgsql auth stuff, part 2 8) if [ "$dbc_dbtype" = "pgsql" ] && [ ! "$dbc_frontend" ]; then db_get $dbc_package/pgsql/authmethod-admin && authmethod_admin="$RET" # if we are using ident, we don't need passwords if [ "$authmethod_admin" = "ident" ]; then need_adminpw="false" fi # default the user auth method to the admin method # ...but only if the answer hasn't already been specified. if [ ! "${dbc_authmethod_user}" ]; then db_set $dbc_package/pgsql/authmethod-user "$authmethod_admin" fi db_input medium $dbc_package/pgsql/authmethod-user || true fi ;; # state 9 - admin/app user/pass, dbname 9) if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then # who's the admin user if [ ! "$dbc_frontend" ]; then db_input $userdb_prio $dbc_package/$dbc_dbtype/admin-user || true if [ "$need_adminpw" != "false" ]; then dbc_get_admin_pass fi fi db_input $userdb_prio $dbc_package/db/app-user || true dbc_get_app_pass fi if echo "$dbc_fs_dbtypes" | grep -q "$dbc_dbtype"; then # check the path / permissions to install to db_input low $dbc_package/db/basepath || true fi # get the name of the database to use db_input $userdb_prio $dbc_package/db/dbname || true ;; # * - end state *) break ;; esac if db_go; then STATE=$(($STATE + 1)) else STATE=$(($STATE - 1)) fi if [ $STATE -lt 1 ]; then exit 10 fi done db_set $dbc_package/internal/skip-preseed true } dbc_migrate() { # if dbc_load_include is set, determine the format # and location of the old config file if [ "$dbc_load_include" ]; then iformat=`echo $dbc_load_include | cut -d: -f1` ifile=`echo $dbc_load_include | cut -d: -f2-` fi ## ## if they want to import settings from a previous ## non-dbc version, do that and mark the questions ## skipped ## if [ -z "$ifile" ] || [ ! -f "$ifile" ]; then return fi dbc_logpart "migrating old settings into dbconfig-common: " if [ "$dbc_debug" ]; then _dbc_debug "dbconfig-load-include $dbc_load_include_args -f $iformat $ifile" dbconfig-load-include $dbc_load_include_args -f $iformat $ifile fi eval `dbconfig-load-include $dbc_load_include_args -f $iformat $ifile` if [ "$?" != "0" ]; then dbc_logline "failed" return fi # the load script needs to return at least a database type, if it's # not a single-dbtype package dbc_dbtype=${dbc_dbtype:-${dbc_hardcoded_dbtype:-}} if [ -z "$dbc_dbtype" ]; then dbc_logline "failed" return fi # if the dbtype is hardcoded, reset it no matter what # dbconfig-load-include tells us if [ "$dbc_hardcoded_dbtype" ]; then dbc_dbtype="$dbc_hardcoded_dbtype" fi for f in database-type $dbc_dbtype/method db/dbname; do db_fset $dbc_package/$f seen true || true done if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then for f in pgsql/authmethod-admin pgsql/authmethod-user $dbc_dbtype/admin-user db/app-user; do db_fset $dbc_package/$f seen true || true done db_set $dbc_package/db/app-user "$dbc_dbuser" db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass" db_set $dbc_package/password-confirm "$dbc_dbpass" fi if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then for f in remote/host remote/newhost remote/port ; do db_fset $dbc_package/$f seen true || true done db_set $dbc_package/remote/host "$dbc_dbserver" db_set $dbc_package/remote/newhost "$dbc_dbserver" db_set $dbc_package/remote/port "$dbc_dbport" if [ "$dbc_dbserver" ]; then db_set $dbc_package/$dbc_dbtype/method "tcp/ip" fi fi db_set $dbc_package/database-type $dbc_dbtype db_set $dbc_package/db/dbname "$dbc_dbname" dbc_logline "done" } PKثY[L## dpkg/preinstnuW+A### ### what happens in this script: ### ### nothing. unfortunately we can't reliably be run out of a package's ### preinst script without pre-dependencies, and we don't really need ### to anyway. ### dbc_go(){ dbc_logline "W: use of dbc preinst hooks is now unnecesary and deprecated" } PKثY[xFFdpkg/preinst.sqlitenuW+Adbc_hardcoded_dbtype=sqlite . /usr/share/dbconfig-common/dpkg/preinst PKثY[W dpkg/postrmnuW+A### ### source common stuff ### dbc_go(){ . /usr/share/dbconfig-common/dpkg/common local cfg _dbc_debug "(postrm) dbc_go() $@" dbc_config $@ if [ "$dbc_command" = "upgrade" ]; then dbc_read_package_config dbc_preseed_package_debconf elif [ "$dbc_command" = "purge" ]; then # remove the dbc configuration file rm -f /etc/dbconfig-common/$dbc_package.conf || true if which ucf >/dev/null 2>&1; then cfg="/etc/dbconfig-common/$dbc_package.conf" ucf -p "$cfg" || true ucfr -p "$dbc_package" "$cfg" fi # forget everything we ever new related to debconf+dbc for t in $dbc_register_templates; do db_unregister $dbc_package/$t || true done fi } PKثY[!4 CCdpkg/prerm.mysqlnuW+Adbc_hardcoded_dbtype=mysql . /usr/share/dbconfig-common/dpkg/prerm PKثY[FFdpkg/postinst.mysqlnuW+Adbc_hardcoded_dbtype=mysql . /usr/share/dbconfig-common/dpkg/postinst PKثY[%lbHHdpkg/postinst.sqlite3nuW+Adbc_hardcoded_dbtype=sqlite3 . /usr/share/dbconfig-common/dpkg/postinst PKثY[cy y dpkg/prermnuW+A### ### some global variables etc ### dbc_go(){ local need_admin_pw dumpfile nowtime rmscript rmsql purgescript purgesql tsubstfile . /usr/share/dbconfig-common/dpkg/common _dbc_debug "(prerm) dbc_go() $@" dbc_config $@ ### ### get all the settings we need ### dbc_read_package_config # and re-run config for db-specific settings dbc_set_dbtype_defaults $dbc_dbtype if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then need_admin_pw="yup" else need_admin_pw="" fi if [ "$dbc_command" = "remove" ] && [ ! "$dbc_frontend" ]; then ### ### if they didn't want our help installing, we should assume ### they don't want our help removing either ### if [ "$dbc_install" != "true" ]; then return 0; fi ### ### ask the admin if we should help with removal ### if [ "$dbc_remove" ]; then db_set $dbc_package/dbconfig-remove "$dbc_remove" fi db_fset $dbc_package/dbconfig-remove seen false db_input high $dbc_package/dbconfig-remove || true db_go || true db_get $dbc_package/dbconfig-remove && dbc_remove="$RET" if [ "$dbc_remove" != "true" ]; then return 0; fi ### ### package removal hooks ### rmscript=/usr/share/dbconfig-common/scripts/$dbc_package/remove/$dbc_dbtype rmsql=/usr/share/dbconfig-common/data/$dbc_package/remove/$dbc_dbtype # run the script if it exists if [ -f "$rmscript" ]; then dbc_logpart "running maintainer removal script hook... " if ! sh -c "$rmscript \"$@\""; then dbc_error="$rmscript existed with non-zero status" dbc_remove_error "running maintainer removal hook" fi dbc_logline "done" fi # run the sql if it exists if [ -f "$rmsql" ]; then dbc_logpart "running maintainer removal sql hook... " if [ ! "$dbc_sql_substitutions" ]; then $dbc_sqlfile_cmd $rmsql || dbc_remove_error "running maintainer removal sql hook" else tsubstfile=`dbc_mktemp` /usr/sbin/dbconfig-generate-include -f template -o template_infile=$rmsql $dbc_packageconfig > $tsubstfile $dbc_sqlfile_cmd $tsubstfile || dbc_remove_error "running maintainer removal sql hook" rm -f $tsubstfile fi dbc_logline "done" fi ### ### ask the admin if the database should be purged ### db_fset $dbc_package/purge seen false db_input high $dbc_package/purge || true db_go || true db_get $dbc_package/purge dbc_purge="$RET" if [ "$dbc_dbtype" = "pgsql" ] && \ [ "$dbc_authmethod_admin" = "ident" ]; then need_admin_pw="" fi if [ "$dbc_purge" = "true" ]; then # get the admin user password if [ "$need_admin_pw" ]; then dbc_get_admin_pass fi # dump the database into a temporary file nowtime=`date +%Y-%m-%d-%H.%M` if [ ! `dirname /var/tmp/$dbc_package` = /var/tmp ]; then mkdir -p `dirname /var/tmp/$dbc_package` fi dumpfile=`mktemp /var/tmp/$dbc_package.$dbc_dbname.$nowtime.$dbc_dbtype.XXXXXX` if [ ! -f $dumpfile ]; then dbc_remove_error "creating temporary file for database dump" fi dbc_logline "dbconfig-common: dumping $dbc_dbtype database $dbc_dbname to $dumpfile" $dbc_dump_cmd $dumpfile || dbc_remove_error "dumping database" dbc_logline "dbconfig-common: dropping $dbc_dbtype database $dbc_dbname" $dbc_dropdb_cmd || dbc_remove_error "dropping database" [ "$dbc_tried_again" ] && return 0 dbc_logline "dbconfig-common: revoking privileges for user $dbc_dbuser on $dbc_dbname" $dbc_dropuser_cmd fi fi } PKثY[(@MEEdpkg/postrm.sqlitenuW+Adbc_hardcoded_dbtype=sqlite . /usr/share/dbconfig-common/dpkg/postrm PKثY[$Pz(( dpkg/postinstnuW+A### ### load up common variables and functions ### dbc_go(){ local importing_from_non_dbc upgrading reconfiguring f tsubstfile upgrades_pending dbc_dumpfile _dbc_asuser reinstall . /usr/share/dbconfig-common/dpkg/common _dbc_debug "(postinst) dbc_go() $@" dbc_config $@ # the maintainer has the option of telling us to not generate include files # for manual installs in case it changes the apps behavior to have the file dbc_dgi_on_manual=${dbc_dgi_on_manual:-true} ### ### begin main code execution ### if [ "$dbc_command" = "configure" ] || [ "$dbc_command" = "reconfigure" ]; then # read in debconf responses (which are seeded from the config) dbc_read_package_debconf # and write them to file. dbc_write_package_config # finally, re-read in the configuration from this file dbc_read_package_config ### ### if they don't want our help, quit ### if [ "$dbc_install" != "true" ]; then return 0; fi # export the config file if it exists, for the scripts if [ "$dbc_generate_include" ]; then # strip the leading format string for convenience dbc_config_include=`echo "$dbc_generate_include" | sed -e 's/^[^:]*://'` export dbc_generate_include export dbc_config_include fi # find out if we're upgrading/reinstalling if [ "$dbc_oldversion" ]; then # read that little crumb left in config if we're reconfiguring db_get $dbc_package/internal/reconfiguring && reconfiguring="$RET" # and set it back to false db_reset $dbc_package/internal/reconfiguring # if not, we're definitely upgrading if [ "$reconfiguring" = "false" ]; then upgrading="yes" else db_get $dbc_package/dbconfig-reinstall && reinstall=$RET db_reset $dbc_package/dbconfig-reinstall # if they've said they don't want to reinstall stuff... if [ "$reinstall" = "false" ]; then return 0; fi fi fi # now, determine if we're upgrading from a non-dbc version. if so, # there's a bunch of stuff that we do NOT want to do if [ "$upgrading" ] && [ "$dbc_first_version" ]; then if dpkg --compare-versions "$dbc_first_version" gt "$dbc_oldversion"; then dbc_logline "detected upgrade from previous non-dbconfig version" importing_from_non_dbc="true" fi fi # don't perform the following block of code during upgrades if [ ! "$upgrading" ]; then ### ### first things first, see if the database client package is installed, ### and in case of failure provide a more sensible error message. ### dbc_detect_installed_dbtype $dbc_dbtype || dbc_missing_db_package_error $dbc_dbclientpackage [ "$dbc_tried_again" ] && return 0 ### ### next, if we're connecting to a local database, ### see if the database server package is installed, ### and in case of failure provide a more sensible error message. ### if [ "$dbc_method" = "unix socket" ]; then $dbc_db_installed_cmd || dbc_missing_db_package_error $dbc_dbpackage [ "$dbc_tried_again" ] && return 0 fi ### ### now, create the app user account ### $dbc_createuser_cmd || dbc_install_error "creating user" [ "$dbc_tried_again" ] && return 0 ### ### create the database ### $dbc_createdb_cmd || dbc_install_error "creating database" [ "$dbc_tried_again" ] && return 0 ### ### populate the database ### # sqlfile is the file to use for installing the database dbc_sqlfile=$dbc_share/data/$dbc_basepackage/install/$dbc_dbtype dbc_sqlfile_adm=$dbc_share/data/$dbc_basepackage/install-dbadmin/$dbc_dbtype dbc_scriptfile=$dbc_share/scripts/$dbc_basepackage/install/$dbc_dbtype if [ -f "$dbc_scriptfile" ]; then dbc_logpart "populating database via scriptfile... " if ! sh -c "$dbc_scriptfile $*"; then dbc_error="$dbc_scriptfile exited with non-zero status" dbc_install_error "populating database" [ "$dbc_tried_again" ] && return 0 fi dbc_logline "done" fi if [ -f "$dbc_sqlfile_adm" ]; then dbc_logpart "populating database via administrative sql... " if [ ! "$dbc_sql_substitutions" ]; then $dbc_sqlfile_cmd $dbc_sqlfile_adm || dbc_install_error "populating database with administrative sql" else tsubstfile=`dbc_mktemp` /usr/sbin/dbconfig-generate-include -f template -o template_infile=$dbc_sqlfile_adm $dbc_packageconfig > $tsubstfile $dbc_sqlfile_cmd $tsubstfile || dbc_install_error "populating database with administrative sql" rm -f $tsubstfile fi [ "$dbc_tried_again" ] && return 0 dbc_logline "done" fi if [ -f "$dbc_sqlfile" ]; then dbc_logpart "populating database via sql... " _dbc_asuser="yes" if [ ! "$dbc_sql_substitutions" ]; then $dbc_sqlfile_cmd $dbc_sqlfile || dbc_install_error "populating database" else tsubstfile=`dbc_mktemp` /usr/sbin/dbconfig-generate-include -f template -o template_infile=$dbc_sqlfile $dbc_packageconfig > $tsubstfile $dbc_sqlfile_cmd $tsubstfile || dbc_install_error "populating database" rm -f $tsubstfile fi _dbc_asuser="" [ "$dbc_tried_again" ] && return 0 dbc_logline "done" fi # now that we are sure that the database has been # (re-)installed, we can reset the purge flag. db_set $dbc_package/purge false db_fset $dbc_package/purge seen false fi # end install/reconfigure section if [ "$importing_from_non_dbc" ]; then if ! $dbc_checkuser_command; then upgrade_error "importing dbconfig-settings" [ "$dbc_tried_again" ] && return 0 fi fi # begin upgrade section if [ "$upgrading" ]; then upgrades_pending=`_dbc_find_upgrades` # if there are any upgrades to be applied if [ "$upgrades_pending" ]; then # ask if they want our help in the process at all db_set $dbc_package/dbconfig-upgrade $dbc_upgrade db_fset $dbc_package/dbconfig-upgrade seen false db_input high $dbc_package/dbconfig-upgrade || true db_go || true db_get $dbc_package/dbconfig-upgrade && dbc_upgrade="$RET" # and if they don't want our help, we'll go away if [ "$dbc_upgrade" != "true" ]; then return 0; fi # get the admin password if it's needed if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then if [ ! "$dbc_frontend" ]; then if [ ! "$dbc_dbtype" = "pgsql" ] || [ ! "$dbc_authmethod_admin" = "ident" ]; then dbc_get_admin_pass fi fi fi # this is the file into which upgrade backups go dbc_dumpfile=/var/cache/dbconfig-common/backups/${dbc_package}_${dbc_oldversion}.$dbc_dbtype dbc_logline "creating database backup in $dbc_dumpfile" # backup before we upgrade _dbc_asuser="" $dbc_dump_cmd $dbc_dumpfile || dbc_upgrade_error "backing up the old database" fi # now perform the updates for f in $upgrades_pending; do _dbc_apply_upgrades $f done fi # end upgrade section fi # don't forget to clean up after ourselves dbc_postinst_cleanup } ## ## search through the predefined upgrade directories, and return ## the versions for which *some* upgrade is available. later for each ## upgrade version with a script we again search through the predefined ## directories to find which upgrade provides it. it's definitely ## less efficient this way, but it's much cleaner and ensures that ## upgrades are provided in-order regardless of which methods are used. ## _dbc_find_upgrades(){ local f s sqldir admsqldir scriptdir upgradedirs pending sorted placed tlist # check for new upgrades in these three locations sqldir=$dbc_share/data/$dbc_basepackage/upgrade/$dbc_dbtype admsqldir=$dbc_share/data/$dbc_basepackage/upgrade-dbadmin/$dbc_dbtype scriptdir=$dbc_share/scripts/$dbc_basepackage/upgrade/$dbc_dbtype for f in $sqldir $admsqldir $scriptdir; do if [ -d "$f" ]; then upgradedirs="${upgradedirs:+$upgradedirs }$f" fi done if [ ! "${upgradedirs:-}" ]; then return 0; fi for f in `find $upgradedirs -xtype f -print0 | \ xargs --no-run-if-empty -0 -n1 basename | sort -n | uniq`; do if dpkg --compare-versions $dbc_oldversion lt $f; then pending="${pending:+$pending }$f" fi done # for each pending update for f in ${pending:-}; do # if the sorted list is empty if [ ! "${sorted:-}" ]; then sorted="$f" else # a scratch list for a sorted insert of the next version tlist="" # for each already sorted version for s in ${sorted:-}; do # if we haven't already placed it if [ ! "${placed:-}" ]; then # if the this version is less than the next sorted one if dpkg --compare-versions $f lt $s; then # insert it here tlist="$tlist $f" placed="yes" fi fi tlist="$tlist $s" done # if we still haven't placed it, tack it on to the end of the list if [ ! "${placed:-}" ]; then tlist="$tlist $f" fi # and now reset the placed variable, and update the sorted list placed="" sorted="$tlist" fi done echo $sorted } ## ## this function applies all available upgrade scripts/sql for a specific ## version ($1). no checking is done to make sure that the upgrade *should* ## be applied, that is assumed to have been done by _dbc_find_upgrades(). ## _dbc_apply_upgrades(){ local f vers sqlfile admsqlfile scriptfile _dbc_debug "_dbc_apply_upgrades() $@" # check for new upgrades in these three locations vers="$1" sqlfile="$dbc_share/data/$dbc_basepackage/upgrade/$dbc_dbtype/$vers" admsqlfile="$dbc_share/data/$dbc_basepackage/upgrade-dbadmin/$dbc_dbtype/$vers" scriptfile="$dbc_share/scripts/$dbc_basepackage/upgrade/$dbc_dbtype/$vers" # now go through script updates if [ -f "$scriptfile" ]; then dbc_logline "applying upgrade script for $dbc_oldversion -> $vers" # XXX $* if ! sh -c "$scriptfile $*"; then dbc_error="$scriptfile exited with non-zero status" dbc_upgrade_error "processing $scriptfile" [ "$dbc_tried_again" ] && return 0 fi fi _dbc_asuser="" if [ -f "$admsqlfile" ]; then dbc_logline "applying upgrade admin sql for $dbc_oldversion -> $vers" $dbc_sqlfile_cmd $admsqlfile || dbc_upgrade_error "processing $admsqlfile" [ "$dbc_tried_again" ] && return 0 fi if [ -f "$sqlfile" ]; then _dbc_asuser="yes" dbc_logline "applying upgrade sql for $dbc_oldversion -> $vers" $dbc_sqlfile_cmd $sqlfile || dbc_upgrade_error "processing $sqlfile" [ "$dbc_tried_again" ] && return 0 _dbc_asuser="" fi } PKثY[݇ DDdpkg/prerm.sqlitenuW+Adbc_hardcoded_dbtype=sqlite . /usr/share/dbconfig-common/dpkg/prerm PKثY[qCCdpkg/frontend.postrm.mysqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/postrm.mysql PKثY[b'FVEEdpkg/frontend.postinst.mysqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/postinst.mysql PKثY[6EEdpkg/frontend.postinst.pgsqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/postinst.pgsql PKثY[7HEEdpkg/config.pgsqlnuW+Adbc_hardcoded_dbtype=pgsql . /usr/share/dbconfig-common/dpkg/config PKثY[bFFdpkg/preinst.pgsqlnuW+Adbc_hardcoded_dbtype=pgsql . /usr/share/dbconfig-common/dpkg/preinst PKثY[mCCdpkg/frontend.config.mysqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/config.mysql PKثY[e|&DDdpkg/postrm.pgsqlnuW+Adbc_hardcoded_dbtype=pgsql . /usr/share/dbconfig-common/dpkg/postrm PKثY[|TCCdpkg/frontend.postrm.pgsqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/postrm.pgsql PKثY[$CCdpkg/frontend.config.pgsqlnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/config.pgsql PKثY[IEEdpkg/preinst.mysqlnuW+Adbc_hardcoded_dbtype=mysql . /usr/share/dbconfig-common/dpkg/preinst PKثY[c8DDdpkg/config.mysqlnuW+Adbc_hardcoded_dbtype=mysql . /usr/share/dbconfig-common/dpkg/config PKثY[o6DDdpkg/postrm.mysqlnuW+Adbc_hardcoded_dbtype=mysql . /usr/share/dbconfig-common/dpkg/postrm PKثY[6t%EEdpkg/prerm.sqlite3nuW+Adbc_hardcoded_dbtype=sqlite3 . /usr/share/dbconfig-common/dpkg/prerm PKثY[n>>dpkg/frontend.preinstnuW+Adbc_frontend="true" . /usr/share/dbconfig-common/dpkg/preinst PKثY[~data/phpmyadmin/install/mysqlnuW+A-- -------------------------------------------------------- -- SQL Commands to set up the pmadb as described in Documentation.html. -- -- This file is meant for use with MySQL 5 and above! -- -- This script expects the user pma to already be existing. If we would put a -- line here to create him too many users might just use this script and end -- up with having the same password for the controluser. -- -- This user "pma" must be defined in config.inc.php (controluser/controlpass) -- -- Please don't forget to set up the tablenames in config.inc.php -- -- $Id$ -- -------------------------------------------------------- -- -------------------------------------------------------- -- -- Privileges -- -- (activate this statement if necessary) -- GRANT SELECT, INSERT, DELETE, UPDATE ON `phpmyadmin`.* TO -- 'pma'@localhost; -- -------------------------------------------------------- -- -- Table structure for table `pma_bookmark` -- CREATE TABLE IF NOT EXISTS `pma_bookmark` ( `id` int(11) NOT NULL auto_increment, `dbase` varchar(255) NOT NULL default '', `user` varchar(255) NOT NULL default '', `label` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default '', `query` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM COMMENT='Bookmarks' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; -- -------------------------------------------------------- -- -- Table structure for table `pma_column_info` -- CREATE TABLE IF NOT EXISTS `pma_column_info` ( `id` int(5) unsigned NOT NULL auto_increment, `db_name` varchar(64) NOT NULL default '', `table_name` varchar(64) NOT NULL default '', `column_name` varchar(64) NOT NULL default '', `comment` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default '', `mimetype` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default '', `transformation` varchar(255) NOT NULL default '', `transformation_options` varchar(255) NOT NULL default '', PRIMARY KEY (`id`), UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`) ) ENGINE=MyISAM COMMENT='Column information for phpMyAdmin' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; -- -------------------------------------------------------- -- -- Table structure for table `pma_history` -- CREATE TABLE IF NOT EXISTS `pma_history` ( `id` bigint(20) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default '', `db` varchar(64) NOT NULL default '', `table` varchar(64) NOT NULL default '', `timevalue` timestamp(14) NOT NULL, `sqlquery` text NOT NULL, PRIMARY KEY (`id`), KEY `username` (`username`,`db`,`table`,`timevalue`) ) ENGINE=MyISAM COMMENT='SQL history for phpMyAdmin' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; -- -------------------------------------------------------- -- -- Table structure for table `pma_pdf_pages` -- CREATE TABLE IF NOT EXISTS `pma_pdf_pages` ( `db_name` varchar(64) NOT NULL default '', `page_nr` int(10) unsigned NOT NULL auto_increment, `page_descr` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default '', PRIMARY KEY (`page_nr`), KEY `db_name` (`db_name`) ) ENGINE=MyISAM COMMENT='PDF relation pages for phpMyAdmin' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; -- -------------------------------------------------------- -- -- Table structure for table `pma_relation` -- CREATE TABLE IF NOT EXISTS `pma_relation` ( `master_db` varchar(64) NOT NULL default '', `master_table` varchar(64) NOT NULL default '', `master_field` varchar(64) NOT NULL default '', `foreign_db` varchar(64) NOT NULL default '', `foreign_table` varchar(64) NOT NULL default '', `foreign_field` varchar(64) NOT NULL default '', PRIMARY KEY (`master_db`,`master_table`,`master_field`), KEY `foreign_field` (`foreign_db`,`foreign_table`) ) ENGINE=MyISAM COMMENT='Relation table' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; -- -------------------------------------------------------- -- -- Table structure for table `pma_table_coords` -- CREATE TABLE IF NOT EXISTS `pma_table_coords` ( `db_name` varchar(64) NOT NULL default '', `table_name` varchar(64) NOT NULL default '', `pdf_page_number` int(11) NOT NULL default '0', `x` float unsigned NOT NULL default '0', `y` float unsigned NOT NULL default '0', PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`) ) ENGINE=MyISAM COMMENT='Table coordinates for phpMyAdmin PDF output' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; -- -------------------------------------------------------- -- -- Table structure for table `pma_table_info` -- CREATE TABLE IF NOT EXISTS `pma_table_info` ( `db_name` varchar(64) NOT NULL default '', `table_name` varchar(64) NOT NULL default '', `display_field` varchar(64) NOT NULL default '', PRIMARY KEY (`db_name`,`table_name`) ) ENGINE=MyISAM COMMENT='Table information for phpMyAdmin' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; -- -------------------------------------------------------- -- -- Table structure for table `pma_designer_coords` -- CREATE TABLE IF NOT EXISTS `pma_designer_coords` ( `db_name` varchar(64) NOT NULL default '', `table_name` varchar(64) NOT NULL default '', `x` INT, `y` INT, `v` TINYINT, `h` TINYINT, PRIMARY KEY (`db_name`,`table_name`) ) ENGINE=MyISAM COMMENT='Table coordinates for Designer' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; -- -------------------------------------------------------- -- -- Table structure for table `pma_tracking` -- CREATE TABLE IF NOT EXISTS `pma_tracking` ( `db_name` varchar(64) collate utf8_bin NOT NULL, `table_name` varchar(64) collate utf8_bin NOT NULL, `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL, `date_updated` datetime NOT NULL, `schema_snapshot` text collate utf8_bin NOT NULL, `schema_sql` text collate utf8_bin, `data_sql` longtext collate utf8_bin, `tracking` set('UPDATE','REPLACE','INSERT','DELETE','TRUNCATE','CREATE DATABASE','ALTER DATABASE','DROP DATABASE','CREATE TABLE','ALTER TABLE','RENAME TABLE','DROP TABLE','CREATE INDEX','DROP INDEX','CREATE VIEW','ALTER VIEW','DROP VIEW') collate utf8_bin default NULL, `tracking_active` int(1) unsigned NOT NULL default '1', PRIMARY KEY (`db_name`,`table_name`,`version`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=COMPACT; PKثY['data/phpmyadmin/upgrade/mysql/4:3.3.2-2nuW+A-- -- Table structure for table `pma_tracking` -- CREATE TABLE IF NOT EXISTS `pma_tracking` ( `db_name` varchar(64) collate utf8_bin NOT NULL, `table_name` varchar(64) collate utf8_bin NOT NULL, `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL, `date_updated` datetime NOT NULL, `schema_snapshot` text collate utf8_bin NOT NULL, `schema_sql` text collate utf8_bin, `data_sql` longtext collate utf8_bin, `tracking` set('UPDATE','REPLACE','INSERT','DELETE','TRUNCATE','CREATE DATABASE','ALTER DATABASE','DROP DATABASE','CREATE TABLE','ALTER TABLE','RENAME TABLE','DROP TABLE','CREATE INDEX','DROP INDEX','CREATE VIEW','ALTER VIEW','DROP VIEW') collate utf8_bin default NULL, `tracking_active` int(1) unsigned NOT NULL default '1', PRIMARY KEY (`db_name`,`table_name`,`version`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=COMPACT; PKثY[BaFlinternal/commonnuW+APKثY[9##[internal/mysqlnuW+APKثY[nA22r8internal/pgsqlnuW+APKثY[_ajkinternal/sqlitenuW+APKثY[<"GG|dpkg/config.sqlite3nuW+APKثY[# FF}dpkg/postrm.sqlite3nuW+APKثY[[Loo }dpkg/commonnuW+APKثY[b@FFdpkg/postinst.pgsqlnuW+APKثY[ M`??Fdpkg/frontend.postinstnuW+APKثY[)DDdpkg/frontend.preinst.mysqlnuW+APKثY[8fGGZdpkg/preinst.sqlite3nuW+APKثY[!BBdpkg/frontend.prerm.pgsqlnuW+APKثY[BBpdpkg/frontend.prerm.mysqlnuW+APKثY[`GGdpkg/postinst.sqlitenuW+APKثY[锗FFdpkg/config.sqlitenuW+APKثY[[==dpkg/frontend.postrmnuW+APKثY[^\<<dpkg/frontend.prermnuW+APKثY[fDDdpkg/frontend.preinst.pgsqlnuW+APKثY[ O==dpkg/frontend.confignuW+APKثY[RCCdpkg/prerm.pgsqlnuW+APKثY[b@66 dpkg/confignuW+APKثY[L## +dpkg/preinstnuW+APKثY[xFF.-dpkg/preinst.sqlitenuW+APKثY[W -dpkg/postrmnuW+APKثY[!4 CC0dpkg/prerm.mysqlnuW+APKثY[FF1dpkg/postinst.mysqlnuW+APKثY[%lbHH1dpkg/postinst.sqlite3nuW+APKثY[cy y .2dpkg/prermnuW+APKثY[(@MEE?dpkg/postrm.sqlitenuW+APKثY[$Pz(( h@dpkg/postinstnuW+APKثY[݇ DDHidpkg/prerm.sqlitenuW+APKثY[qCCidpkg/frontend.postrm.mysqlnuW+APKثY[b'FVEEZjdpkg/frontend.postinst.mysqlnuW+APKثY[6EEjdpkg/frontend.postinst.pgsqlnuW+APKثY[7HEE|kdpkg/config.pgsqlnuW+APKثY[bFFldpkg/preinst.pgsqlnuW+APKثY[mCCldpkg/frontend.config.mysqlnuW+APKثY[e|&DDmdpkg/postrm.pgsqlnuW+APKثY[|TCCmdpkg/frontend.postrm.pgsqlnuW+APKثY[$CC)ndpkg/frontend.config.pgsqlnuW+APKثY[IEEndpkg/preinst.mysqlnuW+APKثY[c8DD=odpkg/config.mysqlnuW+APKثY[o6DDodpkg/postrm.mysqlnuW+APKثY[6t%EEGpdpkg/prerm.sqlite3nuW+APKثY[n>>pdpkg/frontend.preinstnuW+APKثY[~Qqdata/phpmyadmin/install/mysqlnuW+APKثY['<data/phpmyadmin/upgrade/mysql/4:3.3.2-2nuW+APK//[